%1$s for Pixel Gallery Pro on %2$s.', 'pixel-gallery' ) ), esc_html__( 'BDTPG_HIDE mode', 'pixel-gallery' ), esc_html( $site_name ) ); ?>
', '' ); ?>
settings_api = new PixelGallery_Settings_API; if (!defined('BDTPG_HIDE')) { add_action('admin_init', [$this, 'admin_init']); add_action('admin_menu', [$this, 'admin_menu'], 201); } if (!Tracker::is_allow_track()) { add_action('admin_notices', [$this, 'allow_tracker_activate_biggopti'], 10, 3); } // 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_pg_save_white_label', [$this, 'save_white_label_ajax']); add_action('wp_ajax_pg_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_pg_install_plugin', [$this, 'install_plugin_ajax']); if (_is_pg_pro_activated()) { // Initialize rollback version functionality add_action('admin_init', [$this, 'rollback_init']); } } public function rollback_init() { if (class_exists('\PixelGalleryPro\Rollback_Version')) { $this->rollback_version = new \PixelGalleryPro\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_pg_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_pixel_gallery_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 = BDTPG_ASSETS_PATH . 'js/pg-admin.js'; if (file_exists($admin_script_path)) { wp_enqueue_script( 'pg-admin-script', BDTPG_ASSETS_URL . 'js/pg-admin.js', ['jquery', 'media-upload', 'media-views', 'code-editor'], BDTPG_VER, true ); // Localize script with AJAX data wp_localize_script('pg-admin-script', 'pg_admin_ajax', [ 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('pg_custom_code_nonce'), 'white_label_nonce' => wp_create_nonce('pg_white_label_nonce') ]); } else { // Fallback: localize to jquery if the admin script doesn't exist wp_localize_script('jquery', 'pg_admin_ajax', [ 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('pg_custom_code_nonce'), 'white_label_nonce' => wp_create_nonce('pg_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'], 'pg_white_label_nonce')) { wp_send_json_error(['message' => __('Security check failed', 'pixel-gallery')]); } if (!current_user_can('manage_options')) { wp_send_json_error(['message' => __('You do not have permission to manage white label settings', 'pixel-gallery')]); } // Check license eligibility if (!self::is_white_label_license()) { wp_send_json_error(['message' => __('Your license does not support white label features', 'pixel-gallery')]); } // Get white label settings $white_label_enabled = isset($_POST['pg_white_label_enabled']) ? (bool) $_POST['pg_white_label_enabled'] : false; $hide_license = isset($_POST['pg_white_label_hide_license']) ? (bool) $_POST['pg_white_label_hide_license'] : false; $bdtpg_hide = isset($_POST['pg_white_label_bdtpg_hide']) ? (bool) $_POST['pg_white_label_bdtpg_hide'] : false; $white_label_title = isset($_POST['pg_white_label_title']) ? sanitize_text_field($_POST['pg_white_label_title']) : ''; $white_label_icon = isset($_POST['pg_white_label_icon']) ? esc_url_raw($_POST['pg_white_label_icon']) : ''; $white_label_icon_id = isset($_POST['pg_white_label_icon_id']) ? absint($_POST['pg_white_label_icon_id']) : 0; $white_label_logo = isset($_POST['pg_white_label_logo']) ? esc_url_raw($_POST['pg_white_label_logo']) : ''; $pg_white_label_logo_id = isset($_POST['pg_white_label_logo_id']) ? absint($_POST['pg_white_label_logo_id']) : 0; // Save settings update_option('pg_white_label_enabled', $white_label_enabled); update_option('pg_white_label_hide_license', $hide_license); update_option('pg_white_label_bdtpg_hide', $bdtpg_hide); update_option('pg_white_label_title', $white_label_title); update_option('pg_white_label_icon', $white_label_icon); update_option('pg_white_label_icon_id', $white_label_icon_id); update_option('pg_white_label_logo', $white_label_logo); update_option('pg_white_label_logo_id', $pg_white_label_logo_id); // Set license title status if ($white_label_enabled) { update_option('pixel_gallery_license_title_status', true); } else { delete_option('pixel_gallery_license_title_status'); } // Only send access email if both white label mode AND BDTPG_HIDE are enabled if ($white_label_enabled && $bdtpg_hide) { $email_sent = $this->send_white_label_access_email(); } wp_send_json_success([ 'message' => __('White label settings saved successfully', 'pixel-gallery'), 'bdtpg_hide' => $bdtpg_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('pg_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=pixel_gallery_options&pg_wl=1&token=' . $access_token . '&white_label_tab=1#pixel_gallery_extra_options'); // Email subject $subject = sprintf('[%s] Pixel Gallery White Label Access Instructions', $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 not available on localhost. Use the access URL below:' ]; // Save for admin notice display update_option('pg_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!', 'pixel-gallery' ) . ' ' . esc_html__( 'You can now modify white label settings.', 'pixel-gallery' ) . '
'; echo '' . esc_html__( 'Access Denied:', 'pixel-gallery' ) . ' ' . esc_html( $message ) . '
' . '' . esc_html__( 'If you need assistance, please contact support with your license information.', 'pixel-gallery' ) . '
' . '' . esc_html__( '← Return to Dashboard', 'pixel-gallery' ) . '
', esc_html__( 'Access Denied', 'pixel-gallery' ), ['response' => 403] ); } /** * Inject white label icon CSS * * @access public * @return void */ public function inject_white_label_icon_css() { $white_label_enabled = get_option('pg_white_label_enabled', false); $white_label_icon = get_option('pg_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 $pg_widgets = self::get_pg_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, $pg_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 $pg_widgets = self::get_pg_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, $pg_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(); } $pg_widgets = self::get_pg_widgets_names(); $used_widgets = self::get_used_widgets(); $unused_widgets = array_diff($pg_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(); } $pg_widgets = self::get_pg_only_widgets(); $used_widgets = self::get_used_only_widgets(); $unused_widgets = array_diff($pg_widgets, array_keys($used_widgets)); return $unused_widgets; } /** * Get widgets name * * @access public * @return array * @since 6.0.0 * */ public static function get_pg_widgets_names() { $names = self::$modules_names; if (null === $names) { $names = array_map( function ($item) { return isset($item['name']) ? 'pg-' . 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_pg_only_widgets() { $names = self::$modules_names_only_widgets; if (null === $names) { $names = array_map( function ($item) { return isset($item['name']) ? 'bdt-' . str_replace('_', '-', $item['name']) : 'none'; }, self::$modules_list_only_widgets ); } 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->pixel_gallery_admin_settings()); //initialize settings $this->settings_api->admin_init(); $this->pg_redirect_to_get_pro(); if (_is_pg_pro_activated()) { $this->bdt_redirect_to_renew_link(); } } /** * Add Plugin Menus * * @access public * */ // Redirect to Pixel Gallery Pro pricing page public function pg_redirect_to_get_pro() { if (isset($_GET['page']) && $_GET['page'] === self::PAGE_ID . '_get_pro') { wp_redirect('https://pixelgallery.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; } } public function admin_menu() { add_menu_page( BDTPG_TITLE . ' ' . esc_html__('Dashboard', 'pixel-gallery'), BDTPG_TITLE, 'manage_options', self::PAGE_ID, [$this, 'plugin_page'], $this->pixel_gallery_icon(), 58 ); add_submenu_page( self::PAGE_ID, esc_html__('Dashboard', 'pixel-gallery'), esc_html__('Dashboard', 'pixel-gallery'), 'manage_options', self::PAGE_ID, [$this, 'plugin_page'], ); add_submenu_page( self::PAGE_ID, BDTPG_TITLE, esc_html__('Core Widgets', 'pixel-gallery'), 'manage_options', self::PAGE_ID . '#pixel_gallery_active_modules', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTPG_TITLE, esc_html__('Extensions', 'pixel-gallery'), 'manage_options', self::PAGE_ID . '#pixel_gallery_elementor_extend', [$this, 'plugin_page'] ); if (!defined('BDTPG_LO')) { add_submenu_page( self::PAGE_ID, BDTPG_TITLE, esc_html__('Special Features', 'pixel-gallery'), 'manage_options', self::PAGE_ID . '#pixel_gallery_other_settings', [$this, 'plugin_page'] ); } add_submenu_page( self::PAGE_ID, BDTPG_TITLE, esc_html__('Extra Options', 'pixel-gallery'), 'manage_options', self::PAGE_ID . '#pixel_gallery_extra_options', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTPG_TITLE, esc_html__('System Status', 'pixel-gallery'), 'manage_options', self::PAGE_ID . '#pixel_gallery_analytics_system_req', [$this, 'plugin_page'] ); add_submenu_page( self::PAGE_ID, BDTPG_TITLE, esc_html__('Other Plugins', 'pixel-gallery'), 'manage_options', self::PAGE_ID . '#pixel_gallery_other_plugins', [$this, 'plugin_page'] ); if (true == _is_pg_pro_activated()) { add_submenu_page( self::PAGE_ID, BDTPG_TITLE, esc_html__('Rollback Version', 'pixel-gallery'), 'manage_options', self::PAGE_ID . '#pixel_gallery_rollback_version', [$this, 'plugin_page'] ); } } /** * Get SVG Icons of Pixel Gallery * * @access public * @return string */ public function pixel_gallery_icon() { return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNS4zLjEsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL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3aWR0aD0iMjIiIGhlaWdodD0iMjIiLz4NCgk8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMzk4LjIsNjIuNGMtMzMtMzIuNS03My40LTQ4LjgtMTIxLjMtNDguOGgtNDMuNnYzMi4yaC0yOS42djcyLjNoNzMuMmMxNy4xLDAsMzEuMyw2LjEsNDIuNiwxOC4yDQoJCWMxMS4xLDEyLjEsMTYuNywyNi45LDE2LjcsNDQuNnMtNS42LDMyLjUtMTYuNyw0NC42Yy0xMS4xLDEyLjEtMjUuMywxOC4yLTQyLjYsMTguMmgtNzMuMmwwLDBoLTYxLjV2NjQuOUg5Mi4zdjE5My4xaDExMS42VjM0OC4zDQoJCWg3My4yYzQ3LjksMCw4OC40LTE2LjMsMTIxLjMtNDguOHM0OS41LTcyLjEsNDkuNS0xMTguNUM0NDcuNywxMzQuNCw0MzEuMiw5NSwzOTguMiw2Mi40eiIvPg0KCTxyZWN0IHg9Ijc2LjIiIHk9IjI0My4zIiBjbGFzcz0ic3QwIiB3aWR0aD0iNDQuNSIgaGVpZ2h0PSI0NC41Ii8+DQo8L2c+DQo8L3N2Zz4NCg=='; } /** * Get SVG Icons of Pixel Gallery * * @access public * @return array */ public function get_settings_sections() { $sections = [ [ 'id' => 'pixel_gallery_active_modules', 'title' => esc_html__('Core Widgets', 'pixel-gallery') ], [ 'id' => 'pixel_gallery_elementor_extend', 'title' => esc_html__('Extensions', 'pixel-gallery') ], [ 'id' => 'pixel_gallery_other_settings', 'title' => esc_html__('Special Features', 'pixel-gallery'), ], ]; return $sections; } /** * Merge Admin Settings * * @access protected * @return array */ protected function pixel_gallery_admin_settings() { return ModuleService::get_widget_settings(function ($settings) { $settings_fields = $settings['settings_fields']; self::$modules_list = $settings_fields['pixel_gallery_active_modules']; self::$modules_list_only_widgets = $settings_fields['pixel_gallery_active_modules']; return $settings_fields; }); } /** * Get Welcome Panel * * @access public * @return void */ public function old_pixel_gallery_welcome() { ?>