PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.5.3
JetFormBuilder — Dynamic Blocks Form Builder v1.5.3
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / framework / admin-bar / jet-admin-bar.php
jetformbuilder / framework / admin-bar Last commit date
jet-admin-bar.php 4 years ago
jet-admin-bar.php
325 lines
1 <?php
2 /**
3 * Admin Bar module
4 *
5 * Version: 1.0.2
6 */
7
8 // If this file is called directly, abort.
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 if ( ! class_exists( 'Jet_Admin_Bar' ) ) {
14
15 /**
16 * Admin Bar management module.
17 */
18 class Jet_Admin_Bar {
19
20 /**
21 * A reference to an instance of this class.
22 *
23 * @access private
24 * @var object
25 */
26 private static $instance = null;
27
28 /**
29 * A reference to an instance of this class.
30 *
31 * @access private
32 * @var object
33 */
34 public $args = array();
35
36 /**
37 * Module version.
38 *
39 * @var string
40 */
41 protected $version = '1.0.2';
42
43 private $items = array();
44
45 private $default_parent_item = 'jet_plugins';
46
47 /**
48 * Constructor.
49 *
50 * @param array $args
51 * @access public
52 * @return void
53 */
54 public function __construct( $args = array() ) {
55
56 if ( is_admin() || ! is_admin_bar_showing() ) {
57 return;
58 }
59
60 if ( ! current_user_can( 'manage_options' ) ) {
61 return;
62 }
63
64 remove_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
65
66 add_action( 'init', array( $this, 'register_default_items' ) );
67 add_action( 'admin_bar_menu', array( $this, 'register_items' ), 99 );
68
69 add_action( 'wp_enqueue_scripts', array( $this, 'add_inline_style' ) );
70 }
71
72 /**
73 * Register default items.
74 */
75 public function register_default_items() {
76 $this->register_parent_item(
77 $this->default_parent_item,
78 array(
79 'title' => 'Edit with JetPlugins',
80 )
81 );
82 }
83
84 /**
85 * Register items.
86 *
87 * @param WP_Admin_Bar $wp_admin_bar
88 */
89 public function register_items( $wp_admin_bar ) {
90
91 foreach ( $this->items as $parent_id => $parent_args ) {
92
93 if ( empty( $parent_args['children'] ) ) {
94 continue;
95 }
96
97 $_parent_args = $parent_args;
98 $_parent_args['id'] = $parent_id;
99
100 unset( $_parent_args['children'] );
101
102 $wp_admin_bar->add_menu( $_parent_args );
103
104 // Register children items.
105 $parent_args['children'] = $this->sort_children_items( $parent_args['children'] );
106
107 foreach ( $parent_args['children'] as $child_id => $child_args ) {
108 $child_args['id'] = $child_id;
109 $child_args = $this->prepare_child_item_args( $child_args );
110 $wp_admin_bar->add_menu( $child_args );
111 }
112 }
113
114 }
115
116 /**
117 * Sorting children items.
118 *
119 * @param array $children
120 * @return array
121 */
122 public function sort_children_items( $children ) {
123 $children = wp_list_sort(
124 $children,
125 array(
126 'priority' => 'ASC',
127 'sub_title' => 'ASC',
128 ),
129 null,
130 true
131 );
132 return $children;
133 }
134
135 /**
136 * Register parent item.
137 *
138 * @param string $id
139 * @param array $args
140 */
141 public function register_parent_item( $id = null, $args = array() ) {
142 $args['id'] = $id;
143 $this->items[ $id ] = $args;
144 }
145
146 /**
147 * Register child item.
148 *
149 * @param string $id
150 * @param array $args
151 */
152 public function register_item( $id = null, $args = array() ) {
153
154 $default_args = array(
155 'title' => '',
156 'sub_title' => '',
157 'href' => '',
158 'parent' => $this->default_parent_item,
159
160 // Additional arguments
161 'class' => '',
162 'target_blank' => true,
163 'priority' => 10,
164 );
165
166 $args = array_merge( $default_args, $args );
167
168 if ( $this->has_item( $id, $args ) ) {
169 return;
170 }
171
172 $this->items[ $args['parent'] ]['children'][ $id ] = $args;
173 }
174
175 /**
176 * Prepare child item arguments.
177 *
178 * @param array $args
179 * @return array
180 */
181 public function prepare_child_item_args( $args ) {
182
183 if ( ! empty( $args['sub_title'] ) ) {
184 $args['title'] = sprintf(
185 '<span class="jet-ab-title">%1$s</span><span class="jet-ab-sub-title">%2$s</span>',
186 $args['title'],
187 $args['sub_title']
188 );
189 }
190
191 $classes = array( 'jet-ab-item' );
192
193 if ( ! empty( $args['class'] ) ) {
194 $classes[] = $args['class'];
195 }
196
197 $args['meta']['class'] = join( ' ', $classes );
198
199 if ( $args['target_blank'] ) {
200 $args['meta']['target'] = '_blank';
201 }
202
203 unset( $args['sub_title'] );
204 unset( $args['class'] );
205 unset( $args['target_blank'] );
206 unset( $args['priority'] );
207
208 return $args;
209 }
210
211 /**
212 * Register child item by post ID.
213 *
214 * @param int $post_id
215 * @param array $args
216 */
217 public function register_post_item( $post_id = null, $args = array() ) {
218
219 if ( empty( $post_id ) ) {
220 return;
221 }
222
223 $id = 'edit_post_' . $post_id;
224
225 if ( $this->has_item( $id, $args ) ) {
226 return;
227 }
228
229 $post = get_post( $post_id );
230
231 if ( empty( $post ) ) {
232 return;
233 }
234
235 $default_args = array(
236 'title' => $post->post_title,
237 'sub_title' => $this->get_post_type_label( $post->post_type ),
238 'href' => $this->get_edit_url( $post_id ),
239 );
240
241 $args = array_merge( $default_args, $args );
242
243 $this->register_item( $id, $args );
244 }
245
246 public function has_item( $id, $args ) {
247 $args['parent'] = ! empty( $args['parent'] ) ? $args['parent'] : $this->default_parent_item;
248 return isset( $this->items[ $args['parent'] ]['children'][ $id ] );
249 }
250
251 public function get_post_type_label( $post_type ) {
252 $post_type_obj = get_post_type_object( $post_type );
253 return $post_type_obj->labels->singular_name;
254 }
255
256 public function get_edit_url( $id ) {
257 $is_build_with_elementor = ! ! get_post_meta( $id, '_elementor_edit_mode', true );
258
259 if ( $is_build_with_elementor && class_exists( 'Elementor\Plugin' ) ) {
260 $edit_url = Elementor\Plugin::instance()->documents->get( $id )->get_edit_url();
261 } else {
262 $edit_url = get_edit_post_link( $id, '' );
263 }
264
265 return $edit_url;
266 }
267
268 public function add_inline_style() {
269 $css = '
270 #wpadminbar #wp-admin-bar-jet_plugins > .ab-item::before {
271 content: "";
272 width: 20px;
273 height: 18px;
274 top: 3px;
275 background-size: contain;
276 background-repeat: no-repeat;
277 background-position: center center;
278 background-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0iI2E3YWFhZCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTIwIDFINEMyLjM0MzE1IDEgMSAyLjM0MzE1IDEgNFYyMEMxIDIxLjY1NjkgMi4zNDMxNSAyMyA0IDIzSDIwQzIxLjY1NjkgMjMgMjMgMjEuNjU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OCAxMy40MDU5IDEzLjI5MzIgMTMuNDA1OUMxMy4wMjY4IDEzLjQwNTkgMTIuNzgzMyAxMy41MDkyIDEyLjYwNTcgMTMuNjgwNUMxMi4wMDY5IDE0LjA4MSAxMS4yMTAyIDE0LjE0MzkgMTAuNTM3OCAxMy43NzYyTDE0LjU2NDQgMTEuOTE5OEMxNC43OTc4IDExLjg0OTMgMTUuMDA1OSAxMS42OTMxIDE1LjEzNTMgMTEuNDY2NEMxNS4yOTI2IDExLjE5NjkgMTUuMzA3OCAxMC44ODcxIDE1LjIwMzggMTAuNjE3NlpNMTIuNDg2NCAxMC4zMTUzQzEyLjYwNTcgMTAuMzgzMyAxMi43MTIyIDEwLjQ2MTQgMTIuODExMiAxMC41NDcxTDkuNDk3NTQgMTIuMDcwOUM5LjQ4OTkzIDExLjcyMDggOS41NzYyIDExLjM2NTcgOS43NjM5NSAxMS4wNDA3QzEwLjMxNDUgMTAuMDkzNyAxMS41MzI0IDkuNzY4NzQgMTIuNDg2NCAxMC4zMTUzWiIgZmlsbD0iI2E3YWFhZCIvPjwvc3ZnPg==")!important;
279 }
280 #wpadminbar #wp-admin-bar-jet_plugins > .ab-sub-wrapper {
281 max-height: calc(100vh - 50px);
282 overflow-y: auto;
283 }
284 #wpadminbar .jet-ab-item .ab-item {
285 display: flex;
286 justify-content: space-between;
287 align-items: center;
288 gap: 10px;
289 }
290 #wpadminbar .jet-ab-title {
291 white-space: nowrap;
292 text-overflow: ellipsis;
293 overflow: hidden;
294 width: 100%;
295 }
296 #wpadminbar .jet-ab-sub-title {
297 padding: 4px 8px;
298 font-size: 11px;
299 line-height: 9px;
300 background: #55595c;
301 border-radius: 3px;
302 }
303 ';
304
305 wp_add_inline_style( 'admin-bar', $css );
306 }
307
308 /**
309 * Returns the instance.
310 *
311 * @param array $args
312 * @access public
313 * @return object
314 */
315 public static function get_instance( array $args = array() ) {
316 // If the single instance hasn't been set, set it now.
317 if ( null == self::$instance ) {
318 self::$instance = new self( $args );
319 }
320
321 return self::$instance;
322 }
323 }
324 }
325