| @@ -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,16 +25,19 @@ | ||
| 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 | } |
| 39 | - return $this->is_installed() ? $this->activate_url() : $this->install_url(); | |
| 33 | + | |
| 34 | + if ( $this->is_installed() ) { | |
| 35 | + $url = $this->activate_url(); | |
| 36 | + } else { | |
| 37 | + $url = $this->install_url(); | |
| 38 | + } | |
| 39 | + return $url; | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @return bool |
| @@ -81,48 +81,40 @@ | ||
| 81 | 81 | |
| 82 | 82 | // Get posted data. |
| 83 | 83 | $plugin_slug = FrmAppHelper::get_post_param( 'plugin', '', 'sanitize_text_field' ); |
| 84 | 84 | |
| 85 | - if ( ! empty( get_plugins()[ $plugin_slug ] ) ) { | |
| 86 | - $activate = activate_plugin( $plugin_slug ); | |
| 87 | - } else { | |
| 88 | - // Include necessary files for plugin installation. | |
| 89 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 90 | - 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'; | |
| 91 | 88 | |
| 92 | - // Get the plugin information. | |
| 93 | - $api = plugins_api( | |
| 94 | - 'plugin_information', | |
| 95 | - array( | |
| 96 | - 'slug' => $plugin_slug, | |
| 97 | - 'fields' => array( | |
| 98 | - 'sections' => false, | |
| 99 | - ), | |
| 100 | - ) | |
| 101 | - ); | |
| 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 | + } | |
| 102 | 105 | |
| 103 | - if ( is_wp_error( $api ) ) { | |
| 104 | - wp_send_json_error( $api->get_error_message() ); | |
| 105 | - } | |
| 106 | + // Set up the Plugin Upgrader. | |
| 107 | + $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() ); | |
| 106 | 108 | |
| 107 | - if ( ! FrmAddonsController::url_is_allowed( $api->versions['trunk'] ) ) { | |
| 108 | - wp_send_json_error( 'This download is not allowed' ); | |
| 109 | - } | |
| 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 | + } | |
| 110 | 114 | |
| 111 | - // Set up the Plugin Upgrader. | |
| 112 | - $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() ); | |
| 113 | - | |
| 114 | - // Install the plugin. | |
| 115 | - $result = $upgrader->install( $api->versions['trunk'] ); | |
| 116 | - | |
| 117 | - if ( is_wp_error( $result ) ) { | |
| 118 | - wp_send_json_error( $result->get_error_message() ); | |
| 119 | - } | |
| 120 | - | |
| 121 | - // Activate the plugin. | |
| 122 | - $activate = activate_plugin( $upgrader->plugin_info() ); | |
| 123 | - }//end if | |
| 124 | - | |
| 115 | + // Activate the plugin. | |
| 116 | + $activate = activate_plugin( $upgrader->plugin_info() ); | |
| 125 | 117 | if ( is_wp_error( $activate ) ) { |
| 126 | 118 | wp_send_json_error( $activate->get_error_message() ); |
| 127 | 119 | } |
| 128 | 120 | |