PluginProbe
Boxzilla – WordPress Popup Builder / 3.4.5
Boxzilla – WordPress Popup Builder v3.4.5
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.5, at src/admin/class-menu.php

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