| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace PXLBSAdminify\Inc\Classes\Wizard; | |
| 3 | +namespace WPAdminify\Inc\Classes\Wizard; | |
| 4 | 4 | |
| 5 | -use \PXLBSAdminify\Inc\Admin\AdminSettings; | |
| 6 | -use PXLBSAdminify\Inc\Utils; | |
| 5 | +use \WPAdminify\Inc\Admin\AdminSettings; | |
| 6 | +use WPAdminify\Inc\Utils; | |
| 7 | 7 | |
| 8 | 8 | // no direct access allowed |
| 9 | 9 | if (!defined('ABSPATH')) { |
| 10 | 10 | exit; |
| @@ -16,15 +16,15 @@ | ||
| 16 | 16 | public function __construct() { |
| 17 | 17 | |
| 18 | 18 | if (current_user_can('manage_options') && current_user_can('administrator')) { |
| 19 | 19 | |
| 20 | - add_action('wp_ajax_pxlbsadminify_save_wizard_data', [$this, 'pxlbsadminify_save_wizard_data']); | |
| 20 | + add_action('wp_ajax_wpadminify_save_wizard_data', [$this, 'wpadminify_save_wizard_data']); | |
| 21 | 21 | |
| 22 | 22 | $this->options = (array) AdminSettings::get_instance()->get(); |
| 23 | 23 | |
| 24 | - $this->setup_wizard(); | |
| 24 | + $this->jltwp_adminify_setup_wizard(); | |
| 25 | 25 | |
| 26 | - add_action('wp_ajax_pxlbsadminify_drag_and_drop_image', [$this, 'pxlbsadminify_drag_and_drop_image_callback']); | |
| 26 | + add_action('wp_ajax_adminify_drag_and_drop_image', [$this, 'adminify_drag_and_drop_image_callback']); | |
| 27 | 27 | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | } |
| @@ -29,17 +29,11 @@ | ||
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // Drag and Drop Image |
| 33 | - public function pxlbsadminify_drag_and_drop_image_callback() { | |
| 34 | - check_ajax_referer('pxlbsadminify_sw'); | |
| 33 | + public function adminify_drag_and_drop_image_callback() { | |
| 34 | + check_ajax_referer('jltwp_adminify_sw'); | |
| 35 | 35 | |
| 36 | - // Security check - only administrators can upload images via wizard | |
| 37 | - if (!current_user_can('manage_options')) { | |
| 38 | - wp_send_json_error(__('You do not have permission to perform this action.', 'adminify')); | |
| 39 | - } | |
| 40 | - | |
| 41 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- nonce verified above; settings array recursively sanitized via wp_kses_post_deep(). | |
| 42 | 36 | $data_source = empty($_POST['settings']) ? [] : (array) wp_kses_post_deep(wp_unslash($_POST['settings'])); |
| 43 | 37 | |
| 44 | 38 | $base64_image = $data_source['image_data']; |
| 45 | 39 | |
| @@ -84,26 +78,20 @@ | ||
| 84 | 78 | return $setting; |
| 85 | 79 | } |
| 86 | 80 | |
| 87 | 81 | // TEXT validation |
| 88 | - public function text_validation($text) { | |
| 82 | + public function wpadminify_text_validation($text) { | |
| 89 | 83 | return sanitize_text_field( wp_unslash( $text ?? '' ) ); |
| 90 | 84 | } |
| 91 | 85 | |
| 92 | - public function pxlbsadminify_save_wizard_data() { | |
| 93 | - check_ajax_referer('pxlbsadminify_sw'); | |
| 86 | + public function wpadminify_save_wizard_data() { | |
| 87 | + check_ajax_referer('jltwp_adminify_sw'); | |
| 94 | 88 | |
| 95 | - // Security check - only administrators can save wizard settings | |
| 96 | - if (!current_user_can('manage_options')) { | |
| 97 | - wp_send_json_error(__('You do not have permission to perform this action.', 'adminify')); | |
| 98 | - } | |
| 99 | - | |
| 100 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- nonce verified above; settings array recursively sanitized via wp_kses_post_deep(). | |
| 101 | 89 | $settings = empty($_POST['settings']) ? [] : (array) wp_kses_post_deep(wp_unslash($_POST['settings'])); |
| 102 | 90 | |
| 103 | 91 | $validate_settings = $this->validate_before_save($settings); |
| 104 | 92 | |
| 105 | - $settings = get_option('pxlbsadminify_settings', []); | |
| 93 | + $settings = get_option('_wpadminify', []); | |
| 106 | 94 | |
| 107 | 95 | // Adminify UI |
| 108 | 96 | if( array_key_exists('admin_ui', $validate_settings) ) { |
| 109 | 97 | $settings['admin_ui'] = !empty($validate_settings['admin_ui']) ? true : false; |
| @@ -113,9 +101,9 @@ | ||
| 113 | 101 | if( array_key_exists('admin_ui_logo_type', $validate_settings) && array_key_exists('admin_ui_light_mode', $validate_settings)) { |
| 114 | 102 | |
| 115 | 103 | $settings['light_dark_mode']['admin_ui_logo_type'] = $validate_settings['admin_ui_logo_type']; |
| 116 | 104 | if($validate_settings['admin_ui_logo_type'] === 'text_logo') { |
| 117 | - $settings['light_dark_mode']['admin_ui_light_mode']['admin_ui_light_logo_text'] = $this->text_validation( $validate_settings['admin_ui_light_mode']['admin_ui_light_logo_text'] ); | |
| 105 | + $settings['light_dark_mode']['admin_ui_light_mode']['admin_ui_light_logo_text'] = $this->wpadminify_text_validation( $validate_settings['admin_ui_light_mode']['admin_ui_light_logo_text'] ); | |
| 118 | 106 | } |
| 119 | 107 | if($validate_settings['admin_ui_logo_type'] === 'image_logo') { |
| 120 | 108 | $settings['light_dark_mode']['admin_ui_light_mode']['admin_ui_light_logo']['url'] = wp_http_validate_url($validate_settings['admin_ui_light_mode']['admin_ui_light_logo']['url']); |
| 121 | 109 | } |
| @@ -126,19 +114,12 @@ | ||
| 126 | 114 | if( array_key_exists('footer_text', $validate_settings) ) { |
| 127 | 115 | $settings['white_label']['wordpress']['footer_text'] = wp_kses_post( $validate_settings['footer_text'] ); |
| 128 | 116 | } |
| 129 | 117 | |
| 130 | - update_option('pxlbsadminify_settings', $settings); | |
| 131 | - | |
| 132 | - $is_complete = !empty($_POST['is_complete']) && $_POST['is_complete'] === '1'; | |
| 133 | - if ($is_complete) { | |
| 134 | - update_option('pxlbsadminify_setup_wizard_ran', '1'); | |
| 135 | - } | |
| 136 | - | |
| 118 | + update_option('_wpadminify', $settings); | |
| 137 | 119 | wp_send_json_success( |
| 138 | 120 | [ |
| 139 | - 'redirect' => true, | |
| 140 | - 'is_complete' => $is_complete, | |
| 121 | + 'redirect' => true, | |
| 141 | 122 | ] |
| 142 | 123 | ); |
| 143 | 124 | } |
| 144 | 125 | |
| @@ -144,56 +125,25 @@ | ||
| 144 | 125 | |
| 145 | 126 | public function load_scripts() { |
| 146 | 127 | |
| 147 | 128 | // Register |
| 148 | - // wp_register_script('wp-adminify-vue-vendors', PXLBSADMINIFY_ASSETS . 'admin/js/vendor' . Utils::assets_ext('.js'), [], PXLBSADMINIFY_VER, true); | |
| 149 | - wp_register_style('adminify-sw-setup', PXLBSADMINIFY_ASSETS . 'css/setup.css', array(), PXLBSADMINIFY_VER); | |
| 150 | - wp_register_script('adminify-sw-setup', PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify--setup-wizard' . Utils::assets_ext('.js'), ['react', 'jquery'], PXLBSADMINIFY_VER, true); | |
| 129 | + // wp_register_script('wp-adminify-vue-vendors', WP_ADMINIFY_ASSETS . 'admin/js/vendor' . Utils::assets_ext('.js'), [], WP_ADMINIFY_VER, true); | |
| 130 | + wp_register_style('wp-adminify-sw-setup', WP_ADMINIFY_ASSETS . 'css/setup.css'); | |
| 131 | + wp_register_script('wp-adminify-sw-setup', WP_ADMINIFY_ASSETS . 'admin/js/wp-adminify--setup-wizard' . Utils::assets_ext('.js'), ['react', 'jquery'], WP_ADMINIFY_VER, true); | |
| 151 | 132 | |
| 152 | - // Elementor registers "elementor-ai-media-library" inside the | |
| 153 | - // WordPress media iframe with dependencies (elementor-v2-ui, | |
| 154 | - // elementor-v2-icons) that are not registered in this admin | |
| 155 | - // context. WordPress 6.9.1+ raises a "called incorrectly" notice | |
| 156 | - // at registration time when that happens. Pre-register empty stubs | |
| 157 | - // for those handles before wp_enqueue_media() so the dependency | |
| 158 | - // check passes silently. The wizard does not use Elementor, so we | |
| 159 | - // also dequeue Elementor's media-library script after enqueue to | |
| 160 | - // avoid loading unrelated assets here. | |
| 161 | - if (!wp_script_is('elementor-v2-ui', 'registered')) { | |
| 162 | - wp_register_script('elementor-v2-ui', '', [], PXLBSADMINIFY_VER, true); | |
| 163 | - } | |
| 164 | - if (!wp_script_is('elementor-v2-icons', 'registered')) { | |
| 165 | - wp_register_script('elementor-v2-icons', '', [], PXLBSADMINIFY_VER, true); | |
| 166 | - } | |
| 167 | - | |
| 168 | 133 | // Media uploader |
| 169 | 134 | wp_enqueue_media(); |
| 170 | 135 | |
| 171 | - add_action('admin_print_scripts', function () { | |
| 172 | - if (wp_script_is('elementor-ai-media-library', 'enqueued')) { | |
| 173 | - wp_dequeue_script('elementor-ai-media-library'); | |
| 174 | - } | |
| 175 | - }, 999); | |
| 176 | - | |
| 177 | 136 | // Load |
| 178 | - wp_enqueue_style('adminify-sw-setup'); | |
| 137 | + wp_enqueue_style('wp-adminify-sw-setup'); | |
| 179 | 138 | // wp_enqueue_script('media-upload'); |
| 180 | - wp_enqueue_script('adminify-sw-setup'); | |
| 139 | + wp_enqueue_script('wp-adminify-sw-setup'); | |
| 181 | 140 | |
| 182 | 141 | |
| 183 | - $is_network = is_multisite() && is_network_admin(); | |
| 184 | - $settings_url = $is_network | |
| 185 | - ? network_admin_url('admin.php?page=wp-adminify-settings') | |
| 186 | - : admin_url('admin.php?page=wp-adminify-settings'); | |
| 187 | - $dashboard_url = $is_network ? network_admin_url('/') : admin_url('/'); | |
| 188 | - | |
| 189 | 142 | // Localize Script |
| 190 | 143 | $adminify_data = [ |
| 191 | 144 | // 'rest_base' => $this->get_rest_url(''), |
| 192 | 145 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 193 | - 'admin_url' => $dashboard_url, | |
| 194 | - 'settings_url' => $settings_url, | |
| 195 | - 'rest_url' => esc_url_raw(rest_url('adminify/v1/')), | |
| 196 | 146 | 'settings' => [ |
| 197 | 147 | 'admin_ui' => $this->options['admin_ui'], |
| 198 | 148 | 'admin_ui_logo_type' => $this->options['light_dark_mode']['admin_ui_logo_type'], |
| 199 | 149 | 'admin_ui_light_mode' => [ |
| @@ -203,14 +153,14 @@ | ||
| 203 | 153 | 'admin_ui_light_logo_text' => $this->options['light_dark_mode']['admin_ui_light_mode']['admin_ui_light_logo_text'] ?? '', |
| 204 | 154 | ], |
| 205 | 155 | 'footer_text' => $this->options['white_label']['wordpress']['footer_text'], |
| 206 | 156 | ], |
| 207 | - 'images' => PXLBSADMINIFY_ASSETS_IMAGE, | |
| 208 | - 'wpnonce' => wp_create_nonce('pxlbsadminify_sw'), | |
| 157 | + 'images' => WP_ADMINIFY_ASSETS_IMAGE, | |
| 158 | + 'wpnonce' => wp_create_nonce('jltwp_adminify_sw'), | |
| 209 | 159 | 'rest_nonce' => wp_create_nonce('wp_rest') |
| 210 | 160 | ]; |
| 211 | 161 | |
| 212 | - wp_localize_script('adminify-sw-setup', 'PXLBSADMINIFY_SETUP_WIZARD_DATA', $adminify_data); | |
| 162 | + wp_localize_script('wp-adminify-sw-setup', 'adminify_setup_wizard_data', $adminify_data); | |
| 213 | 163 | |
| 214 | 164 | |
| 215 | 165 | // // Dequeue Styles |
| 216 | 166 | // // wp_dequeue_style('install'); |
| @@ -224,13 +174,12 @@ | ||
| 224 | 174 | // wp_deregister_script('shortcode'); |
| 225 | 175 | |
| 226 | 176 | } |
| 227 | 177 | |
| 228 | - public function setup_wizard() { | |
| 178 | + public function jltwp_adminify_setup_wizard() { | |
| 229 | 179 | global $hook_suffix; |
| 230 | 180 | |
| 231 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change. | |
| 232 | - if (empty($_GET['page']) || 'wp-adminify-setup-wizard' !== sanitize_text_field(wp_unslash($_GET['page']))) { | |
| 181 | + if (empty($_GET['page']) || 'wp-adminify-setup-wizard' !== $_GET['page']) { | |
| 233 | 182 | return; |
| 234 | 183 | } |
| 235 | 184 | |
| 236 | 185 | require_once ABSPATH . WPINC . '/media-template.php'; |