Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions assets/theme-mode/demo-theme-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,21 @@ function custom_theme_options() {
'condition' => '',
'operator' => 'and',
),
array(
'id' => 'demo_menu_select',
'label' => __( 'Menu Select', 'theme-text-domain' ),
'desc' => '<p>' . sprintf( __( 'This option type makes it possible for users to select a WordPress menu to use on a specific area.', 'theme-text-domain' ) ) . '</p>',
'std' => '',
'type' => 'menu-select',
'section' => 'option_types',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'min_max_step' => '',
'class' => '',
'condition' => '',
'operator' => 'and',
),
array(
'id' => 'demo_social_links',
'label' => __( 'Social Links', 'theme-text-domain' ),
Expand Down
5 changes: 3 additions & 2 deletions includes/ot-functions-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ function _filter_wp_kses_post( $add = true ) {
if ( ! empty( $input ) ) {
$input_safe = sanitize_text_field( $input );
}
} elseif ( 'radio' === $type || 'radio-image' === $type || 'select' === $type || 'sidebar-select' === $type ) {
} elseif ( 'radio' === $type || 'radio-image' === $type || 'select' === $type || 'sidebar-select' === $type || 'menu-select' === $type ) {
$input_safe = '';

if ( ! empty( $input ) ) {
Expand Down Expand Up @@ -2302,6 +2302,7 @@ function ot_option_types_array() {
'radio-image' => esc_html__( 'Radio Image', 'option-tree' ),
'select' => esc_html__( 'Select', 'option-tree' ),
'sidebar-select' => esc_html__( 'Sidebar Select', 'option-tree' ),
'menu-select' => esc_html__( 'Menu Select', 'option-tree' ),
'slider' => esc_html__( 'Slider', 'option-tree' ),
'social-links' => esc_html__( 'Social Links', 'option-tree' ),
'spacing' => esc_html__( 'Spacing', 'option-tree' ),
Expand Down Expand Up @@ -5057,7 +5058,7 @@ function ot_decode( $value ) {
preg_match( '/a:\d+:{.*?}/', $decoded, $array_matches, PREG_OFFSET_CAPTURE, 0 );

// Search for an object.
preg_match( '/O|C:\+?\d+:"[a-z0-9_]+":\+?\d+:/i', $decoded, $obj_matches, PREG_OFFSET_CAPTURE, 0 );
preg_match( '/O|C:\+?\d+:"[a-z0-9_]+":\+?\d+:/', $decoded, $obj_matches, PREG_OFFSET_CAPTURE, 0 );

// Prevent object injection or non arrays.
if ( $obj_matches || ! $array_matches ) {
Expand Down
61 changes: 61 additions & 0 deletions includes/ot-functions-option-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,67 @@ function ot_type_sidebar_select( $args = array() ) {
}
}

if ( ! function_exists( 'ot_type_menu_select' ) ) {

/**
* Menu Select option type.
*
* This option type bring us to have all Wordpress navigation menus as a select box in the
* Option panel.
*
* Suppose you want to create a mega menu in multi dimensions row and column or wanting
* To create, manage and show some custom menus in the some post or pages or even creating a dynamical menu.
* This functionality help us to do all of them.
*
* See @ot_display_by_type to see the full list of available arguments.
*
* @param array $args An array of arguments.
*
* @access public
* @since 2.7.3
*/
function ot_type_menu_select( $args = array() ) {

// Turns arguments array into variables.
extract( $args ); // phpcs:ignore

// Verify a description.
$has_desc = ! empty( $field_desc ) ? true : false;

// Format setting outer wrapper.
echo '<div class="format-setting type-menu-select ' . ( $has_desc ? 'has-desc' : 'no-desc' ) . '">';

/* description */
echo $has_desc ? '<div class="description">' . wp_kses_post( htmlspecialchars_decode( $field_desc ) ) . '</div>' : '';

// Format setting inner wrapper.
echo '<div class="format-setting-inner">';

// Build menu select.
echo '<select name="' . esc_attr( $field_name ) . '" id="' . esc_attr( $field_id ) . '" class="option-tree-ui-select ' . esc_attr( $field_class ) . '">';

// Query menus array
$my_menus = wp_get_nav_menus();

// Has menus.
if ( is_array( $my_menus ) && ! empty( $my_menus ) ) {
echo '<option value="">-- ' . esc_html__( 'Choose One', 'option-tree' ) . ' --</option>';
foreach ( $my_menus as $my_menu ) {
$menu_name = ! empty( $my_menu->name ) ? $my_menu->name : 'Untitled';
echo '<option value="' . esc_attr( $my_menu->term_id ) . '" ' . selected( $field_value, $my_menu->term_id, false ) . '>' . esc_html( $menu_name ) . '</option>';
}
} else {
echo '<option value="">' . esc_html__( 'No Menus Found', 'option-tree' ) . '</option>';
}

echo '</select>';

echo '</div>';

echo '</div>';
}
}

if ( ! function_exists( 'ot_type_slider' ) ) {

/**
Expand Down