@@ -14,619 +14,619 @@ |
||
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 Localisation files. |
|
158 | - * |
|
159 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | - * |
|
161 | - * Locales found in: |
|
162 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - */ |
|
167 | - public function load_textdomain() { |
|
168 | - |
|
169 | - load_plugin_textdomain( |
|
170 | - 'invoicing', |
|
171 | - false, |
|
172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | - ); |
|
174 | - |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Include required core files used in admin and on the frontend. |
|
179 | - */ |
|
180 | - public function includes() { |
|
181 | - |
|
182 | - // Start with the settings. |
|
183 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
184 | - |
|
185 | - // Packages/libraries. |
|
186 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
188 | - |
|
189 | - // Load functions. |
|
190 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
205 | - |
|
206 | - // Register autoloader. |
|
207 | - try { |
|
208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | - } catch ( Exception $e ) { |
|
210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | - } |
|
212 | - |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
234 | - |
|
235 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | - GetPaid_Post_Types_Admin::init(); |
|
237 | - |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
244 | - // load the user class only on the users.php page |
|
245 | - global $pagenow; |
|
246 | - if($pagenow=='users.php'){ |
|
247 | - new WPInv_Admin_Users(); |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - // Register cli commands |
|
252 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
253 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
254 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
255 | - } |
|
256 | - |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Class autoloader |
|
261 | - * |
|
262 | - * @param string $class_name The name of the class to load. |
|
263 | - * @access public |
|
264 | - * @since 1.0.19 |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - public function autoload( $class_name ) { |
|
268 | - |
|
269 | - // Normalize the class name... |
|
270 | - $class_name = strtolower( $class_name ); |
|
271 | - |
|
272 | - // ... and make sure it is our class. |
|
273 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | - return; |
|
275 | - } |
|
276 | - |
|
277 | - // Next, prepare the file name from the class. |
|
278 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | - |
|
280 | - // Base path of the classes. |
|
281 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | - |
|
283 | - // And an array of possible locations in order of importance. |
|
284 | - $locations = array( |
|
285 | - "$plugin_path/includes", |
|
286 | - "$plugin_path/includes/data-stores", |
|
287 | - "$plugin_path/includes/gateways", |
|
288 | - "$plugin_path/includes/payments", |
|
289 | - "$plugin_path/includes/geolocation", |
|
290 | - "$plugin_path/includes/reports", |
|
291 | - "$plugin_path/includes/api", |
|
292 | - "$plugin_path/includes/admin", |
|
293 | - "$plugin_path/includes/admin/meta-boxes", |
|
294 | - ); |
|
295 | - |
|
296 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | - |
|
298 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
299 | - include trailingslashit( $location ) . $file_name; |
|
300 | - break; |
|
301 | - } |
|
302 | - |
|
303 | - } |
|
304 | - |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Inits hooks etc. |
|
309 | - */ |
|
310 | - public function init() { |
|
311 | - |
|
312 | - // Fires before getpaid inits. |
|
313 | - do_action( 'before_getpaid_init', $this ); |
|
314 | - |
|
315 | - // Maybe upgrade. |
|
316 | - $this->maybe_upgrade_database(); |
|
317 | - |
|
318 | - // Load default gateways. |
|
319 | - $gateways = apply_filters( |
|
320 | - 'getpaid_default_gateways', |
|
321 | - array( |
|
322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | - ) |
|
328 | - ); |
|
329 | - |
|
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
332 | - } |
|
333 | - |
|
334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | - GetPaid_Installer::rename_gateways_label(); |
|
336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | - } |
|
338 | - |
|
339 | - // Fires after getpaid inits. |
|
340 | - do_action( 'getpaid_init', $this ); |
|
341 | - |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Checks if this is an IPN request and processes it. |
|
346 | - */ |
|
347 | - public function maybe_process_ipn() { |
|
348 | - |
|
349 | - // Ensure that this is an IPN request. |
|
350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | - return; |
|
352 | - } |
|
353 | - |
|
354 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
355 | - |
|
356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | - exit; |
|
359 | - |
|
360 | - } |
|
361 | - |
|
362 | - public function enqueue_scripts() { |
|
363 | - |
|
364 | - // Fires before adding scripts. |
|
365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
366 | - |
|
367 | - $localize = array(); |
|
368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | - |
|
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | - |
|
380 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
383 | - } |
|
384 | - |
|
385 | - public function wpinv_actions() { |
|
386 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | - } |
|
389 | - |
|
390 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
391 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
392 | - } |
|
393 | - } |
|
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 Localisation files. |
|
158 | + * |
|
159 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | + * |
|
161 | + * Locales found in: |
|
162 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + */ |
|
167 | + public function load_textdomain() { |
|
168 | + |
|
169 | + load_plugin_textdomain( |
|
170 | + 'invoicing', |
|
171 | + false, |
|
172 | + plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | + ); |
|
174 | + |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Include required core files used in admin and on the frontend. |
|
179 | + */ |
|
180 | + public function includes() { |
|
181 | + |
|
182 | + // Start with the settings. |
|
183 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
184 | + |
|
185 | + // Packages/libraries. |
|
186 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
187 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
188 | + |
|
189 | + // Load functions. |
|
190 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
205 | + |
|
206 | + // Register autoloader. |
|
207 | + try { |
|
208 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | + } catch ( Exception $e ) { |
|
210 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | + } |
|
212 | + |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
216 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
219 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
234 | + |
|
235 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | + GetPaid_Post_Types_Admin::init(); |
|
237 | + |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
244 | + // load the user class only on the users.php page |
|
245 | + global $pagenow; |
|
246 | + if($pagenow=='users.php'){ |
|
247 | + new WPInv_Admin_Users(); |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + // Register cli commands |
|
252 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
253 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
254 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
255 | + } |
|
256 | + |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Class autoloader |
|
261 | + * |
|
262 | + * @param string $class_name The name of the class to load. |
|
263 | + * @access public |
|
264 | + * @since 1.0.19 |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + public function autoload( $class_name ) { |
|
268 | + |
|
269 | + // Normalize the class name... |
|
270 | + $class_name = strtolower( $class_name ); |
|
271 | + |
|
272 | + // ... and make sure it is our class. |
|
273 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | + return; |
|
275 | + } |
|
276 | + |
|
277 | + // Next, prepare the file name from the class. |
|
278 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | + |
|
280 | + // Base path of the classes. |
|
281 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | + |
|
283 | + // And an array of possible locations in order of importance. |
|
284 | + $locations = array( |
|
285 | + "$plugin_path/includes", |
|
286 | + "$plugin_path/includes/data-stores", |
|
287 | + "$plugin_path/includes/gateways", |
|
288 | + "$plugin_path/includes/payments", |
|
289 | + "$plugin_path/includes/geolocation", |
|
290 | + "$plugin_path/includes/reports", |
|
291 | + "$plugin_path/includes/api", |
|
292 | + "$plugin_path/includes/admin", |
|
293 | + "$plugin_path/includes/admin/meta-boxes", |
|
294 | + ); |
|
295 | + |
|
296 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | + |
|
298 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
299 | + include trailingslashit( $location ) . $file_name; |
|
300 | + break; |
|
301 | + } |
|
302 | + |
|
303 | + } |
|
304 | + |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Inits hooks etc. |
|
309 | + */ |
|
310 | + public function init() { |
|
311 | + |
|
312 | + // Fires before getpaid inits. |
|
313 | + do_action( 'before_getpaid_init', $this ); |
|
314 | + |
|
315 | + // Maybe upgrade. |
|
316 | + $this->maybe_upgrade_database(); |
|
317 | + |
|
318 | + // Load default gateways. |
|
319 | + $gateways = apply_filters( |
|
320 | + 'getpaid_default_gateways', |
|
321 | + array( |
|
322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | + ) |
|
328 | + ); |
|
329 | + |
|
330 | + foreach ( $gateways as $id => $class ) { |
|
331 | + $this->gateways[ $id ] = new $class(); |
|
332 | + } |
|
333 | + |
|
334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | + GetPaid_Installer::rename_gateways_label(); |
|
336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | + } |
|
338 | + |
|
339 | + // Fires after getpaid inits. |
|
340 | + do_action( 'getpaid_init', $this ); |
|
394 | 341 | |
395 | - /** |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Checks if this is an IPN request and processes it. |
|
346 | + */ |
|
347 | + public function maybe_process_ipn() { |
|
348 | + |
|
349 | + // Ensure that this is an IPN request. |
|
350 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | + return; |
|
352 | + } |
|
353 | + |
|
354 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
355 | + |
|
356 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | + exit; |
|
359 | + |
|
360 | + } |
|
361 | + |
|
362 | + public function enqueue_scripts() { |
|
363 | + |
|
364 | + // Fires before adding scripts. |
|
365 | + do_action( 'getpaid_enqueue_scripts' ); |
|
366 | + |
|
367 | + $localize = array(); |
|
368 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | + |
|
378 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | + |
|
380 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
383 | + } |
|
384 | + |
|
385 | + public function wpinv_actions() { |
|
386 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | + } |
|
389 | + |
|
390 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
391 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | 396 | * Fires an action after verifying that a user can fire them. |
397 | - * |
|
398 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
399 | - * current user owns the invoice/subscription. |
|
397 | + * |
|
398 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
399 | + * current user owns the invoice/subscription. |
|
400 | 400 | */ |
401 | 401 | public function maybe_do_authenticated_action() { |
402 | 402 | |
403 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
403 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
404 | + |
|
405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | + $data = wp_unslash( $_REQUEST ); |
|
407 | + if ( is_user_logged_in() ) { |
|
408 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
409 | + } |
|
410 | + |
|
411 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
412 | + |
|
413 | + } |
|
414 | + |
|
415 | + } |
|
416 | + |
|
417 | + public function pre_get_posts( $wp_query ) { |
|
418 | + |
|
419 | + 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() ) { |
|
420 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
421 | + } |
|
422 | + |
|
423 | + return $wp_query; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * Register widgets |
|
428 | + * |
|
429 | + */ |
|
430 | + public function register_widgets() { |
|
431 | + global $pagenow; |
|
432 | + |
|
433 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
434 | + // So we disable our widgets when editing a page with UX Builder. |
|
435 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
436 | + return; |
|
437 | + } |
|
438 | + |
|
439 | + $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
440 | + |
|
441 | + if ( is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
442 | + // don't initiate in these conditions. |
|
443 | + }else{ |
|
444 | + |
|
445 | + // Only load allowed widgets. |
|
446 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
447 | + $widgets = apply_filters( |
|
448 | + 'getpaid_widget_classes', |
|
449 | + array( |
|
450 | + 'WPInv_Checkout_Widget', |
|
451 | + 'WPInv_History_Widget', |
|
452 | + 'WPInv_Receipt_Widget', |
|
453 | + 'WPInv_Subscriptions_Widget', |
|
454 | + 'WPInv_Buy_Item_Widget', |
|
455 | + 'WPInv_Messages_Widget', |
|
456 | + 'WPInv_GetPaid_Widget' |
|
457 | + ) |
|
458 | + ); |
|
459 | + |
|
460 | + // For each widget... |
|
461 | + foreach ( $widgets as $widget ) { |
|
462 | + |
|
463 | + // Abort early if it is excluded for this page. |
|
464 | + if ( in_array( $widget, $exclude ) ) { |
|
465 | + continue; |
|
466 | + } |
|
467 | + |
|
468 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
469 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
470 | + register_widget( $widget ); |
|
471 | + } else { |
|
472 | + new $widget(); |
|
473 | + } |
|
474 | + |
|
475 | + } |
|
476 | + |
|
477 | + } |
|
478 | + |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Upgrades the database. |
|
483 | + * |
|
484 | + * @since 2.0.2 |
|
485 | + */ |
|
486 | + public function maybe_upgrade_database() { |
|
404 | 487 | |
405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | - $data = wp_unslash( $_REQUEST ); |
|
407 | - if ( is_user_logged_in() ) { |
|
408 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
409 | - } |
|
488 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
410 | 489 | |
411 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
490 | + if ( $wpi_version == WPINV_VERSION ) { |
|
491 | + return; |
|
492 | + } |
|
412 | 493 | |
413 | - } |
|
494 | + $installer = new GetPaid_Installer(); |
|
495 | + |
|
496 | + if ( empty( $wpi_version ) ) { |
|
497 | + return $installer->upgrade_db( 0 ); |
|
498 | + } |
|
499 | + |
|
500 | + $upgrades = array( |
|
501 | + '0.0.5' => '004', |
|
502 | + '1.0.3' => '102', |
|
503 | + '2.0.0' => '118', |
|
504 | + '2.0.8' => '207', |
|
505 | + ); |
|
506 | + |
|
507 | + foreach ( $upgrades as $key => $method ) { |
|
508 | + |
|
509 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
510 | + return $installer->upgrade_db( $method ); |
|
511 | + } |
|
512 | + |
|
513 | + } |
|
414 | 514 | |
415 | 515 | } |
416 | 516 | |
417 | - public function pre_get_posts( $wp_query ) { |
|
517 | + /** |
|
518 | + * Flushes the permalinks if needed. |
|
519 | + * |
|
520 | + * @since 2.0.8 |
|
521 | + */ |
|
522 | + public function maybe_flush_permalinks() { |
|
418 | 523 | |
419 | - 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() ) { |
|
420 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
421 | - } |
|
422 | - |
|
423 | - return $wp_query; |
|
424 | - } |
|
524 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
425 | 525 | |
426 | - /** |
|
427 | - * Register widgets |
|
428 | - * |
|
429 | - */ |
|
430 | - public function register_widgets() { |
|
431 | - global $pagenow; |
|
526 | + if ( ! empty( $flush ) ) { |
|
527 | + flush_rewrite_rules(); |
|
528 | + delete_option( 'wpinv_flush_permalinks' ); |
|
529 | + } |
|
432 | 530 | |
433 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
434 | - // So we disable our widgets when editing a page with UX Builder. |
|
435 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
436 | - return; |
|
437 | - } |
|
438 | - |
|
439 | - $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
440 | - |
|
441 | - if ( is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
442 | - // don't initiate in these conditions. |
|
443 | - }else{ |
|
444 | - |
|
445 | - // Only load allowed widgets. |
|
446 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
447 | - $widgets = apply_filters( |
|
448 | - 'getpaid_widget_classes', |
|
449 | - array( |
|
450 | - 'WPInv_Checkout_Widget', |
|
451 | - 'WPInv_History_Widget', |
|
452 | - 'WPInv_Receipt_Widget', |
|
453 | - 'WPInv_Subscriptions_Widget', |
|
454 | - 'WPInv_Buy_Item_Widget', |
|
455 | - 'WPInv_Messages_Widget', |
|
456 | - 'WPInv_GetPaid_Widget' |
|
457 | - ) |
|
458 | - ); |
|
459 | - |
|
460 | - // For each widget... |
|
461 | - foreach ( $widgets as $widget ) { |
|
531 | + } |
|
462 | 532 | |
463 | - // Abort early if it is excluded for this page. |
|
464 | - if ( in_array( $widget, $exclude ) ) { |
|
465 | - continue; |
|
466 | - } |
|
533 | + /** |
|
534 | + * Remove our pages from yoast sitemaps. |
|
535 | + * |
|
536 | + * @since 1.0.19 |
|
537 | + * @param int[] $excluded_posts_ids |
|
538 | + */ |
|
539 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
467 | 540 | |
468 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
469 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
470 | - register_widget( $widget ); |
|
471 | - } else { |
|
472 | - new $widget(); |
|
473 | - } |
|
541 | + // Ensure that we have an array. |
|
542 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
543 | + $excluded_posts_ids = array(); |
|
544 | + } |
|
474 | 545 | |
475 | - } |
|
546 | + // Prepare our pages. |
|
547 | + $our_pages = array(); |
|
476 | 548 | |
477 | - } |
|
549 | + // Checkout page. |
|
550 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
478 | 551 | |
479 | - } |
|
552 | + // Success page. |
|
553 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
480 | 554 | |
481 | - /** |
|
482 | - * Upgrades the database. |
|
483 | - * |
|
484 | - * @since 2.0.2 |
|
485 | - */ |
|
486 | - public function maybe_upgrade_database() { |
|
487 | - |
|
488 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
489 | - |
|
490 | - if ( $wpi_version == WPINV_VERSION ) { |
|
491 | - return; |
|
492 | - } |
|
493 | - |
|
494 | - $installer = new GetPaid_Installer(); |
|
495 | - |
|
496 | - if ( empty( $wpi_version ) ) { |
|
497 | - return $installer->upgrade_db( 0 ); |
|
498 | - } |
|
499 | - |
|
500 | - $upgrades = array( |
|
501 | - '0.0.5' => '004', |
|
502 | - '1.0.3' => '102', |
|
503 | - '2.0.0' => '118', |
|
504 | - '2.0.8' => '207', |
|
505 | - ); |
|
506 | - |
|
507 | - foreach ( $upgrades as $key => $method ) { |
|
508 | - |
|
509 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
510 | - return $installer->upgrade_db( $method ); |
|
511 | - } |
|
512 | - |
|
513 | - } |
|
514 | - |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Flushes the permalinks if needed. |
|
519 | - * |
|
520 | - * @since 2.0.8 |
|
521 | - */ |
|
522 | - public function maybe_flush_permalinks() { |
|
523 | - |
|
524 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
525 | - |
|
526 | - if ( ! empty( $flush ) ) { |
|
527 | - flush_rewrite_rules(); |
|
528 | - delete_option( 'wpinv_flush_permalinks' ); |
|
529 | - } |
|
530 | - |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Remove our pages from yoast sitemaps. |
|
535 | - * |
|
536 | - * @since 1.0.19 |
|
537 | - * @param int[] $excluded_posts_ids |
|
538 | - */ |
|
539 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
540 | - |
|
541 | - // Ensure that we have an array. |
|
542 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
543 | - $excluded_posts_ids = array(); |
|
544 | - } |
|
545 | - |
|
546 | - // Prepare our pages. |
|
547 | - $our_pages = array(); |
|
548 | - |
|
549 | - // Checkout page. |
|
550 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
551 | - |
|
552 | - // Success page. |
|
553 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
554 | - |
|
555 | - // Failure page. |
|
556 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
555 | + // Failure page. |
|
556 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
557 | 557 | |
558 | - // History page. |
|
559 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
558 | + // History page. |
|
559 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
560 | 560 | |
561 | - // Subscriptions page. |
|
562 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
561 | + // Subscriptions page. |
|
562 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
563 | 563 | |
564 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
564 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
565 | 565 | |
566 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
567 | - return array_unique( $excluded_posts_ids ); |
|
566 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
567 | + return array_unique( $excluded_posts_ids ); |
|
568 | 568 | |
569 | - } |
|
569 | + } |
|
570 | 570 | |
571 | - /** |
|
572 | - * Displays additional footer code. |
|
573 | - * |
|
574 | - * @since 2.0.0 |
|
575 | - */ |
|
576 | - public function wp_footer() { |
|
577 | - wpinv_get_template( 'frontend-footer.php' ); |
|
578 | - } |
|
571 | + /** |
|
572 | + * Displays additional footer code. |
|
573 | + * |
|
574 | + * @since 2.0.0 |
|
575 | + */ |
|
576 | + public function wp_footer() { |
|
577 | + wpinv_get_template( 'frontend-footer.php' ); |
|
578 | + } |
|
579 | 579 | |
580 | - /** |
|
581 | - * Displays additional header code. |
|
582 | - * |
|
583 | - * @since 2.0.0 |
|
584 | - */ |
|
585 | - public function wp_head() { |
|
586 | - wpinv_get_template( 'frontend-head.php' ); |
|
587 | - } |
|
580 | + /** |
|
581 | + * Displays additional header code. |
|
582 | + * |
|
583 | + * @since 2.0.0 |
|
584 | + */ |
|
585 | + public function wp_head() { |
|
586 | + wpinv_get_template( 'frontend-head.php' ); |
|
587 | + } |
|
588 | 588 | |
589 | - /** |
|
590 | - * Custom query vars. |
|
591 | - * |
|
592 | - */ |
|
593 | - public function custom_query_vars( $vars ) { |
|
589 | + /** |
|
590 | + * Custom query vars. |
|
591 | + * |
|
592 | + */ |
|
593 | + public function custom_query_vars( $vars ) { |
|
594 | 594 | $vars[] = 'getpaid-ipn'; |
595 | 595 | return $vars; |
596 | - } |
|
596 | + } |
|
597 | 597 | |
598 | - /** |
|
599 | - * Add rewrite tags and rules. |
|
600 | - * |
|
601 | - */ |
|
602 | - public function add_rewrite_rule() { |
|
598 | + /** |
|
599 | + * Add rewrite tags and rules. |
|
600 | + * |
|
601 | + */ |
|
602 | + public function add_rewrite_rule() { |
|
603 | 603 | $tag = 'getpaid-ipn'; |
604 | 604 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
605 | 605 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' ); |
606 | - } |
|
606 | + } |
|
607 | 607 | |
608 | - /** |
|
609 | - * Processes non-query string ipns. |
|
610 | - * |
|
611 | - */ |
|
612 | - public function maybe_process_new_ipn( $query ) { |
|
608 | + /** |
|
609 | + * Processes non-query string ipns. |
|
610 | + * |
|
611 | + */ |
|
612 | + public function maybe_process_new_ipn( $query ) { |
|
613 | 613 | |
614 | 614 | if ( is_admin() || ! $query->is_main_query() ) { |
615 | 615 | return; |
616 | 616 | } |
617 | 617 | |
618 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
618 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
619 | 619 | |
620 | 620 | if ( ! empty( $gateway ) ){ |
621 | 621 | |
622 | - $gateway = sanitize_text_field( $gateway ); |
|
623 | - nocache_headers(); |
|
624 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
625 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
626 | - exit; |
|
622 | + $gateway = sanitize_text_field( $gateway ); |
|
623 | + nocache_headers(); |
|
624 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
625 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
626 | + exit; |
|
627 | 627 | |
628 | 628 | } |
629 | 629 | |
630 | - } |
|
630 | + } |
|
631 | 631 | |
632 | 632 | } |
@@ -10,232 +10,232 @@ discard block |
||
10 | 10 | |
11 | 11 | if (!class_exists('RapidAddon')) { |
12 | 12 | |
13 | - class RapidAddon { |
|
14 | - |
|
15 | - public $name; |
|
16 | - public $slug; |
|
17 | - public $fields; |
|
18 | - public $options = array(); |
|
19 | - public $accordions = array(); |
|
20 | - public $image_sections = array(); |
|
21 | - public $import_function; |
|
22 | - public $post_saved_function; |
|
23 | - public $notice_text; |
|
24 | - public $logger = null; |
|
25 | - public $when_to_run = false; |
|
26 | - public $image_options = array( |
|
27 | - 'download_images' => 'yes', |
|
28 | - 'download_featured_delim' => ',', |
|
29 | - 'download_featured_image' => '', |
|
30 | - 'gallery_featured_image' => '', |
|
31 | - 'gallery_featured_delim' => ',', |
|
32 | - 'featured_image' => '', |
|
33 | - 'featured_delim' => ',', |
|
34 | - 'search_existing_images' => 1, |
|
35 | - 'is_featured' => 0, |
|
36 | - 'create_draft' => 'no', |
|
37 | - 'set_image_meta_title' => 0, |
|
38 | - 'image_meta_title_delim' => ',', |
|
39 | - 'image_meta_title' => '', |
|
40 | - 'set_image_meta_caption' => 0, |
|
41 | - 'image_meta_caption_delim' => ',', |
|
42 | - 'image_meta_caption' => '', |
|
43 | - 'set_image_meta_alt' => 0, |
|
44 | - 'image_meta_alt_delim' => ',', |
|
45 | - 'image_meta_alt' => '', |
|
46 | - 'set_image_meta_description' => 0, |
|
47 | - 'image_meta_description_delim' => ',', |
|
48 | - 'image_meta_description_delim_logic' => 'separate', |
|
49 | - 'image_meta_description' => '', |
|
50 | - 'auto_rename_images' => 0, |
|
51 | - 'auto_rename_images_suffix' => '', |
|
52 | - 'auto_set_extension' => 0, |
|
53 | - 'new_extension' => '', |
|
54 | - 'do_not_remove_images' => 1, |
|
13 | + class RapidAddon { |
|
14 | + |
|
15 | + public $name; |
|
16 | + public $slug; |
|
17 | + public $fields; |
|
18 | + public $options = array(); |
|
19 | + public $accordions = array(); |
|
20 | + public $image_sections = array(); |
|
21 | + public $import_function; |
|
22 | + public $post_saved_function; |
|
23 | + public $notice_text; |
|
24 | + public $logger = null; |
|
25 | + public $when_to_run = false; |
|
26 | + public $image_options = array( |
|
27 | + 'download_images' => 'yes', |
|
28 | + 'download_featured_delim' => ',', |
|
29 | + 'download_featured_image' => '', |
|
30 | + 'gallery_featured_image' => '', |
|
31 | + 'gallery_featured_delim' => ',', |
|
32 | + 'featured_image' => '', |
|
33 | + 'featured_delim' => ',', |
|
34 | + 'search_existing_images' => 1, |
|
35 | + 'is_featured' => 0, |
|
36 | + 'create_draft' => 'no', |
|
37 | + 'set_image_meta_title' => 0, |
|
38 | + 'image_meta_title_delim' => ',', |
|
39 | + 'image_meta_title' => '', |
|
40 | + 'set_image_meta_caption' => 0, |
|
41 | + 'image_meta_caption_delim' => ',', |
|
42 | + 'image_meta_caption' => '', |
|
43 | + 'set_image_meta_alt' => 0, |
|
44 | + 'image_meta_alt_delim' => ',', |
|
45 | + 'image_meta_alt' => '', |
|
46 | + 'set_image_meta_description' => 0, |
|
47 | + 'image_meta_description_delim' => ',', |
|
48 | + 'image_meta_description_delim_logic' => 'separate', |
|
49 | + 'image_meta_description' => '', |
|
50 | + 'auto_rename_images' => 0, |
|
51 | + 'auto_rename_images_suffix' => '', |
|
52 | + 'auto_set_extension' => 0, |
|
53 | + 'new_extension' => '', |
|
54 | + 'do_not_remove_images' => 1, |
|
55 | 55 | 'search_existing_images_logic' => 'by_url' |
56 | - ); |
|
56 | + ); |
|
57 | 57 | |
58 | - protected $isWizard = true; |
|
58 | + protected $isWizard = true; |
|
59 | 59 | |
60 | - function __construct($name, $slug) { |
|
61 | - $this->name = $name; |
|
62 | - $this->slug = $slug; |
|
63 | - if (!empty($_GET['id'])){ |
|
64 | - $this->isWizard = false; |
|
65 | - } |
|
60 | + function __construct($name, $slug) { |
|
61 | + $this->name = $name; |
|
62 | + $this->slug = $slug; |
|
63 | + if (!empty($_GET['id'])){ |
|
64 | + $this->isWizard = false; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | |
68 | - function set_import_function($name) { |
|
69 | - $this->import_function = $name; |
|
70 | - } |
|
68 | + function set_import_function($name) { |
|
69 | + $this->import_function = $name; |
|
70 | + } |
|
71 | 71 | |
72 | - function set_post_saved_function($name) { |
|
73 | - $this->post_saved_function = $name; |
|
74 | - } |
|
72 | + function set_post_saved_function($name) { |
|
73 | + $this->post_saved_function = $name; |
|
74 | + } |
|
75 | 75 | |
76 | - function is_active_addon($post_type = null) { |
|
76 | + function is_active_addon($post_type = null) { |
|
77 | 77 | |
78 | - if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
79 | - return false; |
|
80 | - } |
|
78 | + if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
79 | + return false; |
|
80 | + } |
|
81 | 81 | |
82 | - $addon_active = false; |
|
82 | + $addon_active = false; |
|
83 | 83 | |
84 | - if ($post_type !== null) { |
|
85 | - if (@in_array($post_type, $this->active_post_types) or empty($this->active_post_types)) { |
|
86 | - $addon_active = true; |
|
87 | - } |
|
88 | - } |
|
84 | + if ($post_type !== null) { |
|
85 | + if (@in_array($post_type, $this->active_post_types) or empty($this->active_post_types)) { |
|
86 | + $addon_active = true; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - if ($addon_active){ |
|
90 | + if ($addon_active){ |
|
91 | 91 | |
92 | - $current_theme = wp_get_theme(); |
|
92 | + $current_theme = wp_get_theme(); |
|
93 | 93 | |
94 | - $parent_theme = $current_theme->parent(); |
|
94 | + $parent_theme = $current_theme->parent(); |
|
95 | 95 | |
96 | - $theme_name = $current_theme->get('Name'); |
|
96 | + $theme_name = $current_theme->get('Name'); |
|
97 | 97 | |
98 | - $addon_active = (@in_array($theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
|
98 | + $addon_active = (@in_array($theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
|
99 | 99 | |
100 | - if ( ! $addon_active and $parent_theme ){ |
|
101 | - $parent_theme_name = $parent_theme->get('Name'); |
|
102 | - $addon_active = (@in_array($parent_theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
|
100 | + if ( ! $addon_active and $parent_theme ){ |
|
101 | + $parent_theme_name = $parent_theme->get('Name'); |
|
102 | + $addon_active = (@in_array($parent_theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
|
103 | 103 | |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - if ( $addon_active and ! empty($this->active_plugins) ){ |
|
106 | + if ( $addon_active and ! empty($this->active_plugins) ){ |
|
107 | 107 | |
108 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
108 | + include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
109 | 109 | |
110 | - foreach ($this->active_plugins as $plugin) { |
|
111 | - if ( ! is_plugin_active($plugin) ) { |
|
112 | - $addon_active = false; |
|
113 | - break; |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
110 | + foreach ($this->active_plugins as $plugin) { |
|
111 | + if ( ! is_plugin_active($plugin) ) { |
|
112 | + $addon_active = false; |
|
113 | + break; |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | 117 | |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - if ($this->when_to_run == "always") { |
|
121 | - $addon_active = true; |
|
122 | - } |
|
120 | + if ($this->when_to_run == "always") { |
|
121 | + $addon_active = true; |
|
122 | + } |
|
123 | 123 | |
124 | - return apply_filters('rapid_is_active_add_on', $addon_active, $post_type, $this->slug); |
|
125 | - } |
|
124 | + return apply_filters('rapid_is_active_add_on', $addon_active, $post_type, $this->slug); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * |
|
129 | - * Add-On Initialization |
|
130 | - * |
|
131 | - * @param array $conditions - list of supported themes and post types |
|
132 | - * |
|
133 | - */ |
|
134 | - function run($conditions = array()) { |
|
135 | - |
|
136 | - if (empty($conditions)) { |
|
137 | - $this->when_to_run = "always"; |
|
138 | - } |
|
127 | + /** |
|
128 | + * |
|
129 | + * Add-On Initialization |
|
130 | + * |
|
131 | + * @param array $conditions - list of supported themes and post types |
|
132 | + * |
|
133 | + */ |
|
134 | + function run($conditions = array()) { |
|
135 | + |
|
136 | + if (empty($conditions)) { |
|
137 | + $this->when_to_run = "always"; |
|
138 | + } |
|
139 | 139 | |
140 | - @$this->active_post_types = ( ! empty($conditions['post_types'])) ? $conditions['post_types'] : array(); |
|
141 | - @$this->active_themes = ( ! empty($conditions['themes'])) ? $conditions['themes'] : array(); |
|
142 | - @$this->active_plugins = ( ! empty($conditions['plugins'])) ? $conditions['plugins'] : array(); |
|
140 | + @$this->active_post_types = ( ! empty($conditions['post_types'])) ? $conditions['post_types'] : array(); |
|
141 | + @$this->active_themes = ( ! empty($conditions['themes'])) ? $conditions['themes'] : array(); |
|
142 | + @$this->active_plugins = ( ! empty($conditions['plugins'])) ? $conditions['plugins'] : array(); |
|
143 | 143 | |
144 | - add_filter('pmxi_addons', array($this, 'wpai_api_register')); |
|
145 | - add_filter('wp_all_import_addon_parse', array($this, 'wpai_api_parse')); |
|
146 | - add_filter('wp_all_import_addon_import', array($this, 'wpai_api_import')); |
|
147 | - add_filter('wp_all_import_addon_saved_post', array($this, 'wpai_api_post_saved')); |
|
148 | - add_filter('pmxi_options_options', array($this, 'wpai_api_options')); |
|
144 | + add_filter('pmxi_addons', array($this, 'wpai_api_register')); |
|
145 | + add_filter('wp_all_import_addon_parse', array($this, 'wpai_api_parse')); |
|
146 | + add_filter('wp_all_import_addon_import', array($this, 'wpai_api_import')); |
|
147 | + add_filter('wp_all_import_addon_saved_post', array($this, 'wpai_api_post_saved')); |
|
148 | + add_filter('pmxi_options_options', array($this, 'wpai_api_options')); |
|
149 | 149 | add_filter('wp_all_import_image_sections', array($this, 'additional_sections'), 10, 1); |
150 | 150 | add_filter('pmxi_custom_types', array($this, 'filter_post_types'), 10, 2); |
151 | 151 | add_filter('pmxi_post_list_order', array($this,'sort_post_types'), 10, 1); |
152 | 152 | add_filter('wp_all_import_post_type_image', array($this, 'post_type_image'), 10, 1 ); |
153 | - add_action('pmxi_extend_options_featured', array($this, 'wpai_api_metabox'), 10, 2); |
|
153 | + add_action('pmxi_extend_options_featured', array($this, 'wpai_api_metabox'), 10, 2); |
|
154 | 154 | add_action('admin_init', array($this, 'admin_notice_ignore')); |
155 | 155 | } |
156 | 156 | |
157 | - function parse($data) { |
|
157 | + function parse($data) { |
|
158 | 158 | |
159 | - if ( ! $this->is_active_addon($data['import']->options['custom_type'])) return false; |
|
159 | + if ( ! $this->is_active_addon($data['import']->options['custom_type'])) return false; |
|
160 | 160 | |
161 | - $parsedData = $this->helper_parse($data, $this->options_array()); |
|
162 | - return $parsedData; |
|
161 | + $parsedData = $this->helper_parse($data, $this->options_array()); |
|
162 | + return $parsedData; |
|
163 | 163 | |
164 | - } |
|
164 | + } |
|
165 | 165 | |
166 | 166 | |
167 | - function add_field($field_slug, $field_name, $field_type, $enum_values = null, $tooltip = "", $is_html = true, $default_text = '') { |
|
167 | + function add_field($field_slug, $field_name, $field_type, $enum_values = null, $tooltip = "", $is_html = true, $default_text = '') { |
|
168 | 168 | |
169 | - $field = array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug, "is_html" => $is_html, 'default_text' => $default_text); |
|
169 | + $field = array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug, "is_html" => $is_html, 'default_text' => $default_text); |
|
170 | 170 | |
171 | - $this->fields[$field_slug] = $field; |
|
171 | + $this->fields[$field_slug] = $field; |
|
172 | 172 | |
173 | - if ( ! empty($enum_values) ){ |
|
174 | - foreach ($enum_values as $key => $value) { |
|
175 | - if (is_array($value)) |
|
176 | - { |
|
177 | - if ($field['type'] == 'accordion') |
|
178 | - { |
|
179 | - $this->fields[$value['slug']]['is_sub_field'] = true; |
|
180 | - } |
|
181 | - else |
|
182 | - { |
|
183 | - foreach ($value as $n => $param) { |
|
184 | - if (is_array($param) and ! empty($this->fields[$param['slug']])){ |
|
185 | - $this->fields[$param['slug']]['is_sub_field'] = true; |
|
186 | - } |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
191 | - } |
|
173 | + if ( ! empty($enum_values) ){ |
|
174 | + foreach ($enum_values as $key => $value) { |
|
175 | + if (is_array($value)) |
|
176 | + { |
|
177 | + if ($field['type'] == 'accordion') |
|
178 | + { |
|
179 | + $this->fields[$value['slug']]['is_sub_field'] = true; |
|
180 | + } |
|
181 | + else |
|
182 | + { |
|
183 | + foreach ($value as $n => $param) { |
|
184 | + if (is_array($param) and ! empty($this->fields[$param['slug']])){ |
|
185 | + $this->fields[$param['slug']]['is_sub_field'] = true; |
|
186 | + } |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - return $field; |
|
193 | + return $field; |
|
194 | 194 | |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - function add_acf_field($field){ |
|
198 | - $this->fields[$field->post_name] = array( |
|
199 | - 'type' => 'acf', |
|
200 | - 'field_obj' => $field |
|
201 | - ); |
|
202 | - } |
|
197 | + function add_acf_field($field){ |
|
198 | + $this->fields[$field->post_name] = array( |
|
199 | + 'type' => 'acf', |
|
200 | + 'field_obj' => $field |
|
201 | + ); |
|
202 | + } |
|
203 | 203 | |
204 | - private $acfGroups = array(); |
|
204 | + private $acfGroups = array(); |
|
205 | 205 | |
206 | - function use_acf_group($acf_group){ |
|
207 | - $this->add_text( |
|
208 | - '<div class="postbox acf_postbox default acf_signle_group rad4"> |
|
206 | + function use_acf_group($acf_group){ |
|
207 | + $this->add_text( |
|
208 | + '<div class="postbox acf_postbox default acf_signle_group rad4"> |
|
209 | 209 | <h3 class="hndle" style="margin-top:0;"><span>'.$acf_group['title'].'</span></h3> |
210 | 210 | <div class="inside">'); |
211 | - $acf_fields = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field', 'post_parent' => $acf_group['ID'], 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC')); |
|
212 | - if (!empty($acf_fields)){ |
|
213 | - foreach ($acf_fields as $field) { |
|
214 | - $this->add_acf_field($field); |
|
215 | - } |
|
216 | - } |
|
217 | - $this->add_text('</div></div>'); |
|
218 | - $this->acfGroups[] = $acf_group['ID']; |
|
219 | - add_filter('wp_all_import_acf_is_show_group', array($this, 'acf_is_show_group'), 10, 2); |
|
220 | - } |
|
221 | - |
|
222 | - function acf_is_show_group($is_show, $acf_group){ |
|
223 | - return (in_array($acf_group['ID'], $this->acfGroups)) ? false : true; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * |
|
228 | - * Add an option to WP All Import options list |
|
229 | - * |
|
230 | - * @param string $slug - option name |
|
231 | - * @param string $default_value - default option value |
|
232 | - * |
|
233 | - */ |
|
234 | - function add_option($slug, $default_value = ''){ |
|
235 | - $this->options[$slug] = $default_value; |
|
236 | - } |
|
211 | + $acf_fields = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field', 'post_parent' => $acf_group['ID'], 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC')); |
|
212 | + if (!empty($acf_fields)){ |
|
213 | + foreach ($acf_fields as $field) { |
|
214 | + $this->add_acf_field($field); |
|
215 | + } |
|
216 | + } |
|
217 | + $this->add_text('</div></div>'); |
|
218 | + $this->acfGroups[] = $acf_group['ID']; |
|
219 | + add_filter('wp_all_import_acf_is_show_group', array($this, 'acf_is_show_group'), 10, 2); |
|
220 | + } |
|
237 | 221 | |
238 | - function options_array() { |
|
222 | + function acf_is_show_group($is_show, $acf_group){ |
|
223 | + return (in_array($acf_group['ID'], $this->acfGroups)) ? false : true; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * |
|
228 | + * Add an option to WP All Import options list |
|
229 | + * |
|
230 | + * @param string $slug - option name |
|
231 | + * @param string $default_value - default option value |
|
232 | + * |
|
233 | + */ |
|
234 | + function add_option($slug, $default_value = ''){ |
|
235 | + $this->options[$slug] = $default_value; |
|
236 | + } |
|
237 | + |
|
238 | + function options_array() { |
|
239 | 239 | |
240 | 240 | $options_list = array(); |
241 | 241 | |
@@ -255,528 +255,528 @@ discard block |
||
255 | 255 | |
256 | 256 | } |
257 | 257 | |
258 | - if ( ! empty($this->options) ){ |
|
259 | - foreach ($this->options as $slug => $value) { |
|
260 | - $options_arr[$slug] = $value; |
|
261 | - } |
|
262 | - } |
|
258 | + if ( ! empty($this->options) ){ |
|
259 | + foreach ($this->options as $slug => $value) { |
|
260 | + $options_arr[$slug] = $value; |
|
261 | + } |
|
262 | + } |
|
263 | 263 | |
264 | - $options_arr[$this->slug] = $options_list; |
|
265 | - $options_arr['rapid_addon'] = plugin_basename( __FILE__ ); |
|
264 | + $options_arr[$this->slug] = $options_list; |
|
265 | + $options_arr['rapid_addon'] = plugin_basename( __FILE__ ); |
|
266 | 266 | |
267 | - return $options_arr; |
|
267 | + return $options_arr; |
|
268 | 268 | |
269 | - } |
|
269 | + } |
|
270 | 270 | |
271 | - function wpai_api_options($all_options) { |
|
271 | + function wpai_api_options($all_options) { |
|
272 | 272 | |
273 | - $all_options = $all_options + $this->options_array(); |
|
273 | + $all_options = $all_options + $this->options_array(); |
|
274 | 274 | |
275 | - return $all_options; |
|
275 | + return $all_options; |
|
276 | 276 | |
277 | - } |
|
277 | + } |
|
278 | 278 | |
279 | 279 | |
280 | - function wpai_api_register($addons) { |
|
280 | + function wpai_api_register($addons) { |
|
281 | 281 | |
282 | - if (empty($addons[$this->slug])) { |
|
283 | - $addons[$this->slug] = 1; |
|
284 | - } |
|
282 | + if (empty($addons[$this->slug])) { |
|
283 | + $addons[$this->slug] = 1; |
|
284 | + } |
|
285 | 285 | |
286 | - return $addons; |
|
286 | + return $addons; |
|
287 | 287 | |
288 | - } |
|
288 | + } |
|
289 | 289 | |
290 | 290 | |
291 | - function wpai_api_parse($functions) { |
|
291 | + function wpai_api_parse($functions) { |
|
292 | 292 | |
293 | - $functions[$this->slug] = array($this, 'parse'); |
|
294 | - return $functions; |
|
293 | + $functions[$this->slug] = array($this, 'parse'); |
|
294 | + return $functions; |
|
295 | 295 | |
296 | - } |
|
296 | + } |
|
297 | 297 | |
298 | - function wpai_api_post_saved($functions){ |
|
299 | - $functions[$this->slug] = array($this, 'post_saved'); |
|
300 | - return $functions; |
|
301 | - } |
|
298 | + function wpai_api_post_saved($functions){ |
|
299 | + $functions[$this->slug] = array($this, 'post_saved'); |
|
300 | + return $functions; |
|
301 | + } |
|
302 | 302 | |
303 | 303 | |
304 | - function wpai_api_import($functions) { |
|
304 | + function wpai_api_import($functions) { |
|
305 | 305 | |
306 | - $functions[$this->slug] = array($this, 'import'); |
|
307 | - return $functions; |
|
306 | + $functions[$this->slug] = array($this, 'import'); |
|
307 | + return $functions; |
|
308 | 308 | |
309 | - } |
|
309 | + } |
|
310 | 310 | |
311 | - function post_saved( $importData ){ |
|
311 | + function post_saved( $importData ){ |
|
312 | 312 | |
313 | - if (is_callable($this->post_saved_function)) |
|
314 | - call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']); |
|
313 | + if (is_callable($this->post_saved_function)) |
|
314 | + call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']); |
|
315 | 315 | |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | - function import($importData, $parsedData) { |
|
318 | + function import($importData, $parsedData) { |
|
319 | 319 | |
320 | - if (!$this->is_active_addon($importData['post_type'])) { |
|
321 | - return; |
|
322 | - } |
|
320 | + if (!$this->is_active_addon($importData['post_type'])) { |
|
321 | + return; |
|
322 | + } |
|
323 | 323 | |
324 | - $import_options = $importData['import']['options'][$this->slug]; |
|
324 | + $import_options = $importData['import']['options'][$this->slug]; |
|
325 | 325 | |
326 | - // echo "<pre>"; |
|
327 | - // print_r($import_options); |
|
328 | - // echo "</pre>"; |
|
326 | + // echo "<pre>"; |
|
327 | + // print_r($import_options); |
|
328 | + // echo "</pre>"; |
|
329 | 329 | |
330 | - if ( ! empty($parsedData) ) { |
|
330 | + if ( ! empty($parsedData) ) { |
|
331 | 331 | |
332 | - $this->logger = $importData['logger']; |
|
332 | + $this->logger = $importData['logger']; |
|
333 | 333 | |
334 | - $post_id = $importData['pid']; |
|
335 | - $index = $importData['i']; |
|
336 | - $data = array(); |
|
337 | - if (!empty($this->fields)){ |
|
338 | - foreach ($this->fields as $field_slug => $field_params) { |
|
339 | - if (in_array($field_params['type'], array('title', 'plain_text'))) continue; |
|
340 | - switch ($field_params['type']) { |
|
334 | + $post_id = $importData['pid']; |
|
335 | + $index = $importData['i']; |
|
336 | + $data = array(); |
|
337 | + if (!empty($this->fields)){ |
|
338 | + foreach ($this->fields as $field_slug => $field_params) { |
|
339 | + if (in_array($field_params['type'], array('title', 'plain_text'))) continue; |
|
340 | + switch ($field_params['type']) { |
|
341 | 341 | |
342 | - case 'image': |
|
342 | + case 'image': |
|
343 | 343 | |
344 | - // import the specified image, then set the value of the field to the image ID in the media library |
|
344 | + // import the specified image, then set the value of the field to the image ID in the media library |
|
345 | 345 | |
346 | - $image_url_or_path = $parsedData[$field_slug][$index]; |
|
346 | + $image_url_or_path = $parsedData[$field_slug][$index]; |
|
347 | 347 | |
348 | - if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
349 | - continue 2; |
|
350 | - } |
|
348 | + if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
349 | + continue 2; |
|
350 | + } |
|
351 | 351 | |
352 | - $download = $import_options['download_image'][$field_slug]; |
|
352 | + $download = $import_options['download_image'][$field_slug]; |
|
353 | 353 | |
354 | - $uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "images", true, $importData['articleData']); |
|
354 | + $uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "images", true, $importData['articleData']); |
|
355 | 355 | |
356 | - $data[$field_slug] = array( |
|
357 | - "attachment_id" => $uploaded_image, |
|
358 | - "image_url_or_path" => $image_url_or_path, |
|
359 | - "download" => $download |
|
360 | - ); |
|
356 | + $data[$field_slug] = array( |
|
357 | + "attachment_id" => $uploaded_image, |
|
358 | + "image_url_or_path" => $image_url_or_path, |
|
359 | + "download" => $download |
|
360 | + ); |
|
361 | 361 | |
362 | - break; |
|
362 | + break; |
|
363 | 363 | |
364 | - case 'file': |
|
364 | + case 'file': |
|
365 | 365 | |
366 | - $image_url_or_path = $parsedData[$field_slug][$index]; |
|
366 | + $image_url_or_path = $parsedData[$field_slug][$index]; |
|
367 | 367 | |
368 | - if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
369 | - continue 2; |
|
370 | - } |
|
368 | + if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
369 | + continue 2; |
|
370 | + } |
|
371 | 371 | |
372 | - $download = $import_options['download_image'][$field_slug]; |
|
372 | + $download = $import_options['download_image'][$field_slug]; |
|
373 | 373 | |
374 | - $uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files", true, $importData['articleData']); |
|
374 | + $uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files", true, $importData['articleData']); |
|
375 | 375 | |
376 | - $data[$field_slug] = array( |
|
377 | - "attachment_id" => $uploaded_file, |
|
378 | - "image_url_or_path" => $image_url_or_path, |
|
379 | - "download" => $download |
|
380 | - ); |
|
376 | + $data[$field_slug] = array( |
|
377 | + "attachment_id" => $uploaded_file, |
|
378 | + "image_url_or_path" => $image_url_or_path, |
|
379 | + "download" => $download |
|
380 | + ); |
|
381 | 381 | |
382 | - break; |
|
382 | + break; |
|
383 | 383 | |
384 | - default: |
|
385 | - // set the field data to the value of the field after it's been parsed |
|
386 | - $data[$field_slug] = $parsedData[$field_slug][$index]; |
|
387 | - break; |
|
388 | - } |
|
384 | + default: |
|
385 | + // set the field data to the value of the field after it's been parsed |
|
386 | + $data[$field_slug] = $parsedData[$field_slug][$index]; |
|
387 | + break; |
|
388 | + } |
|
389 | + |
|
390 | + // apply mapping rules if they exist |
|
391 | + if (!empty($import_options['mapping'][$field_slug])) { |
|
392 | + $mapping_rules = json_decode($import_options['mapping'][$field_slug], true); |
|
393 | + |
|
394 | + if (!empty($mapping_rules) and is_array($mapping_rules)) { |
|
395 | + foreach ($mapping_rules as $rule_number => $map_to) { |
|
396 | + if (isset($map_to[trim($data[$field_slug])])){ |
|
397 | + $data[$field_slug] = trim($map_to[trim($data[$field_slug])]); |
|
398 | + break; |
|
399 | + } |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | + // -------------------- |
|
404 | + } |
|
405 | + } |
|
389 | 406 | |
390 | - // apply mapping rules if they exist |
|
391 | - if (!empty($import_options['mapping'][$field_slug])) { |
|
392 | - $mapping_rules = json_decode($import_options['mapping'][$field_slug], true); |
|
407 | + call_user_func($this->import_function, $post_id, $data, $importData['import'], $importData['articleData'], $importData['logger']); |
|
408 | + } |
|
393 | 409 | |
394 | - if (!empty($mapping_rules) and is_array($mapping_rules)) { |
|
395 | - foreach ($mapping_rules as $rule_number => $map_to) { |
|
396 | - if (isset($map_to[trim($data[$field_slug])])){ |
|
397 | - $data[$field_slug] = trim($map_to[trim($data[$field_slug])]); |
|
398 | - break; |
|
399 | - } |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
403 | - // -------------------- |
|
404 | - } |
|
405 | - } |
|
410 | + } |
|
406 | 411 | |
407 | - call_user_func($this->import_function, $post_id, $data, $importData['import'], $importData['articleData'], $importData['logger']); |
|
408 | - } |
|
409 | 412 | |
410 | - } |
|
413 | + function wpai_api_metabox($post_type, $current_values) { |
|
411 | 414 | |
415 | + if (!$this->is_active_addon($post_type)) { |
|
416 | + return; |
|
417 | + } |
|
412 | 418 | |
413 | - function wpai_api_metabox($post_type, $current_values) { |
|
419 | + echo $this->helper_metabox_top($this->name); |
|
414 | 420 | |
415 | - if (!$this->is_active_addon($post_type)) { |
|
416 | - return; |
|
417 | - } |
|
421 | + $visible_fields = 0; |
|
418 | 422 | |
419 | - echo $this->helper_metabox_top($this->name); |
|
423 | + foreach ($this->fields as $field_slug => $field_params) { |
|
424 | + if ($field_params['is_sub_field']) continue; |
|
425 | + $visible_fields++; |
|
426 | + } |
|
420 | 427 | |
421 | - $visible_fields = 0; |
|
428 | + $counter = 0; |
|
422 | 429 | |
423 | - foreach ($this->fields as $field_slug => $field_params) { |
|
424 | - if ($field_params['is_sub_field']) continue; |
|
425 | - $visible_fields++; |
|
426 | - } |
|
430 | + foreach ($this->fields as $field_slug => $field_params) { |
|
427 | 431 | |
428 | - $counter = 0; |
|
432 | + // do not render sub fields |
|
433 | + if ($field_params['is_sub_field']) continue; |
|
429 | 434 | |
430 | - foreach ($this->fields as $field_slug => $field_params) { |
|
435 | + $counter++; |
|
431 | 436 | |
432 | - // do not render sub fields |
|
433 | - if ($field_params['is_sub_field']) continue; |
|
437 | + $this->render_field($field_params, $field_slug, $current_values, $visible_fields == $counter); |
|
434 | 438 | |
435 | - $counter++; |
|
439 | + //if ( $field_params['type'] != 'accordion' ) echo "<br />"; |
|
436 | 440 | |
437 | - $this->render_field($field_params, $field_slug, $current_values, $visible_fields == $counter); |
|
441 | + } |
|
438 | 442 | |
439 | - //if ( $field_params['type'] != 'accordion' ) echo "<br />"; |
|
443 | + echo $this->helper_metabox_bottom(); |
|
444 | + |
|
445 | + if ( ! empty($this->image_sections) ){ |
|
446 | + $is_images_section_enabled = apply_filters('wp_all_import_is_images_section_enabled', true, $post_type); |
|
447 | + foreach ($this->image_sections as $k => $section) { |
|
448 | + $section_options = array(); |
|
449 | + foreach ($this->image_options as $slug => $value) { |
|
450 | + $section_options[$section['slug'] . $slug] = $value; |
|
451 | + } |
|
452 | + if ( ! $is_images_section_enabled and ! $k ){ |
|
453 | + $section_options[$section['slug'] . 'is_featured'] = 1; |
|
454 | + } |
|
455 | + PMXI_API::add_additional_images_section($section['title'], $section['slug'], $current_values, '', true, false, $section['type']); |
|
456 | + } |
|
457 | + } |
|
440 | 458 | |
441 | - } |
|
459 | + } |
|
442 | 460 | |
443 | - echo $this->helper_metabox_bottom(); |
|
461 | + function render_field($field_params, $field_slug, $current_values, $in_the_bottom = false){ |
|
444 | 462 | |
445 | - if ( ! empty($this->image_sections) ){ |
|
446 | - $is_images_section_enabled = apply_filters('wp_all_import_is_images_section_enabled', true, $post_type); |
|
447 | - foreach ($this->image_sections as $k => $section) { |
|
448 | - $section_options = array(); |
|
449 | - foreach ($this->image_options as $slug => $value) { |
|
450 | - $section_options[$section['slug'] . $slug] = $value; |
|
451 | - } |
|
452 | - if ( ! $is_images_section_enabled and ! $k ){ |
|
453 | - $section_options[$section['slug'] . 'is_featured'] = 1; |
|
454 | - } |
|
455 | - PMXI_API::add_additional_images_section($section['title'], $section['slug'], $current_values, '', true, false, $section['type']); |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - } |
|
460 | - |
|
461 | - function render_field($field_params, $field_slug, $current_values, $in_the_bottom = false){ |
|
462 | - |
|
463 | - if (!isset($current_values[$this->slug][$field_slug])) { |
|
464 | - $current_values[$this->slug][$field_slug] = isset($field_params['default_text']) ? $field_params['default_text'] : ''; |
|
465 | - } |
|
466 | - |
|
467 | - if ($field_params['type'] == 'text') { |
|
468 | - |
|
469 | - PMXI_API::add_field( |
|
470 | - 'simple', |
|
471 | - $field_params['name'], |
|
472 | - array( |
|
473 | - 'tooltip' => $field_params['tooltip'], |
|
474 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
475 | - 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
476 | - ) |
|
477 | - ); |
|
478 | - |
|
479 | - } else if ($field_params['type'] == 'textarea') { |
|
480 | - |
|
481 | - PMXI_API::add_field( |
|
482 | - 'textarea', |
|
483 | - $field_params['name'], |
|
484 | - array( |
|
485 | - 'tooltip' => $field_params['tooltip'], |
|
486 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
487 | - 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
488 | - ) |
|
489 | - ); |
|
490 | - |
|
491 | - } else if ($field_params['type'] == 'wp_editor') { |
|
492 | - |
|
493 | - PMXI_API::add_field( |
|
494 | - 'wp_editor', |
|
495 | - $field_params['name'], |
|
496 | - array( |
|
497 | - 'tooltip' => $field_params['tooltip'], |
|
498 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
499 | - 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
500 | - ) |
|
501 | - ); |
|
502 | - |
|
503 | - } else if ($field_params['type'] == 'image' or $field_params['type'] == 'file') { |
|
463 | + if (!isset($current_values[$this->slug][$field_slug])) { |
|
464 | + $current_values[$this->slug][$field_slug] = isset($field_params['default_text']) ? $field_params['default_text'] : ''; |
|
465 | + } |
|
466 | + |
|
467 | + if ($field_params['type'] == 'text') { |
|
468 | + |
|
469 | + PMXI_API::add_field( |
|
470 | + 'simple', |
|
471 | + $field_params['name'], |
|
472 | + array( |
|
473 | + 'tooltip' => $field_params['tooltip'], |
|
474 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
475 | + 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
476 | + ) |
|
477 | + ); |
|
478 | + |
|
479 | + } else if ($field_params['type'] == 'textarea') { |
|
480 | + |
|
481 | + PMXI_API::add_field( |
|
482 | + 'textarea', |
|
483 | + $field_params['name'], |
|
484 | + array( |
|
485 | + 'tooltip' => $field_params['tooltip'], |
|
486 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
487 | + 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
488 | + ) |
|
489 | + ); |
|
490 | + |
|
491 | + } else if ($field_params['type'] == 'wp_editor') { |
|
492 | + |
|
493 | + PMXI_API::add_field( |
|
494 | + 'wp_editor', |
|
495 | + $field_params['name'], |
|
496 | + array( |
|
497 | + 'tooltip' => $field_params['tooltip'], |
|
498 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
499 | + 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
500 | + ) |
|
501 | + ); |
|
502 | + |
|
503 | + } else if ($field_params['type'] == 'image' or $field_params['type'] == 'file') { |
|
504 | 504 | |
505 | - if (!isset($current_values[$this->slug]['download_image'][$field_slug])) { $current_values[$this->slug]['download_image'][$field_slug] = ''; } |
|
506 | - |
|
507 | - PMXI_API::add_field( |
|
508 | - $field_params['type'], |
|
509 | - $field_params['name'], |
|
510 | - array( |
|
511 | - 'tooltip' => $field_params['tooltip'], |
|
512 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
513 | - 'field_value' => $current_values[$this->slug][$field_slug], |
|
514 | - 'download_image' => $current_values[$this->slug]['download_image'][$field_slug], |
|
515 | - 'field_key' => $field_slug, |
|
516 | - 'addon_prefix' => $this->slug |
|
517 | - |
|
518 | - ) |
|
519 | - ); |
|
520 | - |
|
521 | - } else if ($field_params['type'] == 'radio') { |
|
505 | + if (!isset($current_values[$this->slug]['download_image'][$field_slug])) { $current_values[$this->slug]['download_image'][$field_slug] = ''; } |
|
506 | + |
|
507 | + PMXI_API::add_field( |
|
508 | + $field_params['type'], |
|
509 | + $field_params['name'], |
|
510 | + array( |
|
511 | + 'tooltip' => $field_params['tooltip'], |
|
512 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
513 | + 'field_value' => $current_values[$this->slug][$field_slug], |
|
514 | + 'download_image' => $current_values[$this->slug]['download_image'][$field_slug], |
|
515 | + 'field_key' => $field_slug, |
|
516 | + 'addon_prefix' => $this->slug |
|
517 | + |
|
518 | + ) |
|
519 | + ); |
|
520 | + |
|
521 | + } else if ($field_params['type'] == 'radio') { |
|
522 | 522 | |
523 | - if (!isset($current_values[$this->slug]['mapping'][$field_slug])) { $current_values[$this->slug]['mapping'][$field_slug] = array(); } |
|
524 | - if (!isset($current_values[$this->slug]['xpaths'][$field_slug])) { $current_values[$this->slug]['xpaths'][$field_slug] = ''; } |
|
525 | - |
|
526 | - PMXI_API::add_field( |
|
527 | - 'enum', |
|
528 | - $field_params['name'], |
|
529 | - array( |
|
530 | - 'tooltip' => $field_params['tooltip'], |
|
531 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
532 | - 'field_value' => $current_values[$this->slug][$field_slug], |
|
533 | - 'enum_values' => $field_params['enum_values'], |
|
534 | - 'mapping' => true, |
|
535 | - 'field_key' => $field_slug, |
|
536 | - 'mapping_rules' => $current_values[$this->slug]['mapping'][$field_slug], |
|
537 | - 'xpath' => $current_values[$this->slug]['xpaths'][$field_slug], |
|
538 | - 'addon_prefix' => $this->slug, |
|
539 | - 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values) |
|
540 | - ) |
|
541 | - ); |
|
542 | - |
|
543 | - } else if($field_params['type'] == 'accordion') { |
|
544 | - |
|
545 | - PMXI_API::add_field( |
|
546 | - 'accordion', |
|
547 | - $field_params['name'], |
|
548 | - array( |
|
549 | - 'tooltip' => $field_params['tooltip'], |
|
550 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
551 | - 'field_key' => $field_slug, |
|
552 | - 'addon_prefix' => $this->slug, |
|
553 | - 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values), |
|
554 | - 'in_the_bottom' => $in_the_bottom |
|
555 | - ) |
|
556 | - ); |
|
557 | - |
|
558 | - } else if($field_params['type'] == 'acf') { |
|
559 | - $fieldData = (!empty($field_params['field_obj']->post_content)) ? unserialize($field_params['field_obj']->post_content) : array(); |
|
560 | - $fieldData['ID'] = $field_params['field_obj']->ID; |
|
561 | - $fieldData['id'] = $field_params['field_obj']->ID; |
|
562 | - $fieldData['label'] = $field_params['field_obj']->post_title; |
|
563 | - $fieldData['key'] = $field_params['field_obj']->post_name; |
|
564 | - if (empty($fieldData['name'])) $fieldData['name'] = $field_params['field_obj']->post_excerpt; |
|
565 | - if (function_exists('pmai_render_field')) { |
|
566 | - echo pmai_render_field($fieldData, ( ! empty($current_values) ) ? $current_values : array() ); |
|
567 | - } |
|
568 | - } else if($field_params['type'] == 'title'){ |
|
569 | - ?> |
|
523 | + if (!isset($current_values[$this->slug]['mapping'][$field_slug])) { $current_values[$this->slug]['mapping'][$field_slug] = array(); } |
|
524 | + if (!isset($current_values[$this->slug]['xpaths'][$field_slug])) { $current_values[$this->slug]['xpaths'][$field_slug] = ''; } |
|
525 | + |
|
526 | + PMXI_API::add_field( |
|
527 | + 'enum', |
|
528 | + $field_params['name'], |
|
529 | + array( |
|
530 | + 'tooltip' => $field_params['tooltip'], |
|
531 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
532 | + 'field_value' => $current_values[$this->slug][$field_slug], |
|
533 | + 'enum_values' => $field_params['enum_values'], |
|
534 | + 'mapping' => true, |
|
535 | + 'field_key' => $field_slug, |
|
536 | + 'mapping_rules' => $current_values[$this->slug]['mapping'][$field_slug], |
|
537 | + 'xpath' => $current_values[$this->slug]['xpaths'][$field_slug], |
|
538 | + 'addon_prefix' => $this->slug, |
|
539 | + 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values) |
|
540 | + ) |
|
541 | + ); |
|
542 | + |
|
543 | + } else if($field_params['type'] == 'accordion') { |
|
544 | + |
|
545 | + PMXI_API::add_field( |
|
546 | + 'accordion', |
|
547 | + $field_params['name'], |
|
548 | + array( |
|
549 | + 'tooltip' => $field_params['tooltip'], |
|
550 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
551 | + 'field_key' => $field_slug, |
|
552 | + 'addon_prefix' => $this->slug, |
|
553 | + 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values), |
|
554 | + 'in_the_bottom' => $in_the_bottom |
|
555 | + ) |
|
556 | + ); |
|
557 | + |
|
558 | + } else if($field_params['type'] == 'acf') { |
|
559 | + $fieldData = (!empty($field_params['field_obj']->post_content)) ? unserialize($field_params['field_obj']->post_content) : array(); |
|
560 | + $fieldData['ID'] = $field_params['field_obj']->ID; |
|
561 | + $fieldData['id'] = $field_params['field_obj']->ID; |
|
562 | + $fieldData['label'] = $field_params['field_obj']->post_title; |
|
563 | + $fieldData['key'] = $field_params['field_obj']->post_name; |
|
564 | + if (empty($fieldData['name'])) $fieldData['name'] = $field_params['field_obj']->post_excerpt; |
|
565 | + if (function_exists('pmai_render_field')) { |
|
566 | + echo pmai_render_field($fieldData, ( ! empty($current_values) ) ? $current_values : array() ); |
|
567 | + } |
|
568 | + } else if($field_params['type'] == 'title'){ |
|
569 | + ?> |
|
570 | 570 | <h4 class="wpallimport-add-on-options-title"><?php _e($field_params['name'], 'wp_all_import_plugin'); ?><?php if ( ! empty($field_params['tooltip'])): ?><a href="#help" class="wpallimport-help" title="<?php echo $field_params['tooltip']; ?>" style="position:relative; top: -1px;">?</a><?php endif; ?></h4> |
571 | 571 | <?php |
572 | 572 | |
573 | - } else if($field_params['type'] == 'plain_text'){ |
|
574 | - if ($field_params['is_html']): |
|
575 | - echo $field_params['name']; |
|
576 | - else: |
|
577 | - ?> |
|
573 | + } else if($field_params['type'] == 'plain_text'){ |
|
574 | + if ($field_params['is_html']): |
|
575 | + echo $field_params['name']; |
|
576 | + else: |
|
577 | + ?> |
|
578 | 578 | <p style="margin: 0 0 12px 0;"><?php echo $field_params['name'];?></p> |
579 | 579 | <?php |
580 | - endif; |
|
581 | - } |
|
580 | + endif; |
|
581 | + } |
|
582 | 582 | |
583 | 583 | |
584 | - } |
|
585 | - /** |
|
586 | - * |
|
587 | - * Helper function for nested radio fields |
|
588 | - * |
|
589 | - */ |
|
590 | - function get_sub_fields($field_params, $field_slug, $current_values){ |
|
591 | - $sub_fields = array(); |
|
592 | - if ( ! empty($field_params['enum_values']) ){ |
|
593 | - foreach ($field_params['enum_values'] as $key => $value) { |
|
594 | - $sub_fields[$key] = array(); |
|
595 | - if (is_array($value)){ |
|
596 | - if ($field_params['type'] == 'accordion'){ |
|
597 | - $sub_fields[$key][] = $this->convert_field($value, $current_values); |
|
598 | - } |
|
599 | - else |
|
600 | - { |
|
601 | - foreach ($value as $k => $sub_field) { |
|
602 | - if (is_array($sub_field) and ! empty($this->fields[$sub_field['slug']])) |
|
603 | - { |
|
604 | - $sub_fields[$key][] = $this->convert_field($sub_field, $current_values); |
|
605 | - } |
|
606 | - } |
|
607 | - } |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - return $sub_fields; |
|
612 | - } |
|
613 | - |
|
614 | - function convert_field($sub_field, $current_values){ |
|
615 | - $field = array(); |
|
616 | - if (!isset($current_values[$this->slug][$sub_field['slug']])) { |
|
617 | - $current_values[$this->slug][$sub_field['slug']] = isset($sub_field['default_text']) ? $sub_field['default_text'] : ''; |
|
618 | - } |
|
619 | - switch ($this->fields[$sub_field['slug']]['type']) { |
|
620 | - case 'text': |
|
621 | - $field = array( |
|
622 | - 'type' => 'simple', |
|
623 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
624 | - 'params' => array( |
|
625 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
626 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
627 | - 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
628 | - 'is_main_field' => $sub_field['is_main_field'] |
|
629 | - ) |
|
630 | - ); |
|
631 | - break; |
|
632 | - case 'textarea': |
|
633 | - $field = array( |
|
634 | - 'type' => 'textarea', |
|
635 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
636 | - 'params' => array( |
|
637 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
638 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
639 | - 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
640 | - 'is_main_field' => $sub_field['is_main_field'] |
|
641 | - ) |
|
642 | - ); |
|
643 | - break; |
|
644 | - case 'wp_editor': |
|
645 | - $field = array( |
|
646 | - 'type' => 'wp_editor', |
|
647 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
648 | - 'params' => array( |
|
649 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
650 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
651 | - 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
652 | - 'is_main_field' => $sub_field['is_main_field'] |
|
653 | - ) |
|
654 | - ); |
|
655 | - break; |
|
656 | - case 'image': |
|
657 | - $field = array( |
|
658 | - 'type' => 'image', |
|
659 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
660 | - 'params' => array( |
|
661 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
662 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
663 | - 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
664 | - 'download_image' => null, |
|
665 | - 'field_key' => $sub_field['slug'], |
|
666 | - 'addon_prefix' => $this->slug, |
|
667 | - 'is_main_field' => $sub_field['is_main_field'] |
|
668 | - ) |
|
669 | - ); |
|
670 | - |
|
671 | - if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
672 | - $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
|
673 | - } |
|
584 | + } |
|
585 | + /** |
|
586 | + * |
|
587 | + * Helper function for nested radio fields |
|
588 | + * |
|
589 | + */ |
|
590 | + function get_sub_fields($field_params, $field_slug, $current_values){ |
|
591 | + $sub_fields = array(); |
|
592 | + if ( ! empty($field_params['enum_values']) ){ |
|
593 | + foreach ($field_params['enum_values'] as $key => $value) { |
|
594 | + $sub_fields[$key] = array(); |
|
595 | + if (is_array($value)){ |
|
596 | + if ($field_params['type'] == 'accordion'){ |
|
597 | + $sub_fields[$key][] = $this->convert_field($value, $current_values); |
|
598 | + } |
|
599 | + else |
|
600 | + { |
|
601 | + foreach ($value as $k => $sub_field) { |
|
602 | + if (is_array($sub_field) and ! empty($this->fields[$sub_field['slug']])) |
|
603 | + { |
|
604 | + $sub_fields[$key][] = $this->convert_field($sub_field, $current_values); |
|
605 | + } |
|
606 | + } |
|
607 | + } |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + return $sub_fields; |
|
612 | + } |
|
613 | + |
|
614 | + function convert_field($sub_field, $current_values){ |
|
615 | + $field = array(); |
|
616 | + if (!isset($current_values[$this->slug][$sub_field['slug']])) { |
|
617 | + $current_values[$this->slug][$sub_field['slug']] = isset($sub_field['default_text']) ? $sub_field['default_text'] : ''; |
|
618 | + } |
|
619 | + switch ($this->fields[$sub_field['slug']]['type']) { |
|
620 | + case 'text': |
|
621 | + $field = array( |
|
622 | + 'type' => 'simple', |
|
623 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
624 | + 'params' => array( |
|
625 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
626 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
627 | + 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
628 | + 'is_main_field' => $sub_field['is_main_field'] |
|
629 | + ) |
|
630 | + ); |
|
674 | 631 | break; |
675 | - case 'file': |
|
676 | - $field = array( |
|
677 | - 'type' => 'file', |
|
678 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
679 | - 'params' => array( |
|
680 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
681 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
682 | - 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
683 | - 'download_image' => null, |
|
684 | - 'field_key' => $sub_field['slug'], |
|
685 | - 'addon_prefix' => $this->slug, |
|
686 | - 'is_main_field' => $sub_field['is_main_field'] |
|
687 | - ) |
|
688 | - ); |
|
689 | - |
|
690 | - if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
691 | - $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
|
692 | - } |
|
693 | - |
|
694 | - break; |
|
695 | - case 'radio': |
|
696 | - $field = array( |
|
697 | - 'type' => 'enum', |
|
698 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
699 | - 'params' => array( |
|
700 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
701 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
702 | - 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
703 | - 'enum_values' => $this->fields[$sub_field['slug']]['enum_values'], |
|
704 | - 'mapping' => true, |
|
705 | - 'field_key' => $sub_field['slug'], |
|
706 | - 'mapping_rules' => isset($current_values[$this->slug]['mapping'][$sub_field['slug']]) ? $current_values[$this->slug]['mapping'][$sub_field['slug']] : array(), |
|
707 | - 'xpath' => isset($current_values[$this->slug]['xpaths'][$sub_field['slug']]) ? $current_values[$this->slug]['xpaths'][$sub_field['slug']] : '', |
|
708 | - 'addon_prefix' => $this->slug, |
|
709 | - 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values), |
|
710 | - 'is_main_field' => $sub_field['is_main_field'] |
|
711 | - ) |
|
712 | - ); |
|
713 | - break; |
|
714 | - case 'accordion': |
|
715 | - $field = array( |
|
716 | - 'type' => 'accordion', |
|
717 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
718 | - 'params' => array( |
|
719 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
720 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
721 | - 'field_key' => $sub_field['slug'], |
|
722 | - 'addon_prefix' => $this->slug, |
|
723 | - 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values), |
|
724 | - 'in_the_bottom' => false |
|
725 | - ) |
|
726 | - ); |
|
727 | - break; |
|
728 | - default: |
|
729 | - # code... |
|
730 | - break; |
|
731 | - } |
|
732 | - return $field; |
|
733 | - } |
|
734 | - |
|
735 | - /** |
|
736 | - * |
|
737 | - * Add accordion options |
|
738 | - * |
|
739 | - * |
|
740 | - */ |
|
741 | - function add_options( $main_field = false, $title = '', $fields = array() ){ |
|
632 | + case 'textarea': |
|
633 | + $field = array( |
|
634 | + 'type' => 'textarea', |
|
635 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
636 | + 'params' => array( |
|
637 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
638 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
639 | + 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
640 | + 'is_main_field' => $sub_field['is_main_field'] |
|
641 | + ) |
|
642 | + ); |
|
643 | + break; |
|
644 | + case 'wp_editor': |
|
645 | + $field = array( |
|
646 | + 'type' => 'wp_editor', |
|
647 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
648 | + 'params' => array( |
|
649 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
650 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
651 | + 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
652 | + 'is_main_field' => $sub_field['is_main_field'] |
|
653 | + ) |
|
654 | + ); |
|
655 | + break; |
|
656 | + case 'image': |
|
657 | + $field = array( |
|
658 | + 'type' => 'image', |
|
659 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
660 | + 'params' => array( |
|
661 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
662 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
663 | + 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
664 | + 'download_image' => null, |
|
665 | + 'field_key' => $sub_field['slug'], |
|
666 | + 'addon_prefix' => $this->slug, |
|
667 | + 'is_main_field' => $sub_field['is_main_field'] |
|
668 | + ) |
|
669 | + ); |
|
670 | + |
|
671 | + if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
672 | + $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
|
673 | + } |
|
674 | + break; |
|
675 | + case 'file': |
|
676 | + $field = array( |
|
677 | + 'type' => 'file', |
|
678 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
679 | + 'params' => array( |
|
680 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
681 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
682 | + 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
683 | + 'download_image' => null, |
|
684 | + 'field_key' => $sub_field['slug'], |
|
685 | + 'addon_prefix' => $this->slug, |
|
686 | + 'is_main_field' => $sub_field['is_main_field'] |
|
687 | + ) |
|
688 | + ); |
|
689 | + |
|
690 | + if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
691 | + $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
|
692 | + } |
|
693 | + |
|
694 | + break; |
|
695 | + case 'radio': |
|
696 | + $field = array( |
|
697 | + 'type' => 'enum', |
|
698 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
699 | + 'params' => array( |
|
700 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
701 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
702 | + 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
703 | + 'enum_values' => $this->fields[$sub_field['slug']]['enum_values'], |
|
704 | + 'mapping' => true, |
|
705 | + 'field_key' => $sub_field['slug'], |
|
706 | + 'mapping_rules' => isset($current_values[$this->slug]['mapping'][$sub_field['slug']]) ? $current_values[$this->slug]['mapping'][$sub_field['slug']] : array(), |
|
707 | + 'xpath' => isset($current_values[$this->slug]['xpaths'][$sub_field['slug']]) ? $current_values[$this->slug]['xpaths'][$sub_field['slug']] : '', |
|
708 | + 'addon_prefix' => $this->slug, |
|
709 | + 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values), |
|
710 | + 'is_main_field' => $sub_field['is_main_field'] |
|
711 | + ) |
|
712 | + ); |
|
713 | + break; |
|
714 | + case 'accordion': |
|
715 | + $field = array( |
|
716 | + 'type' => 'accordion', |
|
717 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
718 | + 'params' => array( |
|
719 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
720 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
721 | + 'field_key' => $sub_field['slug'], |
|
722 | + 'addon_prefix' => $this->slug, |
|
723 | + 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values), |
|
724 | + 'in_the_bottom' => false |
|
725 | + ) |
|
726 | + ); |
|
727 | + break; |
|
728 | + default: |
|
729 | + # code... |
|
730 | + break; |
|
731 | + } |
|
732 | + return $field; |
|
733 | + } |
|
734 | + |
|
735 | + /** |
|
736 | + * |
|
737 | + * Add accordion options |
|
738 | + * |
|
739 | + * |
|
740 | + */ |
|
741 | + function add_options( $main_field = false, $title = '', $fields = array() ){ |
|
742 | 742 | |
743 | - if ( ! empty($fields) ) |
|
744 | - { |
|
743 | + if ( ! empty($fields) ) |
|
744 | + { |
|
745 | 745 | |
746 | - if ($main_field){ |
|
746 | + if ($main_field){ |
|
747 | 747 | |
748 | - $main_field['is_main_field'] = true; |
|
749 | - $fields[] = $main_field; |
|
748 | + $main_field['is_main_field'] = true; |
|
749 | + $fields[] = $main_field; |
|
750 | 750 | |
751 | - } |
|
751 | + } |
|
752 | 752 | |
753 | - return $this->add_field('accordion_' . $fields[0]['slug'], $title, 'accordion', $fields); |
|
753 | + return $this->add_field('accordion_' . $fields[0]['slug'], $title, 'accordion', $fields); |
|
754 | 754 | |
755 | - } |
|
755 | + } |
|
756 | 756 | |
757 | - } |
|
757 | + } |
|
758 | 758 | |
759 | - function add_title($title = '', $tooltip = ''){ |
|
759 | + function add_title($title = '', $tooltip = ''){ |
|
760 | 760 | |
761 | - if (empty($title)) return; |
|
761 | + if (empty($title)) return; |
|
762 | 762 | |
763 | - return $this->add_field(sanitize_key($title) . time(), $title, 'title', null, $tooltip); |
|
763 | + return $this->add_field(sanitize_key($title) . time(), $title, 'title', null, $tooltip); |
|
764 | 764 | |
765 | - } |
|
765 | + } |
|
766 | 766 | |
767 | - function add_text($text = '', $is_html = false){ |
|
767 | + function add_text($text = '', $is_html = false){ |
|
768 | 768 | |
769 | - if (empty($text)) return; |
|
769 | + if (empty($text)) return; |
|
770 | 770 | |
771 | - $count = is_array($this->fields) ? count($this->fields) : 0; |
|
771 | + $count = is_array($this->fields) ? count($this->fields) : 0; |
|
772 | 772 | |
773 | - return $this->add_field(sanitize_key($text) . time() . uniqid() . $count, $text, 'plain_text', null, "", $is_html); |
|
773 | + return $this->add_field(sanitize_key($text) . time() . uniqid() . $count, $text, 'plain_text', null, "", $is_html); |
|
774 | 774 | |
775 | - } |
|
775 | + } |
|
776 | 776 | |
777 | - function helper_metabox_top($name) { |
|
777 | + function helper_metabox_top($name) { |
|
778 | 778 | |
779 | - return ' |
|
779 | + return ' |
|
780 | 780 | <style type="text/css"> |
781 | 781 | .wpallimport-plugin .wpallimport-addon div.input { |
782 | 782 | margin-bottom: 15px; |
@@ -872,11 +872,11 @@ discard block |
||
872 | 872 | <table class="form-table" style="max-width:none;"> |
873 | 873 | <tr> |
874 | 874 | <td colspan="3">'; |
875 | - } |
|
875 | + } |
|
876 | 876 | |
877 | - function helper_metabox_bottom() { |
|
877 | + function helper_metabox_bottom() { |
|
878 | 878 | |
879 | - return ' </td> |
|
879 | + return ' </td> |
|
880 | 880 | </tr> |
881 | 881 | </table> |
882 | 882 | </div> |
@@ -884,298 +884,298 @@ discard block |
||
884 | 884 | </div> |
885 | 885 | </div>'; |
886 | 886 | |
887 | - } |
|
887 | + } |
|
888 | 888 | |
889 | - /** |
|
890 | - * |
|
891 | - * simply add an additional section for attachments |
|
892 | - * |
|
893 | - */ |
|
894 | - function import_files( $slug, $title, $callback = NULL ){ |
|
895 | - $this->import_images( $slug, $title, 'files', $callback); |
|
896 | - } |
|
889 | + /** |
|
890 | + * |
|
891 | + * simply add an additional section for attachments |
|
892 | + * |
|
893 | + */ |
|
894 | + function import_files( $slug, $title, $callback = NULL ){ |
|
895 | + $this->import_images( $slug, $title, 'files', $callback); |
|
896 | + } |
|
897 | 897 | |
898 | - /** |
|
899 | - * |
|
900 | - * simply add an additional section |
|
901 | - * |
|
902 | - */ |
|
903 | - function import_images( $slug, $title, $type = 'images', $callback = NULL ){ |
|
898 | + /** |
|
899 | + * |
|
900 | + * simply add an additional section |
|
901 | + * |
|
902 | + */ |
|
903 | + function import_images( $slug, $title, $type = 'images', $callback = NULL ){ |
|
904 | 904 | |
905 | - if ( empty($title) or empty($slug) ) return; |
|
905 | + if ( empty($title) or empty($slug) ) return; |
|
906 | 906 | |
907 | - if (is_array($slug)) { |
|
907 | + if (is_array($slug)) { |
|
908 | 908 | $section_slug = 'pmxi_' . md5(serialize($slug)); |
909 | 909 | } else { |
910 | 910 | $section_slug = 'pmxi_' . $slug; |
911 | 911 | } |
912 | 912 | |
913 | - $this->image_sections[] = array( |
|
914 | - 'title' => $title, |
|
915 | - 'slug' => $section_slug, |
|
916 | - 'type' => $type |
|
917 | - ); |
|
913 | + $this->image_sections[] = array( |
|
914 | + 'title' => $title, |
|
915 | + 'slug' => $section_slug, |
|
916 | + 'type' => $type |
|
917 | + ); |
|
918 | 918 | |
919 | - foreach ($this->image_options as $option_slug => $value) { |
|
920 | - $this->add_option($section_slug . $option_slug, $value); |
|
921 | - } |
|
919 | + foreach ($this->image_options as $option_slug => $value) { |
|
920 | + $this->add_option($section_slug . $option_slug, $value); |
|
921 | + } |
|
922 | 922 | |
923 | - if (count($this->image_sections) > 1){ |
|
924 | - add_filter('wp_all_import_is_show_add_new_images', array($this, 'filter_is_show_add_new_images'), 10, 2); |
|
925 | - } |
|
923 | + if (count($this->image_sections) > 1){ |
|
924 | + add_filter('wp_all_import_is_show_add_new_images', array($this, 'filter_is_show_add_new_images'), 10, 2); |
|
925 | + } |
|
926 | 926 | |
927 | - add_filter('wp_all_import_is_allow_import_images', array($this, 'is_allow_import_images'), 10, 2); |
|
927 | + add_filter('wp_all_import_is_allow_import_images', array($this, 'is_allow_import_images'), 10, 2); |
|
928 | 928 | |
929 | - if ($callback && is_callable($callback)) { |
|
929 | + if ($callback && is_callable($callback)) { |
|
930 | 930 | add_action( $section_slug, $callback, 10, 4); |
931 | 931 | } else { |
932 | 932 | if (function_exists($slug)) { |
933 | 933 | add_action( $section_slug, $slug, 10, 4); |
934 | 934 | } |
935 | 935 | } |
936 | - } |
|
937 | - /** |
|
938 | - * |
|
939 | - * filter to allow import images for free edition of WP All Import |
|
940 | - * |
|
941 | - */ |
|
942 | - function is_allow_import_images($is_allow, $post_type){ |
|
943 | - return ($this->is_active_addon($post_type)) ? true : $is_allow; |
|
944 | - } |
|
945 | - |
|
946 | - /** |
|
947 | - * |
|
948 | - * filter to control additional images sections |
|
949 | - * |
|
950 | - */ |
|
951 | - function additional_sections($sections){ |
|
952 | - if ( ! empty($this->image_sections) ){ |
|
953 | - foreach ($this->image_sections as $add_section) { |
|
954 | - $sections[] = $add_section; |
|
955 | - } |
|
956 | - } |
|
936 | + } |
|
937 | + /** |
|
938 | + * |
|
939 | + * filter to allow import images for free edition of WP All Import |
|
940 | + * |
|
941 | + */ |
|
942 | + function is_allow_import_images($is_allow, $post_type){ |
|
943 | + return ($this->is_active_addon($post_type)) ? true : $is_allow; |
|
944 | + } |
|
945 | + |
|
946 | + /** |
|
947 | + * |
|
948 | + * filter to control additional images sections |
|
949 | + * |
|
950 | + */ |
|
951 | + function additional_sections($sections){ |
|
952 | + if ( ! empty($this->image_sections) ){ |
|
953 | + foreach ($this->image_sections as $add_section) { |
|
954 | + $sections[] = $add_section; |
|
955 | + } |
|
956 | + } |
|
957 | 957 | |
958 | - return $sections; |
|
959 | - } |
|
960 | - /** |
|
961 | - * |
|
962 | - * remove the 'Don't touch existing images, append new images' when more than one image section is in use. |
|
963 | - * |
|
964 | - */ |
|
965 | - function filter_is_show_add_new_images($is_show, $post_type){ |
|
966 | - return ($this->is_active_addon($post_type)) ? false : $is_show; |
|
967 | - } |
|
968 | - |
|
969 | - /** |
|
970 | - * |
|
971 | - * disable the default images section |
|
972 | - * |
|
973 | - */ |
|
974 | - function disable_default_images($post_type = false){ |
|
958 | + return $sections; |
|
959 | + } |
|
960 | + /** |
|
961 | + * |
|
962 | + * remove the 'Don't touch existing images, append new images' when more than one image section is in use. |
|
963 | + * |
|
964 | + */ |
|
965 | + function filter_is_show_add_new_images($is_show, $post_type){ |
|
966 | + return ($this->is_active_addon($post_type)) ? false : $is_show; |
|
967 | + } |
|
968 | + |
|
969 | + /** |
|
970 | + * |
|
971 | + * disable the default images section |
|
972 | + * |
|
973 | + */ |
|
974 | + function disable_default_images($post_type = false){ |
|
975 | 975 | |
976 | - add_filter('wp_all_import_is_images_section_enabled', array($this, 'is_enable_default_images_section'), 10, 2); |
|
976 | + add_filter('wp_all_import_is_images_section_enabled', array($this, 'is_enable_default_images_section'), 10, 2); |
|
977 | 977 | |
978 | - } |
|
979 | - function is_enable_default_images_section($is_enabled, $post_type){ |
|
978 | + } |
|
979 | + function is_enable_default_images_section($is_enabled, $post_type){ |
|
980 | 980 | |
981 | - return ($this->is_active_addon($post_type)) ? false : true; |
|
981 | + return ($this->is_active_addon($post_type)) ? false : true; |
|
982 | 982 | |
983 | - } |
|
983 | + } |
|
984 | 984 | |
985 | - function helper_parse($parsingData, $options) { |
|
985 | + function helper_parse($parsingData, $options) { |
|
986 | 986 | |
987 | - extract($parsingData); |
|
987 | + extract($parsingData); |
|
988 | 988 | |
989 | - $data = array(); // parsed data |
|
989 | + $data = array(); // parsed data |
|
990 | 990 | |
991 | - if ( ! empty($import->options[$this->slug])){ |
|
991 | + if ( ! empty($import->options[$this->slug])){ |
|
992 | 992 | |
993 | - $this->logger = $parsingData['logger']; |
|
993 | + $this->logger = $parsingData['logger']; |
|
994 | 994 | |
995 | - $cxpath = $xpath_prefix . $import->xpath; |
|
995 | + $cxpath = $xpath_prefix . $import->xpath; |
|
996 | 996 | |
997 | - $tmp_files = array(); |
|
997 | + $tmp_files = array(); |
|
998 | 998 | |
999 | - foreach ($options[$this->slug] as $option_name => $option_value) { |
|
1000 | - if ( isset($import->options[$this->slug][$option_name]) and $import->options[$this->slug][$option_name] != '') { |
|
1001 | - if ($import->options[$this->slug][$option_name] == "xpath") { |
|
1002 | - if ($import->options[$this->slug]['xpaths'][$option_name] == ""){ |
|
1003 | - $count and $data[$option_name] = array_fill(0, $count, ""); |
|
1004 | - } else { |
|
1005 | - $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug]['xpaths'][$option_name], $file)->parse(); |
|
1006 | - $tmp_files[] = $file; |
|
1007 | - } |
|
1008 | - } |
|
1009 | - else { |
|
1010 | - $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug][$option_name], $file)->parse(); |
|
1011 | - $tmp_files[] = $file; |
|
1012 | - } |
|
999 | + foreach ($options[$this->slug] as $option_name => $option_value) { |
|
1000 | + if ( isset($import->options[$this->slug][$option_name]) and $import->options[$this->slug][$option_name] != '') { |
|
1001 | + if ($import->options[$this->slug][$option_name] == "xpath") { |
|
1002 | + if ($import->options[$this->slug]['xpaths'][$option_name] == ""){ |
|
1003 | + $count and $data[$option_name] = array_fill(0, $count, ""); |
|
1004 | + } else { |
|
1005 | + $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug]['xpaths'][$option_name], $file)->parse(); |
|
1006 | + $tmp_files[] = $file; |
|
1007 | + } |
|
1008 | + } |
|
1009 | + else { |
|
1010 | + $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug][$option_name], $file)->parse(); |
|
1011 | + $tmp_files[] = $file; |
|
1012 | + } |
|
1013 | 1013 | |
1014 | 1014 | |
1015 | - } else { |
|
1016 | - $data[$option_name] = array_fill(0, $count, ""); |
|
1017 | - } |
|
1015 | + } else { |
|
1016 | + $data[$option_name] = array_fill(0, $count, ""); |
|
1017 | + } |
|
1018 | 1018 | |
1019 | - } |
|
1019 | + } |
|
1020 | 1020 | |
1021 | - foreach ($tmp_files as $file) { // remove all temporary files created |
|
1022 | - unlink($file); |
|
1023 | - } |
|
1021 | + foreach ($tmp_files as $file) { // remove all temporary files created |
|
1022 | + unlink($file); |
|
1023 | + } |
|
1024 | 1024 | |
1025 | - } |
|
1025 | + } |
|
1026 | 1026 | |
1027 | - return $data; |
|
1028 | - } |
|
1027 | + return $data; |
|
1028 | + } |
|
1029 | 1029 | |
1030 | 1030 | |
1031 | - function can_update_meta($meta_key, $import_options) { |
|
1031 | + function can_update_meta($meta_key, $import_options) { |
|
1032 | 1032 | |
1033 | - //echo "<pre>"; |
|
1034 | - //print_r($import_options['options']); |
|
1035 | - //echo "</pre>"; |
|
1033 | + //echo "<pre>"; |
|
1034 | + //print_r($import_options['options']); |
|
1035 | + //echo "</pre>"; |
|
1036 | 1036 | |
1037 | - $import_options = $import_options['options']; |
|
1037 | + $import_options = $import_options['options']; |
|
1038 | 1038 | |
1039 | - if ($import_options['update_all_data'] == 'yes') return true; |
|
1039 | + if ($import_options['update_all_data'] == 'yes') return true; |
|
1040 | 1040 | |
1041 | - if ( ! $import_options['is_update_custom_fields'] ) return false; |
|
1041 | + if ( ! $import_options['is_update_custom_fields'] ) return false; |
|
1042 | 1042 | |
1043 | - if ($import_options['update_custom_fields_logic'] == "full_update") return true; |
|
1044 | - if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) return true; |
|
1045 | - if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) return true; |
|
1043 | + if ($import_options['update_custom_fields_logic'] == "full_update") return true; |
|
1044 | + if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) return true; |
|
1045 | + if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) return true; |
|
1046 | 1046 | |
1047 | - return false; |
|
1047 | + return false; |
|
1048 | 1048 | |
1049 | - } |
|
1049 | + } |
|
1050 | 1050 | |
1051 | - function can_update_taxonomy($tax_name, $import_options) { |
|
1051 | + function can_update_taxonomy($tax_name, $import_options) { |
|
1052 | 1052 | |
1053 | - //echo "<pre>"; |
|
1054 | - //print_r($import_options['options']); |
|
1055 | - //echo "</pre>"; |
|
1053 | + //echo "<pre>"; |
|
1054 | + //print_r($import_options['options']); |
|
1055 | + //echo "</pre>"; |
|
1056 | 1056 | |
1057 | - $import_options = $import_options['options']; |
|
1057 | + $import_options = $import_options['options']; |
|
1058 | 1058 | |
1059 | - if ($import_options['update_all_data'] == 'yes') return true; |
|
1059 | + if ($import_options['update_all_data'] == 'yes') return true; |
|
1060 | 1060 | |
1061 | - if ( ! $import_options['is_update_categories'] ) return false; |
|
1061 | + if ( ! $import_options['is_update_categories'] ) return false; |
|
1062 | 1062 | |
1063 | - if ($import_options['update_categories_logic'] == "full_update") return true; |
|
1064 | - if ($import_options['update_categories_logic'] == "only" and ! empty($import_options['taxonomies_list']) and is_array($import_options['taxonomies_list']) and in_array($tax_name, $import_options['taxonomies_list']) ) return true; |
|
1065 | - if ($import_options['update_categories_logic'] == "all_except" and ( empty($import_options['taxonomies_list']) or ! in_array($tax_name, $import_options['taxonomies_list']) )) return true; |
|
1063 | + if ($import_options['update_categories_logic'] == "full_update") return true; |
|
1064 | + if ($import_options['update_categories_logic'] == "only" and ! empty($import_options['taxonomies_list']) and is_array($import_options['taxonomies_list']) and in_array($tax_name, $import_options['taxonomies_list']) ) return true; |
|
1065 | + if ($import_options['update_categories_logic'] == "all_except" and ( empty($import_options['taxonomies_list']) or ! in_array($tax_name, $import_options['taxonomies_list']) )) return true; |
|
1066 | 1066 | |
1067 | - return false; |
|
1067 | + return false; |
|
1068 | 1068 | |
1069 | - } |
|
1069 | + } |
|
1070 | 1070 | |
1071 | - function can_update_image($import_options) { |
|
1071 | + function can_update_image($import_options) { |
|
1072 | 1072 | |
1073 | - $import_options = $import_options['options']; |
|
1073 | + $import_options = $import_options['options']; |
|
1074 | 1074 | |
1075 | - if ($import_options['update_all_data'] == 'yes') return true; |
|
1075 | + if ($import_options['update_all_data'] == 'yes') return true; |
|
1076 | 1076 | |
1077 | - if (!$import_options['is_update_images']) return false; |
|
1077 | + if (!$import_options['is_update_images']) return false; |
|
1078 | 1078 | |
1079 | - if ($import_options['is_update_images']) return true; |
|
1079 | + if ($import_options['is_update_images']) return true; |
|
1080 | 1080 | |
1081 | - return false; |
|
1082 | - } |
|
1081 | + return false; |
|
1082 | + } |
|
1083 | 1083 | |
1084 | 1084 | |
1085 | - function admin_notice_ignore() { |
|
1086 | - if (isset($_GET[$this->slug.'_ignore']) && '0' == $_GET[$this->slug.'_ignore'] ) { |
|
1087 | - update_option($this->slug.'_ignore', 'true'); |
|
1088 | - } |
|
1089 | - } |
|
1085 | + function admin_notice_ignore() { |
|
1086 | + if (isset($_GET[$this->slug.'_ignore']) && '0' == $_GET[$this->slug.'_ignore'] ) { |
|
1087 | + update_option($this->slug.'_ignore', 'true'); |
|
1088 | + } |
|
1089 | + } |
|
1090 | 1090 | |
1091 | - function display_admin_notice() { |
|
1091 | + function display_admin_notice() { |
|
1092 | 1092 | |
1093 | 1093 | |
1094 | - if ($this->notice_text) { |
|
1095 | - $notice_text = $this->notice_text; |
|
1096 | - } else { |
|
1097 | - $notice_text = $this->name.' requires WP All Import <a href="http://www.wpallimport.com/" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>.'; |
|
1098 | - } |
|
1094 | + if ($this->notice_text) { |
|
1095 | + $notice_text = $this->notice_text; |
|
1096 | + } else { |
|
1097 | + $notice_text = $this->name.' requires WP All Import <a href="http://www.wpallimport.com/" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>.'; |
|
1098 | + } |
|
1099 | 1099 | |
1100 | - if (!get_option(sanitize_key($this->slug).'_notice_ignore')) { |
|
1100 | + if (!get_option(sanitize_key($this->slug).'_notice_ignore')) { |
|
1101 | 1101 | |
1102 | - ?> |
|
1102 | + ?> |
|
1103 | 1103 | |
1104 | 1104 | <div class="error notice is-dismissible wpallimport-dismissible" style="margin-top: 10px;" rel="<?php echo sanitize_key($this->slug); ?>"> |
1105 | 1105 | <p><?php _e( |
1106 | - sprintf( |
|
1107 | - $notice_text, |
|
1108 | - '?'.$this->slug.'_ignore=0' |
|
1109 | - ), |
|
1110 | - 'rapid_addon_'.$this->slug |
|
1111 | - ); ?></p> |
|
1106 | + sprintf( |
|
1107 | + $notice_text, |
|
1108 | + '?'.$this->slug.'_ignore=0' |
|
1109 | + ), |
|
1110 | + 'rapid_addon_'.$this->slug |
|
1111 | + ); ?></p> |
|
1112 | 1112 | </div> |
1113 | 1113 | |
1114 | 1114 | <?php |
1115 | 1115 | |
1116 | - } |
|
1116 | + } |
|
1117 | 1117 | |
1118 | - } |
|
1118 | + } |
|
1119 | 1119 | |
1120 | - /* |
|
1120 | + /* |
|
1121 | 1121 | * |
1122 | 1122 | * $conditions - array('themes' => array('Realia'), 'plugins' => array('plugin-directory/plugin-file.php', 'plugin-directory2/plugin-file.php')) |
1123 | 1123 | * |
1124 | 1124 | */ |
1125 | - function admin_notice($notice_text = '', $conditions = array()) { |
|
1125 | + function admin_notice($notice_text = '', $conditions = array()) { |
|
1126 | 1126 | |
1127 | - $is_show_notice = false; |
|
1127 | + $is_show_notice = false; |
|
1128 | 1128 | |
1129 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
1129 | + include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
1130 | 1130 | |
1131 | - if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
1132 | - $is_show_notice = true; |
|
1133 | - } |
|
1131 | + if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
1132 | + $is_show_notice = true; |
|
1133 | + } |
|
1134 | 1134 | |
1135 | - // Supported Themes |
|
1136 | - if ( ! $is_show_notice and ! empty($conditions['themes']) ){ |
|
1135 | + // Supported Themes |
|
1136 | + if ( ! $is_show_notice and ! empty($conditions['themes']) ){ |
|
1137 | 1137 | |
1138 | - $themeInfo = wp_get_theme(); |
|
1139 | - $parentInfo = $themeInfo->parent(); |
|
1140 | - $currentTheme = $themeInfo->get('Name'); |
|
1138 | + $themeInfo = wp_get_theme(); |
|
1139 | + $parentInfo = $themeInfo->parent(); |
|
1140 | + $currentTheme = $themeInfo->get('Name'); |
|
1141 | 1141 | |
1142 | - $is_show_notice = in_array($currentTheme, $conditions['themes']) ? false : true; |
|
1142 | + $is_show_notice = in_array($currentTheme, $conditions['themes']) ? false : true; |
|
1143 | 1143 | |
1144 | - if ( $is_show_notice and $parentInfo ){ |
|
1145 | - $parent_theme = $parentInfo->get('Name'); |
|
1146 | - $is_show_notice = in_array($parent_theme, $conditions['themes']) ? false : true; |
|
1147 | - } |
|
1144 | + if ( $is_show_notice and $parentInfo ){ |
|
1145 | + $parent_theme = $parentInfo->get('Name'); |
|
1146 | + $is_show_notice = in_array($parent_theme, $conditions['themes']) ? false : true; |
|
1147 | + } |
|
1148 | 1148 | |
1149 | - } |
|
1149 | + } |
|
1150 | 1150 | |
1151 | - // Required Plugins |
|
1152 | - if ( ! $is_show_notice and ! empty($conditions['plugins']) ){ |
|
1151 | + // Required Plugins |
|
1152 | + if ( ! $is_show_notice and ! empty($conditions['plugins']) ){ |
|
1153 | 1153 | |
1154 | - $requires_counter = 0; |
|
1155 | - foreach ($conditions['plugins'] as $plugin) { |
|
1156 | - if ( is_plugin_active($plugin) ) $requires_counter++; |
|
1157 | - } |
|
1154 | + $requires_counter = 0; |
|
1155 | + foreach ($conditions['plugins'] as $plugin) { |
|
1156 | + if ( is_plugin_active($plugin) ) $requires_counter++; |
|
1157 | + } |
|
1158 | 1158 | |
1159 | - if ($requires_counter != count($conditions['plugins'])){ |
|
1160 | - $is_show_notice = true; |
|
1161 | - } |
|
1159 | + if ($requires_counter != count($conditions['plugins'])){ |
|
1160 | + $is_show_notice = true; |
|
1161 | + } |
|
1162 | 1162 | |
1163 | - } |
|
1163 | + } |
|
1164 | 1164 | |
1165 | - if ( $is_show_notice ){ |
|
1165 | + if ( $is_show_notice ){ |
|
1166 | 1166 | |
1167 | - if ( $notice_text != '' ) { |
|
1168 | - $this->notice_text = $notice_text; |
|
1169 | - } |
|
1167 | + if ( $notice_text != '' ) { |
|
1168 | + $this->notice_text = $notice_text; |
|
1169 | + } |
|
1170 | 1170 | |
1171 | - add_action('admin_notices', array($this, 'display_admin_notice')); |
|
1172 | - } |
|
1171 | + add_action('admin_notices', array($this, 'display_admin_notice')); |
|
1172 | + } |
|
1173 | 1173 | |
1174 | - } |
|
1174 | + } |
|
1175 | 1175 | |
1176 | - function log( $m = false){ |
|
1176 | + function log( $m = false){ |
|
1177 | 1177 | |
1178 | - $m and $this->logger and call_user_func($this->logger, $m); |
|
1178 | + $m and $this->logger and call_user_func($this->logger, $m); |
|
1179 | 1179 | |
1180 | 1180 | } |
1181 | 1181 | |
@@ -1293,5 +1293,5 @@ discard block |
||
1293 | 1293 | } |
1294 | 1294 | return $image; |
1295 | 1295 | } |
1296 | - } |
|
1296 | + } |
|
1297 | 1297 | } |
1298 | 1298 | \ No newline at end of file |
@@ -14,133 +14,133 @@ |
||
14 | 14 | */ |
15 | 15 | class GetPaid_WP_All_Import { |
16 | 16 | |
17 | - /** |
|
18 | - * @var RapidAddon[] |
|
19 | - */ |
|
20 | - protected $add_ons; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $datastores = array( |
|
26 | - 'item' =>'WPInv_Item', |
|
27 | - 'invoice' =>'WPInv_Invoice', |
|
28 | - 'discount' =>'WPInv_Discount', |
|
29 | - ); |
|
17 | + /** |
|
18 | + * @var RapidAddon[] |
|
19 | + */ |
|
20 | + protected $add_ons; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $datastores = array( |
|
26 | + 'item' =>'WPInv_Item', |
|
27 | + 'invoice' =>'WPInv_Invoice', |
|
28 | + 'discount' =>'WPInv_Discount', |
|
29 | + ); |
|
30 | 30 | |
31 | 31 | /** |
32 | - * Class constructor. |
|
33 | - */ |
|
32 | + * Class constructor. |
|
33 | + */ |
|
34 | 34 | public function __construct() { |
35 | 35 | |
36 | - // Init each store separately. |
|
37 | - foreach ( array_keys( $this->datastores ) as $key ) { |
|
38 | - $this->init_store( $key ); |
|
39 | - } |
|
36 | + // Init each store separately. |
|
37 | + foreach ( array_keys( $this->datastores ) as $key ) { |
|
38 | + $this->init_store( $key ); |
|
39 | + } |
|
40 | 40 | |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Inits a store. |
|
45 | - */ |
|
43 | + /** |
|
44 | + * Inits a store. |
|
45 | + */ |
|
46 | 46 | public function init_store( $key ) { |
47 | 47 | |
48 | - // Register the add-on. |
|
49 | - $this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key ); |
|
48 | + // Register the add-on. |
|
49 | + $this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key ); |
|
50 | 50 | |
51 | - // Create import function. |
|
52 | - $import_function = function ( $post_id, $data, $import_options, $_post ) use ( $key ) { |
|
53 | - $this->import_store( $key, $post_id, $data, $import_options, $_post ); |
|
51 | + // Create import function. |
|
52 | + $import_function = function ( $post_id, $data, $import_options, $_post ) use ( $key ) { |
|
53 | + $this->import_store( $key, $post_id, $data, $import_options, $_post ); |
|
54 | 54 | }; |
55 | 55 | |
56 | - $this->add_ons[ $key ]->set_import_function( $import_function ); |
|
56 | + $this->add_ons[ $key ]->set_import_function( $import_function ); |
|
57 | 57 | |
58 | - // Register store fields. |
|
59 | - $this->add_store_fields( $key ); |
|
58 | + // Register store fields. |
|
59 | + $this->add_store_fields( $key ); |
|
60 | 60 | |
61 | - // Only load on the correct post type. |
|
62 | - $this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) ); |
|
61 | + // Only load on the correct post type. |
|
62 | + $this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) ); |
|
63 | 63 | |
64 | - // Disable images. |
|
65 | - $this->add_ons[ $key ]->disable_default_images(); |
|
64 | + // Disable images. |
|
65 | + $this->add_ons[ $key ]->disable_default_images(); |
|
66 | 66 | |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Retrieves store fields. |
|
71 | - */ |
|
69 | + /** |
|
70 | + * Retrieves store fields. |
|
71 | + */ |
|
72 | 72 | public function get_store_fields( $key ) { |
73 | 73 | |
74 | - // Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php |
|
75 | - $fields = wpinv_get_data( $key . '-schema' ); |
|
74 | + // Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php |
|
75 | + $fields = wpinv_get_data( $key . '-schema' ); |
|
76 | 76 | |
77 | - if ( empty( $fields ) ) { |
|
78 | - return array(); |
|
79 | - } |
|
77 | + if ( empty( $fields ) ) { |
|
78 | + return array(); |
|
79 | + } |
|
80 | 80 | |
81 | - // Clean the fields. |
|
82 | - $prepared = array(); |
|
83 | - foreach ( $fields as $id => $field ) { |
|
81 | + // Clean the fields. |
|
82 | + $prepared = array(); |
|
83 | + foreach ( $fields as $id => $field ) { |
|
84 | 84 | |
85 | - // Skip read only fields. |
|
86 | - if ( ! empty( $field['readonly'] ) ) { |
|
87 | - continue; |
|
88 | - } |
|
85 | + // Skip read only fields. |
|
86 | + if ( ! empty( $field['readonly'] ) ) { |
|
87 | + continue; |
|
88 | + } |
|
89 | 89 | |
90 | - $prepared[ $id ] = $field; |
|
90 | + $prepared[ $id ] = $field; |
|
91 | 91 | |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - return $prepared; |
|
94 | + return $prepared; |
|
95 | 95 | |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Registers store fields. |
|
100 | - */ |
|
98 | + /** |
|
99 | + * Registers store fields. |
|
100 | + */ |
|
101 | 101 | public function add_store_fields( $key ) { |
102 | 102 | |
103 | - foreach ( $this->get_store_fields( $key ) as $field_id => $data ) { |
|
104 | - $this->add_ons[ $key ]->add_field( $field_id, $data['description'], 'text' ); |
|
105 | - } |
|
103 | + foreach ( $this->get_store_fields( $key ) as $field_id => $data ) { |
|
104 | + $this->add_ons[ $key ]->add_field( $field_id, $data['description'], 'text' ); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * Handles store imports. |
|
111 | - */ |
|
109 | + /** |
|
110 | + * Handles store imports. |
|
111 | + */ |
|
112 | 112 | public function import_store( $key, $post_id, $data, $import_options, $_post ) { |
113 | 113 | |
114 | - // Is the store class set? |
|
115 | - if ( ! isset( $this->datastores[ $key ] ) ) { |
|
116 | - return; |
|
117 | - } |
|
114 | + // Is the store class set? |
|
115 | + if ( ! isset( $this->datastores[ $key ] ) ) { |
|
116 | + return; |
|
117 | + } |
|
118 | 118 | |
119 | - /**@var GetPaid_Data */ |
|
120 | - $data_store = new $this->datastores[ $key ]( $post_id ); |
|
119 | + /**@var GetPaid_Data */ |
|
120 | + $data_store = new $this->datastores[ $key ]( $post_id ); |
|
121 | 121 | |
122 | - // Abort if the invoice/item/discount does not exist. |
|
123 | - if ( ! $data_store->exists() ) { |
|
124 | - return; |
|
125 | - } |
|
122 | + // Abort if the invoice/item/discount does not exist. |
|
123 | + if ( ! $data_store->exists() ) { |
|
124 | + return; |
|
125 | + } |
|
126 | 126 | |
127 | - // Prepare data props. |
|
128 | - $prepared = array(); |
|
127 | + // Prepare data props. |
|
128 | + $prepared = array(); |
|
129 | 129 | |
130 | - foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { |
|
131 | - // Make sure the user has allowed this field to be updated. |
|
132 | - if ( empty( $_post['ID'] ) || $this->add_ons[ $key ]->can_update_meta( $field, $import_options ) ) { |
|
130 | + foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { |
|
131 | + // Make sure the user has allowed this field to be updated. |
|
132 | + if ( empty( $_post['ID'] ) || $this->add_ons[ $key ]->can_update_meta( $field, $import_options ) ) { |
|
133 | 133 | |
134 | - // Update the custom field with the imported data. |
|
135 | - $prepared[ $field ] = $data[ $field ]; |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - // Only update if we have something to update. |
|
140 | - if ( ! empty( $prepared ) ) { |
|
141 | - $data_store->set_props( $prepared ); |
|
142 | - $data_store->save(); |
|
143 | - } |
|
134 | + // Update the custom field with the imported data. |
|
135 | + $prepared[ $field ] = $data[ $field ]; |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + // Only update if we have something to update. |
|
140 | + if ( ! empty( $prepared ) ) { |
|
141 | + $data_store->set_props( $prepared ); |
|
142 | + $data_store->save(); |
|
143 | + } |
|
144 | 144 | |
145 | 145 | } |
146 | 146 |
@@ -12,294 +12,294 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
14 | 14 | |
15 | - /** |
|
16 | - * Contains the response for refreshing prices. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $response = array(); |
|
15 | + /** |
|
16 | + * Contains the response for refreshing prices. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $response = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $this->response = array( |
|
29 | - 'submission_id' => $submission->id, |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $this->response = array( |
|
29 | + 'submission_id' => $submission->id, |
|
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | - 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | - 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
31 | + 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | + 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
33 | 33 | 'is_free' => ! $submission->should_collect_payment_details(), |
34 | - ); |
|
35 | - |
|
36 | - $this->add_totals( $submission ); |
|
37 | - $this->add_texts( $submission ); |
|
38 | - $this->add_items( $submission ); |
|
39 | - $this->add_fees( $submission ); |
|
40 | - $this->add_discounts( $submission ); |
|
41 | - $this->add_taxes( $submission ); |
|
42 | - $this->add_gateways( $submission ); |
|
43 | - $this->add_data( $submission ); |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Adds totals to a response for submission refresh prices. |
|
49 | - * |
|
50 | - * @param GetPaid_Payment_Form_Submission $submission |
|
51 | - */ |
|
52 | - public function add_totals( $submission ) { |
|
53 | - |
|
54 | - $this->response = array_merge( |
|
55 | - $this->response, |
|
56 | - array( |
|
57 | - |
|
58 | - 'totals' => array( |
|
59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
65 | - ), |
|
66 | - |
|
67 | - 'recurring' => array( |
|
68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
73 | - ), |
|
74 | - |
|
75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
76 | - 'currency' => $submission->get_currency(), |
|
77 | - |
|
78 | - ) |
|
79 | - ); |
|
80 | - |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Adds texts to a response for submission refresh prices. |
|
85 | - * |
|
86 | - * @param GetPaid_Payment_Form_Submission $submission |
|
87 | - */ |
|
88 | - public function add_texts( $submission ) { |
|
89 | - |
|
90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
92 | - |
|
93 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
94 | - |
|
95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
97 | - $main_item = reset( $groups ); |
|
98 | - |
|
99 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
100 | - $payable = "$payable / $period"; |
|
101 | - } else if ( $main_item ) { |
|
102 | - |
|
103 | - $main_item = reset( $main_item ); |
|
104 | - |
|
105 | - // Calculate the next renewal date. |
|
106 | - $_period = $main_item->get_recurring_period( true ); |
|
107 | - $_interval = $main_item->get_recurring_interval(); |
|
108 | - |
|
109 | - // If the subscription item has a trial period... |
|
110 | - if ( $main_item->has_free_trial() ) { |
|
111 | - $_period = $main_item->get_trial_period( true ); |
|
112 | - $_interval = $main_item->get_trial_interval(); |
|
113 | - } |
|
114 | - |
|
115 | - $payable = sprintf( |
|
116 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
117 | - $submission->format_amount( $submission->get_total() ), |
|
118 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
119 | - $period |
|
120 | - ); |
|
121 | - |
|
122 | - $payable .= sprintf( |
|
123 | - '<small class="text-muted form-text">%s</small>', |
|
124 | - sprintf( |
|
125 | - __( 'First renewal on %s', 'invoicing' ), |
|
126 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
127 | - ) |
|
128 | - ); |
|
129 | - |
|
130 | - } else { |
|
131 | - $payable = sprintf( |
|
132 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
133 | - $submission->format_amount( $submission->get_total() ), |
|
134 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
135 | - $period |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - } |
|
140 | - |
|
141 | - $texts = array( |
|
142 | - '.getpaid-checkout-total-payable' => $payable, |
|
143 | - ); |
|
144 | - |
|
145 | - foreach ( $submission->get_items() as $item ) { |
|
146 | - $item_id = $item->get_id(); |
|
147 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
148 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
149 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
150 | - $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
151 | - |
|
152 | - if ( $item->get_quantity() == 1 ) { |
|
153 | - $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = ''; |
|
154 | - } |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
159 | - |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Adds items to a response for submission refresh prices. |
|
164 | - * |
|
165 | - * @param GetPaid_Payment_Form_Submission $submission |
|
166 | - */ |
|
167 | - public function add_items( $submission ) { |
|
168 | - |
|
169 | - // Add items. |
|
170 | - $items = array(); |
|
34 | + ); |
|
35 | + |
|
36 | + $this->add_totals( $submission ); |
|
37 | + $this->add_texts( $submission ); |
|
38 | + $this->add_items( $submission ); |
|
39 | + $this->add_fees( $submission ); |
|
40 | + $this->add_discounts( $submission ); |
|
41 | + $this->add_taxes( $submission ); |
|
42 | + $this->add_gateways( $submission ); |
|
43 | + $this->add_data( $submission ); |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Adds totals to a response for submission refresh prices. |
|
49 | + * |
|
50 | + * @param GetPaid_Payment_Form_Submission $submission |
|
51 | + */ |
|
52 | + public function add_totals( $submission ) { |
|
53 | + |
|
54 | + $this->response = array_merge( |
|
55 | + $this->response, |
|
56 | + array( |
|
57 | + |
|
58 | + 'totals' => array( |
|
59 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
60 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
61 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
62 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
63 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
64 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
65 | + ), |
|
66 | + |
|
67 | + 'recurring' => array( |
|
68 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
69 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
70 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
71 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
72 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
73 | + ), |
|
74 | + |
|
75 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
76 | + 'currency' => $submission->get_currency(), |
|
77 | + |
|
78 | + ) |
|
79 | + ); |
|
80 | + |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Adds texts to a response for submission refresh prices. |
|
85 | + * |
|
86 | + * @param GetPaid_Payment_Form_Submission $submission |
|
87 | + */ |
|
88 | + public function add_texts( $submission ) { |
|
89 | + |
|
90 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
91 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
92 | + |
|
93 | + if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
94 | + |
|
95 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
96 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
97 | + $main_item = reset( $groups ); |
|
98 | + |
|
99 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
100 | + $payable = "$payable / $period"; |
|
101 | + } else if ( $main_item ) { |
|
102 | + |
|
103 | + $main_item = reset( $main_item ); |
|
104 | + |
|
105 | + // Calculate the next renewal date. |
|
106 | + $_period = $main_item->get_recurring_period( true ); |
|
107 | + $_interval = $main_item->get_recurring_interval(); |
|
108 | + |
|
109 | + // If the subscription item has a trial period... |
|
110 | + if ( $main_item->has_free_trial() ) { |
|
111 | + $_period = $main_item->get_trial_period( true ); |
|
112 | + $_interval = $main_item->get_trial_interval(); |
|
113 | + } |
|
114 | + |
|
115 | + $payable = sprintf( |
|
116 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
117 | + $submission->format_amount( $submission->get_total() ), |
|
118 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
119 | + $period |
|
120 | + ); |
|
121 | + |
|
122 | + $payable .= sprintf( |
|
123 | + '<small class="text-muted form-text">%s</small>', |
|
124 | + sprintf( |
|
125 | + __( 'First renewal on %s', 'invoicing' ), |
|
126 | + getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
127 | + ) |
|
128 | + ); |
|
129 | + |
|
130 | + } else { |
|
131 | + $payable = sprintf( |
|
132 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
133 | + $submission->format_amount( $submission->get_total() ), |
|
134 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
135 | + $period |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + } |
|
140 | + |
|
141 | + $texts = array( |
|
142 | + '.getpaid-checkout-total-payable' => $payable, |
|
143 | + ); |
|
144 | + |
|
145 | + foreach ( $submission->get_items() as $item ) { |
|
146 | + $item_id = $item->get_id(); |
|
147 | + $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
148 | + $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
149 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
150 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
151 | + |
|
152 | + if ( $item->get_quantity() == 1 ) { |
|
153 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = ''; |
|
154 | + } |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
159 | + |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Adds items to a response for submission refresh prices. |
|
164 | + * |
|
165 | + * @param GetPaid_Payment_Form_Submission $submission |
|
166 | + */ |
|
167 | + public function add_items( $submission ) { |
|
168 | + |
|
169 | + // Add items. |
|
170 | + $items = array(); |
|
171 | 171 | |
172 | 172 | foreach ( $submission->get_items() as $item ) { |
173 | - $item_id = $item->get_id(); |
|
174 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
175 | - } |
|
173 | + $item_id = $item->get_id(); |
|
174 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
175 | + } |
|
176 | 176 | |
177 | - $this->response = array_merge( |
|
178 | - $this->response, |
|
179 | - array( 'items' => $items ) |
|
180 | - ); |
|
177 | + $this->response = array_merge( |
|
178 | + $this->response, |
|
179 | + array( 'items' => $items ) |
|
180 | + ); |
|
181 | 181 | |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Adds fees to a response for submission refresh prices. |
|
186 | - * |
|
187 | - * @param GetPaid_Payment_Form_Submission $submission |
|
188 | - */ |
|
189 | - public function add_fees( $submission ) { |
|
184 | + /** |
|
185 | + * Adds fees to a response for submission refresh prices. |
|
186 | + * |
|
187 | + * @param GetPaid_Payment_Form_Submission $submission |
|
188 | + */ |
|
189 | + public function add_fees( $submission ) { |
|
190 | 190 | |
191 | - $fees = array(); |
|
191 | + $fees = array(); |
|
192 | 192 | |
193 | 193 | foreach ( $submission->get_fees() as $name => $data ) { |
194 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
195 | - } |
|
194 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
195 | + } |
|
196 | 196 | |
197 | - $this->response = array_merge( |
|
198 | - $this->response, |
|
199 | - array( 'fees' => $fees ) |
|
200 | - ); |
|
197 | + $this->response = array_merge( |
|
198 | + $this->response, |
|
199 | + array( 'fees' => $fees ) |
|
200 | + ); |
|
201 | 201 | |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Adds discounts to a response for submission refresh prices. |
|
206 | - * |
|
207 | - * @param GetPaid_Payment_Form_Submission $submission |
|
208 | - */ |
|
209 | - public function add_discounts( $submission ) { |
|
204 | + /** |
|
205 | + * Adds discounts to a response for submission refresh prices. |
|
206 | + * |
|
207 | + * @param GetPaid_Payment_Form_Submission $submission |
|
208 | + */ |
|
209 | + public function add_discounts( $submission ) { |
|
210 | 210 | |
211 | - $discounts = array(); |
|
211 | + $discounts = array(); |
|
212 | 212 | |
213 | 213 | foreach ( $submission->get_discounts() as $name => $data ) { |
214 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
215 | - } |
|
214 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
215 | + } |
|
216 | 216 | |
217 | - $this->response = array_merge( |
|
218 | - $this->response, |
|
219 | - array( 'discounts' => $discounts ) |
|
220 | - ); |
|
217 | + $this->response = array_merge( |
|
218 | + $this->response, |
|
219 | + array( 'discounts' => $discounts ) |
|
220 | + ); |
|
221 | 221 | |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Adds taxes to a response for submission refresh prices. |
|
226 | - * |
|
227 | - * @param GetPaid_Payment_Form_Submission $submission |
|
228 | - */ |
|
229 | - public function add_taxes( $submission ) { |
|
230 | - |
|
231 | - $taxes = array(); |
|
232 | - $markup = ''; |
|
224 | + /** |
|
225 | + * Adds taxes to a response for submission refresh prices. |
|
226 | + * |
|
227 | + * @param GetPaid_Payment_Form_Submission $submission |
|
228 | + */ |
|
229 | + public function add_taxes( $submission ) { |
|
230 | + |
|
231 | + $taxes = array(); |
|
232 | + $markup = ''; |
|
233 | 233 | foreach ( $submission->get_taxes() as $name => $data ) { |
234 | - $name = sanitize_text_field( $name ); |
|
235 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
236 | - $taxes[$name] = $amount; |
|
237 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
238 | - } |
|
239 | - |
|
240 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
241 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
242 | - } |
|
243 | - |
|
244 | - $this->response = array_merge( |
|
245 | - $this->response, |
|
246 | - array( 'taxes' => $taxes ) |
|
247 | - ); |
|
248 | - |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Adds gateways to a response for submission refresh prices. |
|
253 | - * |
|
254 | - * @param GetPaid_Payment_Form_Submission $submission |
|
255 | - */ |
|
256 | - public function add_gateways( $submission ) { |
|
257 | - |
|
258 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
259 | - |
|
260 | - if ( $this->response['has_recurring'] ) { |
|
261 | - |
|
262 | - foreach ( $gateways as $i => $gateway ) { |
|
263 | - |
|
264 | - if ( |
|
265 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
266 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
267 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
268 | - unset( $gateways[ $i ] ); |
|
269 | - } |
|
270 | - |
|
271 | - } |
|
272 | - |
|
273 | - } |
|
274 | - |
|
275 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
276 | - $this->response = array_merge( |
|
277 | - $this->response, |
|
278 | - array( 'gateways' => $gateways ) |
|
279 | - ); |
|
280 | - |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Adds data to a response for submission refresh prices. |
|
285 | - * |
|
286 | - * @param GetPaid_Payment_Form_Submission $submission |
|
287 | - */ |
|
288 | - public function add_data( $submission ) { |
|
289 | - |
|
290 | - $this->response = array_merge( |
|
291 | - $this->response, |
|
292 | - array( |
|
293 | - 'js_data' => apply_filters( |
|
294 | - 'getpaid_submission_js_data', |
|
295 | - array( |
|
296 | - 'is_recurring' => $this->response['has_recurring'], |
|
297 | - ), |
|
298 | - $submission |
|
299 | - ) |
|
300 | - ) |
|
301 | - ); |
|
302 | - |
|
303 | - } |
|
234 | + $name = sanitize_text_field( $name ); |
|
235 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
236 | + $taxes[$name] = $amount; |
|
237 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
238 | + } |
|
239 | + |
|
240 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
241 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
242 | + } |
|
243 | + |
|
244 | + $this->response = array_merge( |
|
245 | + $this->response, |
|
246 | + array( 'taxes' => $taxes ) |
|
247 | + ); |
|
248 | + |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Adds gateways to a response for submission refresh prices. |
|
253 | + * |
|
254 | + * @param GetPaid_Payment_Form_Submission $submission |
|
255 | + */ |
|
256 | + public function add_gateways( $submission ) { |
|
257 | + |
|
258 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
259 | + |
|
260 | + if ( $this->response['has_recurring'] ) { |
|
261 | + |
|
262 | + foreach ( $gateways as $i => $gateway ) { |
|
263 | + |
|
264 | + if ( |
|
265 | + ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
266 | + || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
267 | + || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
268 | + unset( $gateways[ $i ] ); |
|
269 | + } |
|
270 | + |
|
271 | + } |
|
272 | + |
|
273 | + } |
|
274 | + |
|
275 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
276 | + $this->response = array_merge( |
|
277 | + $this->response, |
|
278 | + array( 'gateways' => $gateways ) |
|
279 | + ); |
|
280 | + |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Adds data to a response for submission refresh prices. |
|
285 | + * |
|
286 | + * @param GetPaid_Payment_Form_Submission $submission |
|
287 | + */ |
|
288 | + public function add_data( $submission ) { |
|
289 | + |
|
290 | + $this->response = array_merge( |
|
291 | + $this->response, |
|
292 | + array( |
|
293 | + 'js_data' => apply_filters( |
|
294 | + 'getpaid_submission_js_data', |
|
295 | + array( |
|
296 | + 'is_recurring' => $this->response['has_recurring'], |
|
297 | + ), |
|
298 | + $submission |
|
299 | + ) |
|
300 | + ) |
|
301 | + ); |
|
302 | + |
|
303 | + } |
|
304 | 304 | |
305 | 305 | } |
@@ -13,96 +13,96 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
90 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
92 | 92 | |
93 | - parent::__construct(); |
|
93 | + parent::__construct(); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | - * Process Payment. |
|
98 | - * |
|
99 | - * |
|
100 | - * @param WPInv_Invoice $invoice Invoice. |
|
101 | - * @param array $submission_data Posted checkout fields. |
|
102 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
97 | + * Process Payment. |
|
98 | + * |
|
99 | + * |
|
100 | + * @param WPInv_Invoice $invoice Invoice. |
|
101 | + * @param array $submission_data Posted checkout fields. |
|
102 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
106 | 106 | |
107 | 107 | // Get redirect url. |
108 | 108 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get the PayPal request URL for an invoice. |
|
129 | - * |
|
130 | - * @param WPInv_Invoice $invoice Invoice object. |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function get_request_url( $invoice ) { |
|
128 | + * Get the PayPal request URL for an invoice. |
|
129 | + * |
|
130 | + * @param WPInv_Invoice $invoice Invoice object. |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function get_request_url( $invoice ) { |
|
134 | 134 | |
135 | 135 | // Endpoint for this request |
136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
136 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | 137 | |
138 | 138 | // Retrieve paypal args. |
139 | 139 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -146,45 +146,45 @@ discard block |
||
146 | 146 | |
147 | 147 | return add_query_arg( $paypal_args, $this->endpoint ); |
148 | 148 | |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | 151 | /** |
152 | - * Get PayPal Args for passing to PP. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - protected function get_paypal_args( $invoice ) { |
|
152 | + * Get PayPal Args for passing to PP. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + protected function get_paypal_args( $invoice ) { |
|
158 | 158 | |
159 | 159 | // Whether or not to send the line items as one item. |
160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | - |
|
162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | - $force_one_line_item = true; |
|
164 | - } |
|
165 | - |
|
166 | - $paypal_args = apply_filters( |
|
167 | - 'getpaid_paypal_args', |
|
168 | - array_merge( |
|
169 | - $this->get_transaction_args( $invoice ), |
|
170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | - ), |
|
172 | - $invoice |
|
173 | - ); |
|
174 | - |
|
175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
160 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | + |
|
162 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | + $force_one_line_item = true; |
|
164 | + } |
|
165 | + |
|
166 | + $paypal_args = apply_filters( |
|
167 | + 'getpaid_paypal_args', |
|
168 | + array_merge( |
|
169 | + $this->get_transaction_args( $invoice ), |
|
170 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | + ), |
|
172 | + $invoice |
|
173 | + ); |
|
174 | + |
|
175 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Get transaction args for paypal request. |
|
180 | - * |
|
181 | - * @param WPInv_Invoice $invoice Invoice object. |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - protected function get_transaction_args( $invoice ) { |
|
185 | - |
|
186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | - return array( |
|
179 | + * Get transaction args for paypal request. |
|
180 | + * |
|
181 | + * @param WPInv_Invoice $invoice Invoice object. |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + protected function get_transaction_args( $invoice ) { |
|
185 | + |
|
186 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | + return array( |
|
188 | 188 | 'cmd' => '_cart', |
189 | 189 | 'business' => $email, |
190 | 190 | 'no_shipping' => '1', |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get line item args for paypal request. |
|
213 | - * |
|
214 | - * @param WPInv_Invoice $invoice Invoice object. |
|
215 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | - * @return array |
|
217 | - */ |
|
218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
212 | + * Get line item args for paypal request. |
|
213 | + * |
|
214 | + * @param WPInv_Invoice $invoice Invoice object. |
|
215 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | + * @return array |
|
217 | + */ |
|
218 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | 219 | |
220 | 220 | // Maybe send invoice as a single item. |
221 | - if ( $force_one_line_item ) { |
|
221 | + if ( $force_one_line_item ) { |
|
222 | 222 | return $this->get_line_item_args_single_item( $invoice ); |
223 | 223 | } |
224 | 224 | |
@@ -238,129 +238,129 @@ discard block |
||
238 | 238 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
239 | 239 | } |
240 | 240 | |
241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
241 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | - * Get line item args for paypal request as a single line item. |
|
247 | - * |
|
248 | - * @param WPInv_Invoice $invoice Invoice object. |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
252 | - $this->delete_line_items(); |
|
246 | + * Get line item args for paypal request as a single line item. |
|
247 | + * |
|
248 | + * @param WPInv_Invoice $invoice Invoice object. |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function get_line_item_args_single_item( $invoice ) { |
|
252 | + $this->delete_line_items(); |
|
253 | 253 | |
254 | 254 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
255 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
256 | 256 | |
257 | - return $this->get_line_items(); |
|
257 | + return $this->get_line_items(); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Return all line items. |
|
262 | - */ |
|
263 | - protected function get_line_items() { |
|
264 | - return $this->line_items; |
|
265 | - } |
|
261 | + * Return all line items. |
|
262 | + */ |
|
263 | + protected function get_line_items() { |
|
264 | + return $this->line_items; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | - * Remove all line items. |
|
269 | - */ |
|
270 | - protected function delete_line_items() { |
|
271 | - $this->line_items = array(); |
|
268 | + * Remove all line items. |
|
269 | + */ |
|
270 | + protected function delete_line_items() { |
|
271 | + $this->line_items = array(); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Prepare line items to send to paypal. |
|
276 | - * |
|
277 | - * @param WPInv_Invoice $invoice Invoice object. |
|
278 | - */ |
|
279 | - protected function prepare_line_items( $invoice ) { |
|
280 | - $this->delete_line_items(); |
|
281 | - |
|
282 | - // Items. |
|
283 | - foreach ( $invoice->get_items() as $item ) { |
|
284 | - $amount = $item->get_price(); |
|
285 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
275 | + * Prepare line items to send to paypal. |
|
276 | + * |
|
277 | + * @param WPInv_Invoice $invoice Invoice object. |
|
278 | + */ |
|
279 | + protected function prepare_line_items( $invoice ) { |
|
280 | + $this->delete_line_items(); |
|
281 | + |
|
282 | + // Items. |
|
283 | + foreach ( $invoice->get_items() as $item ) { |
|
284 | + $amount = $item->get_price(); |
|
285 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fees. |
290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
290 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
291 | 291 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Add PayPal Line Item. |
|
298 | - * |
|
299 | - * @param string $item_name Item name. |
|
300 | - * @param float $quantity Item quantity. |
|
301 | - * @param float $amount Amount. |
|
302 | - * @param string $item_number Item number. |
|
303 | - */ |
|
304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | - |
|
307 | - $item = apply_filters( |
|
308 | - 'getpaid_paypal_line_item', |
|
309 | - array( |
|
310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | - 'quantity' => (float) $quantity, |
|
312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | - 'item_number' => $item_number, |
|
314 | - ), |
|
315 | - $item_name, |
|
316 | - $quantity, |
|
317 | - $amount, |
|
318 | - $item_number |
|
319 | - ); |
|
320 | - |
|
321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
297 | + * Add PayPal Line Item. |
|
298 | + * |
|
299 | + * @param string $item_name Item name. |
|
300 | + * @param float $quantity Item quantity. |
|
301 | + * @param float $amount Amount. |
|
302 | + * @param string $item_number Item number. |
|
303 | + */ |
|
304 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | + |
|
307 | + $item = apply_filters( |
|
308 | + 'getpaid_paypal_line_item', |
|
309 | + array( |
|
310 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | + 'quantity' => (float) $quantity, |
|
312 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | + 'item_number' => $item_number, |
|
314 | + ), |
|
315 | + $item_name, |
|
316 | + $quantity, |
|
317 | + $amount, |
|
318 | + $item_number |
|
319 | + ); |
|
320 | + |
|
321 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
322 | 322 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
323 | 323 | |
324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
325 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | - * |
|
332 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | - * |
|
334 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | - * @return array |
|
337 | - */ |
|
338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | - $max_paypal_length = 2083; |
|
340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | - |
|
342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | - return $paypal_args; |
|
344 | - } |
|
345 | - |
|
346 | - return apply_filters( |
|
347 | - 'getpaid_paypal_args', |
|
348 | - array_merge( |
|
349 | - $this->get_transaction_args( $invoice ), |
|
350 | - $this->get_line_item_args( $invoice, true ) |
|
351 | - ), |
|
352 | - $invoice |
|
353 | - ); |
|
330 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | + * |
|
332 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | + * |
|
334 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | + * @return array |
|
337 | + */ |
|
338 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | + $max_paypal_length = 2083; |
|
340 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | + |
|
342 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | + return $paypal_args; |
|
344 | + } |
|
345 | + |
|
346 | + return apply_filters( |
|
347 | + 'getpaid_paypal_args', |
|
348 | + array_merge( |
|
349 | + $this->get_transaction_args( $invoice ), |
|
350 | + $this->get_line_item_args( $invoice, true ) |
|
351 | + ), |
|
352 | + $invoice |
|
353 | + ); |
|
354 | 354 | |
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Processes recurring invoices. |
|
359 | - * |
|
360 | - * @param array $paypal_args PayPal args. |
|
361 | - * @param WPInv_Invoice $invoice Invoice object. |
|
362 | - */ |
|
363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
358 | + * Processes recurring invoices. |
|
359 | + * |
|
360 | + * @param array $paypal_args PayPal args. |
|
361 | + * @param WPInv_Invoice $invoice Invoice object. |
|
362 | + */ |
|
363 | + public function process_subscription( $paypal_args, $invoice ) { |
|
364 | 364 | |
365 | 365 | // Make sure this is a subscription. |
366 | 366 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -381,21 +381,21 @@ discard block |
||
381 | 381 | $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
382 | 382 | $subscription_item = $invoice->get_recurring( true ); |
383 | 383 | |
384 | - // Convert 365 days to 1 year. |
|
385 | - if ( 'D' == $period && 365 == $interval ) { |
|
386 | - $period = 'Y'; |
|
387 | - $interval = 1; |
|
388 | - } |
|
384 | + // Convert 365 days to 1 year. |
|
385 | + if ( 'D' == $period && 365 == $interval ) { |
|
386 | + $period = 'Y'; |
|
387 | + $interval = 1; |
|
388 | + } |
|
389 | 389 | |
390 | 390 | if ( $subscription_item->has_free_trial() ) { |
391 | 391 | |
392 | 392 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
393 | 393 | |
394 | - // Trial period length. |
|
395 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
394 | + // Trial period length. |
|
395 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
396 | 396 | |
397 | - // Trial period. |
|
398 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
397 | + // Trial period. |
|
398 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
399 | 399 | |
400 | 400 | } else if ( $initial_amount != $recurring_amount ) { |
401 | 401 | |
@@ -418,40 +418,40 @@ discard block |
||
418 | 418 | } |
419 | 419 | |
420 | 420 | // We have a recurring payment |
421 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
421 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
422 | 422 | |
423 | - // Subscription price |
|
424 | - $paypal_args['a3'] = $recurring_amount; |
|
423 | + // Subscription price |
|
424 | + $paypal_args['a3'] = $recurring_amount; |
|
425 | 425 | |
426 | - // Subscription duration |
|
427 | - $paypal_args['p3'] = $interval; |
|
426 | + // Subscription duration |
|
427 | + $paypal_args['p3'] = $interval; |
|
428 | 428 | |
429 | - // Subscription period |
|
430 | - $paypal_args['t3'] = $period; |
|
429 | + // Subscription period |
|
430 | + $paypal_args['t3'] = $period; |
|
431 | 431 | |
432 | 432 | } |
433 | 433 | |
434 | 434 | // Recurring payments |
435 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
435 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
436 | 436 | |
437 | - // Non-recurring payments |
|
438 | - $paypal_args['src'] = 0; |
|
437 | + // Non-recurring payments |
|
438 | + $paypal_args['src'] = 0; |
|
439 | 439 | |
440 | - } else { |
|
440 | + } else { |
|
441 | 441 | |
442 | - $paypal_args['src'] = 1; |
|
442 | + $paypal_args['src'] = 1; |
|
443 | 443 | |
444 | - if ( $bill_times > 0 ) { |
|
444 | + if ( $bill_times > 0 ) { |
|
445 | 445 | |
446 | - // An initial period is being used to charge a sign-up fee |
|
447 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
448 | - $bill_times--; |
|
449 | - } |
|
446 | + // An initial period is being used to charge a sign-up fee |
|
447 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
448 | + $bill_times--; |
|
449 | + } |
|
450 | 450 | |
451 | 451 | // Make sure it's not over the max of 52 |
452 | 452 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
453 | 453 | |
454 | - } |
|
454 | + } |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | // Force return URL so that order description & instructions display |
@@ -467,19 +467,19 @@ discard block |
||
467 | 467 | } |
468 | 468 | |
469 | 469 | return apply_filters( |
470 | - 'getpaid_paypal_subscription_args', |
|
471 | - $paypal_args, |
|
472 | - $invoice |
|
470 | + 'getpaid_paypal_subscription_args', |
|
471 | + $paypal_args, |
|
472 | + $invoice |
|
473 | 473 | ); |
474 | 474 | |
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
478 | - * Processes ipns and marks payments as complete. |
|
479 | - * |
|
480 | - * @return void |
|
481 | - */ |
|
482 | - public function verify_ipn() { |
|
478 | + * Processes ipns and marks payments as complete. |
|
479 | + * |
|
480 | + * @return void |
|
481 | + */ |
|
482 | + public function verify_ipn() { |
|
483 | 483 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
484 | 484 | } |
485 | 485 | |
@@ -489,19 +489,19 @@ discard block |
||
489 | 489 | public function sandbox_notice() { |
490 | 490 | |
491 | 491 | return sprintf( |
492 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
493 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
494 | - '</a>' |
|
495 | - ); |
|
492 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
493 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
494 | + '</a>' |
|
495 | + ); |
|
496 | 496 | |
497 | 497 | } |
498 | 498 | |
499 | - /** |
|
500 | - * Filters the gateway settings. |
|
501 | - * |
|
502 | - * @param array $admin_settings |
|
503 | - */ |
|
504 | - public function admin_settings( $admin_settings ) { |
|
499 | + /** |
|
500 | + * Filters the gateway settings. |
|
501 | + * |
|
502 | + * @param array $admin_settings |
|
503 | + */ |
|
504 | + public function admin_settings( $admin_settings ) { |
|
505 | 505 | |
506 | 506 | $currencies = sprintf( |
507 | 507 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -511,39 +511,39 @@ discard block |
||
511 | 511 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
512 | 512 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
513 | 513 | |
514 | - // Access tokens. |
|
515 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
516 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
517 | - |
|
518 | - $admin_settings['paypal_connect'] = array( |
|
519 | - 'type' => 'raw_html', |
|
520 | - 'id' => 'paypal_connect', |
|
521 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
522 | - 'desc' => sprintf( |
|
523 | - '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
524 | - esc_url( self::get_connect_url( false ) ), |
|
525 | - __( 'Connect to PayPal', 'invoicing' ), |
|
526 | - esc_url( self::get_connect_url( true ) ), |
|
527 | - __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
528 | - $this->get_js() |
|
529 | - ), |
|
530 | - ); |
|
514 | + // Access tokens. |
|
515 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
516 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
517 | + |
|
518 | + $admin_settings['paypal_connect'] = array( |
|
519 | + 'type' => 'raw_html', |
|
520 | + 'id' => 'paypal_connect', |
|
521 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
522 | + 'desc' => sprintf( |
|
523 | + '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
524 | + esc_url( self::get_connect_url( false ) ), |
|
525 | + __( 'Connect to PayPal', 'invoicing' ), |
|
526 | + esc_url( self::get_connect_url( true ) ), |
|
527 | + __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
528 | + $this->get_js() |
|
529 | + ), |
|
530 | + ); |
|
531 | 531 | |
532 | 532 | $admin_settings['paypal_email'] = array( |
533 | 533 | 'type' => 'text', |
534 | - 'class' => 'live-auth-data', |
|
534 | + 'class' => 'live-auth-data', |
|
535 | 535 | 'id' => 'paypal_email', |
536 | 536 | 'name' => __( 'Live Email Address', 'invoicing' ), |
537 | 537 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
538 | 538 | ); |
539 | 539 | |
540 | - $admin_settings['paypal_sandbox_email'] = array( |
|
540 | + $admin_settings['paypal_sandbox_email'] = array( |
|
541 | 541 | 'type' => 'text', |
542 | - 'class' => 'sandbox-auth-data', |
|
542 | + 'class' => 'sandbox-auth-data', |
|
543 | 543 | 'id' => 'paypal_sandbox_email', |
544 | 544 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
545 | 545 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
546 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
546 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
547 | 547 | ); |
548 | 548 | |
549 | 549 | $admin_settings['paypal_ipn_url'] = array( |
@@ -555,29 +555,29 @@ discard block |
||
555 | 555 | 'readonly' => true, |
556 | 556 | ); |
557 | 557 | |
558 | - return $admin_settings; |
|
559 | - } |
|
558 | + return $admin_settings; |
|
559 | + } |
|
560 | 560 | |
561 | - /** |
|
562 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
563 | - * |
|
564 | - * |
|
561 | + /** |
|
562 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
563 | + * |
|
564 | + * |
|
565 | 565 | * @param array $data |
566 | 566 | * @return string |
567 | - */ |
|
568 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
569 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Retrieves the PayPal connect URL. |
|
574 | - * |
|
575 | - * |
|
567 | + */ |
|
568 | + public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
569 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Retrieves the PayPal connect URL. |
|
574 | + * |
|
575 | + * |
|
576 | 576 | * @param bool $is_sandbox |
577 | - * @param string $redirect |
|
577 | + * @param string $redirect |
|
578 | 578 | * @return string |
579 | - */ |
|
580 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
579 | + */ |
|
580 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
581 | 581 | |
582 | 582 | $redirect_url = add_query_arg( |
583 | 583 | array( |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | 'tab' => 'gateways', |
588 | 588 | 'section' => 'paypal', |
589 | 589 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
590 | - 'redirect' => urlencode( $redirect ), |
|
590 | + 'redirect' => urlencode( $redirect ), |
|
591 | 591 | ), |
592 | 592 | admin_url( 'admin.php' ) |
593 | 593 | ); |
@@ -602,12 +602,12 @@ discard block |
||
602 | 602 | |
603 | 603 | } |
604 | 604 | |
605 | - /** |
|
606 | - * Generates settings page js. |
|
607 | - * |
|
605 | + /** |
|
606 | + * Generates settings page js. |
|
607 | + * |
|
608 | 608 | * @return void |
609 | - */ |
|
610 | - public static function get_js() { |
|
609 | + */ |
|
610 | + public static function get_js() { |
|
611 | 611 | ob_start(); |
612 | 612 | ?> |
613 | 613 | <script> |
@@ -643,72 +643,72 @@ discard block |
||
643 | 643 | return ob_get_clean(); |
644 | 644 | } |
645 | 645 | |
646 | - /** |
|
647 | - * Connects to PayPal. |
|
648 | - * |
|
649 | - * @param array $data Connection data. |
|
650 | - * @return void |
|
651 | - */ |
|
652 | - public function connect_paypal( $data ) { |
|
653 | - |
|
654 | - $sandbox = $this->is_sandbox(); |
|
655 | - $data = wp_unslash( $data ); |
|
656 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
657 | - |
|
658 | - if ( isset( $data['live_mode'] ) ) { |
|
659 | - $sandbox = empty( $data['live_mode'] ); |
|
660 | - } |
|
661 | - |
|
662 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
663 | - wpinv_update_option( 'paypal_active', 1 ); |
|
664 | - |
|
665 | - if ( ! empty( $data['error_description'] ) ) { |
|
666 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
667 | - } else { |
|
668 | - |
|
669 | - // Retrieve the user info. |
|
670 | - $user_info = wp_remote_get( |
|
671 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
672 | - array( |
|
673 | - |
|
674 | - 'headers' => array( |
|
675 | - 'Authorization' => 'Bearer ' . $access_token, |
|
676 | - 'Content-type' => 'application/json', |
|
677 | - ) |
|
678 | - |
|
679 | - ) |
|
680 | - ); |
|
681 | - |
|
682 | - if ( is_wp_error( $user_info ) ) { |
|
683 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
684 | - } else { |
|
685 | - |
|
686 | - // Create application. |
|
687 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
688 | - |
|
689 | - if ( $sandbox ) { |
|
690 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
691 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
692 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
693 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
694 | - } else { |
|
695 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
696 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
697 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
698 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
699 | - } |
|
700 | - |
|
701 | - } |
|
702 | - |
|
703 | - } |
|
704 | - |
|
705 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
706 | - |
|
707 | - if ( isset( $data['step'] ) ) { |
|
708 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
709 | - } |
|
710 | - wp_redirect( $redirect ); |
|
711 | - exit; |
|
712 | - } |
|
646 | + /** |
|
647 | + * Connects to PayPal. |
|
648 | + * |
|
649 | + * @param array $data Connection data. |
|
650 | + * @return void |
|
651 | + */ |
|
652 | + public function connect_paypal( $data ) { |
|
653 | + |
|
654 | + $sandbox = $this->is_sandbox(); |
|
655 | + $data = wp_unslash( $data ); |
|
656 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
657 | + |
|
658 | + if ( isset( $data['live_mode'] ) ) { |
|
659 | + $sandbox = empty( $data['live_mode'] ); |
|
660 | + } |
|
661 | + |
|
662 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
663 | + wpinv_update_option( 'paypal_active', 1 ); |
|
664 | + |
|
665 | + if ( ! empty( $data['error_description'] ) ) { |
|
666 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
667 | + } else { |
|
668 | + |
|
669 | + // Retrieve the user info. |
|
670 | + $user_info = wp_remote_get( |
|
671 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
672 | + array( |
|
673 | + |
|
674 | + 'headers' => array( |
|
675 | + 'Authorization' => 'Bearer ' . $access_token, |
|
676 | + 'Content-type' => 'application/json', |
|
677 | + ) |
|
678 | + |
|
679 | + ) |
|
680 | + ); |
|
681 | + |
|
682 | + if ( is_wp_error( $user_info ) ) { |
|
683 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
684 | + } else { |
|
685 | + |
|
686 | + // Create application. |
|
687 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
688 | + |
|
689 | + if ( $sandbox ) { |
|
690 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
691 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
692 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
693 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
694 | + } else { |
|
695 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
696 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
697 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
698 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
699 | + } |
|
700 | + |
|
701 | + } |
|
702 | + |
|
703 | + } |
|
704 | + |
|
705 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
706 | + |
|
707 | + if ( isset( $data['step'] ) ) { |
|
708 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
709 | + } |
|
710 | + wp_redirect( $redirect ); |
|
711 | + exit; |
|
712 | + } |
|
713 | 713 | |
714 | 714 | } |
@@ -15,31 +15,31 @@ discard block |
||
15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
16 | 16 | |
17 | 17 | /** |
18 | - * Class constructor. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
18 | + * Class constructor. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | 21 | parent::__construct(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | - * Returns the API URL. |
|
26 | - * |
|
27 | - * |
|
28 | - * @param WPInv_Invoice $invoice Invoice. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function get_api_url( $invoice ) { |
|
25 | + * Returns the API URL. |
|
26 | + * |
|
27 | + * |
|
28 | + * @param WPInv_Invoice $invoice Invoice. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function get_api_url( $invoice ) { |
|
32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * Communicates with authorize.net |
|
37 | - * |
|
38 | - * |
|
39 | - * @param array $post Data to post. |
|
36 | + * Communicates with authorize.net |
|
37 | + * |
|
38 | + * |
|
39 | + * @param array $post Data to post. |
|
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | - * @return stdClass|WP_Error |
|
42 | - */ |
|
41 | + * @return stdClass|WP_Error |
|
42 | + */ |
|
43 | 43 | public function post( $post, $invoice ){ |
44 | 44 | |
45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | - * Returns the API authentication params. |
|
93 | - * |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function get_auth_params() { |
|
92 | + * Returns the API authentication params. |
|
93 | + * |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function get_auth_params() { |
|
98 | 98 | |
99 | 99 | return array( |
100 | 100 | 'name' => $this->get_option( 'login_id' ), |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | - * Cancels a subscription remotely |
|
108 | - * |
|
109 | - * |
|
110 | - * @param WPInv_Subscription $subscription Subscription. |
|
107 | + * Cancels a subscription remotely |
|
108 | + * |
|
109 | + * |
|
110 | + * @param WPInv_Subscription $subscription Subscription. |
|
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | - */ |
|
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
112 | + */ |
|
113 | + public function cancel_subscription( $subscription, $invoice ) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | - * Processes ipns. |
|
130 | - * |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function verify_ipn() { |
|
129 | + * Processes ipns. |
|
130 | + * |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function verify_ipn() { |
|
134 | 134 | |
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | 138 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
139 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
@@ -175,24 +175,24 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | - * Validates IPN invoices. |
|
179 | - * |
|
178 | + * Validates IPN invoices. |
|
179 | + * |
|
180 | 180 | * @param WPInv_Invoice $invoice |
181 | 181 | * @param object $payload |
182 | - * @return void |
|
183 | - */ |
|
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | 185 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | - * Process subscriptio IPNS. |
|
192 | - * |
|
193 | - * @return void |
|
194 | - */ |
|
195 | - public function maybe_process_old_ipn() { |
|
191 | + * Process subscriptio IPNS. |
|
192 | + * |
|
193 | + * @return void |
|
194 | + */ |
|
195 | + public function maybe_process_old_ipn() { |
|
196 | 196 | |
197 | 197 | $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
198 | 198 | |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
237 | - * Validates the old IPN signature. |
|
237 | + * Validates the old IPN signature. |
|
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | - */ |
|
241 | - public function validate_old_ipn_signature( $posted ) { |
|
240 | + */ |
|
241 | + public function validate_old_ipn_signature( $posted ) { |
|
242 | 242 | |
243 | 243 | $signature = $this->get_option( 'signature_key' ); |
244 | 244 | if ( ! empty( $signature ) ) { |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | - * Check Authorize.NET IPN validity. |
|
261 | - */ |
|
262 | - public function validate_ipn() { |
|
260 | + * Check Authorize.NET IPN validity. |
|
261 | + */ |
|
262 | + public function validate_ipn() { |
|
263 | 263 | |
264 | 264 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
265 | 265 |
@@ -12,276 +12,276 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
21 | - |
|
22 | 15 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
26 | - |
|
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | - |
|
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | - |
|
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | - |
|
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
44 | - |
|
45 | - // For invoices... |
|
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
47 | - |
|
48 | - // For payment forms. |
|
49 | - self::add_payment_form_meta_boxes( $post_type, $post ); |
|
50 | - |
|
51 | - // For invoice items. |
|
52 | - self::add_item_meta_boxes( $post_type ); |
|
53 | - |
|
54 | - // For invoice discounts. |
|
55 | - if ( $post_type == 'wpi_discount' ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | - } |
|
58 | - |
|
59 | - } |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
60 | 21 | |
61 | - /** |
|
62 | - * Register core metaboxes. |
|
63 | - */ |
|
64 | - protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
22 | + /** |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
65 | 26 | |
66 | - // For payment forms. |
|
67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
68 | 29 | |
69 | - // Design payment form. |
|
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
71 | 32 | |
72 | - // Payment form information. |
|
73 | - if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
74 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
75 | - } |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
76 | 35 | |
77 | - } |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
78 | 39 | |
79 | - } |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
80 | 44 | |
81 | - /** |
|
82 | - * Register core metaboxes. |
|
83 | - */ |
|
84 | - protected static function add_item_meta_boxes( $post_type ) { |
|
45 | + // For invoices... |
|
46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
85 | 47 | |
86 | - if ( $post_type == 'wpi_item' ) { |
|
48 | + // For payment forms. |
|
49 | + self::add_payment_form_meta_boxes( $post_type, $post ); |
|
87 | 50 | |
88 | - // Item details. |
|
89 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
51 | + // For invoice items. |
|
52 | + self::add_item_meta_boxes( $post_type ); |
|
90 | 53 | |
91 | - // If taxes are enabled, register the tax metabox. |
|
92 | - if ( wpinv_use_taxes() ) { |
|
93 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
94 | - } |
|
54 | + // For invoice discounts. |
|
55 | + if ( $post_type == 'wpi_discount' ) { |
|
56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | + } |
|
95 | 58 | |
96 | - // Item info. |
|
97 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
59 | + } |
|
98 | 60 | |
99 | - } |
|
61 | + /** |
|
62 | + * Register core metaboxes. |
|
63 | + */ |
|
64 | + protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
100 | 65 | |
101 | - } |
|
66 | + // For payment forms. |
|
67 | + if ( $post_type == 'wpi_payment_form' ) { |
|
102 | 68 | |
103 | - /** |
|
104 | - * Register invoice metaboxes. |
|
105 | - */ |
|
106 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
69 | + // Design payment form. |
|
70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
107 | 71 | |
108 | - // For invoices... |
|
109 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
110 | - $invoice = new WPInv_Invoice( $post ); |
|
72 | + // Payment form information. |
|
73 | + if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
74 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
75 | + } |
|
111 | 76 | |
112 | - // Resend invoice. |
|
113 | - if ( ! $invoice->is_draft() ) { |
|
77 | + } |
|
114 | 78 | |
115 | - add_meta_box( |
|
116 | - 'wpinv-mb-resend-invoice', |
|
117 | - sprintf( |
|
118 | - __( 'Resend %s', 'invoicing' ), |
|
119 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
120 | - ), |
|
121 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
122 | - $post_type, |
|
123 | - 'side', |
|
124 | - 'low' |
|
125 | - ); |
|
79 | + } |
|
126 | 80 | |
127 | - } |
|
81 | + /** |
|
82 | + * Register core metaboxes. |
|
83 | + */ |
|
84 | + protected static function add_item_meta_boxes( $post_type ) { |
|
128 | 85 | |
129 | - // Subscriptions. |
|
130 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
131 | - if ( ! empty( $subscriptions ) ) { |
|
86 | + if ( $post_type == 'wpi_item' ) { |
|
132 | 87 | |
133 | - if ( is_array( $subscriptions ) ) { |
|
134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
135 | - } else { |
|
136 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
137 | - } |
|
88 | + // Item details. |
|
89 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
138 | 90 | |
139 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
140 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
141 | - } |
|
91 | + // If taxes are enabled, register the tax metabox. |
|
92 | + if ( wpinv_use_taxes() ) { |
|
93 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
94 | + } |
|
142 | 95 | |
143 | - } |
|
96 | + // Item info. |
|
97 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
144 | 98 | |
145 | - // Invoice details. |
|
146 | - add_meta_box( |
|
147 | - 'wpinv-details', |
|
148 | - sprintf( |
|
149 | - __( '%s Details', 'invoicing' ), |
|
150 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
151 | - ), |
|
152 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
153 | - $post_type, |
|
154 | - 'side' |
|
155 | - ); |
|
99 | + } |
|
156 | 100 | |
157 | - // Payment details. |
|
158 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
101 | + } |
|
159 | 102 | |
160 | - // Billing details. |
|
161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
103 | + /** |
|
104 | + * Register invoice metaboxes. |
|
105 | + */ |
|
106 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
107 | + |
|
108 | + // For invoices... |
|
109 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
110 | + $invoice = new WPInv_Invoice( $post ); |
|
111 | + |
|
112 | + // Resend invoice. |
|
113 | + if ( ! $invoice->is_draft() ) { |
|
114 | + |
|
115 | + add_meta_box( |
|
116 | + 'wpinv-mb-resend-invoice', |
|
117 | + sprintf( |
|
118 | + __( 'Resend %s', 'invoicing' ), |
|
119 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
120 | + ), |
|
121 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
122 | + $post_type, |
|
123 | + 'side', |
|
124 | + 'low' |
|
125 | + ); |
|
126 | + |
|
127 | + } |
|
128 | + |
|
129 | + // Subscriptions. |
|
130 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
131 | + if ( ! empty( $subscriptions ) ) { |
|
132 | + |
|
133 | + if ( is_array( $subscriptions ) ) { |
|
134 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
135 | + } else { |
|
136 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
137 | + } |
|
138 | + |
|
139 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
140 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
141 | + } |
|
142 | + |
|
143 | + } |
|
144 | + |
|
145 | + // Invoice details. |
|
146 | + add_meta_box( |
|
147 | + 'wpinv-details', |
|
148 | + sprintf( |
|
149 | + __( '%s Details', 'invoicing' ), |
|
150 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
151 | + ), |
|
152 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
153 | + $post_type, |
|
154 | + 'side' |
|
155 | + ); |
|
156 | + |
|
157 | + // Payment details. |
|
158 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
159 | + |
|
160 | + // Billing details. |
|
161 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
162 | 162 | |
163 | - // Invoice items. |
|
164 | - add_meta_box( |
|
165 | - 'wpinv-items', |
|
166 | - sprintf( |
|
167 | - __( '%s Items', 'invoicing' ), |
|
168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
169 | - ), |
|
170 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
171 | - $post_type, |
|
172 | - 'normal', |
|
173 | - 'high' |
|
174 | - ); |
|
163 | + // Invoice items. |
|
164 | + add_meta_box( |
|
165 | + 'wpinv-items', |
|
166 | + sprintf( |
|
167 | + __( '%s Items', 'invoicing' ), |
|
168 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
169 | + ), |
|
170 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
171 | + $post_type, |
|
172 | + 'normal', |
|
173 | + 'high' |
|
174 | + ); |
|
175 | 175 | |
176 | - // Invoice notes. |
|
177 | - add_meta_box( |
|
178 | - 'wpinv-notes', |
|
179 | - sprintf( |
|
180 | - __( '%s Notes', 'invoicing' ), |
|
181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
182 | - ), |
|
183 | - 'WPInv_Meta_Box_Notes::output', |
|
184 | - $post_type, |
|
185 | - 'side', |
|
186 | - 'low' |
|
187 | - ); |
|
188 | - |
|
189 | - // Shipping Address. |
|
190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
192 | - } |
|
193 | - |
|
194 | - // Payment form information. |
|
195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
197 | - } |
|
198 | - |
|
199 | - } |
|
200 | - |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Remove some metaboxes. |
|
205 | - */ |
|
206 | - public static function remove_meta_boxes() { |
|
207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Rename other metaboxes. |
|
212 | - */ |
|
213 | - public static function rename_meta_boxes() { |
|
176 | + // Invoice notes. |
|
177 | + add_meta_box( |
|
178 | + 'wpinv-notes', |
|
179 | + sprintf( |
|
180 | + __( '%s Notes', 'invoicing' ), |
|
181 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
182 | + ), |
|
183 | + 'WPInv_Meta_Box_Notes::output', |
|
184 | + $post_type, |
|
185 | + 'side', |
|
186 | + 'low' |
|
187 | + ); |
|
188 | + |
|
189 | + // Shipping Address. |
|
190 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
192 | + } |
|
193 | + |
|
194 | + // Payment form information. |
|
195 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
197 | + } |
|
198 | + |
|
199 | + } |
|
200 | + |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Remove some metaboxes. |
|
205 | + */ |
|
206 | + public static function remove_meta_boxes() { |
|
207 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Rename other metaboxes. |
|
212 | + */ |
|
213 | + public static function rename_meta_boxes() { |
|
214 | 214 | |
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Check if we're saving, then trigger an action based on the post type. |
|
219 | - * |
|
220 | - * @param int $post_id Post ID. |
|
221 | - * @param object $post Post object. |
|
222 | - */ |
|
223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
224 | - $post_id = absint( $post_id ); |
|
225 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
226 | - |
|
227 | - // Do not save for ajax requests. |
|
228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
229 | - return; |
|
230 | - } |
|
231 | - |
|
232 | - // $post_id and $post are required |
|
233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
234 | - return; |
|
235 | - } |
|
236 | - |
|
237 | - // Dont' save meta boxes for revisions or autosaves. |
|
238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
239 | - return; |
|
240 | - } |
|
241 | - |
|
242 | - // Check the nonce. |
|
243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
244 | - return; |
|
245 | - } |
|
246 | - |
|
247 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
249 | - return; |
|
250 | - } |
|
251 | - |
|
252 | - // Check user has permission to edit. |
|
253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
254 | - return; |
|
255 | - } |
|
256 | - |
|
257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
258 | - |
|
259 | - // We need this save event to run once to avoid potential endless loops. |
|
260 | - self::$saved_meta_boxes = true; |
|
261 | - |
|
262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
263 | - |
|
264 | - } |
|
265 | - |
|
266 | - // Ensure this is our post type. |
|
267 | - $post_types_map = array( |
|
268 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
269 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
270 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
271 | - ); |
|
272 | - |
|
273 | - // Is this our post type? |
|
274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // We need this save event to run once to avoid potential endless loops. |
|
279 | - self::$saved_meta_boxes = true; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Check if we're saving, then trigger an action based on the post type. |
|
219 | + * |
|
220 | + * @param int $post_id Post ID. |
|
221 | + * @param object $post Post object. |
|
222 | + */ |
|
223 | + public static function save_meta_boxes( $post_id, $post ) { |
|
224 | + $post_id = absint( $post_id ); |
|
225 | + $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
226 | + |
|
227 | + // Do not save for ajax requests. |
|
228 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
229 | + return; |
|
230 | + } |
|
231 | + |
|
232 | + // $post_id and $post are required |
|
233 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
234 | + return; |
|
235 | + } |
|
236 | + |
|
237 | + // Dont' save meta boxes for revisions or autosaves. |
|
238 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
239 | + return; |
|
240 | + } |
|
241 | + |
|
242 | + // Check the nonce. |
|
243 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
244 | + return; |
|
245 | + } |
|
246 | + |
|
247 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
248 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
249 | + return; |
|
250 | + } |
|
251 | + |
|
252 | + // Check user has permission to edit. |
|
253 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
254 | + return; |
|
255 | + } |
|
256 | + |
|
257 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
258 | + |
|
259 | + // We need this save event to run once to avoid potential endless loops. |
|
260 | + self::$saved_meta_boxes = true; |
|
261 | + |
|
262 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
263 | + |
|
264 | + } |
|
265 | + |
|
266 | + // Ensure this is our post type. |
|
267 | + $post_types_map = array( |
|
268 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
269 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
270 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
271 | + ); |
|
272 | + |
|
273 | + // Is this our post type? |
|
274 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // We need this save event to run once to avoid potential endless loops. |
|
279 | + self::$saved_meta_boxes = true; |
|
280 | 280 | |
281 | - // Save the post. |
|
282 | - $class = $post_types_map[ $post->post_type ]; |
|
283 | - $class::save( $post_id, $_POST, $post ); |
|
281 | + // Save the post. |
|
282 | + $class = $post_types_map[ $post->post_type ]; |
|
283 | + $class::save( $post_id, $_POST, $post ); |
|
284 | 284 | |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | 287 | } |
@@ -12,58 +12,58 @@ |
||
12 | 12 | $label = empty( $label ) ? '' : wp_kses_post( $label ); |
13 | 13 | $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
14 | 14 | if ( ! empty( $required ) ) { |
15 | - $label .= "<span class='text-danger'> *</span>"; |
|
15 | + $label .= "<span class='text-danger'> *</span>"; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | $disable_dates = array(); |
19 | 19 | |
20 | 20 | if ( ! empty( $disabled_dates ) ) { |
21 | - $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | - $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | - $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
21 | + $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | + $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | + $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
24 | 24 | |
25 | - foreach ( $disabled_dates as $disabled_date ) { |
|
25 | + foreach ( $disabled_dates as $disabled_date ) { |
|
26 | 26 | |
27 | - $disabled_date = trim( $disabled_date ); |
|
27 | + $disabled_date = trim( $disabled_date ); |
|
28 | 28 | |
29 | - if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | - $disable_dates[] = $disabled_date; |
|
31 | - continue; |
|
32 | - } |
|
29 | + if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | + $disable_dates[] = $disabled_date; |
|
31 | + continue; |
|
32 | + } |
|
33 | 33 | |
34 | - $disabled_date = explode( '|', $disabled_date ); |
|
35 | - $disable_dates[] = array( |
|
36 | - 'from' => trim( $disabled_date[0] ), |
|
37 | - 'to' => trim( $disabled_date[1] ), |
|
38 | - ); |
|
34 | + $disabled_date = explode( '|', $disabled_date ); |
|
35 | + $disable_dates[] = array( |
|
36 | + 'from' => trim( $disabled_date[0] ), |
|
37 | + 'to' => trim( $disabled_date[1] ), |
|
38 | + ); |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | $options = array( |
45 | - 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
46 | - 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
47 | - 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
48 | - 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
49 | - 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
50 | - 'data-date-format' => 'Y-m-d', |
|
51 | - 'data-alt-input' => 'true', |
|
52 | - 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
53 | - 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
45 | + 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
46 | + 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
47 | + 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
48 | + 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
49 | + 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
50 | + 'data-date-format' => 'Y-m-d', |
|
51 | + 'data-alt-input' => 'true', |
|
52 | + 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
53 | + 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
54 | 54 | ); |
55 | 55 | |
56 | 56 | echo aui()->input( |
57 | - array( |
|
58 | - 'name' => esc_attr( $id ), |
|
59 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
60 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
61 | - 'required' => ! empty( $required ), |
|
62 | - 'label' => $label, |
|
63 | - 'label_type' => 'vertical', |
|
64 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
65 | - 'type' => 'datepicker', |
|
66 | - 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
67 | - 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
68 | - ) |
|
57 | + array( |
|
58 | + 'name' => esc_attr( $id ), |
|
59 | + 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
60 | + 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
61 | + 'required' => ! empty( $required ), |
|
62 | + 'label' => $label, |
|
63 | + 'label_type' => 'vertical', |
|
64 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
65 | + 'type' => 'datepicker', |
|
66 | + 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
67 | + 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
68 | + ) |
|
69 | 69 | ); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,203 +10,203 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - 'shipping' => array( |
|
54 | - 'initial' => 0, |
|
55 | - 'recurring' => 0, |
|
56 | - ), |
|
57 | - |
|
58 | - ); |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets the associated payment form. |
|
62 | - * |
|
63 | - * @var GetPaid_Payment_Form |
|
64 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + 'shipping' => array( |
|
54 | + 'initial' => 0, |
|
55 | + 'recurring' => 0, |
|
56 | + ), |
|
57 | + |
|
58 | + ); |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets the associated payment form. |
|
62 | + * |
|
63 | + * @var GetPaid_Payment_Form |
|
64 | + */ |
|
65 | 65 | protected $payment_form = null; |
66 | 66 | |
67 | 67 | /** |
68 | - * The country for the submission. |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - public $country = null; |
|
73 | - |
|
74 | - /** |
|
75 | - * The state for the submission. |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @var string |
|
79 | - */ |
|
80 | - public $state = null; |
|
81 | - |
|
82 | - /** |
|
83 | - * The invoice associated with the submission. |
|
84 | - * |
|
85 | - * @var WPInv_Invoice |
|
86 | - */ |
|
87 | - protected $invoice = null; |
|
88 | - |
|
89 | - /** |
|
90 | - * The recurring item for the submission. |
|
91 | - * |
|
92 | - * @var int |
|
93 | - */ |
|
94 | - public $has_recurring = 0; |
|
95 | - |
|
96 | - /** |
|
97 | - * An array of fees for the submission. |
|
98 | - * |
|
99 | - * @var array |
|
100 | - */ |
|
101 | - protected $fees = array(); |
|
102 | - |
|
103 | - /** |
|
104 | - * An array of discounts for the submission. |
|
105 | - * |
|
106 | - * @var array |
|
107 | - */ |
|
108 | - protected $discounts = array(); |
|
109 | - |
|
110 | - /** |
|
111 | - * An array of taxes for the submission. |
|
112 | - * |
|
113 | - * @var array |
|
114 | - */ |
|
115 | - protected $taxes = array(); |
|
116 | - |
|
117 | - /** |
|
118 | - * An array of items for the submission. |
|
119 | - * |
|
120 | - * @var GetPaid_Form_Item[] |
|
121 | - */ |
|
122 | - protected $items = array(); |
|
123 | - |
|
124 | - /** |
|
125 | - * The last error. |
|
126 | - * |
|
127 | - * @var string |
|
128 | - */ |
|
129 | - public $last_error = null; |
|
130 | - |
|
131 | - /** |
|
132 | - * The last error code. |
|
133 | - * |
|
134 | - * @var string |
|
135 | - */ |
|
136 | - public $last_error_code = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * Class constructor. |
|
140 | - * |
|
141 | - */ |
|
142 | - public function __construct() { |
|
143 | - |
|
144 | - // Set the state and country to the default state and country. |
|
145 | - $this->country = wpinv_default_billing_country(); |
|
146 | - $this->state = wpinv_get_default_state(); |
|
147 | - |
|
148 | - // Do we have an actual submission? |
|
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( $_POST ); |
|
151 | - } |
|
152 | - |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Loads submission data. |
|
157 | - * |
|
158 | - * @param array $data |
|
159 | - */ |
|
160 | - public function load_data( $data ) { |
|
161 | - |
|
162 | - // Remove slashes from the submitted data... |
|
163 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
164 | - |
|
165 | - // Allow plugins to filter the data. |
|
166 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
167 | - |
|
168 | - // Cache it... |
|
169 | - $this->data = $data; |
|
170 | - |
|
171 | - // Then generate a unique id from the data. |
|
172 | - $this->id = md5( wp_json_encode( $data ) ); |
|
173 | - |
|
174 | - // Finally, process the submission. |
|
175 | - try { |
|
176 | - |
|
177 | - // Each process is passed an instance of the class (with reference) |
|
178 | - // and should throw an Exception whenever it encounters one. |
|
179 | - $processors = apply_filters( |
|
180 | - 'getpaid_payment_form_submission_processors', |
|
181 | - array( |
|
182 | - array( $this, 'process_payment_form' ), |
|
183 | - array( $this, 'process_invoice' ), |
|
184 | - array( $this, 'process_fees' ), |
|
185 | - array( $this, 'process_items' ), |
|
186 | - array( $this, 'process_discount' ), |
|
187 | - array( $this, 'process_taxes' ), |
|
188 | - ), |
|
189 | - $this |
|
190 | - ); |
|
191 | - |
|
192 | - foreach ( $processors as $processor ) { |
|
193 | - call_user_func_array( $processor, array( &$this ) ); |
|
194 | - } |
|
195 | - |
|
196 | - } catch( GetPaid_Payment_Exception $e ) { |
|
197 | - $this->last_error = $e->getMessage(); |
|
198 | - $this->last_error_code = $e->getErrorCode(); |
|
199 | - } catch ( Exception $e ) { |
|
200 | - $this->last_error = $e->getMessage(); |
|
201 | - $this->last_error_code = $e->getCode(); |
|
202 | - } |
|
203 | - |
|
204 | - // Fired when we are done processing a submission. |
|
205 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
206 | - |
|
207 | - } |
|
208 | - |
|
209 | - /* |
|
68 | + * The country for the submission. |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + public $country = null; |
|
73 | + |
|
74 | + /** |
|
75 | + * The state for the submission. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var string |
|
79 | + */ |
|
80 | + public $state = null; |
|
81 | + |
|
82 | + /** |
|
83 | + * The invoice associated with the submission. |
|
84 | + * |
|
85 | + * @var WPInv_Invoice |
|
86 | + */ |
|
87 | + protected $invoice = null; |
|
88 | + |
|
89 | + /** |
|
90 | + * The recurring item for the submission. |
|
91 | + * |
|
92 | + * @var int |
|
93 | + */ |
|
94 | + public $has_recurring = 0; |
|
95 | + |
|
96 | + /** |
|
97 | + * An array of fees for the submission. |
|
98 | + * |
|
99 | + * @var array |
|
100 | + */ |
|
101 | + protected $fees = array(); |
|
102 | + |
|
103 | + /** |
|
104 | + * An array of discounts for the submission. |
|
105 | + * |
|
106 | + * @var array |
|
107 | + */ |
|
108 | + protected $discounts = array(); |
|
109 | + |
|
110 | + /** |
|
111 | + * An array of taxes for the submission. |
|
112 | + * |
|
113 | + * @var array |
|
114 | + */ |
|
115 | + protected $taxes = array(); |
|
116 | + |
|
117 | + /** |
|
118 | + * An array of items for the submission. |
|
119 | + * |
|
120 | + * @var GetPaid_Form_Item[] |
|
121 | + */ |
|
122 | + protected $items = array(); |
|
123 | + |
|
124 | + /** |
|
125 | + * The last error. |
|
126 | + * |
|
127 | + * @var string |
|
128 | + */ |
|
129 | + public $last_error = null; |
|
130 | + |
|
131 | + /** |
|
132 | + * The last error code. |
|
133 | + * |
|
134 | + * @var string |
|
135 | + */ |
|
136 | + public $last_error_code = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * Class constructor. |
|
140 | + * |
|
141 | + */ |
|
142 | + public function __construct() { |
|
143 | + |
|
144 | + // Set the state and country to the default state and country. |
|
145 | + $this->country = wpinv_default_billing_country(); |
|
146 | + $this->state = wpinv_get_default_state(); |
|
147 | + |
|
148 | + // Do we have an actual submission? |
|
149 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | + $this->load_data( $_POST ); |
|
151 | + } |
|
152 | + |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Loads submission data. |
|
157 | + * |
|
158 | + * @param array $data |
|
159 | + */ |
|
160 | + public function load_data( $data ) { |
|
161 | + |
|
162 | + // Remove slashes from the submitted data... |
|
163 | + $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
164 | + |
|
165 | + // Allow plugins to filter the data. |
|
166 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
167 | + |
|
168 | + // Cache it... |
|
169 | + $this->data = $data; |
|
170 | + |
|
171 | + // Then generate a unique id from the data. |
|
172 | + $this->id = md5( wp_json_encode( $data ) ); |
|
173 | + |
|
174 | + // Finally, process the submission. |
|
175 | + try { |
|
176 | + |
|
177 | + // Each process is passed an instance of the class (with reference) |
|
178 | + // and should throw an Exception whenever it encounters one. |
|
179 | + $processors = apply_filters( |
|
180 | + 'getpaid_payment_form_submission_processors', |
|
181 | + array( |
|
182 | + array( $this, 'process_payment_form' ), |
|
183 | + array( $this, 'process_invoice' ), |
|
184 | + array( $this, 'process_fees' ), |
|
185 | + array( $this, 'process_items' ), |
|
186 | + array( $this, 'process_discount' ), |
|
187 | + array( $this, 'process_taxes' ), |
|
188 | + ), |
|
189 | + $this |
|
190 | + ); |
|
191 | + |
|
192 | + foreach ( $processors as $processor ) { |
|
193 | + call_user_func_array( $processor, array( &$this ) ); |
|
194 | + } |
|
195 | + |
|
196 | + } catch( GetPaid_Payment_Exception $e ) { |
|
197 | + $this->last_error = $e->getMessage(); |
|
198 | + $this->last_error_code = $e->getErrorCode(); |
|
199 | + } catch ( Exception $e ) { |
|
200 | + $this->last_error = $e->getMessage(); |
|
201 | + $this->last_error_code = $e->getCode(); |
|
202 | + } |
|
203 | + |
|
204 | + // Fired when we are done processing a submission. |
|
205 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
206 | + |
|
207 | + } |
|
208 | + |
|
209 | + /* |
|
210 | 210 | |-------------------------------------------------------------------------- |
211 | 211 | | Payment Forms. |
212 | 212 | |-------------------------------------------------------------------------- |
@@ -215,39 +215,39 @@ discard block |
||
215 | 215 | | submission has an active payment form etc. |
216 | 216 | */ |
217 | 217 | |
218 | - /** |
|
219 | - * Prepares the submission's payment form. |
|
220 | - * |
|
221 | - * @since 1.0.19 |
|
222 | - */ |
|
223 | - public function process_payment_form() { |
|
218 | + /** |
|
219 | + * Prepares the submission's payment form. |
|
220 | + * |
|
221 | + * @since 1.0.19 |
|
222 | + */ |
|
223 | + public function process_payment_form() { |
|
224 | 224 | |
225 | - // Every submission needs an active payment form. |
|
226 | - if ( empty( $this->data['form_id'] ) ) { |
|
227 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
228 | - } |
|
225 | + // Every submission needs an active payment form. |
|
226 | + if ( empty( $this->data['form_id'] ) ) { |
|
227 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
228 | + } |
|
229 | 229 | |
230 | - // Fetch the payment form. |
|
231 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
230 | + // Fetch the payment form. |
|
231 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
232 | 232 | |
233 | - if ( ! $this->payment_form->is_active() ) { |
|
234 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
235 | - } |
|
233 | + if ( ! $this->payment_form->is_active() ) { |
|
234 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
235 | + } |
|
236 | 236 | |
237 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
238 | - } |
|
237 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
238 | + } |
|
239 | 239 | |
240 | 240 | /** |
241 | - * Returns the payment form. |
|
242 | - * |
|
243 | - * @since 1.0.19 |
|
244 | - * @return GetPaid_Payment_Form |
|
245 | - */ |
|
246 | - public function get_payment_form() { |
|
247 | - return $this->payment_form; |
|
248 | - } |
|
241 | + * Returns the payment form. |
|
242 | + * |
|
243 | + * @since 1.0.19 |
|
244 | + * @return GetPaid_Payment_Form |
|
245 | + */ |
|
246 | + public function get_payment_form() { |
|
247 | + return $this->payment_form; |
|
248 | + } |
|
249 | 249 | |
250 | - /* |
|
250 | + /* |
|
251 | 251 | |-------------------------------------------------------------------------- |
252 | 252 | | Invoices. |
253 | 253 | |-------------------------------------------------------------------------- |
@@ -256,84 +256,84 @@ discard block |
||
256 | 256 | | might be for an existing invoice. |
257 | 257 | */ |
258 | 258 | |
259 | - /** |
|
260 | - * Prepares the submission's invoice. |
|
261 | - * |
|
262 | - * @since 1.0.19 |
|
263 | - */ |
|
264 | - public function process_invoice() { |
|
259 | + /** |
|
260 | + * Prepares the submission's invoice. |
|
261 | + * |
|
262 | + * @since 1.0.19 |
|
263 | + */ |
|
264 | + public function process_invoice() { |
|
265 | 265 | |
266 | - // Abort if there is no invoice. |
|
267 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
268 | - return; |
|
269 | - } |
|
266 | + // Abort if there is no invoice. |
|
267 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
268 | + return; |
|
269 | + } |
|
270 | 270 | |
271 | - // If the submission is for an existing invoice, ensure that it exists |
|
272 | - // and that it is not paid for. |
|
273 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
271 | + // If the submission is for an existing invoice, ensure that it exists |
|
272 | + // and that it is not paid for. |
|
273 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
274 | 274 | |
275 | 275 | if ( empty( $invoice ) ) { |
276 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
277 | - } |
|
276 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
277 | + } |
|
278 | 278 | |
279 | - if ( $invoice->is_paid() ) { |
|
280 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
281 | - } |
|
279 | + if ( $invoice->is_paid() ) { |
|
280 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
281 | + } |
|
282 | 282 | |
283 | - $this->payment_form->invoice = $invoice; |
|
284 | - if ( ! $this->payment_form->is_default() ) { |
|
283 | + $this->payment_form->invoice = $invoice; |
|
284 | + if ( ! $this->payment_form->is_default() ) { |
|
285 | 285 | |
286 | - $items = array(); |
|
287 | - $item_ids = array(); |
|
286 | + $items = array(); |
|
287 | + $item_ids = array(); |
|
288 | 288 | |
289 | - foreach ( $invoice->get_items() as $item ) { |
|
290 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
291 | - $item_ids[] = $item->get_id(); |
|
292 | - $items[] = $item; |
|
293 | - } |
|
294 | - } |
|
289 | + foreach ( $invoice->get_items() as $item ) { |
|
290 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
291 | + $item_ids[] = $item->get_id(); |
|
292 | + $items[] = $item; |
|
293 | + } |
|
294 | + } |
|
295 | 295 | |
296 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | - $item_ids[] = $item->get_id(); |
|
299 | - $items[] = $item; |
|
300 | - } |
|
301 | - } |
|
296 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
297 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | + $item_ids[] = $item->get_id(); |
|
299 | + $items[] = $item; |
|
300 | + } |
|
301 | + } |
|
302 | 302 | |
303 | - $this->payment_form->set_items( $items ); |
|
303 | + $this->payment_form->set_items( $items ); |
|
304 | 304 | |
305 | - } else { |
|
306 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
307 | - } |
|
308 | - |
|
309 | - $this->country = $invoice->get_country(); |
|
310 | - $this->state = $invoice->get_state(); |
|
311 | - $this->invoice = $invoice; |
|
312 | - |
|
313 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Returns the associated invoice. |
|
318 | - * |
|
319 | - * @since 1.0.19 |
|
320 | - * @return WPInv_Invoice |
|
321 | - */ |
|
322 | - public function get_invoice() { |
|
323 | - return $this->invoice; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Checks whether there is an invoice associated with this submission. |
|
328 | - * |
|
329 | - * @since 1.0.19 |
|
330 | - * @return bool |
|
331 | - */ |
|
332 | - public function has_invoice() { |
|
333 | - return ! empty( $this->invoice ); |
|
334 | - } |
|
335 | - |
|
336 | - /* |
|
305 | + } else { |
|
306 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
307 | + } |
|
308 | + |
|
309 | + $this->country = $invoice->get_country(); |
|
310 | + $this->state = $invoice->get_state(); |
|
311 | + $this->invoice = $invoice; |
|
312 | + |
|
313 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Returns the associated invoice. |
|
318 | + * |
|
319 | + * @since 1.0.19 |
|
320 | + * @return WPInv_Invoice |
|
321 | + */ |
|
322 | + public function get_invoice() { |
|
323 | + return $this->invoice; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Checks whether there is an invoice associated with this submission. |
|
328 | + * |
|
329 | + * @since 1.0.19 |
|
330 | + * @return bool |
|
331 | + */ |
|
332 | + public function has_invoice() { |
|
333 | + return ! empty( $this->invoice ); |
|
334 | + } |
|
335 | + |
|
336 | + /* |
|
337 | 337 | |-------------------------------------------------------------------------- |
338 | 338 | | Items. |
339 | 339 | |-------------------------------------------------------------------------- |
@@ -342,129 +342,129 @@ discard block |
||
342 | 342 | | recurring item. But can have an unlimited number of non-recurring items. |
343 | 343 | */ |
344 | 344 | |
345 | - /** |
|
346 | - * Prepares the submission's items. |
|
347 | - * |
|
348 | - * @since 1.0.19 |
|
349 | - */ |
|
350 | - public function process_items() { |
|
351 | - |
|
352 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
353 | - |
|
354 | - foreach ( $processor->items as $item ) { |
|
355 | - $this->add_item( $item ); |
|
356 | - } |
|
357 | - |
|
358 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Adds an item to the submission. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param GetPaid_Form_Item $item |
|
366 | - */ |
|
367 | - public function add_item( $item ) { |
|
368 | - |
|
369 | - // Make sure that it is available for purchase. |
|
370 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
371 | - return; |
|
372 | - } |
|
373 | - |
|
374 | - // Each submission can only contain one recurring item. |
|
375 | - if ( $item->is_recurring() ) { |
|
376 | - $this->has_recurring = $item->get_id(); |
|
377 | - } |
|
378 | - |
|
379 | - // Update the items and totals. |
|
380 | - $this->items[ $item->get_id() ] = $item; |
|
381 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
382 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
383 | - |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Removes a specific item. |
|
388 | - * |
|
389 | - * You should not call this method after the discounts and taxes |
|
390 | - * have been calculated. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - */ |
|
394 | - public function remove_item( $item_id ) { |
|
395 | - |
|
396 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
397 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
398 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
399 | - |
|
400 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
401 | - $this->has_recurring = 0; |
|
402 | - } |
|
403 | - |
|
404 | - unset( $this->items[ $item_id ] ); |
|
405 | - } |
|
406 | - |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Returns the subtotal. |
|
411 | - * |
|
412 | - * @since 1.0.19 |
|
413 | - */ |
|
414 | - public function get_subtotal() { |
|
415 | - |
|
416 | - if ( wpinv_prices_include_tax() ) { |
|
417 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
418 | - } |
|
419 | - |
|
420 | - return $this->totals['subtotal']['initial']; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Returns the recurring subtotal. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - */ |
|
428 | - public function get_recurring_subtotal() { |
|
429 | - |
|
430 | - if ( wpinv_prices_include_tax() ) { |
|
431 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
432 | - } |
|
433 | - |
|
434 | - return $this->totals['subtotal']['recurring']; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Returns all items. |
|
439 | - * |
|
440 | - * @since 1.0.19 |
|
441 | - * @return GetPaid_Form_Item[] |
|
442 | - */ |
|
443 | - public function get_items() { |
|
444 | - return $this->items; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Checks if there's a single subscription group in the submission. |
|
449 | - * |
|
450 | - * @since 2.3.0 |
|
451 | - * @return bool |
|
452 | - */ |
|
453 | - public function has_subscription_group() { |
|
454 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Checks if there are multipe subscription groups in the submission. |
|
459 | - * |
|
460 | - * @since 2.3.0 |
|
461 | - * @return bool |
|
462 | - */ |
|
463 | - public function has_multiple_subscription_groups() { |
|
464 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
465 | - } |
|
466 | - |
|
467 | - /* |
|
345 | + /** |
|
346 | + * Prepares the submission's items. |
|
347 | + * |
|
348 | + * @since 1.0.19 |
|
349 | + */ |
|
350 | + public function process_items() { |
|
351 | + |
|
352 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
353 | + |
|
354 | + foreach ( $processor->items as $item ) { |
|
355 | + $this->add_item( $item ); |
|
356 | + } |
|
357 | + |
|
358 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Adds an item to the submission. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param GetPaid_Form_Item $item |
|
366 | + */ |
|
367 | + public function add_item( $item ) { |
|
368 | + |
|
369 | + // Make sure that it is available for purchase. |
|
370 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
371 | + return; |
|
372 | + } |
|
373 | + |
|
374 | + // Each submission can only contain one recurring item. |
|
375 | + if ( $item->is_recurring() ) { |
|
376 | + $this->has_recurring = $item->get_id(); |
|
377 | + } |
|
378 | + |
|
379 | + // Update the items and totals. |
|
380 | + $this->items[ $item->get_id() ] = $item; |
|
381 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
382 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
383 | + |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Removes a specific item. |
|
388 | + * |
|
389 | + * You should not call this method after the discounts and taxes |
|
390 | + * have been calculated. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + */ |
|
394 | + public function remove_item( $item_id ) { |
|
395 | + |
|
396 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
397 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
398 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
399 | + |
|
400 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
401 | + $this->has_recurring = 0; |
|
402 | + } |
|
403 | + |
|
404 | + unset( $this->items[ $item_id ] ); |
|
405 | + } |
|
406 | + |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Returns the subtotal. |
|
411 | + * |
|
412 | + * @since 1.0.19 |
|
413 | + */ |
|
414 | + public function get_subtotal() { |
|
415 | + |
|
416 | + if ( wpinv_prices_include_tax() ) { |
|
417 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
418 | + } |
|
419 | + |
|
420 | + return $this->totals['subtotal']['initial']; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Returns the recurring subtotal. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + */ |
|
428 | + public function get_recurring_subtotal() { |
|
429 | + |
|
430 | + if ( wpinv_prices_include_tax() ) { |
|
431 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
432 | + } |
|
433 | + |
|
434 | + return $this->totals['subtotal']['recurring']; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Returns all items. |
|
439 | + * |
|
440 | + * @since 1.0.19 |
|
441 | + * @return GetPaid_Form_Item[] |
|
442 | + */ |
|
443 | + public function get_items() { |
|
444 | + return $this->items; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Checks if there's a single subscription group in the submission. |
|
449 | + * |
|
450 | + * @since 2.3.0 |
|
451 | + * @return bool |
|
452 | + */ |
|
453 | + public function has_subscription_group() { |
|
454 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Checks if there are multipe subscription groups in the submission. |
|
459 | + * |
|
460 | + * @since 2.3.0 |
|
461 | + * @return bool |
|
462 | + */ |
|
463 | + public function has_multiple_subscription_groups() { |
|
464 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
465 | + } |
|
466 | + |
|
467 | + /* |
|
468 | 468 | |-------------------------------------------------------------------------- |
469 | 469 | | Taxes |
470 | 470 | |-------------------------------------------------------------------------- |
@@ -473,128 +473,128 @@ discard block |
||
473 | 473 | | or only one-time. |
474 | 474 | */ |
475 | 475 | |
476 | - /** |
|
477 | - * Prepares the submission's taxes. |
|
478 | - * |
|
479 | - * @since 1.0.19 |
|
480 | - */ |
|
481 | - public function process_taxes() { |
|
482 | - |
|
483 | - // Abort if we're not using taxes. |
|
484 | - if ( ! $this->use_taxes() ) { |
|
485 | - return; |
|
486 | - } |
|
487 | - |
|
488 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
489 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
490 | - if ( ! empty( $country ) ) { |
|
491 | - $this->country = $country; |
|
492 | - } |
|
493 | - |
|
494 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
495 | - if ( ! empty( $state ) ) { |
|
496 | - $this->state = $state; |
|
497 | - } |
|
498 | - |
|
499 | - // Confirm if the provided country and the ip country are similar. |
|
500 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
501 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
502 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
503 | - } |
|
504 | - |
|
505 | - // Abort if the country is not taxable. |
|
506 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
507 | - return; |
|
508 | - } |
|
509 | - |
|
510 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
511 | - |
|
512 | - foreach ( $processor->taxes as $tax ) { |
|
513 | - $this->add_tax( $tax ); |
|
514 | - } |
|
515 | - |
|
516 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * Adds a tax to the submission. |
|
521 | - * |
|
522 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
523 | - * @since 1.0.19 |
|
524 | - */ |
|
525 | - public function add_tax( $tax ) { |
|
526 | - |
|
527 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
528 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
529 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
530 | - } |
|
531 | - |
|
532 | - $this->taxes[ $tax['name'] ] = $tax; |
|
533 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
534 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
535 | - |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Removes a specific tax. |
|
540 | - * |
|
541 | - * @since 1.0.19 |
|
542 | - */ |
|
543 | - public function remove_tax( $tax_name ) { |
|
544 | - |
|
545 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
546 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
547 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
548 | - unset( $this->taxes[ $tax_name ] ); |
|
549 | - } |
|
550 | - |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Whether or not we'll use taxes for the submission. |
|
555 | - * |
|
556 | - * @since 1.0.19 |
|
557 | - */ |
|
558 | - public function use_taxes() { |
|
559 | - |
|
560 | - $use_taxes = wpinv_use_taxes(); |
|
561 | - |
|
562 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
563 | - $use_taxes = false; |
|
564 | - } |
|
565 | - |
|
566 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
567 | - |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Returns the tax. |
|
572 | - * |
|
573 | - * @since 1.0.19 |
|
574 | - */ |
|
575 | - public function get_tax() { |
|
576 | - return $this->totals['taxes']['initial']; |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * Returns the recurring tax. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - */ |
|
584 | - public function get_recurring_tax() { |
|
585 | - return $this->totals['taxes']['recurring']; |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Returns all taxes. |
|
590 | - * |
|
591 | - * @since 1.0.19 |
|
592 | - */ |
|
593 | - public function get_taxes() { |
|
594 | - return $this->taxes; |
|
595 | - } |
|
596 | - |
|
597 | - /* |
|
476 | + /** |
|
477 | + * Prepares the submission's taxes. |
|
478 | + * |
|
479 | + * @since 1.0.19 |
|
480 | + */ |
|
481 | + public function process_taxes() { |
|
482 | + |
|
483 | + // Abort if we're not using taxes. |
|
484 | + if ( ! $this->use_taxes() ) { |
|
485 | + return; |
|
486 | + } |
|
487 | + |
|
488 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
489 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
490 | + if ( ! empty( $country ) ) { |
|
491 | + $this->country = $country; |
|
492 | + } |
|
493 | + |
|
494 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
495 | + if ( ! empty( $state ) ) { |
|
496 | + $this->state = $state; |
|
497 | + } |
|
498 | + |
|
499 | + // Confirm if the provided country and the ip country are similar. |
|
500 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
501 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
502 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
503 | + } |
|
504 | + |
|
505 | + // Abort if the country is not taxable. |
|
506 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
507 | + return; |
|
508 | + } |
|
509 | + |
|
510 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
511 | + |
|
512 | + foreach ( $processor->taxes as $tax ) { |
|
513 | + $this->add_tax( $tax ); |
|
514 | + } |
|
515 | + |
|
516 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * Adds a tax to the submission. |
|
521 | + * |
|
522 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
523 | + * @since 1.0.19 |
|
524 | + */ |
|
525 | + public function add_tax( $tax ) { |
|
526 | + |
|
527 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
528 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
529 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
530 | + } |
|
531 | + |
|
532 | + $this->taxes[ $tax['name'] ] = $tax; |
|
533 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
534 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
535 | + |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Removes a specific tax. |
|
540 | + * |
|
541 | + * @since 1.0.19 |
|
542 | + */ |
|
543 | + public function remove_tax( $tax_name ) { |
|
544 | + |
|
545 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
546 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
547 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
548 | + unset( $this->taxes[ $tax_name ] ); |
|
549 | + } |
|
550 | + |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Whether or not we'll use taxes for the submission. |
|
555 | + * |
|
556 | + * @since 1.0.19 |
|
557 | + */ |
|
558 | + public function use_taxes() { |
|
559 | + |
|
560 | + $use_taxes = wpinv_use_taxes(); |
|
561 | + |
|
562 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
563 | + $use_taxes = false; |
|
564 | + } |
|
565 | + |
|
566 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
567 | + |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Returns the tax. |
|
572 | + * |
|
573 | + * @since 1.0.19 |
|
574 | + */ |
|
575 | + public function get_tax() { |
|
576 | + return $this->totals['taxes']['initial']; |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * Returns the recurring tax. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + */ |
|
584 | + public function get_recurring_tax() { |
|
585 | + return $this->totals['taxes']['recurring']; |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Returns all taxes. |
|
590 | + * |
|
591 | + * @since 1.0.19 |
|
592 | + */ |
|
593 | + public function get_taxes() { |
|
594 | + return $this->taxes; |
|
595 | + } |
|
596 | + |
|
597 | + /* |
|
598 | 598 | |-------------------------------------------------------------------------- |
599 | 599 | | Discounts |
600 | 600 | |-------------------------------------------------------------------------- |
@@ -603,99 +603,99 @@ discard block |
||
603 | 603 | | or only one-time. They also do not have to come from a discount code. |
604 | 604 | */ |
605 | 605 | |
606 | - /** |
|
607 | - * Prepares the submission's discount. |
|
608 | - * |
|
609 | - * @since 1.0.19 |
|
610 | - */ |
|
611 | - public function process_discount() { |
|
612 | - |
|
613 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
614 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
615 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
616 | - |
|
617 | - foreach ( $processor->discounts as $discount ) { |
|
618 | - $this->add_discount( $discount ); |
|
619 | - } |
|
620 | - |
|
621 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Adds a discount to the submission. |
|
626 | - * |
|
627 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
628 | - * @since 1.0.19 |
|
629 | - */ |
|
630 | - public function add_discount( $discount ) { |
|
631 | - $this->discounts[ $discount['name'] ] = $discount; |
|
632 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
633 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Removes a discount from the submission. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - */ |
|
641 | - public function remove_discount( $name ) { |
|
642 | - |
|
643 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
644 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
645 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
646 | - unset( $this->discounts[ $name ] ); |
|
647 | - } |
|
648 | - |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Checks whether there is a discount code associated with this submission. |
|
653 | - * |
|
654 | - * @since 1.0.19 |
|
655 | - * @return bool |
|
656 | - */ |
|
657 | - public function has_discount_code() { |
|
658 | - return ! empty( $this->discounts['discount_code'] ); |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * Returns the discount code. |
|
663 | - * |
|
664 | - * @since 1.0.19 |
|
665 | - * @return string |
|
666 | - */ |
|
667 | - public function get_discount_code() { |
|
668 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Returns the discount. |
|
673 | - * |
|
674 | - * @since 1.0.19 |
|
675 | - */ |
|
676 | - public function get_discount() { |
|
677 | - return $this->totals['discount']['initial']; |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Returns the recurring discount. |
|
682 | - * |
|
683 | - * @since 1.0.19 |
|
684 | - */ |
|
685 | - public function get_recurring_discount() { |
|
686 | - return $this->totals['discount']['recurring']; |
|
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Returns all discounts. |
|
691 | - * |
|
692 | - * @since 1.0.19 |
|
693 | - */ |
|
694 | - public function get_discounts() { |
|
695 | - return $this->discounts; |
|
696 | - } |
|
697 | - |
|
698 | - /* |
|
606 | + /** |
|
607 | + * Prepares the submission's discount. |
|
608 | + * |
|
609 | + * @since 1.0.19 |
|
610 | + */ |
|
611 | + public function process_discount() { |
|
612 | + |
|
613 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
614 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
615 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
616 | + |
|
617 | + foreach ( $processor->discounts as $discount ) { |
|
618 | + $this->add_discount( $discount ); |
|
619 | + } |
|
620 | + |
|
621 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Adds a discount to the submission. |
|
626 | + * |
|
627 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
628 | + * @since 1.0.19 |
|
629 | + */ |
|
630 | + public function add_discount( $discount ) { |
|
631 | + $this->discounts[ $discount['name'] ] = $discount; |
|
632 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
633 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Removes a discount from the submission. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + */ |
|
641 | + public function remove_discount( $name ) { |
|
642 | + |
|
643 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
644 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
645 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
646 | + unset( $this->discounts[ $name ] ); |
|
647 | + } |
|
648 | + |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Checks whether there is a discount code associated with this submission. |
|
653 | + * |
|
654 | + * @since 1.0.19 |
|
655 | + * @return bool |
|
656 | + */ |
|
657 | + public function has_discount_code() { |
|
658 | + return ! empty( $this->discounts['discount_code'] ); |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * Returns the discount code. |
|
663 | + * |
|
664 | + * @since 1.0.19 |
|
665 | + * @return string |
|
666 | + */ |
|
667 | + public function get_discount_code() { |
|
668 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * Returns the discount. |
|
673 | + * |
|
674 | + * @since 1.0.19 |
|
675 | + */ |
|
676 | + public function get_discount() { |
|
677 | + return $this->totals['discount']['initial']; |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Returns the recurring discount. |
|
682 | + * |
|
683 | + * @since 1.0.19 |
|
684 | + */ |
|
685 | + public function get_recurring_discount() { |
|
686 | + return $this->totals['discount']['recurring']; |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Returns all discounts. |
|
691 | + * |
|
692 | + * @since 1.0.19 |
|
693 | + */ |
|
694 | + public function get_discounts() { |
|
695 | + return $this->discounts; |
|
696 | + } |
|
697 | + |
|
698 | + /* |
|
699 | 699 | |-------------------------------------------------------------------------- |
700 | 700 | | Fees |
701 | 701 | |-------------------------------------------------------------------------- |
@@ -705,100 +705,100 @@ discard block |
||
705 | 705 | | fees. |
706 | 706 | */ |
707 | 707 | |
708 | - /** |
|
709 | - * Prepares the submission's fees. |
|
710 | - * |
|
711 | - * @since 1.0.19 |
|
712 | - */ |
|
713 | - public function process_fees() { |
|
714 | - |
|
715 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
716 | - |
|
717 | - foreach ( $fees_processor->fees as $fee ) { |
|
718 | - $this->add_fee( $fee ); |
|
719 | - } |
|
720 | - |
|
721 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * Adds a fee to the submission. |
|
726 | - * |
|
727 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
728 | - * @since 1.0.19 |
|
729 | - */ |
|
730 | - public function add_fee( $fee ) { |
|
731 | - |
|
732 | - if ( $fee['name'] == 'shipping' ) { |
|
733 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
734 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
735 | - return; |
|
736 | - } |
|
737 | - |
|
738 | - $this->fees[ $fee['name'] ] = $fee; |
|
739 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
740 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
741 | - |
|
742 | - } |
|
743 | - |
|
744 | - /** |
|
745 | - * Removes a fee from the submission. |
|
746 | - * |
|
747 | - * @since 1.0.19 |
|
748 | - */ |
|
749 | - public function remove_fee( $name ) { |
|
750 | - |
|
751 | - if ( isset( $this->fees[ $name ] ) ) { |
|
752 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
753 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
754 | - unset( $this->fees[ $name ] ); |
|
755 | - } |
|
756 | - |
|
757 | - if ( 'shipping' == $name ) { |
|
758 | - $this->totals['shipping']['initial'] = 0; |
|
759 | - $this->totals['shipping']['recurring'] = 0; |
|
760 | - } |
|
761 | - |
|
762 | - } |
|
763 | - |
|
764 | - /** |
|
765 | - * Returns the fees. |
|
766 | - * |
|
767 | - * @since 1.0.19 |
|
768 | - */ |
|
769 | - public function get_fee() { |
|
770 | - return $this->totals['fees']['initial']; |
|
771 | - } |
|
772 | - |
|
773 | - /** |
|
774 | - * Returns the recurring fees. |
|
775 | - * |
|
776 | - * @since 1.0.19 |
|
777 | - */ |
|
778 | - public function get_recurring_fee() { |
|
779 | - return $this->totals['fees']['recurring']; |
|
780 | - } |
|
781 | - |
|
782 | - /** |
|
783 | - * Returns all fees. |
|
784 | - * |
|
785 | - * @since 1.0.19 |
|
786 | - */ |
|
787 | - public function get_fees() { |
|
788 | - return $this->fees; |
|
789 | - } |
|
790 | - |
|
791 | - /** |
|
792 | - * Checks if there are any fees for the form. |
|
793 | - * |
|
794 | - * @return bool |
|
795 | - * @since 1.0.19 |
|
796 | - */ |
|
797 | - public function has_fees() { |
|
798 | - return count( $this->fees ) !== 0; |
|
799 | - } |
|
800 | - |
|
801 | - /* |
|
708 | + /** |
|
709 | + * Prepares the submission's fees. |
|
710 | + * |
|
711 | + * @since 1.0.19 |
|
712 | + */ |
|
713 | + public function process_fees() { |
|
714 | + |
|
715 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
716 | + |
|
717 | + foreach ( $fees_processor->fees as $fee ) { |
|
718 | + $this->add_fee( $fee ); |
|
719 | + } |
|
720 | + |
|
721 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * Adds a fee to the submission. |
|
726 | + * |
|
727 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
728 | + * @since 1.0.19 |
|
729 | + */ |
|
730 | + public function add_fee( $fee ) { |
|
731 | + |
|
732 | + if ( $fee['name'] == 'shipping' ) { |
|
733 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
734 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
735 | + return; |
|
736 | + } |
|
737 | + |
|
738 | + $this->fees[ $fee['name'] ] = $fee; |
|
739 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
740 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
741 | + |
|
742 | + } |
|
743 | + |
|
744 | + /** |
|
745 | + * Removes a fee from the submission. |
|
746 | + * |
|
747 | + * @since 1.0.19 |
|
748 | + */ |
|
749 | + public function remove_fee( $name ) { |
|
750 | + |
|
751 | + if ( isset( $this->fees[ $name ] ) ) { |
|
752 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
753 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
754 | + unset( $this->fees[ $name ] ); |
|
755 | + } |
|
756 | + |
|
757 | + if ( 'shipping' == $name ) { |
|
758 | + $this->totals['shipping']['initial'] = 0; |
|
759 | + $this->totals['shipping']['recurring'] = 0; |
|
760 | + } |
|
761 | + |
|
762 | + } |
|
763 | + |
|
764 | + /** |
|
765 | + * Returns the fees. |
|
766 | + * |
|
767 | + * @since 1.0.19 |
|
768 | + */ |
|
769 | + public function get_fee() { |
|
770 | + return $this->totals['fees']['initial']; |
|
771 | + } |
|
772 | + |
|
773 | + /** |
|
774 | + * Returns the recurring fees. |
|
775 | + * |
|
776 | + * @since 1.0.19 |
|
777 | + */ |
|
778 | + public function get_recurring_fee() { |
|
779 | + return $this->totals['fees']['recurring']; |
|
780 | + } |
|
781 | + |
|
782 | + /** |
|
783 | + * Returns all fees. |
|
784 | + * |
|
785 | + * @since 1.0.19 |
|
786 | + */ |
|
787 | + public function get_fees() { |
|
788 | + return $this->fees; |
|
789 | + } |
|
790 | + |
|
791 | + /** |
|
792 | + * Checks if there are any fees for the form. |
|
793 | + * |
|
794 | + * @return bool |
|
795 | + * @since 1.0.19 |
|
796 | + */ |
|
797 | + public function has_fees() { |
|
798 | + return count( $this->fees ) !== 0; |
|
799 | + } |
|
800 | + |
|
801 | + /* |
|
802 | 802 | |-------------------------------------------------------------------------- |
803 | 803 | | MISC |
804 | 804 | |-------------------------------------------------------------------------- |
@@ -806,147 +806,147 @@ discard block |
||
806 | 806 | | Extra submission functions. |
807 | 807 | */ |
808 | 808 | |
809 | - /** |
|
810 | - * Returns the shipping amount. |
|
811 | - * |
|
812 | - * @since 1.0.19 |
|
813 | - */ |
|
814 | - public function get_shipping() { |
|
815 | - return $this->totals['shipping']['initial']; |
|
816 | - } |
|
817 | - |
|
818 | - /** |
|
819 | - * Returns the recurring shipping. |
|
820 | - * |
|
821 | - * @since 1.0.19 |
|
822 | - */ |
|
823 | - public function get_recurring_shipping() { |
|
824 | - return $this->totals['shipping']['recurring']; |
|
825 | - } |
|
826 | - |
|
827 | - /** |
|
828 | - * Checks if there are any shipping fees for the form. |
|
829 | - * |
|
830 | - * @return bool |
|
831 | - * @since 1.0.19 |
|
832 | - */ |
|
833 | - public function has_shipping() { |
|
834 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
835 | - } |
|
836 | - |
|
837 | - /** |
|
838 | - * Checks if this is the initial fetch. |
|
839 | - * |
|
840 | - * @return bool |
|
841 | - * @since 1.0.19 |
|
842 | - */ |
|
843 | - public function is_initial_fetch() { |
|
844 | - return empty( $this->data['initial_state'] ); |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * Returns the total amount to collect for this submission. |
|
849 | - * |
|
850 | - * @since 1.0.19 |
|
851 | - */ |
|
852 | - public function get_total() { |
|
853 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
854 | - return max( $total, 0 ); |
|
855 | - } |
|
856 | - |
|
857 | - /** |
|
858 | - * Returns the recurring total amount to collect for this submission. |
|
859 | - * |
|
860 | - * @since 1.0.19 |
|
861 | - */ |
|
862 | - public function get_recurring_total() { |
|
863 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
864 | - return max( $total, 0 ); |
|
865 | - } |
|
866 | - |
|
867 | - /** |
|
868 | - * Whether payment details should be collected for this submission. |
|
869 | - * |
|
870 | - * @since 1.0.19 |
|
871 | - */ |
|
872 | - public function should_collect_payment_details() { |
|
873 | - $initial = $this->get_total(); |
|
874 | - $recurring = $this->get_recurring_total(); |
|
875 | - |
|
876 | - if ( $this->has_recurring == 0 ) { |
|
877 | - $recurring = 0; |
|
878 | - } |
|
879 | - |
|
880 | - $collect = $initial > 0 || $recurring > 0; |
|
881 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Returns the billing email of the user. |
|
886 | - * |
|
887 | - * @since 1.0.19 |
|
888 | - */ |
|
889 | - public function get_billing_email() { |
|
890 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
891 | - } |
|
892 | - |
|
893 | - /** |
|
894 | - * Checks if the submitter has a billing email. |
|
895 | - * |
|
896 | - * @since 1.0.19 |
|
897 | - */ |
|
898 | - public function has_billing_email() { |
|
899 | - $billing_email = $this->get_billing_email(); |
|
900 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
901 | - } |
|
902 | - |
|
903 | - /** |
|
904 | - * Returns the appropriate currency for the submission. |
|
905 | - * |
|
906 | - * @since 1.0.19 |
|
907 | - * @return string |
|
908 | - */ |
|
909 | - public function get_currency() { |
|
910 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
911 | - } |
|
912 | - |
|
913 | - /** |
|
914 | - * Returns the raw submission data. |
|
915 | - * |
|
916 | - * @since 1.0.19 |
|
917 | - * @return array |
|
918 | - */ |
|
919 | - public function get_data() { |
|
920 | - return $this->data; |
|
921 | - } |
|
922 | - |
|
923 | - /** |
|
924 | - * Returns a field from the submission data |
|
925 | - * |
|
926 | - * @param string $field |
|
927 | - * @since 1.0.19 |
|
928 | - * @return mixed|null |
|
929 | - */ |
|
930 | - public function get_field( $field, $sub_array_key = null ) { |
|
931 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
932 | - } |
|
933 | - |
|
934 | - /** |
|
935 | - * Checks if a required field is set. |
|
936 | - * |
|
937 | - * @since 1.0.19 |
|
938 | - */ |
|
939 | - public function is_required_field_set( $field ) { |
|
940 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
941 | - } |
|
942 | - |
|
943 | - /** |
|
944 | - * Formats an amount |
|
945 | - * |
|
946 | - * @since 1.0.19 |
|
947 | - */ |
|
948 | - public function format_amount( $amount ) { |
|
949 | - return wpinv_price( $amount, $this->get_currency() ); |
|
950 | - } |
|
809 | + /** |
|
810 | + * Returns the shipping amount. |
|
811 | + * |
|
812 | + * @since 1.0.19 |
|
813 | + */ |
|
814 | + public function get_shipping() { |
|
815 | + return $this->totals['shipping']['initial']; |
|
816 | + } |
|
817 | + |
|
818 | + /** |
|
819 | + * Returns the recurring shipping. |
|
820 | + * |
|
821 | + * @since 1.0.19 |
|
822 | + */ |
|
823 | + public function get_recurring_shipping() { |
|
824 | + return $this->totals['shipping']['recurring']; |
|
825 | + } |
|
826 | + |
|
827 | + /** |
|
828 | + * Checks if there are any shipping fees for the form. |
|
829 | + * |
|
830 | + * @return bool |
|
831 | + * @since 1.0.19 |
|
832 | + */ |
|
833 | + public function has_shipping() { |
|
834 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
835 | + } |
|
836 | + |
|
837 | + /** |
|
838 | + * Checks if this is the initial fetch. |
|
839 | + * |
|
840 | + * @return bool |
|
841 | + * @since 1.0.19 |
|
842 | + */ |
|
843 | + public function is_initial_fetch() { |
|
844 | + return empty( $this->data['initial_state'] ); |
|
845 | + } |
|
846 | + |
|
847 | + /** |
|
848 | + * Returns the total amount to collect for this submission. |
|
849 | + * |
|
850 | + * @since 1.0.19 |
|
851 | + */ |
|
852 | + public function get_total() { |
|
853 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
854 | + return max( $total, 0 ); |
|
855 | + } |
|
856 | + |
|
857 | + /** |
|
858 | + * Returns the recurring total amount to collect for this submission. |
|
859 | + * |
|
860 | + * @since 1.0.19 |
|
861 | + */ |
|
862 | + public function get_recurring_total() { |
|
863 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
864 | + return max( $total, 0 ); |
|
865 | + } |
|
866 | + |
|
867 | + /** |
|
868 | + * Whether payment details should be collected for this submission. |
|
869 | + * |
|
870 | + * @since 1.0.19 |
|
871 | + */ |
|
872 | + public function should_collect_payment_details() { |
|
873 | + $initial = $this->get_total(); |
|
874 | + $recurring = $this->get_recurring_total(); |
|
875 | + |
|
876 | + if ( $this->has_recurring == 0 ) { |
|
877 | + $recurring = 0; |
|
878 | + } |
|
879 | + |
|
880 | + $collect = $initial > 0 || $recurring > 0; |
|
881 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Returns the billing email of the user. |
|
886 | + * |
|
887 | + * @since 1.0.19 |
|
888 | + */ |
|
889 | + public function get_billing_email() { |
|
890 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
891 | + } |
|
892 | + |
|
893 | + /** |
|
894 | + * Checks if the submitter has a billing email. |
|
895 | + * |
|
896 | + * @since 1.0.19 |
|
897 | + */ |
|
898 | + public function has_billing_email() { |
|
899 | + $billing_email = $this->get_billing_email(); |
|
900 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
901 | + } |
|
902 | + |
|
903 | + /** |
|
904 | + * Returns the appropriate currency for the submission. |
|
905 | + * |
|
906 | + * @since 1.0.19 |
|
907 | + * @return string |
|
908 | + */ |
|
909 | + public function get_currency() { |
|
910 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
911 | + } |
|
912 | + |
|
913 | + /** |
|
914 | + * Returns the raw submission data. |
|
915 | + * |
|
916 | + * @since 1.0.19 |
|
917 | + * @return array |
|
918 | + */ |
|
919 | + public function get_data() { |
|
920 | + return $this->data; |
|
921 | + } |
|
922 | + |
|
923 | + /** |
|
924 | + * Returns a field from the submission data |
|
925 | + * |
|
926 | + * @param string $field |
|
927 | + * @since 1.0.19 |
|
928 | + * @return mixed|null |
|
929 | + */ |
|
930 | + public function get_field( $field, $sub_array_key = null ) { |
|
931 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
932 | + } |
|
933 | + |
|
934 | + /** |
|
935 | + * Checks if a required field is set. |
|
936 | + * |
|
937 | + * @since 1.0.19 |
|
938 | + */ |
|
939 | + public function is_required_field_set( $field ) { |
|
940 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
941 | + } |
|
942 | + |
|
943 | + /** |
|
944 | + * Formats an amount |
|
945 | + * |
|
946 | + * @since 1.0.19 |
|
947 | + */ |
|
948 | + public function format_amount( $amount ) { |
|
949 | + return wpinv_price( $amount, $this->get_currency() ); |
|
950 | + } |
|
951 | 951 | |
952 | 952 | } |