* @copyright Copyright (c) 2013-2015, Nicolas GUILLAUME
* @link http://presscustomizr.com/customizr
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
if ( ! class_exists( 'TC_menu' ) ) :
class TC_menu {
static $instance;
function __construct () {
self::$instance =& $this;
//Set menu customizer options (since 3.2.0)
add_action( 'wp' , array( $this, 'tc_set_menu_hooks') );
}
/***************************************
* WP HOOKS SETTINGS
****************************************/
/*
* hook : wp
*
* @package Customizr
* @since Customizr 3.2.0
*/
function tc_set_menu_hooks() {
if ( (bool) TC_utils::$inst->tc_opt('tc_hide_all_menus') )
return;
//VARIOUS USER OPTIONS
add_filter( 'body_class' , array( $this , 'tc_add_body_classes') );
//Set header css classes based on user options
add_filter( 'tc_header_classes' , array( $this , 'tc_set_header_classes') );
add_filter( 'tc_social_header_block_class' , array( $this, 'tc_set_social_header_class') );
//! tc_user_options_style filter is shared by several classes => must always check the local context inside the callback before appending new css
//fired on hook : wp_enqueue_scripts
add_filter( 'tc_user_options_style' , array( $this , 'tc_menu_item_style_first_letter_css') );
//set second menu specific style including @media rules
add_filter( 'tc_user_options_style' , array( $this , 'tc_add_second_menu_inline_style') );
//SIDE MENU HOOKS SINCE v3.3+
if ( $this -> tc_is_sidenav_enabled() ){
add_action( 'wp_head' , array( $this , 'tc_set_sidenav_hooks') );
add_filter( 'tc_user_options_style' , array( $this , 'tc_set_sidenav_style') );
} else {
// add main menu notice
add_action( '__navbar' , array( $this, 'tc_maybe_display_main_menu_notice'), 50 );
}
//this adds css classes to the navbar-wrapper :
//1) to the main menu if regular (sidenav not enabled)
//2) to the secondary menu if enabled
if ( ! $this -> tc_is_sidenav_enabled() || TC_utils::$inst->tc_is_secondary_menu_enabled() ) {
add_filter( 'tc_navbar_wrapper_class' , array( $this, 'tc_set_menu_style_options'), 0 );
}
//body > header > navbar action ordered by priority
add_action ( '__navbar' , array( $this , 'tc_menu_display' ), 30 );
//adds class
add_filter ( 'wp_page_menu' , array( $this , 'tc_add_menuclass' ));
}
/***************************************
* WP_HEAD HOOKS SETTINGS
****************************************/
/**
* Set Various hooks for the sidemenu
* hook : wp_head
* @return void
*/
function tc_set_sidenav_hooks() {
add_filter( 'body_class' , array( $this, 'tc_sidenav_body_class') );
// disable dropdown on click
add_filter( 'tc_menu_open_on_click' , array( $this, 'tc_disable_dropdown_on_click'), 10, 3 );
// add side menu before the page wrapper
add_action( '__before_page_wrapper' , array( $this, 'tc_sidenav_display'), 0 );
// add side menu help block
add_action( '__sidenav' , array( $this, 'tc_maybe_display_sidenav_help') );
// add menu button to the sidebar
add_action( '__sidenav' , array( $this, 'tc_sidenav_toggle_button_display'), 5 );
// add menu
add_action( '__sidenav' , array( $this, 'tc_sidenav_display_menu_customizer'), 10 );
}
/**
* Displays a dismissable block of information in the sidenav wrapper when conditions are met
* hook : __sidenav
*/
function tc_maybe_display_sidenav_help() {
if ( ! TC_placeholders::tc_is_sidenav_help_on() )
return;
?>
%1$s
%2$s
%3$s
',
__( "This is a default page menu.", "customizr" ),
__( "( If you don't have any pages in your website, then this side menu is empty for the moment. )" , "customizr"),
sprintf( __("If you have already created menu(s), you can %s. If you need to create a new menu, jump to the %s.", "customizr"),
sprintf( '%3$s', TC_utils::tc_get_customizer_url( array( "section" => "nav") ), __( "change the default menu", "customizr"), __("replace this default menu by another one", "customizr") ),
sprintf( '%2$s', admin_url('nav-menus.php'), __( "menu creation screen", "customizr") )
)
);
printf('%1$s x',
__( 'dismiss notice', 'customizr')
);
?>
',
implode(' ', apply_filters( "tc_{$type}_menu_wrapper_class", $menu_wrapper_class ) ),
$menu
);
return apply_filters("tc_{$type}_menu_view", $menu );
}
/***************************************
* PLACEHOLDERS VIEW
****************************************/
/**
* Displays the placeholder view if conditions are met in TC_placeholders::tc_is_main_menu_notice_on()
* fired in tc_menu_display(), hook : __navbar
* @since Customizr 3.4+
*/
function tc_maybe_display_main_menu_notice() {
if ( ! TC_placeholders::tc_is_main_menu_notice_on() )
return;
?>
%1$s %2$s',
__( "You can now display your menu as a vertical and mobile friendly side menu, animated when revealed.", "customizr" ),
sprintf( __("%s or %s.", "customizr"),
sprintf( '%2$s', esc_url('demo.presscustomizr.com?design=nav'), __( "Try it with the demo", "customizr") ),
sprintf( '%3$s', TC_utils::tc_get_customizer_url( array( "section" => "nav") ), __( "open the customizer menu section", "customizr"), __("change your menu design now", "customizr") )
)
);
printf('%1$s x',
__( 'dismiss notice', 'customizr')
);
?>
%1$s %2$s',
__( "You can display your main menu or a second menu here horizontally.", "customizr" ),
sprintf( __("%s or read the %s.", "customizr"),
sprintf( '%3$s', TC_utils::tc_get_customizer_url( array( "section" => "nav") ), __( "Manage menus in the header", "customizr"), __("Manage your menus in the header now", "customizr") ),
sprintf( '%2$s', esc_url('http://docs.presscustomizr.com/article/101-customizr-theme-options-header-settings/#navigation'), __( "documentation", "customizr") )
)
);
printf('%1$s x',
__( 'dismiss notice', 'customizr')
);
?>
tc_opt( 'tc_menu_submenu_fade_effect') ) ) ? array_merge( $_classes, array( 'tc-submenu-fade' ) ) : $_classes;
$_classes = ( 0 != esc_attr( TC_utils::$inst->tc_opt( 'tc_menu_submenu_item_move_effect') ) ) ? array_merge( $_classes, array( 'tc-submenu-move' ) ) : $_classes;
$_classes = ( ! wp_is_mobile() && 'hover' == esc_attr( TC_utils::$inst->tc_opt( 'tc_menu_type' ) ) ) ? array_merge( $_classes, array( 'tc-open-on-hover' ) ) : array_merge( $_classes, array( 'tc-open-on-click' ) );
//Navbar menus positions (not sidenav)
//CASE 1 : regular menu (sidenav not enabled), controled by option 'tc_menu_position'
//CASE 2 : second menu ( is_secondary_menu_enabled ?), controled by option 'tc_second_menu_position'
if ( ! $this -> tc_is_sidenav_enabled() )
array_push( $_classes , esc_attr( TC_utils::$inst->tc_opt( 'tc_menu_position') ) );
if ( TC_utils::$inst->tc_is_secondary_menu_enabled() )
array_push( $_classes , esc_attr( TC_utils::$inst->tc_opt( 'tc_second_menu_position') ) );
return $_classes;
}
/*
* hook : body_class hook
*
* @package Customizr
* @since Customizr 3.2.0
*/
function tc_add_body_classes($_classes) {
//menu type class
$_menu_type = $this -> tc_is_sidenav_enabled() ? 'tc-side-menu' : 'tc-regular-menu';
array_push( $_classes, $_menu_type );
return $_classes;
}
/**
* Set the header classes
* Callback for tc_header_classes filter
*
* @package Customizr
* @since Customizr 3.4+
*/
function tc_set_header_classes( $_classes ) {
//backward compatibility (was not handled has an array in previous versions)
if ( ! is_array($_classes) )
return $_classes;
//adds the second menu state
if ( TC_Utils::$inst -> tc_is_secondary_menu_enabled() )
array_push( $_classes, 'tc-second-menu-on' );
//adds the resp. behaviour option for secondary menu
array_push( $_classes, 'tc-second-menu-' . esc_attr( TC_utils::$inst->tc_opt( 'tc_second_menu_resp_setting' ) . '-when-mobile' ) );
return $_classes;
}
/*
* hook : tc_social_header_block_class hook
*
* @package Customizr
* @since Customizr 3.2.0
*/
function tc_set_social_header_class($_classes) {
return 'span5';
}
/**
* Adds a specific class to the ul wrapper
* hook : 'wp_page_menu'
*
* @package Customizr
* @since Customizr 3.0
*/
function tc_add_menuclass( $ulclass) {
$html = preg_replace( '/