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, 'banner_trigger' => 'immediate', 'banner_scroll_percent' => 50, 'banner_delay_seconds' => 5, 'display_on' => 'everywhere', 'exclude_post_ids' => '', 'exclude_categories' => array(), ); add_option('adasprso_options', $default_options); // Record activation date for the review notice (only on first activation). if ( false === get_option( 'adasprso_activation_date' ) ) { add_option( 'adasprso_activation_date', time() ); } } 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'; // Include admin notices, deactivation feedback, and analytics classes require_once ADASPRSO_PLUGIN_PATH . 'includes/class-aaps-admin-notices.php'; require_once ADASPRSO_PLUGIN_PATH . 'includes/class-aaps-deactivation-feedback.php'; require_once ADASPRSO_PLUGIN_PATH . 'includes/class-aaps-analytics.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')); // Review notice after 8 days new ADASPRSO_Admin_Notices(); // Deactivation feedback modal new ADASPRSO_Deactivation_Feedback( ADASPRSO_PLUGIN_URL, ADASPRSO_VERSION ); // Analytics tracking (registers AJAX handlers) new ADASPRSO_Analytics(); } /** * 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; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only checking current page, no form processing if ( 'options-general.php' === $pagenow && isset( $_GET['page'] ) && sanitize_text_field( wp_unslash( $_GET['page'] ) ) === 'add-as-preferred-source' ) { $link = '' . esc_html__( 'a ★★★★★ rating', 'add-as-preferred-source' ) . ''; return wp_kses( sprintf( /* translators: %s: link to the plugin review page */ __( 'Thank you for using the Add as Preferred Source plugin :) If you like it, please leave %s to support us on WordPress.org to help us spread the word to the community.', 'add-as-preferred-source' ), $link ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array(), ), ) ); } return $text; } add_filter('admin_footer_text', 'adasprso_admin_footer_text'); /** * Begins execution of the plugin. */ function adasprso_run() { $plugin = new ADASPRSO_Main(); } add_action( 'plugins_loaded', 'adasprso_run' );