options = get_option( 'add_search_to_menu' ); $this->loader = new ASTM_Loader(); $this->set_locale(); if ( is_admin() ) { $this->admin_hooks(); } else { $this->public_hooks(); } } /** * PHP 4 Compatible Constructor. */ function Add_Search_To_Menu() { $this->__construct(); } /** * Define the locale for this plugin for internationalization. * * Uses the ASTM_i18n class in order to set the domain and to register the hook * with WordPress. * * @since 1.0.0 * @access private */ private function set_locale() { $this->loader->add_action( 'plugins_loaded', new ASTM_i18n(), 'load_plugin_textdomain' ); } /** * Defines the hooks and callback functions that are used for setting up the plugin's admin options. * * @access private */ private function admin_hooks() { $options = $this->options; $admin = new ASTM_Admin( ASTM_VERSION ); if ( ! isset( $options['dismiss_admin_notices'] ) || ! $options['dismiss_admin_notices'] ) { $this->loader->add_action( 'all_admin_notices', $admin, 'setup_notice' ); } $this->loader->add_action( 'plugin_action_links', $admin, 'plugin_settings_link', 10, 2 ); $this->loader->add_action( 'admin_menu', $admin, 'admin_menu_setup' ); $this->loader->add_action( 'wp_ajax_nopriv_dismiss_notice', $admin, 'dismiss_notice' ); $this->loader->add_action( 'wp_ajax_dismiss_notice', $admin, 'dismiss_notice' ); $this->loader->add_action( 'admin_enqueue_scripts', $admin, 'admin_script_style' ); $this->loader->add_action( 'admin_init', $admin, 'settings_init' ); } /** * Defines the hooks and callback functions that are used for executing plugin functionality * in the front end of site. * * @access private */ private function public_hooks() { $options = $this->options; $public = new ASTM_Public( ASTM_VERSION ); $this->loader->add_action( 'wp_enqueue_scripts', $public, 'enqueue_script_style' ); $display_in_header = isset( $options['add_search_to_menu_display_in_header'] ) ? $options['add_search_to_menu_display_in_header'] : 0; $display_in_mobile_menu = $display_in_header && wp_is_mobile() ? true : false; if ( $display_in_mobile_menu ) { $this->loader->add_filter( 'wp_head', $public, 'search_in_header', 99 ); } else { $this->loader->add_filter( 'wp_nav_menu_items', $public, 'search_menu_item', 99, 2 ); } if ( isset( $options['add_search_to_menu_posts'] ) && ( ! isset( $options['add_search_to_menu_gcse'] ) || '' == $options['add_search_to_menu_gcse'] ) ) { $this->loader->add_action( 'pre_get_posts', $public, 'search_filter' ); } $this->loader->add_action( 'wp_footer', $public, 'custom_css' ); } /** * Sets this class into motion. * * Executes the plugin by calling the init method of the loader class which will * register all of the hooks and callback functions used throughout the plugin * with WordPress. */ public function init() { $this->loader->init(); } } }