| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
die('-1'); |
| 4 |
} |
| 5 |
|
| 6 |
function quadmenu_load_widget() { |
| 7 |
register_widget('quadmenu_widget'); |
| 8 |
} |
| 9 |
|
| 10 |
add_action('widgets_init', 'quadmenu_load_widget'); |
| 11 |
|
| 12 |
class QuadMenu_Widget extends WP_Widget { |
| 13 |
|
| 14 |
function __construct() { |
| 15 |
self::QuadMenu_Widget(); |
| 16 |
} |
| 17 |
|
| 18 |
function QuadMenu_Widget() { |
| 19 |
|
| 20 |
$widget_ops = array('classname' => 'widget_quadmenu_widget', 'description' => esc_html__('A widget that displays the menu in the sidebar.', 'quadmenu')); |
| 21 |
|
| 22 |
$control_ops = array('width' => 200, 'height' => 250, 'id_base' => 'quadmenu_widget'); |
| 23 |
|
| 24 |
parent::__construct('quadmenu_widget', esc_html__('QuadMenu Widget', 'quadmenu'), $widget_ops, $control_ops); |
| 25 |
} |
| 26 |
|
| 27 |
function widget($args, $instance) { |
| 28 |
|
| 29 |
extract($args); |
| 30 |
|
| 31 |
extract(shortcode_atts(array('menu' => '', 'theme' => '', 'layout' => 'inherit'), $instance)); |
| 32 |
|
| 33 |
echo $before_widget; |
| 34 |
|
| 35 |
$args = array( |
| 36 |
'echo' => false, |
| 37 |
'menu' => $menu, |
| 38 |
'theme' => $theme, |
| 39 |
'layout' => $layout, |
| 40 |
'theme_location' => 'widget', |
| 41 |
); |
| 42 |
|
| 43 |
if (wp_doing_ajax()) { |
| 44 |
$args['layout_classes'] = 'js'; |
| 45 |
} |
| 46 |
|
| 47 |
echo quadmenu($args); |
| 48 |
|
| 49 |
echo $after_widget; |
| 50 |
} |
| 51 |
|
| 52 |
function update($new_instance, $old_instance) { |
| 53 |
$instance = $old_instance; |
| 54 |
$instance['theme'] = strip_tags($new_instance['theme']); |
| 55 |
$instance['menu'] = strip_tags($new_instance['menu']); |
| 56 |
$instance['layout'] = strip_tags($new_instance['layout']); |
| 57 |
return $instance; |
| 58 |
} |
| 59 |
|
| 60 |
function themes($current = false) { |
| 61 |
|
| 62 |
global $quadmenu_themes; |
| 63 |
|
| 64 |
foreach ($quadmenu_themes as $key => $theme) { |
| 65 |
?> |
| 66 |
<option value="<?php echo esc_attr($key); ?>" <?php echo selected($key, $current); ?>><?php echo esc_html($theme); ?></option> |
| 67 |
<?php |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
function menus($current = false) { |
| 72 |
|
| 73 |
$menus = wp_get_nav_menus(); |
| 74 |
|
| 75 |
foreach ($menus as $key => $menu) { |
| 76 |
?> |
| 77 |
<option value="<?php echo esc_attr($menu->term_id); ?>" <?php echo selected($menu->term_id, $current); ?>><?php echo esc_html($menu->name); ?></option> |
| 78 |
<?php |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
function layouts($current = false) { |
| 83 |
|
| 84 |
$layouts = array( |
| 85 |
'embed' => esc_html__('Embed', 'quadmenu'), |
| 86 |
'collapse' => esc_html__('Collapse', 'quadmenu'), |
| 87 |
'offcanvas' => esc_html__('Offcanvas', 'quadmenu'), |
| 88 |
'vertical' => esc_html__('Vertical', 'quadmenu'), |
| 89 |
'inherit' => esc_html__('Inherit', 'quadmenu'), |
| 90 |
); |
| 91 |
|
| 92 |
foreach ($layouts as $key => $layout) { |
| 93 |
?> |
| 94 |
<option value="<?php echo esc_attr($key); ?>" <?php echo selected($key, $current); ?>><?php echo esc_html($layout); ?></option> |
| 95 |
<?php |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
function form($instance) { |
| 100 |
|
| 101 |
$defaults = array( |
| 102 |
'location' => '', |
| 103 |
'menu' => '', |
| 104 |
'layout' => '', |
| 105 |
'theme' => '', |
| 106 |
); |
| 107 |
|
| 108 |
$instance = wp_parse_args((array) $instance, $defaults); |
| 109 |
?> |
| 110 |
<p> |
| 111 |
<label for="<?php echo $this->get_field_id('menu'); ?>"><?php esc_html_e('Menu', 'quadmenu'); ?></label> |
| 112 |
<select id="<?php echo $this->get_field_id('menu'); ?>" name="<?php echo $this->get_field_name('menu'); ?>" class="widefat"> |
| 113 |
<?php echo $this->menus($instance['menu']); ?> |
| 114 |
</select> |
| 115 |
</p> |
| 116 |
<p> |
| 117 |
<label for="<?php echo $this->get_field_id('layout'); ?>"><?php esc_html_e('Layout', 'quadmenu'); ?></label> |
| 118 |
<select id="<?php echo $this->get_field_id('layout'); ?>" name="<?php echo $this->get_field_name('layout'); ?>" class="widefat"> |
| 119 |
<?php echo $this->layouts($instance['layout']); ?> |
| 120 |
</select> |
| 121 |
</p> |
| 122 |
<p> |
| 123 |
<label for="<?php echo $this->get_field_id('theme'); ?>"><?php esc_html_e('Theme', 'quadmenu'); ?></label> |
| 124 |
<select id="<?php echo $this->get_field_id('theme'); ?>" name="<?php echo $this->get_field_name('theme'); ?>" class="widefat"> |
| 125 |
<?php echo $this->themes($instance['theme']); ?> |
| 126 |
</select> |
| 127 |
</p> |
| 128 |
<?php |
| 129 |
} |
| 130 |
|
| 131 |
} |
| 132 |
|