| @@ -19,11 +19,8 @@ | ||
| 19 | 19 | * @var string |
| 20 | 20 | */ |
| 21 | 21 | protected $plugin_slug; |
| 22 | 22 | |
| 23 | - /** | |
| 24 | - * @param array $atts | |
| 25 | - */ | |
| 26 | 23 | public function __construct( $atts ) { |
| 27 | 24 | $this->plugin_file = $atts['plugin_file']; |
| 28 | 25 | list( $slug, $file ) = explode( '/', $this->plugin_file ); |
| 29 | 26 | $this->plugin_slug = $slug; |
| @@ -28,11 +25,8 @@ | ||
| 28 | 25 | list( $slug, $file ) = explode( '/', $this->plugin_file ); |
| 29 | 26 | $this->plugin_slug = $slug; |
| 30 | 27 | } |
| 31 | 28 | |
| 32 | - /** | |
| 33 | - * @return string | |
| 34 | - */ | |
| 35 | 29 | public function get_activate_link() { |
| 36 | 30 | if ( $this->is_installed() && $this->is_active() ) { |
| 37 | 31 | return ''; |
| 38 | 32 | } |
| @@ -87,48 +81,40 @@ | ||
| 87 | 81 | |
| 88 | 82 | // Get posted data. |
| 89 | 83 | $plugin_slug = FrmAppHelper::get_post_param( 'plugin', '', 'sanitize_text_field' ); |
| 90 | 84 | |
| 91 | - if ( ! empty( get_plugins()[ $plugin_slug ] ) ) { | |
| 92 | - $activate = activate_plugin( $plugin_slug ); | |
| 93 | - } else { | |
| 94 | - // Include necessary files for plugin installation. | |
| 95 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 96 | - require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; | |
| 85 | + // Include necessary files for plugin installation. | |
| 86 | + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 87 | + require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; | |
| 97 | 88 | |
| 98 | - // Get the plugin information. | |
| 99 | - $api = plugins_api( | |
| 100 | - 'plugin_information', | |
| 101 | - array( | |
| 102 | - 'slug' => $plugin_slug, | |
| 103 | - 'fields' => array( | |
| 104 | - 'sections' => false, | |
| 105 | - ), | |
| 106 | - ) | |
| 107 | - ); | |
| 89 | + // Get the plugin information. | |
| 90 | + $api = plugins_api( | |
| 91 | + 'plugin_information', | |
| 92 | + array( | |
| 93 | + 'slug' => $plugin_slug, | |
| 94 | + 'fields' => array( | |
| 95 | + 'sections' => false, | |
| 96 | + ), | |
| 97 | + ) | |
| 98 | + ); | |
| 99 | + if ( is_wp_error( $api ) ) { | |
| 100 | + wp_send_json_error( $api->get_error_message() ); | |
| 101 | + } | |
| 102 | + if ( ! FrmAddonsController::url_is_allowed( $api->versions['trunk'] ) ) { | |
| 103 | + wp_send_json_error( 'This download is not allowed' ); | |
| 104 | + } | |
| 108 | 105 | |
| 109 | - if ( is_wp_error( $api ) ) { | |
| 110 | - wp_send_json_error( $api->get_error_message() ); | |
| 111 | - } | |
| 106 | + // Set up the Plugin Upgrader. | |
| 107 | + $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() ); | |
| 112 | 108 | |
| 113 | - if ( ! FrmAddonsController::url_is_allowed( $api->versions['trunk'] ) ) { | |
| 114 | - wp_send_json_error( 'This download is not allowed' ); | |
| 115 | - } | |
| 109 | + // Install the plugin. | |
| 110 | + $result = $upgrader->install( $api->versions['trunk'] ); | |
| 111 | + if ( is_wp_error( $result ) ) { | |
| 112 | + wp_send_json_error( $result->get_error_message() ); | |
| 113 | + } | |
| 116 | 114 | |
| 117 | - // Set up the Plugin Upgrader. | |
| 118 | - $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() ); | |
| 119 | - | |
| 120 | - // Install the plugin. | |
| 121 | - $result = $upgrader->install( $api->versions['trunk'] ); | |
| 122 | - | |
| 123 | - if ( is_wp_error( $result ) ) { | |
| 124 | - wp_send_json_error( $result->get_error_message() ); | |
| 125 | - } | |
| 126 | - | |
| 127 | - // Activate the plugin. | |
| 128 | - $activate = activate_plugin( $upgrader->plugin_info() ); | |
| 129 | - }//end if | |
| 130 | - | |
| 115 | + // Activate the plugin. | |
| 116 | + $activate = activate_plugin( $upgrader->plugin_info() ); | |
| 131 | 117 | if ( is_wp_error( $activate ) ) { |
| 132 | 118 | wp_send_json_error( $activate->get_error_message() ); |
| 133 | 119 | } |
| 134 | 120 | |
| @@ -160,19 +146,6 @@ | ||
| 160 | 146 | wp_send_json_success(); |
| 161 | 147 | } else { |
| 162 | 148 | wp_send_json_error(); |
| 163 | 149 | } |
| 164 | - } | |
| 165 | - | |
| 166 | - /** | |
| 167 | - * Check if a plugin is installed. | |
| 168 | - * | |
| 169 | - * @since 6.16 | |
| 170 | - * | |
| 171 | - * @param string $plugin_file | |
| 172 | - * | |
| 173 | - * @return bool | |
| 174 | - */ | |
| 175 | - private static function is_plugin_installed( $plugin_file ) { | |
| 176 | - return isset( get_plugins()[ $plugin_file ] ); | |
| 177 | 150 | } |
| 178 | 151 | } |