| @@ -19,8 +19,11 @@ | ||
| 19 | 19 | * @var string |
| 20 | 20 | */ |
| 21 | 21 | protected $plugin_slug; |
| 22 | 22 | |
| 23 | + /** | |
| 24 | + * @param array $atts | |
| 25 | + */ | |
| 23 | 26 | public function __construct( $atts ) { |
| 24 | 27 | $this->plugin_file = $atts['plugin_file']; |
| 25 | 28 | list( $slug, $file ) = explode( '/', $this->plugin_file ); |
| 26 | 29 | $this->plugin_slug = $slug; |
| @@ -25,19 +28,16 @@ | ||
| 25 | 28 | list( $slug, $file ) = explode( '/', $this->plugin_file ); |
| 26 | 29 | $this->plugin_slug = $slug; |
| 27 | 30 | } |
| 28 | 31 | |
| 32 | + /** | |
| 33 | + * @return string | |
| 34 | + */ | |
| 29 | 35 | public function get_activate_link() { |
| 30 | 36 | if ( $this->is_installed() && $this->is_active() ) { |
| 31 | 37 | return ''; |
| 32 | 38 | } |
| 33 | - | |
| 34 | - if ( $this->is_installed() ) { | |
| 35 | - $url = $this->activate_url(); | |
| 36 | - } else { | |
| 37 | - $url = $this->install_url(); | |
| 38 | - } | |
| 39 | - return $url; | |
| 39 | + return $this->is_installed() ? $this->activate_url() : $this->install_url(); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @return bool |
| @@ -98,11 +98,13 @@ | ||
| 98 | 98 | 'sections' => false, |
| 99 | 99 | ), |
| 100 | 100 | ) |
| 101 | 101 | ); |
| 102 | + | |
| 102 | 103 | if ( is_wp_error( $api ) ) { |
| 103 | 104 | wp_send_json_error( $api->get_error_message() ); |
| 104 | 105 | } |
| 106 | + | |
| 105 | 107 | if ( ! FrmAddonsController::url_is_allowed( $api->versions['trunk'] ) ) { |
| 106 | 108 | wp_send_json_error( 'This download is not allowed' ); |
| 107 | 109 | } |
| 108 | 110 | |
| @@ -110,8 +112,9 @@ | ||
| 110 | 112 | $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() ); |
| 111 | 113 | |
| 112 | 114 | // Install the plugin. |
| 113 | 115 | $result = $upgrader->install( $api->versions['trunk'] ); |
| 116 | + | |
| 114 | 117 | if ( is_wp_error( $result ) ) { |
| 115 | 118 | wp_send_json_error( $result->get_error_message() ); |
| 116 | 119 | } |
| 117 | 120 | |
| @@ -151,18 +154,6 @@ | ||
| 151 | 154 | wp_send_json_success(); |
| 152 | 155 | } else { |
| 153 | 156 | wp_send_json_error(); |
| 154 | 157 | } |
| 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 ] ); | |
| 167 | 158 | } |
| 168 | 159 | } |