PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.2
Jetpack – WP Security, Backup, Speed, & Growth v6.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / custom-post-types / nova.php

nova.php in Jetpack – WP Security, Backup, Speed, & Growth 6.2, at modules/custom-post-types/nova.php

1,300 lines 40.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Put the following code in your theme's Food Menu Page Template to customize the markup of the menu.
5
6 if ( class_exists( 'Nova_Restaurant' ) ) {
7 Nova_Restaurant::init( array(
8 'menu_tag' => 'section',
9 'menu_class' => 'menu-items',
10 'menu_header_tag' => 'header',
11 'menu_header_class' => 'menu-group-header',
12 'menu_title_tag' => 'h1',
13 'menu_title_class' => 'menu-group-title',
14 'menu_description_tag' => 'div',
15 'menu_description_class' => 'menu-group-description',
16 ) );
17 }
18
19 */
20
21 /* @todo
22
23 Bulk/Quick edit response of Menu Item rows is broken.
24
25 Drag and Drop reordering.
26 */
27
28 class Nova_Restaurant {
29 const MENU_ITEM_POST_TYPE = 'nova_menu_item';
30 const MENU_ITEM_LABEL_TAX = 'nova_menu_item_label';
31 const MENU_TAX = 'nova_menu';
32
33 public $version = '0.1';
34
35 protected $default_menu_item_loop_markup = array(
36 'menu_tag' => 'section',
37 'menu_class' => 'menu-items',
38 'menu_header_tag' => 'header',
39 'menu_header_class' => 'menu-group-header',
40 'menu_title_tag' => 'h1',
41 'menu_title_class' => 'menu-group-title',
42 'menu_description_tag' => 'div',
43 'menu_description_class' => 'menu-group-description',
44 );
45
46 protected $menu_item_loop_markup = array();
47 protected $menu_item_loop_last_term_id = false;
48 protected $menu_item_loop_current_term = false;
49
50 static function init( $menu_item_loop_markup = array() ) {
51 static $instance = false;
52
53 if ( !$instance ) {
54 $instance = new Nova_Restaurant;
55 }
56
57 if ( $menu_item_loop_markup ) {
58 $instance->menu_item_loop_markup = wp_parse_args( $menu_item_loop_markup, $instance->default_menu_item_loop_markup );
59 }
60
61 return $instance;
62 }
63
64 function __construct() {
65 if ( ! $this->site_supports_nova() )
66 return;
67
68 $this->register_taxonomies();
69 $this->register_post_types();
70 add_action( 'admin_menu', array( $this, 'add_admin_menus' ) );
71 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_nova_styles' ) );
72 add_action( 'admin_head', array( $this, 'set_custom_font_icon' ) );
73
74 // Always sort menu items correctly
75 add_action( 'parse_query', array( $this, 'sort_menu_item_queries_by_menu_order' ) );
76 add_filter( 'posts_results', array( $this, 'sort_menu_item_queries_by_menu_taxonomy' ), 10, 2 );
77
78 add_action( 'wp_insert_post', array( $this, 'add_post_meta' ) );
79
80 $this->menu_item_loop_markup = $this->default_menu_item_loop_markup;
81
82 // Only output our Menu Item Loop Markup on a real blog view. Not feeds, XML-RPC, admin, etc.
83 add_filter( 'template_include', array( $this, 'setup_menu_item_loop_markup__in_filter' ) );
84
85 add_filter( 'enter_title_here', array( $this, 'change_default_title' ) );
86 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
87 add_filter( 'dashboard_glance_items', array( $this, 'add_to_dashboard' ) );
88 }
89
90 /**
91 * Should this Custom Post Type be made available?
92 */
93 function site_supports_nova() {
94 // If we're on WordPress.com, and it has the menu site vertical.
95 if ( function_exists( 'site_vertical' ) && 'nova_menu' == site_vertical() )
96 return true;
97
98 // Else, if the current theme requests it.
99 if ( current_theme_supports( self::MENU_ITEM_POST_TYPE ) )
100 return true;
101
102 // Otherwise, say no unless something wants to filter us to say yes.
103 /**
104 * Allow something else to hook in and enable this CPT.
105 *
106 * @module custom-content-types
107 *
108 * @since 2.6.0
109 *
110 * @param bool false Whether or not to enable this CPT.
111 * @param string $var The slug for this CPT.
112 */
113 return (bool) apply_filters( 'jetpack_enable_cpt', false, self::MENU_ITEM_POST_TYPE );
114 }
115
116 /* Setup */
117
118 /**
119 * Register Taxonomies and Post Type
120 */
121 function register_taxonomies() {
122 if ( ! taxonomy_exists( self::MENU_ITEM_LABEL_TAX ) ) {
123 register_taxonomy( self::MENU_ITEM_LABEL_TAX, self::MENU_ITEM_POST_TYPE, array(
124 'labels' => array(
125 /* translators: this is about a food menu */
126 'name' => __( 'Menu Item Labels', 'jetpack' ),
127 /* translators: this is about a food menu */
128 'singular_name' => __( 'Menu Item Label', 'jetpack' ),
129 /* translators: this is about a food menu */
130 'search_items' => __( 'Search Menu Item Labels', 'jetpack' ),
131 'popular_items' => __( 'Popular Labels', 'jetpack' ),
132 /* translators: this is about a food menu */
133 'all_items' => __( 'All Menu Item Labels', 'jetpack' ),
134 /* translators: this is about a food menu */
135 'edit_item' => __( 'Edit Menu Item Label', 'jetpack' ),
136 /* translators: this is about a food menu */
137 'view_item' => __( 'View Menu Item Label', 'jetpack' ),
138 /* translators: this is about a food menu */
139 'update_item' => __( 'Update Menu Item Label', 'jetpack' ),
140 /* translators: this is about a food menu */
141 'add_new_item' => __( 'Add New Menu Item Label', 'jetpack' ),
142 /* translators: this is about a food menu */
143 'new_item_name' => __( 'New Menu Item Label Name', 'jetpack' ),
144 'separate_items_with_commas' => __( 'For example, spicy, favorite, etc. <br /> Separate Labels with commas', 'jetpack' ),
145 'add_or_remove_items' => __( 'Add or remove Labels', 'jetpack' ),
146 'choose_from_most_used' => __( 'Choose from the most used Labels', 'jetpack' ),
147 'items_list_navigation' => __( 'Menu item label list navigation', 'jetpack' ),
148 'items_list' => __( 'Menu item labels list', 'jetpack' ),
149 ),
150 'no_tagcloud' => __( 'No Labels found', 'jetpack' ),
151 'hierarchical' => false,
152 ) );
153 }
154
155 if ( ! taxonomy_exists( self::MENU_TAX ) ) {
156 register_taxonomy( self::MENU_TAX, self::MENU_ITEM_POST_TYPE, array(
157 'labels' => array(
158 /* translators: this is about a food menu */
159 'name' => __( 'Menu Sections', 'jetpack' ),
160 /* translators: this is about a food menu */
161 'singular_name' => __( 'Menu Section', 'jetpack' ),
162 /* translators: this is about a food menu */
163 'search_items' => __( 'Search Menu Sections', 'jetpack' ),
164 /* translators: this is about a food menu */
165 'all_items' => __( 'All Menu Sections', 'jetpack' ),
166 /* translators: this is about a food menu */
167 'parent_item' => __( 'Parent Menu Section', 'jetpack' ),
168 /* translators: this is about a food menu */
169 'parent_item_colon' => __( 'Parent Menu Section:', 'jetpack' ),
170 /* translators: this is about a food menu */
171 'edit_item' => __( 'Edit Menu Section', 'jetpack' ),
172 /* translators: this is about a food menu */
173 'view_item' => __( 'View Menu Section', 'jetpack' ),
174 /* translators: this is about a food menu */
175 'update_item' => __( 'Update Menu Section', 'jetpack' ),
176 /* translators: this is about a food menu */
177 'add_new_item' => __( 'Add New Menu Section', 'jetpack' ),
178 /* translators: this is about a food menu */
179 'new_item_name' => __( 'New Menu Sections Name', 'jetpack' ),
180 'items_list_navigation' => __( 'Menu section list navigation', 'jetpack' ),
181 'items_list' => __( 'Menu section list', 'jetpack' ),
182 ),
183 'rewrite' => array(
184 'slug' => 'menu',
185 'with_front' => false,
186 'hierarchical' => true,
187 ),
188 'hierarchical' => true,
189 'show_tagcloud' => false,
190 'query_var' => 'menu',
191 ) );
192 }
193 }
194
195 function register_post_types() {
196 if ( post_type_exists( self::MENU_ITEM_POST_TYPE ) ) {
197 return;
198 }
199
200 register_post_type( self::MENU_ITEM_POST_TYPE, array(
201 'description' => __( "Items on your restaurant's menu", 'jetpack' ),
202
203 'labels' => array(
204 /* translators: this is about a food menu */
205 'name' => __( 'Menu Items', 'jetpack' ),
206 /* translators: this is about a food menu */
207 'singular_name' => __( 'Menu Item', 'jetpack' ),
208 /* translators: this is about a food menu */
209 'menu_name' => __( 'Food Menus', 'jetpack' ),
210 /* translators: this is about a food menu */
211 'all_items' => __( 'Menu Items', 'jetpack' ),
212 /* translators: this is about a food menu */
213 'add_new' => __( 'Add One Item', 'jetpack' ),
214 /* translators: this is about a food menu */
215 'add_new_item' => __( 'Add Menu Item', 'jetpack' ),
216 /* translators: this is about a food menu */
217 'edit_item' => __( 'Edit Menu Item', 'jetpack' ),
218 /* translators: this is about a food menu */
219 'new_item' => __( 'New Menu Item', 'jetpack' ),
220 /* translators: this is about a food menu */
221 'view_item' => __( 'View Menu Item', 'jetpack' ),
222 /* translators: this is about a food menu */
223 'search_items' => __( 'Search Menu Items', 'jetpack' ),
224 /* translators: this is about a food menu */
225 'not_found' => __( 'No Menu Items found', 'jetpack' ),
226 /* translators: this is about a food menu */
227 'not_found_in_trash' => __( 'No Menu Items found in Trash', 'jetpack' ),
228 'filter_items_list' => __( 'Filter menu items list', 'jetpack' ),
229 'items_list_navigation' => __( 'Menu item list navigation', 'jetpack' ),
230 'items_list' => __( 'Menu items list', 'jetpack' ),
231 ),
232 'supports' => array(
233 'title',
234 'editor',
235 'thumbnail',
236 'excerpt',
237 ),
238 'rewrite' => array(
239 'slug' => 'item',
240 'with_front' => false,
241 'feeds' => false,
242 'pages' => false,
243 ),
244 'register_meta_box_cb' => array( $this, 'register_menu_item_meta_boxes' ),
245
246 'public' => true,
247 'show_ui' => true, // set to false to replace with custom UI
248 'menu_position' => 20, // below Pages
249 'capability_type' => 'page',
250 'map_meta_cap' => true,
251 'has_archive' => false,
252 'query_var' => 'item',
253 ) );
254 }
255
256
257 /**
258 * Update messages for the Menu Item admin.
259 */
260 function updated_messages( $messages ) {
261 global $post;
262
263 $messages[self::MENU_ITEM_POST_TYPE] = array(
264 0 => '', // Unused. Messages start at index 1.
265 /* translators: this is about a food menu */
266 1 => sprintf( __( 'Menu item updated. <a href="%s">View item</a>', 'jetpack' ), esc_url( get_permalink( $post->ID ) ) ),
267 2 => esc_html__( 'Custom field updated.', 'jetpack' ),
268 3 => esc_html__( 'Custom field deleted.', 'jetpack' ),
269 /* translators: this is about a food menu */
270 4 => esc_html__( 'Menu item updated.', 'jetpack' ),
271 /* translators: %s: date and time of the revision */
272 5 => isset( $_GET['revision'] ) ? sprintf( esc_html__( 'Menu item restored to revision from %s', 'jetpack' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
273 /* translators: this is about a food menu */
274 6 => sprintf( __( 'Menu item published. <a href="%s">View item</a>', 'jetpack' ), esc_url( get_permalink( $post->ID ) ) ),
275 /* translators: this is about a food menu */
276 7 => esc_html__( 'Menu item saved.', 'jetpack' ),
277 /* translators: this is about a food menu */
278 8 => sprintf( __( 'Menu item submitted. <a target="_blank" href="%s">Preview item</a>', 'jetpack' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
279 /* translators: this is about a food menu */
280 9 => sprintf( __( 'Menu item scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview item</a>', 'jetpack' ),
281 // translators: Publish box date format, see http://php.net/date
282 date_i18n( __( 'M j, Y @ G:i', 'jetpack' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post->ID) ) ),
283 /* translators: this is about a food menu */
284 10 => sprintf( __( 'Menu item draft updated. <a target="_blank" href="%s">Preview item</a>', 'jetpack' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
285 );
286
287 return $messages;
288 }
289
290
291 /**
292 * Nova Styles and Scripts
293 */
294 function enqueue_nova_styles( $hook ) {
295 global $post_type;
296 $pages = array( 'edit.php', 'post.php', 'post-new.php' );
297
298 if ( in_array( $hook, $pages ) && $post_type == self::MENU_ITEM_POST_TYPE ) {
299 wp_enqueue_style( 'nova-style', plugins_url( 'css/nova.css', __FILE__ ), array(), $this->version );
300 }
301
302 wp_enqueue_style( 'nova-font', plugins_url( 'css/nova-font.css', __FILE__ ), array(), $this->version );
303 }
304
305
306 /**
307 * Change ‘Enter Title Here’ text for the Menu Item.
308 */
309 function change_default_title( $title ) {
310 $screen = get_current_screen();
311
312 if ( self::MENU_ITEM_POST_TYPE == $screen->post_type )
313 /* translators: this is about a food menu */
314 $title = esc_html__( "Enter the menu item's name here", 'jetpack' );
315
316 return $title;
317 }
318
319
320 /**
321 * Add to Dashboard At A Glance
322 */
323 function add_to_dashboard() {
324 $number_menu_items = wp_count_posts( self::MENU_ITEM_POST_TYPE );
325
326 if ( current_user_can( 'administrator' ) ) {
327 $number_menu_items_published = sprintf( '<a href="%1$s">%2$s</a>',
328 esc_url( get_admin_url( get_current_blog_id(), 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) ),
329 sprintf( _n( '%1$d Food Menu Item', '%1$d Food Menu Items', intval( $number_menu_items->publish ), 'jetpack' ), number_format_i18n( $number_menu_items->publish ) )
330 );
331 }
332 else {
333 $number_menu_items_published = sprintf( '<span>%1$s</span>',
334 sprintf( _n( '%1$d Food Menu Item', '%1$d Food Menu Items', intval( $number_menu_items->publish ), 'jetpack' ), number_format_i18n( $number_menu_items->publish ) )
335 );
336 }
337
338 echo '<li class="nova-menu-count">' . $number_menu_items_published . '</li>';
339 }
340
341
342 /**
343 * Query
344 */
345 function is_menu_item_query( $query ) {
346 if (
347 ( isset( $query->query_vars['taxonomy'] ) && self::MENU_TAX == $query->query_vars['taxonomy'] )
348 ||
349 ( isset( $query->query_vars['post_type'] ) && self::MENU_ITEM_POST_TYPE == $query->query_vars['post_type'] )
350 ) {
351 return true;
352 }
353
354 return false;
355 }
356
357 function sort_menu_item_queries_by_menu_order( $query ) {
358 if ( ! $this->is_menu_item_query( $query ) ) {
359 return;
360 }
361
362 $query->query_vars['orderby'] = 'menu_order';
363 $query->query_vars['order'] = 'ASC';
364
365 // For now, just turn off paging so we can sort by taxonmy later
366 // If we want paging in the future, we'll need to add the taxonomy sort here (or at least before the DB query is made)
367 $query->query_vars['posts_per_page'] = -1;
368 }
369
370 function sort_menu_item_queries_by_menu_taxonomy( $posts, $query ) {
371 if ( !$posts ) {
372 return $posts;
373 }
374
375 if ( !$this->is_menu_item_query( $query ) ) {
376 return $posts;
377 }
378
379 $grouped_by_term = array();
380
381 foreach ( $posts as $post ) {
382 $term = $this->get_menu_item_menu_leaf( $post->ID );
383 if ( !$term || is_wp_error( $term ) ) {
384 $term_id = 0;
385 } else {
386 $term_id = $term->term_id;
387 }
388
389 if ( !isset( $grouped_by_term["$term_id"] ) ) {
390 $grouped_by_term["$term_id"] = array();
391 }
392
393 $grouped_by_term["$term_id"][] = $post;
394 }
395
396 $term_order = get_option( 'nova_menu_order', array() );
397
398 $return = array();
399 foreach ( $term_order as $term_id ) {
400 if ( isset( $grouped_by_term["$term_id"] ) ) {
401 $return = array_merge( $return, $grouped_by_term["$term_id"] );
402 unset( $grouped_by_term["$term_id"] );
403 }
404 }
405
406 foreach ( $grouped_by_term as $term_id => $posts ) {
407 $return = array_merge( $return, $posts );
408 }
409
410 return $return;
411 }
412
413
414 /**
415 * Add Many Items
416 */
417 function add_admin_menus() {
418 $hook = add_submenu_page(
419 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE,
420 __( 'Add Many Items', 'jetpack' ),
421 __( 'Add Many Items', 'jetpack' ),
422 'edit_pages',
423 'add_many_nova_items',
424 array( $this, 'add_many_new_items_page' )
425 );
426
427 add_action( "load-$hook", array( $this, 'add_many_new_items_page_load' ) );
428
429 add_action( 'current_screen', array( $this, 'current_screen_load' ) );
430
431 //Adjust 'Add Many Items' submenu position
432 if ( isset( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] ) ) {
433 $submenu_item = array_pop( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] );
434 $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE][11] = $submenu_item;
435 ksort( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] );
436 }
437
438
439 $this->setup_menu_item_columns();
440
441 wp_register_script(
442 'nova-menu-checkboxes',
443 Jetpack::get_file_url_for_environment(
444 '_inc/build/custom-post-types/js/menu-checkboxes.min.js',
445 'modules/custom-post-types/js/menu-checkboxes.js'
446 ),
447 array( 'jquery' ),
448 $this->version,
449 true
450 );
451 }
452
453
454 /**
455 * Custom Nova Icon CSS
456 */
457 function set_custom_font_icon() {
458 ?>
459 <style type="text/css">
460 #menu-posts-nova_menu_item .wp-menu-image:before {
461 font-family: 'nova-font' !important;
462 content: '\e603' !important;
463 }
464 </style>
465 <?php
466 }
467
468 function current_screen_load() {
469 $screen = get_current_screen();
470 if ( 'edit-nova_menu_item' !== $screen->id ) {
471 return;
472 }
473
474 $this->edit_menu_items_page_load();
475 add_filter( 'admin_notices', array( $this, 'admin_notices' ) );
476 }
477
478 /* Edit Items List */
479
480 function admin_notices() {
481 if ( isset( $_GET['nova_reordered'] ) )
482 /* translators: this is about a food menu */
483 printf( '<div class="updated"><p>%s</p></div>', __( 'Menu Items re-ordered.', 'jetpack' ) );
484 }
485
486 function no_title_sorting( $columns ) {
487 if ( isset( $columns['title'] ) )
488 unset( $columns['title'] );
489 return $columns;
490 }
491
492 function setup_menu_item_columns() {
493 add_filter( sprintf( 'manage_edit-%s_sortable_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'no_title_sorting' ) );
494 add_filter( sprintf( 'manage_%s_posts_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_columns' ) );
495
496 add_action( sprintf( 'manage_%s_posts_custom_column', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_column_callback' ), 10, 2 );
497 }
498
499 function menu_item_columns( $columns ) {
500 unset( $columns['date'], $columns['likes'] );
501
502 $columns['thumbnail'] = __( 'Thumbnail', 'jetpack' );
503 $columns['labels'] = __( 'Labels', 'jetpack' );
504 $columns['price'] = __( 'Price', 'jetpack' );
505 $columns['order'] = __( 'Order', 'jetpack' );
506
507 return $columns;
508 }
509
510 function menu_item_column_callback( $column, $post_id ) {
511 $screen = get_current_screen();
512
513 switch ( $column ) {
514 case 'thumbnail':
515 echo get_the_post_thumbnail( $post_id, array( 50, 50 ) );
516 break;
517 case 'labels' :
518 $this->list_admin_labels( $post_id );
519 break;
520 case 'price' :
521 $this->display_price( $post_id );
522 break;
523 case 'order' :
524 $url = admin_url( $screen->parent_file );
525
526 $up_url = add_query_arg( array(
527 'action' => 'move-item-up',
528 'post_id' => (int) $post_id,
529 ), wp_nonce_url( $url, 'nova_move_item_up_' . $post_id ) );
530
531 $down_url = add_query_arg( array(
532 'action' => 'move-item-down',
533 'post_id' => (int) $post_id,
534 ), wp_nonce_url( $url, 'nova_move_item_down_' . $post_id ) );
535 $menu_item = get_post($post_id);
536 $this->get_menu_by_post_id( $post_id );
537 if ( $term_id = $this->get_menu_by_post_id( $post_id ) ) {
538 $term_id = $term_id->term_id;
539 }
540 ?>
541 <input type="hidden" class="menu-order-value" name="nova_order[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $menu_item->menu_order ) ?>" />
542 <input type="hidden" class='nova-menu-term' name="nova_menu_term[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $term_id ); ?>">
543
544 <span class="hide-if-js">
545 &nbsp; &nbsp; &mdash; <a class="nova-move-item-up" data-post-id="<?php echo (int) $post_id; ?>" href="<?php echo esc_url( $up_url ); ?>">up</a>
546 <br />
547 &nbsp; &nbsp; &mdash; <a class="nova-move-item-down" data-post-id="<?php echo (int) $post_id; ?>" href="<?php echo esc_url( $down_url ); ?>">down</a>
548 </span>
549 <?php
550 break;
551 }
552 }
553
554 function get_menu_by_post_id( $post_id = null ) {
555 if ( ! $post_id )
556 return false;
557
558 $terms = get_the_terms( $post_id, self::MENU_TAX );
559
560 if ( ! is_array( $terms ) )
561 return false;
562
563 return array_pop( $terms );
564 }
565
566 /**
567 * Fires on a menu edit page. We might have drag-n-drop reordered
568 */
569 function maybe_reorder_menu_items() {
570 // make sure we clicked our button
571 if ( ! ( isset( $_REQUEST['menu_reorder_submit'] ) && $_REQUEST['menu_reorder_submit'] === __( 'Save New Order', 'jetpack' ) ) )
572 return;
573 ;
574
575 // make sure we have the nonce
576 if ( ! ( isset( $_REQUEST['drag-drop-reorder'] ) && wp_verify_nonce( $_REQUEST['drag-drop-reorder'], 'drag-drop-reorder' ) ) )
577 return;
578
579 $term_pairs = array_map( 'absint', $_REQUEST['nova_menu_term'] );
580 $order_pairs = array_map( 'absint', $_REQUEST['nova_order'] );
581
582 foreach( $order_pairs as $ID => $menu_order ) {
583 $ID = absint( $ID );
584 unset( $order_pairs[$ID] );
585 if ( $ID < 0 )
586 continue;
587
588 $post = get_post( $ID );
589 if ( ! $post )
590 continue;
591
592 // save a write if the order hasn't changed
593 if ( $menu_order != $post->menu_order )
594 wp_update_post( compact( 'ID', 'menu_order' ) );
595
596 // save a write if the term hasn't changed
597 if ( $term_pairs[$ID] != $this->get_menu_by_post_id( $ID )->term_id )
598 wp_set_object_terms( $ID, $term_pairs[$ID], self::MENU_TAX );
599
600 }
601
602 $redirect = add_query_arg( array(
603 'post_type' => self::MENU_ITEM_POST_TYPE,
604 'nova_reordered' => '1'
605 ), admin_url( 'edit.php' ) );
606 wp_safe_redirect( $redirect );
607 exit;
608
609 }
610
611 function edit_menu_items_page_load() {
612 if ( isset( $_GET['action'] ) ) {
613 $this->handle_menu_item_actions();
614 }
615
616 $this->maybe_reorder_menu_items();
617
618 wp_enqueue_script(
619 'nova-drag-drop',
620 Jetpack::get_file_url_for_environment(
621 '_inc/build/custom-post-types/js/nova-drag-drop.min.js',
622 'modules/custom-post-types/js/nova-drag-drop.js'
623 ),
624 array( 'jquery-ui-sortable' ),
625 $this->version,
626 true
627 );
628
629 wp_localize_script( 'nova-drag-drop', '_novaDragDrop', array(
630 'nonce' => wp_create_nonce( 'drag-drop-reorder' ),
631 'nonceName' => 'drag-drop-reorder',
632 'reorder' => __( 'Save New Order', 'jetpack' ),
633 'reorderName' => 'menu_reorder_submit'
634 ) );
635 add_action( 'the_post', array( $this, 'show_menu_titles_in_menu_item_list' ) );
636 }
637
638 function handle_menu_item_actions() {
639 $action = (string) $_GET['action'];
640
641 switch ( $action ) {
642 case 'move-item-up' :
643 case 'move-item-down' :
644 $reorder = false;
645
646 $post_id = (int) $_GET['post_id'];
647
648 $term = $this->get_menu_item_menu_leaf( $post_id );
649
650 // Get all posts in that term
651 $query = new WP_Query( array(
652 'taxonomy' => self::MENU_TAX,
653 'term' => $term->slug,
654 ) );
655
656 $order = array();
657 foreach ( $query->posts as $post ) {
658 $order[] = $post->ID;
659 }
660
661 if ( 'move-item-up' == $action ) {
662 check_admin_referer( 'nova_move_item_up_' . $post_id );
663
664 $first_post_id = $order[0];
665 if ( $post_id == $first_post_id ) {
666 break;
667 }
668
669 foreach ( $order as $menu_order => $order_post_id ) {
670 if ( $post_id != $order_post_id ) {
671 continue;
672 }
673
674 $swap_post_id = $order[$menu_order - 1];
675 $order[$menu_order - 1] = $post_id;
676 $order[$menu_order] = $swap_post_id;
677
678 $reorder = true;
679 break;
680 }
681 } else {
682 check_admin_referer( 'nova_move_item_down_' . $post_id );
683
684 $last_post_id = end( $order );
685 if ( $post_id == $last_post_id ) {
686 break;
687 }
688
689 foreach ( $order as $menu_order => $order_post_id ) {
690 if ( $post_id != $order_post_id ) {
691 continue;
692 }
693
694 $swap_post_id = $order[$menu_order + 1];
695 $order[$menu_order + 1] = $post_id;
696 $order[$menu_order] = $swap_post_id;
697
698 $reorder = true;
699 }
700 }
701
702 if ( $reorder ) {
703 foreach ( $order as $menu_order => $ID ) {
704 wp_update_post( compact( 'ID', 'menu_order' ) );
705 }
706 }
707
708 break;
709 case 'move-menu-up' :
710 case 'move-menu-down' :
711 $reorder = false;
712
713 $term_id = (int) $_GET['term_id'];
714
715 $terms = $this->get_menus();
716
717 $order = array();
718 foreach ( $terms as $term ) {
719 $order[] = $term->term_id;
720 }
721
722 if ( 'move-menu-up' == $action ) {
723 check_admin_referer( 'nova_move_menu_up_' . $term_id );
724
725 $first_term_id = $order[0];
726 if ( $term_id == $first_term_id ) {
727 break;
728 }
729
730 foreach ( $order as $menu_order => $order_term_id ) {
731 if ( $term_id != $order_term_id ) {
732 continue;
733 }
734
735 $swap_term_id = $order[$menu_order - 1];
736 $order[$menu_order - 1] = $term_id;
737 $order[$menu_order] = $swap_term_id;
738
739 $reorder = true;
740 break;
741 }
742 } else {
743 check_admin_referer( 'nova_move_menu_down_' . $term_id );
744
745 $last_term_id = end( $order );
746 if ( $term_id == $last_term_id ) {
747 break;
748 }
749
750 foreach ( $order as $menu_order => $order_term_id ) {
751 if ( $term_id != $order_term_id ) {
752 continue;
753 }
754
755 $swap_term_id = $order[$menu_order + 1];
756 $order[$menu_order + 1] = $term_id;
757 $order[$menu_order] = $swap_term_id;
758
759 $reorder = true;
760 }
761 }
762
763 if ( $reorder ) {
764 update_option( 'nova_menu_order', $order );
765 }
766
767 break;
768 default :
769 return;
770 }
771
772 $redirect = add_query_arg( array(
773 'post_type' => self::MENU_ITEM_POST_TYPE,
774 'nova_reordered' => '1'
775 ), admin_url( 'edit.php' ) );
776 wp_safe_redirect( $redirect );
777 exit;
778 }
779
780 /*
781 * Add menu title rows to the list table
782 */
783 function show_menu_titles_in_menu_item_list( $post ) {
784 global $wp_list_table;
785
786 static $last_term_id = false;
787
788 $term = $this->get_menu_item_menu_leaf( $post->ID );
789
790 $term_id = $term instanceof WP_Term ? $term->term_id : null;
791
792 if ( false !== $last_term_id && $last_term_id === $term_id ) {
793 return;
794 }
795
796 if ( is_null( $term_id ) ) {
797 $last_term_id = null;
798 $term_name = '';
799 $parent_count = 0;
800 } else {
801 $last_term_id = $term->term_id;
802 $term_name = $term->name;
803 $parent_count = 0;
804 $current_term = $term;
805 while ( $current_term->parent ) {
806 $parent_count++;
807 $current_term = get_term( $current_term->parent, self::MENU_TAX );
808 }
809 }
810
811 $non_order_column_count = $wp_list_table->get_column_count() - 1;
812
813 $screen = get_current_screen();
814
815 $url = admin_url( $screen->parent_file );
816
817 $up_url = add_query_arg( array(
818 'action' => 'move-menu-up',
819 'term_id' => (int) $term_id,
820 ), wp_nonce_url( $url, 'nova_move_menu_up_' . $term_id ) );
821
822 $down_url = add_query_arg( array(
823 'action' => 'move-menu-down',
824 'term_id' => (int) $term_id,
825 ), wp_nonce_url( $url, 'nova_move_menu_down_' . $term_id ) );
826
827 ?>
828 <tr class="no-items menu-label-row" data-term_id="<?php echo esc_attr( $term_id ) ?>">
829 <td class="colspanchange" colspan="<?php echo (int) $non_order_column_count; ?>">
830 <h3><?php
831 echo str_repeat( ' &mdash; ', (int) $parent_count );
832
833 if ( $term instanceof WP_Term ) {
834 echo esc_html( sanitize_term_field( 'name', $term_name, $term_id, self::MENU_TAX, 'display' ) );
835 edit_term_link( __( 'edit', 'jetpack' ), '<span class="edit-nova-section"><span class="dashicon dashicon-edit"></span>', '</span>', $term );
836
837 } else {
838 _e( 'Uncategorized' , 'jetpack' );
839 }
840 ?></h3>
841 </td>
842 <td>
843 <?php if ( $term instanceof WP_Term ) { ?>
844 <a class="nova-move-menu-up" title="<?php esc_attr_e( 'Move menu section up', 'jetpack' ); ?>" href="<?php echo esc_url( $up_url ); ?>"><?php esc_html_e( 'UP', 'jetpack' ); ?></a>
845 <br />
846 <a class="nova-move-menu-down" title="<?php esc_attr_e( 'Move menu section down', 'jetpack' ); ?>" href="<?php echo esc_url( $down_url ); ?>"><?php esc_html_e( 'DOWN', 'jetpack' ); ?></a>
847 <?php } ?>
848 </td>
849 </tr>
850 <?php
851 }
852
853 /* Edit Many Items */
854
855 function add_many_new_items_page_load() {
856 if ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
857 $this->process_form_request();
858 exit;
859 }
860
861 $this->enqueue_many_items_scripts();
862 }
863
864 function enqueue_many_items_scripts() {
865 wp_enqueue_script(
866 'nova-many-items',
867 Jetpack::get_file_url_for_environment(
868 '_inc/build/custom-post-types/js/many-items.min.js',
869 'modules/custom-post-types/js/many-items.js'
870 ),
871 array( 'jquery' ),
872 $this->version,
873 true
874 );
875 }
876
877 function process_form_request() {
878 if ( !isset( $_POST['nova_title'] ) || !is_array( $_POST['nova_title'] ) ) {
879 return;
880 }
881
882 $is_ajax = !empty( $_POST['ajax'] );
883
884 if ( $is_ajax ) {
885 check_ajax_referer( 'nova_many_items' );
886 } else {
887 check_admin_referer( 'nova_many_items' );
888 }
889
890 foreach ( array_keys( $_POST['nova_title'] ) as $key ) :
891 // $_POST is already slashed
892 $post_details = array(
893 'post_status' => 'publish',
894 'post_type' => self::MENU_ITEM_POST_TYPE,
895 'post_content' => $_POST['nova_content'][$key],
896 'post_title' => $_POST['nova_title'][$key],
897 'tax_input' => array(
898 self::MENU_ITEM_LABEL_TAX => $_POST['nova_labels'][$key],
899 self::MENU_TAX => isset( $_POST['nova_menu_tax'] ) ? $_POST['nova_menu_tax'] : null,
900 ),
901 );
902
903 $post_id = wp_insert_post( $post_details );
904 if ( !$post_id || is_wp_error( $post_id ) ) {
905 continue;
906 }
907
908 $this->set_price( $post_id, isset( $_POST['nova_price'][$key] ) ? stripslashes( $_POST['nova_price'][$key] ) : '' );
909
910 if ( $is_ajax ) :
911 $post = get_post( $post_id );
912 $GLOBALS['post'] = $post;
913 setup_postdata( $post );
914
915 ?>
916 <td><?php the_title(); ?></td>
917 <td class="nova-price"><?php $this->display_price(); ?></td>
918 <td><?php $this->list_labels( $post_id ); ?></td>
919 <td><?php the_content(); ?></td>
920 <?php
921 endif;
922
923 endforeach;
924
925 if ( $is_ajax ) {
926 exit;
927 }
928
929 wp_safe_redirect( admin_url( 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) );
930 exit;
931 }
932
933 function add_many_new_items_page() {
934 ?>
935 <div class="wrap">
936 <h2><?php esc_html_e( 'Add Many Items', 'jetpack' ); ?></h2>
937
938 <p><?php _e( 'Use the <kbd>TAB</kbd> key on your keyboard to move between colums and the <kbd>ENTER</kbd> or <kbd>RETURN</kbd> key to save each row and move on to the next.', 'jetpack' ); ?></p>
939
940 <form method="post" action="" enctype="multipart/form-data">
941 <p><h3><?php esc_html_e( 'Add to section:', 'jetpack' ); ?> <?php wp_dropdown_categories( array(
942 'id' => 'nova-menu-tax',
943 'name' => 'nova_menu_tax',
944 'taxonomy' => self::MENU_TAX,
945 'hide_empty' => false,
946 'hierarchical' => true,
947 ) ); ?></h3></p>
948
949 <table class="many-items-table wp-list-table widefat">
950 <thead>
951 <tr>
952 <th scope="col"><?php esc_html_e( 'Name', 'jetpack' ); ?></th>
953 <th scope="col" class="nova-price"><?php esc_html_e( 'Price', 'jetpack' ); ?></th>
954 <th scope="col"><?php _e( 'Labels: <small>spicy, favorite, etc. <em>Separate Labels with commas</em></small>', 'jetpack' ); ?></th>
955 <th scope="col"><?php esc_html_e( 'Description', 'jetpack' ); ?></th>
956 </tr>
957 </thead>
958 <tbody>
959 <tr>
960 <td><input type="text" name="nova_title[]" aria-required="true" /></td>
961 <td class="nova-price"><input type="text" name="nova_price[]" /></td>
962 <td><input type="text" name="nova_labels[]" /></td>
963 <td><textarea name="nova_content[]" cols="20" rows="1"></textarea>
964 </tr>
965 </tbody>
966 <tbody>
967 <tr>
968 <td><input type="text" name="nova_title[]" aria-required="true" /></td>
969 <td class="nova-price"><input type="text" name="nova_price[]" /></td>
970 <td><input type="text" name="nova_labels[]" /></td>
971 <td><textarea name="nova_content[]" cols="20" rows="1"></textarea>
972 </tr>
973 </tbody>
974 <tfoot>
975 <tr>
976 <th><a class="button button-secondary nova-new-row"><span class="dashicon dashicon-plus"></span> <?php esc_html_e( 'New Row' , 'jetpack' ); ?></a></th>
977 <th class="nova-price"></th>
978 <th></th>
979 <th></th>
980 </tr>
981 </tfoot>
982 </table>
983
984 <p class="submit">
985 <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Add These New Menu Items', 'jetpack' ); ?>" />
986 <?php wp_nonce_field( 'nova_many_items' ); ?>
987 </p>
988 </form>
989 </div>
990 <?php
991 }
992
993 /* Edit One Item */
994
995 function register_menu_item_meta_boxes() {
996 wp_enqueue_script( 'nova-menu-checkboxes' );
997
998 add_meta_box( 'menu_item_price', __( 'Price', 'jetpack' ), array( $this, 'menu_item_price_meta_box' ), null, 'side', 'high' );
999 }
1000
1001 function menu_item_price_meta_box( $post, $meta_box ) {
1002 $price = $this->get_price( $post->ID );
1003 ?>
1004 <label for="nova-price-<?php echo (int) $post->ID; ?>" class="screen-reader-text"><?php esc_html_e( 'Price', 'jetpack' ); ?></label>
1005 <input type="text" id="nova-price-<?php echo (int) $post->ID; ?>" class="widefat" name="nova_price[<?php echo (int) $post->ID; ?>]" value="<?php echo esc_attr( $price ); ?>" />
1006 <?php
1007 }
1008
1009 function add_post_meta( $post_id ) {
1010 if ( !isset( $_POST['nova_price'][$post_id] ) ) {
1011 return;
1012 }
1013
1014 $this->set_price( $post_id, stripslashes( $_POST['nova_price'][$post_id] ) );
1015 }
1016
1017 /* Data */
1018
1019 function get_menus( $args = array() ) {
1020 $args = wp_parse_args( $args, array(
1021 'hide_empty' => false,
1022 ) );
1023
1024 $terms = get_terms( self::MENU_TAX, $args );
1025 if ( !$terms || is_wp_error( $terms ) ) {
1026 return array();
1027 }
1028
1029 $terms_by_id = array();
1030 foreach ( $terms as $term ) {
1031 $terms_by_id["{$term->term_id}"] = $term;
1032 }
1033
1034 $term_order = get_option( 'nova_menu_order', array() );
1035
1036 $return = array();
1037 foreach ( $term_order as $term_id ) {
1038 if ( isset( $terms_by_id["$term_id"] ) ) {
1039 $return[] = $terms_by_id["$term_id"];
1040 unset( $terms_by_id["$term_id"] );
1041 }
1042 }
1043
1044 foreach ( $terms_by_id as $term_id => $term ) {
1045 $return[] = $term;
1046 }
1047
1048 return $return;
1049 }
1050
1051 function get_menu_item_menu_leaf( $post_id ) {
1052 // Get first menu taxonomy "leaf"
1053 $term_ids = wp_get_object_terms( $post_id, self::MENU_TAX, array( 'fields' => 'ids' ) );
1054
1055 foreach ( $term_ids as $term_id ) {
1056 $children = get_term_children( $term_id, self::MENU_TAX );
1057 if ( ! $children ) {
1058 break;
1059 }
1060 }
1061
1062 if ( ! isset( $term_id ) ) {
1063 return false;
1064 }
1065
1066 return get_term( $term_id, self::MENU_TAX );
1067
1068 }
1069
1070 function list_labels( $post_id = 0 ) {
1071 $post = get_post( $post_id );
1072 echo get_the_term_list( $post->ID, self::MENU_ITEM_LABEL_TAX, '', _x( ', ', 'Nova label separator', 'jetpack' ), '' );
1073 }
1074
1075 function list_admin_labels( $post_id = 0 ) {
1076 $post = get_post( $post_id );
1077 $labels = get_the_terms( $post->ID, self::MENU_ITEM_LABEL_TAX );
1078 if ( !empty( $labels ) ) {
1079 $out = array();
1080 foreach ( $labels as $label ) {
1081 $out[] = sprintf( '<a href="%s">%s</a>',
1082 esc_url( add_query_arg( array(
1083 'post_type' => self::MENU_ITEM_POST_TYPE,
1084 'taxonomy' => self::MENU_ITEM_LABEL_TAX,
1085 'term' => $label->slug
1086 ), 'edit.php' ) ),
1087 esc_html( sanitize_term_field( 'name', $label->name, $label->term_id, self::MENU_ITEM_LABEL_TAX, 'display' ) )
1088 );
1089 }
1090
1091 echo join( _x( ', ', 'Nova label separator', 'jetpack' ), $out );
1092 } else {
1093 esc_html_e( 'No Labels', 'jetpack' );
1094 }
1095 }
1096
1097 function set_price( $post_id = 0, $price = '' ) {
1098 $post = get_post( $post_id );
1099
1100 return update_post_meta( $post->ID, 'nova_price', $price );
1101 }
1102
1103 function get_price( $post_id = 0 ) {
1104 $post = get_post( $post_id );
1105
1106 return get_post_meta( $post->ID, 'nova_price', true );
1107 }
1108
1109 function display_price( $post_id = 0 ) {
1110 echo esc_html( $this->get_price( $post_id ) );
1111 }
1112
1113 /* Menu Item Loop Markup */
1114
1115 /* Does not support nested loops */
1116
1117 function get_menu_item_loop_markup( $field = null ) {
1118 return $this->menu_item_loop_markup;
1119 }
1120
1121 /**
1122 * Sets up the loop markup.
1123 * Attached to the 'template_include' *filter*,
1124 * which fires only during a real blog view (not in admin, feeds, etc.)
1125 *
1126 * @param string Template File
1127 * @return string Template File. VERY Important.
1128 */
1129 function setup_menu_item_loop_markup__in_filter( $template ) {
1130 add_action( 'loop_start', array( $this, 'start_menu_item_loop' ) );
1131
1132 return $template;
1133 }
1134
1135 /**
1136 * If the Query is a Menu Item Query, start outputing the Menu Item Loop Marku
1137 * Attached to the 'loop_start' action.
1138 *
1139 * @param WP_Query
1140 */
1141 function start_menu_item_loop( $query ) {
1142 if ( !$this->is_menu_item_query( $query ) ) {
1143 return;
1144 }
1145
1146 $this->menu_item_loop_last_term_id = false;
1147 $this->menu_item_loop_current_term = false;
1148
1149 add_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) );
1150 add_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) );
1151 }
1152
1153 /**
1154 * Outputs the Menu Item Loop Marku
1155 * Attached to the 'the_post' action.
1156 *
1157 * @param WP_Post
1158 */
1159 function menu_item_loop_each_post( $post ) {
1160 $this->menu_item_loop_current_term = $this->get_menu_item_menu_leaf( $post->ID );
1161
1162 if ( false === $this->menu_item_loop_last_term_id ) {
1163 // We're at the very beginning of the loop
1164
1165 $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section
1166 $this->menu_item_loop_header(); // Output the menu's header
1167 } elseif ( $this->menu_item_loop_last_term_id != $this->menu_item_loop_current_term->term_id ) {
1168 // We're not at the very beginning but still need to start a new menu section. End the previous menu section first.
1169
1170 $this->menu_item_loop_close_element( 'menu' ); // End the previous menu section
1171 $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section
1172 $this->menu_item_loop_header(); // Output the menu's header
1173 }
1174
1175 $this->menu_item_loop_last_term_id = $this->menu_item_loop_current_term->term_id;
1176 }
1177
1178 /**
1179 * If the Query is a Menu Item Query, stop outputing the Menu Item Loop Marku
1180 * Attached to the 'loop_end' action.
1181 *
1182 * @param WP_Query
1183 */
1184 function stop_menu_item_loop( $query ) {
1185 if ( !$this->is_menu_item_query( $query ) ) {
1186 return;
1187 }
1188
1189 remove_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) );
1190 remove_action( 'loop_start', array( $this, 'start_menu_item_loop' ) );
1191 remove_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) );
1192
1193 $this->menu_item_loop_close_element( 'menu' ); // End the last menu section
1194 }
1195
1196 /**
1197 * Outputs the Menu Group Header
1198 */
1199 function menu_item_loop_header() {
1200 $this->menu_item_loop_open_element( 'menu_header' );
1201 $this->menu_item_loop_open_element( 'menu_title' );
1202 echo esc_html( $this->menu_item_loop_current_term->name ); // @todo tax filter
1203 $this->menu_item_loop_close_element( 'menu_title' );
1204 if ( $this->menu_item_loop_current_term->description ) :
1205 $this->menu_item_loop_open_element( 'menu_description' );
1206 echo esc_html( $this->menu_item_loop_current_term->description ); // @todo kses, tax filter
1207 $this->menu_item_loop_close_element( 'menu_description' );
1208 endif;
1209 $this->menu_item_loop_close_element( 'menu_header' );
1210 }
1211
1212 /**
1213 * Outputs a Menu Item Markup element opening tag
1214 *
1215 * @param string $field - Menu Item Markup settings field.
1216 */
1217 function menu_item_loop_open_element( $field ) {
1218 $markup = $this->get_menu_item_loop_markup();
1219 /**
1220 * Filter a menu item's element opening tag.
1221 *
1222 * @module custom-content-types
1223 *
1224 * @since 4.4.0
1225 *
1226 * @param string $tag Menu item's element opening tag.
1227 * @param string $field Menu Item Markup settings field.
1228 * @param array $markup Array of markup elements for the menu item.
1229 * @param false|object $term Taxonomy term for current menu item.
1230 */
1231 echo apply_filters(
1232 'jetpack_nova_menu_item_loop_open_element',
1233 '<' . tag_escape( $markup["{$field}_tag"] ) . $this->menu_item_loop_class( $markup["{$field}_class"] ) . ">\n",
1234 $field,
1235 $markup,
1236 $this->menu_item_loop_current_term
1237 );
1238 }
1239
1240 /**
1241 * Outputs a Menu Item Markup element closing tag
1242 *
1243 * @param string $field - Menu Item Markup settings field
1244 */
1245 function menu_item_loop_close_element( $field ) {
1246 $markup = $this->get_menu_item_loop_markup();
1247 /**
1248 * Filter a menu item's element closing tag.
1249 *
1250 * @module custom-content-types
1251 *
1252 * @since 4.4.0
1253 *
1254 * @param string $tag Menu item's element closing tag.
1255 * @param string $field Menu Item Markup settings field.
1256 * @param array $markup Array of markup elements for the menu item.
1257 * @param false|object $term Taxonomy term for current menu item.
1258 */
1259 echo apply_filters(
1260 'jetpack_nova_menu_item_loop_close_element',
1261 '</' . tag_escape( $markup["{$field}_tag"] ) . ">\n",
1262 $field,
1263 $markup,
1264 $this->menu_item_loop_current_term
1265 );
1266 }
1267
1268 /**
1269 * Returns a Menu Item Markup element's class attribute.
1270 *
1271 * @param string $class Class name.
1272 * @return string HTML class attribute with leading whitespace.
1273 */
1274 function menu_item_loop_class( $class ) {
1275 if ( ! $class ) {
1276 return '';
1277 }
1278
1279 /**
1280 * Filter a menu Item Markup element's class attribute.
1281 *
1282 * @module custom-content-types
1283 *
1284 * @since 4.4.0
1285 *
1286 * @param string $tag Menu Item Markup element's class attribute.
1287 * @param string $class Menu Item Class name.
1288 * @param false|object $term Taxonomy term for current menu item.
1289 */
1290 return apply_filters(
1291 'jetpack_nova_menu_item_loop_class',
1292 ' class="' . esc_attr( $class ) . '"',
1293 $class,
1294 $this->menu_item_loop_current_term
1295 );
1296 }
1297 }
1298
1299 add_action( 'init', array( 'Nova_Restaurant', 'init' ) );
1300