1, 'website_name' => get_bloginfo('name'), 'banner_text' => 'Add as a preferred source on Google', 'banner_position' => 'bottom', 'banner_bg_color' => '#1a1a1a', 'text_color' => '#ffffff', 'google_button_image' => ADASPRSO_PLUGIN_URL . 'public/images/google-preferred-source-button.png', 'show_on_mobile' => 1, 'show_on_desktop' => 1 ); add_option('adasprso_options', $default_options); } register_activation_hook(__FILE__, 'adasprso_activate'); /** * The code that runs during plugin deactivation. */ function adasprso_deactivate() { // Nothing specific needed on deactivation } register_deactivation_hook(__FILE__, 'adasprso_deactivate'); /** * The core plugin class. */ class ADASPRSO_Main { /** * The unique identifier of this plugin. */ protected $plugin_name; /** * The current version of the plugin. */ protected $version; /** * Plugin options */ protected $options; /** * Initialize the class and set its properties. */ public function __construct() { $this->plugin_name = ADASPRSO_PLUGIN_NAME; $this->version = ADASPRSO_VERSION; $this->options = get_option('adasprso_options'); $this->load_dependencies(); $this->define_admin_hooks(); $this->define_public_hooks(); } /** * Load the required dependencies for this plugin. */ private function load_dependencies() { // Include admin class require_once ADASPRSO_PLUGIN_PATH . 'admin/class-add-as-preferred-source-admin.php'; // Include public class require_once ADASPRSO_PLUGIN_PATH . 'public/class-add-as-preferred-source-public.php'; } /** * Register all of the hooks related to the admin area functionality. */ private function define_admin_hooks() { $plugin_admin = new ADASPRSO_Admin($this->get_plugin_name(), $this->get_version(), $this->options); // Add settings link to plugin add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($plugin_admin, 'add_action_links')); // Admin notice add_action('admin_notices', array($plugin_admin, 'admin_notice')); // Admin menu add_action('admin_menu', array($plugin_admin, 'add_menu_page')); // Register settings add_action('admin_init', array($plugin_admin, 'register_settings')); // Admin scripts add_action('admin_enqueue_scripts', array($plugin_admin, 'enqueue_styles')); add_action('admin_enqueue_scripts', array($plugin_admin, 'enqueue_scripts')); } /** * Register all of the hooks related to the public-facing functionality. */ private function define_public_hooks() { $plugin_public = new ADASPRSO_Public($this->get_plugin_name(), $this->get_version(), $this->options); // Public scripts add_action('wp_enqueue_scripts', array($plugin_public, 'enqueue_styles')); add_action('wp_enqueue_scripts', array($plugin_public, 'enqueue_scripts')); // Add banner to footer add_action('wp_footer', array($plugin_public, 'display_preferred_source_banner')); // Add inline button to content add_filter('the_content', array($plugin_public, 'add_inline_button_to_content')); } /** * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. */ public function get_plugin_name() { return $this->plugin_name; } /** * Retrieve the version number of the plugin. */ public function get_version() { return $this->version; } } /** * Admin footer text only on the settings page */ function adasprso_admin_footer_text($text) { global $pagenow; // Check if we're on the plugin's settings page // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only checking current page, no form processing if ($pagenow === 'options-general.php' && isset($_GET['page']) && sanitize_text_field(wp_unslash($_GET['page'])) === 'add-as-preferred-source') { $custom_text = __('Thank you for using the Add as Preferred Source plugin :) If you like it, please leave a ★★★★★ rating to support us on WordPress.org to help us spread the word to the community.', 'add-as-preferred-source'); return $custom_text; } return $text; // Default footer text for other pages } add_filter('admin_footer_text', 'adasprso_admin_footer_text'); /** * Begins execution of the plugin. */ function adasprso_run() { $plugin = new ADASPRSO_Main(); } adasprso_run();