| 1 |
<?php |
| 2 |
|
| 3 |
namespace PXLBSAdminify\Inc\Classes; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
class Upgrade_v4_0 extends Upgrade{ |
| 10 |
private static $instance = null; |
| 11 |
|
| 12 |
public function __construct() { |
| 13 |
add_action('admin_notices', array($this, 'check_for_upgrade')); |
| 14 |
add_action('wp_ajax_pxlbsadminify_upgrade_v4_0_db', array($this, 'upgrade_database')); |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public function check_for_upgrade(){ |
| 20 |
$current_version = get_option($this->option_name); |
| 21 |
|
| 22 |
if ($current_version !== PXLBSADMINIFY_VER) { |
| 23 |
$this->show_admin_notice(); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public function show_admin_notice(){ ?> |
| 28 |
<div class="hide-notice--ignored notice notice-warning"> |
| 29 |
<p><?php esc_html_e('A database upgrade is required due to the latest plugin version. Please click the button below to upgrade.', 'adminify'); ?></p> |
| 30 |
<p> |
| 31 |
<button id="upgrade-db" class="button button-primary"><?php esc_html_e('Update Adminify Database', 'adminify'); ?></button> |
| 32 |
<a href="https://wpadminify.com/what-is-new-in-wp-adminify-v4-0/" target="_blank" class="button button-secondary"><?php esc_html_e('Learn more about updates', 'adminify'); ?></a> |
| 33 |
</p> |
| 34 |
</div> |
| 35 |
|
| 36 |
<script type="text/javascript"> |
| 37 |
jQuery(document).ready(function($) { |
| 38 |
$('#upgrade-db').on('click', function(e) { |
| 39 |
e.preventDefault(); |
| 40 |
|
| 41 |
var $button = $(this); |
| 42 |
$button.prop('disabled', true); |
| 43 |
|
| 44 |
$.post(ajaxurl, { |
| 45 |
action: 'pxlbsadminify_upgrade_v4_0_db', |
| 46 |
security: '<?php echo esc_attr( wp_create_nonce('pxlbsadminify_upgrade_v4_0_db_nonce') ); ?>' |
| 47 |
}, function(response) { |
| 48 |
if (response.success) { |
| 49 |
location.reload(); |
| 50 |
} else { |
| 51 |
alert(response.data); |
| 52 |
$button.prop('disabled', false); |
| 53 |
} |
| 54 |
}); |
| 55 |
}); |
| 56 |
}); |
| 57 |
</script> |
| 58 |
<?php |
| 59 |
} |
| 60 |
|
| 61 |
public function upgrade_database() |
| 62 |
{ |
| 63 |
check_ajax_referer('pxlbsadminify_upgrade_v4_0_db_nonce', 'security'); |
| 64 |
|
| 65 |
// Security check - only administrators can run database upgrades |
| 66 |
if (!current_user_can('manage_options')) { |
| 67 |
wp_send_json_error(array('message' => __('You do not have permission to perform this action.', 'adminify'))); |
| 68 |
} |
| 69 |
|
| 70 |
$old_data = get_option('_wpadminify_backup', []); |
| 71 |
|
| 72 |
// Google Page Speed Backup |
| 73 |
if ( !empty($old_data['google_pagepseed_api_key']) ) { |
| 74 |
update_option('google_pagepseed_api_key', $old_data['google_pagepseed_api_key']); |
| 75 |
} |
| 76 |
|
| 77 |
$this->update_data_migration($old_data); |
| 78 |
|
| 79 |
// Plugin Version Update |
| 80 |
update_option($this->option_name, PXLBSADMINIFY_VER); |
| 81 |
|
| 82 |
wp_send_json_success(); |
| 83 |
} |
| 84 |
|
| 85 |
public static function get_instance() |
| 86 |
{ |
| 87 |
if (!isset(self::$instance) && !(self::$instance instanceof Upgrade_v4_0)) { |
| 88 |
self::$instance = new Upgrade_v4_0(); |
| 89 |
} |
| 90 |
|
| 91 |
return self::$instance; |
| 92 |
} |
| 93 |
|
| 94 |
public function update_data_migration($jltwp_adminify_old_data) { |
| 95 |
|
| 96 |
|
| 97 |
function upgrade_v4_data($old_data) { |
| 98 |
|
| 99 |
$data = []; |
| 100 |
|
| 101 |
// MOVE KEYS |
| 102 |
$move_array_keys = [ |
| 103 |
// Customize |
| 104 |
'admin_bar_settings.admin_bar_comments' => 'admin_bar_notif', |
| 105 |
'admin_bar_settings.admin_bar_search' => 'admin_bar_search', |
| 106 |
|
| 107 |
'admin_bar_settings.admin_bar_dark_light_btn' => 'admin_bar_dark_light_btn', |
| 108 |
'adminify_theme_custom_colors.--adminify-btn-bg' => 'adminify_theme_custom_colors.--adminify-primary', |
| 109 |
'admin_general_bg' => 'body_fields.admin_general_bg', |
| 110 |
'admin_general_bg_gradient' => 'body_fields.admin_general_bg_gradient', |
| 111 |
'admin_general_bg_image' => 'body_fields.admin_general_bg_image', |
| 112 |
'admin_bar_mode' => 'light_dark_mode.admin_ui_mode', |
| 113 |
'admin_bar_logo_type' => 'light_dark_mode.admin_ui_logo_type', |
| 114 |
// 'admin_bar_light_mode' => 'light_dark_mode.admin_ui_light_mode', |
| 115 |
|
| 116 |
// light logo |
| 117 |
'admin_bar_light_mode.admin_bar_light_logo_text' => 'light_dark_mode.admin_ui_light_mode.admin_ui_light_logo_text', |
| 118 |
'admin_bar_light_mode.admin_bar_light_logo_text_typo' => 'light_dark_mode.admin_ui_light_mode.admin_ui_light_logo_text_typo', |
| 119 |
'admin_bar_light_mode.admin_bar_light_logo' => 'light_dark_mode.admin_ui_light_mode.admin_ui_light_logo', |
| 120 |
'admin_bar_light_mode.mini_admin_bar_light_logo' => 'light_dark_mode.admin_ui_light_mode.mini_admin_ui_light_logo', |
| 121 |
'admin_bar_light_mode.light_logo_size' => 'light_dark_mode.admin_ui_light_mode.light_logo_size', |
| 122 |
// Dark logo |
| 123 |
'admin_bar_dark_mode.admin_bar_dark_logo_text' => 'light_dark_mode.admin_ui_dark_mode.admin_ui_dark_logo_text', |
| 124 |
'admin_bar_dark_mode.admin_bar_dark_logo_text_typo' => 'light_dark_mode.admin_ui_dark_mode.admin_ui_dark_logo_text_typo', |
| 125 |
'admin_bar_dark_mode.admin_bar_dark_logo' => 'light_dark_mode.admin_ui_dark_mode.admin_ui_dark_logo', |
| 126 |
'admin_bar_dark_mode.mini_admin_bar_dark_logo' => 'light_dark_mode.admin_ui_dark_mode.mini_admin_ui_dark_logo', |
| 127 |
'admin_bar_dark_mode.dark_logo_size' => 'light_dark_mode.admin_ui_dark_mode.dark_logo_size', |
| 128 |
|
| 129 |
'enable_schedule_dark_mode' => 'light_dark_mode.admin_ui_dark_mode.schedule_dark_mode.enable_schedule_dark_mode', |
| 130 |
'schedule_dark_mode_type' => 'light_dark_mode.admin_ui_dark_mode.schedule_dark_mode.schedule_dark_mode_type', |
| 131 |
'schedule_dark_mode_start_time' => 'light_dark_mode.admin_ui_dark_mode.schedule_dark_mode.schedule_dark_mode_start_time', |
| 132 |
'schedule_dark_mode_end_time' => 'light_dark_mode.admin_ui_dark_mode.schedule_dark_mode.schedule_dark_mode_end_time', |
| 133 |
|
| 134 |
// Admin Menu |
| 135 |
'menu_layout_settings.user_info' => 'menu_layout_settings.user_info_fields.enable_user_info', |
| 136 |
'menu_layout_settings.user_info_content' => 'menu_layout_settings.user_info_fields.user_info_content', |
| 137 |
'menu_layout_settings.user_info_avatar' => 'menu_layout_settings.user_info_fields.user_info_avatar', |
| 138 |
|
| 139 |
// Productivity |
| 140 |
'folders' => 'folders.enable_folders', |
| 141 |
'folders_enable_for' => 'folders.enable_for', |
| 142 |
'folders_media' => 'folders.media', |
| 143 |
|
| 144 |
'admin_columns' => 'custom_admin_columns.enable', |
| 145 |
'quick_menu' => 'quick_menus_data.quick_menus_enable', |
| 146 |
'quick_menus' => 'quick_menus_data.quick_menus', |
| 147 |
|
| 148 |
'post_types_order' => 'post_types_order.enable_pto', //TODO: Spacial Check |
| 149 |
'pto_taxonomies' => 'post_types_order.pto_taxonomies', //TODO: Spacial Check |
| 150 |
'pto_posts' => 'post_types_order.pto_posts', //TODO: Spacial Check |
| 151 |
'pto_media' => 'post_types_order.pto_media', //TODO: Spacial Check |
| 152 |
|
| 153 |
'post_duplicator' => 'post_duplicator.enable_post_duplicator', //TODO: Spacial Check |
| 154 |
'adminify_clone_post_posts' => 'post_duplicator.post_types', //TODO: Spacial Check |
| 155 |
'adminify_clone_post_taxonomies' => 'post_duplicator.taxonomies', //TODO: Spacial Check TODO: not exits v_3 |
| 156 |
|
| 157 |
'post_page_column_thumb_image' => 'custom_admin_columns.post_page_column_thumb_image', |
| 158 |
|
| 159 |
'sidebar_widgets_list' => 'remove_widgets.sidebar_widgets_list', |
| 160 |
'sidebar_widgets_disable_gutenberg_editor' => 'remove_widgets.disable_gutenberg_editor', |
| 161 |
'dashboard_widgets_list' => 'remove_widgets.dashboard_widgets_list', |
| 162 |
|
| 163 |
// Security |
| 164 |
'disable_comments' => 'disable_comments.enable_disable_comments', |
| 165 |
'disable_comments_post_types' => 'disable_comments.post_types', |
| 166 |
|
| 167 |
'enable_custom_gravatar' => 'custom_gravatar.enable', |
| 168 |
'custom_gravatar_image' => 'custom_gravatar.image', |
| 169 |
|
| 170 |
'redirect_urls' => 'redirect_urls_fields.enable_redirect_urls', |
| 171 |
|
| 172 |
'remove_feed' => 'security_feed', |
| 173 |
'redirect_feed' => 'security_feed', |
| 174 |
|
| 175 |
// Performance |
| 176 |
'control_heartbeat_api' => 'heartbeat_api.enabled', |
| 177 |
|
| 178 |
// Code Snippets |
| 179 |
'custom_css' => 'backend.custom_css', |
| 180 |
'custom_js' => 'backend.custom_js', |
| 181 |
|
| 182 |
// White Label |
| 183 |
'admin_bar_settings.admin_bar_howdy_text' => 'white_label.wordpress.change_howdy_text', |
| 184 |
'footer_text' => 'white_label.wordpress.footer_text', |
| 185 |
|
| 186 |
'jltwp_adminify_wl_plugin_logo' => 'white_label.adminify.plugin_logo', |
| 187 |
'jltwp_adminify_wl_plugin_name' => 'white_label.adminify.plugin_name', |
| 188 |
'jltwp_adminify_wl_plugin_desc' => 'white_label.adminify.plugin_desc', |
| 189 |
'jltwp_adminify_wl_plugin_author_name' => 'white_label.adminify.author_name', |
| 190 |
'jltwp_adminify_wl_plugin_menu_label' => 'white_label.adminify.menu_label', |
| 191 |
'jltwp_adminify_wl_plugin_url' => 'white_label.adminify.plugin_url', |
| 192 |
'jltwp_adminify_wl_plugin_row_links' => 'white_label.adminify.row_links', |
| 193 |
|
| 194 |
]; |
| 195 |
// $data = \PXLBSAdminify\Inc\Utils::moveNestedKeys($old_data, $move_array_keys); |
| 196 |
|
| 197 |
|
| 198 |
//REPLACE KEYS |
| 199 |
$replace_array_keys = [ |
| 200 |
// Productivity |
| 201 |
'admin_notices' => 'hide_notices', |
| 202 |
]; |
| 203 |
// $data = \PXLBSAdminify\Inc\Utils::replace_keys($data, $replace_array_keys); |
| 204 |
|
| 205 |
// CHECKBOX KEYS |
| 206 |
$checkbox_keys = [ |
| 207 |
//Productivity |
| 208 |
'post_thumb_column' => 'custom_admin_columns.columns_data.post_thumb_column', |
| 209 |
'post_page_id_column' => 'custom_admin_columns.columns_data.post_page_id_column', |
| 210 |
'comment_id_column' => 'custom_admin_columns.columns_data.comment_id_column', |
| 211 |
'taxonomy_id_column' => 'custom_admin_columns.columns_data.taxonomy_id_column', |
| 212 |
|
| 213 |
'remove_welcome_panel' => 'other_notices.welcome_panel', |
| 214 |
'remove_php_update_required_nag' => 'other_notices.php_nag', |
| 215 |
'core_update_notice' => 'other_notices.core_update_notice', |
| 216 |
'plugin_update_notice' => 'other_notices.plugin_update_notice', |
| 217 |
'theme_update_notice' => 'other_notices.theme_update_notice', |
| 218 |
|
| 219 |
// Security |
| 220 |
'disable_xmlrpc' => 'security_head.security_head_data.xmlrpc', |
| 221 |
'generator_wp_version' => 'security_head.security_head_data.generator_wp_version', |
| 222 |
'remove_rsd' => 'security_head.security_head_data.rsd', |
| 223 |
'remove_shortlink' => 'security_head.security_head_data.shortlink', |
| 224 |
'remove_canonical' => 'security_head.security_head_data.canonical', |
| 225 |
'self_ping' => 'security_head.security_head_data.self_ping', |
| 226 |
|
| 227 |
'remove_wc_generator' => 'security_head.security_head_data.wc_generator', |
| 228 |
'remove_revslider_generator' => 'security_head.security_head_data.revslider_generator', |
| 229 |
'remove_visual_composer_generator' => 'security_head.security_head_data.js_composer_generator', |
| 230 |
'remove_wpml_generator' => 'security_head.security_head_data.wpml_generator', |
| 231 |
'remove_yoast_generator' => 'security_head.security_head_data.yoast_generator', |
| 232 |
|
| 233 |
'disable_rest_api' => 'security_rest_api.security_rest_api_data.rest_api', |
| 234 |
'remove_powered' => 'security_rest_api.security_rest_api_data.powered', |
| 235 |
'remove_api_head' => 'security_rest_api.security_rest_api_data.api_head', |
| 236 |
'remove_api_server' => 'security_rest_api.security_rest_aremove_gutenberg_scriptspi_data.api_server', |
| 237 |
'remove_powered' => 'security_head.security_rest_api_data.powered', |
| 238 |
|
| 239 |
'disable_comments_admin_bar' => 'disable_comments.apply_for.admin_bar', |
| 240 |
'disable_comments_menu_redirect' => 'disable_comments.apply_for.menu_redirect', |
| 241 |
'disable_comments_admin_menu' => 'disable_comments.apply_for.admin_menu', |
| 242 |
'disable_comments_discussion_menu' => 'disable_comments.apply_for.discussion_menu', |
| 243 |
'disable_comments_close_front' => 'disable_comments.apply_for.close_front', |
| 244 |
'remove_comments_notes' => 'disable_comments.apply_for.comments_notes', |
| 245 |
'disable_comments_url_field' => 'disable_comments.apply_for.comments_url_field', |
| 246 |
'disable_comments_replace_author_link' => 'disable_comments.apply_for.replace_author_link', |
| 247 |
'disable_comments_replace_comment_link' => 'disable_comments.apply_for.replace_comment_link', |
| 248 |
'remove_recentcomments' => 'disable_comments.apply_for.recentcomments', |
| 249 |
'disable_comments_hide_existing' => 'disable_comments.apply_for.hide_existing', |
| 250 |
|
| 251 |
'display_last_modified_date' => 'post_archives.post_archives_data.last_modified_date', |
| 252 |
'remove_capital_p_dangit' => 'post_archives.post_archives_data.capital_p_dangit', |
| 253 |
'remove_archives_date' => 'post_archives.post_archives_data.archives_date', |
| 254 |
'remove_archives_author' => 'post_archives.post_archives_data.archives_author', |
| 255 |
'remove_archives_tag' => 'post_archives.post_archives_data.archives_tag', |
| 256 |
'remove_archives_category' => 'post_archives.post_archives_data.archives_category', |
| 257 |
'remove_archives_postformat' => 'post_archives.post_archives_data.archives_postformat', |
| 258 |
'remove_archives_search' => 'post_archives.post_archives_data.archives_search', |
| 259 |
|
| 260 |
// Performance |
| 261 |
'remove_dashicons' => 'performance.performance_data.dashicons', |
| 262 |
'remove_version_strings' => 'performance.performance_data.version_strings', |
| 263 |
'gravatar_query_strings' => 'performance.performance_data.gravatar_query_strings', |
| 264 |
'remove_emoji' => 'performance.performance_data.emoji', |
| 265 |
'remove_jquery_migrate' => 'performance.performance_data.jquery_migrate_front', |
| 266 |
'defer_parsing_js_footer' => 'performance.performance_data.defer_parsing_js_footer', |
| 267 |
'cache_gzip_compression' => 'performance.performance_data.cache_gzip_compression', |
| 268 |
|
| 269 |
'remove_gutenberg_scripts' => 'disable_gutenberg.disable_for.remove_gutenberg_scripts', |
| 270 |
|
| 271 |
// White Label |
| 272 |
// WordPress |
| 273 |
// 'admin_footer_ip_address' => 'white_label.wordpress.admin_footer.ip_address', |
| 274 |
// 'admin_footer_php_version' => 'white_label.wordpress.admin_footer.php_version', |
| 275 |
// 'admin_footer_wp_version' => 'white_label.wordpress.admin_footer.wp_version', |
| 276 |
// 'admin_footer_memory_usage' => 'white_label.wordpress.admin_footer.memory_usage', |
| 277 |
// 'admin_footer_memory_limit' => 'white_label.wordpress.admin_footer.memory_limit', |
| 278 |
// 'admin_footer_memory_available' => 'white_label.wordpress.admin_footer.memory_available', |
| 279 |
// // Adminify |
| 280 |
// 'jltwp_adminify_remove_action_links' => 'white_label.adminify.remove_action_links', |
| 281 |
// 'jltwp_adminify_wl_plugin_tab_system_info' => 'white_label.adminify.tab_system_info', |
| 282 |
// 'jltwp_adminify_wl_plugin_option' => 'white_label.adminify.plugin_option', |
| 283 |
]; |
| 284 |
// $data = \PXLBSAdminify\Inc\Utils::checkboxes($data, $checkbox_keys); |
| 285 |
|
| 286 |
|
| 287 |
// REMOVE KEYSmoveNestedKeys |
| 288 |
$removeArrayKeys = [ |
| 289 |
// Admin Menu |
| 290 |
'menu_layout_settings.legacy_menu', |
| 291 |
'menu_layout_settings.show_bloglink', |
| 292 |
|
| 293 |
//Productivity |
| 294 |
'remove_try_gutenberg_panel', |
| 295 |
|
| 296 |
//Security |
| 297 |
'rest_api', |
| 298 |
'disable_comments_dashboard_widget', |
| 299 |
'remove_comments_author_link', |
| 300 |
'remove_comments_autolinking', |
| 301 |
'disable_comments_media', |
| 302 |
|
| 303 |
// Performance |
| 304 |
'remove_pingback', |
| 305 |
'remove_link_url', |
| 306 |
'remove_wlwmanifest', |
| 307 |
'remove_dns_prefetch', |
| 308 |
'remove_prev_next', |
| 309 |
'remove_http_shortlink', |
| 310 |
|
| 311 |
'thumbnails_rss_feed', |
| 312 |
'remove_image_link', |
| 313 |
'remove_attachment', |
| 314 |
'disable_pdf_thumbnail', |
| 315 |
|
| 316 |
'login_customizer', |
| 317 |
'menu_editor', |
| 318 |
'dashboard_widgets', |
| 319 |
'pagespeed_insights', |
| 320 |
'custom_css_js', |
| 321 |
'activity_logs', |
| 322 |
'notification_bar', |
| 323 |
'server_info', |
| 324 |
'sidebar_generator', |
| 325 |
'admin_general_bg_color', |
| 326 |
'admin_general_bg_slideshow', |
| 327 |
'admin_general_bg_video_type', |
| 328 |
'admin_general_bg_video_self_hosted', |
| 329 |
'admin_general_bg_video_youtube', |
| 330 |
'admin_general_bg_video_loop', |
| 331 |
'admin_general_bg_video_poster', |
| 332 |
'admin_glass_effect', |
| 333 |
'admin_danger_button_color', |
| 334 |
// Google pagespeed |
| 335 |
'google_pagepseed_user_roles', |
| 336 |
'google_pagepseed_api_key' |
| 337 |
]; |
| 338 |
// $data = \PXLBSAdminify\Inc\Utils::removeKeys($data, $removeArrayKeys); |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
$data = \PXLBSAdminify\Inc\Utils::replace_keys($old_data, $replace_array_keys); |
| 343 |
$data = \PXLBSAdminify\Inc\Utils::removeKeys($data, $removeArrayKeys); |
| 344 |
$data = \PXLBSAdminify\Inc\Utils::moveNestedKeys($data, $move_array_keys); |
| 345 |
$data = \PXLBSAdminify\Inc\Utils::checkboxes($data, $checkbox_keys); |
| 346 |
|
| 347 |
// Redirect Urls data Mirgrate |
| 348 |
$redirect_urls_data = get_option('_wpadminify_redirect_urls'); |
| 349 |
|
| 350 |
$migrate_redirect_data = [ |
| 351 |
'redirect_urls_fields' => [ |
| 352 |
'enable_redirect_urls' => !empty($data['redirect_urls_fields']['enable_redirect_urls']) ? 1 : 0, |
| 353 |
'redirect_urls_options' => [ |
| 354 |
'redirect_urls_tabs' => !empty($redirect_urls_data['redirect_urls_options']) ? $redirect_urls_data['redirect_urls_options'] : [] |
| 355 |
] |
| 356 |
] |
| 357 |
]; |
| 358 |
|
| 359 |
return array_merge($data, $migrate_redirect_data) ; |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
$new_data = upgrade_v4_data($jltwp_adminify_old_data); |
| 364 |
update_option( '_wpadminify', $new_data ); |
| 365 |
|
| 366 |
|
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
Upgrade_v4_0::get_instance(); |
| 371 |
|