| @@ -7,32 +7,17 @@ | ||
| 7 | 7 | * @since 4.04.04 |
| 8 | 8 | */ |
| 9 | 9 | class FrmInstallPlugin { |
| 10 | 10 | |
| 11 | - /** | |
| 12 | - * Format: folder/filename.php. | |
| 13 | - * | |
| 14 | - * @var string | |
| 15 | - */ | |
| 16 | - protected $plugin_file; | |
| 17 | - | |
| 18 | - /** | |
| 19 | - * @var string | |
| 20 | - */ | |
| 11 | + protected $plugin_file; // format: folder/filename.php | |
| 21 | 12 | protected $plugin_slug; |
| 22 | 13 | |
| 23 | - /** | |
| 24 | - * @param array $atts | |
| 25 | - */ | |
| 26 | 14 | public function __construct( $atts ) { |
| 27 | - $this->plugin_file = $atts['plugin_file']; | |
| 15 | + $this->plugin_file = $atts['plugin_file']; | |
| 28 | 16 | list( $slug, $file ) = explode( '/', $this->plugin_file ); |
| 29 | - $this->plugin_slug = $slug; | |
| 17 | + $this->plugin_slug = $slug; | |
| 30 | 18 | } |
| 31 | 19 | |
| 32 | - /** | |
| 33 | - * @return string | |
| 34 | - */ | |
| 35 | 20 | public function get_activate_link() { |
| 36 | 21 | if ( $this->is_installed() && $this->is_active() ) { |
| 37 | 22 | return ''; |
| 38 | 23 | } |
| @@ -44,135 +29,20 @@ | ||
| 44 | 29 | } |
| 45 | 30 | return $url; |
| 46 | 31 | } |
| 47 | 32 | |
| 48 | - /** | |
| 49 | - * @return bool | |
| 50 | - */ | |
| 51 | 33 | public function is_installed() { |
| 52 | 34 | return is_dir( WP_PLUGIN_DIR . '/' . $this->plugin_slug ); |
| 53 | 35 | } |
| 54 | 36 | |
| 55 | - /** | |
| 56 | - * @return bool | |
| 57 | - */ | |
| 58 | 37 | public function is_active() { |
| 59 | 38 | return is_plugin_active( $this->plugin_file ); |
| 60 | 39 | } |
| 61 | 40 | |
| 62 | - /** | |
| 63 | - * @return string | |
| 64 | - */ | |
| 65 | 41 | protected function install_url() { |
| 66 | 42 | return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $this->plugin_slug ), 'install-plugin_' . $this->plugin_slug ); |
| 67 | 43 | } |
| 68 | 44 | |
| 69 | - /** | |
| 70 | - * @return string | |
| 71 | - */ | |
| 72 | 45 | protected function activate_url() { |
| 73 | 46 | return wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $this->plugin_file ), 'activate-plugin_' . $this->plugin_file ); |
| 74 | - } | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * Handles the AJAX request to install a plugin. | |
| 78 | - * | |
| 79 | - * @since 6.9 | |
| 80 | - * | |
| 81 | - * @return void | |
| 82 | - */ | |
| 83 | - public static function ajax_install_plugin() { | |
| 84 | - // Check permission and nonce. | |
| 85 | - FrmAppHelper::permission_check( 'install_plugins' ); | |
| 86 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 87 | - | |
| 88 | - // Get posted data. | |
| 89 | - $plugin_slug = FrmAppHelper::get_post_param( 'plugin', '', 'sanitize_text_field' ); | |
| 90 | - | |
| 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'; | |
| 97 | - | |
| 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 | - ); | |
| 108 | - | |
| 109 | - if ( is_wp_error( $api ) ) { | |
| 110 | - wp_send_json_error( $api->get_error_message() ); | |
| 111 | - } | |
| 112 | - | |
| 113 | - if ( ! FrmAddonsController::url_is_allowed( $api->versions['trunk'] ) ) { | |
| 114 | - wp_send_json_error( 'This download is not allowed' ); | |
| 115 | - } | |
| 116 | - | |
| 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 | - | |
| 131 | - if ( is_wp_error( $activate ) ) { | |
| 132 | - wp_send_json_error( $activate->get_error_message() ); | |
| 133 | - } | |
| 134 | - | |
| 135 | - if ( 'wp-mail-smtp' === $plugin_slug ) { | |
| 136 | - update_option( 'wp_mail_smtp_activation_prevent_redirect', true ); | |
| 137 | - } | |
| 138 | - | |
| 139 | - // Send a success response. | |
| 140 | - wp_send_json_success( __( 'Plugin installed and activated successfully.', 'formidable' ) ); | |
| 141 | - } | |
| 142 | - | |
| 143 | - /** | |
| 144 | - * Checks plugin activation status via AJAX. | |
| 145 | - * | |
| 146 | - * @since 6.9 | |
| 147 | - * | |
| 148 | - * @return void | |
| 149 | - */ | |
| 150 | - public static function ajax_check_plugin_activation() { | |
| 151 | - // Check permission and nonce. | |
| 152 | - FrmAppHelper::permission_check( 'install_plugins' ); | |
| 153 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 154 | - | |
| 155 | - // Retrieve plugin identifier. | |
| 156 | - $plugin_path = FrmAppHelper::get_post_param( 'plugin_path', '', 'sanitize_text_field' ); | |
| 157 | - | |
| 158 | - // Respond based on plugin status. | |
| 159 | - if ( is_plugin_active( $plugin_path ) ) { | |
| 160 | - wp_send_json_success(); | |
| 161 | - } else { | |
| 162 | - wp_send_json_error(); | |
| 163 | - } | |
| 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 | 47 | } |
| 178 | 48 | } |