| 1 |
<?php |
| 2 |
/** |
| 3 |
* Upgrade routine for v4.2.0 — namespace prefix migration. |
| 4 |
* |
| 5 |
* Copies plugin option keys, user meta, term meta and post meta from the |
| 6 |
* legacy prefixes ("_wpadminify", "wp_adminify_", "jltwp_adminify_", etc.) to |
| 7 |
* the unique "pxlbsadminify_" prefix required for the WordPress.org plugin |
| 8 |
* review. Old keys are intentionally left in place for rollback safety. |
| 9 |
* |
| 10 |
* This file is included by PXLBSAdminify\Inc\Classes\Upgrade::run_updates(). |
| 11 |
* |
| 12 |
* @package Adminify |
| 13 |
*/ |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Run the one-time option/meta key migration. |
| 21 |
* |
| 22 |
* Idempotent: guarded by the "pxlbsadminify_keys_migrated" flag and by |
| 23 |
* per-key existence checks, so it is safe if included more than once. |
| 24 |
* |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
function pxlbsadminify_migrate_namespace_keys() { |
| 28 |
|
| 29 |
if ( get_option( 'pxlbsadminify_keys_migrated' ) ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$unset = '__pxlbsadminify_unset__'; // Sentinel — distinguishes "missing" from a stored empty value. |
| 34 |
|
| 35 |
/* |
| 36 |
* Option key map: legacy key => new key. |
| 37 |
* Framework-managed settings, flat options and notice flags. |
| 38 |
*/ |
| 39 |
$option_map = array( |
| 40 |
// Settings framework instances. |
| 41 |
'_wpadminify' => 'pxlbsadminify_settings', |
| 42 |
'_wpadminify_backup' => 'pxlbsadminify_settings_backup', |
| 43 |
'_wpadminify_custom_js_css' => 'pxlbsadminify_custom_js_css', |
| 44 |
'_wpadminify_redirect_urls' => 'pxlbsadminify_redirect_urls', |
| 45 |
'_wpadminify_server_info' => 'pxlbsadminify_server_info', |
| 46 |
'_wpadminify_menu_settings' => 'pxlbsadminify_menu_settings', |
| 47 |
'_wpadminify_dasboard_widgets' => 'pxlbsadminify_dasboard_widgets', |
| 48 |
'_wpadminify_quick_circle_menu' => 'pxlbsadminify_quick_circle_menu', |
| 49 |
'_wp_adminify_sidebar_settings' => 'pxlbsadminify_sidebar_settings', |
| 50 |
'_jltadminbar_settings' => 'pxlbsadminify_adminbar_settings', |
| 51 |
|
| 52 |
// Notice / conflict flags. |
| 53 |
'_wpadminify_plugin_conflict' => 'pxlbsadminify_plugin_conflict', |
| 54 |
'_wpadminify_plugin_update_info_notice' => 'pxlbsadminify_plugin_update_info_notice', |
| 55 |
'wpadminify_notice_discount_code' => 'pxlbsadminify_notice_discount_code', |
| 56 |
|
| 57 |
// Version tracker. |
| 58 |
'wp_adminify_version' => 'pxlbsadminify_version', |
| 59 |
|
| 60 |
// Addon coupon flags. |
| 61 |
'wp_adminify_addon__coupon' => 'pxlbsadminify_addon_coupon', |
| 62 |
'wp_adminify_addon__coupon_is_deleted' => 'pxlbsadminify_addon_coupon_is_deleted', |
| 63 |
'wp_adminify_addon__is_eligible_for_coupon' => 'pxlbsadminify_addon_is_eligible_for_coupon', |
| 64 |
|
| 65 |
// Misc plugin state. |
| 66 |
'jltwp_adminify_activation_time' => 'pxlbsadminify_activation_time', |
| 67 |
'jltwp_adminify_customizer_flush_url' => 'pxlbsadminify_customizer_flush_url', |
| 68 |
'jltwp_adminify_login' => 'pxlbsadminify_login', |
| 69 |
'jltwp_adminify_setup_wizard_ran' => 'pxlbsadminify_setup_wizard_ran', |
| 70 |
'jltwp_adminify_sheet_promo_data' => 'pxlbsadminify_sheet_promo_data', |
| 71 |
'jltwp_adminify_sheet_promo_data_hash' => 'pxlbsadminify_sheet_promo_data_hash', |
| 72 |
'jltwp_adminify_what_we_collect' => 'pxlbsadminify_what_we_collect', |
| 73 |
'adminify_extra' => 'pxlbsadminify_extra', |
| 74 |
'adminify-notices' => 'pxlbsadminify_notices', |
| 75 |
'adminify-hidden-notices' => 'pxlbsadminify_hidden_notices', |
| 76 |
); |
| 77 |
|
| 78 |
foreach ( $option_map as $old_key => $new_key ) { |
| 79 |
// Skip if the new key already holds a value. |
| 80 |
if ( $unset !== get_option( $new_key, $unset ) ) { |
| 81 |
continue; |
| 82 |
} |
| 83 |
$value = get_option( $old_key, $unset ); |
| 84 |
if ( $unset !== $value ) { |
| 85 |
update_option( $new_key, $value ); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
// Multisite-wide option. |
| 90 |
if ( is_multisite() ) { |
| 91 |
if ( $unset === get_site_option( 'pxlbsadminify_multisite_exclude', $unset ) ) { |
| 92 |
$ms_value = get_site_option( 'wp_adminify_multisite_exclude', $unset ); |
| 93 |
if ( $unset !== $ms_value ) { |
| 94 |
update_site_option( 'pxlbsadminify_multisite_exclude', $ms_value ); |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
global $wpdb; |
| 100 |
|
| 101 |
// User meta: _wpadminify_preferences => pxlbsadminify_preferences (admin-bar collapse state). |
| 102 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time key migration; not cacheable. |
| 103 |
$wpdb->query( |
| 104 |
"INSERT INTO {$wpdb->usermeta} (user_id, meta_key, meta_value) |
| 105 |
SELECT um.user_id, 'pxlbsadminify_preferences', um.meta_value |
| 106 |
FROM {$wpdb->usermeta} um |
| 107 |
WHERE um.meta_key = '_wpadminify_preferences' |
| 108 |
AND NOT EXISTS ( |
| 109 |
SELECT 1 FROM {$wpdb->usermeta} um2 |
| 110 |
WHERE um2.user_id = um.user_id AND um2.meta_key = 'pxlbsadminify_preferences' |
| 111 |
)" |
| 112 |
); |
| 113 |
|
| 114 |
// Term meta: _wp_adminify_fodler_color => pxlbsadminify_fodler_color (Folders module). |
| 115 |
if ( ! empty( $wpdb->termmeta ) ) { |
| 116 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time key migration; not cacheable. |
| 117 |
$wpdb->query( |
| 118 |
"INSERT INTO {$wpdb->termmeta} (term_id, meta_key, meta_value) |
| 119 |
SELECT tm.term_id, 'pxlbsadminify_fodler_color', tm.meta_value |
| 120 |
FROM {$wpdb->termmeta} tm |
| 121 |
WHERE tm.meta_key = '_wp_adminify_fodler_color' |
| 122 |
AND NOT EXISTS ( |
| 123 |
SELECT 1 FROM {$wpdb->termmeta} tm2 |
| 124 |
WHERE tm2.term_id = tm.term_id AND tm2.meta_key = 'pxlbsadminify_fodler_color' |
| 125 |
)" |
| 126 |
); |
| 127 |
} |
| 128 |
|
| 129 |
// Post meta: _wp_adminify_* => pxlbsadminify_* (Pro Admin Pages module). |
| 130 |
// "_wp_adminify_" is 13 characters; keep the suffix after it. |
| 131 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time key migration; not cacheable. |
| 132 |
$wpdb->query( |
| 133 |
"INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) |
| 134 |
SELECT pm.post_id, CONCAT('pxlbsadminify_', SUBSTRING(pm.meta_key, 14)), pm.meta_value |
| 135 |
FROM {$wpdb->postmeta} pm |
| 136 |
WHERE pm.meta_key LIKE '\\_wp\\_adminify\\_%' |
| 137 |
AND NOT EXISTS ( |
| 138 |
SELECT 1 FROM {$wpdb->postmeta} pm2 |
| 139 |
WHERE pm2.post_id = pm.post_id |
| 140 |
AND pm2.meta_key = CONCAT('pxlbsadminify_', SUBSTRING(pm.meta_key, 14)) |
| 141 |
)" |
| 142 |
); |
| 143 |
|
| 144 |
// Clear stale transients renamed in v4.2.0. These are caches that simply |
| 145 |
// regenerate on the next request, so the old keys only need deleting. |
| 146 |
delete_transient( 'wp_adminify_addon_plugins_data' ); |
| 147 |
delete_transient( 'wp_adminify_rollback_versions_' . PXLBSADMINIFY_VER ); |
| 148 |
delete_transient( '_adminify_activation_redirect' ); |
| 149 |
|
| 150 |
// The promo/update remote-sync cron was removed in v4.2.0 (no more remote |
| 151 |
// calls). Unschedule it on existing installs so the dead hook stops firing. |
| 152 |
wp_clear_scheduled_hook( 'pxlbsadminify_sheet_promo_data_remote_sync' ); |
| 153 |
|
| 154 |
// Stop the upgrade loop for installs already on v4.x (past the deferred v4.0 DB upgrade). |
| 155 |
$installed = get_option( 'pxlbsadminify_version', get_option( 'wp_adminify_version', '1.0.0' ) ); |
| 156 |
if ( version_compare( $installed, '4.0', '>=' ) ) { |
| 157 |
update_option( 'pxlbsadminify_version', PXLBSADMINIFY_VER ); |
| 158 |
} |
| 159 |
|
| 160 |
update_option( 'pxlbsadminify_keys_migrated', true ); |
| 161 |
} |
| 162 |
|
| 163 |
pxlbsadminify_migrate_namespace_keys(); |
| 164 |
|