plugin_name = $plugin_name; $this->version = $version; $this->options = $options; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles($hook) { // Only load on plugin settings page if ('settings_page_add-as-preferred-source' !== $hook) { return; } wp_enqueue_style('wp-color-picker'); wp_enqueue_style($this->plugin_name . '-admin', ADASPRSO_PLUGIN_URL . 'admin/css/add-as-preferred-source-admin.css', array(), $this->version, 'all'); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts($hook) { // Only load on plugin settings page if ('settings_page_add-as-preferred-source' !== $hook) { return; } wp_enqueue_script('wp-color-picker'); wp_enqueue_script($this->plugin_name . '-admin', ADASPRSO_PLUGIN_URL . 'admin/js/add-as-preferred-source-admin.js', array('jquery', 'wp-color-picker'), $this->version, false); } /** * Add settings page link to plugins page * * @since 1.0.0 */ public function add_action_links($links) { $settings_link = '' . __('Settings', 'add-as-preferred-source') . ''; array_unshift($links, $settings_link); return $links; } /** * Show admin notice with settings link * * @since 1.0.0 */ public function admin_notice() { // Show notice only once $notice_dismissed = get_option('adasprso_notice_dismissed'); // Check if notice is already dismissed or if not on plugins page if ($notice_dismissed || get_current_screen()->id !== 'plugins') { return; } // Check if we're on the correct page and have proper nonce (if needed) $current_screen = get_current_screen(); if ($current_screen && $current_screen->id === 'plugins') { // Auto-dismiss the notice after showing it once update_option('adasprso_notice_dismissed', true); ?>
plugin_name, array($this, 'display_settings_page') ); } /** * Display the settings page content * * @since 1.0.0 */ public function display_settings_page() { include_once ADASPRSO_PLUGIN_PATH . 'admin/partials/add-as-preferred-source-admin-display.php'; } /** * Register plugin settings * * @since 1.0.0 */ public function register_settings() { register_setting( 'adasprso_settings', 'adasprso_options', array($this, 'validate_settings') ); // General Settings Section add_settings_section( 'adasprso_general_section', __('General Settings', 'add-as-preferred-source'), array($this, 'general_section_callback'), 'adasprso_settings' ); // Banner Enabled add_settings_field( 'adasprso_enabled', __('Enable Banner', 'add-as-preferred-source'), array($this, 'enabled_callback'), 'adasprso_settings', 'adasprso_general_section' ); // Website Name add_settings_field( 'adasprso_website_name', __('Website Name', 'add-as-preferred-source'), array($this, 'website_name_callback'), 'adasprso_settings', 'adasprso_general_section' ); // Banner Text add_settings_field( 'adasprso_banner_text', __('Banner Text', 'add-as-preferred-source'), array($this, 'banner_text_callback'), 'adasprso_settings', 'adasprso_general_section' ); // Banner Position add_settings_field( 'adasprso_banner_position', __('Banner Position', 'add-as-preferred-source'), array($this, 'banner_position_callback'), 'adasprso_settings', 'adasprso_general_section' ); // Color Settings Section add_settings_section( 'adasprso_color_section', __('Color Settings', 'add-as-preferred-source'), array($this, 'color_section_callback'), 'adasprso_settings' ); // Banner Background Color add_settings_field( 'adasprso_banner_bg_color', __('Banner Background Color', 'add-as-preferred-source'), array($this, 'banner_bg_color_callback'), 'adasprso_settings', 'adasprso_color_section' ); // Text Color add_settings_field( 'adasprso_text_color', __('Text Color', 'add-as-preferred-source'), array($this, 'text_color_callback'), 'adasprso_settings', 'adasprso_color_section' ); // Device Settings Section add_settings_section( 'adasprso_device_section', __('Device Settings', 'add-as-preferred-source'), array($this, 'device_section_callback'), 'adasprso_settings' ); // Show on Mobile add_settings_field( 'adasprso_show_on_mobile', __('Show on Mobile', 'add-as-preferred-source'), array($this, 'show_on_mobile_callback'), 'adasprso_settings', 'adasprso_device_section' ); // Show on Desktop add_settings_field( 'adasprso_show_on_desktop', __('Show on Desktop', 'add-as-preferred-source'), array($this, 'show_on_desktop_callback'), 'adasprso_settings', 'adasprso_device_section' ); } /** * Validate settings * * @since 1.0.0 * @param array $input The input options. * @return array The sanitized options. */ public function validate_settings($input) { $sanitized_input = array(); // No need to manually verify nonce - WordPress settings API handles this automatically // The nonce is automatically generated and verified by settings_fields() // Boolean field $sanitized_input['enabled'] = isset($input['enabled']) ? 1 : 0; // Text fields $sanitized_input['website_name'] = sanitize_text_field($input['website_name']); $sanitized_input['banner_text'] = sanitize_text_field($input['banner_text']); // Banner position $sanitized_input['banner_position'] = ($input['banner_position'] === 'top') ? 'top' : 'bottom'; // Color fields $sanitized_input['banner_bg_color'] = sanitize_hex_color($input['banner_bg_color']); $sanitized_input['text_color'] = sanitize_hex_color($input['text_color']); // Device settings $sanitized_input['show_on_mobile'] = isset($input['show_on_mobile']) ? 1 : 0; $sanitized_input['show_on_desktop'] = isset($input['show_on_desktop']) ? 1 : 0; // Google button image (keep the local image path) $sanitized_input['google_button_image'] = ADASPRSO_PLUGIN_URL . 'public/images/google-preferred-source-button.png'; // Add success message add_settings_error('adasprso_options', 'settings_updated', __('Settings saved successfully!', 'add-as-preferred-source'), 'updated'); return $sanitized_input; } /** * General section callback * * @since 1.0.0 */ public function general_section_callback() { echo '' . esc_html__('Configure the general settings for your preferred source banner.', 'add-as-preferred-source') . '
'; } /** * Color section callback * * @since 1.0.0 */ public function color_section_callback() { echo '' . esc_html__('Customize the colors for your preferred source banner.', 'add-as-preferred-source') . '
'; } /** * Device section callback * * @since 1.0.0 */ public function device_section_callback() { echo '' . esc_html__('Choose on which devices the banner should be displayed.', 'add-as-preferred-source') . '
'; } /** * Enable callback * * @since 1.0.0 */ public function enabled_callback() { $enabled = isset($this->options['enabled']) ? $this->options['enabled'] : 0; echo ''; echo ''; } /** * Website name callback * * @since 1.0.0 */ public function website_name_callback() { $website_name = isset($this->options['website_name']) ? $this->options['website_name'] : get_bloginfo('name'); echo ''; echo '' . esc_html__('Enter your website name for the banner text.', 'add-as-preferred-source') . '
'; } /** * Banner text callback * * @since 1.0.0 */ public function banner_text_callback() { $banner_text = isset($this->options['banner_text']) ? $this->options['banner_text'] : 'Add as a preferred source on Google'; echo ''; echo '' . esc_html__('Enter the text to display in the banner. Use {website_name} to include the website name.', 'add-as-preferred-source') . '
'; } /** * Banner position callback * * @since 1.0.0 */ public function banner_position_callback() { $banner_position = isset($this->options['banner_position']) ? $this->options['banner_position'] : 'bottom'; ?> options['banner_bg_color']) ? $this->options['banner_bg_color'] : '#1a1a1a'; echo ''; } /** * Text color callback * * @since 1.0.0 */ public function text_color_callback() { $text_color = isset($this->options['text_color']) ? $this->options['text_color'] : '#ffffff'; echo ''; } /** * Show on mobile callback * * @since 1.0.0 */ public function show_on_mobile_callback() { $show_on_mobile = isset($this->options['show_on_mobile']) ? $this->options['show_on_mobile'] : 1; echo ''; echo ''; } /** * Show on desktop callback * * @since 1.0.0 */ public function show_on_desktop_callback() { $show_on_desktop = isset($this->options['show_on_desktop']) ? $this->options['show_on_desktop'] : 1; echo ''; echo ''; } }