PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.2.2
Jetpack – WP Security, Backup, Speed, & Growth v7.2.2
16.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 All 502 releases
jetpack / modules / custom-post-types / nova.php

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

1,299 lines 40.1 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 if ( self::MENU_ITEM_POST_TYPE == get_post_type() ) {
311 /* translators: this is about a food menu */
312 $title = esc_html__( "Enter the menu item's name here", 'jetpack' );
313 }
314
315 return $title;
316 }
317
318
319 /**
320 * Add to Dashboard At A Glance
321 */
322 function add_to_dashboard() {
323 $number_menu_items = wp_count_posts( self::MENU_ITEM_POST_TYPE );
324
325 if ( current_user_can( 'administrator' ) ) {
326 $number_menu_items_published = sprintf( '<a href="%1$s">%2$s</a>',
327 esc_url( get_admin_url( get_current_blog_id(), 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) ),
328 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 ) )
329 );
330 }
331 else {
332 $number_menu_items_published = sprintf( '<span>%1$s</span>',
333 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 ) )
334 );
335 }
336
337 echo '<li class="nova-menu-count">' . $number_menu_items_published . '</li>';
338 }
339
340
341 /**
342 * Query
343 */
344 function is_menu_item_query( $query ) {
345 if (
346 ( isset( $query->query_vars['taxonomy'] ) && self::MENU_TAX == $query->query_vars['taxonomy'] )
347 ||
348 ( isset( $query->query_vars['post_type'] ) && self::MENU_ITEM_POST_TYPE == $query->query_vars['post_type'] )
349 ) {
350 return true;
351 }
352
353 return false;
354 }
355
356 function sort_menu_item_queries_by_menu_order( $query ) {
357 if ( ! $this->is_menu_item_query( $query ) ) {
358 return;
359 }
360
361 $query->query_vars['orderby'] = 'menu_order';
362 $query->query_vars['order'] = 'ASC';
363
364 // For now, just turn off paging so we can sort by taxonmy later
365 // 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)
366 $query->query_vars['posts_per_page'] = -1;
367 }
368
369 function sort_menu_item_queries_by_menu_taxonomy( $posts, $query ) {
370 if ( !$posts ) {
371 return $posts;
372 }
373
374 if ( !$this->is_menu_item_query( $query ) ) {
375 return $posts;
376 }
377
378 $grouped_by_term = array();
379
380 foreach ( $posts as $post ) {
381 $term = $this->get_menu_item_menu_leaf( $post->ID );
382 if ( !$term || is_wp_error( $term ) ) {
383 $term_id = 0;
384 } else {
385 $term_id = $term->term_id;
386 }
387
388 if ( !isset( $grouped_by_term["$term_id"] ) ) {
389 $grouped_by_term["$term_id"] = array();
390 }
391
392 $grouped_by_term["$term_id"][] = $post;
393 }
394
395 $term_order = get_option( 'nova_menu_order', array() );
396
397 $return = array();
398 foreach ( $term_order as $term_id ) {
399 if ( isset( $grouped_by_term["$term_id"] ) ) {
400 $return = array_merge( $return, $grouped_by_term["$term_id"] );
401 unset( $grouped_by_term["$term_id"] );
402 }
403 }
404
405 foreach ( $grouped_by_term as $term_id => $posts ) {
406 $return = array_merge( $return, $posts );
407 }
408
409 return $return;
410 }
411
412
413 /**
414 * Add Many Items
415 */
416 function add_admin_menus() {
417 $hook = add_submenu_page(
418 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE,
419 __( 'Add Many Items', 'jetpack' ),
420 __( 'Add Many Items', 'jetpack' ),
421 'edit_pages',
422 'add_many_nova_items',
423 array( $this, 'add_many_new_items_page' )
424 );
425
426 add_action( "load-$hook", array( $this, 'add_many_new_items_page_load' ) );
427
428 add_action( 'current_screen', array( $this, 'current_screen_load' ) );
429
430 //Adjust 'Add Many Items' submenu position
431 if ( isset( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] ) ) {
432 $submenu_item = array_pop( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] );
433 $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE][11] = $submenu_item;
434 ksort( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] );
435 }
436
437
438 $this->setup_menu_item_columns();
439
440 wp_register_script(
441 'nova-menu-checkboxes',
442 Jetpack::get_file_url_for_environment(
443 '_inc/build/custom-post-types/js/menu-checkboxes.min.js',
444 'modules/custom-post-types/js/menu-checkboxes.js'
445 ),
446 array( 'jquery' ),
447 $this->version,
448 true
449 );
450 }
451
452
453 /**
454 * Custom Nova Icon CSS
455 */
456 function set_custom_font_icon() {
457 ?>
458 <style type="text/css">
459 #menu-posts-nova_menu_item .wp-menu-image:before {
460 font-family: 'nova-font' !important;
461 content: '\e603' !important;
462 }
463 </style>
464 <?php
465 }
466
467 function current_screen_load() {
468 $screen = get_current_screen();
469 if ( 'edit-nova_menu_item' !== $screen->id ) {
470 return;
471 }
472
473 $this->edit_menu_items_page_load();
474 add_filter( 'admin_notices', array( $this, 'admin_notices' ) );
475 }
476
477 /* Edit Items List */
478
479 function admin_notices() {
480 if ( isset( $_GET['nova_reordered'] ) )
481 /* translators: this is about a food menu */
482 printf( '<div class="updated"><p>%s</p></div>', __( 'Menu Items re-ordered.', 'jetpack' ) );
483 }
484
485 function no_title_sorting( $columns ) {
486 if ( isset( $columns['title'] ) )
487 unset( $columns['title'] );
488 return $columns;
489 }
490
491 function setup_menu_item_columns() {
492 add_filter( sprintf( 'manage_edit-%s_sortable_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'no_title_sorting' ) );
493 add_filter( sprintf( 'manage_%s_posts_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_columns' ) );
494
495 add_action( sprintf( 'manage_%s_posts_custom_column', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_column_callback' ), 10, 2 );
496 }
497
498 function menu_item_columns( $columns ) {
499 unset( $columns['date'], $columns['likes'] );
500
501 $columns['thumbnail'] = __( 'Thumbnail', 'jetpack' );
502 $columns['labels'] = __( 'Labels', 'jetpack' );
503 $columns['price'] = __( 'Price', 'jetpack' );
504 $columns['order'] = __( 'Order', 'jetpack' );
505
506 return $columns;
507 }
508
509 function menu_item_column_callback( $column, $post_id ) {
510 $screen = get_current_screen();
511
512 switch ( $column ) {
513 case 'thumbnail':
514 echo get_the_post_thumbnail( $post_id, array( 50, 50 ) );
515 break;
516 case 'labels' :
517 $this->list_admin_labels( $post_id );
518 break;
519 case 'price' :
520 $this->display_price( $post_id );
521 break;
522 case 'order' :
523 $url = admin_url( $screen->parent_file );
524
525 $up_url = add_query_arg( array(
526 'action' => 'move-item-up',
527 'post_id' => (int) $post_id,
528 ), wp_nonce_url( $url, 'nova_move_item_up_' . $post_id ) );
529
530 $down_url = add_query_arg( array(
531 'action' => 'move-item-down',
532 'post_id' => (int) $post_id,
533 ), wp_nonce_url( $url, 'nova_move_item_down_' . $post_id ) );
534 $menu_item = get_post($post_id);
535 $this->get_menu_by_post_id( $post_id );
536 if ( $term_id = $this->get_menu_by_post_id( $post_id ) ) {
537 $term_id = $term_id->term_id;
538 }
539 ?>
540 <input type="hidden" class="menu-order-value" name="nova_order[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $menu_item->menu_order ) ?>" />
541 <input type="hidden" class='nova-menu-term' name="nova_menu_term[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $term_id ); ?>">
542
543 <span class="hide-if-js">
544 &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>
545 <br />
546 &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>
547 </span>
548 <?php
549 break;
550 }
551 }
552
553 function get_menu_by_post_id( $post_id = null ) {
554 if ( ! $post_id )
555 return false;
556
557 $terms = get_the_terms( $post_id, self::MENU_TAX );
558
559 if ( ! is_array( $terms ) )
560 return false;
561
562 return array_pop( $terms );
563 }
564
565 /**
566 * Fires on a menu edit page. We might have drag-n-drop reordered
567 */
568 function maybe_reorder_menu_items() {
569 // make sure we clicked our button
570 if ( ! ( isset( $_REQUEST['menu_reorder_submit'] ) && $_REQUEST['menu_reorder_submit'] === __( 'Save New Order', 'jetpack' ) ) )
571 return;
572 ;
573
574 // make sure we have the nonce
575 if ( ! ( isset( $_REQUEST['drag-drop-reorder'] ) && wp_verify_nonce( $_REQUEST['drag-drop-reorder'], 'drag-drop-reorder' ) ) )
576 return;
577
578 $term_pairs = array_map( 'absint', $_REQUEST['nova_menu_term'] );
579 $order_pairs = array_map( 'absint', $_REQUEST['nova_order'] );
580
581 foreach( $order_pairs as $ID => $menu_order ) {
582 $ID = absint( $ID );
583 unset( $order_pairs[$ID] );
584 if ( $ID < 0 )
585 continue;
586
587 $post = get_post( $ID );
588 if ( ! $post )
589 continue;
590
591 // save a write if the order hasn't changed
592 if ( $menu_order != $post->menu_order )
593 wp_update_post( compact( 'ID', 'menu_order' ) );
594
595 // save a write if the term hasn't changed
596 if ( $term_pairs[$ID] != $this->get_menu_by_post_id( $ID )->term_id )
597 wp_set_object_terms( $ID, $term_pairs[$ID], self::MENU_TAX );
598
599 }
600
601 $redirect = add_query_arg( array(
602 'post_type' => self::MENU_ITEM_POST_TYPE,
603 'nova_reordered' => '1'
604 ), admin_url( 'edit.php' ) );
605 wp_safe_redirect( $redirect );
606 exit;
607
608 }
609
610 function edit_menu_items_page_load() {
611 if ( isset( $_GET['action'] ) ) {
612 $this->handle_menu_item_actions();
613 }
614
615 $this->maybe_reorder_menu_items();
616
617 wp_enqueue_script(
618 'nova-drag-drop',
619 Jetpack::get_file_url_for_environment(
620 '_inc/build/custom-post-types/js/nova-drag-drop.min.js',
621 'modules/custom-post-types/js/nova-drag-drop.js'
622 ),
623 array( 'jquery-ui-sortable' ),
624 $this->version,
625 true
626 );
627
628 wp_localize_script( 'nova-drag-drop', '_novaDragDrop', array(
629 'nonce' => wp_create_nonce( 'drag-drop-reorder' ),
630 'nonceName' => 'drag-drop-reorder',
631 'reorder' => __( 'Save New Order', 'jetpack' ),
632 'reorderName' => 'menu_reorder_submit'
633 ) );
634 add_action( 'the_post', array( $this, 'show_menu_titles_in_menu_item_list' ) );
635 }
636
637 function handle_menu_item_actions() {
638 $action = (string) $_GET['action'];
639
640 switch ( $action ) {
641 case 'move-item-up' :
642 case 'move-item-down' :
643 $reorder = false;
644
645 $post_id = (int) $_GET['post_id'];
646
647 $term = $this->get_menu_item_menu_leaf( $post_id );
648
649 // Get all posts in that term
650 $query = new WP_Query( array(
651 'taxonomy' => self::MENU_TAX,
652 'term' => $term->slug,
653 ) );
654
655 $order = array();
656 foreach ( $query->posts as $post ) {
657 $order[] = $post->ID;
658 }
659
660 if ( 'move-item-up' == $action ) {
661 check_admin_referer( 'nova_move_item_up_' . $post_id );
662
663 $first_post_id = $order[0];
664 if ( $post_id == $first_post_id ) {
665 break;
666 }
667
668 foreach ( $order as $menu_order => $order_post_id ) {
669 if ( $post_id != $order_post_id ) {
670 continue;
671 }
672
673 $swap_post_id = $order[$menu_order - 1];
674 $order[$menu_order - 1] = $post_id;
675 $order[$menu_order] = $swap_post_id;
676
677 $reorder = true;
678 break;
679 }
680 } else {
681 check_admin_referer( 'nova_move_item_down_' . $post_id );
682
683 $last_post_id = end( $order );
684 if ( $post_id == $last_post_id ) {
685 break;
686 }
687
688 foreach ( $order as $menu_order => $order_post_id ) {
689 if ( $post_id != $order_post_id ) {
690 continue;
691 }
692
693 $swap_post_id = $order[$menu_order + 1];
694 $order[$menu_order + 1] = $post_id;
695 $order[$menu_order] = $swap_post_id;
696
697 $reorder = true;
698 }
699 }
700
701 if ( $reorder ) {
702 foreach ( $order as $menu_order => $ID ) {
703 wp_update_post( compact( 'ID', 'menu_order' ) );
704 }
705 }
706
707 break;
708 case 'move-menu-up' :
709 case 'move-menu-down' :
710 $reorder = false;
711
712 $term_id = (int) $_GET['term_id'];
713
714 $terms = $this->get_menus();
715
716 $order = array();
717 foreach ( $terms as $term ) {
718 $order[] = $term->term_id;
719 }
720
721 if ( 'move-menu-up' == $action ) {
722 check_admin_referer( 'nova_move_menu_up_' . $term_id );
723
724 $first_term_id = $order[0];
725 if ( $term_id == $first_term_id ) {
726 break;
727 }
728
729 foreach ( $order as $menu_order => $order_term_id ) {
730 if ( $term_id != $order_term_id ) {
731 continue;
732 }
733
734 $swap_term_id = $order[$menu_order - 1];
735 $order[$menu_order - 1] = $term_id;
736 $order[$menu_order] = $swap_term_id;
737
738 $reorder = true;
739 break;
740 }
741 } else {
742 check_admin_referer( 'nova_move_menu_down_' . $term_id );
743
744 $last_term_id = end( $order );
745 if ( $term_id == $last_term_id ) {
746 break;
747 }
748
749 foreach ( $order as $menu_order => $order_term_id ) {
750 if ( $term_id != $order_term_id ) {
751 continue;
752 }
753
754 $swap_term_id = $order[$menu_order + 1];
755 $order[$menu_order + 1] = $term_id;
756 $order[$menu_order] = $swap_term_id;
757
758 $reorder = true;
759 }
760 }
761
762 if ( $reorder ) {
763 update_option( 'nova_menu_order', $order );
764 }
765
766 break;
767 default :
768 return;
769 }
770
771 $redirect = add_query_arg( array(
772 'post_type' => self::MENU_ITEM_POST_TYPE,
773 'nova_reordered' => '1'
774 ), admin_url( 'edit.php' ) );
775 wp_safe_redirect( $redirect );
776 exit;
777 }
778
779 /*
780 * Add menu title rows to the list table
781 */
782 function show_menu_titles_in_menu_item_list( $post ) {
783 global $wp_list_table;
784
785 static $last_term_id = false;
786
787 $term = $this->get_menu_item_menu_leaf( $post->ID );
788
789 $term_id = $term instanceof WP_Term ? $term->term_id : null;
790
791 if ( false !== $last_term_id && $last_term_id === $term_id ) {
792 return;
793 }
794
795 if ( is_null( $term_id ) ) {
796 $last_term_id = null;
797 $term_name = '';
798 $parent_count = 0;
799 } else {
800 $last_term_id = $term->term_id;
801 $term_name = $term->name;
802 $parent_count = 0;
803 $current_term = $term;
804 while ( $current_term->parent ) {
805 $parent_count++;
806 $current_term = get_term( $current_term->parent, self::MENU_TAX );
807 }
808 }
809
810 $non_order_column_count = $wp_list_table->get_column_count() - 1;
811
812 $screen = get_current_screen();
813
814 $url = admin_url( $screen->parent_file );
815
816 $up_url = add_query_arg( array(
817 'action' => 'move-menu-up',
818 'term_id' => (int) $term_id,
819 ), wp_nonce_url( $url, 'nova_move_menu_up_' . $term_id ) );
820
821 $down_url = add_query_arg( array(
822 'action' => 'move-menu-down',
823 'term_id' => (int) $term_id,
824 ), wp_nonce_url( $url, 'nova_move_menu_down_' . $term_id ) );
825
826 ?>
827 <tr class="no-items menu-label-row" data-term_id="<?php echo esc_attr( $term_id ) ?>">
828 <td class="colspanchange" colspan="<?php echo (int) $non_order_column_count; ?>">
829 <h3><?php
830 echo str_repeat( ' &mdash; ', (int) $parent_count );
831
832 if ( $term instanceof WP_Term ) {
833 echo esc_html( sanitize_term_field( 'name', $term_name, $term_id, self::MENU_TAX, 'display' ) );
834 edit_term_link( __( 'edit', 'jetpack' ), '<span class="edit-nova-section"><span class="dashicon dashicon-edit"></span>', '</span>', $term );
835
836 } else {
837 _e( 'Uncategorized' , 'jetpack' );
838 }
839 ?></h3>
840 </td>
841 <td>
842 <?php if ( $term instanceof WP_Term ) { ?>
843 <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>
844 <br />
845 <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>
846 <?php } ?>
847 </td>
848 </tr>
849 <?php
850 }
851
852 /* Edit Many Items */
853
854 function add_many_new_items_page_load() {
855 if ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
856 $this->process_form_request();
857 exit;
858 }
859
860 $this->enqueue_many_items_scripts();
861 }
862
863 function enqueue_many_items_scripts() {
864 wp_enqueue_script(
865 'nova-many-items',
866 Jetpack::get_file_url_for_environment(
867 '_inc/build/custom-post-types/js/many-items.min.js',
868 'modules/custom-post-types/js/many-items.js'
869 ),
870 array( 'jquery' ),
871 $this->version,
872 true
873 );
874 }
875
876 function process_form_request() {
877 if ( !isset( $_POST['nova_title'] ) || !is_array( $_POST['nova_title'] ) ) {
878 return;
879 }
880
881 $is_ajax = !empty( $_POST['ajax'] );
882
883 if ( $is_ajax ) {
884 check_ajax_referer( 'nova_many_items' );
885 } else {
886 check_admin_referer( 'nova_many_items' );
887 }
888
889 foreach ( array_keys( $_POST['nova_title'] ) as $key ) :
890 // $_POST is already slashed
891 $post_details = array(
892 'post_status' => 'publish',
893 'post_type' => self::MENU_ITEM_POST_TYPE,
894 'post_content' => $_POST['nova_content'][$key],
895 'post_title' => $_POST['nova_title'][$key],
896 'tax_input' => array(
897 self::MENU_ITEM_LABEL_TAX => $_POST['nova_labels'][$key],
898 self::MENU_TAX => isset( $_POST['nova_menu_tax'] ) ? $_POST['nova_menu_tax'] : null,
899 ),
900 );
901
902 $post_id = wp_insert_post( $post_details );
903 if ( !$post_id || is_wp_error( $post_id ) ) {
904 continue;
905 }
906
907 $this->set_price( $post_id, isset( $_POST['nova_price'][$key] ) ? stripslashes( $_POST['nova_price'][$key] ) : '' );
908
909 if ( $is_ajax ) :
910 $post = get_post( $post_id );
911 $GLOBALS['post'] = $post;
912 setup_postdata( $post );
913
914 ?>
915 <td><?php the_title(); ?></td>
916 <td class="nova-price"><?php $this->display_price(); ?></td>
917 <td><?php $this->list_labels( $post_id ); ?></td>
918 <td><?php the_content(); ?></td>
919 <?php
920 endif;
921
922 endforeach;
923
924 if ( $is_ajax ) {
925 exit;
926 }
927
928 wp_safe_redirect( admin_url( 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) );
929 exit;
930 }
931
932 function add_many_new_items_page() {
933 ?>
934 <div class="wrap">
935 <h2><?php esc_html_e( 'Add Many Items', 'jetpack' ); ?></h2>
936
937 <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>
938
939 <form method="post" action="" enctype="multipart/form-data">
940 <p><h3><?php esc_html_e( 'Add to section:', 'jetpack' ); ?> <?php wp_dropdown_categories( array(
941 'id' => 'nova-menu-tax',
942 'name' => 'nova_menu_tax',
943 'taxonomy' => self::MENU_TAX,
944 'hide_empty' => false,
945 'hierarchical' => true,
946 ) ); ?></h3></p>
947
948 <table class="many-items-table wp-list-table widefat">
949 <thead>
950 <tr>
951 <th scope="col"><?php esc_html_e( 'Name', 'jetpack' ); ?></th>
952 <th scope="col" class="nova-price"><?php esc_html_e( 'Price', 'jetpack' ); ?></th>
953 <th scope="col"><?php _e( 'Labels: <small>spicy, favorite, etc. <em>Separate Labels with commas</em></small>', 'jetpack' ); ?></th>
954 <th scope="col"><?php esc_html_e( 'Description', 'jetpack' ); ?></th>
955 </tr>
956 </thead>
957 <tbody>
958 <tr>
959 <td><input type="text" name="nova_title[]" aria-required="true" /></td>
960 <td class="nova-price"><input type="text" name="nova_price[]" /></td>
961 <td><input type="text" name="nova_labels[]" /></td>
962 <td><textarea name="nova_content[]" cols="20" rows="1"></textarea>
963 </tr>
964 </tbody>
965 <tbody>
966 <tr>
967 <td><input type="text" name="nova_title[]" aria-required="true" /></td>
968 <td class="nova-price"><input type="text" name="nova_price[]" /></td>
969 <td><input type="text" name="nova_labels[]" /></td>
970 <td><textarea name="nova_content[]" cols="20" rows="1"></textarea>
971 </tr>
972 </tbody>
973 <tfoot>
974 <tr>
975 <th><a class="button button-secondary nova-new-row"><span class="dashicon dashicon-plus"></span> <?php esc_html_e( 'New Row' , 'jetpack' ); ?></a></th>
976 <th class="nova-price"></th>
977 <th></th>
978 <th></th>
979 </tr>
980 </tfoot>
981 </table>
982
983 <p class="submit">
984 <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Add These New Menu Items', 'jetpack' ); ?>" />
985 <?php wp_nonce_field( 'nova_many_items' ); ?>
986 </p>
987 </form>
988 </div>
989 <?php
990 }
991
992 /* Edit One Item */
993
994 function register_menu_item_meta_boxes() {
995 wp_enqueue_script( 'nova-menu-checkboxes' );
996
997 add_meta_box( 'menu_item_price', __( 'Price', 'jetpack' ), array( $this, 'menu_item_price_meta_box' ), null, 'side', 'high' );
998 }
999
1000 function menu_item_price_meta_box( $post, $meta_box ) {
1001 $price = $this->get_price( $post->ID );
1002 ?>
1003 <label for="nova-price-<?php echo (int) $post->ID; ?>" class="screen-reader-text"><?php esc_html_e( 'Price', 'jetpack' ); ?></label>
1004 <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 ); ?>" />
1005 <?php
1006 }
1007
1008 function add_post_meta( $post_id ) {
1009 if ( !isset( $_POST['nova_price'][$post_id] ) ) {
1010 return;
1011 }
1012
1013 $this->set_price( $post_id, stripslashes( $_POST['nova_price'][$post_id] ) );
1014 }
1015
1016 /* Data */
1017
1018 function get_menus( $args = array() ) {
1019 $args = wp_parse_args( $args, array(
1020 'hide_empty' => false,
1021 ) );
1022
1023 $terms = get_terms( self::MENU_TAX, $args );
1024 if ( !$terms || is_wp_error( $terms ) ) {
1025 return array();
1026 }
1027
1028 $terms_by_id = array();
1029 foreach ( $terms as $term ) {
1030 $terms_by_id["{$term->term_id}"] = $term;
1031 }
1032
1033 $term_order = get_option( 'nova_menu_order', array() );
1034
1035 $return = array();
1036 foreach ( $term_order as $term_id ) {
1037 if ( isset( $terms_by_id["$term_id"] ) ) {
1038 $return[] = $terms_by_id["$term_id"];
1039 unset( $terms_by_id["$term_id"] );
1040 }
1041 }
1042
1043 foreach ( $terms_by_id as $term_id => $term ) {
1044 $return[] = $term;
1045 }
1046
1047 return $return;
1048 }
1049
1050 function get_menu_item_menu_leaf( $post_id ) {
1051 // Get first menu taxonomy "leaf"
1052 $term_ids = wp_get_object_terms( $post_id, self::MENU_TAX, array( 'fields' => 'ids' ) );
1053
1054 foreach ( $term_ids as $term_id ) {
1055 $children = get_term_children( $term_id, self::MENU_TAX );
1056 if ( ! $children ) {
1057 break;
1058 }
1059 }
1060
1061 if ( ! isset( $term_id ) ) {
1062 return false;
1063 }
1064
1065 return get_term( $term_id, self::MENU_TAX );
1066
1067 }
1068
1069 function list_labels( $post_id = 0 ) {
1070 $post = get_post( $post_id );
1071 echo get_the_term_list( $post->ID, self::MENU_ITEM_LABEL_TAX, '', _x( ', ', 'Nova label separator', 'jetpack' ), '' );
1072 }
1073
1074 function list_admin_labels( $post_id = 0 ) {
1075 $post = get_post( $post_id );
1076 $labels = get_the_terms( $post->ID, self::MENU_ITEM_LABEL_TAX );
1077 if ( !empty( $labels ) ) {
1078 $out = array();
1079 foreach ( $labels as $label ) {
1080 $out[] = sprintf( '<a href="%s">%s</a>',
1081 esc_url( add_query_arg( array(
1082 'post_type' => self::MENU_ITEM_POST_TYPE,
1083 'taxonomy' => self::MENU_ITEM_LABEL_TAX,
1084 'term' => $label->slug
1085 ), 'edit.php' ) ),
1086 esc_html( sanitize_term_field( 'name', $label->name, $label->term_id, self::MENU_ITEM_LABEL_TAX, 'display' ) )
1087 );
1088 }
1089
1090 echo join( _x( ', ', 'Nova label separator', 'jetpack' ), $out );
1091 } else {
1092 esc_html_e( 'No Labels', 'jetpack' );
1093 }
1094 }
1095
1096 function set_price( $post_id = 0, $price = '' ) {
1097 $post = get_post( $post_id );
1098
1099 return update_post_meta( $post->ID, 'nova_price', $price );
1100 }
1101
1102 function get_price( $post_id = 0 ) {
1103 $post = get_post( $post_id );
1104
1105 return get_post_meta( $post->ID, 'nova_price', true );
1106 }
1107
1108 function display_price( $post_id = 0 ) {
1109 echo esc_html( $this->get_price( $post_id ) );
1110 }
1111
1112 /* Menu Item Loop Markup */
1113
1114 /* Does not support nested loops */
1115
1116 function get_menu_item_loop_markup( $field = null ) {
1117 return $this->menu_item_loop_markup;
1118 }
1119
1120 /**
1121 * Sets up the loop markup.
1122 * Attached to the 'template_include' *filter*,
1123 * which fires only during a real blog view (not in admin, feeds, etc.)
1124 *
1125 * @param string Template File
1126 * @return string Template File. VERY Important.
1127 */
1128 function setup_menu_item_loop_markup__in_filter( $template ) {
1129 add_action( 'loop_start', array( $this, 'start_menu_item_loop' ) );
1130
1131 return $template;
1132 }
1133
1134 /**
1135 * If the Query is a Menu Item Query, start outputing the Menu Item Loop Marku
1136 * Attached to the 'loop_start' action.
1137 *
1138 * @param WP_Query
1139 */
1140 function start_menu_item_loop( $query ) {
1141 if ( !$this->is_menu_item_query( $query ) ) {
1142 return;
1143 }
1144
1145 $this->menu_item_loop_last_term_id = false;
1146 $this->menu_item_loop_current_term = false;
1147
1148 add_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) );
1149 add_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) );
1150 }
1151
1152 /**
1153 * Outputs the Menu Item Loop Marku
1154 * Attached to the 'the_post' action.
1155 *
1156 * @param WP_Post
1157 */
1158 function menu_item_loop_each_post( $post ) {
1159 $this->menu_item_loop_current_term = $this->get_menu_item_menu_leaf( $post->ID );
1160
1161 if ( false === $this->menu_item_loop_last_term_id ) {
1162 // We're at the very beginning of the loop
1163
1164 $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section
1165 $this->menu_item_loop_header(); // Output the menu's header
1166 } elseif ( $this->menu_item_loop_last_term_id != $this->menu_item_loop_current_term->term_id ) {
1167 // We're not at the very beginning but still need to start a new menu section. End the previous menu section first.
1168
1169 $this->menu_item_loop_close_element( 'menu' ); // End the previous menu section
1170 $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section
1171 $this->menu_item_loop_header(); // Output the menu's header
1172 }
1173
1174 $this->menu_item_loop_last_term_id = $this->menu_item_loop_current_term->term_id;
1175 }
1176
1177 /**
1178 * If the Query is a Menu Item Query, stop outputing the Menu Item Loop Marku
1179 * Attached to the 'loop_end' action.
1180 *
1181 * @param WP_Query
1182 */
1183 function stop_menu_item_loop( $query ) {
1184 if ( !$this->is_menu_item_query( $query ) ) {
1185 return;
1186 }
1187
1188 remove_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) );
1189 remove_action( 'loop_start', array( $this, 'start_menu_item_loop' ) );
1190 remove_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) );
1191
1192 $this->menu_item_loop_close_element( 'menu' ); // End the last menu section
1193 }
1194
1195 /**
1196 * Outputs the Menu Group Header
1197 */
1198 function menu_item_loop_header() {
1199 $this->menu_item_loop_open_element( 'menu_header' );
1200 $this->menu_item_loop_open_element( 'menu_title' );
1201 echo esc_html( $this->menu_item_loop_current_term->name ); // @todo tax filter
1202 $this->menu_item_loop_close_element( 'menu_title' );
1203 if ( $this->menu_item_loop_current_term->description ) :
1204 $this->menu_item_loop_open_element( 'menu_description' );
1205 echo esc_html( $this->menu_item_loop_current_term->description ); // @todo kses, tax filter
1206 $this->menu_item_loop_close_element( 'menu_description' );
1207 endif;
1208 $this->menu_item_loop_close_element( 'menu_header' );
1209 }
1210
1211 /**
1212 * Outputs a Menu Item Markup element opening tag
1213 *
1214 * @param string $field - Menu Item Markup settings field.
1215 */
1216 function menu_item_loop_open_element( $field ) {
1217 $markup = $this->get_menu_item_loop_markup();
1218 /**
1219 * Filter a menu item's element opening tag.
1220 *
1221 * @module custom-content-types
1222 *
1223 * @since 4.4.0
1224 *
1225 * @param string $tag Menu item's element opening tag.
1226 * @param string $field Menu Item Markup settings field.
1227 * @param array $markup Array of markup elements for the menu item.
1228 * @param false|object $term Taxonomy term for current menu item.
1229 */
1230 echo apply_filters(
1231 'jetpack_nova_menu_item_loop_open_element',
1232 '<' . tag_escape( $markup["{$field}_tag"] ) . $this->menu_item_loop_class( $markup["{$field}_class"] ) . ">\n",
1233 $field,
1234 $markup,
1235 $this->menu_item_loop_current_term
1236 );
1237 }
1238
1239 /**
1240 * Outputs a Menu Item Markup element closing tag
1241 *
1242 * @param string $field - Menu Item Markup settings field
1243 */
1244 function menu_item_loop_close_element( $field ) {
1245 $markup = $this->get_menu_item_loop_markup();
1246 /**
1247 * Filter a menu item's element closing tag.
1248 *
1249 * @module custom-content-types
1250 *
1251 * @since 4.4.0
1252 *
1253 * @param string $tag Menu item's element closing tag.
1254 * @param string $field Menu Item Markup settings field.
1255 * @param array $markup Array of markup elements for the menu item.
1256 * @param false|object $term Taxonomy term for current menu item.
1257 */
1258 echo apply_filters(
1259 'jetpack_nova_menu_item_loop_close_element',
1260 '</' . tag_escape( $markup["{$field}_tag"] ) . ">\n",
1261 $field,
1262 $markup,
1263 $this->menu_item_loop_current_term
1264 );
1265 }
1266
1267 /**
1268 * Returns a Menu Item Markup element's class attribute.
1269 *
1270 * @param string $class Class name.
1271 * @return string HTML class attribute with leading whitespace.
1272 */
1273 function menu_item_loop_class( $class ) {
1274 if ( ! $class ) {
1275 return '';
1276 }
1277
1278 /**
1279 * Filter a menu Item Markup element's class attribute.
1280 *
1281 * @module custom-content-types
1282 *
1283 * @since 4.4.0
1284 *
1285 * @param string $tag Menu Item Markup element's class attribute.
1286 * @param string $class Menu Item Class name.
1287 * @param false|object $term Taxonomy term for current menu item.
1288 */
1289 return apply_filters(
1290 'jetpack_nova_menu_item_loop_class',
1291 ' class="' . esc_attr( $class ) . '"',
1292 $class,
1293 $this->menu_item_loop_current_term
1294 );
1295 }
1296 }
1297
1298 add_action( 'init', array( 'Nova_Restaurant', 'init' ) );
1299