| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * Admin Plugins |
| 4 | 4 | * |
| 5 | 5 | * @package Give |
| 6 | 6 | * @subpackage Admin/Plugins |
| 7 | - * @copyright Copyright (c) 2016, WordImpress | |
| 7 | + * @copyright Copyright (c) 2016, GiveWP | |
| 8 | 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | 9 | * @since 1.4 |
| 10 | 10 | */ |
| 11 | 11 | |
| @@ -23,15 +23,15 @@ | ||
| 23 | 23 | * |
| 24 | 24 | * @return array An array of updated action links. |
| 25 | 25 | */ |
| 26 | 26 | function give_plugin_action_links( $actions ) { |
| 27 | - $new_actions = array( | |
| 27 | + $new_actions = [ | |
| 28 | 28 | 'settings' => sprintf( |
| 29 | 29 | '<a href="%1$s">%2$s</a>', |
| 30 | 30 | admin_url( 'edit.php?post_type=give_forms&page=give-settings' ), |
| 31 | 31 | __( 'Settings', 'give' ) |
| 32 | 32 | ), |
| 33 | - ); | |
| 33 | + ]; | |
| 34 | 34 | |
| 35 | 35 | return array_merge( $new_actions, $actions ); |
| 36 | 36 | } |
| 37 | 37 | |
| @@ -42,9 +42,9 @@ | ||
| 42 | 42 | * Plugin row meta links |
| 43 | 43 | * |
| 44 | 44 | * @since 1.4 |
| 45 | 45 | * |
| 46 | - * @param array $plugin_meta An array of the plugin's metadata. | |
| 46 | + * @param array $plugin_meta An array of the plugin's metadata. | |
| 47 | 47 | * @param string $plugin_file Path to the plugin file, relative to the plugins directory. |
| 48 | 48 | * |
| 49 | 49 | * @return array |
| 50 | 50 | */ |
| @@ -52,18 +52,19 @@ | ||
| 52 | 52 | if ( GIVE_PLUGIN_BASENAME !== $plugin_file ) { |
| 53 | 53 | return $plugin_meta; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $new_meta_links = array( | |
| 56 | + $new_meta_links = [ | |
| 57 | 57 | sprintf( |
| 58 | 58 | '<a href="%1$s" target="_blank">%2$s</a>', |
| 59 | 59 | esc_url( |
| 60 | 60 | add_query_arg( |
| 61 | - array( | |
| 61 | + [ | |
| 62 | 62 | 'utm_source' => 'plugins-page', |
| 63 | 63 | 'utm_medium' => 'plugin-row', |
| 64 | 64 | 'utm_campaign' => 'admin', |
| 65 | - ), 'https://givewp.com/documentation/' | |
| 65 | + ], | |
| 66 | + 'https://givewp.com/documentation/' | |
| 66 | 67 | ) |
| 67 | 68 | ), |
| 68 | 69 | __( 'Documentation', 'give' ) |
| 69 | 70 | ), |
| @@ -70,18 +71,19 @@ | ||
| 70 | 71 | sprintf( |
| 71 | 72 | '<a href="%1$s" target="_blank">%2$s</a>', |
| 72 | 73 | esc_url( |
| 73 | 74 | add_query_arg( |
| 74 | - array( | |
| 75 | + [ | |
| 75 | 76 | 'utm_source' => 'plugins-page', |
| 76 | 77 | 'utm_medium' => 'plugin-row', |
| 77 | 78 | 'utm_campaign' => 'admin', |
| 78 | - ), 'https://givewp.com/addons/' | |
| 79 | + ], | |
| 80 | + 'https://givewp.com/addons/' | |
| 79 | 81 | ) |
| 80 | 82 | ), |
| 81 | 83 | __( 'Add-ons', 'give' ) |
| 82 | 84 | ), |
| 83 | - ); | |
| 85 | + ]; | |
| 84 | 86 | |
| 85 | 87 | return array_merge( $plugin_meta, $new_meta_links ); |
| 86 | 88 | } |
| 87 | 89 | |
| @@ -130,9 +132,9 @@ | ||
| 130 | 132 | function give_recently_activated_addons() { |
| 131 | 133 | // Check if action is set. |
| 132 | 134 | if ( isset( $_REQUEST['action'] ) ) { |
| 133 | 135 | $plugin_action = ( '-1' !== $_REQUEST['action'] ) ? $_REQUEST['action'] : ( isset( $_REQUEST['action2'] ) ? $_REQUEST['action2'] : '' ); |
| 134 | - $plugins = array(); | |
| 136 | + $plugins = []; | |
| 135 | 137 | |
| 136 | 138 | switch ( $plugin_action ) { |
| 137 | 139 | case 'activate': // Single add-on activation. |
| 138 | 140 | $plugins[] = $_REQUEST['plugin']; |
| @@ -141,9 +143,8 @@ | ||
| 141 | 143 | $plugins = $_REQUEST['checked']; |
| 142 | 144 | break; |
| 143 | 145 | } |
| 144 | 146 | |
| 145 | - | |
| 146 | 147 | if ( ! empty( $plugins ) ) { |
| 147 | 148 | |
| 148 | 149 | $give_addons = give_get_recently_activated_addons(); |
| 149 | 150 | |
| @@ -176,18 +177,27 @@ | ||
| 176 | 177 | */ |
| 177 | 178 | function give_filter_addons_do_filter_addons( $plugin_menu ) { |
| 178 | 179 | global $plugins; |
| 179 | 180 | |
| 180 | - foreach ( $plugins['all'] as $plugin_slug => $plugin_data ) { | |
| 181 | + $give_addons = wp_list_pluck( give_get_plugins( [ 'only_add_on' => true ] ), 'Name' ); | |
| 181 | 182 | |
| 182 | - if ( false !== strpos( $plugin_data['Name'], 'Give' ) && ( false !== strpos( $plugin_data['AuthorName'], 'WordImpress' ) || false !== strpos( $plugin_data['AuthorName'], 'GiveWP' ) ) ) { | |
| 183 | - $plugins['give'][ $plugin_slug ] = $plugins['all'][ $plugin_slug ]; | |
| 184 | - $plugins['give'][ $plugin_slug ]['plugin'] = $plugin_slug; | |
| 185 | - // replicate the next step. | |
| 186 | - if ( current_user_can( 'update_plugins' ) ) { | |
| 187 | - $current = get_site_transient( 'update_plugins' ); | |
| 188 | - if ( isset( $current->response[ $plugin_slug ] ) ) { | |
| 189 | - $plugins['give'][ $plugin_slug ]['update'] = true; | |
| 183 | + if ( ! empty( $give_addons ) ) { | |
| 184 | + foreach ( $plugins['all'] as $file => $plugin_data ) { | |
| 185 | + | |
| 186 | + if ( in_array( $plugin_data['Name'], $give_addons ) ) { | |
| 187 | + $plugins['give'][ $file ] = $plugins['all'][ $file ]; | |
| 188 | + $plugins['give'][ $file ]['plugin'] = $file; | |
| 189 | + | |
| 190 | + // Replicate the next step. | |
| 191 | + if ( current_user_can( 'update_plugins' ) ) { | |
| 192 | + $current = get_site_transient( 'update_plugins' ); | |
| 193 | + | |
| 194 | + if ( isset( $current->response[ $file ] ) ) { | |
| 195 | + $plugins['give'][ $file ]['update'] = true; | |
| 196 | + $plugins['give'][ $file ] = array_merge( (array) $current->response[ $file ], $plugins['give'][ $file ] ); | |
| 197 | + } elseif ( isset( $current->no_update[ $file ] ) ) { | |
| 198 | + $plugins['give'][ $file ] = array_merge( (array) $current->no_update[ $file ], $plugins['give'][ $file ] ); | |
| 199 | + } | |
| 190 | 200 | } |
| 191 | 201 | } |
| 192 | 202 | } |
| 193 | 203 | } |
| @@ -349,13 +359,13 @@ | ||
| 349 | 359 | * @return string |
| 350 | 360 | */ |
| 351 | 361 | function give_parse_plugin_update_notice( $content, $new_version ) { |
| 352 | 362 | $version_parts = explode( '.', $new_version ); |
| 353 | - $check_for_notices = array( | |
| 363 | + $check_for_notices = [ | |
| 354 | 364 | $version_parts[0] . '.0', |
| 355 | 365 | $version_parts[0] . '.0.0', |
| 356 | 366 | $version_parts[0] . '.' . $version_parts[1] . '.' . '0', |
| 357 | - ); | |
| 367 | + ]; | |
| 358 | 368 | |
| 359 | 369 | // Regex to extract Upgrade notice from the readme.txt file. |
| 360 | 370 | $notice_regexp = '~==\s*Upgrade Notice\s*==\s*=\s*(.*)\s*=(.*)(=\s*' . preg_quote( $new_version ) . '\s*=|$)~Uis'; |
| 361 | 371 | |
| @@ -433,9 +443,9 @@ | ||
| 433 | 443 | * |
| 434 | 444 | * @return mixed|array list of recently activated add-on |
| 435 | 445 | */ |
| 436 | 446 | function give_get_recently_activated_addons() { |
| 437 | - return get_option( 'give_recently_activated_addons', array() ); | |
| 447 | + return get_option( 'give_recently_activated_addons', [] ); | |
| 438 | 448 | } |
| 439 | 449 | |
| 440 | 450 | /** |
| 441 | 451 | * Renders the Give Deactivation Survey Form. |
| @@ -443,10 +453,14 @@ | ||
| 443 | 453 | * |
| 444 | 454 | * @since 2.2 |
| 445 | 455 | */ |
| 446 | 456 | function give_deactivation_popup() { |
| 457 | + // Bailout. | |
| 458 | + if ( ! current_user_can( 'delete_plugins' ) ) { | |
| 459 | + give_die(); | |
| 460 | + } | |
| 447 | 461 | |
| 448 | - $results = array(); | |
| 462 | + $results = []; | |
| 449 | 463 | |
| 450 | 464 | // Start output buffering. |
| 451 | 465 | ob_start(); |
| 452 | 466 | ?> |
| @@ -451,10 +465,10 @@ | ||
| 451 | 465 | ob_start(); |
| 452 | 466 | ?> |
| 453 | 467 | |
| 454 | 468 | <h2 id="deactivation-survey-title"> |
| 455 | - <img src="<?php echo esc_url( GIVE_PLUGIN_URL ) ?>/assets/dist/images/give-icon-full-circle.svg"> | |
| 456 | - <span><?php esc_html_e( 'Give Deactivation', 'give' ); ?></span> | |
| 469 | + <img src="<?php echo esc_url( GIVE_PLUGIN_URL ); ?>/assets/dist/images/give-icon-full-circle.svg"> | |
| 470 | + <span><?php esc_html_e( 'GiveWP Deactivation', 'give' ); ?></span> | |
| 457 | 471 | </h2> |
| 458 | 472 | <form class="deactivation-survey-form" method="POST"> |
| 459 | 473 | <p><?php esc_html_e( 'If you have a moment, please let us know why you are deactivating Give. All submissions are anonymous and we only use this feedback to improve this plugin.', 'give' ); ?></p> |
| 460 | 474 | |
| @@ -497,18 +511,19 @@ | ||
| 497 | 511 | <?php esc_html_e( 'The plugin broke my site', 'give' ); ?> |
| 498 | 512 | </label> |
| 499 | 513 | |
| 500 | 514 | <div class="give-survey-extra-field"> |
| 501 | - <p><?php | |
| 515 | + <p> | |
| 516 | + <?php | |
| 502 | 517 | printf( |
| 503 | 518 | '%1$s %2$s %3$s', |
| 504 | 519 | __( "We're sorry to hear that, check", 'give' ), |
| 505 | - '<a href="https://wordpress.org/support/plugin/give">Give Support</a>.', | |
| 520 | + '<a href="https://wordpress.org/support/plugin/give">GiveWP Support</a>.', | |
| 506 | 521 | __( 'Can you describe the issue?', 'give' ) |
| 507 | 522 | ); |
| 508 | - ?> | |
| 523 | + ?> | |
| 509 | 524 | </p> |
| 510 | - <textarea disabled name="user-reason" class="widefat" rows="6"></textarea disabled> | |
| 525 | + <textarea disabled name="user-reason" class="widefat" rows="6"></textarea> | |
| 511 | 526 | </div> |
| 512 | 527 | </div> |
| 513 | 528 | |
| 514 | 529 | <div> |
| @@ -517,18 +532,19 @@ | ||
| 517 | 532 | <?php esc_html_e( 'The plugin suddenly stopped working', 'give' ); ?> |
| 518 | 533 | </label> |
| 519 | 534 | |
| 520 | 535 | <div class="give-survey-extra-field"> |
| 521 | - <p><?php | |
| 536 | + <p> | |
| 537 | + <?php | |
| 522 | 538 | printf( |
| 523 | 539 | '%1$s %2$s %3$s', |
| 524 | 540 | __( "We're sorry to hear that, check", 'give' ), |
| 525 | - '<a href="https://wordpress.org/support/plugin/give">Give Support</a>.', | |
| 541 | + '<a href="https://wordpress.org/support/plugin/give">GiveWP Support</a>.', | |
| 526 | 542 | __( 'Can you describe the issue?', 'give' ) |
| 527 | 543 | ); |
| 528 | - ?> | |
| 544 | + ?> | |
| 529 | 545 | </p> |
| 530 | - <textarea disabled name="user-reason" class="widefat" rows="6"></textarea disabled> | |
| 546 | + <textarea disabled name="user-reason" class="widefat" rows="6"></textarea> | |
| 531 | 547 | </div> |
| 532 | 548 | </div> |
| 533 | 549 | |
| 534 | 550 | <div> |
| @@ -538,9 +554,9 @@ | ||
| 538 | 554 | </label> |
| 539 | 555 | |
| 540 | 556 | <div class="give-survey-extra-field"> |
| 541 | 557 | <p><?php esc_html_e( "Please describe why you're deactivating Give", 'give' ); ?></p> |
| 542 | - <textarea disabled name="user-reason" class="widefat" rows="6"></textarea disabled> | |
| 558 | + <textarea disabled name="user-reason" class="widefat" rows="6"></textarea> | |
| 543 | 559 | </div> |
| 544 | 560 | </div> |
| 545 | 561 | |
| 546 | 562 | <div id="survey-and-delete-data"> |
| @@ -546,21 +562,15 @@ | ||
| 546 | 562 | <div id="survey-and-delete-data"> |
| 547 | 563 | <p> |
| 548 | 564 | <label> |
| 549 | 565 | <input type="checkbox" name="confirm_reset_store" value="1"> |
| 550 | - <?php esc_html_e( 'Would you like to delete all Give data?', 'give' ); ?> | |
| 566 | + <?php esc_html_e( 'Would you like to delete all GiveWP data?', 'give' ); ?> | |
| 551 | 567 | </label> |
| 552 | 568 | <section class="give-field-description"> |
| 553 | - <?php esc_html_e( 'By default the custom roles, Give options, and database entries are not deleted when you deactivate Give. If you are deleting Give completely from your website and want those items removed as well check this option. Note: This will permanently delete all Give data from your database.', 'give' ); ?> | |
| 569 | + <?php esc_html_e( 'By default the custom roles, GiveWP options, and database entries are not deleted when you deactivate Give. If you are deleting GiveWP completely from your website and want those items removed as well check this option. Note: This will permanently delete all GiveWP data from your database.', 'give' ); ?> | |
| 554 | 570 | </section> |
| 555 | 571 | </p> |
| 556 | 572 | </div> |
| 557 | - <?php | |
| 558 | - $current_user = wp_get_current_user(); | |
| 559 | - $current_user_email = $current_user->user_email; | |
| 560 | - ?> | |
| 561 | - <input type="hidden" name="current-user-email" value="<?php echo $current_user_email; ?>"> | |
| 562 | - <input type="hidden" name="current-site-url" value="<?php echo esc_url( get_bloginfo( 'url' ) ); ?>"> | |
| 563 | 573 | <input type="hidden" name="give-export-class" value="Give_Tools_Reset_Stats"> |
| 564 | 574 | <?php wp_nonce_field( 'give_ajax_export', 'give_ajax_export' ); ?> |
| 565 | 575 | </form> |
| 566 | 576 | |
| @@ -566,13 +576,10 @@ | ||
| 566 | 576 | |
| 567 | 577 | <?php |
| 568 | 578 | |
| 569 | 579 | // Echo content (deactivation form) from the output buffer. |
| 570 | - $output = ob_get_contents(); | |
| 580 | + $output = ob_get_clean(); | |
| 571 | 581 | |
| 572 | - // Erase and stop output buffer. | |
| 573 | - ob_end_clean(); | |
| 574 | - | |
| 575 | 582 | $results['html'] = $output; |
| 576 | 583 | |
| 577 | 584 | wp_send_json( $results ); |
| 578 | 585 | } |
| @@ -588,9 +595,8 @@ | ||
| 588 | 595 | function give_deactivation_form_submit() { |
| 589 | 596 | |
| 590 | 597 | if ( ! check_ajax_referer( 'deactivation_survey_nonce', 'nonce', false ) ) { |
| 591 | 598 | wp_send_json_error(); |
| 592 | - wp_die(); | |
| 593 | 599 | } |
| 594 | 600 | |
| 595 | 601 | $form_data = give_clean( wp_parse_args( $_POST['form-data'] ) ); |
| 596 | 602 | |
| @@ -599,53 +605,28 @@ | ||
| 599 | 605 | |
| 600 | 606 | // Get the reason if any radio button has an optional text field. |
| 601 | 607 | $user_reason = isset( $form_data['user-reason'] ) ? $form_data['user-reason'] : ''; |
| 602 | 608 | |
| 603 | - // Get the email of the user who deactivated the plugin. | |
| 604 | - $user_email = isset( $form_data['current-user-email'] ) ? $form_data['current-user-email'] : ''; | |
| 605 | - | |
| 606 | - // Get the URL of the website on which Give plugin is being deactivated. | |
| 607 | - $site_url = isset( $form_data['current-site-url'] ) ? $form_data['current-site-url'] : ''; | |
| 608 | - | |
| 609 | 609 | // Get the value of the checkbox for deleting Give's data. |
| 610 | 610 | $delete_data = isset( $form_data['confirm_reset_store'] ) ? $form_data['confirm_reset_store'] : ''; |
| 611 | 611 | |
| 612 | - /** | |
| 613 | - * Make a POST request to the endpoint to send the survey data. | |
| 614 | - */ | |
| 615 | - $response = wp_remote_post( | |
| 616 | - 'http://survey.givewp.com/wp-json/give/v2/survey/', | |
| 617 | - array( | |
| 618 | - 'body' => array( | |
| 619 | - 'radio_value' => $radio_value, | |
| 620 | - 'user_reason' => $user_reason, | |
| 621 | - 'current_user_email' => $user_email, | |
| 622 | - 'site_url' => $site_url, | |
| 623 | - ), | |
| 624 | - ) | |
| 625 | - ); | |
| 612 | + // Send data to survey server. It doesn't matter if it fails. | |
| 613 | + wp_remote_post( | |
| 614 | + 'http://survey.givewp.com/wp-json/give/v2/survey/', | |
| 615 | + [ | |
| 616 | + 'body' => [ | |
| 617 | + 'radio_value' => $radio_value, | |
| 618 | + 'user_reason' => $user_reason, | |
| 619 | + ], | |
| 620 | + 'timeout' => 0.1 | |
| 621 | + ] | |
| 622 | + ); | |
| 626 | 623 | |
| 627 | - // Check if the data is sent and stored correctly. | |
| 628 | - $response = wp_remote_retrieve_body( $response ); | |
| 624 | + if ( '1' === $delete_data ) { | |
| 625 | + give_update_option( 'uninstall_on_delete', 'enabled' ); | |
| 626 | + wp_send_json_success( [ 'delete_data' => true ] ); | |
| 627 | + } | |
| 629 | 628 | |
| 630 | - if ( 'true' === $response ) { | |
| 631 | - if ( '1' === $delete_data ) { | |
| 632 | - wp_send_json_success( | |
| 633 | - array( | |
| 634 | - 'delete_data' => true, | |
| 635 | - ) | |
| 636 | - ); | |
| 637 | - } else { | |
| 638 | - wp_send_json_success( | |
| 639 | - array( | |
| 640 | - 'delete_data' => false, | |
| 641 | - ) | |
| 642 | - ); | |
| 643 | - } | |
| 644 | - } else { | |
| 645 | - wp_send_json_error(); | |
| 646 | - } | |
| 647 | - | |
| 648 | - wp_die(); | |
| 629 | + wp_send_json_success( [ 'delete_data' => false ] ); | |
| 649 | 630 | } |
| 650 | 631 | |
| 651 | 632 | add_action( 'wp_ajax_deactivation_form_submit', 'give_deactivation_form_submit' ); |