PluginProbe
Essential Widgets / 2.2
Essential Widgets v2.2
3.2.1 3.3 3.2 trunk 1.0.0 1.0.1 1.1 1.2 1.2.1 1.2.2 1.3 1.4 1.4.1 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 1.9 2.0 2.1 2.2 All 31 releases
essential-widgets / includes / ew-block / blocks / ew-menu / index.php

index.php in Essential Widgets 2.2, at includes/ew-block/blocks/ew-menu/index.php

133 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Hook the post rendering to the block
4 if ( function_exists( 'register_block_type' ) ) :
5 register_block_type(
6 'ew-block/ew-menu',
7 array(
8 'attributes' => array(
9 'title' => array(
10 'type' => 'string',
11 'default' => esc_html__( 'Navigation', 'essential-widgets' ),
12 ),
13 'menu' => array(
14 'type' => 'string',
15 'default' => '',
16 ),
17 'container' => array(
18 'type' => 'string',
19 'default' => 'div',
20 ),
21 'container_id' => array(
22 'type' => 'string',
23 'default' => '',
24 ),
25 'container_class' => array(
26 'type' => 'string',
27 'default' => '',
28 ),
29 'menu_id' => array(
30 'type' => 'string',
31 'default' => '',
32 ),
33 'menu_class' => array(
34 'type' => 'string',
35 'default' => 'nav-menu',
36 ),
37 'depth' => array(
38 'type' => 'number',
39 'default' => 0,
40 ),
41 'before' => array(
42 'type' => 'string',
43 'default' => '',
44 ),
45 'after' => array(
46 'type' => 'string',
47 'default' => '',
48 ),
49 'link_before' => array(
50 'type' => 'string',
51 'default' => '',
52 ),
53 'link_after' => array(
54 'type' => 'string',
55 'default' => '',
56 ),
57 'fallback_cb' => array(
58 'type' => 'string',
59 'default' => 'wp_page_menu',
60 ),
61 'is_block' => array(
62 'type' => 'boolean',
63 'default' => true,
64 ),
65
66 ),
67 'render_callback' => 'ew_menu_render_shortcode',
68 )
69 );
70 endif;
71
72 if ( ! function_exists( 'ew_menu_render_shortcode' ) ) :
73 add_shortcode( 'ew-menu', 'ew_menu_render_shortcode' );
74 function ew_menu_render_shortcode( $atts ) {
75 $instance['title'] = $atts['title'];
76 $instance['menu'] = $atts['menu'];
77 $instance['container'] = $atts['container'];
78 $instance['container_id'] = $atts['container_id'];
79 $instance['container_class'] = $atts['container_class'];
80 $instance['menu_id'] = $atts['menu_id'];
81 $instance['menu_class'] = $atts['menu_class'];
82 $instance['depth'] = $atts['depth'];
83 $instance['before'] = $atts['before'];
84 $instance['after'] = $atts['after'];
85 $instance['link_before'] = $atts['link_before'];
86 $instance['link_after'] = $atts['link_after'];
87 $instance['fallback_cb'] = $atts['fallback_cb'];
88 $instance['is_block'] = $atts['is_block'];
89
90 $ew_menu = new EW_Menus();
91
92 return $ew_menu->shortcode( $instance );
93 }
94 endif;
95
96
97 if ( ! function_exists( 'ew_menu_list' ) ) :
98 /**
99 * Get nav menus for select option via custom REST API!
100 *
101 * @return array|null Array of nav menus object with label and value pair, * or null if none.
102 */
103 function ew_menu_list() {
104 $menus = wp_get_nav_menus();
105
106 $menu_list = array();
107
108 foreach ( $menus as $menu ) {
109 $object = new stdClass();
110 $object->label = $menu->name;
111 $object->value = $menu->term_id;
112 $menu_list[] = $object;
113 }
114
115 return $menu_list;
116 }
117
118 add_action(
119 'rest_api_init',
120 function () {
121 register_rest_route(
122 'ew-rest/v1',
123 'ew-menu-list',
124 array(
125 'methods' => 'GET',
126 'callback' => 'ew_menu_list',
127 'permission_callback' => '__return_true', // for public use
128 )
129 );
130 }
131 );
132 endif;
133