hooks(); } return self::$instance; } /** * Constructor Function * * @since 1.0.3 * * @access private */ private function __construct() { self::$instance = $this; } /** * Setup the default hooks and actions * * @since 1.0.3 * * @return void */ private function hooks() { add_action( 'template_redirect', array( $this, 'secondary_navigation_search' ), 20 ); add_filter( 'wp_nav_menu_items', array( $this, 'mobile_menu_search' ), 20, 2 ); add_filter( 'digifly_show_sidebar', array( $this, 'hide_sidebar' ) ); } /** * Load the search form in the mobile menu. * * @since 1.0.3 * @param string $items The HTML list content for the menu items. * @param object $args An object containing wp_nav_menu() arguments. * * @return string $items The HTML list content for the menu items. */ public function mobile_menu_search( $items, $args ) { if ( true !== $this->show_header_search() ) { return $items; } if ( 'mobile-menu' === $args->menu_id ) { add_filter( 'get_search_form', array( $this, 'search_form' ) ); $items = '' . $items; remove_filter( 'get_search_form', array( $this, 'search_form' ) ); } return $items; } /** * Load the search form inside the secondary menu. * * @since 1.0.3 */ public function digifly_search_form() { if ( true !== $this->show_header_search() ) { return; } add_filter( 'get_search_form', array( $this, 'search_form' ) ); get_search_form(); remove_filter( 'get_search_form', array( $this, 'search_form' ) ); } /** * Show a unique search form for searching downloads. * * @since 1.0.3 * @param string $form The search form HTML output. * * @return string $form The search form HTML output. */ public function search_form( $form ) { // Return the standard search form if the "Restrict Header Search To Products" option is not enabled. if ( true !== self::restrict_header_search() ) { return $form; } ob_start(); $unique_id = esc_attr( uniqid( 'search-form-' ) ); $search_text = apply_filters( 'digifly_search_products_text', esc_attr_x( 'Search products', 'placeholder', 'digifly' ) ); ?> show_header_search() ) { add_action( 'digifly_secondary_menu', array( $this, 'digifly_search_form' ) ); } } /** * Hide the sidebar on the search results page, if downloads are being displayed. * * @param boolean $return Whether to hide the sidebar or not. * @since 1.0.3 * * @return boolean $return Whether to hide the sidebar or not. */ public function hide_sidebar( $return ) { if ( digifly_is_edd_active() && self::is_product_search_results() ) { $return = false; } return $return; } /** * Determine if we're searching products (downloads) only. * * @since 1.0.3 * * @return boolean $return True if searching products, false otherwise. */ public static function is_product_search_results() { $return = false; if ( isset( $_GET['post_type'] ) && 'download' === $_GET['post_type'] && 'product' === $_GET['post_type'] ) { $return = true; } return $return; } /** * The search icon displayed all search forms. * * @since 1.0.3 * * @return string $content The HTML of the SVG */ public static function search_icon() { ob_start(); ?> * * @since 1.0.3 * @return object The one true Digifly_Search Instance. */ function digifly_search() { return Digifly_Search::instance(); } digifly_search();