PluginProbe
Boxzilla – WordPress Popup Builder / 3.4.7
Boxzilla – WordPress Popup Builder v3.4.7
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
boxzilla / src / admin / class-menu.php

class-menu.php in Boxzilla – WordPress Popup Builder 3.4.7, at src/admin/class-menu.php

139 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Boxzilla\Admin;
4
5 class Menu
6 {
7 public function init(): void
8 {
9 add_action('admin_head-nav-menus.php', [ $this, 'add_nav_menu_meta_boxes' ]);
10
11 // Include custom items to customizer nav menu settings.
12 add_filter('customize_nav_menu_available_item_types', [ $this, 'register_customize_nav_menu_item_types' ]);
13 add_filter('customize_nav_menu_available_items', [ $this, 'register_customize_nav_menu_items' ], 10, 4);
14 }
15
16 /**
17 * Add custom nav meta box.
18 *
19 * Adapted from http://www.johnmorrisonline.com/how-to-add-a-fully-functional-custom-meta-box-to-wordpress-navigation-menus/.
20 */
21 public function add_nav_menu_meta_boxes()
22 {
23 add_meta_box('boxzilla_nav_link', esc_html__('Boxzilla Pop-ups', 'boxzilla'), [ $this, 'nav_menu_links' ], 'nav-menus', 'side', 'low');
24 }
25
26 private function get_boxes()
27 {
28 $q = new \WP_Query();
29 $posts = $q->query(
30 [
31 'post_type' => 'boxzilla-box',
32 'post_status' => 'publish',
33 'posts_per_page' => -1,
34 'ignore_sticky_posts' => true,
35 'no_found_rows' => true,
36 ]
37 );
38 return $posts;
39 }
40
41 /**
42 * Output menu links.
43 */
44 public function nav_menu_links()
45 {
46 $posts = $this->get_boxes();
47 if (count($posts) === 0) {
48 return;
49 }
50
51 ?>
52 <div id="posttype-boxzilla-boxes" class="posttypediv">
53 <div id="tabs-panel-boxzilla-boxes" class="tabs-panel tabs-panel-active">
54 <ul id="boxzilla-boxes-checklist" class="categorychecklist form-no-clear">
55 <?php
56 $i = -1;
57 foreach ($posts as $key => $post) :
58 ?>
59 <li>
60 <label class="menu-item-title">
61 <input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo $i; ?>][menu-item-object-id]" value="<?php echo $i; ?>" /> <?php echo esc_html($post->post_title); ?>
62 </label>
63 <input type="hidden" class="menu-item-type" name="menu-item[<?php echo $i; ?>][menu-item-type]" value="custom" />
64 <input type="hidden" class="menu-item-title" name="menu-item[<?php echo $i; ?>][menu-item-title]" value="<?php echo esc_attr($post->post_title); ?>" />
65 <input type="hidden" class="menu-item-url" name="menu-item[<?php echo $i; ?>][menu-item-url]" value="<?php echo "#boxzilla-{$post->ID}"; ?>" />
66 <input type="hidden" class="menu-item-classes" name="menu-item[<?php echo $i; ?>][menu-item-classes]" />
67 </li>
68 <?php
69 $i--;
70 endforeach;
71 ?>
72 </ul>
73 </div>
74 <p class="button-controls">
75 <span class="list-controls">
76 </span>
77 <span class="add-to-menu">
78 <button type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'boxzilla'); ?>" name="add-post-type-menu-item" id="submit-posttype-boxzilla-boxes"><?php esc_html_e('Add to menu', 'boxzilla'); ?></button>
79 <span class="spinner"></span>
80 </span>
81 </p>
82 </div>
83 <?php
84 }
85
86 /**
87 * Register customize new nav menu item types.
88 *
89 * @since 3.1.0
90 * @param array $item_types Menu item types.
91 * @return array
92 */
93 public function register_customize_nav_menu_item_types($item_types)
94 {
95 $item_types[] = [
96 'title' => esc_html__('Boxzilla Pop-ups', 'boxzilla'),
97 'type_label' => esc_html__('Boxzilla Pop-ups', 'boxzilla'),
98 'type' => 'boxzilla_nav',
99 'object' => 'boxzilla_box',
100 ];
101
102 return $item_types;
103 }
104
105 /**
106 * Register account endpoints to customize nav menu items.
107 *
108 * @since 3.1.0
109 * @param array $items List of nav menu items.
110 * @param string $type Nav menu type.
111 * @param string $object Nav menu object.
112 * @param integer $page Page number.
113 * @return array
114 */
115 public function register_customize_nav_menu_items($items = [], $type = '', $object = '', $page = 0)
116 {
117 if ('boxzilla_box' !== $object) {
118 return $items;
119 }
120
121 // Don't allow pagination since all items are loaded at once.
122 if (0 < $page) {
123 return $items;
124 }
125
126 $boxes = $this->get_boxes();
127 foreach ($boxes as $i => $post) {
128 $items[] = [
129 'id' => $i,
130 'title' => $post->post_title,
131 'type_label' => esc_html__('Custom Link', 'boxzilla'),
132 'url' => "#boxzilla-{$post->ID}",
133 ];
134 }
135
136 return $items;
137 }
138 }
139