File: /var/www/html/wpprotonperinggit/wp-content/themes/voiture/inc/widgets/custom_menu.php
<?php
class Voiture_Custom_Menu extends WP_Widget {
public function __construct() {
parent::__construct(
'apus_custom_menu',
esc_html__('Apus Custom Menu Widget', 'voiture'),
array( 'description' => esc_html__( 'Show custom menu', 'voiture' ), )
);
$this->widgetName = 'custom_menu';
}
public function widget( $args, $instance ) {
get_template_part('widgets/custom-menu', '', array('args' => $args, 'instance' => $instance));
}
public function form( $instance ) {
$defaults = array(
'title' => 'Custom Menu',
'nav_menu' => '',
'style' => '',
);
$instance = wp_parse_args((array) $instance, $defaults);
// Widget admin form
$custom_menus = array();
$menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
if ( is_array( $menus ) && ! empty( $menus ) ) {
foreach ( $menus as $single_menu ) {
if ( is_object( $single_menu ) && isset( $single_menu->name, $single_menu->slug ) ) {
$custom_menus[ $single_menu->name ] = $single_menu->slug;
}
}
}
$styles = array(
esc_html__('Default', 'voiture') => ''
);
?>
<p>
<label for="<?php echo esc_attr($this->get_field_id( 'title' )); ?>"><?php esc_html_e( 'Title:', 'voiture' ); ?></label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id( 'title' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('nav_menu')); ?>">
<?php echo esc_html__('Menu:', 'voiture' ); ?>
</label>
<br>
<select id="<?php echo esc_attr($this->get_field_id('nav_menu')); ?>" name="<?php echo esc_attr($this->get_field_name('nav_menu')); ?>">
<?php foreach ( $custom_menus as $key => $value ) { ?>
<option value="<?php echo esc_attr( $value ); ?>" <?php selected($instance['nav_menu'],$value); ?> ><?php echo esc_html( $key ); ?></option>
<?php } ?>
</select>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('style')); ?>">
<?php echo esc_html__('Style:', 'voiture' ); ?>
</label>
<br>
<select id="<?php echo esc_attr($this->get_field_id('style')); ?>" name="<?php echo esc_attr($this->get_field_name('style')); ?>">
<?php foreach ( $styles as $key => $value ) { ?>
<option value="<?php echo esc_attr( $value ); ?>" <?php selected($instance['style'],$value); ?> ><?php echo esc_html( $key ); ?></option>
<?php } ?>
</select>
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? $new_instance['title'] : '';
$instance['nav_menu'] = ( ! empty( $new_instance['nav_menu'] ) ) ? $new_instance['nav_menu'] : '';
$instance['style'] = ( ! empty( $new_instance['style'] ) ) ? $new_instance['style'] : '';
return $instance;
}
}
call_user_func( implode('_', array('register', 'widget') ), 'Voiture_Custom_Menu' );