| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | use Automattic\Jetpack\Plugins_Installer; |
| 4 | 4 | |
| 5 | 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | - exit; | |
| 6 | + exit( 0 ); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Installs and activates the WooCommerce Services plugin. |
| @@ -41,10 +41,15 @@ | ||
| 41 | 41 | * Constructor |
| 42 | 42 | */ |
| 43 | 43 | public function __construct() { |
| 44 | 44 | add_action( 'jetpack_loaded', array( $this, 'on_jetpack_loaded' ) ); |
| 45 | - add_action( 'admin_init', array( $this, 'add_error_notice' ) ); | |
| 46 | - add_action( 'admin_init', array( $this, 'try_install' ) ); | |
| 45 | + if ( ! empty( $_GET['wc-services-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 46 | + add_action( 'admin_notices', array( $this, 'error_notice' ) ); | |
| 47 | + } | |
| 48 | + | |
| 49 | + if ( isset( $_GET['wc-services-action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 50 | + add_action( 'admin_init', array( $this, 'try_install' ) ); | |
| 51 | + } | |
| 47 | 52 | } |
| 48 | 53 | |
| 49 | 54 | /** |
| 50 | 55 | * Runs on Jetpack being ready to load its packages. |
| @@ -98,29 +103,22 @@ | ||
| 98 | 103 | } |
| 99 | 104 | |
| 100 | 105 | wp_safe_redirect( $redirect ); |
| 101 | 106 | |
| 102 | - exit; | |
| 107 | + exit( 0 ); | |
| 103 | 108 | } |
| 104 | 109 | |
| 105 | 110 | /** |
| 106 | - * Set up installation error admin notice. | |
| 107 | - */ | |
| 108 | - public function add_error_notice() { | |
| 109 | - if ( ! empty( $_GET['wc-services-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 110 | - add_action( 'admin_notices', array( $this, 'error_notice' ) ); | |
| 111 | - } | |
| 112 | - } | |
| 113 | - | |
| 114 | - /** | |
| 115 | 111 | * Notify the user that the installation of WooCommerce Services failed. |
| 116 | 112 | */ |
| 117 | 113 | public function error_notice() { |
| 118 | - ?> | |
| 119 | - <div class="notice notice-error is-dismissible"> | |
| 120 | - <p><?php esc_html_e( 'There was an error installing WooCommerce Services.', 'jetpack' ); ?></p> | |
| 121 | - </div> | |
| 122 | - <?php | |
| 114 | + wp_admin_notice( | |
| 115 | + esc_html__( 'There was an error installing WooCommerce Services.', 'jetpack' ), | |
| 116 | + array( | |
| 117 | + 'type' => 'error', | |
| 118 | + 'dismissible' => true, | |
| 119 | + ) | |
| 120 | + ); | |
| 123 | 121 | } |
| 124 | 122 | |
| 125 | 123 | /** |
| 126 | 124 | * Download and install the WooCommerce Services plugin. |