options = $options;
}
/**
* Function to create element for menu items.
*
* @access public
* @version 4.0.0
*
* @param string/HTML $output
* @param object $item
* @param int $depth
* @param array $args
* @param int $id
*/
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$this->set_current_item( $item );
$classes = array();
if ( ! empty( $item->classes ) ) {
$classes = (array) $item->classes;
}
$rmp_menu_classes = $classes;
/** Add rmp menu classes as per item */
foreach ( $classes as $class ) {
switch ( $class ) {
case 'menu-item':
$rmp_menu_classes[] = 'rmp-menu-item';
break;
case 'current-menu-item':
$rmp_menu_classes[] = 'rmp-menu-current-item';
break;
case 'menu-item-has-children':
$rmp_menu_classes[] = 'rmp-menu-item-has-children';
break;
case 'current-menu-parent':
$rmp_menu_classes[] = 'rmp-menu-item-current-parent';
break;
case 'current-menu-ancestor':
$rmp_menu_classes[] = 'rmp-menu-item-current-ancestor';
break;
}
}
// Add top/sub level class as per item.
if ( 0 === intval( $item->menu_item_parent ) ) {
$rmp_menu_classes[] = 'rmp-menu-top-level-item';
$this->root_item_id = $item->ID;
} else {
$rmp_menu_classes[] = 'rmp-menu-sub-level-item';
}
/* Clear child class if we are at the final depth level */
if ( isset( $rmp_menu_classes ) ) {
$has_child = array_search( 'rmp-menu-item-has-children', $rmp_menu_classes, true );
if ( ( intval( $depth ) + 1 ) === intval( $this->options['menu_depth'] ) && false !== $has_child ) {
unset( $rmp_menu_classes[ $has_child ] );
}
}
$class_names = join( ' ', array_unique( $rmp_menu_classes ) );
/** Prepare classes for menu item. */
if ( ! empty( $class_names ) ) {
$class_names = sprintf( 'class="%s"', esc_attr( $class_names ) );
} else {
$class_names = '';
}
$class_names = apply_filters( 'rmp_nav_item_class', $class_names, $item );
// Start menu item and set classes & ID.
$output .= sprintf(
'
';
}
/**
* Function to close the sub-menu items.
*
* @since 4.0.0
* @access public
*
* @param string|HTML $output
* @param int $depth
* @param array $args
*/
public function end_lvl( &$output, $depth = 0, $args = array() ) {
$output .= '';
}
/**
* Function get the active item toggle icon.
*
* @return HTML
*/
public function get_active_arrow() {
if ( ! empty( $this->options['active_arrow_font_icon'] ) ) {
return $this->options['active_arrow_font_icon'];
} elseif ( ! empty( $this->options['active_arrow_image'] ) ) {
return sprintf(
'
',
rmp_image_alt_by_url( $this->options['active_arrow_image'] ),
esc_url( $this->options['active_arrow_image'] )
);
} else {
return $this->options['active_arrow_shape'];
}
}
/**
* Function get the inactive item toggle icon.
*
* @return HTML
*/
public function get_inactive_arrow() {
if ( ! empty( $this->options['inactive_arrow_font_icon'] ) ) {
return $this->options['inactive_arrow_font_icon'];
} elseif ( ! empty( $this->options['inactive_arrow_image'] ) ) {
return sprintf(
'
',
rmp_image_alt_by_url( $this->options['inactive_arrow_image'] ),
esc_url( $this->options['inactive_arrow_image'] )
);
} else {
return $this->options['inactive_arrow_shape'];
}
}
/**
* Function to set the current item object.
*
* @param object $item Menu item object.
*/
public function set_current_item( $item ) {
$this->current_item = $item;
}
/**
* Function to return the current item object.
*
* @return object $item Menu item object.
*/
public function get_current_item() {
return $this->current_item;
}
/**
* Check submenu need to open or not.
*
* @return boolean
*/
public function get_submenu_class_open_or_not() {
return $this->expand_all_submenu_options_is_on() || $this->expand_current_submenu_on_and_item_is_parent() ? ' rmp-submenu-open' : '';
}
/**
* Check all submenu need to open or not.
*
* @return boolean
*/
public function expand_all_submenu_options_is_on() {
return 'on' === $this->options['auto_expand_all_submenus'];
}
/**
* Check current submenu need to open or not.
*
* @return boolean
*/
public function expand_current_submenu_on_and_item_is_parent() {
return ( 'on' === $this->options['auto_expand_current_submenus'] )
&& ( $this->get_current_item()->current_item_ancestor || $this->get_current_item()->current_item_parent );
}
}