this->convertAndSanitize( $v ); } return $sanitized; default: return ''; } } /** * Starts an import. * * @since 4.0.0 * * @param string $plugin The slug of the plugin to import. * @param array $settings Which settings to import. * @return void */ public function startImport( $plugin, $settings ) { // First cancel any scans running that might interfere with our import. $this->cancelScans(); foreach ( $this->plugins as $pluginData ) { if ( $pluginData['slug'] === $plugin ) { $pluginData['class']->doImport( $settings ); return; } } } /** * Cancel scans that are currently running and could conflict with our migration. * * @since 4.1.4 * * @return void */ private function cancelScans() { // Figure out how to check if these addons are enabled and then get the action names that way. aioseo()->actionScheduler->unschedule( 'aioseo_video_sitemap_scan' ); aioseo()->actionScheduler->unschedule( 'aioseo_image_sitemap_scan' ); } /** * Checks if an import is currently running. * * @since 4.1.4 * * @return boolean True if an import is currently running. */ public function isImportRunning() { $importsRunning = aioseo()->core->cache->get( 'import_%_meta_%' ); return ! empty( $importsRunning ); } /** * Adds plugins to the import/export. * * @since 4.0.0 * * @param array $plugins The plugins to add. * @return void */ public function addPlugins( $plugins ) { $this->plugins = array_merge( $this->plugins, $plugins ); } /** * Get the plugins we allow importing from. * * @since 4.0.0 * * @return array */ public function plugins() { require_once ABSPATH . 'wp-admin/includes/plugin.php'; $plugins = []; $installedPlugins = array_keys( get_plugins() ); foreach ( $this->plugins as $importerPlugin ) { $data = [ 'slug' => $importerPlugin['slug'], 'name' => $importerPlugin['name'], 'version' => null, 'canImport' => false, 'basename' => $importerPlugin['basename'], 'installed' => false ]; if ( in_array( $importerPlugin['basename'], $installedPlugins, true ) ) { $pluginData = get_file_data( trailingslashit( WP_PLUGIN_DIR ) . $importerPlugin['basename'], [ 'name' => 'Plugin Name', 'version' => 'Version', ] ); $canImport = false; if ( version_compare( $importerPlugin['version'], $pluginData['version'], '<=' ) ) { $canImport = true; } $data['name'] = $pluginData['name']; $data['version'] = $pluginData['version']; $data['canImport'] = $canImport; $data['installed'] = true; } $plugins[] = $data; } return $plugins; } }