@@ -24,64 +24,64 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | <?php |
| 26 | 26 | |
| 27 | - // Fires before printing a line item column. |
|
| 28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
| 27 | + // Fires before printing a line item column. |
|
| 28 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
| 29 | 29 | |
| 30 | - // Item name. |
|
| 31 | - if ( 'name' == $key ) { |
|
| 30 | + // Item name. |
|
| 31 | + if ( 'name' == $key ) { |
|
| 32 | 32 | |
| 33 | - // Display the name. |
|
| 34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
| 33 | + // Display the name. |
|
| 34 | + echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
| 35 | 35 | |
| 36 | - // And an optional description. |
|
| 36 | + // And an optional description. |
|
| 37 | 37 | $description = $item->get_description(); |
| 38 | 38 | |
| 39 | 39 | if ( ! empty( $description ) ) { |
| 40 | 40 | $description = wp_kses_post( $description ); |
| 41 | 41 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // Price help text. |
|
| 44 | + // Price help text. |
|
| 45 | 45 | $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
| 46 | 46 | if ( $description ) { |
| 47 | 47 | echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>"; |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // Item price. |
|
| 53 | - if ( 'price' == $key ) { |
|
| 52 | + // Item price. |
|
| 53 | + if ( 'price' == $key ) { |
|
| 54 | 54 | |
| 55 | - // Set the currency position. |
|
| 56 | - $position = wpinv_currency_position(); |
|
| 55 | + // Set the currency position. |
|
| 56 | + $position = wpinv_currency_position(); |
|
| 57 | 57 | |
| 58 | - if ( $position == 'left_space' ) { |
|
| 59 | - $position = 'left'; |
|
| 60 | - } |
|
| 58 | + if ( $position == 'left_space' ) { |
|
| 59 | + $position = 'left'; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - if ( $position == 'right_space' ) { |
|
| 63 | - $position = 'right'; |
|
| 64 | - } |
|
| 62 | + if ( $position == 'right_space' ) { |
|
| 63 | + $position = 'right'; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if ( $item->user_can_set_their_price() ) { |
|
| 67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
| 68 | - $minimum = (float) $item->get_minimum_price(); |
|
| 69 | - $validate_minimum = ''; |
|
| 70 | - $class = ''; |
|
| 71 | - $data_minimum = ''; |
|
| 66 | + if ( $item->user_can_set_their_price() ) { |
|
| 67 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
| 68 | + $minimum = (float) $item->get_minimum_price(); |
|
| 69 | + $validate_minimum = ''; |
|
| 70 | + $class = ''; |
|
| 71 | + $data_minimum = ''; |
|
| 72 | 72 | |
| 73 | - if ( $minimum > 0 ) { |
|
| 74 | - $validate_minimum = sprintf( |
|
| 75 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
| 76 | - sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
| 77 | - ); |
|
| 73 | + if ( $minimum > 0 ) { |
|
| 74 | + $validate_minimum = sprintf( |
|
| 75 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
| 76 | + sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - $class = 'getpaid-validate-minimum-amount'; |
|
| 79 | + $class = 'getpaid-validate-minimum-amount'; |
|
| 80 | 80 | |
| 81 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
| 82 | - } |
|
| 81 | + $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - ?> |
|
| 84 | + ?> |
|
| 85 | 85 | <div class="input-group input-group-sm"> |
| 86 | 86 | <?php if( 'left' == $position ) : ?> |
| 87 | 87 | <div class="input-group-prepend"> |
@@ -105,37 +105,37 @@ discard block |
||
| 105 | 105 | </div> |
| 106 | 106 | |
| 107 | 107 | <?php |
| 108 | - } else { |
|
| 109 | - echo wpinv_price( $item->get_price(), $currency ); |
|
| 110 | - ?> |
|
| 108 | + } else { |
|
| 109 | + echo wpinv_price( $item->get_price(), $currency ); |
|
| 110 | + ?> |
|
| 111 | 111 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
| 112 | 112 | <?php |
| 113 | - } |
|
| 114 | - } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - // Item quantity. |
|
| 117 | - if ( 'quantity' == $key ) { |
|
| 116 | + // Item quantity. |
|
| 117 | + if ( 'quantity' == $key ) { |
|
| 118 | 118 | |
| 119 | - if ( $item->allows_quantities() ) { |
|
| 120 | - ?> |
|
| 119 | + if ( $item->allows_quantities() ) { |
|
| 120 | + ?> |
|
| 121 | 121 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required> |
| 122 | 122 | <?php |
| 123 | - } else { |
|
| 124 | - echo (float) $item->get_quantity(); |
|
| 125 | - echo ' '; |
|
| 126 | - ?> |
|
| 123 | + } else { |
|
| 124 | + echo (float) $item->get_quantity(); |
|
| 125 | + echo ' '; |
|
| 126 | + ?> |
|
| 127 | 127 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
| 128 | 128 | <?php |
| 129 | - } |
|
| 130 | - } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // Item sub total. |
|
| 133 | - if ( 'subtotal' == $key ) { |
|
| 134 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
| 135 | - } |
|
| 132 | + // Item sub total. |
|
| 133 | + if ( 'subtotal' == $key ) { |
|
| 134 | + echo wpinv_price( $item->get_sub_total(), $currency ); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
| 138 | - ?> |
|
| 137 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
| 138 | + ?> |
|
| 139 | 139 | |
| 140 | 140 | </div> |
| 141 | 141 | |
@@ -14,592 +14,592 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array An array of payment gateways. |
|
| 40 | - */ |
|
| 41 | - public $gateways; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Class constructor. |
|
| 45 | - */ |
|
| 46 | - public function __construct() { |
|
| 47 | - $this->define_constants(); |
|
| 48 | - $this->includes(); |
|
| 49 | - $this->init_hooks(); |
|
| 50 | - $this->set_properties(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Sets a custom data property. |
|
| 55 | - * |
|
| 56 | - * @param string $prop The prop to set. |
|
| 57 | - * @param mixed $value The value to retrieve. |
|
| 58 | - */ |
|
| 59 | - public function set( $prop, $value ) { |
|
| 60 | - $this->data[ $prop ] = $value; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets a custom data property. |
|
| 65 | - * |
|
| 66 | - * @param string $prop The prop to set. |
|
| 67 | - * @return mixed The value. |
|
| 68 | - */ |
|
| 69 | - public function get( $prop ) { |
|
| 70 | - |
|
| 71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 72 | - return $this->data[ $prop ]; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return null; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Define class properties. |
|
| 80 | - */ |
|
| 81 | - public function set_properties() { |
|
| 82 | - |
|
| 83 | - // Sessions. |
|
| 84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 87 | - |
|
| 88 | - // Init other objects. |
|
| 89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 91 | - $this->set( 'api', new WPInv_API() ); |
|
| 92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 93 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 101 | - |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Define plugin constants. |
|
| 106 | - */ |
|
| 107 | - public function define_constants() { |
|
| 108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 110 | - $this->version = WPINV_VERSION; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Hook into actions and filters. |
|
| 115 | - * |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - */ |
|
| 118 | - protected function init_hooks() { |
|
| 119 | - /* Internationalize the text strings used. */ |
|
| 120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 121 | - |
|
| 122 | - // Init the plugin after WordPress inits. |
|
| 123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 130 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 133 | - |
|
| 134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Data container. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Form elements instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Payment_Form_Elements |
|
| 35 | + */ |
|
| 36 | + public $form_elements; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array An array of payment gateways. |
|
| 40 | + */ |
|
| 41 | + public $gateways; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Class constructor. |
|
| 45 | + */ |
|
| 46 | + public function __construct() { |
|
| 47 | + $this->define_constants(); |
|
| 48 | + $this->includes(); |
|
| 49 | + $this->init_hooks(); |
|
| 50 | + $this->set_properties(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Sets a custom data property. |
|
| 55 | + * |
|
| 56 | + * @param string $prop The prop to set. |
|
| 57 | + * @param mixed $value The value to retrieve. |
|
| 58 | + */ |
|
| 59 | + public function set( $prop, $value ) { |
|
| 60 | + $this->data[ $prop ] = $value; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets a custom data property. |
|
| 65 | + * |
|
| 66 | + * @param string $prop The prop to set. |
|
| 67 | + * @return mixed The value. |
|
| 68 | + */ |
|
| 69 | + public function get( $prop ) { |
|
| 70 | + |
|
| 71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 72 | + return $this->data[ $prop ]; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return null; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Define class properties. |
|
| 80 | + */ |
|
| 81 | + public function set_properties() { |
|
| 82 | + |
|
| 83 | + // Sessions. |
|
| 84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 87 | + |
|
| 88 | + // Init other objects. |
|
| 89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 91 | + $this->set( 'api', new WPInv_API() ); |
|
| 92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 93 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Define plugin constants. |
|
| 106 | + */ |
|
| 107 | + public function define_constants() { |
|
| 108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 110 | + $this->version = WPINV_VERSION; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Hook into actions and filters. |
|
| 115 | + * |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + */ |
|
| 118 | + protected function init_hooks() { |
|
| 119 | + /* Internationalize the text strings used. */ |
|
| 120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 121 | + |
|
| 122 | + // Init the plugin after WordPress inits. |
|
| 123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 128 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 129 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 130 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 131 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 133 | + |
|
| 134 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 135 | 135 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
| 136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 137 | - |
|
| 138 | - // Fires after registering actions. |
|
| 139 | - do_action( 'wpinv_actions', $this ); |
|
| 140 | - do_action( 'getpaid_actions', $this ); |
|
| 141 | - |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function plugins_loaded() { |
|
| 145 | - /* Internationalize the text strings used. */ |
|
| 146 | - $this->load_textdomain(); |
|
| 147 | - |
|
| 148 | - do_action( 'wpinv_loaded' ); |
|
| 149 | - |
|
| 150 | - // Fix oxygen page builder conflict |
|
| 151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 152 | - wpinv_oxygen_fix_conflict(); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Load the translation of the plugin. |
|
| 158 | - * |
|
| 159 | - * @since 1.0 |
|
| 160 | - */ |
|
| 161 | - public function load_textdomain( $locale = NULL ) { |
|
| 162 | - if ( empty( $locale ) ) { |
|
| 163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 167 | - |
|
| 168 | - unload_textdomain( 'invoicing' ); |
|
| 169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Define language constants. |
|
| 174 | - */ |
|
| 175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Include required core files used in admin and on the frontend. |
|
| 180 | - */ |
|
| 181 | - public function includes() { |
|
| 182 | - |
|
| 183 | - // Start with the settings. |
|
| 184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 185 | - |
|
| 186 | - // Packages/libraries. |
|
| 187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 189 | - |
|
| 190 | - // Load functions. |
|
| 191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
| 200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
| 205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 206 | - |
|
| 207 | - // Register autoloader. |
|
| 208 | - try { |
|
| 209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 210 | - } catch ( Exception $e ) { |
|
| 211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 234 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 235 | - |
|
| 236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 237 | - GetPaid_Post_Types_Admin::init(); |
|
| 238 | - |
|
| 239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 245 | - // load the user class only on the users.php page |
|
| 246 | - global $pagenow; |
|
| 247 | - if($pagenow=='users.php'){ |
|
| 248 | - new WPInv_Admin_Users(); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // Register cli commands |
|
| 253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 254 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Class autoloader |
|
| 262 | - * |
|
| 263 | - * @param string $class_name The name of the class to load. |
|
| 264 | - * @access public |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @return void |
|
| 267 | - */ |
|
| 268 | - public function autoload( $class_name ) { |
|
| 269 | - |
|
| 270 | - // Normalize the class name... |
|
| 271 | - $class_name = strtolower( $class_name ); |
|
| 272 | - |
|
| 273 | - // ... and make sure it is our class. |
|
| 274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // Next, prepare the file name from the class. |
|
| 279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 280 | - |
|
| 281 | - // Base path of the classes. |
|
| 282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 283 | - |
|
| 284 | - // And an array of possible locations in order of importance. |
|
| 285 | - $locations = array( |
|
| 286 | - "$plugin_path/includes", |
|
| 287 | - "$plugin_path/includes/data-stores", |
|
| 288 | - "$plugin_path/includes/gateways", |
|
| 289 | - "$plugin_path/includes/payments", |
|
| 290 | - "$plugin_path/includes/geolocation", |
|
| 291 | - "$plugin_path/includes/reports", |
|
| 292 | - "$plugin_path/includes/api", |
|
| 293 | - "$plugin_path/includes/admin", |
|
| 294 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 295 | - ); |
|
| 296 | - |
|
| 297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 298 | - |
|
| 299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 300 | - include trailingslashit( $location ) . $file_name; |
|
| 301 | - break; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Inits hooks etc. |
|
| 310 | - */ |
|
| 311 | - public function init() { |
|
| 312 | - |
|
| 313 | - // Fires before getpaid inits. |
|
| 314 | - do_action( 'before_getpaid_init', $this ); |
|
| 315 | - |
|
| 316 | - // Maybe upgrade. |
|
| 317 | - $this->maybe_upgrade_database(); |
|
| 318 | - |
|
| 319 | - // Load default gateways. |
|
| 320 | - $gateways = apply_filters( |
|
| 321 | - 'getpaid_default_gateways', |
|
| 322 | - array( |
|
| 323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 328 | - ) |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - foreach ( $gateways as $id => $class ) { |
|
| 332 | - $this->gateways[ $id ] = new $class(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 336 | - GetPaid_Installer::rename_gateways_label(); |
|
| 337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - // Fires after getpaid inits. |
|
| 341 | - do_action( 'getpaid_init', $this ); |
|
| 342 | - |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Checks if this is an IPN request and processes it. |
|
| 347 | - */ |
|
| 348 | - public function maybe_process_ipn() { |
|
| 349 | - |
|
| 350 | - // Ensure that this is an IPN request. |
|
| 351 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 352 | - return; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 356 | - |
|
| 357 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 358 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 359 | - exit; |
|
| 360 | - |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - public function enqueue_scripts() { |
|
| 364 | - |
|
| 365 | - // Fires before adding scripts. |
|
| 366 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 367 | - |
|
| 368 | - $localize = array(); |
|
| 369 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 370 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
| 371 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
| 372 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 373 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 374 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 375 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 376 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 377 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 378 | - |
|
| 379 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 380 | - |
|
| 381 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 382 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 383 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - public function wpinv_actions() { |
|
| 387 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 388 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 136 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 137 | + |
|
| 138 | + // Fires after registering actions. |
|
| 139 | + do_action( 'wpinv_actions', $this ); |
|
| 140 | + do_action( 'getpaid_actions', $this ); |
|
| 141 | + |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function plugins_loaded() { |
|
| 145 | + /* Internationalize the text strings used. */ |
|
| 146 | + $this->load_textdomain(); |
|
| 147 | + |
|
| 148 | + do_action( 'wpinv_loaded' ); |
|
| 149 | + |
|
| 150 | + // Fix oxygen page builder conflict |
|
| 151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 152 | + wpinv_oxygen_fix_conflict(); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Load the translation of the plugin. |
|
| 158 | + * |
|
| 159 | + * @since 1.0 |
|
| 160 | + */ |
|
| 161 | + public function load_textdomain( $locale = NULL ) { |
|
| 162 | + if ( empty( $locale ) ) { |
|
| 163 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 167 | + |
|
| 168 | + unload_textdomain( 'invoicing' ); |
|
| 169 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 170 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Define language constants. |
|
| 174 | + */ |
|
| 175 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Include required core files used in admin and on the frontend. |
|
| 180 | + */ |
|
| 181 | + public function includes() { |
|
| 182 | + |
|
| 183 | + // Start with the settings. |
|
| 184 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 185 | + |
|
| 186 | + // Packages/libraries. |
|
| 187 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 188 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 189 | + |
|
| 190 | + // Load functions. |
|
| 191 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 194 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 195 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 198 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 199 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
| 200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 204 | + require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
| 205 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 206 | + |
|
| 207 | + // Register autoloader. |
|
| 208 | + try { |
|
| 209 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 210 | + } catch ( Exception $e ) { |
|
| 211 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 216 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 219 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 220 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 222 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 225 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 230 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 231 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 233 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 234 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 235 | + |
|
| 236 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 237 | + GetPaid_Post_Types_Admin::init(); |
|
| 238 | + |
|
| 239 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 240 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 241 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 242 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 243 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 244 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 245 | + // load the user class only on the users.php page |
|
| 246 | + global $pagenow; |
|
| 247 | + if($pagenow=='users.php'){ |
|
| 248 | + new WPInv_Admin_Users(); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // Register cli commands |
|
| 253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 254 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Class autoloader |
|
| 262 | + * |
|
| 263 | + * @param string $class_name The name of the class to load. |
|
| 264 | + * @access public |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @return void |
|
| 267 | + */ |
|
| 268 | + public function autoload( $class_name ) { |
|
| 269 | + |
|
| 270 | + // Normalize the class name... |
|
| 271 | + $class_name = strtolower( $class_name ); |
|
| 272 | + |
|
| 273 | + // ... and make sure it is our class. |
|
| 274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // Next, prepare the file name from the class. |
|
| 279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 280 | + |
|
| 281 | + // Base path of the classes. |
|
| 282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 283 | + |
|
| 284 | + // And an array of possible locations in order of importance. |
|
| 285 | + $locations = array( |
|
| 286 | + "$plugin_path/includes", |
|
| 287 | + "$plugin_path/includes/data-stores", |
|
| 288 | + "$plugin_path/includes/gateways", |
|
| 289 | + "$plugin_path/includes/payments", |
|
| 290 | + "$plugin_path/includes/geolocation", |
|
| 291 | + "$plugin_path/includes/reports", |
|
| 292 | + "$plugin_path/includes/api", |
|
| 293 | + "$plugin_path/includes/admin", |
|
| 294 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 295 | + ); |
|
| 296 | + |
|
| 297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 298 | + |
|
| 299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 300 | + include trailingslashit( $location ) . $file_name; |
|
| 301 | + break; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Inits hooks etc. |
|
| 310 | + */ |
|
| 311 | + public function init() { |
|
| 312 | + |
|
| 313 | + // Fires before getpaid inits. |
|
| 314 | + do_action( 'before_getpaid_init', $this ); |
|
| 315 | + |
|
| 316 | + // Maybe upgrade. |
|
| 317 | + $this->maybe_upgrade_database(); |
|
| 318 | + |
|
| 319 | + // Load default gateways. |
|
| 320 | + $gateways = apply_filters( |
|
| 321 | + 'getpaid_default_gateways', |
|
| 322 | + array( |
|
| 323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 328 | + ) |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + foreach ( $gateways as $id => $class ) { |
|
| 332 | + $this->gateways[ $id ] = new $class(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 336 | + GetPaid_Installer::rename_gateways_label(); |
|
| 337 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + // Fires after getpaid inits. |
|
| 341 | + do_action( 'getpaid_init', $this ); |
|
| 342 | + |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Checks if this is an IPN request and processes it. |
|
| 347 | + */ |
|
| 348 | + public function maybe_process_ipn() { |
|
| 349 | + |
|
| 350 | + // Ensure that this is an IPN request. |
|
| 351 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 356 | + |
|
| 357 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 358 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 359 | + exit; |
|
| 360 | + |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + public function enqueue_scripts() { |
|
| 364 | + |
|
| 365 | + // Fires before adding scripts. |
|
| 366 | + do_action( 'getpaid_enqueue_scripts' ); |
|
| 367 | + |
|
| 368 | + $localize = array(); |
|
| 369 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 370 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
| 371 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
| 372 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 373 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 374 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 375 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 376 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 377 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 378 | + |
|
| 379 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 380 | + |
|
| 381 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 382 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 383 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + public function wpinv_actions() { |
|
| 387 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 388 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | 393 | * Fires an action after verifying that a user can fire them. |
| 394 | - * |
|
| 395 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 396 | - * current user owns the invoice/subscription. |
|
| 394 | + * |
|
| 395 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 396 | + * current user owns the invoice/subscription. |
|
| 397 | 397 | */ |
| 398 | 398 | public function maybe_do_authenticated_action() { |
| 399 | 399 | |
| 400 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 400 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 401 | + |
|
| 402 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 403 | + $data = wp_unslash( $_REQUEST ); |
|
| 404 | + if ( is_user_logged_in() ) { |
|
| 405 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 409 | + |
|
| 410 | + } |
|
| 401 | 411 | |
| 402 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 403 | - $data = wp_unslash( $_REQUEST ); |
|
| 404 | - if ( is_user_logged_in() ) { |
|
| 405 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 406 | - } |
|
| 412 | + } |
|
| 407 | 413 | |
| 408 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 414 | + public function pre_get_posts( $wp_query ) { |
|
| 409 | 415 | |
| 410 | - } |
|
| 416 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 417 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 418 | + } |
|
| 411 | 419 | |
| 420 | + return $wp_query; |
|
| 412 | 421 | } |
| 413 | 422 | |
| 414 | - public function pre_get_posts( $wp_query ) { |
|
| 415 | - |
|
| 416 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 417 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - return $wp_query; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Register widgets |
|
| 425 | - * |
|
| 426 | - */ |
|
| 427 | - public function register_widgets() { |
|
| 428 | - |
|
| 429 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 430 | - // So we disable our widgets when editing a page with UX Builder. |
|
| 431 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 432 | - return; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - $widgets = apply_filters( |
|
| 436 | - 'getpaid_widget_classes', |
|
| 437 | - array( |
|
| 438 | - 'WPInv_Checkout_Widget', |
|
| 439 | - 'WPInv_History_Widget', |
|
| 440 | - 'WPInv_Receipt_Widget', |
|
| 441 | - 'WPInv_Subscriptions_Widget', |
|
| 442 | - 'WPInv_Buy_Item_Widget', |
|
| 443 | - 'WPInv_Messages_Widget', |
|
| 444 | - 'WPInv_GetPaid_Widget' |
|
| 445 | - ) |
|
| 446 | - ); |
|
| 447 | - |
|
| 448 | - foreach ( $widgets as $widget ) { |
|
| 449 | - register_widget( $widget ); |
|
| 450 | - } |
|
| 423 | + /** |
|
| 424 | + * Register widgets |
|
| 425 | + * |
|
| 426 | + */ |
|
| 427 | + public function register_widgets() { |
|
| 428 | + |
|
| 429 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 430 | + // So we disable our widgets when editing a page with UX Builder. |
|
| 431 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 432 | + return; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + $widgets = apply_filters( |
|
| 436 | + 'getpaid_widget_classes', |
|
| 437 | + array( |
|
| 438 | + 'WPInv_Checkout_Widget', |
|
| 439 | + 'WPInv_History_Widget', |
|
| 440 | + 'WPInv_Receipt_Widget', |
|
| 441 | + 'WPInv_Subscriptions_Widget', |
|
| 442 | + 'WPInv_Buy_Item_Widget', |
|
| 443 | + 'WPInv_Messages_Widget', |
|
| 444 | + 'WPInv_GetPaid_Widget' |
|
| 445 | + ) |
|
| 446 | + ); |
|
| 447 | + |
|
| 448 | + foreach ( $widgets as $widget ) { |
|
| 449 | + register_widget( $widget ); |
|
| 450 | + } |
|
| 451 | 451 | |
| 452 | - } |
|
| 452 | + } |
|
| 453 | 453 | |
| 454 | - /** |
|
| 455 | - * Upgrades the database. |
|
| 456 | - * |
|
| 457 | - * @since 2.0.2 |
|
| 458 | - */ |
|
| 459 | - public function maybe_upgrade_database() { |
|
| 454 | + /** |
|
| 455 | + * Upgrades the database. |
|
| 456 | + * |
|
| 457 | + * @since 2.0.2 |
|
| 458 | + */ |
|
| 459 | + public function maybe_upgrade_database() { |
|
| 460 | 460 | |
| 461 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 461 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 462 | 462 | |
| 463 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 464 | - return; |
|
| 465 | - } |
|
| 463 | + if ( $wpi_version == WPINV_VERSION ) { |
|
| 464 | + return; |
|
| 465 | + } |
|
| 466 | 466 | |
| 467 | - $installer = new GetPaid_Installer(); |
|
| 467 | + $installer = new GetPaid_Installer(); |
|
| 468 | 468 | |
| 469 | - if ( empty( $wpi_version ) ) { |
|
| 470 | - return $installer->upgrade_db( 0 ); |
|
| 471 | - } |
|
| 469 | + if ( empty( $wpi_version ) ) { |
|
| 470 | + return $installer->upgrade_db( 0 ); |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - $upgrades = array( |
|
| 474 | - '0.0.5' => '004', |
|
| 475 | - '1.0.3' => '102', |
|
| 476 | - '2.0.0' => '118', |
|
| 477 | - '2.0.8' => '207', |
|
| 478 | - ); |
|
| 473 | + $upgrades = array( |
|
| 474 | + '0.0.5' => '004', |
|
| 475 | + '1.0.3' => '102', |
|
| 476 | + '2.0.0' => '118', |
|
| 477 | + '2.0.8' => '207', |
|
| 478 | + ); |
|
| 479 | 479 | |
| 480 | - foreach ( $upgrades as $key => $method ) { |
|
| 480 | + foreach ( $upgrades as $key => $method ) { |
|
| 481 | 481 | |
| 482 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 483 | - return $installer->upgrade_db( $method ); |
|
| 484 | - } |
|
| 482 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 483 | + return $installer->upgrade_db( $method ); |
|
| 484 | + } |
|
| 485 | 485 | |
| 486 | - } |
|
| 486 | + } |
|
| 487 | 487 | |
| 488 | - } |
|
| 488 | + } |
|
| 489 | 489 | |
| 490 | - /** |
|
| 491 | - * Flushes the permalinks if needed. |
|
| 492 | - * |
|
| 493 | - * @since 2.0.8 |
|
| 494 | - */ |
|
| 495 | - public function maybe_flush_permalinks() { |
|
| 490 | + /** |
|
| 491 | + * Flushes the permalinks if needed. |
|
| 492 | + * |
|
| 493 | + * @since 2.0.8 |
|
| 494 | + */ |
|
| 495 | + public function maybe_flush_permalinks() { |
|
| 496 | 496 | |
| 497 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 497 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 498 | 498 | |
| 499 | - if ( ! empty( $flush ) ) { |
|
| 500 | - flush_rewrite_rules(); |
|
| 501 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 502 | - } |
|
| 499 | + if ( ! empty( $flush ) ) { |
|
| 500 | + flush_rewrite_rules(); |
|
| 501 | + delete_option( 'wpinv_flush_permalinks' ); |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - } |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - /** |
|
| 507 | - * Remove our pages from yoast sitemaps. |
|
| 508 | - * |
|
| 509 | - * @since 1.0.19 |
|
| 510 | - * @param int[] $excluded_posts_ids |
|
| 511 | - */ |
|
| 512 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 506 | + /** |
|
| 507 | + * Remove our pages from yoast sitemaps. |
|
| 508 | + * |
|
| 509 | + * @since 1.0.19 |
|
| 510 | + * @param int[] $excluded_posts_ids |
|
| 511 | + */ |
|
| 512 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 513 | 513 | |
| 514 | - // Ensure that we have an array. |
|
| 515 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 516 | - $excluded_posts_ids = array(); |
|
| 517 | - } |
|
| 514 | + // Ensure that we have an array. |
|
| 515 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 516 | + $excluded_posts_ids = array(); |
|
| 517 | + } |
|
| 518 | 518 | |
| 519 | - // Prepare our pages. |
|
| 520 | - $our_pages = array(); |
|
| 519 | + // Prepare our pages. |
|
| 520 | + $our_pages = array(); |
|
| 521 | 521 | |
| 522 | - // Checkout page. |
|
| 523 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 522 | + // Checkout page. |
|
| 523 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 524 | 524 | |
| 525 | - // Success page. |
|
| 526 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 525 | + // Success page. |
|
| 526 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 527 | 527 | |
| 528 | - // Failure page. |
|
| 529 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 528 | + // Failure page. |
|
| 529 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 530 | 530 | |
| 531 | - // History page. |
|
| 532 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 531 | + // History page. |
|
| 532 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 533 | 533 | |
| 534 | - // Subscriptions page. |
|
| 535 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 534 | + // Subscriptions page. |
|
| 535 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 536 | 536 | |
| 537 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 537 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 538 | 538 | |
| 539 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 540 | - return array_unique( $excluded_posts_ids ); |
|
| 539 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 540 | + return array_unique( $excluded_posts_ids ); |
|
| 541 | 541 | |
| 542 | - } |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - /** |
|
| 545 | - * Displays additional footer code. |
|
| 546 | - * |
|
| 547 | - * @since 2.0.0 |
|
| 548 | - */ |
|
| 549 | - public function wp_footer() { |
|
| 550 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 551 | - } |
|
| 544 | + /** |
|
| 545 | + * Displays additional footer code. |
|
| 546 | + * |
|
| 547 | + * @since 2.0.0 |
|
| 548 | + */ |
|
| 549 | + public function wp_footer() { |
|
| 550 | + wpinv_get_template( 'frontend-footer.php' ); |
|
| 551 | + } |
|
| 552 | 552 | |
| 553 | - /** |
|
| 554 | - * Displays additional header code. |
|
| 555 | - * |
|
| 556 | - * @since 2.0.0 |
|
| 557 | - */ |
|
| 558 | - public function wp_head() { |
|
| 559 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 560 | - } |
|
| 553 | + /** |
|
| 554 | + * Displays additional header code. |
|
| 555 | + * |
|
| 556 | + * @since 2.0.0 |
|
| 557 | + */ |
|
| 558 | + public function wp_head() { |
|
| 559 | + wpinv_get_template( 'frontend-head.php' ); |
|
| 560 | + } |
|
| 561 | 561 | |
| 562 | - /** |
|
| 563 | - * Custom query vars. |
|
| 564 | - * |
|
| 565 | - */ |
|
| 566 | - public function custom_query_vars( $vars ) { |
|
| 562 | + /** |
|
| 563 | + * Custom query vars. |
|
| 564 | + * |
|
| 565 | + */ |
|
| 566 | + public function custom_query_vars( $vars ) { |
|
| 567 | 567 | $vars[] = 'getpaid-ipn'; |
| 568 | 568 | return $vars; |
| 569 | - } |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | - /** |
|
| 572 | - * Add rewrite tags and rules. |
|
| 573 | - * |
|
| 574 | - */ |
|
| 575 | - public function add_rewrite_rule() { |
|
| 571 | + /** |
|
| 572 | + * Add rewrite tags and rules. |
|
| 573 | + * |
|
| 574 | + */ |
|
| 575 | + public function add_rewrite_rule() { |
|
| 576 | 576 | $tag = 'getpaid-ipn'; |
| 577 | 577 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
| 578 | 578 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' ); |
| 579 | - } |
|
| 579 | + } |
|
| 580 | 580 | |
| 581 | - /** |
|
| 582 | - * Processes non-query string ipns. |
|
| 583 | - * |
|
| 584 | - */ |
|
| 585 | - public function maybe_process_new_ipn( $query ) { |
|
| 581 | + /** |
|
| 582 | + * Processes non-query string ipns. |
|
| 583 | + * |
|
| 584 | + */ |
|
| 585 | + public function maybe_process_new_ipn( $query ) { |
|
| 586 | 586 | |
| 587 | 587 | if ( is_admin() || ! $query->is_main_query() ) { |
| 588 | 588 | return; |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 591 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 592 | 592 | |
| 593 | 593 | if ( ! empty( $gateway ) ){ |
| 594 | 594 | |
| 595 | - $gateway = sanitize_text_field( $gateway ); |
|
| 596 | - nocache_headers(); |
|
| 597 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 598 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 599 | - exit; |
|
| 595 | + $gateway = sanitize_text_field( $gateway ); |
|
| 596 | + nocache_headers(); |
|
| 597 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 598 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 599 | + exit; |
|
| 600 | 600 | |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | - } |
|
| 603 | + } |
|
| 604 | 604 | |
| 605 | 605 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | - exit; // Exit if accessed directly |
|
| 11 | + exit; // Exit if accessed directly |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | class GetPaid_Meta_Box_Item_Details { |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Output the metabox. |
|
| 21 | - * |
|
| 22 | - * @param WP_Post $post |
|
| 23 | - */ |
|
| 20 | + * Output the metabox. |
|
| 21 | + * |
|
| 22 | + * @param WP_Post $post |
|
| 23 | + */ |
|
| 24 | 24 | public static function output( $post ) { |
| 25 | 25 | |
| 26 | 26 | // Prepare the item. |
@@ -270,35 +270,35 @@ discard block |
||
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | - * Save meta box data. |
|
| 274 | - * |
|
| 275 | - * @param int $post_id |
|
| 276 | - */ |
|
| 277 | - public static function save( $post_id ) { |
|
| 273 | + * Save meta box data. |
|
| 274 | + * |
|
| 275 | + * @param int $post_id |
|
| 276 | + */ |
|
| 277 | + public static function save( $post_id ) { |
|
| 278 | 278 | |
| 279 | 279 | // Prepare the item. |
| 280 | 280 | $item = new WPInv_Item( $post_id ); |
| 281 | 281 | |
| 282 | 282 | // Load new data. |
| 283 | 283 | $item->set_props( |
| 284 | - array( |
|
| 285 | - 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
| 286 | - 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
| 287 | - 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
| 288 | - 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
| 289 | - 'is_dynamic_pricing' => isset( $_POST['wpinv_name_your_price'] ), |
|
| 284 | + array( |
|
| 285 | + 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
| 286 | + 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
| 287 | + 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
| 288 | + 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
| 289 | + 'is_dynamic_pricing' => isset( $_POST['wpinv_name_your_price'] ), |
|
| 290 | 290 | 'minimum_price' => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null, |
| 291 | - 'is_recurring' => isset( $_POST['wpinv_is_recurring'] ), |
|
| 292 | - 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
| 293 | - 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
| 294 | - 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
| 295 | - 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
| 296 | - 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
| 297 | - 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
| 298 | - ) |
|
| 291 | + 'is_recurring' => isset( $_POST['wpinv_is_recurring'] ), |
|
| 292 | + 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
| 293 | + 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
| 294 | + 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
| 295 | + 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
| 296 | + 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
| 297 | + 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
| 298 | + ) |
|
| 299 | 299 | ); |
| 300 | 300 | |
| 301 | - $item->save(); |
|
| 302 | - do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
| 303 | - } |
|
| 301 | + $item->save(); |
|
| 302 | + do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
| 303 | + } |
|
| 304 | 304 | } |
@@ -12,80 +12,80 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission items. |
|
| 17 | - * @var GetPaid_Form_Item[] |
|
| 18 | - */ |
|
| 19 | - public $items = array(); |
|
| 15 | + /** |
|
| 16 | + * Submission items. |
|
| 17 | + * @var GetPaid_Form_Item[] |
|
| 18 | + */ |
|
| 19 | + public $items = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $data = $submission->get_data(); |
|
| 29 | + $payment_form = $submission->get_payment_form(); |
|
| 30 | + |
|
| 31 | + // Prepare the selected items. |
|
| 32 | + $selected_items = array(); |
|
| 33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // For default forms, ensure that an item has been set. |
|
| 38 | + if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) { |
|
| 39 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 40 | + $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // Process each individual item. |
|
| 44 | + foreach ( $payment_form->get_items() as $item ) { |
|
| 45 | + $this->process_item( $item, $selected_items, $submission ); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + } |
|
| 20 | 49 | |
| 21 | 50 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $data = $submission->get_data(); |
|
| 29 | - $payment_form = $submission->get_payment_form(); |
|
| 30 | - |
|
| 31 | - // Prepare the selected items. |
|
| 32 | - $selected_items = array(); |
|
| 33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // For default forms, ensure that an item has been set. |
|
| 38 | - if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) { |
|
| 39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - // Process each individual item. |
|
| 44 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 45 | - $this->process_item( $item, $selected_items, $submission ); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Process a single item. |
|
| 52 | - * |
|
| 53 | - * @param GetPaid_Form_Item $item |
|
| 54 | - * @param array $selected_items |
|
| 55 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 56 | - */ |
|
| 57 | - public function process_item( $item, $selected_items, $submission ) { |
|
| 58 | - |
|
| 59 | - // Abort if this is an optional item and it has not been selected. |
|
| 60 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 61 | - return; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // (maybe) let customers change the quantities and prices. |
|
| 65 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 66 | - |
|
| 67 | - // Maybe change the quantities. |
|
| 68 | - if ( $item->allows_quantities() ) { |
|
| 69 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // Maybe change the price. |
|
| 73 | - if ( $item->user_can_set_their_price() ) { |
|
| 74 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 75 | - |
|
| 76 | - if ( $item->get_minimum_price() > $price ) { |
|
| 77 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $item->set_price( $price ); |
|
| 81 | - |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Save the item. |
|
| 87 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
| 88 | - |
|
| 89 | - } |
|
| 51 | + * Process a single item. |
|
| 52 | + * |
|
| 53 | + * @param GetPaid_Form_Item $item |
|
| 54 | + * @param array $selected_items |
|
| 55 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 56 | + */ |
|
| 57 | + public function process_item( $item, $selected_items, $submission ) { |
|
| 58 | + |
|
| 59 | + // Abort if this is an optional item and it has not been selected. |
|
| 60 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // (maybe) let customers change the quantities and prices. |
|
| 65 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 66 | + |
|
| 67 | + // Maybe change the quantities. |
|
| 68 | + if ( $item->allows_quantities() ) { |
|
| 69 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // Maybe change the price. |
|
| 73 | + if ( $item->user_can_set_their_price() ) { |
|
| 74 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 75 | + |
|
| 76 | + if ( $item->get_minimum_price() > $price ) { |
|
| 77 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $item->set_price( $price ); |
|
| 81 | + |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Save the item. |
|
| 87 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |
@@ -12,114 +12,114 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * The fee validation error. |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - public $fee_error; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Submission fees. |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $fees = array(); |
|
| 15 | + /** |
|
| 16 | + * The fee validation error. |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + public $fee_error; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Submission fees. |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $fees = array(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Process any existing invoice fees. |
|
| 35 | + if ( $submission->has_invoice() ) { |
|
| 36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Process price fields. |
|
| 40 | + $data = $submission->get_data(); |
|
| 41 | + $payment_form = $submission->get_payment_form(); |
|
| 42 | + |
|
| 43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | + |
|
| 45 | + if ( 'price_input' == $element['type'] ) { |
|
| 46 | + $this->process_price_input( $element, $data, $submission ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ( 'price_select' == $element['type'] ) { |
|
| 50 | + $this->process_price_select( $element, $data ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Process a price input field. |
|
| 59 | + * |
|
| 60 | + * @param array $element |
|
| 61 | + * @param array $data |
|
| 62 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 63 | + */ |
|
| 64 | + public function process_price_input( $element, $data, $submission ) { |
|
| 65 | + |
|
| 66 | + // Abort if not passed. |
|
| 67 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 72 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 73 | + |
|
| 74 | + if ( $amount < $minimum ) { |
|
| 75 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $this->fees[ $element['label'] ] = array( |
|
| 79 | + 'name' => $element['label'], |
|
| 80 | + 'initial_fee' => $amount, |
|
| 81 | + 'recurring_fee' => 0, |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + } |
|
| 26 | 85 | |
| 27 | 86 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Process any existing invoice fees. |
|
| 35 | - if ( $submission->has_invoice() ) { |
|
| 36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Process price fields. |
|
| 40 | - $data = $submission->get_data(); |
|
| 41 | - $payment_form = $submission->get_payment_form(); |
|
| 42 | - |
|
| 43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | - |
|
| 45 | - if ( 'price_input' == $element['type'] ) { |
|
| 46 | - $this->process_price_input( $element, $data, $submission ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ( 'price_select' == $element['type'] ) { |
|
| 50 | - $this->process_price_select( $element, $data ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Process a price input field. |
|
| 59 | - * |
|
| 60 | - * @param array $element |
|
| 61 | - * @param array $data |
|
| 62 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 63 | - */ |
|
| 64 | - public function process_price_input( $element, $data, $submission ) { |
|
| 65 | - |
|
| 66 | - // Abort if not passed. |
|
| 67 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 68 | - return; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 73 | - |
|
| 74 | - if ( $amount < $minimum ) { |
|
| 75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $this->fees[ $element['label'] ] = array( |
|
| 79 | - 'name' => $element['label'], |
|
| 80 | - 'initial_fee' => $amount, |
|
| 81 | - 'recurring_fee' => 0, |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Process a price select field. |
|
| 88 | - * |
|
| 89 | - * @param array $element |
|
| 90 | - * @param array $data |
|
| 91 | - */ |
|
| 92 | - public function process_price_select( $element, $data ) { |
|
| 93 | - |
|
| 94 | - // Abort if not passed. |
|
| 95 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 100 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
| 101 | - $total = 0; |
|
| 102 | - $sub_labels = array(); |
|
| 103 | - |
|
| 104 | - foreach ( $selected as $price ) { |
|
| 105 | - |
|
| 106 | - if ( ! isset( $options[ $price ] ) ) { |
|
| 107 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $price = explode( '|', $price ); |
|
| 111 | - |
|
| 112 | - $sub_labels[] = $price[0]; |
|
| 113 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $this->fees[ $element['label'] ] = array( |
|
| 117 | - 'name' => $element['label'], |
|
| 118 | - 'initial_fee' => $total, |
|
| 119 | - 'recurring_fee' => 0, |
|
| 120 | - 'description' => implode( ', ', $sub_labels ), |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - } |
|
| 87 | + * Process a price select field. |
|
| 88 | + * |
|
| 89 | + * @param array $element |
|
| 90 | + * @param array $data |
|
| 91 | + */ |
|
| 92 | + public function process_price_select( $element, $data ) { |
|
| 93 | + |
|
| 94 | + // Abort if not passed. |
|
| 95 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 100 | + $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
| 101 | + $total = 0; |
|
| 102 | + $sub_labels = array(); |
|
| 103 | + |
|
| 104 | + foreach ( $selected as $price ) { |
|
| 105 | + |
|
| 106 | + if ( ! isset( $options[ $price ] ) ) { |
|
| 107 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $price = explode( '|', $price ); |
|
| 111 | + |
|
| 112 | + $sub_labels[] = $price[0]; |
|
| 113 | + $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $this->fees[ $element['label'] ] = array( |
|
| 117 | + 'name' => $element['label'], |
|
| 118 | + 'initial_fee' => $total, |
|
| 119 | + 'recurring_fee' => 0, |
|
| 120 | + 'description' => implode( ', ', $sub_labels ), |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | } |