/** * Process the request that will start the execution of the plugin * reinstallation, it will check if the plugins submitted are (in fact) * installed in the system, then check if they are free download from the * WordPress market place, and finally download and install them. * * @param boolean $process_form Whether a form was submitted or not. * @return void */ function sucuriscan_posthack_reinstall_plugins($process_form = false) { if ($process_form && isset($_POST['sucuriscan_reset_plugins'])) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // For plugins_api. if ($plugin_list = SucuriScanRequest::post('plugin_path', '_array')) { // Create an instance of the FileInfo interface. $file_info = new SucuriScanFileInfo(); $file_info->ignore_files = false; $file_info->ignore_directories = false; $file_info->skip_directories = false; // Get (possible) cached information from the installed plugins. $all_plugins = SucuriScanAPI::getPlugins(); // Loop through all the installed plugins. foreach ($_POST['plugin_path'] as $plugin_path) { if (array_key_exists($plugin_path, $all_plugins)) { $plugin_data = $all_plugins[$plugin_path]; // Check if the plugin can be downloaded from the free market. if ($plugin_data['IsFreePlugin'] === true) { $plugin_info = SucuriScanAPI::getRemotePluginData($plugin_data['RepositoryName']); if ($plugin_info) { // First, remove all files/sub-folders from the plugin's directory. if (substr_count($plugin_path, '/') >= 1) { $plugin_directory = dirname(WP_PLUGIN_DIR . '/' . $plugin_path); $file_info->remove_directory_tree($plugin_directory); } // Install a fresh copy of the plugin's files. $upgrader_skin = new Plugin_Installer_Skin(); $upgrader = new Plugin_Upgrader($upgrader_skin); $upgrader->install($plugin_info->download_link); SucuriScanEvent::report_notice_event('Plugin re-installed: ' . $plugin_path); } else { SucuriScanInterface::error('Connection with the WordPress plugin market failed.'); } } } } } else { SucuriScanInterface::error('You did not select a free plugin to reinstall.'); } } }