%1$s for Ultimate Post Kit Pro on %2$s.', 'ultimate-post-kit' ) ), esc_html__( 'BDTUPK_HIDE mode', 'ultimate-post-kit' ), esc_html( $site_name ) ); ?>
', '' ); ?>
settings_api = new UltimatePostKit_Settings_API; if (!defined('BDTUPK_HIDE')) { add_action('admin_init', [$this, 'admin_init']); add_action('admin_menu', [$this, 'admin_menu'], 201); } // Handle white label access link $this->handle_white_label_access(); // Add custom CSS/JS functionality $this->init_custom_code_functionality(); // White label settings (admin only) add_action( 'wp_ajax_upk_save_white_label', [ $this, 'save_white_label_ajax' ] ); add_action( 'wp_ajax_upk_revoke_white_label_token', [ $this, 'revoke_white_label_token_ajax' ] ); add_action( 'admin_head', [ $this, 'inject_white_label_icon_css' ] ); // Plugin installation (admin only) add_action('wp_ajax_upk_install_plugin', [$this, 'install_plugin_ajax']); if (_is_upk_pro_activated()) { // Initialize rollback version functionality add_action('admin_init', [$this, 'rollback_init']); } } public function rollback_init() { if ( class_exists('\UltimatePostKitPro\Rollback_Version') ) { $this->rollback_version = new \UltimatePostKitPro\Rollback_Version(); } } /** * Initialize Custom Code Functionality * * @access public * @return void */ public function init_custom_code_functionality() { // AJAX handler for saving custom code (admin only) add_action( 'wp_ajax_upk_save_custom_code', [ $this, 'save_custom_code_ajax' ] ); // Admin scripts (admin only) add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_custom_code_scripts' ] ); // Frontend injection is now handled by global functions in the main plugin file self::init_frontend_injection(); } /** * Initialize frontend injection hooks (works on both admin and frontend) * * @access public static * @return void */ public static function init_frontend_injection() { // Frontend hooks are now registered in the main plugin file // This method is kept for backwards compatibility but does nothing } /** * Enqueue scripts for custom code editor * * @access public * @return void */ public function enqueue_custom_code_scripts( $hook ) { if ( $hook !== 'toplevel_page_ultimate_post_kit_options' ) { return; } // Enqueue WordPress built-in CodeMirror wp_enqueue_code_editor( array( 'type' => 'text/css' ) ); wp_enqueue_code_editor( array( 'type' => 'application/javascript' ) ); // Enqueue WordPress media library scripts wp_enqueue_media(); // Enqueue the admin script if it exists $admin_script_path = BDTUPK_ASSETS_PATH . 'js/upk-admin.js'; if ( file_exists( $admin_script_path ) ) { wp_enqueue_script( 'upk-admin-script', BDTUPK_ASSETS_URL . 'js/upk-admin.js', [ 'jquery', 'media-upload', 'media-views', 'code-editor' ], BDTUPK_VER, true ); // Localize script with AJAX data wp_localize_script( 'upk-admin-script', 'upk_admin_ajax', [ 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'upk_custom_code_nonce' ), 'white_label_nonce' => wp_create_nonce( 'upk_white_label_nonce' ) ] ); } else { // Fallback: localize to jquery if the admin script doesn't exist wp_localize_script( 'jquery', 'upk_admin_ajax', [ 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'upk_custom_code_nonce' ), 'white_label_nonce' => wp_create_nonce( 'upk_white_label_nonce' ) ] ); } } /** * AJAX handler for saving white label settings * * @access public * @return void */ public function save_white_label_ajax() { // Check nonce and permissions if (!wp_verify_nonce($_POST['nonce'], 'upk_white_label_nonce')) { wp_send_json_error(['message' => __('Security check failed', 'ultimate-post-kit')]); } if (!current_user_can('manage_options')) { wp_send_json_error(['message' => __('You do not have permission to manage white label settings', 'ultimate-post-kit')]); } // Check license eligibility if (!self::is_white_label_license()) { wp_send_json_error(['message' => __('Your license does not support white label features', 'ultimate-post-kit')]); } // Get white label settings $white_label_enabled = isset($_POST['upk_white_label_enabled']) ? (bool) $_POST['upk_white_label_enabled'] : false; $hide_license = isset($_POST['upk_white_label_hide_license']) ? (bool) $_POST['upk_white_label_hide_license'] : false; $bdtupk_hide = isset($_POST['upk_white_label_bdtupk_hide']) ? (bool) $_POST['upk_white_label_bdtupk_hide'] : false; $white_label_title = isset($_POST['upk_white_label_title']) ? sanitize_text_field($_POST['upk_white_label_title']) : ''; $white_label_icon = isset($_POST['upk_white_label_icon']) ? esc_url_raw($_POST['upk_white_label_icon']) : ''; $white_label_icon_id = isset($_POST['upk_white_label_icon_id']) ? absint($_POST['upk_white_label_icon_id']) : 0; $white_label_logo = isset($_POST['upk_white_label_logo']) ? esc_url_raw($_POST['upk_white_label_logo']) : ''; $upk_white_label_logo_id = isset($_POST['upk_white_label_logo_id']) ? absint($_POST['upk_white_label_logo_id']) : 0; // Save settings update_option('upk_white_label_enabled', $white_label_enabled); update_option('upk_white_label_hide_license', $hide_license); update_option('upk_white_label_bdtupk_hide', $bdtupk_hide); update_option('upk_white_label_title', $white_label_title); update_option('upk_white_label_icon', $white_label_icon); update_option('upk_white_label_icon_id', $white_label_icon_id); update_option('upk_white_label_logo', $white_label_logo); update_option('upk_white_label_logo_id', $upk_white_label_logo_id); // Set license title status if ($white_label_enabled) { update_option('ultimate_post_kit_license_title_status', true); } else { delete_option('ultimate_post_kit_license_title_status'); } // Only send access email if both white label mode AND BDTUPK_HIDE are enabled if ($white_label_enabled && $bdtupk_hide) { $email_sent = $this->send_white_label_access_email(); } wp_send_json_success([ 'message' => __('White label settings saved successfully', 'ultimate-post-kit'), 'bdtupk_hide' => $bdtupk_hide, 'email_sent' => isset($email_sent) ? $email_sent : false ]); } /** * Send white label access email with special link * * @access private * @return bool */ private function send_white_label_access_email() { $license_email = self::get_license_email(); $admin_email = get_bloginfo( 'admin_email' ); $license_key = self::get_license_key(); $site_name = get_bloginfo( 'name' ); $site_url = get_bloginfo( 'url' ); // Generate secure access token with additional entropy $access_token = wp_hash( $license_key . time() . wp_salt() . wp_generate_password( 32, false ) ); // Store access token in database with no expiration $token_data = [ 'token' => $access_token, 'license_key' => $license_key, 'created_at' => current_time( 'timestamp' ), 'user_id' => get_current_user_id() ]; update_option( 'upk_white_label_access_token', $token_data ); // Generate access URL using token instead of license key for security // Add white_label_tab=1 parameter to automatically switch to White Label tab $access_url = admin_url( 'admin.php?page=ultimate_post_kit_options&upk_wl=1&token=' . $access_token . '&white_label_tab=1#ultimate_post_kit_extra_options' ); // Email subject $subject = sprintf( /* translators: %s: Site name. */ __( '[%s] Ultimate Post Kit White Label Access Instructions', 'ultimate-post-kit' ), $site_name ); // Email message $message = $this->get_white_label_email_template( $site_name, $site_url, $access_url, $license_key ); // Email headers $headers = [ 'Content-Type: text/html; charset=UTF-8', 'From: ' . $site_name . ' <' . $admin_email . '>' ]; $email_sent = false; // Send to license email if ( ! empty( $license_email ) && is_email( $license_email ) ) { $email_sent = wp_mail( $license_email, $subject, $message, $headers ); // If on localhost or email failed, save email content for manual access if ( ! $email_sent || $this->is_localhost() ) { $this->save_email_content_for_localhost( $access_url, $message, $license_email ); } } return $email_sent; } /** * Check if running on localhost * * @access private * @return bool */ private function is_localhost() { $server_name = $_SERVER['SERVER_NAME'] ?? ''; $server_addr = $_SERVER['SERVER_ADDR'] ?? ''; $localhost_indicators = [ 'localhost', '127.0.0.1', '::1', '.local', '.test', '.dev' ]; foreach ( $localhost_indicators as $indicator ) { if ( strpos( $server_name, $indicator ) !== false || strpos( $server_addr, $indicator ) !== false ) { return true; } } return false; } /** * Save email content for localhost testing * * @access private * @param string $access_url * @param string $email_content * @param string $recipient_email * @return void */ private function save_email_content_for_localhost( $access_url, $email_content, $recipient_email ) { $email_data = [ 'access_url' => $access_url, 'email_content' => $email_content, 'recipient_email' => $recipient_email, 'message' => __( 'Email functionality is not available on localhost. Use the access URL below:', 'ultimate-post-kit' ), ]; // Save for admin notice display update_option( 'upk_localhost_email_data', $email_data ); } /** * Get white label email template * * @access private * @param string $site_name * @param string $site_url * @param string $access_url * @param string $license_key * @return string */ private function get_white_label_email_template( $site_name, $site_url, $access_url, $license_key ) { $masked_license = substr( $license_key, 0, 8 ) . '****-****-****-' . substr( $license_key, -4 ); ob_start(); ?>
' . esc_html__( '✅ White Label Access Granted!', 'ultimate-post-kit' ) . ' ' . esc_html__( 'You can now modify white label settings.', 'ultimate-post-kit' ) . '
'; echo '' . esc_html__( 'Access Denied:', 'ultimate-post-kit' ) . ' ' . esc_html( $message ) . '
' . '' . esc_html__( 'If you need assistance, please contact support with your license information.', 'ultimate-post-kit' ) . '
' . '' . esc_html__( '← Return to Dashboard', 'ultimate-post-kit' ) . '
', esc_html__( 'Access Denied', 'ultimate-post-kit' ), [ 'response' => 403 ] ); } /** * Inject white label icon CSS * * @access public * @return void */ public function inject_white_label_icon_css() { $white_label_enabled = get_option('upk_white_label_enabled', false); $white_label_icon = get_option('upk_white_label_icon', ''); // Only inject CSS when white label is enabled AND a custom icon is set if ( $white_label_enabled && ! empty( $white_label_icon ) ) { echo ''; } // When white label is disabled or no icon is set, don't inject any CSS // This allows WordPress's original icon to display naturally } /** * Get used widgets. * * @access public * @return array * @since 6.0.0 * */ public static function get_used_widgets() { $used_widgets = array(); if (class_exists('Elementor\Modules\Usage\Module')) { $module = Module::instance(); $old_error_level = error_reporting(); error_reporting(E_ALL & ~E_WARNING); // Suppress warnings $elements = $module->get_formatted_usage('raw'); error_reporting($old_error_level); // Restore $upk_widgets = self::get_upk_widgets_names(); if (is_array($elements) || is_object($elements)) { foreach ($elements as $post_type => $data) { foreach ($data['elements'] as $element => $count) { if (in_array($element, $upk_widgets, true)) { if (isset($used_widgets[$element])) { $used_widgets[$element] += $count; } else { $used_widgets[$element] = $count; } } } } } } return $used_widgets; } /** * Get used separate widgets. * * @access public * @return array * @since 6.0.0 * */ public static function get_used_only_widgets() { $used_widgets = array(); if (class_exists('Elementor\Modules\Usage\Module')) { $module = Module::instance(); $old_error_level = error_reporting(); error_reporting(E_ALL & ~E_WARNING); // Suppress warnings $elements = $module->get_formatted_usage('raw'); error_reporting($old_error_level); // Restore $upk_widgets = self::get_upk_only_widgets(); if (is_array($elements) || is_object($elements)) { foreach ($elements as $post_type => $data) { foreach ($data['elements'] as $element => $count) { if (in_array($element, $upk_widgets, true)) { if (isset($used_widgets[$element])) { $used_widgets[$element] += $count; } else { $used_widgets[$element] = $count; } } } } } } return $used_widgets; } /** * Get unused widgets. * * @access public * @return array * @since 6.0.0 * */ public static function get_unused_widgets() { if (!current_user_can('install_plugins')) { die(); } $upk_widgets = self::get_upk_widgets_names(); $used_widgets = self::get_used_widgets(); $unused_widgets = array_diff($upk_widgets, array_keys($used_widgets)); return $unused_widgets; } /** * Get unused separate widgets. * * @access public * @return array * @since 6.0.0 * */ public static function get_unused_only_widgets() { if (!current_user_can('install_plugins')) { die(); } $upk_widgets = self::get_upk_only_widgets(); $used_widgets = self::get_used_only_widgets(); $unused_widgets = array_diff($upk_widgets, array_keys($used_widgets)); return $unused_widgets; } /** * Get widgets name * * @access public * @return array * @since 6.0.0 * */ public static function get_upk_widgets_names() { $names = self::$modules_names; if (null === $names) { $names = array_map( function ($item) { return isset($item['name']) ? 'upk-' . str_replace('_', '-', $item['name']) : 'none'; }, self::$modules_list ); } return $names; } /** * Get separate widgets name * * @access public * @return array * @since 6.0.0 * */ public static function get_upk_only_widgets() { $names = self::$modules_names_only_widgets; if (null === $names) { $names = array_map( function ($item) { return isset($item['name']) ? 'upk-' . str_replace('_', '-', $item['name']) : 'none'; }, self::$modules_list_only_widgets ); } return $names; } /** * Get separate 3rdParty widgets name * * @access public * @return array * @since 6.0.0 * */ public static function get_upk_only_3rdparty_names() { $names = self::$modules_names_only_3rdparty; if (null === $names) { $names = array_map( function ($item) { return isset($item['name']) ? 'upk-' . str_replace('_', '-', $item['name']) : 'none'; }, self::$modules_list_only_3rdparty ); } return $names; } /** * Get URL with page id * * @access public * */ public static function get_url() { return admin_url('admin.php?page=' . self::PAGE_ID); } /** * Init settings API * * @access public * */ public function admin_init() { //set the settings $this->settings_api->set_sections($this->get_settings_sections()); $this->settings_api->set_fields($this->ultimate_post_kit_admin_settings()); //initialize settings $this->settings_api->admin_init(); $this->upk_redirect_to_get_pro(); if (true === _is_upk_pro_activated()) { $this->bdt_redirect_to_renew_link(); } } /** * Add Plugin Menus * * @access public * */ // Redirect to Ultimate Post Kit Pro pricing page public function upk_redirect_to_get_pro() { if (isset($_GET['page']) && $_GET['page'] === self::PAGE_ID . '_get_pro') { wp_redirect('https://postkit.pro/pricing/'); exit; } } /** * Redirect to license renewal page * * @access public * */ public function bdt_redirect_to_renew_link() { if (isset($_GET['page']) && $_GET['page'] === self::PAGE_ID . '_license_renew') { wp_redirect('https://account.bdthemes.com/'); exit; } } /** * Add Plugin Menus * * @access public * */ public function admin_menu() { add_menu_page( BDTUPK_TITLE . ' ' . esc_html__('Dashboard', 'ultimate-post-kit'), BDTUPK_TITLE, 'manage_options', self::PAGE_ID, [$this, 'plugin_page'], $this->ultimate_post_kit_icon(), 58 ); add_submenu_page( self::PAGE_ID, BDTUPK_TITLE, esc_html__('Core Widgets', 'ultimate-post-kit'), 'manage_options', self::PAGE_ID . '#ultimate_post_kit_active_modules', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTUPK_TITLE, esc_html__('Extensions', 'ultimate-post-kit'), 'manage_options', self::PAGE_ID . '#ultimate_post_kit_elementor_extend', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTUPK_TITLE, esc_html__('Special Features', 'ultimate-post-kit'), 'manage_options', self::PAGE_ID . '#ultimate_post_kit_other_settings', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTUPK_TITLE, esc_html__('API Settings', 'ultimate-post-kit'), 'manage_options', self::PAGE_ID . '#ultimate_post_kit_api_settings', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTUPK_TITLE, esc_html__('Extra Options', 'ultimate-post-kit'), 'manage_options', self::PAGE_ID . '#ultimate_post_kit_extra_options', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTUPK_TITLE, esc_html__('System Status', 'ultimate-post-kit'), 'manage_options', self::PAGE_ID . '#ultimate_post_kit_analytics_system_req', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTUPK_TITLE, esc_html__('Other Plugins', 'ultimate-post-kit'), 'manage_options', self::PAGE_ID . '#ultimate_post_kit_other_plugins', [$this, 'plugin_page'] ); // add_submenu_page( // self::PAGE_ID, // BDTUPK_TITLE, // esc_html__('Get Up to 60%', 'ultimate-post-kit'), // 'manage_options', // self::PAGE_ID . '#ultimate_post_kit_affiliate', // [$this, 'plugin_page'] // ); if (true == _is_upk_pro_activated()) { add_submenu_page( self::PAGE_ID, BDTUPK_TITLE, esc_html__('Rollback Version', 'ultimate-post-kit'), 'manage_options', self::PAGE_ID . '#ultimate_post_kit_rollback_version', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTUPK_TITLE, esc_html__('Template Builder', 'ultimate-post-kit'), 'edit_pages', 'edit.php?post_type=upk-template-builder', ); } } /** * Get SVG Icons of Ultimate Post Kit * * @access public * @return string */ public function ultimate_post_kit_icon() { return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNC4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCA5MDkuMyA4ODMuOCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgOTA5LjMgODgzLjg7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+DQoJLnN0MHtmaWxsOiNBN0FBQUQ7fQ0KPC9zdHlsZT4NCjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik04MTEuMiwyNzIuOUg2ODEuNnYxMjkuN2MwLDEzLjYtMTEsMjQuNy0yNC43LDI0LjdoLTEwNWMtMTMuNiwwLTI0LjctMTEtMjQuNy0yNC43YzAsMCwwLDAsMCwwdi0xMDUNCgljMC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laWdodD0iOC45Ii8+DQo8cmVjdCB4PSI4NzcuNCIgeT0iMzgiIGNsYXNzPSJzdDAiIHdpZHRoPSI3LjIiIGhlaWdodD0iNy4yIi8+DQo8cmVjdCB4PSI4NTIuNiIgeT0iODciIGNsYXNzPSJzdDAiIHdpZHRoPSI4LjkiIGhlaWdodD0iOC45Ii8+DQo8cmVjdCB4PSI3MzUuNCIgeT0iMTgyLjgiIGNsYXNzPSJzdDAiIHdpZHRoPSIxOS43IiBoZWlnaHQ9IjE5LjciLz4NCjxyZWN0IHg9IjgyNi4zIiB5PSIyMDQuNiIgY2xhc3M9InN0MCIgd2lkdGg9IjE0LjEiIGhlaWdodD0iMTQuMSIvPg0KPC9zdmc+DQo='; } /** * Get SVG Icons of Element Pack * * @access public * @return array */ public function get_settings_sections() { $sections = [ [ 'id' => 'ultimate_post_kit_active_modules', 'title' => esc_html__('Core Widgets', 'ultimate-post-kit'), 'icon' => 'dashicons dashicons-screenoptions', ], [ 'id' => 'ultimate_post_kit_elementor_extend', 'title' => esc_html__('Extensions', 'ultimate-post-kit'), 'icon' => 'dashicons dashicons-screenoptions', ], [ 'id' => 'ultimate_post_kit_other_settings', 'title' => esc_html__('Special Features', 'ultimate-post-kit'), 'icon' => 'dashicons dashicons-screenoptions', ], [ 'id' => 'ultimate_post_kit_api_settings', 'title' => esc_html__('API Settings', 'ultimate-post-kit'), 'icon' => 'dashicons dashicons-admin-settings', ], ]; return $sections; } /** * Merge Admin Settings * * @access protected * @return array */ protected function ultimate_post_kit_admin_settings() { return ModuleService::get_widget_settings(function ($settings) { $settings_fields = $settings['settings_fields']; self::$modules_list = $settings_fields['ultimate_post_kit_active_modules']; self::$modules_list_only_widgets = $settings_fields['ultimate_post_kit_active_modules']; return $settings_fields; }); } /** * Get Welcome Panel * * @access public * @return void */ public function ultimate_post_kit_welcome() { ?>