| @@ -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 |
| @@ -98,13 +98,11 @@ | ||
| 98 | 98 | 'sections' => false, |
| 99 | 99 | ), |
| 100 | 100 | ) |
| 101 | 101 | ); |
| 102 | - | |
| 103 | 102 | if ( is_wp_error( $api ) ) { |
| 104 | 103 | wp_send_json_error( $api->get_error_message() ); |
| 105 | 104 | } |
| 106 | - | |
| 107 | 105 | if ( ! FrmAddonsController::url_is_allowed( $api->versions['trunk'] ) ) { |
| 108 | 106 | wp_send_json_error( 'This download is not allowed' ); |
| 109 | 107 | } |
| 110 | 108 | |
| @@ -112,9 +110,8 @@ | ||
| 112 | 110 | $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() ); |
| 113 | 111 | |
| 114 | 112 | // Install the plugin. |
| 115 | 113 | $result = $upgrader->install( $api->versions['trunk'] ); |
| 116 | - | |
| 117 | 114 | if ( is_wp_error( $result ) ) { |
| 118 | 115 | wp_send_json_error( $result->get_error_message() ); |
| 119 | 116 | } |
| 120 | 117 | |
| @@ -154,6 +151,18 @@ | ||
| 154 | 151 | wp_send_json_success(); |
| 155 | 152 | } else { |
| 156 | 153 | wp_send_json_error(); |
| 157 | 154 | } |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Check if a plugin is installed. | |
| 159 | + * | |
| 160 | + * @since 6.16 | |
| 161 | + * | |
| 162 | + * @param string $plugin_file | |
| 163 | + * @return bool | |
| 164 | + */ | |
| 165 | + private static function is_plugin_installed( $plugin_file ) { | |
| 166 | + return isset( get_plugins()[ $plugin_file ] ); | |
| 158 | 167 | } |
| 159 | 168 | } |