options = $option_manager->get_options( $menu_id );
$this->menu_id = $menu_id;
}
/**
* Prepare mobile menu markup.
*
* @version 4.0.0
*
* @return HTML|string
*/
public function mobile_menu() {
$menu_items = '';
if ( ! empty( $this->options['items_order'] ) ) {
$menu_items = $this->options['items_order'];
}
if ( empty( $menu_items ) ) {
return;
}
$side_animation = 'rmp-' . $this->options['animation_type'] . '-' . $this->options['menu_appear_from'];
$menu_container_classes = apply_filters( 'rmp_menu_container_classes', array( 'rmp-container', $side_animation ), $this->menu_id );
$menu_container_classes = implode( ' ', $menu_container_classes );
$this->menu_trigger()
?>
mobile_menu();
/**
* Filters the menu marksup.
*
* @since 4.1.0
*
* @param HTML|string $html
* @param int menu_id
*/
echo apply_filters( 'rmp_menu_html', '', $this->menu_id );
}
/**
* Function to return the prepared menu items.
*
* @since 4.0.0
*
* @return HTML|string
*/
public function menu() {
$param = $this->rmp_nav_menu_args();
if ( empty( $param ) ) {
return;
}
$param['echo'] = false;
echo wp_nav_menu( $param );
/**
* Filters the nav menu markups.
*
* @since 4.1.2
*
* @param HTML $menu_markups
* @param int $this->menu_id
* @param array $param
*/
echo apply_filters( 'rmp_menu_markups', '', $this->menu_id, $param );
}
public function menu_trigger() {
$trigger_click_animation = '';
if ( ! empty( $this->options['button_click_animation'] ) ) {
$trigger_click_animation = 'rmp-menu-trigger-' . $this->options['button_click_animation'];
}
$toggle_theme_class = '';
if ( ! empty( $this->options['menu_theme'] ) ) {
$toggle_theme_class = 'rmp-' . str_replace( ' ', '-', strtolower( $this->options['menu_theme'] ) ) . '-trigger';
}
$toggle_theme_class = apply_filters( 'rmp_menu_toggle_classes', array( 'rmp_menu_trigger', $trigger_click_animation ), $this->menu_id );
$toggle_theme_class = implode( ' ', $toggle_theme_class );
if ( wp_is_mobile() ) {
$toggle_theme_class .= ' rmp-mobile-device-menu';
}
$menu_trigger_destination = '';
if ( ! empty( $this->options['hamburger_position_selector'] ) ) {
$menu_trigger_destination = 'data-destination=' . $this->options['hamburger_position_selector'];
}
?>
options['menu_title'] ) ) {
$menu_title = $this->options['menu_title'];
}
$menu_image = '';
if ( ! empty( $this->options['menu_title_image'] ) ) {
$image_alt = rmp_image_alt_by_url( $this->options['menu_title_image'] );
$menu_image = sprintf(
'',
esc_url( $this->options['menu_title_image'] ),
esc_attr( $image_alt )
);
}
if ( ! empty( $this->options['menu_title_font_icon'] ) ) {
$menu_image = sprintf( '%s', $this->options['menu_title_font_icon'] );
}
$link_target = '_self';
if ( ! empty( $this->options['menu_title_link_location'] ) ) {
$link_target = $this->options['menu_title_link_location'];
}
?>
options['menu_additional_content'] ) ) {
// Sanitize HTML content using wp_kses with a strict allowlist.
// This replaces the previous script-tag-only regex strip, which was
// bypassable via event-handler attributes (e.g. onerror, onload).
$content = rm_sanitize_html_tags( $this->options['menu_additional_content'] );
}
?>
menu_id );
}
/**
* Function to prepare the menu social icons section.
*
* @since 4.6.0
*
* @return void
*/
public function menu_social_icons() {
$social_icons = array();
if ( ! empty( $this->options['menu_social_icons'] ) && is_array( $this->options['menu_social_icons'] ) ) {
$social_icons = $this->options['menu_social_icons'];
}
if ( empty( $social_icons ) ) {
return;
}
$layout = ! empty( $this->options['menu_social_icons_layout'] ) ? $this->options['menu_social_icons_layout'] : 'horizontal';
$layout = in_array( $layout, array( 'horizontal', 'vertical' ), true ) ? $layout : 'horizontal';
$alignment = ! empty( $this->options['menu_social_icons_alignment'] ) ? $this->options['menu_social_icons_alignment'] : 'left';
$alignment = in_array( $alignment, array( 'left', 'center', 'right' ), true ) ? $alignment : 'left';
$wrapper_classes = array(
'rmp-menu-social-icons',
'rmp-social-icons-layout-' . $layout,
'rmp-social-icons-align-' . $alignment,
);
?>
menu_id );
}
public function rmp_nav_menu_args( $args = null ) {
$menu = $this->get_wp_menu_to_use();
$menu_location = $this->get_wp_menu_location();
$wp_menu_obj = wp_get_nav_menu_object( $menu );
// Check menu object is not empty.
if ( empty( $wp_menu_obj ) ) {
return $args;
}
$menu_depth = 0;
if ( ! empty( $this->options['menu_depth'] ) ) {
$menu_depth = $this->options['menu_depth'];
}
$menu_label = ! empty( $this->options['menu_name'] ) ? $this->options['menu_name'] : 'Default';
if ( empty( $menu_label ) ) {
$menu_label = $menu;
}
$item_wrap_attrs = array(
'id' => '%1$s',
'class' => '%2$s',
'role' => 'menubar',
'aria-label' => $menu_label,
);
$wrap_attributes = apply_filters( 'rmp_wrap_attributes', $item_wrap_attrs, $this->menu_id, $menu_location );
$attributes = '';
foreach ( $wrap_attributes as $attribute => $value ) {
if ( ! empty( $value ) ) {
$attributes .= sprintf( ' %s="%s"', $attribute, esc_attr( $value ) );
}
}
$walker = new Walker( $this->options );
if ( ! empty( $this->options['custom_walker'] ) ) {
$walker = new $this->options['custom_walker']( $this->options );
}
$param = array(
'container' => 'div',
'container_id' => 'rmp-menu-wrap-' . $this->menu_id,
'container_class' => 'rmp-menu-wrap',
'menu_id' => 'rmp-menu-' . $this->menu_id,
'menu_class' => 'rmp-menu',
'menu' => $wp_menu_obj,
'depth' => $menu_depth,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'theme_location' => '',
'walker' => $walker,
'items_wrap' => '',
);
$param = apply_filters( 'rmp_nav_menu_args', $param, $wp_menu_obj->term_id, $menu_location );
return $param;
}
/**
* Function to return the correct wp menu name.
*
* @version 4.0.0
*
* @return string Name of wp menu.
*/
public function get_wp_menu_to_use() {
$menu = '';
// Set menu as per settings priority.
if ( ! empty( $this->options['different_menu_for_mobile'] ) && 'on' === $this->options['different_menu_for_mobile'] && wp_is_mobile() ) {
$menu = $this->options['menu_to_use_in_mobile'];
} elseif ( ! empty( $this->options['theme_location_menu'] ) && has_nav_menu( $this->options['theme_location_menu'] ) ) {
$menu = get_term( get_nav_menu_locations()[ $this->options['theme_location_menu'] ], 'nav_menu' )->slug;
} elseif ( ! empty( $this->options['menu_to_use'] ) ) {
$menu = $this->options['menu_to_use'];
} elseif ( ! empty( get_terms( 'nav_menu' )[0]->slug ) ) {
$menu = get_terms( 'nav_menu' )[0]->slug;
}
return $menu;
}
/**
* Function to get the location of menu.
*
* @return string Returns the menu location.
*/
public function get_wp_menu_location() {
$menu = $this->get_wp_menu_to_use();
if ( empty( $menu ) ) {
return;
}
$theme_location = null;
$menu_object = wp_get_nav_menu_object( $menu );
$theme_locations = get_nav_menu_locations();
foreach ( $theme_locations as $location => $value ) {
if ( $value === $menu_object->term_id ) {
$theme_location = $location;
break;
}
}
return $theme_location;
}
}
endif;