@@ -615,8 +615,11 @@ |
||
615 | 615 | <a href="<?php echo esc_url( add_query_arg( array( 'give-restart-db-upgrades' => 1 ), admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-restart-updater-btn"> |
616 | 616 | <?php _e( 'Restart the updater', 'give' ); ?> |
617 | 617 | </a> |
618 | - <?php else: ?> |
|
619 | - <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
|
618 | + <?php else { |
|
619 | + : ?> |
|
620 | + <strong><?php _e( 'Database Update', 'give' ); |
|
621 | +} |
|
622 | +?></strong> |
|
620 | 623 | – <?php _e( 'An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give' ); ?> |
621 | 624 | <a href="<?php echo esc_url('http://docs.givewp.com/troubleshooting-db-updates')?>" target="_blank"><?php _e( 'Read More', 'give' ); ?> »</a> |
622 | 625 | <?php |
@@ -80,34 +80,34 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param array $args |
82 | 82 | */ |
83 | - public function register( $args ) { |
|
83 | + public function register($args) { |
|
84 | 84 | $args_default = array( |
85 | 85 | 'id' => '', |
86 | 86 | 'version' => '', |
87 | 87 | 'callback' => '', |
88 | 88 | ); |
89 | 89 | |
90 | - $args = wp_parse_args( $args, $args_default ); |
|
90 | + $args = wp_parse_args($args, $args_default); |
|
91 | 91 | |
92 | 92 | // You can only register database upgrade. |
93 | 93 | $args['type'] = 'database'; |
94 | 94 | |
95 | 95 | // Bailout. |
96 | 96 | if ( |
97 | - empty( $args['id'] ) || |
|
98 | - empty( $args['version'] ) || |
|
99 | - empty( $args['callback'] ) || |
|
100 | - ! is_callable( $args['callback'] ) |
|
97 | + empty($args['id']) || |
|
98 | + empty($args['version']) || |
|
99 | + empty($args['callback']) || |
|
100 | + ! is_callable($args['callback']) |
|
101 | 101 | ) { |
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | 105 | // Change depend param to array. |
106 | - if ( isset( $args['depend'] ) && is_string( $args['depend'] ) ) { |
|
107 | - $args['depend'] = array( $args['depend'] ); |
|
106 | + if (isset($args['depend']) && is_string($args['depend'])) { |
|
107 | + $args['depend'] = array($args['depend']); |
|
108 | 108 | } |
109 | 109 | |
110 | - $this->updates[ $args['type'] ][] = $args; |
|
110 | + $this->updates[$args['type']][] = $args; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @return static |
119 | 119 | */ |
120 | 120 | static function get_instance() { |
121 | - if ( is_null( self::$instance ) ) { |
|
121 | + if (is_null(self::$instance)) { |
|
122 | 122 | self::$instance = new self(); |
123 | 123 | } |
124 | 124 | |
@@ -136,27 +136,27 @@ discard block |
||
136 | 136 | /** |
137 | 137 | * Load file |
138 | 138 | */ |
139 | - require_once GIVE_PLUGIN_DIR . 'includes/class-give-background-updater.php'; |
|
140 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; |
|
139 | + require_once GIVE_PLUGIN_DIR.'includes/class-give-background-updater.php'; |
|
140 | + require_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/upgrade-functions.php'; |
|
141 | 141 | |
142 | 142 | self::$background_updater = new Give_Background_Updater(); |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * Setup hooks. |
146 | 146 | */ |
147 | - add_action( 'init', array( $this, '__register_upgrade' ), 9999 ); |
|
148 | - add_action( 'give_set_upgrade_completed', array( $this, '__flush_resume_updates' ), 9999 ); |
|
149 | - add_action( 'wp_ajax_give_db_updates_info', array( $this, '__give_db_updates_info' ) ); |
|
150 | - add_action( 'wp_ajax_give_run_db_updates', array( $this, '__give_start_updating' ) ); |
|
151 | - add_action( 'admin_init', array( $this, '__redirect_admin' ) ); |
|
152 | - add_action( 'admin_init', array( $this, '__pause_db_update' ), - 1 ); |
|
153 | - add_action( 'admin_init', array( $this, '__restart_db_update' ), - 1 ); |
|
154 | - add_action( 'admin_notices', array( $this, '__show_notice' ) ); |
|
155 | - add_action( 'give_restart_db_upgrade', array( $this, '__health_background_update' ) ); |
|
156 | - |
|
157 | - if ( is_admin() ) { |
|
158 | - add_action( 'admin_init', array( $this, '__change_donations_label' ), 9999 ); |
|
159 | - add_action( 'admin_menu', array( $this, '__register_menu' ), 9999 ); |
|
147 | + add_action('init', array($this, '__register_upgrade'), 9999); |
|
148 | + add_action('give_set_upgrade_completed', array($this, '__flush_resume_updates'), 9999); |
|
149 | + add_action('wp_ajax_give_db_updates_info', array($this, '__give_db_updates_info')); |
|
150 | + add_action('wp_ajax_give_run_db_updates', array($this, '__give_start_updating')); |
|
151 | + add_action('admin_init', array($this, '__redirect_admin')); |
|
152 | + add_action('admin_init', array($this, '__pause_db_update'), - 1); |
|
153 | + add_action('admin_init', array($this, '__restart_db_update'), - 1); |
|
154 | + add_action('admin_notices', array($this, '__show_notice')); |
|
155 | + add_action('give_restart_db_upgrade', array($this, '__health_background_update')); |
|
156 | + |
|
157 | + if (is_admin()) { |
|
158 | + add_action('admin_init', array($this, '__change_donations_label'), 9999); |
|
159 | + add_action('admin_menu', array($this, '__register_menu'), 9999); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -170,12 +170,12 @@ discard block |
||
170 | 170 | $addons = give_get_plugins(); |
171 | 171 | $plugin_updates = get_plugin_updates(); |
172 | 172 | |
173 | - foreach ( $addons as $key => $info ) { |
|
174 | - if ( 'active' != $info['Status'] || 'add-on' != $info['Type'] || empty( $plugin_updates[ $key ] ) ) { |
|
173 | + foreach ($addons as $key => $info) { |
|
174 | + if ('active' != $info['Status'] || 'add-on' != $info['Type'] || empty($plugin_updates[$key])) { |
|
175 | 175 | continue; |
176 | 176 | } |
177 | 177 | |
178 | - $this->updates['plugin'][] = array_merge( $info, (array) $plugin_updates[ $key ] ); |
|
178 | + $this->updates['plugin'][] = array_merge($info, (array) $plugin_updates[$key]); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @access public |
188 | 188 | */ |
189 | 189 | public function __register_upgrade() { |
190 | - if ( ! is_admin() ) { |
|
190 | + if ( ! is_admin()) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @since 1.8.12 |
198 | 198 | */ |
199 | - do_action( 'give_register_updates', $this ); |
|
199 | + do_action('give_register_updates', $this); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -209,23 +209,22 @@ discard block |
||
209 | 209 | global $menu; |
210 | 210 | |
211 | 211 | // Bailout. |
212 | - if ( empty( $menu ) || ! $this->get_total_update_count() ) { |
|
212 | + if (empty($menu) || ! $this->get_total_update_count()) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | - $is_update = ( $this->is_doing_updates() && ! self::$background_updater->is_paused_process() ); |
|
216 | + $is_update = ($this->is_doing_updates() && ! self::$background_updater->is_paused_process()); |
|
217 | 217 | |
218 | - foreach ( $menu as $index => $menu_item ) { |
|
219 | - if ( 'edit.php?post_type=give_forms' !== $menu_item[2] ) { |
|
218 | + foreach ($menu as $index => $menu_item) { |
|
219 | + if ('edit.php?post_type=give_forms' !== $menu_item[2]) { |
|
220 | 220 | continue; |
221 | 221 | } |
222 | 222 | |
223 | - $menu[ $index ][0] = sprintf( |
|
223 | + $menu[$index][0] = sprintf( |
|
224 | 224 | '%1$s <span class="update-plugins"><span class="plugin-count give-update-progress-count">%2$s%3$s</span></span>', |
225 | - __( 'Donations', 'give' ), |
|
225 | + __('Donations', 'give'), |
|
226 | 226 | $is_update ? |
227 | - $this->get_db_update_processing_percentage() : |
|
228 | - $this->get_total_update_count(), |
|
227 | + $this->get_db_update_processing_percentage() : $this->get_total_update_count(), |
|
229 | 228 | $is_update ? '%' : '' |
230 | 229 | ); |
231 | 230 | |
@@ -244,41 +243,40 @@ discard block |
||
244 | 243 | $this->__register_plugin_addon_updates(); |
245 | 244 | |
246 | 245 | // Bailout. |
247 | - if ( ! $this->get_total_update_count() ) { |
|
246 | + if ( ! $this->get_total_update_count()) { |
|
248 | 247 | // Show complete update message if still on update setting page. |
249 | - if ( isset( $_GET['page'] ) && 'give-updates' === $_GET['page'] ) { |
|
248 | + if (isset($_GET['page']) && 'give-updates' === $_GET['page']) { |
|
250 | 249 | // Upgrades |
251 | 250 | add_submenu_page( |
252 | 251 | 'edit.php?post_type=give_forms', |
253 | - esc_html__( 'Give Updates Complete', 'give' ), |
|
254 | - __( 'Updates', 'give' ), |
|
252 | + esc_html__('Give Updates Complete', 'give'), |
|
253 | + __('Updates', 'give'), |
|
255 | 254 | 'manage_give_settings', |
256 | 255 | 'give-updates', |
257 | - array( $this, 'render_complete_page' ) |
|
256 | + array($this, 'render_complete_page') |
|
258 | 257 | ); |
259 | 258 | } |
260 | 259 | |
261 | 260 | return; |
262 | 261 | } |
263 | 262 | |
264 | - $is_update = ( $this->is_doing_updates() && ! self::$background_updater->is_paused_process() ); |
|
263 | + $is_update = ($this->is_doing_updates() && ! self::$background_updater->is_paused_process()); |
|
265 | 264 | |
266 | 265 | // Upgrades |
267 | 266 | add_submenu_page( |
268 | 267 | 'edit.php?post_type=give_forms', |
269 | - esc_html__( 'Give Updates', 'give' ), |
|
268 | + esc_html__('Give Updates', 'give'), |
|
270 | 269 | sprintf( |
271 | 270 | '%1$s <span class="update-plugins"%2$s><span class="plugin-count give-update-progress-count">%3$s%4$s</span></span>', |
272 | - __( 'Updates', 'give' ), |
|
273 | - isset( $_GET['give-pause-db-upgrades'] ) ? ' style="display:none;"' : '', |
|
271 | + __('Updates', 'give'), |
|
272 | + isset($_GET['give-pause-db-upgrades']) ? ' style="display:none;"' : '', |
|
274 | 273 | $is_update ? |
275 | - $this->get_db_update_processing_percentage() : |
|
276 | - $this->get_total_update_count(), |
|
274 | + $this->get_db_update_processing_percentage() : $this->get_total_update_count(), |
|
277 | 275 | $is_update ? '%' : '' |
278 | 276 | ), |
279 | 277 | 'manage_give_settings', |
280 | 278 | 'give-updates', |
281 | - array( $this, 'render_page' ) |
|
279 | + array($this, 'render_page') |
|
282 | 280 | ); |
283 | 281 | } |
284 | 282 | |
@@ -293,13 +291,13 @@ discard block |
||
293 | 291 | // Show db upgrade completed notice. |
294 | 292 | if ( |
295 | 293 | ! wp_doing_ajax() && |
296 | - current_user_can( 'manage_give_settings' ) && |
|
297 | - get_option( 'give_show_db_upgrade_complete_notice' ) && |
|
298 | - ! isset( $_GET['give-db-update-completed'] ) |
|
294 | + current_user_can('manage_give_settings') && |
|
295 | + get_option('give_show_db_upgrade_complete_notice') && |
|
296 | + ! isset($_GET['give-db-update-completed']) |
|
299 | 297 | ) { |
300 | - delete_option( 'give_show_db_upgrade_complete_notice' ); |
|
298 | + delete_option('give_show_db_upgrade_complete_notice'); |
|
301 | 299 | |
302 | - wp_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-updates&give-db-update-completed=give_db_upgrade_completed' ) ); |
|
300 | + wp_redirect(admin_url('edit.php?post_type=give_forms&page=give-updates&give-db-update-completed=give_db_upgrade_completed')); |
|
303 | 301 | exit(); |
304 | 302 | } |
305 | 303 | } |
@@ -315,15 +313,15 @@ discard block |
||
315 | 313 | * |
316 | 314 | * @return bool |
317 | 315 | */ |
318 | - public function __pause_db_update( $force = false ) { |
|
316 | + public function __pause_db_update($force = false) { |
|
319 | 317 | // Bailout. |
320 | 318 | if ( |
321 | 319 | ! $force && |
322 | 320 | ( |
323 | 321 | wp_doing_ajax() || |
324 | - ! isset( $_GET['page'] ) || |
|
322 | + ! isset($_GET['page']) || |
|
325 | 323 | 'give-updates' !== $_GET['page'] || |
326 | - ! isset( $_GET['give-pause-db-upgrades'] ) || |
|
324 | + ! isset($_GET['give-pause-db-upgrades']) || |
|
327 | 325 | self::$background_updater->is_paused_process() |
328 | 326 | ) |
329 | 327 | |
@@ -331,13 +329,13 @@ discard block |
||
331 | 329 | return false; |
332 | 330 | } |
333 | 331 | |
334 | - delete_option( 'give_upgrade_error' ); |
|
332 | + delete_option('give_upgrade_error'); |
|
335 | 333 | |
336 | - $this->__health_background_update( $this ); |
|
334 | + $this->__health_background_update($this); |
|
337 | 335 | $batch = self::$background_updater->get_all_batch(); |
338 | 336 | |
339 | 337 | // Bailout: if batch is empty |
340 | - if ( empty( $batch->data ) ) { |
|
338 | + if (empty($batch->data)) { |
|
341 | 339 | return false; |
342 | 340 | } |
343 | 341 | |
@@ -346,25 +344,25 @@ discard block |
||
346 | 344 | |
347 | 345 | // Do not stop background process immediately if task running. |
348 | 346 | // @see Give_Background_Updater::lock_process |
349 | - if ( ! $force && self::$background_updater->is_process_running() ) { |
|
350 | - update_option( 'give_pause_upgrade', 1, false ); |
|
347 | + if ( ! $force && self::$background_updater->is_process_running()) { |
|
348 | + update_option('give_pause_upgrade', 1, false); |
|
351 | 349 | |
352 | 350 | return true; |
353 | 351 | } |
354 | 352 | |
355 | - update_option( 'give_paused_batches', $batch, false ); |
|
356 | - delete_option( $batch->key ); |
|
357 | - delete_site_transient( self::$background_updater->get_identifier() . '_process_lock' ); |
|
358 | - wp_clear_scheduled_hook( self::$background_updater->get_cron_identifier() ); |
|
353 | + update_option('give_paused_batches', $batch, false); |
|
354 | + delete_option($batch->key); |
|
355 | + delete_site_transient(self::$background_updater->get_identifier().'_process_lock'); |
|
356 | + wp_clear_scheduled_hook(self::$background_updater->get_cron_identifier()); |
|
359 | 357 | |
360 | - Give()->logs->add( 'Update Pause', print_r( $batch, true ), 0, 'update' ); |
|
358 | + Give()->logs->add('Update Pause', print_r($batch, true), 0, 'update'); |
|
361 | 359 | |
362 | 360 | /** |
363 | 361 | * Fire action when pause db updates |
364 | 362 | * |
365 | 363 | * @since 2.0.1 |
366 | 364 | */ |
367 | - do_action( 'give_pause_db_upgrade', $this ); |
|
365 | + do_action('give_pause_db_upgrade', $this); |
|
368 | 366 | |
369 | 367 | return true; |
370 | 368 | } |
@@ -381,31 +379,31 @@ discard block |
||
381 | 379 | // Bailout. |
382 | 380 | if ( |
383 | 381 | wp_doing_ajax() || |
384 | - ! isset( $_GET['page'] ) || |
|
382 | + ! isset($_GET['page']) || |
|
385 | 383 | 'give-updates' !== $_GET['page'] || |
386 | - ! isset( $_GET['give-restart-db-upgrades'] ) || |
|
384 | + ! isset($_GET['give-restart-db-upgrades']) || |
|
387 | 385 | ! self::$background_updater->is_paused_process() |
388 | 386 | ) { |
389 | 387 | return false; |
390 | 388 | } |
391 | 389 | |
392 | 390 | Give_Background_Updater::flush_cache(); |
393 | - $batch = get_option( 'give_paused_batches' ); |
|
391 | + $batch = get_option('give_paused_batches'); |
|
394 | 392 | |
395 | - if ( ! empty( $batch ) ) { |
|
396 | - wp_cache_delete( $batch->key, 'options' ); |
|
397 | - update_option( $batch->key, $batch->data, false ); |
|
393 | + if ( ! empty($batch)) { |
|
394 | + wp_cache_delete($batch->key, 'options'); |
|
395 | + update_option($batch->key, $batch->data, false); |
|
398 | 396 | |
399 | - delete_option( 'give_paused_batches' ); |
|
397 | + delete_option('give_paused_batches'); |
|
400 | 398 | |
401 | - Give()->logs->add( 'Update Restart', print_r( $batch, true ), 0, 'update' ); |
|
399 | + Give()->logs->add('Update Restart', print_r($batch, true), 0, 'update'); |
|
402 | 400 | |
403 | 401 | |
404 | 402 | /** Fire action when restart db updates |
405 | 403 | * |
406 | 404 | * @since 2.0.1 |
407 | 405 | */ |
408 | - do_action( 'give_restart_db_upgrade', $this ); |
|
406 | + do_action('give_restart_db_upgrade', $this); |
|
409 | 407 | |
410 | 408 | self::$background_updater->dispatch(); |
411 | 409 | } |
@@ -421,53 +419,53 @@ discard block |
||
421 | 419 | * |
422 | 420 | * @param Give_Updates $give_updates |
423 | 421 | */ |
424 | - public function __health_background_update( $give_updates ) { |
|
425 | - if ( ! $this->is_doing_updates() ) { |
|
422 | + public function __health_background_update($give_updates) { |
|
423 | + if ( ! $this->is_doing_updates()) { |
|
426 | 424 | return; |
427 | 425 | } |
428 | 426 | |
429 | 427 | Give_Background_Updater::flush_cache(); |
430 | 428 | |
431 | 429 | $batch = Give_Updates::$background_updater->get_all_batch(); |
432 | - $batch_data_count = count( $batch->data ); |
|
433 | - $all_updates = $give_updates->get_updates( 'database', 'all' ); |
|
434 | - $all_update_ids = wp_list_pluck( $all_updates, 'id' ); |
|
435 | - $all_batch_update_ids = ! empty( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : array(); |
|
430 | + $batch_data_count = count($batch->data); |
|
431 | + $all_updates = $give_updates->get_updates('database', 'all'); |
|
432 | + $all_update_ids = wp_list_pluck($all_updates, 'id'); |
|
433 | + $all_batch_update_ids = ! empty($batch->data) ? wp_list_pluck($batch->data, 'id') : array(); |
|
436 | 434 | $log_data = ''; |
437 | - $doing_upgrade_args = get_option( 'give_doing_upgrade' ); |
|
435 | + $doing_upgrade_args = get_option('give_doing_upgrade'); |
|
438 | 436 | |
439 | - if ( ! empty( $doing_upgrade_args ) ) { |
|
440 | - $log_data .= 'Doing update:' . "\n"; |
|
441 | - $log_data .= print_r( $doing_upgrade_args, true ) . "\n"; |
|
437 | + if ( ! empty($doing_upgrade_args)) { |
|
438 | + $log_data .= 'Doing update:'."\n"; |
|
439 | + $log_data .= print_r($doing_upgrade_args, true)."\n"; |
|
442 | 440 | } |
443 | 441 | |
444 | 442 | /** |
445 | 443 | * Add remove upgrade from batch |
446 | 444 | */ |
447 | - if ( ! empty( $batch->data ) ) { |
|
445 | + if ( ! empty($batch->data)) { |
|
448 | 446 | |
449 | - foreach ( $batch->data as $index => $update ) { |
|
450 | - $log_data = print_r( $update, true ) . "\n"; |
|
447 | + foreach ($batch->data as $index => $update) { |
|
448 | + $log_data = print_r($update, true)."\n"; |
|
451 | 449 | |
452 | - if ( ! is_callable( $update['callback'] ) ) { |
|
453 | - $log_data .= 'Removing missing callback update: ' . "{$update['id']}\n"; |
|
454 | - unset( $batch->data[ $index ] ); |
|
455 | - } elseif ( give_has_upgrade_completed( $update['id'] ) ) { |
|
456 | - $log_data .= 'Removing already completed update: ' . "{$update['id']}\n"; |
|
457 | - unset( $batch->data[ $index ] ); |
|
450 | + if ( ! is_callable($update['callback'])) { |
|
451 | + $log_data .= 'Removing missing callback update: '."{$update['id']}\n"; |
|
452 | + unset($batch->data[$index]); |
|
453 | + } elseif (give_has_upgrade_completed($update['id'])) { |
|
454 | + $log_data .= 'Removing already completed update: '."{$update['id']}\n"; |
|
455 | + unset($batch->data[$index]); |
|
458 | 456 | } |
459 | 457 | |
460 | - if ( ! empty( $update['depend'] ) ) { |
|
458 | + if ( ! empty($update['depend'])) { |
|
461 | 459 | |
462 | - foreach ( $update['depend'] as $depend ) { |
|
463 | - if ( give_has_upgrade_completed( $depend ) ) { |
|
464 | - $log_data .= 'Completed update: ' . "{$depend}\n"; |
|
460 | + foreach ($update['depend'] as $depend) { |
|
461 | + if (give_has_upgrade_completed($depend)) { |
|
462 | + $log_data .= 'Completed update: '."{$depend}\n"; |
|
465 | 463 | continue; |
466 | 464 | } |
467 | 465 | |
468 | - if ( in_array( $depend, $all_update_ids ) && ! in_array( $depend, $all_batch_update_ids ) ) { |
|
469 | - $log_data .= 'Adding missing update: ' . "{$depend}\n"; |
|
470 | - array_unshift( $batch->data, $all_updates[ array_search( $depend, $all_update_ids ) ] ); |
|
466 | + if (in_array($depend, $all_update_ids) && ! in_array($depend, $all_batch_update_ids)) { |
|
467 | + $log_data .= 'Adding missing update: '."{$depend}\n"; |
|
468 | + array_unshift($batch->data, $all_updates[array_search($depend, $all_update_ids)]); |
|
471 | 469 | } |
472 | 470 | } |
473 | 471 | } |
@@ -477,52 +475,52 @@ discard block |
||
477 | 475 | /** |
478 | 476 | * Add new upgrade to batch |
479 | 477 | */ |
480 | - if ( $new_updates = $this->get_updates( 'database', 'new' ) ) { |
|
481 | - $all_batch_update_ids = ! empty( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : array(); |
|
478 | + if ($new_updates = $this->get_updates('database', 'new')) { |
|
479 | + $all_batch_update_ids = ! empty($batch->data) ? wp_list_pluck($batch->data, 'id') : array(); |
|
482 | 480 | |
483 | - foreach ( $new_updates as $index => $new_update ) { |
|
484 | - if ( give_has_upgrade_completed( $new_update['id'] ) || in_array( $new_update['id'], $all_batch_update_ids ) ) { |
|
485 | - unset( $new_updates[ $index ] ); |
|
481 | + foreach ($new_updates as $index => $new_update) { |
|
482 | + if (give_has_upgrade_completed($new_update['id']) || in_array($new_update['id'], $all_batch_update_ids)) { |
|
483 | + unset($new_updates[$index]); |
|
486 | 484 | } |
487 | 485 | } |
488 | 486 | |
489 | - if ( ! empty( $new_updates ) ) { |
|
490 | - $log_data .= 'Adding new update: ' . "\n"; |
|
491 | - $log_data .= print_r( $new_updates, true ) . "\n"; |
|
487 | + if ( ! empty($new_updates)) { |
|
488 | + $log_data .= 'Adding new update: '."\n"; |
|
489 | + $log_data .= print_r($new_updates, true)."\n"; |
|
492 | 490 | |
493 | - $batch->data = array_merge( (array) $batch->data, $new_updates ); |
|
494 | - update_option( 'give_db_update_count', ( absint( get_option( 'give_db_update_count' ) ) + count( $new_updates ) ), false ); |
|
491 | + $batch->data = array_merge((array) $batch->data, $new_updates); |
|
492 | + update_option('give_db_update_count', (absint(get_option('give_db_update_count')) + count($new_updates)), false); |
|
495 | 493 | } |
496 | 494 | } |
497 | 495 | |
498 | 496 | /** |
499 | 497 | * Fix batch |
500 | 498 | */ |
501 | - if ( empty( $batch->data ) ) { |
|
499 | + if (empty($batch->data)) { |
|
502 | 500 | // Complete batch if do not have any data to process. |
503 | - self::$background_updater->delete( $batch->key ); |
|
501 | + self::$background_updater->delete($batch->key); |
|
504 | 502 | |
505 | - if ( self::$background_updater->has_queue() ) { |
|
506 | - $this->__health_background_update( $this ); |
|
503 | + if (self::$background_updater->has_queue()) { |
|
504 | + $this->__health_background_update($this); |
|
507 | 505 | } else { |
508 | - delete_site_transient( self::$background_updater->get_identifier() . '_process_lock' ); |
|
509 | - wp_clear_scheduled_hook( self::$background_updater->get_cron_identifier() ); |
|
506 | + delete_site_transient(self::$background_updater->get_identifier().'_process_lock'); |
|
507 | + wp_clear_scheduled_hook(self::$background_updater->get_cron_identifier()); |
|
510 | 508 | |
511 | 509 | self::$background_updater->complete(); |
512 | 510 | } |
513 | 511 | |
514 | - } elseif ( $batch_data_count !== count( $batch->data ) ) { |
|
512 | + } elseif ($batch_data_count !== count($batch->data)) { |
|
515 | 513 | |
516 | - $log_data .= 'Updating batch' . "\n"; |
|
517 | - $log_data .= print_r( $batch, true ); |
|
514 | + $log_data .= 'Updating batch'."\n"; |
|
515 | + $log_data .= print_r($batch, true); |
|
518 | 516 | |
519 | - if ( ! empty( $batch->key ) ) { |
|
520 | - wp_cache_delete( $batch->key, 'options' ); |
|
521 | - update_option( $batch->key, $batch->data, false ); |
|
517 | + if ( ! empty($batch->key)) { |
|
518 | + wp_cache_delete($batch->key, 'options'); |
|
519 | + update_option($batch->key, $batch->data, false); |
|
522 | 520 | } else { |
523 | 521 | |
524 | - foreach ( $batch->data as $data ) { |
|
525 | - Give_Updates::$background_updater->push_to_queue( $data ); |
|
522 | + foreach ($batch->data as $data) { |
|
523 | + Give_Updates::$background_updater->push_to_queue($data); |
|
526 | 524 | } |
527 | 525 | |
528 | 526 | Give_Updates::$background_updater->save(); |
@@ -533,31 +531,31 @@ discard block |
||
533 | 531 | /** |
534 | 532 | * Fix give_doing_upgrade option |
535 | 533 | */ |
536 | - if( $fresh_new_db_count = $this->get_total_new_db_update_count( true ) ) { |
|
537 | - update_option( 'give_db_update_count', $fresh_new_db_count, false ); |
|
534 | + if ($fresh_new_db_count = $this->get_total_new_db_update_count(true)) { |
|
535 | + update_option('give_db_update_count', $fresh_new_db_count, false); |
|
538 | 536 | } |
539 | 537 | |
540 | 538 | $doing_upgrade_args['update'] = 1; |
541 | - $doing_upgrade_args['heading'] = sprintf( 'Update %s of %s', 1, $fresh_new_db_count ); |
|
542 | - $doing_upgrade_args['total_percentage'] = $this->get_db_update_processing_percentage( true ); |
|
539 | + $doing_upgrade_args['heading'] = sprintf('Update %s of %s', 1, $fresh_new_db_count); |
|
540 | + $doing_upgrade_args['total_percentage'] = $this->get_db_update_processing_percentage(true); |
|
543 | 541 | |
544 | 542 | // Remove already completed update from info. |
545 | 543 | if ( |
546 | - empty( $doing_upgrade_args['update_info'] ) |
|
547 | - || give_has_upgrade_completed( $doing_upgrade_args['update_info']['id'] ) |
|
544 | + empty($doing_upgrade_args['update_info']) |
|
545 | + || give_has_upgrade_completed($doing_upgrade_args['update_info']['id']) |
|
548 | 546 | ) { |
549 | - $doing_upgrade_args['update_info'] = current( array_values( $batch->data ) ); |
|
547 | + $doing_upgrade_args['update_info'] = current(array_values($batch->data)); |
|
550 | 548 | $doing_upgrade_args['step'] = 1; |
551 | 549 | } |
552 | 550 | |
553 | 551 | // Check if dependency completed or not. |
554 | - if ( isset( $doing_upgrade_args['update_info']['depend'] ) ) { |
|
555 | - foreach ( $doing_upgrade_args['update_info']['depend'] as $depend ) { |
|
556 | - if ( give_has_upgrade_completed( $depend ) ) { |
|
552 | + if (isset($doing_upgrade_args['update_info']['depend'])) { |
|
553 | + foreach ($doing_upgrade_args['update_info']['depend'] as $depend) { |
|
554 | + if (give_has_upgrade_completed($depend)) { |
|
557 | 555 | continue; |
558 | 556 | } |
559 | 557 | |
560 | - $doing_upgrade_args['update_info'] = $all_updates[ array_search( $depend, $all_update_ids ) ]; |
|
558 | + $doing_upgrade_args['update_info'] = $all_updates[array_search($depend, $all_update_ids)]; |
|
561 | 559 | $doing_upgrade_args['step'] = 1; |
562 | 560 | $doing_upgrade_args['percentage'] = 0; |
563 | 561 | $doing_upgrade_args['total_percentage'] = 0; |
@@ -566,14 +564,14 @@ discard block |
||
566 | 564 | } |
567 | 565 | } |
568 | 566 | |
569 | - if( ! empty( $doing_upgrade_args['update_info'] ) ) { |
|
570 | - update_option( 'give_doing_upgrade', $doing_upgrade_args, false ); |
|
567 | + if ( ! empty($doing_upgrade_args['update_info'])) { |
|
568 | + update_option('give_doing_upgrade', $doing_upgrade_args, false); |
|
571 | 569 | |
572 | - $log_data .= 'Updated doing update:' . "\n"; |
|
573 | - $log_data .= print_r( $doing_upgrade_args, true ) . "\n"; |
|
570 | + $log_data .= 'Updated doing update:'."\n"; |
|
571 | + $log_data .= print_r($doing_upgrade_args, true)."\n"; |
|
574 | 572 | } |
575 | 573 | |
576 | - Give()->logs->add( 'Update Health Check', $log_data, 0, 'update' ); |
|
574 | + Give()->logs->add('Update Health Check', $log_data, 0, 'update'); |
|
577 | 575 | } |
578 | 576 | |
579 | 577 | |
@@ -587,90 +585,90 @@ discard block |
||
587 | 585 | $current_screen = get_current_screen(); |
588 | 586 | |
589 | 587 | // Bailout. |
590 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
588 | + if ( ! current_user_can('manage_give_settings')) { |
|
591 | 589 | return; |
592 | 590 | } |
593 | 591 | |
594 | 592 | // Run DB updates. |
595 | - if ( ! empty( $_GET['give-run-db-update'] ) ) { |
|
593 | + if ( ! empty($_GET['give-run-db-update'])) { |
|
596 | 594 | $this->run_db_update(); |
597 | 595 | } |
598 | 596 | |
599 | 597 | |
600 | 598 | // Bailout. |
601 | - if ( in_array( $current_screen->base, array( 'give_forms_page_give-updates', 'update-core' ) ) ) { |
|
599 | + if (in_array($current_screen->base, array('give_forms_page_give-updates', 'update-core'))) { |
|
602 | 600 | return; |
603 | 601 | } |
604 | 602 | |
605 | 603 | // Show notice if upgrade paused. |
606 | - if ( self::$background_updater->is_paused_process() ) { |
|
604 | + if (self::$background_updater->is_paused_process()) { |
|
607 | 605 | ob_start(); |
608 | 606 | |
609 | - $upgrade_error = get_option( 'give_upgrade_error' ); |
|
610 | - if ( ! $upgrade_error ) : ?> |
|
611 | - <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
|
612 | - – <?php _e( 'GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a backup before proceeding.', 'give' ); ?> |
|
607 | + $upgrade_error = get_option('give_upgrade_error'); |
|
608 | + if ( ! $upgrade_error) : ?> |
|
609 | + <strong><?php _e('Database Update', 'give'); ?></strong> |
|
610 | + – <?php _e('GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a backup before proceeding.', 'give'); ?> |
|
613 | 611 | <br> |
614 | 612 | <br> |
615 | - <a href="<?php echo esc_url( add_query_arg( array( 'give-restart-db-upgrades' => 1 ), admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-restart-updater-btn"> |
|
616 | - <?php _e( 'Restart the updater', 'give' ); ?> |
|
613 | + <a href="<?php echo esc_url(add_query_arg(array('give-restart-db-upgrades' => 1), admin_url('edit.php?post_type=give_forms&page=give-updates'))); ?>" class="button button-primary give-restart-updater-btn"> |
|
614 | + <?php _e('Restart the updater', 'give'); ?> |
|
617 | 615 | </a> |
618 | 616 | <?php else: ?> |
619 | - <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
|
620 | - – <?php _e( 'An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give' ); ?> |
|
621 | - <a href="<?php echo esc_url('http://docs.givewp.com/troubleshooting-db-updates')?>" target="_blank"><?php _e( 'Read More', 'give' ); ?> »</a> |
|
617 | + <strong><?php _e('Database Update', 'give'); ?></strong> |
|
618 | + – <?php _e('An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give'); ?> |
|
619 | + <a href="<?php echo esc_url('http://docs.givewp.com/troubleshooting-db-updates')?>" target="_blank"><?php _e('Read More', 'give'); ?> »</a> |
|
622 | 620 | <?php |
623 | 621 | endif; |
624 | 622 | $desc_html = ob_get_clean(); |
625 | 623 | |
626 | - Give()->notices->register_notice( array( |
|
624 | + Give()->notices->register_notice(array( |
|
627 | 625 | 'id' => 'give_upgrade_db', |
628 | 626 | 'type' => 'error', |
629 | 627 | 'dismissible' => false, |
630 | 628 | 'description' => $desc_html, |
631 | - ) ); |
|
629 | + )); |
|
632 | 630 | } |
633 | 631 | |
634 | 632 | // Bailout if doing upgrades. |
635 | - if ( $this->is_doing_updates() ) { |
|
633 | + if ($this->is_doing_updates()) { |
|
636 | 634 | return; |
637 | 635 | } |
638 | 636 | |
639 | 637 | // Show db upgrade completed notice. |
640 | - if ( ! empty( $_GET['give-db-update-completed'] ) ) { |
|
641 | - Give()->notices->register_notice( array( |
|
638 | + if ( ! empty($_GET['give-db-update-completed'])) { |
|
639 | + Give()->notices->register_notice(array( |
|
642 | 640 | 'id' => 'give_db_upgrade_completed', |
643 | 641 | 'type' => 'updated', |
644 | - 'description' => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ), |
|
642 | + 'description' => __('Give database updates completed successfully. Thank you for updating to the latest version!', 'give'), |
|
645 | 643 | 'show' => true, |
646 | - ) ); |
|
644 | + )); |
|
647 | 645 | |
648 | 646 | // Start update. |
649 | - } elseif ( ! empty( $_GET['give-run-db-update'] ) ) { |
|
647 | + } elseif ( ! empty($_GET['give-run-db-update'])) { |
|
650 | 648 | $this->run_db_update(); |
651 | 649 | |
652 | 650 | // Show run the update notice. |
653 | - } elseif ( $this->get_total_new_db_update_count() ) { |
|
651 | + } elseif ($this->get_total_new_db_update_count()) { |
|
654 | 652 | ob_start(); |
655 | 653 | ?> |
656 | 654 | <p> |
657 | - <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
|
658 | - – <?php _e( 'GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a complete backup before proceeding.', 'give' ); ?> |
|
655 | + <strong><?php _e('Database Update', 'give'); ?></strong> |
|
656 | + – <?php _e('GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a complete backup before proceeding.', 'give'); ?> |
|
659 | 657 | </p> |
660 | 658 | <p class="submit"> |
661 | - <a href="<?php echo esc_url( add_query_arg( array( 'give-run-db-update' => 1 ), admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-run-update-now"> |
|
662 | - <?php _e( 'Run the updater', 'give' ); ?> |
|
659 | + <a href="<?php echo esc_url(add_query_arg(array('give-run-db-update' => 1), admin_url('edit.php?post_type=give_forms&page=give-updates'))); ?>" class="button button-primary give-run-update-now"> |
|
660 | + <?php _e('Run the updater', 'give'); ?> |
|
663 | 661 | </a> |
664 | 662 | </p> |
665 | 663 | <?php |
666 | 664 | $desc_html = ob_get_clean(); |
667 | 665 | |
668 | - Give()->notices->register_notice( array( |
|
666 | + Give()->notices->register_notice(array( |
|
669 | 667 | 'id' => 'give_upgrade_db', |
670 | 668 | 'type' => 'updated', |
671 | 669 | 'dismissible' => false, |
672 | 670 | 'description' => $desc_html, |
673 | - ) ); |
|
671 | + )); |
|
674 | 672 | } |
675 | 673 | } |
676 | 674 | |
@@ -681,7 +679,7 @@ discard block |
||
681 | 679 | * @access public |
682 | 680 | */ |
683 | 681 | public function render_complete_page() { |
684 | - include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades-complete.php'; |
|
682 | + include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades-complete.php'; |
|
685 | 683 | } |
686 | 684 | |
687 | 685 | /** |
@@ -691,7 +689,7 @@ discard block |
||
691 | 689 | * @access public |
692 | 690 | */ |
693 | 691 | public function render_page() { |
694 | - include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades.php'; |
|
692 | + include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades.php'; |
|
695 | 693 | } |
696 | 694 | |
697 | 695 | /** |
@@ -702,26 +700,26 @@ discard block |
||
702 | 700 | */ |
703 | 701 | private function run_db_update() { |
704 | 702 | // Bailout. |
705 | - if ( $this->is_doing_updates() || ! $this->get_total_new_db_update_count() ) { |
|
703 | + if ($this->is_doing_updates() || ! $this->get_total_new_db_update_count()) { |
|
706 | 704 | return; |
707 | 705 | } |
708 | 706 | |
709 | - $updates = $this->get_updates( 'database', 'new' ); |
|
707 | + $updates = $this->get_updates('database', 'new'); |
|
710 | 708 | |
711 | - foreach ( $updates as $update ) { |
|
712 | - self::$background_updater->push_to_queue( $update ); |
|
709 | + foreach ($updates as $update) { |
|
710 | + self::$background_updater->push_to_queue($update); |
|
713 | 711 | } |
714 | 712 | |
715 | - add_option( 'give_db_update_count', count( $updates ), '', false ); |
|
713 | + add_option('give_db_update_count', count($updates), '', false); |
|
716 | 714 | |
717 | - add_option( 'give_doing_upgrade', array( |
|
715 | + add_option('give_doing_upgrade', array( |
|
718 | 716 | 'update_info' => $updates[0], |
719 | 717 | 'step' => 1, |
720 | 718 | 'update' => 1, |
721 | - 'heading' => sprintf( 'Update %s of %s', 1, count( $updates ) ), |
|
719 | + 'heading' => sprintf('Update %s of %s', 1, count($updates)), |
|
722 | 720 | 'percentage' => 0, |
723 | 721 | 'total_percentage' => 0, |
724 | - ), '', false ); |
|
722 | + ), '', false); |
|
725 | 723 | |
726 | 724 | self::$background_updater->save()->dispatch(); |
727 | 725 | } |
@@ -735,14 +733,13 @@ discard block |
||
735 | 733 | */ |
736 | 734 | public function __flush_resume_updates() { |
737 | 735 | //delete_option( 'give_doing_upgrade' ); |
738 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ), false ); |
|
736 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION), false); |
|
739 | 737 | |
740 | 738 | // Reset counter. |
741 | 739 | $this->step = $this->percentage = 0; |
742 | 740 | |
743 | - $this->update = ( $this->get_total_db_update_count() > $this->update ) ? |
|
744 | - ( $this->update + 1 ) : |
|
745 | - $this->update; |
|
741 | + $this->update = ($this->get_total_db_update_count() > $this->update) ? |
|
742 | + ($this->update + 1) : $this->update; |
|
746 | 743 | } |
747 | 744 | |
748 | 745 | |
@@ -757,7 +754,7 @@ discard block |
||
757 | 754 | public function __give_start_updating() { |
758 | 755 | // Check permission. |
759 | 756 | if ( |
760 | - ! current_user_can( 'manage_give_settings' ) || |
|
757 | + ! current_user_can('manage_give_settings') || |
|
761 | 758 | $this->is_doing_updates() |
762 | 759 | ) { |
763 | 760 | // Run update via ajax |
@@ -768,7 +765,7 @@ discard block |
||
768 | 765 | |
769 | 766 | // @todo: validate nonce |
770 | 767 | // @todo: set http method to post |
771 | - if ( empty( $_POST['run_db_update'] ) ) { |
|
768 | + if (empty($_POST['run_db_update'])) { |
|
772 | 769 | wp_send_json_error(); |
773 | 770 | } |
774 | 771 | |
@@ -787,34 +784,34 @@ discard block |
||
787 | 784 | * @return string |
788 | 785 | */ |
789 | 786 | public function __give_db_updates_info() { |
790 | - $update_info = get_option( 'give_doing_upgrade' ); |
|
787 | + $update_info = get_option('give_doing_upgrade'); |
|
791 | 788 | $response_type = ''; |
792 | 789 | |
793 | - if ( self::$background_updater->is_paused_process() ) { |
|
790 | + if (self::$background_updater->is_paused_process()) { |
|
794 | 791 | $update_info = array( |
795 | - 'message' => __( 'The updates have been paused.', 'give' ), |
|
792 | + 'message' => __('The updates have been paused.', 'give'), |
|
796 | 793 | 'heading' => '', |
797 | 794 | 'percentage' => 0, |
798 | 795 | ); |
799 | 796 | |
800 | - if ( get_option( 'give_upgrade_error' ) ) { |
|
801 | - $update_info['message'] = __( 'An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give' ); |
|
797 | + if (get_option('give_upgrade_error')) { |
|
798 | + $update_info['message'] = __('An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give'); |
|
802 | 799 | } |
803 | 800 | |
804 | 801 | $response_type = 'error'; |
805 | 802 | |
806 | - } elseif ( empty( $update_info ) || ! $this->get_total_new_db_update_count( true ) ) { |
|
803 | + } elseif (empty($update_info) || ! $this->get_total_new_db_update_count(true)) { |
|
807 | 804 | $update_info = array( |
808 | - 'message' => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ), |
|
809 | - 'heading' => __( 'Updates Completed.', 'give' ), |
|
805 | + 'message' => __('Give database updates completed successfully. Thank you for updating to the latest version!', 'give'), |
|
806 | + 'heading' => __('Updates Completed.', 'give'), |
|
810 | 807 | 'percentage' => 0, |
811 | 808 | ); |
812 | 809 | $response_type = 'success'; |
813 | 810 | |
814 | - delete_option( 'give_show_db_upgrade_complete_notice' ); |
|
811 | + delete_option('give_show_db_upgrade_complete_notice'); |
|
815 | 812 | } |
816 | 813 | |
817 | - $this->send_ajax_response( $update_info, $response_type ); |
|
814 | + $this->send_ajax_response($update_info, $response_type); |
|
818 | 815 | } |
819 | 816 | |
820 | 817 | /** |
@@ -826,7 +823,7 @@ discard block |
||
826 | 823 | * @param $data |
827 | 824 | * @param string $type |
828 | 825 | */ |
829 | - public function send_ajax_response( $data, $type = '' ) { |
|
826 | + public function send_ajax_response($data, $type = '') { |
|
830 | 827 | $default = array( |
831 | 828 | 'message' => '', |
832 | 829 | 'heading' => '', |
@@ -836,24 +833,24 @@ discard block |
||
836 | 833 | ); |
837 | 834 | |
838 | 835 | // Set data. |
839 | - $data = wp_parse_args( $data, $default ); |
|
836 | + $data = wp_parse_args($data, $default); |
|
840 | 837 | |
841 | 838 | // Enable cache. |
842 | 839 | Give_Cache::enable(); |
843 | 840 | |
844 | - switch ( $type ) { |
|
841 | + switch ($type) { |
|
845 | 842 | case 'success': |
846 | - wp_send_json_success( $data ); |
|
843 | + wp_send_json_success($data); |
|
847 | 844 | break; |
848 | 845 | |
849 | 846 | case 'error': |
850 | - wp_send_json_error( $data ); |
|
847 | + wp_send_json_error($data); |
|
851 | 848 | break; |
852 | 849 | |
853 | 850 | default: |
854 | - wp_send_json( array( |
|
851 | + wp_send_json(array( |
|
855 | 852 | 'data' => $data, |
856 | - ) ); |
|
853 | + )); |
|
857 | 854 | break; |
858 | 855 | } |
859 | 856 | } |
@@ -867,12 +864,12 @@ discard block |
||
867 | 864 | * @param $total |
868 | 865 | * @param $current_total |
869 | 866 | */ |
870 | - public function set_percentage( $total, $current_total ) { |
|
867 | + public function set_percentage($total, $current_total) { |
|
871 | 868 | // Set percentage. |
872 | - $this->percentage = $total ? ( ( $current_total ) / $total ) * 100 : 0; |
|
869 | + $this->percentage = $total ? (($current_total) / $total) * 100 : 0; |
|
873 | 870 | |
874 | 871 | // Verify percentage. |
875 | - $this->percentage = ( 100 < $this->percentage ) ? 100 : $this->percentage; |
|
872 | + $this->percentage = (100 < $this->percentage) ? 100 : $this->percentage; |
|
876 | 873 | } |
877 | 874 | |
878 | 875 | /** |
@@ -885,22 +882,22 @@ discard block |
||
885 | 882 | * |
886 | 883 | * @return bool|null |
887 | 884 | */ |
888 | - public function is_parent_updates_completed( $update ) { |
|
885 | + public function is_parent_updates_completed($update) { |
|
889 | 886 | // Bailout. |
890 | - if ( empty( $update['depend'] ) ) { |
|
887 | + if (empty($update['depend'])) { |
|
891 | 888 | return true; |
892 | 889 | } |
893 | 890 | |
894 | 891 | // Check if dependency is valid or not. |
895 | - if ( ! $this->has_valid_dependency( $update ) ) { |
|
892 | + if ( ! $this->has_valid_dependency($update)) { |
|
896 | 893 | return null; |
897 | 894 | } |
898 | 895 | |
899 | 896 | $is_dependency_completed = true; |
900 | 897 | |
901 | - foreach ( $update['depend'] as $depend ) { |
|
898 | + foreach ($update['depend'] as $depend) { |
|
902 | 899 | |
903 | - if ( ! give_has_upgrade_completed( $depend ) ) { |
|
900 | + if ( ! give_has_upgrade_completed($depend)) { |
|
904 | 901 | $is_dependency_completed = false; |
905 | 902 | break; |
906 | 903 | } |
@@ -917,7 +914,7 @@ discard block |
||
917 | 914 | * @return bool |
918 | 915 | */ |
919 | 916 | public function is_doing_updates() { |
920 | - return (bool) get_option( 'give_doing_upgrade' ); |
|
917 | + return (bool) get_option('give_doing_upgrade'); |
|
921 | 918 | } |
922 | 919 | |
923 | 920 | |
@@ -931,7 +928,7 @@ discard block |
||
931 | 928 | * |
932 | 929 | * @return bool |
933 | 930 | */ |
934 | - public function has_valid_dependency( $update ) { |
|
931 | + public function has_valid_dependency($update) { |
|
935 | 932 | $is_valid_dependency = true; |
936 | 933 | // $update_ids = wp_list_pluck( $this->get_updates( 'database', 'all' ), 'id' ); |
937 | 934 | // |
@@ -957,33 +954,33 @@ discard block |
||
957 | 954 | * |
958 | 955 | * @return array |
959 | 956 | */ |
960 | - public function get_updates( $update_type = '', $status = 'all' ) { |
|
957 | + public function get_updates($update_type = '', $status = 'all') { |
|
961 | 958 | // return all updates. |
962 | - if ( empty( $update_type ) ) { |
|
959 | + if (empty($update_type)) { |
|
963 | 960 | return $this->updates; |
964 | 961 | } |
965 | 962 | |
966 | 963 | // Get specific update. |
967 | - $updates = ! empty( $this->updates[ $update_type ] ) ? $this->updates[ $update_type ] : array(); |
|
964 | + $updates = ! empty($this->updates[$update_type]) ? $this->updates[$update_type] : array(); |
|
968 | 965 | |
969 | 966 | // Bailout. |
970 | - if ( empty( $updates ) ) { |
|
967 | + if (empty($updates)) { |
|
971 | 968 | return $updates; |
972 | 969 | } |
973 | 970 | |
974 | - switch ( $status ) { |
|
971 | + switch ($status) { |
|
975 | 972 | case 'new': |
976 | 973 | // Remove already completed updates. |
977 | - wp_cache_delete( 'give_completed_upgrades', 'options' ); |
|
974 | + wp_cache_delete('give_completed_upgrades', 'options'); |
|
978 | 975 | $completed_updates = give_get_completed_upgrades(); |
979 | 976 | |
980 | - if ( ! empty( $completed_updates ) ) { |
|
981 | - foreach ( $updates as $index => $update ) { |
|
982 | - if ( in_array( $update['id'], $completed_updates ) ) { |
|
983 | - unset( $updates[ $index ] ); |
|
977 | + if ( ! empty($completed_updates)) { |
|
978 | + foreach ($updates as $index => $update) { |
|
979 | + if (in_array($update['id'], $completed_updates)) { |
|
980 | + unset($updates[$index]); |
|
984 | 981 | } |
985 | 982 | } |
986 | - $updates = array_values( $updates ); |
|
983 | + $updates = array_values($updates); |
|
987 | 984 | } |
988 | 985 | |
989 | 986 | break; |
@@ -1000,7 +997,7 @@ discard block |
||
1000 | 997 | * @return int |
1001 | 998 | */ |
1002 | 999 | public function get_total_plugin_update_count() { |
1003 | - return count( $this->get_updates( 'plugin' ) ); |
|
1000 | + return count($this->get_updates('plugin')); |
|
1004 | 1001 | } |
1005 | 1002 | |
1006 | 1003 | /** |
@@ -1015,7 +1012,7 @@ discard block |
||
1015 | 1012 | $db_update_count = $this->get_pending_db_update_count(); |
1016 | 1013 | $plugin_update_count = $this->get_total_plugin_update_count(); |
1017 | 1014 | |
1018 | - return ( $db_update_count + $plugin_update_count ); |
|
1015 | + return ($db_update_count + $plugin_update_count); |
|
1019 | 1016 | } |
1020 | 1017 | |
1021 | 1018 | /** |
@@ -1027,7 +1024,7 @@ discard block |
||
1027 | 1024 | * @return int |
1028 | 1025 | */ |
1029 | 1026 | public function get_pending_db_update_count() { |
1030 | - return count( $this->get_updates( 'database', 'new' ) ); |
|
1027 | + return count($this->get_updates('database', 'new')); |
|
1031 | 1028 | } |
1032 | 1029 | |
1033 | 1030 | /** |
@@ -1039,7 +1036,7 @@ discard block |
||
1039 | 1036 | * @return int |
1040 | 1037 | */ |
1041 | 1038 | public function get_total_db_update_count() { |
1042 | - return count( $this->get_updates( 'database', 'all' ) ); |
|
1039 | + return count($this->get_updates('database', 'all')); |
|
1043 | 1040 | } |
1044 | 1041 | |
1045 | 1042 | /** |
@@ -1052,10 +1049,9 @@ discard block |
||
1052 | 1049 | * |
1053 | 1050 | * @return int |
1054 | 1051 | */ |
1055 | - public function get_total_new_db_update_count( $refresh = false ) { |
|
1052 | + public function get_total_new_db_update_count($refresh = false) { |
|
1056 | 1053 | $update_count = $this->is_doing_updates() && ! $refresh ? |
1057 | - get_option( 'give_db_update_count' ) : |
|
1058 | - $this->get_pending_db_update_count(); |
|
1054 | + get_option('give_db_update_count') : $this->get_pending_db_update_count(); |
|
1059 | 1055 | |
1060 | 1056 | return $update_count; |
1061 | 1057 | } |
@@ -1070,11 +1066,11 @@ discard block |
||
1070 | 1066 | * |
1071 | 1067 | * @return int |
1072 | 1068 | */ |
1073 | - public function get_running_db_update( $refresh = false ) { |
|
1069 | + public function get_running_db_update($refresh = false) { |
|
1074 | 1070 | $current_update = 1; |
1075 | 1071 | |
1076 | - if ( $this->is_doing_updates() && ! $refresh ) { |
|
1077 | - $current_update = get_option( 'give_doing_upgrade' ); |
|
1072 | + if ($this->is_doing_updates() && ! $refresh) { |
|
1073 | + $current_update = get_option('give_doing_upgrade'); |
|
1078 | 1074 | $current_update = $current_update['update']; |
1079 | 1075 | } |
1080 | 1076 | |
@@ -1091,25 +1087,23 @@ discard block |
||
1091 | 1087 | * |
1092 | 1088 | * @return float|int |
1093 | 1089 | */ |
1094 | - public function get_db_update_processing_percentage( $refresh = false ) { |
|
1090 | + public function get_db_update_processing_percentage($refresh = false) { |
|
1095 | 1091 | // Bailout. |
1096 | - if ( ! $this->get_total_new_db_update_count( $refresh ) ) { |
|
1092 | + if ( ! $this->get_total_new_db_update_count($refresh)) { |
|
1097 | 1093 | return 0; |
1098 | 1094 | } |
1099 | 1095 | |
1100 | - $resume_update = get_option( 'give_doing_upgrade' ); |
|
1101 | - $update_count_percentages = ( ( $this->get_running_db_update( $refresh ) - 1 ) / $this->get_total_new_db_update_count( $refresh ) ) * 100; |
|
1102 | - $update_percentage_share = ( 1 / $this->get_total_new_db_update_count() ) * 100; |
|
1103 | - $upgrade_percentage = ( ( $resume_update['percentage'] * $update_percentage_share ) / 100 ); |
|
1096 | + $resume_update = get_option('give_doing_upgrade'); |
|
1097 | + $update_count_percentages = (($this->get_running_db_update($refresh) - 1) / $this->get_total_new_db_update_count($refresh)) * 100; |
|
1098 | + $update_percentage_share = (1 / $this->get_total_new_db_update_count()) * 100; |
|
1099 | + $upgrade_percentage = (($resume_update['percentage'] * $update_percentage_share) / 100); |
|
1104 | 1100 | |
1105 | 1101 | $final_percentage = $update_count_percentages + $upgrade_percentage; |
1106 | 1102 | |
1107 | 1103 | return $this->is_doing_updates() ? |
1108 | - ( absint( $final_percentage ) ? |
|
1109 | - absint( $final_percentage ) : |
|
1110 | - round( $final_percentage, 2 ) |
|
1111 | - ) : |
|
1112 | - 0; |
|
1104 | + (absint($final_percentage) ? |
|
1105 | + absint($final_percentage) : round($final_percentage, 2) |
|
1106 | + ) : 0; |
|
1113 | 1107 | } |
1114 | 1108 | |
1115 | 1109 | |
@@ -1121,8 +1115,8 @@ discard block |
||
1121 | 1115 | * @return array |
1122 | 1116 | */ |
1123 | 1117 | public function get_update_ids() { |
1124 | - $all_updates = $this->get_updates( 'database', 'all' ); |
|
1125 | - $all_update_ids = wp_list_pluck( $all_updates, 'id' ); |
|
1118 | + $all_updates = $this->get_updates('database', 'all'); |
|
1119 | + $all_update_ids = wp_list_pluck($all_updates, 'id'); |
|
1126 | 1120 | |
1127 | 1121 | return $all_update_ids; |
1128 | 1122 | } |
@@ -1137,10 +1131,9 @@ discard block |
||
1137 | 1131 | * |
1138 | 1132 | * @return float|int |
1139 | 1133 | */ |
1140 | - public function get_offset( $process_item_count ) { |
|
1141 | - return ( 1 === $this->step ) ? |
|
1142 | - 0 : |
|
1143 | - ( $this->step - 1 ) * $process_item_count; |
|
1134 | + public function get_offset($process_item_count) { |
|
1135 | + return (1 === $this->step) ? |
|
1136 | + 0 : ($this->step - 1) * $process_item_count; |
|
1144 | 1137 | } |
1145 | 1138 | } |
1146 | 1139 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() { |
26 | 26 | |
27 | - $this->shortcode['title'] = esc_html__( 'Donation Receipt', 'give' ); |
|
28 | - $this->shortcode['label'] = esc_html__( 'Donation Receipt', 'give' ); |
|
27 | + $this->shortcode['title'] = esc_html__('Donation Receipt', 'give'); |
|
28 | + $this->shortcode['label'] = esc_html__('Donation Receipt', 'give'); |
|
29 | 29 | |
30 | - parent::__construct( 'give_receipt' ); |
|
30 | + parent::__construct('give_receipt'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -40,71 +40,71 @@ discard block |
||
40 | 40 | return array( |
41 | 41 | array( |
42 | 42 | 'type' => 'container', |
43 | - 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'Optional settings', 'give' ) ), |
|
43 | + 'html' => sprintf('<p class="strong">%s</p>', esc_html__('Optional settings', 'give')), |
|
44 | 44 | ), |
45 | 45 | array( |
46 | 46 | 'type' => 'listbox', |
47 | 47 | 'name' => 'price', |
48 | - 'label' => esc_html__( 'Show Donation Amount:', 'give' ), |
|
48 | + 'label' => esc_html__('Show Donation Amount:', 'give'), |
|
49 | 49 | 'options' => array( |
50 | - 'false' => esc_html__( 'Hide', 'give' ), |
|
50 | + 'false' => esc_html__('Hide', 'give'), |
|
51 | 51 | ), |
52 | - 'placeholder' => esc_html__( 'Show', 'give' ) |
|
52 | + 'placeholder' => esc_html__('Show', 'give') |
|
53 | 53 | ), |
54 | 54 | array( |
55 | 55 | 'type' => 'listbox', |
56 | 56 | 'name' => 'donor', |
57 | - 'label' => esc_html__( 'Show Donor Name:', 'give' ), |
|
57 | + 'label' => esc_html__('Show Donor Name:', 'give'), |
|
58 | 58 | 'options' => array( |
59 | - 'true' => esc_html__( 'Show', 'give' ), |
|
60 | - 'false' => esc_html__( 'Hide', 'give' ), |
|
59 | + 'true' => esc_html__('Show', 'give'), |
|
60 | + 'false' => esc_html__('Hide', 'give'), |
|
61 | 61 | ), |
62 | - 'placeholder' => esc_html__( 'Show', 'give' ) |
|
62 | + 'placeholder' => esc_html__('Show', 'give') |
|
63 | 63 | ), |
64 | 64 | array( |
65 | 65 | 'type' => 'listbox', |
66 | 66 | 'name' => 'date', |
67 | - 'label' => esc_html__( 'Show Date:', 'give' ), |
|
67 | + 'label' => esc_html__('Show Date:', 'give'), |
|
68 | 68 | 'options' => array( |
69 | - 'false' => esc_html__( 'Hide', 'give' ), |
|
69 | + 'false' => esc_html__('Hide', 'give'), |
|
70 | 70 | ), |
71 | - 'placeholder' => esc_html__( 'Show', 'give' ), |
|
71 | + 'placeholder' => esc_html__('Show', 'give'), |
|
72 | 72 | ), |
73 | 73 | array( |
74 | 74 | 'type' => 'listbox', |
75 | 75 | 'name' => 'payment_key', |
76 | - 'label' => esc_html__( 'Show Payment Key:', 'give' ), |
|
76 | + 'label' => esc_html__('Show Payment Key:', 'give'), |
|
77 | 77 | 'options' => array( |
78 | - 'true' => esc_html__( 'Show', 'give' ), |
|
78 | + 'true' => esc_html__('Show', 'give'), |
|
79 | 79 | ), |
80 | - 'placeholder' => esc_html__( 'Hide', 'give' ), |
|
80 | + 'placeholder' => esc_html__('Hide', 'give'), |
|
81 | 81 | ), |
82 | 82 | array( |
83 | 83 | 'type' => 'listbox', |
84 | 84 | 'name' => 'payment_method', |
85 | - 'label' => esc_html__( 'Show Payment Method:', 'give' ), |
|
85 | + 'label' => esc_html__('Show Payment Method:', 'give'), |
|
86 | 86 | 'options' => array( |
87 | - 'false' => esc_html__( 'Hide', 'give' ), |
|
87 | + 'false' => esc_html__('Hide', 'give'), |
|
88 | 88 | ), |
89 | - 'placeholder' => esc_html__( 'Show', 'give' ), |
|
89 | + 'placeholder' => esc_html__('Show', 'give'), |
|
90 | 90 | ), |
91 | 91 | array( |
92 | 92 | 'type' => 'listbox', |
93 | 93 | 'name' => 'payment_id', |
94 | - 'label' => esc_html__( 'Show Payment ID:', 'give' ), |
|
94 | + 'label' => esc_html__('Show Payment ID:', 'give'), |
|
95 | 95 | 'options' => array( |
96 | - 'false' => esc_html__( 'Hide', 'give' ), |
|
96 | + 'false' => esc_html__('Hide', 'give'), |
|
97 | 97 | ), |
98 | - 'placeholder' => esc_html__( 'Show', 'give' ), |
|
98 | + 'placeholder' => esc_html__('Show', 'give'), |
|
99 | 99 | ), |
100 | 100 | array( |
101 | 101 | 'type' => 'listbox', |
102 | 102 | 'name' => 'company_name', |
103 | - 'label' => esc_html__( 'Company Name:', 'give' ), |
|
103 | + 'label' => esc_html__('Company Name:', 'give'), |
|
104 | 104 | 'options' => array( |
105 | - 'true' => esc_html__( 'Show', 'give' ), |
|
105 | + 'true' => esc_html__('Show', 'give'), |
|
106 | 106 | ), |
107 | - 'placeholder' => esc_html__( 'Hide', 'give' ) |
|
107 | + 'placeholder' => esc_html__('Hide', 'give') |
|
108 | 108 | ), |
109 | 109 | ); |
110 | 110 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if access directly. |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return static |
47 | 47 | */ |
48 | 48 | static function get_instance() { |
49 | - if ( null === static::$instance ) { |
|
49 | + if (null === static::$instance) { |
|
50 | 50 | self::$instance = new static(); |
51 | 51 | } |
52 | 52 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return bool |
66 | 66 | */ |
67 | - public static function has_preview( Give_Email_Notification $email ) { |
|
67 | + public static function has_preview(Give_Email_Notification $email) { |
|
68 | 68 | return $email->config['has_preview']; |
69 | 69 | } |
70 | 70 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return bool |
80 | 80 | */ |
81 | - public static function has_recipient_field( Give_Email_Notification $email ) { |
|
81 | + public static function has_recipient_field(Give_Email_Notification $email) { |
|
82 | 82 | return $email->config['has_recipient_field']; |
83 | 83 | } |
84 | 84 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return bool |
94 | 94 | */ |
95 | - public static function is_notification_status_editable( Give_Email_Notification $email ) { |
|
95 | + public static function is_notification_status_editable(Give_Email_Notification $email) { |
|
96 | 96 | $user_can_edit = $email->config['notification_status_editable']; |
97 | 97 | |
98 | 98 | return (bool) $user_can_edit; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return bool |
110 | 110 | */ |
111 | - public static function is_content_type_editable( Give_Email_Notification $email ) { |
|
111 | + public static function is_content_type_editable(Give_Email_Notification $email) { |
|
112 | 112 | return $email->config['content_type_editable']; |
113 | 113 | } |
114 | 114 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @return bool |
124 | 124 | */ |
125 | - public static function is_email_preview_has_header( Give_Email_Notification $email ) { |
|
125 | + public static function is_email_preview_has_header(Give_Email_Notification $email) { |
|
126 | 126 | return $email->config['has_preview_header']; |
127 | 127 | } |
128 | 128 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * |
137 | 137 | * @return bool |
138 | 138 | */ |
139 | - public static function is_email_preview( Give_Email_Notification $email ) { |
|
139 | + public static function is_email_preview(Give_Email_Notification $email) { |
|
140 | 140 | return $email->config['has_preview']; |
141 | 141 | } |
142 | 142 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return bool |
152 | 152 | */ |
153 | - public static function is_show_on_emails_setting_page( Give_Email_Notification $email ){ |
|
153 | + public static function is_show_on_emails_setting_page(Give_Email_Notification $email) { |
|
154 | 154 | return $email->config['show_on_emails_setting_page']; |
155 | 155 | } |
156 | 156 | |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @return bool |
167 | 167 | */ |
168 | - public static function can_use_form_email_options( Give_Email_Notification $email, $form_id = null ){ |
|
169 | - return give_is_setting_enabled( give_get_meta( $form_id, '_give_email_options', true ) ); |
|
168 | + public static function can_use_form_email_options(Give_Email_Notification $email, $form_id = null) { |
|
169 | + return give_is_setting_enabled(give_get_meta($form_id, '_give_email_options', true)); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @return string |
182 | 182 | */ |
183 | - public static function is_email_notification_active( Give_Email_Notification $email, $form_id = null ) { |
|
184 | - $notification_status = $email->get_notification_status( $form_id ); |
|
183 | + public static function is_email_notification_active(Give_Email_Notification $email, $form_id = null) { |
|
184 | + $notification_status = $email->get_notification_status($form_id); |
|
185 | 185 | |
186 | 186 | |
187 | - $notification_status = empty( $form_id ) |
|
188 | - ? give_is_setting_enabled( $notification_status ) |
|
189 | - : give_is_setting_enabled( give_get_option( "{$email->config['id']}_notification", $email->config['notification_status'] ) ) && give_is_setting_enabled( $notification_status, array( 'enabled', 'global' ) ); |
|
187 | + $notification_status = empty($form_id) |
|
188 | + ? give_is_setting_enabled($notification_status) |
|
189 | + : give_is_setting_enabled(give_get_option("{$email->config['id']}_notification", $email->config['notification_status'])) && give_is_setting_enabled($notification_status, array('enabled', 'global')); |
|
190 | 190 | // To check if email notification is active or not on a per-form basis, email notification must be globally active—otherwise it will be considered disabled. |
191 | 191 | |
192 | 192 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @param bool $notification_status True if notification is enable and false when disable |
202 | 202 | */ |
203 | - return apply_filters( "give_{$email->config['id']}_is_email_notification_active", $notification_status, $email, $form_id ); |
|
203 | + return apply_filters("give_{$email->config['id']}_is_email_notification_active", $notification_status, $email, $form_id); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | $is_preview = false; |
215 | 215 | |
216 | 216 | if ( |
217 | - current_user_can( 'manage_give_settings' ) |
|
218 | - && ! empty( $_GET['give_action'] ) |
|
217 | + current_user_can('manage_give_settings') |
|
218 | + && ! empty($_GET['give_action']) |
|
219 | 219 | && 'preview_email' === $_GET['give_action'] |
220 | 220 | ) { |
221 | 221 | $is_preview = true; |
@@ -235,8 +235,8 @@ discard block |
||
235 | 235 | $is_preview = false; |
236 | 236 | |
237 | 237 | if ( |
238 | - current_user_can( 'manage_give_settings' ) |
|
239 | - && ! empty( $_GET['give_action'] ) |
|
238 | + current_user_can('manage_give_settings') |
|
239 | + && ! empty($_GET['give_action']) |
|
240 | 240 | && 'send_preview_email' === $_GET['give_action'] |
241 | 241 | ) { |
242 | 242 | $is_preview = true; |
@@ -256,13 +256,13 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return string |
258 | 258 | */ |
259 | - public static function get_formatted_email_type( $content_type ) { |
|
259 | + public static function get_formatted_email_type($content_type) { |
|
260 | 260 | $email_contents = array( |
261 | - 'text/html' => __( 'HTML', 'give' ), |
|
262 | - 'text/plain' => __( 'Plain', 'give' ), |
|
261 | + 'text/html' => __('HTML', 'give'), |
|
262 | + 'text/plain' => __('Plain', 'give'), |
|
263 | 263 | ); |
264 | 264 | |
265 | - return $email_contents[ $content_type ]; |
|
265 | + return $email_contents[$content_type]; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | |
@@ -279,41 +279,41 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return mixed |
281 | 281 | */ |
282 | - public static function get_value( Give_Email_Notification $email, $option_name, $form_id = null, $default = false ) { |
|
282 | + public static function get_value(Give_Email_Notification $email, $option_name, $form_id = null, $default = false) { |
|
283 | 283 | // If form id set then option name can be contain _give_ prefix which is only used for meta key, |
284 | 284 | // So make sure you are using correct option name. |
285 | - $global_option_name = ( 0 === strpos( $option_name, '_give_' ) |
|
286 | - ? str_replace( '_give_', '', $option_name ) |
|
287 | - : $option_name ); |
|
288 | - $option_value = give_get_option( $global_option_name, $default ); |
|
285 | + $global_option_name = (0 === strpos($option_name, '_give_') |
|
286 | + ? str_replace('_give_', '', $option_name) |
|
287 | + : $option_name); |
|
288 | + $option_value = give_get_option($global_option_name, $default); |
|
289 | 289 | |
290 | 290 | if ( |
291 | - ! empty( $form_id ) |
|
291 | + ! empty($form_id) |
|
292 | 292 | && give_is_setting_enabled( |
293 | 293 | give_get_meta( |
294 | 294 | $form_id, |
295 | - Give_Email_Setting_Field::get_prefix( $email, $form_id ) . 'notification', |
|
295 | + Give_Email_Setting_Field::get_prefix($email, $form_id).'notification', |
|
296 | 296 | true, |
297 | 297 | 'global' |
298 | 298 | ) |
299 | 299 | ) |
300 | 300 | ) { |
301 | - $option_value = get_post_meta( $form_id, $option_name, true ); |
|
301 | + $option_value = get_post_meta($form_id, $option_name, true); |
|
302 | 302 | |
303 | 303 | // Get only email field value from recipients setting. |
304 | - if( Give_Email_Setting_Field::get_prefix( $email, $form_id ) . 'recipient' === $option_name ) { |
|
305 | - $option_value = wp_list_pluck( $option_value, 'email' ); |
|
304 | + if (Give_Email_Setting_Field::get_prefix($email, $form_id).'recipient' === $option_name) { |
|
305 | + $option_value = wp_list_pluck($option_value, 'email'); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | - $option_value = empty( $option_value ) ? $default : $option_value; |
|
309 | + $option_value = empty($option_value) ? $default : $option_value; |
|
310 | 310 | |
311 | 311 | /** |
312 | 312 | * Filter the setting value |
313 | 313 | * |
314 | 314 | * @since 2.0 |
315 | 315 | */ |
316 | - return apply_filters( 'give_email_setting_value', $option_value, $option_name, $email, $form_id, $default ); |
|
316 | + return apply_filters('give_email_setting_value', $option_value, $option_name, $email, $form_id, $default); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | * |
329 | 329 | * @return string |
330 | 330 | */ |
331 | - public static function get_email_logo( $form_id ) { |
|
331 | + public static function get_email_logo($form_id) { |
|
332 | 332 | |
333 | 333 | // Email logo tag. |
334 | - $header_img = $form_id && give_is_setting_enabled( give_get_meta( $form_id, '_give_email_options', true ) ) |
|
335 | - ? give_get_meta( $form_id, '_give_email_logo', true ) |
|
336 | - : give_get_option( 'email_logo', '' ); |
|
334 | + $header_img = $form_id && give_is_setting_enabled(give_get_meta($form_id, '_give_email_options', true)) |
|
335 | + ? give_get_meta($form_id, '_give_email_logo', true) |
|
336 | + : give_get_option('email_logo', ''); |
|
337 | 337 | |
338 | 338 | return $header_img; |
339 | 339 | } |
@@ -9,11 +9,11 @@ discard block |
||
9 | 9 | * @since 1.8 |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; // Exit if accessed directly. |
14 | 14 | } |
15 | 15 | |
16 | -if ( ! class_exists( 'Give_Settings_License' ) ) : |
|
16 | +if ( ! class_exists('Give_Settings_License')) : |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Give_Settings_License. |
@@ -27,12 +27,12 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function __construct() { |
29 | 29 | $this->id = 'licenses'; |
30 | - $this->label = esc_html__( 'Licenses', 'give' ); |
|
30 | + $this->label = esc_html__('Licenses', 'give'); |
|
31 | 31 | |
32 | 32 | parent::__construct(); |
33 | 33 | |
34 | 34 | // Filter to remove the license tab. |
35 | - add_filter( 'give-settings_tabs_array', array( $this, 'remove_license_tab' ), 9999999, 1 ); |
|
35 | + add_filter('give-settings_tabs_array', array($this, 'remove_license_tab'), 9999999, 1); |
|
36 | 36 | |
37 | 37 | } |
38 | 38 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * Filter the licenses settings. |
50 | 50 | * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8 |
51 | 51 | */ |
52 | - $settings = apply_filters( 'give_settings_licenses', $settings ); |
|
52 | + $settings = apply_filters('give_settings_licenses', $settings); |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Filter the settings. |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @param array $settings |
60 | 60 | */ |
61 | - $settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
|
61 | + $settings = apply_filters('give_get_settings_'.$this->id, $settings); |
|
62 | 62 | |
63 | 63 | // Output. |
64 | 64 | return $settings; |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return array |
76 | 76 | */ |
77 | - public function remove_license_tab( $tabs ) { |
|
77 | + public function remove_license_tab($tabs) { |
|
78 | 78 | /** |
79 | 79 | * Remove the license tab if no Give licensed addon |
80 | 80 | * is activated. |
81 | 81 | */ |
82 | - if ( ! $this->is_show_setting_page() ) { |
|
83 | - unset( $tabs['licenses'] ); |
|
82 | + if ( ! $this->is_show_setting_page()) { |
|
83 | + unset($tabs['licenses']); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | return $tabs; |
@@ -97,17 +97,17 @@ discard block |
||
97 | 97 | */ |
98 | 98 | private function is_show_setting_page() { |
99 | 99 | $licensed_addons = Give_License::get_licensed_addons(); |
100 | - $activated_plugins = get_option( 'active_plugins', array() ); |
|
100 | + $activated_plugins = get_option('active_plugins', array()); |
|
101 | 101 | |
102 | 102 | // Get list of network enabled plugin. |
103 | - if ( is_multisite() ) { |
|
104 | - $sitewide_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
105 | - $activated_plugins = ! empty( $activated_plugins ) |
|
106 | - ? array_merge( $sitewide_activated_plugins, $activated_plugins ) |
|
103 | + if (is_multisite()) { |
|
104 | + $sitewide_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
105 | + $activated_plugins = ! empty($activated_plugins) |
|
106 | + ? array_merge($sitewide_activated_plugins, $activated_plugins) |
|
107 | 107 | : $sitewide_activated_plugins; |
108 | 108 | } |
109 | 109 | |
110 | - return (bool) count( array_intersect( $activated_plugins, $licensed_addons ) ); |
|
110 | + return (bool) count(array_intersect($activated_plugins, $licensed_addons)); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @since 1.0 |
23 | 23 | * |
24 | - * @return array|bool $output Response messages |
|
24 | + * @return false|null $output Response messages |
|
25 | 25 | */ |
26 | 26 | function give_edit_donor( $args ) { |
27 | 27 | |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * |
435 | 435 | * @since 1.7 |
436 | 436 | * |
437 | - * @return bool|null |
|
437 | + * @return false|null |
|
438 | 438 | */ |
439 | 439 | function give_remove_donor_email() { |
440 | 440 | if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | * |
479 | 479 | * @since 1.7 |
480 | 480 | * |
481 | - * @return bool|null |
|
481 | + * @return false|null |
|
482 | 482 | */ |
483 | 483 | function give_set_donor_primary_email() { |
484 | 484 | if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -23,37 +23,37 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return array|bool $output Response messages |
25 | 25 | */ |
26 | -function give_edit_donor( $args ) { |
|
26 | +function give_edit_donor($args) { |
|
27 | 27 | |
28 | - $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' ); |
|
28 | + $donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments'); |
|
29 | 29 | |
30 | - if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) { |
|
31 | - wp_die( esc_html__( 'You do not have permission to edit this donor.', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
30 | + if ( ! is_admin() || ! current_user_can($donor_edit_role)) { |
|
31 | + wp_die(esc_html__('You do not have permission to edit this donor.', 'give'), esc_html__('Error', 'give'), array( |
|
32 | 32 | 'response' => 403, |
33 | - ) ); |
|
33 | + )); |
|
34 | 34 | } |
35 | 35 | |
36 | - if ( empty( $args ) ) { |
|
36 | + if (empty($args)) { |
|
37 | 37 | return false; |
38 | 38 | } |
39 | 39 | |
40 | 40 | // Sanitize Data. |
41 | - $args = give_clean( $args ); |
|
41 | + $args = give_clean($args); |
|
42 | 42 | |
43 | 43 | // Verify Nonce. |
44 | - if ( ! wp_verify_nonce( $args['_wpnonce'], 'edit-donor' ) ) { |
|
45 | - wp_die( esc_html__( 'Cheatin’ uh?', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
44 | + if ( ! wp_verify_nonce($args['_wpnonce'], 'edit-donor')) { |
|
45 | + wp_die(esc_html__('Cheatin’ uh?', 'give'), esc_html__('Error', 'give'), array( |
|
46 | 46 | 'response' => 400, |
47 | - ) ); |
|
47 | + )); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | $donor_info = $args['donor_info']; |
51 | - $donor_id = intval( $donor_info['id'] ); |
|
51 | + $donor_id = intval($donor_info['id']); |
|
52 | 52 | |
53 | - $donor = new Give_Donor( $donor_id ); |
|
53 | + $donor = new Give_Donor($donor_id); |
|
54 | 54 | |
55 | 55 | // Bailout, if donor id doesn't exists. |
56 | - if ( empty( $donor->id ) ) { |
|
56 | + if (empty($donor->id)) { |
|
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
@@ -69,30 +69,30 @@ discard block |
||
69 | 69 | 'country' => '', |
70 | 70 | ); |
71 | 71 | |
72 | - $donor_info = wp_parse_args( $donor_info, $defaults ); |
|
72 | + $donor_info = wp_parse_args($donor_info, $defaults); |
|
73 | 73 | |
74 | - if ( (int) $donor_info['user_id'] !== (int) $donor->user_id ) { |
|
74 | + if ((int) $donor_info['user_id'] !== (int) $donor->user_id) { |
|
75 | 75 | |
76 | 76 | // Make sure we don't already have this user attached to a donor. |
77 | - if ( ! empty( $donor_info['user_id'] ) && false !== Give()->donors->get_donor_by( 'user_id', $donor_info['user_id'] ) ) { |
|
77 | + if ( ! empty($donor_info['user_id']) && false !== Give()->donors->get_donor_by('user_id', $donor_info['user_id'])) { |
|
78 | 78 | give_set_error( |
79 | 79 | 'give-invalid-donor-user_id', |
80 | 80 | sprintf( |
81 | 81 | /* translators: %d User ID */ |
82 | - __( 'The User ID #%d is already associated with a different donor.', 'give' ), |
|
82 | + __('The User ID #%d is already associated with a different donor.', 'give'), |
|
83 | 83 | $donor_info['user_id'] |
84 | 84 | ) |
85 | 85 | ); |
86 | 86 | } |
87 | 87 | |
88 | 88 | // Make sure it's actually a user. |
89 | - $user = get_user_by( 'id', $donor_info['user_id'] ); |
|
90 | - if ( ! empty( $donor_info['user_id'] ) && false === $user ) { |
|
89 | + $user = get_user_by('id', $donor_info['user_id']); |
|
90 | + if ( ! empty($donor_info['user_id']) && false === $user) { |
|
91 | 91 | give_set_error( |
92 | 92 | 'give-invalid-user_id', |
93 | 93 | sprintf( |
94 | 94 | /* translators: %d User ID */ |
95 | - __( 'The User ID #%d does not exist. Please assign an existing user.', 'give' ), |
|
95 | + __('The User ID #%d does not exist. Please assign an existing user.', 'give'), |
|
96 | 96 | $donor_info['user_id'] |
97 | 97 | ) |
98 | 98 | ); |
@@ -100,29 +100,29 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | // Bailout, if errors are present. |
103 | - if ( give_get_errors() ) { |
|
103 | + if (give_get_errors()) { |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | |
107 | - $donor->update_meta( '_give_anonymous_donor', absint( $args['give_anonymous_donor'] ) ); |
|
107 | + $donor->update_meta('_give_anonymous_donor', absint($args['give_anonymous_donor'])); |
|
108 | 108 | |
109 | 109 | // Save company name in when admin update donor company name from dashboard. |
110 | - $donor->update_meta( '_give_donor_company', sanitize_text_field( $args['give_donor_company'] ) ); |
|
110 | + $donor->update_meta('_give_donor_company', sanitize_text_field($args['give_donor_company'])); |
|
111 | 111 | |
112 | 112 | // If First name of donor is empty, then fetch the current first name of donor. |
113 | - if ( empty( $donor_info['first_name'] ) ) { |
|
113 | + if (empty($donor_info['first_name'])) { |
|
114 | 114 | $donor_info['first_name'] = $donor->get_first_name(); |
115 | 115 | } |
116 | 116 | |
117 | 117 | // Sanitize the inputs. |
118 | 118 | $donor_data = array(); |
119 | - $donor_data['name'] = trim( "{$donor_info['first_name']} {$donor_info['last_name']}" ); |
|
119 | + $donor_data['name'] = trim("{$donor_info['first_name']} {$donor_info['last_name']}"); |
|
120 | 120 | $donor_data['first_name'] = $donor_info['first_name']; |
121 | 121 | $donor_data['last_name'] = $donor_info['last_name']; |
122 | 122 | $donor_data['title'] = $donor_info['title']; |
123 | 123 | $donor_data['user_id'] = $donor_info['user_id']; |
124 | 124 | |
125 | - $donor_data = apply_filters( 'give_edit_donor_info', $donor_data, $donor_id ); |
|
125 | + $donor_data = apply_filters('give_edit_donor_info', $donor_data, $donor_id); |
|
126 | 126 | |
127 | 127 | /** |
128 | 128 | * Filter the address |
@@ -131,21 +131,21 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @since 1.0 |
133 | 133 | */ |
134 | - $address = apply_filters( 'give_edit_donor_address', array(), $donor_id ); |
|
134 | + $address = apply_filters('give_edit_donor_address', array(), $donor_id); |
|
135 | 135 | |
136 | - $donor_data = give_clean( $donor_data ); |
|
137 | - $address = give_clean( $address ); |
|
136 | + $donor_data = give_clean($donor_data); |
|
137 | + $address = give_clean($address); |
|
138 | 138 | |
139 | - $output = give_connect_user_donor_profile( $donor, $donor_data, $address ); |
|
139 | + $output = give_connect_user_donor_profile($donor, $donor_data, $address); |
|
140 | 140 | |
141 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
142 | - header( 'Content-Type: application/json' ); |
|
143 | - echo wp_json_encode( $output ); |
|
141 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
142 | + header('Content-Type: application/json'); |
|
143 | + echo wp_json_encode($output); |
|
144 | 144 | wp_die(); |
145 | 145 | } |
146 | 146 | |
147 | - if ( $output['success'] ) { |
|
148 | - wp_safe_redirect( add_query_arg( |
|
147 | + if ($output['success']) { |
|
148 | + wp_safe_redirect(add_query_arg( |
|
149 | 149 | array( |
150 | 150 | 'post_type' => 'give_forms', |
151 | 151 | 'page' => 'give-donors', |
@@ -153,15 +153,15 @@ discard block |
||
153 | 153 | 'id' => $donor_id, |
154 | 154 | 'give-messages[]' => 'profile-updated' |
155 | 155 | ), |
156 | - esc_url( admin_url( 'edit.php' ) ) |
|
157 | - ) ); |
|
156 | + esc_url(admin_url('edit.php')) |
|
157 | + )); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | exit; |
161 | 161 | |
162 | 162 | } |
163 | 163 | |
164 | -add_action( 'give_edit-donor', 'give_edit_donor', 10, 1 ); |
|
164 | +add_action('give_edit-donor', 'give_edit_donor', 10, 1); |
|
165 | 165 | |
166 | 166 | /** |
167 | 167 | * Save a donor note. |
@@ -172,40 +172,40 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return int The Note ID that was saved, or 0 if nothing was saved. |
174 | 174 | */ |
175 | -function give_donor_save_note( $args ) { |
|
175 | +function give_donor_save_note($args) { |
|
176 | 176 | |
177 | - $donor_view_role = apply_filters( 'give_view_donors_role', 'view_give_reports' ); |
|
177 | + $donor_view_role = apply_filters('give_view_donors_role', 'view_give_reports'); |
|
178 | 178 | |
179 | - if ( ! is_admin() || ! current_user_can( $donor_view_role ) ) { |
|
180 | - wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array( |
|
179 | + if ( ! is_admin() || ! current_user_can($donor_view_role)) { |
|
180 | + wp_die(__('You do not have permission to edit this donor.', 'give'), __('Error', 'give'), array( |
|
181 | 181 | 'response' => 403, |
182 | - ) ); |
|
182 | + )); |
|
183 | 183 | } |
184 | 184 | |
185 | - if ( empty( $args ) ) { |
|
185 | + if (empty($args)) { |
|
186 | 186 | return false; |
187 | 187 | } |
188 | 188 | |
189 | - $donor_note = trim( give_clean( $args['donor_note'] ) ); |
|
189 | + $donor_note = trim(give_clean($args['donor_note'])); |
|
190 | 190 | $donor_id = (int) $args['customer_id']; |
191 | 191 | $nonce = $args['add_donor_note_nonce']; |
192 | 192 | |
193 | - if ( ! wp_verify_nonce( $nonce, 'add-donor-note' ) ) { |
|
194 | - wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array( |
|
193 | + if ( ! wp_verify_nonce($nonce, 'add-donor-note')) { |
|
194 | + wp_die(__('Cheatin’ uh?', 'give'), __('Error', 'give'), array( |
|
195 | 195 | 'response' => 400, |
196 | - ) ); |
|
196 | + )); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( empty( $donor_note ) ) { |
|
200 | - give_set_error( 'empty-donor-note', __( 'A note is required.', 'give' ) ); |
|
199 | + if (empty($donor_note)) { |
|
200 | + give_set_error('empty-donor-note', __('A note is required.', 'give')); |
|
201 | 201 | } |
202 | 202 | |
203 | - if ( give_get_errors() ) { |
|
203 | + if (give_get_errors()) { |
|
204 | 204 | return false; |
205 | 205 | } |
206 | 206 | |
207 | - $donor = new Give_Donor( $donor_id ); |
|
208 | - $new_note = $donor->add_note( $donor_note ); |
|
207 | + $donor = new Give_Donor($donor_id); |
|
208 | + $new_note = $donor->add_note($donor_note); |
|
209 | 209 | |
210 | 210 | /** |
211 | 211 | * Fires before inserting donor note. |
@@ -215,22 +215,22 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @since 1.0 |
217 | 217 | */ |
218 | - do_action( 'give_pre_insert_donor_note', $donor_id, $new_note ); |
|
218 | + do_action('give_pre_insert_donor_note', $donor_id, $new_note); |
|
219 | 219 | |
220 | - if ( ! empty( $new_note ) && ! empty( $donor->id ) ) { |
|
220 | + if ( ! empty($new_note) && ! empty($donor->id)) { |
|
221 | 221 | |
222 | 222 | ob_start(); |
223 | 223 | ?> |
224 | 224 | <div class="donor-note-wrapper dashboard-comment-wrap comment-item"> |
225 | 225 | <span class="note-content-wrap"> |
226 | - <?php echo stripslashes( $new_note ); ?> |
|
226 | + <?php echo stripslashes($new_note); ?> |
|
227 | 227 | </span> |
228 | 228 | </div> |
229 | 229 | <?php |
230 | 230 | $output = ob_get_contents(); |
231 | 231 | ob_end_clean(); |
232 | 232 | |
233 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
233 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
234 | 234 | echo $output; |
235 | 235 | exit; |
236 | 236 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | } |
245 | 245 | |
246 | -add_action( 'give_add-donor-note', 'give_donor_save_note', 10, 1 ); |
|
246 | +add_action('give_add-donor-note', 'give_donor_save_note', 10, 1); |
|
247 | 247 | |
248 | 248 | |
249 | 249 | /** |
@@ -255,17 +255,17 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @return bool|array If the disconnect was successful. |
257 | 257 | */ |
258 | -function give_disconnect_donor_user_id( $args ) { |
|
258 | +function give_disconnect_donor_user_id($args) { |
|
259 | 259 | |
260 | - $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' ); |
|
260 | + $donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments'); |
|
261 | 261 | |
262 | - if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) { |
|
263 | - wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array( |
|
262 | + if ( ! is_admin() || ! current_user_can($donor_edit_role)) { |
|
263 | + wp_die(__('You do not have permission to edit this donor.', 'give'), __('Error', 'give'), array( |
|
264 | 264 | 'response' => 403, |
265 | - ) ); |
|
265 | + )); |
|
266 | 266 | } |
267 | 267 | |
268 | - if ( empty( $args ) ) { |
|
268 | + if (empty($args)) { |
|
269 | 269 | return false; |
270 | 270 | } |
271 | 271 | |
@@ -273,14 +273,14 @@ discard block |
||
273 | 273 | |
274 | 274 | $nonce = $args['_wpnonce']; |
275 | 275 | |
276 | - if ( ! wp_verify_nonce( $nonce, 'edit-donor' ) ) { |
|
277 | - wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array( |
|
276 | + if ( ! wp_verify_nonce($nonce, 'edit-donor')) { |
|
277 | + wp_die(__('Cheatin’ uh?', 'give'), __('Error', 'give'), array( |
|
278 | 278 | 'response' => 400, |
279 | - ) ); |
|
279 | + )); |
|
280 | 280 | } |
281 | 281 | |
282 | - $donor = new Give_Donor( $donor_id ); |
|
283 | - if ( empty( $donor->id ) ) { |
|
282 | + $donor = new Give_Donor($donor_id); |
|
283 | + if (empty($donor->id)) { |
|
284 | 284 | return false; |
285 | 285 | } |
286 | 286 | |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @since 1.0 |
296 | 296 | */ |
297 | - do_action( 'give_pre_donor_disconnect_user_id', $donor_id, $user_id ); |
|
297 | + do_action('give_pre_donor_disconnect_user_id', $donor_id, $user_id); |
|
298 | 298 | |
299 | 299 | $output = array(); |
300 | 300 | $donor_args = array( |
@@ -303,19 +303,19 @@ discard block |
||
303 | 303 | |
304 | 304 | |
305 | 305 | $output['success'] = true; |
306 | - if ( ! $donor->update( $donor_args ) ) { |
|
307 | - update_user_meta( $user_id, '_give_is_donor_disconnected', true ); |
|
308 | - update_user_meta( $user_id, '_give_disconnected_donor_id', $donor->id ); |
|
309 | - $donor->update_meta( '_give_disconnected_user_id', $user_id ); |
|
306 | + if ( ! $donor->update($donor_args)) { |
|
307 | + update_user_meta($user_id, '_give_is_donor_disconnected', true); |
|
308 | + update_user_meta($user_id, '_give_disconnected_donor_id', $donor->id); |
|
309 | + $donor->update_meta('_give_disconnected_user_id', $user_id); |
|
310 | 310 | |
311 | 311 | $output['success'] = true; |
312 | 312 | |
313 | 313 | } else { |
314 | 314 | $output['success'] = false; |
315 | - give_set_error( 'give-disconnect-user-fail', __( 'Failed to disconnect user from donor.', 'give' ) ); |
|
315 | + give_set_error('give-disconnect-user-fail', __('Failed to disconnect user from donor.', 'give')); |
|
316 | 316 | } |
317 | 317 | |
318 | - $output['redirect'] = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' ) . $donor_id; |
|
318 | + $output['redirect'] = admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id=').$donor_id; |
|
319 | 319 | |
320 | 320 | /** |
321 | 321 | * Fires after disconnecting user ID from a donor. |
@@ -324,11 +324,11 @@ discard block |
||
324 | 324 | * |
325 | 325 | * @since 1.0 |
326 | 326 | */ |
327 | - do_action( 'give_post_donor_disconnect_user_id', $donor_id ); |
|
327 | + do_action('give_post_donor_disconnect_user_id', $donor_id); |
|
328 | 328 | |
329 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
330 | - header( 'Content-Type: application/json' ); |
|
331 | - echo json_encode( $output ); |
|
329 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
330 | + header('Content-Type: application/json'); |
|
331 | + echo json_encode($output); |
|
332 | 332 | wp_die(); |
333 | 333 | } |
334 | 334 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | |
337 | 337 | } |
338 | 338 | |
339 | -add_action( 'give_disconnect-userid', 'give_disconnect_donor_user_id', 10, 1 ); |
|
339 | +add_action('give_disconnect-userid', 'give_disconnect_donor_user_id', 10, 1); |
|
340 | 340 | |
341 | 341 | /** |
342 | 342 | * Add an email address to the donor from within the admin and log a donor note. |
@@ -347,86 +347,86 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @return mixed If DOING_AJAX echos out JSON, otherwise returns array of success (bool) and message (string). |
349 | 349 | */ |
350 | -function give_add_donor_email( $args ) { |
|
350 | +function give_add_donor_email($args) { |
|
351 | 351 | |
352 | 352 | $donor_id = ''; |
353 | - $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' ); |
|
353 | + $donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments'); |
|
354 | 354 | |
355 | - if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) { |
|
356 | - wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array( |
|
355 | + if ( ! is_admin() || ! current_user_can($donor_edit_role)) { |
|
356 | + wp_die(__('You do not have permission to edit this donor.', 'give'), __('Error', 'give'), array( |
|
357 | 357 | 'response' => 403, |
358 | - ) ); |
|
358 | + )); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | $output = array(); |
362 | - if ( empty( $args ) || empty( $args['email'] ) || empty( $args['customer_id'] ) ) { |
|
362 | + if (empty($args) || empty($args['email']) || empty($args['customer_id'])) { |
|
363 | 363 | $output['success'] = false; |
364 | - if ( empty( $args['email'] ) ) { |
|
365 | - $output['message'] = __( 'Email address is required.', 'give' ); |
|
366 | - } elseif ( empty( $args['customer_id'] ) ) { |
|
367 | - $output['message'] = __( 'Donor ID is required.', 'give' ); |
|
364 | + if (empty($args['email'])) { |
|
365 | + $output['message'] = __('Email address is required.', 'give'); |
|
366 | + } elseif (empty($args['customer_id'])) { |
|
367 | + $output['message'] = __('Donor ID is required.', 'give'); |
|
368 | 368 | } else { |
369 | - $output['message'] = __( 'An error has occurred. Please try again.', 'give' ); |
|
369 | + $output['message'] = __('An error has occurred. Please try again.', 'give'); |
|
370 | 370 | } |
371 | - } elseif ( ! wp_verify_nonce( $args['_wpnonce'], 'give_add_donor_email' ) ) { |
|
371 | + } elseif ( ! wp_verify_nonce($args['_wpnonce'], 'give_add_donor_email')) { |
|
372 | 372 | $output = array( |
373 | 373 | 'success' => false, |
374 | - 'message' => __( 'Nonce verification failed.', 'give' ), |
|
374 | + 'message' => __('Nonce verification failed.', 'give'), |
|
375 | 375 | ); |
376 | - } elseif ( ! is_email( $args['email'] ) ) { |
|
376 | + } elseif ( ! is_email($args['email'])) { |
|
377 | 377 | $output = array( |
378 | 378 | 'success' => false, |
379 | - 'message' => __( 'Invalid email.', 'give' ), |
|
379 | + 'message' => __('Invalid email.', 'give'), |
|
380 | 380 | ); |
381 | 381 | } else { |
382 | - $email = sanitize_email( $args['email'] ); |
|
382 | + $email = sanitize_email($args['email']); |
|
383 | 383 | $donor_id = (int) $args['customer_id']; |
384 | 384 | $primary = 'true' === $args['primary'] ? true : false; |
385 | - $donor = new Give_Donor( $donor_id ); |
|
386 | - if ( false === $donor->add_email( $email, $primary ) ) { |
|
387 | - if ( in_array( $email, $donor->emails ) ) { |
|
385 | + $donor = new Give_Donor($donor_id); |
|
386 | + if (false === $donor->add_email($email, $primary)) { |
|
387 | + if (in_array($email, $donor->emails)) { |
|
388 | 388 | $output = array( |
389 | 389 | 'success' => false, |
390 | - 'message' => __( 'Email already associated with this donor.', 'give' ), |
|
390 | + 'message' => __('Email already associated with this donor.', 'give'), |
|
391 | 391 | ); |
392 | 392 | } else { |
393 | 393 | $output = array( |
394 | 394 | 'success' => false, |
395 | - 'message' => __( 'Email address is already associated with another donor.', 'give' ), |
|
395 | + 'message' => __('Email address is already associated with another donor.', 'give'), |
|
396 | 396 | ); |
397 | 397 | } |
398 | 398 | } else { |
399 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor_id . '&give-messages[]=email-added' ); |
|
399 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor_id.'&give-messages[]=email-added'); |
|
400 | 400 | $output = array( |
401 | 401 | 'success' => true, |
402 | - 'message' => __( 'Email successfully added to donor.', 'give' ), |
|
402 | + 'message' => __('Email successfully added to donor.', 'give'), |
|
403 | 403 | 'redirect' => $redirect, |
404 | 404 | ); |
405 | 405 | |
406 | 406 | $user = wp_get_current_user(); |
407 | - $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' ); |
|
408 | - $donor_note = sprintf( __( 'Email address %1$s added by %2$s', 'give' ), $email, $user_login ); |
|
409 | - $donor->add_note( $donor_note ); |
|
407 | + $user_login = ! empty($user->user_login) ? $user->user_login : __('System', 'give'); |
|
408 | + $donor_note = sprintf(__('Email address %1$s added by %2$s', 'give'), $email, $user_login); |
|
409 | + $donor->add_note($donor_note); |
|
410 | 410 | |
411 | - if ( $primary ) { |
|
412 | - $donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $email, $user_login ); |
|
413 | - $donor->add_note( $donor_note ); |
|
411 | + if ($primary) { |
|
412 | + $donor_note = sprintf(__('Email address %1$s set as primary by %2$s', 'give'), $email, $user_login); |
|
413 | + $donor->add_note($donor_note); |
|
414 | 414 | } |
415 | 415 | } |
416 | 416 | } // End if(). |
417 | 417 | |
418 | - do_action( 'give_post_add_donor_email', $donor_id, $args ); |
|
418 | + do_action('give_post_add_donor_email', $donor_id, $args); |
|
419 | 419 | |
420 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
421 | - header( 'Content-Type: application/json' ); |
|
422 | - echo json_encode( $output ); |
|
420 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
421 | + header('Content-Type: application/json'); |
|
422 | + echo json_encode($output); |
|
423 | 423 | wp_die(); |
424 | 424 | } |
425 | 425 | |
426 | 426 | return $output; |
427 | 427 | } |
428 | 428 | |
429 | -add_action( 'give_add_donor_email', 'give_add_donor_email', 10, 1 ); |
|
429 | +add_action('give_add_donor_email', 'give_add_donor_email', 10, 1); |
|
430 | 430 | |
431 | 431 | |
432 | 432 | /** |
@@ -437,39 +437,39 @@ discard block |
||
437 | 437 | * @return bool|null |
438 | 438 | */ |
439 | 439 | function give_remove_donor_email() { |
440 | - if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
440 | + if (empty($_GET['id']) || ! is_numeric($_GET['id'])) { |
|
441 | 441 | return false; |
442 | 442 | } |
443 | - if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) { |
|
443 | + if (empty($_GET['email']) || ! is_email($_GET['email'])) { |
|
444 | 444 | return false; |
445 | 445 | } |
446 | - if ( empty( $_GET['_wpnonce'] ) ) { |
|
446 | + if (empty($_GET['_wpnonce'])) { |
|
447 | 447 | return false; |
448 | 448 | } |
449 | 449 | |
450 | 450 | $nonce = $_GET['_wpnonce']; |
451 | - if ( ! wp_verify_nonce( $nonce, 'give-remove-donor-email' ) ) { |
|
452 | - wp_die( __( 'Nonce verification failed', 'give' ), __( 'Error', 'give' ), array( |
|
451 | + if ( ! wp_verify_nonce($nonce, 'give-remove-donor-email')) { |
|
452 | + wp_die(__('Nonce verification failed', 'give'), __('Error', 'give'), array( |
|
453 | 453 | 'response' => 403, |
454 | - ) ); |
|
454 | + )); |
|
455 | 455 | } |
456 | 456 | |
457 | - $donor = new Give_Donor( $_GET['id'] ); |
|
458 | - if ( $donor->remove_email( $_GET['email'] ) ) { |
|
459 | - $url = add_query_arg( 'give-messages[]', 'email-removed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
457 | + $donor = new Give_Donor($_GET['id']); |
|
458 | + if ($donor->remove_email($_GET['email'])) { |
|
459 | + $url = add_query_arg('give-messages[]', 'email-removed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
460 | 460 | $user = wp_get_current_user(); |
461 | - $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' ); |
|
462 | - $donor_note = sprintf( __( 'Email address %1$s removed by %2$s', 'give' ), $_GET['email'], $user_login ); |
|
463 | - $donor->add_note( $donor_note ); |
|
461 | + $user_login = ! empty($user->user_login) ? $user->user_login : __('System', 'give'); |
|
462 | + $donor_note = sprintf(__('Email address %1$s removed by %2$s', 'give'), $_GET['email'], $user_login); |
|
463 | + $donor->add_note($donor_note); |
|
464 | 464 | } else { |
465 | - $url = add_query_arg( 'give-messages[]', 'email-remove-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
465 | + $url = add_query_arg('give-messages[]', 'email-remove-failed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
466 | 466 | } |
467 | 467 | |
468 | - wp_safe_redirect( $url ); |
|
468 | + wp_safe_redirect($url); |
|
469 | 469 | exit; |
470 | 470 | } |
471 | 471 | |
472 | -add_action( 'give_remove_donor_email', 'give_remove_donor_email', 10 ); |
|
472 | +add_action('give_remove_donor_email', 'give_remove_donor_email', 10); |
|
473 | 473 | |
474 | 474 | |
475 | 475 | /** |
@@ -481,44 +481,44 @@ discard block |
||
481 | 481 | * @return bool|null |
482 | 482 | */ |
483 | 483 | function give_set_donor_primary_email() { |
484 | - if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
484 | + if (empty($_GET['id']) || ! is_numeric($_GET['id'])) { |
|
485 | 485 | return false; |
486 | 486 | } |
487 | 487 | |
488 | - if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) { |
|
488 | + if (empty($_GET['email']) || ! is_email($_GET['email'])) { |
|
489 | 489 | return false; |
490 | 490 | } |
491 | 491 | |
492 | - if ( empty( $_GET['_wpnonce'] ) ) { |
|
492 | + if (empty($_GET['_wpnonce'])) { |
|
493 | 493 | return false; |
494 | 494 | } |
495 | 495 | |
496 | 496 | $nonce = $_GET['_wpnonce']; |
497 | 497 | |
498 | - if ( ! wp_verify_nonce( $nonce, 'give-set-donor-primary-email' ) ) { |
|
499 | - wp_die( __( 'Nonce verification failed', 'give' ), __( 'Error', 'give' ), array( |
|
498 | + if ( ! wp_verify_nonce($nonce, 'give-set-donor-primary-email')) { |
|
499 | + wp_die(__('Nonce verification failed', 'give'), __('Error', 'give'), array( |
|
500 | 500 | 'response' => 403, |
501 | - ) ); |
|
501 | + )); |
|
502 | 502 | } |
503 | 503 | |
504 | - $donor = new Give_Donor( $_GET['id'] ); |
|
504 | + $donor = new Give_Donor($_GET['id']); |
|
505 | 505 | |
506 | - if ( $donor->set_primary_email( $_GET['email'] ) ) { |
|
507 | - $url = add_query_arg( 'give-messages[]', 'primary-email-updated', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
506 | + if ($donor->set_primary_email($_GET['email'])) { |
|
507 | + $url = add_query_arg('give-messages[]', 'primary-email-updated', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
508 | 508 | $user = wp_get_current_user(); |
509 | - $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' ); |
|
510 | - $donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $_GET['email'], $user_login ); |
|
509 | + $user_login = ! empty($user->user_login) ? $user->user_login : __('System', 'give'); |
|
510 | + $donor_note = sprintf(__('Email address %1$s set as primary by %2$s', 'give'), $_GET['email'], $user_login); |
|
511 | 511 | |
512 | - $donor->add_note( $donor_note ); |
|
512 | + $donor->add_note($donor_note); |
|
513 | 513 | } else { |
514 | - $url = add_query_arg( 'give-messages[]', 'primary-email-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
514 | + $url = add_query_arg('give-messages[]', 'primary-email-failed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
515 | 515 | } |
516 | 516 | |
517 | - wp_safe_redirect( $url ); |
|
517 | + wp_safe_redirect($url); |
|
518 | 518 | exit; |
519 | 519 | } |
520 | 520 | |
521 | -add_action( 'give_set_donor_primary_email', 'give_set_donor_primary_email', 10 ); |
|
521 | +add_action('give_set_donor_primary_email', 'give_set_donor_primary_email', 10); |
|
522 | 522 | |
523 | 523 | |
524 | 524 | /** |
@@ -528,15 +528,15 @@ discard block |
||
528 | 528 | * |
529 | 529 | * @since 2.2 |
530 | 530 | */ |
531 | -function give_process_donor_deletion( $args ) { |
|
531 | +function give_process_donor_deletion($args) { |
|
532 | 532 | |
533 | - $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' ); |
|
533 | + $donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments'); |
|
534 | 534 | |
535 | 535 | // Verify user capabilities to proceed for deleting donor. |
536 | - if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) { |
|
536 | + if ( ! is_admin() || ! current_user_can($donor_edit_role)) { |
|
537 | 537 | wp_die( |
538 | - esc_html__( 'You do not have permission to delete donors.', 'give' ), |
|
539 | - esc_html__( 'Error', 'give' ), |
|
538 | + esc_html__('You do not have permission to delete donors.', 'give'), |
|
539 | + esc_html__('Error', 'give'), |
|
540 | 540 | array( |
541 | 541 | 'response' => 403, |
542 | 542 | ) |
@@ -544,32 +544,32 @@ discard block |
||
544 | 544 | } |
545 | 545 | |
546 | 546 | $nonce_action = ''; |
547 | - if ( 'delete_bulk_donor' === $args['give_action'] ) { |
|
547 | + if ('delete_bulk_donor' === $args['give_action']) { |
|
548 | 548 | $nonce_action = 'bulk-donors'; |
549 | - } elseif ( 'delete_donor' === $args['give_action'] ) { |
|
549 | + } elseif ('delete_donor' === $args['give_action']) { |
|
550 | 550 | $nonce_action = 'give-delete-donor'; |
551 | 551 | } |
552 | 552 | |
553 | 553 | // Verify Nonce for deleting bulk donors. |
554 | - give_validate_nonce( $args['_wpnonce'], $nonce_action ); |
|
554 | + give_validate_nonce($args['_wpnonce'], $nonce_action); |
|
555 | 555 | |
556 | 556 | $redirect_args = array(); |
557 | - $donor_ids = ( isset( $args['donor'] ) && is_array( $args['donor'] ) ) ? $args['donor'] : array( $args['donor_id'] ); |
|
558 | - $redirect_args['order'] = ! empty( $args['order'] ) ? $args['order'] : 'DESC'; |
|
559 | - $redirect_args['orderby'] = ! empty( $args['orderby'] ) ? $args['orderby'] : 'ID'; |
|
560 | - $redirect_args['s'] = ! empty( $args['s'] ) ? $args['s'] : ''; |
|
561 | - $delete_donor = ! empty( $args['give-donor-delete-confirm'] ) ? give_is_setting_enabled( $args['give-donor-delete-confirm'] ) : false; |
|
562 | - $delete_donation = ! empty( $args['give-donor-delete-records'] ) ? give_is_setting_enabled( $args['give-donor-delete-records'] ) : false; |
|
557 | + $donor_ids = (isset($args['donor']) && is_array($args['donor'])) ? $args['donor'] : array($args['donor_id']); |
|
558 | + $redirect_args['order'] = ! empty($args['order']) ? $args['order'] : 'DESC'; |
|
559 | + $redirect_args['orderby'] = ! empty($args['orderby']) ? $args['orderby'] : 'ID'; |
|
560 | + $redirect_args['s'] = ! empty($args['s']) ? $args['s'] : ''; |
|
561 | + $delete_donor = ! empty($args['give-donor-delete-confirm']) ? give_is_setting_enabled($args['give-donor-delete-confirm']) : false; |
|
562 | + $delete_donation = ! empty($args['give-donor-delete-records']) ? give_is_setting_enabled($args['give-donor-delete-records']) : false; |
|
563 | 563 | |
564 | - if ( count( $donor_ids ) > 0 ) { |
|
564 | + if (count($donor_ids) > 0) { |
|
565 | 565 | |
566 | 566 | // Loop through the selected donors to delete. |
567 | - foreach ( $donor_ids as $donor_id ) { |
|
567 | + foreach ($donor_ids as $donor_id) { |
|
568 | 568 | |
569 | - $donor = new Give_Donor( $donor_id ); |
|
569 | + $donor = new Give_Donor($donor_id); |
|
570 | 570 | |
571 | 571 | // Proceed only if valid donor id is provided. |
572 | - if ( $donor->id > 0 ) { |
|
572 | + if ($donor->id > 0) { |
|
573 | 573 | |
574 | 574 | /** |
575 | 575 | * Fires before deleting donor. |
@@ -580,19 +580,19 @@ discard block |
||
580 | 580 | * |
581 | 581 | * @since 1.0 |
582 | 582 | */ |
583 | - do_action( 'give_pre_delete_donor', $donor->id, $delete_donor, $delete_donation ); |
|
583 | + do_action('give_pre_delete_donor', $donor->id, $delete_donor, $delete_donation); |
|
584 | 584 | |
585 | 585 | // Proceed only, if user confirmed whether they need to delete the donor. |
586 | - if ( $delete_donor ) { |
|
586 | + if ($delete_donor) { |
|
587 | 587 | |
588 | 588 | // Delete donor and linked donations. |
589 | - $donor_delete_status = give_delete_donor_and_related_donation( $donor, array( |
|
589 | + $donor_delete_status = give_delete_donor_and_related_donation($donor, array( |
|
590 | 590 | 'delete_donation' => $delete_donation, |
591 | - ) ); |
|
591 | + )); |
|
592 | 592 | |
593 | - if ( 1 === $donor_delete_status ) { |
|
593 | + if (1 === $donor_delete_status) { |
|
594 | 594 | $redirect_args['give-messages[]'] = 'donor-deleted'; |
595 | - } elseif ( 2 === $donor_delete_status ) { |
|
595 | + } elseif (2 === $donor_delete_status) { |
|
596 | 596 | $redirect_args['give-messages[]'] = 'donor-donations-deleted'; |
597 | 597 | } |
598 | 598 | } else { |
@@ -608,12 +608,12 @@ discard block |
||
608 | 608 | |
609 | 609 | $redirect_url = add_query_arg( |
610 | 610 | $redirect_args, |
611 | - admin_url( 'edit.php?post_type=give_forms&page=give-donors' ) |
|
611 | + admin_url('edit.php?post_type=give_forms&page=give-donors') |
|
612 | 612 | ); |
613 | 613 | |
614 | - wp_safe_redirect( $redirect_url ); |
|
614 | + wp_safe_redirect($redirect_url); |
|
615 | 615 | give_die(); |
616 | 616 | |
617 | 617 | } |
618 | -add_action( 'give_delete_donor', 'give_process_donor_deletion' ); |
|
619 | -add_action( 'give_delete_bulk_donor', 'give_process_donor_deletion' ); |
|
618 | +add_action('give_delete_donor', 'give_process_donor_deletion'); |
|
619 | +add_action('give_delete_bulk_donor', 'give_process_donor_deletion'); |
@@ -162,7 +162,7 @@ |
||
162 | 162 | /** |
163 | 163 | * This function is used to delete donor and related donation without redirection. |
164 | 164 | * |
165 | - * @param int|Give_Donor $donor Donor ID or List of Donor IDs. |
|
165 | + * @param Give_Donor $donor Donor ID or List of Donor IDs. |
|
166 | 166 | * @param array $args List of arguments to handle donor and related donation deletion process. |
167 | 167 | * |
168 | 168 | * @type bool delete_donation Delete donor linked donations if set to true. Default is false. |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return array The altered list of views. |
25 | 25 | */ |
26 | -function give_register_default_donor_views( $views ) { |
|
26 | +function give_register_default_donor_views($views) { |
|
27 | 27 | |
28 | 28 | $default_views = array( |
29 | 29 | 'overview' => 'give_donor_view', |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | 'notes' => 'give_donor_notes_view', |
32 | 32 | ); |
33 | 33 | |
34 | - return array_merge( $views, $default_views ); |
|
34 | + return array_merge($views, $default_views); |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
38 | -add_filter( 'give_donor_views', 'give_register_default_donor_views', 1, 1 ); |
|
38 | +add_filter('give_donor_views', 'give_register_default_donor_views', 1, 1); |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Register a tab for the single donor view. |
@@ -46,23 +46,23 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return array The altered list of tabs |
48 | 48 | */ |
49 | -function give_register_default_donor_tabs( $tabs ) { |
|
49 | +function give_register_default_donor_tabs($tabs) { |
|
50 | 50 | |
51 | 51 | $default_tabs = array( |
52 | 52 | 'overview' => array( |
53 | 53 | 'dashicon' => 'dashicons-admin-users', |
54 | - 'title' => __( 'Donor Profile', 'give' ), |
|
54 | + 'title' => __('Donor Profile', 'give'), |
|
55 | 55 | ), |
56 | 56 | 'notes' => array( |
57 | 57 | 'dashicon' => 'dashicons-admin-comments', |
58 | - 'title' => __( 'Donor Notes', 'give' ), |
|
58 | + 'title' => __('Donor Notes', 'give'), |
|
59 | 59 | ), |
60 | 60 | ); |
61 | 61 | |
62 | - return array_merge( $tabs, $default_tabs ); |
|
62 | + return array_merge($tabs, $default_tabs); |
|
63 | 63 | } |
64 | 64 | |
65 | -add_filter( 'give_donor_tabs', 'give_register_default_donor_tabs', 1, 1 ); |
|
65 | +add_filter('give_donor_tabs', 'give_register_default_donor_tabs', 1, 1); |
|
66 | 66 | |
67 | 67 | /** |
68 | 68 | * Register the Delete icon as late as possible so it's at the bottom. |
@@ -73,17 +73,17 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return array The altered list of tabs, with 'delete' at the bottom. |
75 | 75 | */ |
76 | -function give_register_delete_donor_tab( $tabs ) { |
|
76 | +function give_register_delete_donor_tab($tabs) { |
|
77 | 77 | |
78 | 78 | $tabs['delete'] = array( |
79 | 79 | 'dashicon' => 'dashicons-trash', |
80 | - 'title' => __( 'Delete Donor', 'give' ), |
|
80 | + 'title' => __('Delete Donor', 'give'), |
|
81 | 81 | ); |
82 | 82 | |
83 | 83 | return $tabs; |
84 | 84 | } |
85 | 85 | |
86 | -add_filter( 'give_donor_tabs', 'give_register_delete_donor_tab', PHP_INT_MAX, 1 ); |
|
86 | +add_filter('give_donor_tabs', 'give_register_delete_donor_tab', PHP_INT_MAX, 1); |
|
87 | 87 | |
88 | 88 | /** |
89 | 89 | * Connect and Reconnect Donor with User profile. |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @return array |
100 | 100 | */ |
101 | -function give_connect_user_donor_profile( $donor, $donor_data, $address ) { |
|
101 | +function give_connect_user_donor_profile($donor, $donor_data, $address) { |
|
102 | 102 | |
103 | 103 | $donor_id = $donor->id; |
104 | 104 | $previous_user_id = $donor->user_id; |
@@ -112,32 +112,32 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @since 1.0 |
114 | 114 | */ |
115 | - do_action( 'give_pre_edit_donor', $donor_id, $donor_data, $address ); |
|
115 | + do_action('give_pre_edit_donor', $donor_id, $donor_data, $address); |
|
116 | 116 | |
117 | 117 | $output = array(); |
118 | 118 | |
119 | - if ( $donor->update( $donor_data ) ) { |
|
119 | + if ($donor->update($donor_data)) { |
|
120 | 120 | |
121 | 121 | // Create and Update Donor First Name and Last Name in Meta Fields. |
122 | - $donor->update_meta( '_give_donor_first_name', $donor_data['first_name'] ); |
|
123 | - $donor->update_meta( '_give_donor_last_name', $donor_data['last_name'] ); |
|
124 | - $donor->update_meta( '_give_donor_title_prefix', $donor_data['title'] ); |
|
122 | + $donor->update_meta('_give_donor_first_name', $donor_data['first_name']); |
|
123 | + $donor->update_meta('_give_donor_last_name', $donor_data['last_name']); |
|
124 | + $donor->update_meta('_give_donor_title_prefix', $donor_data['title']); |
|
125 | 125 | |
126 | 126 | // Fetch disconnected user id, if exists. |
127 | - $disconnected_user_id = $donor->get_meta( '_give_disconnected_user_id', true ); |
|
127 | + $disconnected_user_id = $donor->get_meta('_give_disconnected_user_id', true); |
|
128 | 128 | |
129 | 129 | // Flag User and Donor Disconnection. |
130 | - delete_user_meta( $disconnected_user_id, '_give_is_donor_disconnected' ); |
|
130 | + delete_user_meta($disconnected_user_id, '_give_is_donor_disconnected'); |
|
131 | 131 | |
132 | 132 | // Check whether the disconnected user id and the reconnected user id are same or not. |
133 | 133 | // If both are same then delete user id store in donor meta. |
134 | - if ( $donor_data['user_id'] === $disconnected_user_id ) { |
|
135 | - delete_user_meta( $disconnected_user_id, '_give_disconnected_donor_id' ); |
|
136 | - $donor->delete_meta( '_give_disconnected_user_id' ); |
|
134 | + if ($donor_data['user_id'] === $disconnected_user_id) { |
|
135 | + delete_user_meta($disconnected_user_id, '_give_disconnected_donor_id'); |
|
136 | + $donor->delete_meta('_give_disconnected_user_id'); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | $output['success'] = true; |
140 | - $donor_data = array_merge( $donor_data, $address ); |
|
140 | + $donor_data = array_merge($donor_data, $address); |
|
141 | 141 | $output['customer_info'] = $donor_data; |
142 | 142 | |
143 | 143 | } else { |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @since 1.0 |
156 | 156 | */ |
157 | - do_action( 'give_post_edit_donor', $donor_id, $donor_data ); |
|
157 | + do_action('give_post_edit_donor', $donor_id, $donor_data); |
|
158 | 158 | |
159 | 159 | return $output; |
160 | 160 | } |
@@ -171,39 +171,39 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @return int |
173 | 173 | */ |
174 | -function give_delete_donor_and_related_donation( $donor, $args = array() ) { |
|
174 | +function give_delete_donor_and_related_donation($donor, $args = array()) { |
|
175 | 175 | |
176 | 176 | // Default Arguments. |
177 | 177 | $default_args = array( |
178 | 178 | 'delete_donation' => false, |
179 | 179 | ); |
180 | 180 | |
181 | - $args = wp_parse_args( $args, $default_args ); |
|
181 | + $args = wp_parse_args($args, $default_args); |
|
182 | 182 | |
183 | 183 | // If $donor not an instance of Give_Donor then create one. |
184 | - if ( ! $donor instanceof Give_Donor ) { |
|
185 | - $donor = new Give_Donor( $donor ); |
|
184 | + if ( ! $donor instanceof Give_Donor) { |
|
185 | + $donor = new Give_Donor($donor); |
|
186 | 186 | } |
187 | 187 | |
188 | - if ( $donor->id > 0 ) { |
|
188 | + if ($donor->id > 0) { |
|
189 | 189 | |
190 | 190 | // Delete Donor. |
191 | - $donor_deleted = Give()->donors->delete( $donor->id ); |
|
191 | + $donor_deleted = Give()->donors->delete($donor->id); |
|
192 | 192 | |
193 | 193 | // Fetch linked donations of a particular donor. |
194 | - $donation_ids = explode( ',', $donor->payment_ids ); |
|
194 | + $donation_ids = explode(',', $donor->payment_ids); |
|
195 | 195 | |
196 | 196 | // Proceed to delete related donation, if user opted and donor is deleted successfully. |
197 | - if ( $donor_deleted && $args['delete_donation'] ) { |
|
198 | - foreach ( $donation_ids as $donation_id ) { |
|
199 | - give_delete_donation( $donation_id ); |
|
197 | + if ($donor_deleted && $args['delete_donation']) { |
|
198 | + foreach ($donation_ids as $donation_id) { |
|
199 | + give_delete_donation($donation_id); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return 2; // Donor and linked Donations deleted. |
203 | 203 | |
204 | 204 | } else { |
205 | - foreach ( $donation_ids as $donation_id ) { |
|
206 | - give_update_payment_meta( $donation_id, '_give_payment_donor_id', 0 ); |
|
205 | + foreach ($donation_ids as $donation_id) { |
|
206 | + give_update_payment_meta($donation_id, '_give_payment_donor_id', 0); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 |
@@ -290,7 +290,7 @@ |
||
290 | 290 | * |
291 | 291 | * @since 1.8.12 |
292 | 292 | * |
293 | - * @return int |
|
293 | + * @return double |
|
294 | 294 | */ |
295 | 295 | public function get_percentage_complete() { |
296 | 296 | return ceil( ( 100 * $this->step_completed ) / $this->total_step ); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // Exit if accessed directly. |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param int $_step Steps. |
136 | 136 | */ |
137 | - public function __construct( $_step = 1 ) { |
|
138 | - parent::__construct( $_step ); |
|
137 | + public function __construct($_step = 1) { |
|
138 | + parent::__construct($_step); |
|
139 | 139 | |
140 | 140 | $this->is_writable = true; |
141 | 141 | } |
@@ -154,38 +154,38 @@ discard block |
||
154 | 154 | $donor_ids = array(); |
155 | 155 | |
156 | 156 | // Check if the ajax request if running for the first time. |
157 | - if ( 1 === (int) $this->step ) { |
|
157 | + if (1 === (int) $this->step) { |
|
158 | 158 | |
159 | 159 | // Delete all the form ids. |
160 | - $this->delete_option( $this->form_key ); |
|
160 | + $this->delete_option($this->form_key); |
|
161 | 161 | |
162 | 162 | // Delete all the donation ids. |
163 | - $this->delete_option( $this->donation_key ); |
|
163 | + $this->delete_option($this->donation_key); |
|
164 | 164 | |
165 | 165 | // Delete all the donor ids. |
166 | - $this->delete_option( $this->donor_key ); |
|
166 | + $this->delete_option($this->donor_key); |
|
167 | 167 | |
168 | 168 | // Delete all the step and set to 'count' which if the first step in the process of deleting the donors. |
169 | - $this->update_option( $this->step_key, 'count' ); |
|
169 | + $this->update_option($this->step_key, 'count'); |
|
170 | 170 | |
171 | 171 | // Delete tha page count of the step. |
172 | - $this->update_option( $this->step_on_key, '0' ); |
|
172 | + $this->update_option($this->step_on_key, '0'); |
|
173 | 173 | } else { |
174 | 174 | |
175 | 175 | // Get the old donors list. |
176 | - $donor_ids = $this->get_option( $this->donor_key ); |
|
176 | + $donor_ids = $this->get_option($this->donor_key); |
|
177 | 177 | |
178 | 178 | // Get the old donation list. |
179 | - $donation_ids = $this->get_option( $this->donation_key ); |
|
179 | + $donation_ids = $this->get_option($this->donation_key); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Get the step and check for it if it's on the first step( 'count' ) or not. |
183 | 183 | $step = (int) $this->get_step(); |
184 | - if ( 1 === $step ) { |
|
184 | + if (1 === $step) { |
|
185 | 185 | /** |
186 | 186 | * Will add or update the donation and donor data by running wp query. |
187 | 187 | */ |
188 | - $this->count( $step, $donation_ids, $donor_ids ); |
|
188 | + $this->count($step, $donation_ids, $donor_ids); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
@@ -196,18 +196,18 @@ discard block |
||
196 | 196 | * @param array $donation_ids Contain the list of all the donation id's that has being add before this. |
197 | 197 | * @param array $donor_ids Contain the list of all the donors id's that has being add before this. |
198 | 198 | */ |
199 | - private function count( $step, $donation_ids = array(), $donor_ids = array() ) { |
|
199 | + private function count($step, $donation_ids = array(), $donor_ids = array()) { |
|
200 | 200 | |
201 | 201 | // Get the Page count by default it's zero. |
202 | 202 | $paged = (int) $this->get_step_page(); |
203 | 203 | |
204 | 204 | // Increased the page count by one. |
205 | - ++ $paged; |
|
205 | + ++$paged; |
|
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Filter add to alter the argument before the wp quest run |
209 | 209 | */ |
210 | - $args = apply_filters( 'give_tools_reset_stats_total_args', array( |
|
210 | + $args = apply_filters('give_tools_reset_stats_total_args', array( |
|
211 | 211 | 'post_type' => 'give_payment', |
212 | 212 | 'post_status' => 'any', |
213 | 213 | 'posts_per_page' => $this->per_step, |
@@ -215,41 +215,41 @@ discard block |
||
215 | 215 | 'meta_key' => '_give_payment_import', |
216 | 216 | 'meta_value_num' => 1, |
217 | 217 | 'meta_compare' => '=', |
218 | - ) ); |
|
218 | + )); |
|
219 | 219 | |
220 | 220 | // Reset the post data. |
221 | 221 | wp_reset_postdata(); |
222 | 222 | |
223 | 223 | // Getting the new donation. |
224 | - $donation_posts = new WP_Query( $args ); |
|
224 | + $donation_posts = new WP_Query($args); |
|
225 | 225 | |
226 | 226 | // The Loop. |
227 | - if ( $donation_posts->have_posts() ) { |
|
228 | - while ( $donation_posts->have_posts() ) { |
|
227 | + if ($donation_posts->have_posts()) { |
|
228 | + while ($donation_posts->have_posts()) { |
|
229 | 229 | $add_author = true; |
230 | 230 | $donation_posts->the_post(); |
231 | 231 | global $post; |
232 | 232 | // Add the donation id in side the array. |
233 | 233 | $donation_ids[] = $post->ID; |
234 | 234 | |
235 | - $donor_id = (int) give_get_meta( $post->ID, '_give_payment_customer_id', true ); |
|
236 | - if ( ! empty( $donor_id ) ) { |
|
237 | - $donor = new Give_Donor( $donor_id ); |
|
238 | - if ( ! empty( $donor->id ) ) { |
|
239 | - if ( empty( $donor->user_id ) && ! empty( $donor->payment_ids ) ) { |
|
235 | + $donor_id = (int) give_get_meta($post->ID, '_give_payment_customer_id', true); |
|
236 | + if ( ! empty($donor_id)) { |
|
237 | + $donor = new Give_Donor($donor_id); |
|
238 | + if ( ! empty($donor->id)) { |
|
239 | + if (empty($donor->user_id) && ! empty($donor->payment_ids)) { |
|
240 | 240 | $add_author = false; |
241 | - $count = (int) count( $donor->payment_ids ); |
|
242 | - if ( 1 === $count ) { |
|
243 | - give_delete_donor_and_related_donation( $donor ); |
|
241 | + $count = (int) count($donor->payment_ids); |
|
242 | + if (1 === $count) { |
|
243 | + give_delete_donor_and_related_donation($donor); |
|
244 | 244 | } else { |
245 | - $donor->remove_payment( $post->ID ); |
|
245 | + $donor->remove_payment($post->ID); |
|
246 | 246 | $donor->decrease_donation_count(); |
247 | 247 | } |
248 | 248 | } |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | - if ( ! empty( $add_author ) ) { |
|
252 | + if ( ! empty($add_author)) { |
|
253 | 253 | // Add the donor id in side the array. |
254 | 254 | $donor_ids[] = (int) $post->post_author; |
255 | 255 | } |
@@ -263,24 +263,24 @@ discard block |
||
263 | 263 | $max_num_pages = (int) $donation_posts->max_num_pages; |
264 | 264 | |
265 | 265 | // Check current page is less then max number of page or not. |
266 | - if ( $paged < $max_num_pages ) { |
|
266 | + if ($paged < $max_num_pages) { |
|
267 | 267 | |
268 | 268 | // Update the current page variable for the next step. |
269 | - $this->update_option( $this->step_on_key, $paged ); |
|
269 | + $this->update_option($this->step_on_key, $paged); |
|
270 | 270 | |
271 | 271 | // Calculating percentage. |
272 | 272 | $page_remain = $max_num_pages - $paged; |
273 | - $this->total_step = (int) $max_num_pages + ( $total_donation / $this->per_step ) + ( ( $page_remain * 2 ) * count( $donor_ids ) ); |
|
273 | + $this->total_step = (int) $max_num_pages + ($total_donation / $this->per_step) + (($page_remain * 2) * count($donor_ids)); |
|
274 | 274 | $this->step_completed = $paged; |
275 | 275 | } else { |
276 | - $donation_ids_count = count( $donor_ids ); |
|
277 | - $this->update_option( $this->step_key, 'donation' ); |
|
278 | - $this->update_option( $this->step_on_key, '0' ); |
|
276 | + $donation_ids_count = count($donor_ids); |
|
277 | + $this->update_option($this->step_key, 'donation'); |
|
278 | + $this->update_option($this->step_on_key, '0'); |
|
279 | 279 | } |
280 | 280 | |
281 | - $donor_ids = array_unique( $donor_ids ); |
|
282 | - $this->update_option( $this->donor_key, $donor_ids ); |
|
283 | - $this->update_option( $this->donation_key, $donation_ids ); |
|
281 | + $donor_ids = array_unique($donor_ids); |
|
282 | + $this->update_option($this->donor_key, $donor_ids); |
|
283 | + $this->update_option($this->donation_key, $donation_ids); |
|
284 | 284 | |
285 | 285 | wp_reset_postdata(); |
286 | 286 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * @return int |
294 | 294 | */ |
295 | 295 | public function get_percentage_complete() { |
296 | - return ceil( ( 100 * $this->step_completed ) / $this->total_step ); |
|
296 | + return ceil((100 * $this->step_completed) / $this->total_step); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public function process_step() { |
305 | 305 | |
306 | - if ( ! $this->can_export() ) { |
|
306 | + if ( ! $this->can_export()) { |
|
307 | 307 | wp_die( |
308 | - esc_html__( 'You do not have permission to delete Import transactions.', 'give' ), |
|
309 | - esc_html__( 'Error', 'give' ), |
|
308 | + esc_html__('You do not have permission to delete Import transactions.', 'give'), |
|
309 | + esc_html__('Error', 'give'), |
|
310 | 310 | array( |
311 | 311 | 'response' => 403, |
312 | 312 | ) |
@@ -315,18 +315,18 @@ discard block |
||
315 | 315 | |
316 | 316 | $had_data = $this->get_data(); |
317 | 317 | |
318 | - if ( $had_data ) { |
|
318 | + if ($had_data) { |
|
319 | 319 | $this->done = false; |
320 | 320 | |
321 | 321 | return true; |
322 | 322 | } else { |
323 | - update_option( 'give_earnings_total', give_get_total_earnings( true ), false ); |
|
324 | - Give_Cache::delete( Give_Cache::get_key( 'give_estimated_monthly_stats' ) ); |
|
323 | + update_option('give_earnings_total', give_get_total_earnings(true), false); |
|
324 | + Give_Cache::delete(Give_Cache::get_key('give_estimated_monthly_stats')); |
|
325 | 325 | |
326 | - $this->delete_option( $this->donation_key ); |
|
326 | + $this->delete_option($this->donation_key); |
|
327 | 327 | |
328 | 328 | $this->done = true; |
329 | - $this->message = __( 'Imported donor and transactions successfully deleted.', 'give' ); |
|
329 | + $this->message = __('Imported donor and transactions successfully deleted.', 'give'); |
|
330 | 330 | |
331 | 331 | return false; |
332 | 332 | } |
@@ -344,12 +344,12 @@ discard block |
||
344 | 344 | public function get_data() { |
345 | 345 | |
346 | 346 | // Get the donation id's. |
347 | - $donation_ids = $this->get_option( $this->donation_key ); |
|
347 | + $donation_ids = $this->get_option($this->donation_key); |
|
348 | 348 | |
349 | 349 | /** |
350 | 350 | * Return false id not Import donation is found. |
351 | 351 | */ |
352 | - if ( empty( $donation_ids ) ) { |
|
352 | + if (empty($donation_ids)) { |
|
353 | 353 | $this->is_empty = true; |
354 | 354 | $this->total_step = 1; |
355 | 355 | |
@@ -360,110 +360,110 @@ discard block |
||
360 | 360 | $step = (int) $this->get_step(); |
361 | 361 | |
362 | 362 | // Get the donor ids. |
363 | - $donor_ids = $this->get_option( $this->donor_key ); |
|
363 | + $donor_ids = $this->get_option($this->donor_key); |
|
364 | 364 | |
365 | 365 | // Delete all the imported donations. |
366 | - if ( 2 === $step ) { |
|
366 | + if (2 === $step) { |
|
367 | 367 | $pass_to_donor = false; |
368 | 368 | $page = (int) $this->get_step_page(); |
369 | - $page ++; |
|
370 | - $count = count( $donation_ids ); |
|
369 | + $page++; |
|
370 | + $count = count($donation_ids); |
|
371 | 371 | |
372 | - $this->total_step = ( ( count( $donation_ids ) / $this->per_step ) * 2 ) + count( $donor_ids ); |
|
372 | + $this->total_step = ((count($donation_ids) / $this->per_step) * 2) + count($donor_ids); |
|
373 | 373 | $this->step_completed = $page; |
374 | 374 | |
375 | - if ( $count > $this->per_step ) { |
|
375 | + if ($count > $this->per_step) { |
|
376 | 376 | |
377 | - $this->update_option( $this->step_on_key, $page ); |
|
378 | - $donation_ids = $this->get_delete_ids( $donation_ids, $page ); |
|
379 | - $current_page = (int) ceil( $count / $this->per_step ); |
|
377 | + $this->update_option($this->step_on_key, $page); |
|
378 | + $donation_ids = $this->get_delete_ids($donation_ids, $page); |
|
379 | + $current_page = (int) ceil($count / $this->per_step); |
|
380 | 380 | |
381 | - if ( $page === $current_page ) { |
|
381 | + if ($page === $current_page) { |
|
382 | 382 | $pass_to_donor = true; |
383 | 383 | } |
384 | 384 | } else { |
385 | 385 | $pass_to_donor = true; |
386 | 386 | } |
387 | 387 | |
388 | - if ( true === $pass_to_donor ) { |
|
389 | - $this->update_option( $this->step_key, 'donor' ); |
|
390 | - $this->update_option( $this->step_on_key, '0' ); |
|
388 | + if (true === $pass_to_donor) { |
|
389 | + $this->update_option($this->step_key, 'donor'); |
|
390 | + $this->update_option($this->step_on_key, '0'); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | // Get the old form list. |
394 | - $form_ids = (array) $this->get_option( $this->form_key ); |
|
394 | + $form_ids = (array) $this->get_option($this->form_key); |
|
395 | 395 | |
396 | - foreach ( $donation_ids as $item ) { |
|
397 | - $form_ids[] = give_get_meta( $item, '_give_payment_form_id', true ); |
|
396 | + foreach ($donation_ids as $item) { |
|
397 | + $form_ids[] = give_get_meta($item, '_give_payment_form_id', true); |
|
398 | 398 | |
399 | 399 | // Delete the main payment. |
400 | - give_delete_donation( absint( $item ) ); |
|
400 | + give_delete_donation(absint($item)); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | // Update the new form list. |
404 | - $this->update_option( $this->form_key, $form_ids ); |
|
404 | + $this->update_option($this->form_key, $form_ids); |
|
405 | 405 | } // End if(). |
406 | 406 | |
407 | 407 | // Delete all the donors. |
408 | - if ( 3 === $step ) { |
|
408 | + if (3 === $step) { |
|
409 | 409 | |
410 | 410 | // Get the old form list. |
411 | - $form_ids = (array) $this->get_option( $this->form_key ); |
|
412 | - if ( ! empty( $form_ids ) ) { |
|
413 | - $form_ids = array_unique( $form_ids ); |
|
414 | - foreach ( $form_ids as $form_id ) { |
|
415 | - give_recount_form_income_donation( (int) $form_id ); |
|
411 | + $form_ids = (array) $this->get_option($this->form_key); |
|
412 | + if ( ! empty($form_ids)) { |
|
413 | + $form_ids = array_unique($form_ids); |
|
414 | + foreach ($form_ids as $form_id) { |
|
415 | + give_recount_form_income_donation((int) $form_id); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | // update the new form list. |
419 | - $this->update_option( $this->form_key, array() ); |
|
419 | + $this->update_option($this->form_key, array()); |
|
420 | 420 | |
421 | 421 | $page = (int) $this->get_step_page(); |
422 | - $count = count( $donor_ids ); |
|
422 | + $count = count($donor_ids); |
|
423 | 423 | |
424 | - $this->total_step = ( ( count( $donation_ids ) / $this->per_step ) * 2 ) + count( $donor_ids ); |
|
425 | - $this->step_completed = $page + ( count( $donation_ids ) / $this->per_step ); |
|
424 | + $this->total_step = ((count($donation_ids) / $this->per_step) * 2) + count($donor_ids); |
|
425 | + $this->step_completed = $page + (count($donation_ids) / $this->per_step); |
|
426 | 426 | |
427 | - if ( ! empty( $donor_ids[ $page ] ) ) { |
|
428 | - $args = apply_filters( 'give_tools_reset_stats_total_args', array( |
|
427 | + if ( ! empty($donor_ids[$page])) { |
|
428 | + $args = apply_filters('give_tools_reset_stats_total_args', array( |
|
429 | 429 | 'post_status' => 'any', |
430 | 430 | 'posts_per_page' => 1, |
431 | - 'author' => $donor_ids[ $page ], |
|
432 | - ) ); |
|
431 | + 'author' => $donor_ids[$page], |
|
432 | + )); |
|
433 | 433 | |
434 | 434 | $donations = array(); |
435 | - $payments = new Give_Payments_Query( $args ); |
|
435 | + $payments = new Give_Payments_Query($args); |
|
436 | 436 | $payments = $payments->get_payments(); |
437 | - if ( empty( $payments ) ) { |
|
438 | - Give()->donors->delete_by_user_id( $donor_ids[ $page ] ); |
|
437 | + if (empty($payments)) { |
|
438 | + Give()->donors->delete_by_user_id($donor_ids[$page]); |
|
439 | 439 | |
440 | 440 | /** |
441 | 441 | * If Checked then delete WP user. |
442 | 442 | * |
443 | 443 | * @since 1.8.14 |
444 | 444 | */ |
445 | - $delete_import_donors = isset( $_REQUEST['delete-import-donors'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['delete-import-donors'] ) ) : ''; |
|
445 | + $delete_import_donors = isset($_REQUEST['delete-import-donors']) ? sanitize_text_field(wp_unslash($_REQUEST['delete-import-donors'])) : ''; |
|
446 | 446 | |
447 | - if ( 'on' === (string) $delete_import_donors ) { |
|
448 | - wp_delete_user( $donor_ids[ $page ] ); |
|
447 | + if ('on' === (string) $delete_import_donors) { |
|
448 | + wp_delete_user($donor_ids[$page]); |
|
449 | 449 | } |
450 | 450 | } else { |
451 | - foreach ( $payments as $payment ) { |
|
451 | + foreach ($payments as $payment) { |
|
452 | 452 | $donations[] = $payment->ID; |
453 | 453 | } |
454 | 454 | |
455 | - $donor = new Give_Donor( $donor_ids[ $page ], true ); |
|
455 | + $donor = new Give_Donor($donor_ids[$page], true); |
|
456 | 456 | $data_to_update = array( |
457 | - 'purchase_count' => count( $donations ), |
|
458 | - 'payment_ids' => implode( ',', $donations ), |
|
457 | + 'purchase_count' => count($donations), |
|
458 | + 'payment_ids' => implode(',', $donations), |
|
459 | 459 | ); |
460 | - $donor->update( $data_to_update ); |
|
460 | + $donor->update($data_to_update); |
|
461 | 461 | } |
462 | 462 | } // End if(). |
463 | 463 | |
464 | - $page ++; |
|
465 | - $this->update_option( $this->step_on_key, $page ); |
|
466 | - if ( $count === $page ) { |
|
464 | + $page++; |
|
465 | + $this->update_option($this->step_on_key, $page); |
|
466 | + if ($count === $page) { |
|
467 | 467 | $this->is_empty = false; |
468 | 468 | |
469 | 469 | return false; |
@@ -483,24 +483,24 @@ discard block |
||
483 | 483 | * |
484 | 484 | * @return mixed |
485 | 485 | */ |
486 | - public function get_delete_ids( $donation_ids, $page ) { |
|
487 | - $index = $page --; |
|
488 | - $count = count( $donation_ids ); |
|
486 | + public function get_delete_ids($donation_ids, $page) { |
|
487 | + $index = $page--; |
|
488 | + $count = count($donation_ids); |
|
489 | 489 | $temp = 0; |
490 | 490 | $current_page = 0; |
491 | 491 | $post_delete = $this->per_step; |
492 | 492 | $page_donation_id = array(); |
493 | 493 | |
494 | - foreach ( $donation_ids as $item ) { |
|
495 | - $temp ++; |
|
496 | - $page_donation_id[ $current_page ][] = $item; |
|
497 | - if ( $temp === $post_delete ) { |
|
498 | - $current_page ++; |
|
494 | + foreach ($donation_ids as $item) { |
|
495 | + $temp++; |
|
496 | + $page_donation_id[$current_page][] = $item; |
|
497 | + if ($temp === $post_delete) { |
|
498 | + $current_page++; |
|
499 | 499 | $temp = 0; |
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
503 | - return $page_donation_id[ $page ]; |
|
503 | + return $page_donation_id[$page]; |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
@@ -513,8 +513,8 @@ discard block |
||
513 | 513 | * |
514 | 514 | * @return mixed Returns the data from the database |
515 | 515 | */ |
516 | - public function get_option( $key, $default_value = false ) { |
|
517 | - return get_option( $key, $default_value ); |
|
516 | + public function get_option($key, $default_value = false) { |
|
517 | + return get_option($key, $default_value); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
@@ -527,8 +527,8 @@ discard block |
||
527 | 527 | * |
528 | 528 | * @return void |
529 | 529 | */ |
530 | - public function update_option( $key, $value ) { |
|
531 | - update_option( $key, $value, false ); |
|
530 | + public function update_option($key, $value) { |
|
531 | + update_option($key, $value, false); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | /** |
@@ -540,8 +540,8 @@ discard block |
||
540 | 540 | * |
541 | 541 | * @return void |
542 | 542 | */ |
543 | - public function delete_option( $key ) { |
|
544 | - delete_option( $key ); |
|
543 | + public function delete_option($key) { |
|
544 | + delete_option($key); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -552,12 +552,12 @@ discard block |
||
552 | 552 | * @return int|string |
553 | 553 | */ |
554 | 554 | private function get_step() { |
555 | - $step_key = (string) $this->get_option( $this->step_key, false ); |
|
556 | - if ( 'count' === $step_key ) { |
|
555 | + $step_key = (string) $this->get_option($this->step_key, false); |
|
556 | + if ('count' === $step_key) { |
|
557 | 557 | return 1; |
558 | - } elseif ( 'donation' === $step_key ) { |
|
558 | + } elseif ('donation' === $step_key) { |
|
559 | 559 | return 2; |
560 | - } elseif ( 'donor' === $step_key ) { |
|
560 | + } elseif ('donor' === $step_key) { |
|
561 | 561 | return 3; |
562 | 562 | } else { |
563 | 563 | return $step_key; |
@@ -568,6 +568,6 @@ discard block |
||
568 | 568 | * Get the current $page value in the ajax. |
569 | 569 | */ |
570 | 570 | private function get_step_page() { |
571 | - return $this->get_option( $this->step_on_key, false ); |
|
571 | + return $this->get_option($this->step_on_key, false); |
|
572 | 572 | } |
573 | 573 | } |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * @param int $comment_id |
446 | 446 | * @param WP_Comment $comment |
447 | 447 | * |
448 | - * @return mixed |
|
448 | + * @return string |
|
449 | 449 | */ |
450 | 450 | public function __get_comment_author( $author, $comment_id, $comment ) { |
451 | 451 | if ( in_array( $comment->comment_type, $this->comment_types ) ) { |
@@ -468,6 +468,7 @@ discard block |
||
468 | 468 | * @access public |
469 | 469 | * |
470 | 470 | * @param array @comment_types |
471 | + * @param string[] $comment_types |
|
471 | 472 | * |
472 | 473 | * @return array |
473 | 474 | */ |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return Give_Comment |
47 | 47 | */ |
48 | 48 | public static function get_instance() { |
49 | - if ( null === static::$instance ) { |
|
49 | + if (null === static::$instance) { |
|
50 | 50 | self::$instance = new static(); |
51 | 51 | self::$instance->init(); |
52 | 52 | } |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | */ |
69 | 69 | $this->comment_types = apply_filters( |
70 | 70 | 'give_comment_type', |
71 | - self::get_comment_types( array( 'payment', 'donor' ) ) |
|
71 | + self::get_comment_types(array('payment', 'donor')) |
|
72 | 72 | ); |
73 | 73 | |
74 | - add_action( 'pre_get_comments', array( $this, 'hide_comments' ), 10 ); |
|
75 | - add_filter( 'comments_clauses', array( $this, 'hide_comments_pre_wp_41' ), 10, 1 ); |
|
76 | - add_filter( 'comment_feed_where', array( $this, 'hide_comments_from_feeds' ), 10, 1 ); |
|
77 | - add_filter( 'wp_count_comments', array( $this, 'remove_comments_from_comment_counts' ), 10, 2 ); |
|
78 | - add_filter( 'get_comment_author', array( $this, '__get_comment_author' ), 10, 3 ); |
|
74 | + add_action('pre_get_comments', array($this, 'hide_comments'), 10); |
|
75 | + add_filter('comments_clauses', array($this, 'hide_comments_pre_wp_41'), 10, 1); |
|
76 | + add_filter('comment_feed_where', array($this, 'hide_comments_from_feeds'), 10, 1); |
|
77 | + add_filter('wp_count_comments', array($this, 'remove_comments_from_comment_counts'), 10, 2); |
|
78 | + add_filter('get_comment_author', array($this, '__get_comment_author'), 10, 3); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return int|WP_Error |
93 | 93 | */ |
94 | - public static function add( $id, $note, $comment_type, $comment_args = array() ) { |
|
94 | + public static function add($id, $note, $comment_type, $comment_args = array()) { |
|
95 | 95 | // Bailout |
96 | - if ( empty( $id ) || empty( $note ) || empty( $comment_type ) ) { |
|
97 | - return new WP_Error( 'give_invalid_required_param', __( 'This comment has invalid ID or comment text or cooment type', 'give' ) ); |
|
96 | + if (empty($id) || empty($note) || empty($comment_type)) { |
|
97 | + return new WP_Error('give_invalid_required_param', __('This comment has invalid ID or comment text or cooment type', 'give')); |
|
98 | 98 | } |
99 | 99 | |
100 | - $is_existing_comment = array_key_exists( 'comment_ID', $comment_args ) && ! empty( $comment_args['comment_ID'] ); |
|
100 | + $is_existing_comment = array_key_exists('comment_ID', $comment_args) && ! empty($comment_args['comment_ID']); |
|
101 | 101 | $action_type = $is_existing_comment ? 'update' : 'insert'; |
102 | 102 | |
103 | 103 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @since 1.0 |
110 | 110 | */ |
111 | - do_action( "give_pre_{$action_type}_{$comment_type}_note", $id, $note ); |
|
111 | + do_action("give_pre_{$action_type}_{$comment_type}_note", $id, $note); |
|
112 | 112 | |
113 | 113 | $comment_args = wp_parse_args( |
114 | 114 | $comment_args, |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | 'comment_post_ID' => $id, |
117 | 117 | 'comment_content' => $note, |
118 | 118 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
119 | - 'comment_date' => current_time( 'mysql' ), |
|
120 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
119 | + 'comment_date' => current_time('mysql'), |
|
120 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
121 | 121 | 'comment_approved' => 1, |
122 | 122 | 'comment_parent' => 0, |
123 | 123 | 'comment_author' => '', |
@@ -131,30 +131,30 @@ discard block |
||
131 | 131 | |
132 | 132 | |
133 | 133 | // Check comment max length. |
134 | - $error = wp_check_comment_data_max_lengths( $comment_args ); |
|
135 | - if( is_wp_error( $error ) ) { |
|
134 | + $error = wp_check_comment_data_max_lengths($comment_args); |
|
135 | + if (is_wp_error($error)) { |
|
136 | 136 | return $error; |
137 | 137 | } |
138 | 138 | |
139 | 139 | // Remove moderation emails when comment posted. |
140 | - remove_action( 'comment_post', 'wp_new_comment_notify_moderator' ); |
|
141 | - remove_action( 'comment_post', 'wp_new_comment_notify_postauthor' ); |
|
140 | + remove_action('comment_post', 'wp_new_comment_notify_moderator'); |
|
141 | + remove_action('comment_post', 'wp_new_comment_notify_postauthor'); |
|
142 | 142 | |
143 | 143 | // Remove comment flood check. |
144 | - remove_action( 'check_comment_flood', 'check_comment_flood_db', 10 ); |
|
144 | + remove_action('check_comment_flood', 'check_comment_flood_db', 10); |
|
145 | 145 | |
146 | 146 | $comment_id = $is_existing_comment |
147 | - ? wp_update_comment( $comment_args ) |
|
148 | - : wp_new_comment( $comment_args, true ); |
|
147 | + ? wp_update_comment($comment_args) |
|
148 | + : wp_new_comment($comment_args, true); |
|
149 | 149 | |
150 | 150 | // Add moderation emails when comment posted. |
151 | - add_action( 'comment_post', 'wp_new_comment_notify_moderator' ); |
|
152 | - add_action( 'comment_post', 'wp_new_comment_notify_postauthor' ); |
|
151 | + add_action('comment_post', 'wp_new_comment_notify_moderator'); |
|
152 | + add_action('comment_post', 'wp_new_comment_notify_postauthor'); |
|
153 | 153 | |
154 | 154 | // Add comment flood check. |
155 | - add_action( 'check_comment_flood', 'check_comment_flood_db', 10, 4 ); |
|
155 | + add_action('check_comment_flood', 'check_comment_flood_db', 10, 4); |
|
156 | 156 | |
157 | - update_comment_meta( $comment_id, "_give_{$comment_type}_id", $id ); |
|
157 | + update_comment_meta($comment_id, "_give_{$comment_type}_id", $id); |
|
158 | 158 | |
159 | 159 | /** |
160 | 160 | * Fires after payment|donor comment inserted/updated. |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @since 1.0 |
167 | 167 | */ |
168 | - do_action( "give_{$action_type}_{$comment_type}_note", $comment_id, $id, $note ); |
|
168 | + do_action("give_{$action_type}_{$comment_type}_note", $comment_id, $id, $note); |
|
169 | 169 | |
170 | 170 | return $comment_id; |
171 | 171 | } |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @return bool True on success, false otherwise. |
187 | 187 | */ |
188 | - public static function delete( $comment_id, $id, $comment_type ) { |
|
188 | + public static function delete($comment_id, $id, $comment_type) { |
|
189 | 189 | $ret = false; |
190 | 190 | |
191 | 191 | // Bailout |
192 | - if ( empty( $id ) || empty( $comment_id ) || empty( $comment_type ) ) { |
|
192 | + if (empty($id) || empty($comment_id) || empty($comment_type)) { |
|
193 | 193 | return $ret; |
194 | 194 | } |
195 | 195 | |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @since 1.0 |
203 | 203 | */ |
204 | - do_action( "give_pre_delete_{$comment_type}_note", $comment_id, $id ); |
|
204 | + do_action("give_pre_delete_{$comment_type}_note", $comment_id, $id); |
|
205 | 205 | |
206 | - $ret = wp_delete_comment( $comment_id, true ); |
|
206 | + $ret = wp_delete_comment($comment_id, true); |
|
207 | 207 | |
208 | 208 | /** |
209 | 209 | * Fires after donation note deleted. |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @since 1.0 |
216 | 216 | */ |
217 | - do_action( "give_post_delete_{$comment_type}_note", $comment_id, $id, $ret ); |
|
217 | + do_action("give_post_delete_{$comment_type}_note", $comment_id, $id, $ret); |
|
218 | 218 | |
219 | 219 | return $ret; |
220 | 220 | } |
@@ -233,25 +233,25 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return array |
235 | 235 | */ |
236 | - public static function get( $id, $comment_type, $comment_args = array(), $search = '' ) { |
|
236 | + public static function get($id, $comment_type, $comment_args = array(), $search = '') { |
|
237 | 237 | $comments = array(); |
238 | 238 | |
239 | 239 | // Set default meta_query value. |
240 | - if ( ! isset( $comment_args['meta_query'] ) ) { |
|
240 | + if ( ! isset($comment_args['meta_query'])) { |
|
241 | 241 | $comment_args['meta_query'] = array(); |
242 | 242 | } |
243 | 243 | |
244 | 244 | // Bailout |
245 | - if ( empty( $id ) || empty( $comment_type ) ) { |
|
245 | + if (empty($id) || empty($comment_type)) { |
|
246 | 246 | return $comments; |
247 | 247 | } |
248 | 248 | |
249 | - remove_action( 'pre_get_comments', array( self::$instance, 'hide_comments' ), 10 ); |
|
250 | - remove_filter( 'comments_clauses', array( self::$instance, 'hide_comments_pre_wp_41' ), 10 ); |
|
249 | + remove_action('pre_get_comments', array(self::$instance, 'hide_comments'), 10); |
|
250 | + remove_filter('comments_clauses', array(self::$instance, 'hide_comments_pre_wp_41'), 10); |
|
251 | 251 | |
252 | - switch ( $comment_type ) { |
|
252 | + switch ($comment_type) { |
|
253 | 253 | case 'payment': |
254 | - $comment_args['meta_query'] = ! empty( $comment_args['meta_query'] ) |
|
254 | + $comment_args['meta_query'] = ! empty($comment_args['meta_query']) |
|
255 | 255 | ? $comment_args['meta_query'] |
256 | 256 | : array( |
257 | 257 | array( |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | ) |
261 | 261 | ); |
262 | 262 | |
263 | - $comments = get_comments( wp_parse_args( |
|
263 | + $comments = get_comments(wp_parse_args( |
|
264 | 264 | $comment_args, |
265 | 265 | array( |
266 | 266 | 'post_id' => $id, |
@@ -268,11 +268,11 @@ discard block |
||
268 | 268 | 'search' => $search, |
269 | 269 | 'type' => 'give_payment_note' |
270 | 270 | ) |
271 | - ) ); |
|
271 | + )); |
|
272 | 272 | break; |
273 | 273 | |
274 | 274 | case 'donor': |
275 | - $comment_args['meta_query'] = ! empty( $comment_args['meta_query'] ) |
|
275 | + $comment_args['meta_query'] = ! empty($comment_args['meta_query']) |
|
276 | 276 | ? $comment_args['meta_query'] |
277 | 277 | : array( |
278 | 278 | array( |
@@ -281,19 +281,19 @@ discard block |
||
281 | 281 | ) |
282 | 282 | ); |
283 | 283 | |
284 | - $comments = get_comments( wp_parse_args( |
|
284 | + $comments = get_comments(wp_parse_args( |
|
285 | 285 | $comment_args, |
286 | 286 | array( |
287 | 287 | 'order' => 'ASC', |
288 | 288 | 'search' => $search, |
289 | 289 | 'type' => 'give_donor_note' |
290 | 290 | ) |
291 | - ) ); |
|
291 | + )); |
|
292 | 292 | break; |
293 | 293 | } |
294 | 294 | |
295 | - add_action( 'pre_get_comments', array( self::$instance, 'hide_comments' ), 10, 1 ); |
|
296 | - add_filter( 'comments_clauses', array( self::$instance, 'hide_comments_pre_wp_41' ), 10, 1 ); |
|
295 | + add_action('pre_get_comments', array(self::$instance, 'hide_comments'), 10, 1); |
|
296 | + add_filter('comments_clauses', array(self::$instance, 'hide_comments_pre_wp_41'), 10, 1); |
|
297 | 297 | |
298 | 298 | return $comments; |
299 | 299 | } |
@@ -309,14 +309,14 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @return void |
311 | 311 | */ |
312 | - public function hide_comments( $query ) { |
|
313 | - if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '>=' ) ) { |
|
314 | - $types = isset( $query->query_vars['type__not_in'] ) ? $query->query_vars['type__not_in'] : array(); |
|
315 | - if ( ! is_array( $types ) ) { |
|
316 | - $types = array( $types ); |
|
312 | + public function hide_comments($query) { |
|
313 | + if (version_compare(floatval(get_bloginfo('version')), '4.1', '>=')) { |
|
314 | + $types = isset($query->query_vars['type__not_in']) ? $query->query_vars['type__not_in'] : array(); |
|
315 | + if ( ! is_array($types)) { |
|
316 | + $types = array($types); |
|
317 | 317 | } |
318 | 318 | |
319 | - $types = array_filter( array_merge( $types, $this->comment_types ) ); |
|
319 | + $types = array_filter(array_merge($types, $this->comment_types)); |
|
320 | 320 | |
321 | 321 | $query->query_vars['type__not_in'] = $types; |
322 | 322 | } |
@@ -332,9 +332,9 @@ discard block |
||
332 | 332 | * |
333 | 333 | * @return array $clauses Updated comment clauses. |
334 | 334 | */ |
335 | - public function hide_comments_pre_wp_41( $clauses ) { |
|
336 | - if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '<' ) ) { |
|
337 | - foreach ( $this->comment_types as $comment_type ) { |
|
335 | + public function hide_comments_pre_wp_41($clauses) { |
|
336 | + if (version_compare(floatval(get_bloginfo('version')), '4.1', '<')) { |
|
337 | + foreach ($this->comment_types as $comment_type) { |
|
338 | 338 | $clauses['where'] .= " AND comment_type != \"{$comment_type}\""; |
339 | 339 | } |
340 | 340 | } |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | * |
353 | 353 | * @return string $where |
354 | 354 | */ |
355 | - public function hide_comments_from_feeds( $where ) { |
|
355 | + public function hide_comments_from_feeds($where) { |
|
356 | 356 | global $wpdb; |
357 | 357 | |
358 | - foreach ( $this->comment_types as $comment_type ) { |
|
359 | - $where .= $wpdb->prepare( ' AND comment_type!=%s', $comment_type ); |
|
358 | + foreach ($this->comment_types as $comment_type) { |
|
359 | + $where .= $wpdb->prepare(' AND comment_type!=%s', $comment_type); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | return $where; |
@@ -373,30 +373,30 @@ discard block |
||
373 | 373 | * |
374 | 374 | * @return array|object Array of comment counts. |
375 | 375 | */ |
376 | - public function remove_comments_from_comment_counts( $stats, $post_id ) { |
|
376 | + public function remove_comments_from_comment_counts($stats, $post_id) { |
|
377 | 377 | global $wpdb; |
378 | 378 | |
379 | 379 | $post_id = (int) $post_id; |
380 | 380 | |
381 | - if ( apply_filters( 'give_count_payment_notes_in_comments', false ) ) { |
|
381 | + if (apply_filters('give_count_payment_notes_in_comments', false)) { |
|
382 | 382 | return $stats; |
383 | 383 | } |
384 | 384 | |
385 | - $stats = Give_Cache::get_group( "comments-{$post_id}", 'counts' ); |
|
385 | + $stats = Give_Cache::get_group("comments-{$post_id}", 'counts'); |
|
386 | 386 | |
387 | 387 | // Return result from cache. |
388 | - if ( ! is_null( $stats ) ) { |
|
388 | + if ( ! is_null($stats)) { |
|
389 | 389 | return $stats; |
390 | 390 | } |
391 | 391 | |
392 | 392 | $where = 'WHERE'; |
393 | 393 | |
394 | - foreach ( $this->comment_types as $index => $comment_type ) { |
|
395 | - $where .= ( $index ? ' AND ' : ' ' ) . "comment_type != \"{$comment_type}\""; |
|
394 | + foreach ($this->comment_types as $index => $comment_type) { |
|
395 | + $where .= ($index ? ' AND ' : ' ')."comment_type != \"{$comment_type}\""; |
|
396 | 396 | } |
397 | 397 | |
398 | - if ( $post_id > 0 ) { |
|
399 | - $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id ); |
|
398 | + if ($post_id > 0) { |
|
399 | + $where .= $wpdb->prepare(' AND comment_post_ID = %d', $post_id); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | $count = $wpdb->get_results( |
@@ -417,26 +417,26 @@ discard block |
||
417 | 417 | 'post-trashed' => 'post-trashed', |
418 | 418 | ); |
419 | 419 | |
420 | - foreach ( (array) $count as $row ) { |
|
420 | + foreach ((array) $count as $row) { |
|
421 | 421 | // Don't count post-trashed toward totals. |
422 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) { |
|
422 | + if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) { |
|
423 | 423 | $total += $row['num_comments']; |
424 | 424 | } |
425 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
426 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
425 | + if (isset($approved[$row['comment_approved']])) { |
|
426 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
430 | 430 | $stats['total_comments'] = $stats['all'] = $total; |
431 | - foreach ( $approved as $key ) { |
|
432 | - if ( empty( $stats[ $key ] ) ) { |
|
433 | - $stats[ $key ] = 0; |
|
431 | + foreach ($approved as $key) { |
|
432 | + if (empty($stats[$key])) { |
|
433 | + $stats[$key] = 0; |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
437 | 437 | $stats = (object) $stats; |
438 | 438 | |
439 | - Give_Cache::set_group( "comments-{$post_id}", $stats, 'counts' ); |
|
439 | + Give_Cache::set_group("comments-{$post_id}", $stats, 'counts'); |
|
440 | 440 | |
441 | 441 | return $stats; |
442 | 442 | } |
@@ -453,12 +453,12 @@ discard block |
||
453 | 453 | * |
454 | 454 | * @return mixed |
455 | 455 | */ |
456 | - public function __get_comment_author( $author, $comment_id, $comment ) { |
|
457 | - if ( in_array( $comment->comment_type, $this->comment_types ) ) { |
|
458 | - switch ( $comment->comment_type ) { |
|
456 | + public function __get_comment_author($author, $comment_id, $comment) { |
|
457 | + if (in_array($comment->comment_type, $this->comment_types)) { |
|
458 | + switch ($comment->comment_type) { |
|
459 | 459 | case 'give_payment_note': |
460 | - if ( get_comment_meta( $comment_id, '_give_donor_id', true ) ) { |
|
461 | - $author = give_get_donor_name_by( $comment->comment_post_ID ); |
|
460 | + if (get_comment_meta($comment_id, '_give_donor_id', true)) { |
|
461 | + $author = give_get_donor_name_by($comment->comment_post_ID); |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 | } |
@@ -477,9 +477,9 @@ discard block |
||
477 | 477 | * |
478 | 478 | * @return array |
479 | 479 | */ |
480 | - public static function get_comment_types( $comment_types ) { |
|
480 | + public static function get_comment_types($comment_types) { |
|
481 | 481 | $_comment_types = array(); |
482 | - foreach ( $comment_types as $comment_type ) { |
|
482 | + foreach ($comment_types as $comment_type) { |
|
483 | 483 | $_comment_types[] = "give_{$comment_type}_note"; |
484 | 484 | } |
485 | 485 |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | /** |
280 | 280 | * Rename query clauses for new meta table |
281 | 281 | * |
282 | - * @param $clause |
|
282 | + * @param string $clause |
|
283 | 283 | * @param $filter |
284 | 284 | * |
285 | 285 | * @return mixed |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | * @since 2.0.4 |
516 | 516 | * @access public |
517 | 517 | * |
518 | - * @return string |
|
518 | + * @return boolean |
|
519 | 519 | */ |
520 | 520 | public function get_meta_type() { |
521 | 521 | return $this->meta_type; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -77,40 +77,40 @@ discard block |
||
77 | 77 | parent::__construct(); |
78 | 78 | |
79 | 79 | // Bailout. |
80 | - if ( empty( $this->supports ) || ! $this->is_custom_meta_table_active() ) { |
|
80 | + if (empty($this->supports) || ! $this->is_custom_meta_table_active()) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | - if ( in_array( 'add_post_metadata', $this->supports ) ) { |
|
85 | - add_filter( 'add_post_metadata', array( $this, '__add_meta' ), 0, 5 ); |
|
84 | + if (in_array('add_post_metadata', $this->supports)) { |
|
85 | + add_filter('add_post_metadata', array($this, '__add_meta'), 0, 5); |
|
86 | 86 | } |
87 | 87 | |
88 | - if ( in_array( 'get_post_metadata', $this->supports ) ) { |
|
89 | - add_filter( 'get_post_metadata', array( $this, '__get_meta' ), 10, 4 ); |
|
88 | + if (in_array('get_post_metadata', $this->supports)) { |
|
89 | + add_filter('get_post_metadata', array($this, '__get_meta'), 10, 4); |
|
90 | 90 | } |
91 | 91 | |
92 | - if ( in_array( 'update_post_metadata', $this->supports ) ) { |
|
93 | - add_filter( 'update_post_metadata', array( $this, '__update_meta' ), 0, 5 ); |
|
92 | + if (in_array('update_post_metadata', $this->supports)) { |
|
93 | + add_filter('update_post_metadata', array($this, '__update_meta'), 0, 5); |
|
94 | 94 | } |
95 | 95 | |
96 | - if ( in_array( 'delete_post_metadata', $this->supports ) ) { |
|
97 | - add_filter( 'delete_post_metadata', array( $this, '__delete_meta' ), 0, 5 ); |
|
96 | + if (in_array('delete_post_metadata', $this->supports)) { |
|
97 | + add_filter('delete_post_metadata', array($this, '__delete_meta'), 0, 5); |
|
98 | 98 | } |
99 | 99 | |
100 | - if ( in_array( 'posts_where', $this->supports ) ) { |
|
101 | - add_filter( 'posts_where', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
|
100 | + if (in_array('posts_where', $this->supports)) { |
|
101 | + add_filter('posts_where', array($this, '__rename_meta_table_name_in_query'), 99999, 2); |
|
102 | 102 | } |
103 | 103 | |
104 | - if ( in_array( 'posts_join', $this->supports ) ) { |
|
105 | - add_filter( 'posts_join', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
|
104 | + if (in_array('posts_join', $this->supports)) { |
|
105 | + add_filter('posts_join', array($this, '__rename_meta_table_name_in_query'), 99999, 2); |
|
106 | 106 | } |
107 | 107 | |
108 | - if ( in_array( 'posts_groupby', $this->supports ) ) { |
|
109 | - add_filter( 'posts_groupby', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
|
108 | + if (in_array('posts_groupby', $this->supports)) { |
|
109 | + add_filter('posts_groupby', array($this, '__rename_meta_table_name_in_query'), 99999, 2); |
|
110 | 110 | } |
111 | 111 | |
112 | - if ( in_array( 'posts_orderby', $this->supports ) ) { |
|
113 | - add_filter( 'posts_orderby', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
|
112 | + if (in_array('posts_orderby', $this->supports)) { |
|
113 | + add_filter('posts_orderby', array($this, '__rename_meta_table_name_in_query'), 99999, 2); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -128,16 +128,16 @@ discard block |
||
128 | 128 | * @return mixed Will be an array if $single is false. Will be value of meta data field if $single |
129 | 129 | * is true. |
130 | 130 | */ |
131 | - public function get_meta( $id = 0, $meta_key = '', $single = false ) { |
|
132 | - $id = $this->sanitize_id( $id ); |
|
131 | + public function get_meta($id = 0, $meta_key = '', $single = false) { |
|
132 | + $id = $this->sanitize_id($id); |
|
133 | 133 | |
134 | 134 | // Bailout. |
135 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
135 | + if ( ! $this->is_valid_post_type($id)) { |
|
136 | 136 | return $this->check; |
137 | 137 | } |
138 | 138 | |
139 | - if ( $this->raw_result ) { |
|
140 | - if ( ! ( $value = get_metadata( $this->meta_type, $id, $meta_key, false ) ) ) { |
|
139 | + if ($this->raw_result) { |
|
140 | + if ( ! ($value = get_metadata($this->meta_type, $id, $meta_key, false))) { |
|
141 | 141 | $value = ''; |
142 | 142 | } |
143 | 143 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $this->raw_result = false; |
146 | 146 | |
147 | 147 | } else { |
148 | - $value = get_metadata( $this->meta_type, $id, $meta_key, $single ); |
|
148 | + $value = get_metadata($this->meta_type, $id, $meta_key, $single); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return $value; |
@@ -167,18 +167,18 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return int|bool False for failure. True for success. |
169 | 169 | */ |
170 | - public function add_meta( $id = 0, $meta_key = '', $meta_value, $unique = false ) { |
|
171 | - $id = $this->sanitize_id( $id ); |
|
170 | + public function add_meta($id = 0, $meta_key = '', $meta_value, $unique = false) { |
|
171 | + $id = $this->sanitize_id($id); |
|
172 | 172 | |
173 | 173 | // Bailout. |
174 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
174 | + if ( ! $this->is_valid_post_type($id)) { |
|
175 | 175 | return $this->check; |
176 | 176 | } |
177 | 177 | |
178 | - $meta_id = add_metadata( $this->meta_type, $id, $meta_key, $meta_value, $unique ); |
|
178 | + $meta_id = add_metadata($this->meta_type, $id, $meta_key, $meta_value, $unique); |
|
179 | 179 | |
180 | - if ( $meta_id ) { |
|
181 | - $this->delete_cache( $id ); |
|
180 | + if ($meta_id) { |
|
181 | + $this->delete_cache($id); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | return $meta_id; |
@@ -204,18 +204,18 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @return int|bool False on failure, true if success. |
206 | 206 | */ |
207 | - public function update_meta( $id = 0, $meta_key = '', $meta_value, $prev_value = '' ) { |
|
208 | - $id = $this->sanitize_id( $id ); |
|
207 | + public function update_meta($id = 0, $meta_key = '', $meta_value, $prev_value = '') { |
|
208 | + $id = $this->sanitize_id($id); |
|
209 | 209 | |
210 | 210 | // Bailout. |
211 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
211 | + if ( ! $this->is_valid_post_type($id)) { |
|
212 | 212 | return $this->check; |
213 | 213 | } |
214 | 214 | |
215 | - $meta_id = update_metadata( $this->meta_type, $id, $meta_key, $meta_value, $prev_value ); |
|
215 | + $meta_id = update_metadata($this->meta_type, $id, $meta_key, $meta_value, $prev_value); |
|
216 | 216 | |
217 | - if ( $meta_id ) { |
|
218 | - $this->delete_cache( $id ); |
|
217 | + if ($meta_id) { |
|
218 | + $this->delete_cache($id); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | return $meta_id; |
@@ -238,18 +238,18 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @return bool False for failure. True for success. |
240 | 240 | */ |
241 | - public function delete_meta( $id = 0, $meta_key = '', $meta_value = '', $delete_all = '' ) { |
|
242 | - $id = $this->sanitize_id( $id ); |
|
241 | + public function delete_meta($id = 0, $meta_key = '', $meta_value = '', $delete_all = '') { |
|
242 | + $id = $this->sanitize_id($id); |
|
243 | 243 | |
244 | 244 | // Bailout. |
245 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
245 | + if ( ! $this->is_valid_post_type($id)) { |
|
246 | 246 | return $this->check; |
247 | 247 | } |
248 | 248 | |
249 | - $is_meta_deleted = delete_metadata( $this->meta_type, $id, $meta_key, $meta_value, $delete_all ); |
|
249 | + $is_meta_deleted = delete_metadata($this->meta_type, $id, $meta_key, $meta_value, $delete_all); |
|
250 | 250 | |
251 | - if ( $is_meta_deleted ) { |
|
252 | - $this->delete_cache( $id ); |
|
251 | + if ($is_meta_deleted) { |
|
252 | + $this->delete_cache($id); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | return $is_meta_deleted; |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | * |
267 | 267 | * @return string |
268 | 268 | */ |
269 | - public function __rename_meta_table_name_in_query( $clause, $wp_query ) { |
|
269 | + public function __rename_meta_table_name_in_query($clause, $wp_query) { |
|
270 | 270 | // Add new table to sql query. |
271 | - if ( $this->is_post_type_query( $wp_query ) && ! empty( $wp_query->meta_query->queries ) ) { |
|
272 | - $clause = $this->__rename_meta_table_name( $clause, current_filter() ); |
|
271 | + if ($this->is_post_type_query($wp_query) && ! empty($wp_query->meta_query->queries)) { |
|
272 | + $clause = $this->__rename_meta_table_name($clause, current_filter()); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | return $clause; |
@@ -284,42 +284,42 @@ discard block |
||
284 | 284 | * |
285 | 285 | * @return mixed |
286 | 286 | */ |
287 | - public function __rename_meta_table_name( $clause, $filter ) { |
|
287 | + public function __rename_meta_table_name($clause, $filter) { |
|
288 | 288 | global $wpdb; |
289 | 289 | |
290 | - $clause = str_replace( "{$wpdb->postmeta}.post_id", "{$this->table_name}.{$this->meta_type}_id", $clause ); |
|
291 | - $clause = str_replace( $wpdb->postmeta, $this->table_name, $clause ); |
|
290 | + $clause = str_replace("{$wpdb->postmeta}.post_id", "{$this->table_name}.{$this->meta_type}_id", $clause); |
|
291 | + $clause = str_replace($wpdb->postmeta, $this->table_name, $clause); |
|
292 | 292 | |
293 | - switch ( $filter ) { |
|
293 | + switch ($filter) { |
|
294 | 294 | case 'posts_join': |
295 | - $joins = array( 'INNER JOIN', 'LEFT JOIN' ); |
|
295 | + $joins = array('INNER JOIN', 'LEFT JOIN'); |
|
296 | 296 | |
297 | - foreach ( $joins as $join ) { |
|
298 | - if ( false !== strpos( $clause, $join ) ) { |
|
299 | - $clause = explode( $join, $clause ); |
|
297 | + foreach ($joins as $join) { |
|
298 | + if (false !== strpos($clause, $join)) { |
|
299 | + $clause = explode($join, $clause); |
|
300 | 300 | |
301 | - foreach ( $clause as $key => $clause_part ) { |
|
302 | - if ( empty( $clause_part ) ) { |
|
301 | + foreach ($clause as $key => $clause_part) { |
|
302 | + if (empty($clause_part)) { |
|
303 | 303 | continue; |
304 | 304 | } |
305 | 305 | |
306 | - preg_match( '/' . $wpdb->prefix . 'give_' . $this->meta_type . 'meta AS (.*) ON/', $clause_part, $alias_table_name ); |
|
306 | + preg_match('/'.$wpdb->prefix.'give_'.$this->meta_type.'meta AS (.*) ON/', $clause_part, $alias_table_name); |
|
307 | 307 | |
308 | - if ( isset( $alias_table_name[1] ) ) { |
|
309 | - $clause[ $key ] = str_replace( "{$alias_table_name[1]}.post_id", "{$alias_table_name[1]}.{$this->meta_type}_id", $clause_part ); |
|
308 | + if (isset($alias_table_name[1])) { |
|
309 | + $clause[$key] = str_replace("{$alias_table_name[1]}.post_id", "{$alias_table_name[1]}.{$this->meta_type}_id", $clause_part); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | - $clause = implode( "{$join} ", $clause ); |
|
313 | + $clause = implode("{$join} ", $clause); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | break; |
317 | 317 | |
318 | 318 | case 'posts_where': |
319 | - $clause = str_replace( array( 'mt2.post_id', 'mt1.post_id' ), array( |
|
319 | + $clause = str_replace(array('mt2.post_id', 'mt1.post_id'), array( |
|
320 | 320 | "mt2.{$this->meta_type}_id", |
321 | 321 | "mt1.{$this->meta_type}_id" |
322 | - ), $clause ); |
|
322 | + ), $clause); |
|
323 | 323 | break; |
324 | 324 | } |
325 | 325 | |
@@ -337,19 +337,19 @@ discard block |
||
337 | 337 | * |
338 | 338 | * @return bool |
339 | 339 | */ |
340 | - protected function is_post_type_query( $wp_query ) { |
|
340 | + protected function is_post_type_query($wp_query) { |
|
341 | 341 | $status = false; |
342 | 342 | |
343 | 343 | // Check if it is payment query. |
344 | - if ( ! empty( $wp_query->query['post_type'] ) ) { |
|
344 | + if ( ! empty($wp_query->query['post_type'])) { |
|
345 | 345 | if ( |
346 | - is_string( $wp_query->query['post_type'] ) && |
|
346 | + is_string($wp_query->query['post_type']) && |
|
347 | 347 | $this->post_type === $wp_query->query['post_type'] |
348 | 348 | ) { |
349 | 349 | $status = true; |
350 | 350 | } elseif ( |
351 | - is_array( $wp_query->query['post_type'] ) && |
|
352 | - in_array( $this->post_type, $wp_query->query['post_type'] ) |
|
351 | + is_array($wp_query->query['post_type']) && |
|
352 | + in_array($this->post_type, $wp_query->query['post_type']) |
|
353 | 353 | ) { |
354 | 354 | $status = true; |
355 | 355 | } |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | * |
369 | 369 | * @return bool |
370 | 370 | */ |
371 | - protected function is_valid_post_type( $ID ) { |
|
372 | - return $ID && ( $this->post_type === get_post_type( $ID ) ); |
|
371 | + protected function is_valid_post_type($ID) { |
|
372 | + return $ID && ($this->post_type === get_post_type($ID)); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -395,8 +395,8 @@ discard block |
||
395 | 395 | * |
396 | 396 | * @return void |
397 | 397 | */ |
398 | - private function delete_cache( $id, $meta_type = '' ) { |
|
399 | - $meta_type = empty( $meta_type ) ? $this->meta_type : $meta_type; |
|
398 | + private function delete_cache($id, $meta_type = '') { |
|
399 | + $meta_type = empty($meta_type) ? $this->meta_type : $meta_type; |
|
400 | 400 | |
401 | 401 | $group = array( |
402 | 402 | 'payment' => 'give-donations', // Backward compatibility |
@@ -405,8 +405,8 @@ discard block |
||
405 | 405 | 'customer' => 'give-donors', // Backward compatibility for pre upgrade in 2.0 |
406 | 406 | ); |
407 | 407 | |
408 | - if ( array_key_exists( $meta_type, $group ) ) { |
|
409 | - Give_Cache::delete_group( $id, $group[ $meta_type ] ); |
|
408 | + if (array_key_exists($meta_type, $group)) { |
|
409 | + Give_Cache::delete_group($id, $group[$meta_type]); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
@@ -421,8 +421,8 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @return mixed |
423 | 423 | */ |
424 | - public function __call( $name, $arguments ) { |
|
425 | - switch ( $name ) { |
|
424 | + public function __call($name, $arguments) { |
|
425 | + switch ($name) { |
|
426 | 426 | case '__add_meta': |
427 | 427 | $this->check = $arguments[0]; |
428 | 428 | $id = $arguments[1]; |
@@ -431,11 +431,11 @@ discard block |
||
431 | 431 | $unique = $arguments[4]; |
432 | 432 | |
433 | 433 | // Bailout. |
434 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
434 | + if ( ! $this->is_valid_post_type($id)) { |
|
435 | 435 | return $this->check; |
436 | 436 | } |
437 | 437 | |
438 | - return $this->add_meta( $id, $meta_key, $meta_value, $unique ); |
|
438 | + return $this->add_meta($id, $meta_key, $meta_value, $unique); |
|
439 | 439 | |
440 | 440 | case '__get_meta': |
441 | 441 | $this->check = $arguments[0]; |
@@ -444,13 +444,13 @@ discard block |
||
444 | 444 | $single = $arguments[3]; |
445 | 445 | |
446 | 446 | // Bailout. |
447 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
447 | + if ( ! $this->is_valid_post_type($id)) { |
|
448 | 448 | return $this->check; |
449 | 449 | } |
450 | 450 | |
451 | 451 | $this->raw_result = true; |
452 | 452 | |
453 | - return $this->get_meta( $id, $meta_key, $single ); |
|
453 | + return $this->get_meta($id, $meta_key, $single); |
|
454 | 454 | |
455 | 455 | case '__update_meta': |
456 | 456 | $this->check = $arguments[0]; |
@@ -459,11 +459,11 @@ discard block |
||
459 | 459 | $meta_value = $arguments[3]; |
460 | 460 | |
461 | 461 | // Bailout. |
462 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
462 | + if ( ! $this->is_valid_post_type($id)) { |
|
463 | 463 | return $this->check; |
464 | 464 | } |
465 | 465 | |
466 | - return $this->update_meta( $id, $meta_key, $meta_value ); |
|
466 | + return $this->update_meta($id, $meta_key, $meta_value); |
|
467 | 467 | |
468 | 468 | case '__delete_meta': |
469 | 469 | $this->check = $arguments[0]; |
@@ -473,11 +473,11 @@ discard block |
||
473 | 473 | $delete_all = $arguments[3]; |
474 | 474 | |
475 | 475 | // Bailout. |
476 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
476 | + if ( ! $this->is_valid_post_type($id)) { |
|
477 | 477 | return $this->check; |
478 | 478 | } |
479 | 479 | |
480 | - return $this->delete_meta( $id, $meta_key, $meta_value, $delete_all ); |
|
480 | + return $this->delete_meta($id, $meta_key, $meta_value, $delete_all); |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
@@ -502,10 +502,10 @@ discard block |
||
502 | 502 | KEY meta_key (meta_key({$this->min_index_length})) |
503 | 503 | ) {$charset_collate};"; |
504 | 504 | |
505 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
506 | - dbDelta( $sql ); |
|
505 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
506 | + dbDelta($sql); |
|
507 | 507 | |
508 | - update_option( $this->table_name . '_db_version', $this->version, false ); |
|
508 | + update_option($this->table_name.'_db_version', $this->version, false); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @return bool False for failure. True for success. |
533 | 533 | */ |
534 | - public function delete_all_meta( $id = 0 ) { |
|
534 | + public function delete_all_meta($id = 0) { |
|
535 | 535 | global $wpdb; |
536 | - $status = $wpdb->delete( $this->table_name, array( "{$this->meta_type}_id" => $id ), array( '%d' ) ); |
|
536 | + $status = $wpdb->delete($this->table_name, array("{$this->meta_type}_id" => $id), array('%d')); |
|
537 | 537 | |
538 | - if ( $status ) { |
|
539 | - $this->delete_cache( $id, $this->meta_type ); |
|
538 | + if ($status) { |
|
539 | + $this->delete_cache($id, $this->meta_type); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | return $status; |