get_col($wpdb->prepare("SELECT option_name FROM %i WHERE option_name LIKE %s", $wpdb->options, $wpdb->esc_like('ssp_') . '%')); foreach ((array) $old as $name) { $new = 'mpseo_' . substr((string) $name, 4); if (get_option($new, null) === null) { $value = get_option($name); $autoload = $wpdb->get_var($wpdb->prepare("SELECT autoload FROM %i WHERE option_name=%s", $wpdb->options, $name)); add_option($new, $value, '', in_array((string) $autoload, ['no', 'off', 'auto-off'], true) ? false : true); } delete_option($name); } // Old transients are only caches: removed. $wpdb->query($wpdb->prepare("DELETE FROM %i WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->options, $wpdb->esc_like('_transient_ssp_') . '%', $wpdb->esc_like('_transient_timeout_ssp_') . '%')); foreach ([$wpdb->postmeta, $wpdb->termmeta] as $table) { $wpdb->query($wpdb->prepare("UPDATE %i SET meta_key=REPLACE(meta_key,%s,%s) WHERE meta_key LIKE %s", $table, '_ssp_', '_mpseo_', $wpdb->esc_like('_ssp_') . '%')); $wpdb->query($wpdb->prepare("UPDATE %i SET meta_key=REPLACE(meta_key,%s,%s) WHERE meta_key LIKE %s", $table, 'ssp_', 'mpseo_', $wpdb->esc_like('ssp_') . '%')); } $wpdb->query($wpdb->prepare("UPDATE %i SET meta_key=REPLACE(meta_key,%s,%s) WHERE meta_key LIKE %s", $wpdb->usermeta, 'ssp_', 'mpseo_', $wpdb->esc_like('ssp_') . '%')); foreach (['redirects', '404', 'revisions', 'link_index', 'links'] as $t) { $from = $wpdb->prefix . 'ssp_' . $t; $to = $wpdb->prefix . 'mpseo_' . $t; $has_from = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($from))); $has_to = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($to))); if ($has_from && !$has_to) { $wpdb->suppress_errors(true); $ok = $wpdb->query($wpdb->prepare('ALTER TABLE %i RENAME TO %i', $from, $to)); $wpdb->suppress_errors(false); if ($ok === false) $copy[$from] = $to; } } // Database engines without table renaming: the tables are created again and the rows copied (old tables are kept). if (!empty($copy)) { foreach (['MPSEO_Redirects', 'MPSEO_Revisions', 'MPSEO_V49_Scalability'] as $class) { if (class_exists($class) && method_exists($class, 'install')) $class::install(); } foreach ($copy as $from => $to) { $has_to = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($to))); if ($has_to && !(int) $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM %i', $to))) $wpdb->query($wpdb->prepare('INSERT INTO %i SELECT * FROM %i', $to, $from)); } } // phpcs:enable // Old scheduled events and capabilities. foreach (['ssp_daily_health_event', 'ssp_speed_db_weekly', 'ssp_speed_hourly', 'ssp_speed_preload', 'ssp_speed_theme_scan', 'ssp_v52_daily', 'ssp_v53_daily'] as $hook) wp_clear_scheduled_hook($hook); if (function_exists('wp_roles')) { foreach (wp_roles()->role_objects as $role) { foreach (['ssp_edit_seo', 'ssp_manage_seo', 'ssp_manage_redirects', 'ssp_run_audits', 'ssp_manage_settings', 'ssp_use_ai'] as $cap) { if ($role->has_cap($cap)) { $role->add_cap('mpseo_' . substr($cap, 4)); $role->remove_cap($cap); } } } } delete_option('mpseo_access_caps_version'); update_option('mpseo_prefix_migrated', '1', true); }