/modules/custom-post-types/nova.php

  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. if ( $menu_item_loop_markup ) { 
  57. $instance->menu_item_loop_markup = wp_parse_args( $menu_item_loop_markup, $instance->default_menu_item_loop_markup ); 
  58.  
  59. return $instance; 
  60.  
  61. function __construct() { 
  62. if ( ! $this->site_supports_nova() ) 
  63. return; 
  64.  
  65. $this->register_taxonomies(); 
  66. $this->register_post_types(); 
  67. add_action( 'admin_menu', array( $this, 'add_admin_menus' ) ); 
  68. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_nova_styles' ) ); 
  69. add_action( 'admin_head', array( $this, 'set_custom_font_icon' ) ); 
  70.  
  71. // Enable Omnisearch for Menu Items. 
  72. if ( class_exists( 'Jetpack_Omnisearch_Posts' ) ) 
  73. new Jetpack_Omnisearch_Posts( self::MENU_ITEM_POST_TYPE ); 
  74.  
  75. // Always sort menu items correctly 
  76. add_action( 'parse_query', array( $this, 'sort_menu_item_queries_by_menu_order' ) ); 
  77. add_filter( 'posts_results', array( $this, 'sort_menu_item_queries_by_menu_taxonomy' ), 10, 2 ); 
  78.  
  79. add_action( 'wp_insert_post', array( $this, 'add_post_meta' ) ); 
  80.  
  81. $this->menu_item_loop_markup = $this->default_menu_item_loop_markup; 
  82.  
  83. // Only output our Menu Item Loop Markup on a real blog view. Not feeds, XML-RPC, admin, etc. 
  84. add_filter( 'template_include', array( $this, 'setup_menu_item_loop_markup__in_filter' ) ); 
  85.  
  86. add_filter( 'enter_title_here', array( $this, 'change_default_title' ) ); 
  87. add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); 
  88. add_filter( 'dashboard_glance_items', array( $this, 'add_to_dashboard' ) ); 
  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. /** Setup */ 
  116.  
  117. /** 
  118. * Register Taxonomies and Post Type 
  119. */ 
  120. function register_taxonomies() { 
  121. register_taxonomy( self::MENU_ITEM_LABEL_TAX, self::MENU_ITEM_POST_TYPE, array( 
  122. 'labels' => array( 
  123. 'name' => __( 'Menu Item Labels', 'jetpack' ),  
  124. 'singular_name' => __( 'Menu Item Label', 'jetpack' ),  
  125. 'search_items' => __( 'Search Menu Item Labels', 'jetpack' ),  
  126. 'popular_items' => __( 'Popular Labels', 'jetpack' ),  
  127. 'all_items' => __( 'All Menu Item Labels', 'jetpack' ),  
  128. 'edit_item' => __( 'Edit Menu Item Label', 'jetpack' ),  
  129. 'view_item' => __( 'View Menu Item Label', 'jetpack' ),  
  130. 'update_item' => __( 'Update Menu Item Label', 'jetpack' ),  
  131. 'add_new_item' => __( 'Add New Menu Item Label', 'jetpack' ),  
  132. 'new_item_name' => __( 'New Menu Item Label Name', 'jetpack' ),  
  133. 'separate_items_with_commas' => __( 'For example, spicy, favorite, etc. <br /> Separate Labels with commas', 'jetpack' ),  
  134. 'add_or_remove_items' => __( 'Add or remove Labels', 'jetpack' ),  
  135. 'choose_from_most_used' => __( 'Choose from the most used Labels', 'jetpack' ),  
  136. 'items_list_navigation' => __( 'Menu item label list navigation', 'jetpack' ),  
  137. 'items_list' => __( 'Menu item labels list', 'jetpack' ),  
  138. ),  
  139. 'no_tagcloud' => __( 'No Labels found', 'jetpack' ),  
  140.  
  141. 'hierarchical' => false,  
  142. ) ); 
  143.  
  144. register_taxonomy( self::MENU_TAX, self::MENU_ITEM_POST_TYPE, array( 
  145. 'labels' => array( 
  146. 'name' => __( 'Menu Sections', 'jetpack' ),  
  147. 'singular_name' => __( 'Menu Section', 'jetpack' ),  
  148. 'search_items' => __( 'Search Menu Sections', 'jetpack' ),  
  149. 'all_items' => __( 'All Menu Sections', 'jetpack' ),  
  150. 'parent_item' => __( 'Parent Menu Section', 'jetpack' ),  
  151. 'parent_item_colon' => __( 'Parent Menu Section:', 'jetpack' ),  
  152. 'edit_item' => __( 'Edit Menu Section', 'jetpack' ),  
  153. 'view_item' => __( 'View Menu Section', 'jetpack' ),  
  154. 'update_item' => __( 'Update Menu Section', 'jetpack' ),  
  155. 'add_new_item' => __( 'Add New Menu Section', 'jetpack' ),  
  156. 'new_item_name' => __( 'New Menu Sections Name', 'jetpack' ),  
  157. 'items_list_navigation' => __( 'Menu section list navigation', 'jetpack' ),  
  158. 'items_list' => __( 'Menu section list', 'jetpack' ),  
  159. ),  
  160. 'rewrite' => array( 
  161. 'slug' => 'menu',  
  162. 'with_front' => false,  
  163. 'hierarchical' => true,  
  164. ),  
  165.  
  166. 'hierarchical' => true,  
  167. 'show_tagcloud' => false,  
  168. 'query_var' => 'menu',  
  169. ) ); 
  170.  
  171. function register_post_types() { 
  172. register_post_type( self::MENU_ITEM_POST_TYPE, array( 
  173. 'description' => __( "Items on your restaurant's menu", 'jetpack' ),  
  174.  
  175. 'labels' => array( 
  176. 'name' => __( 'Menu Items', 'jetpack' ),  
  177. 'singular_name' => __( 'Menu Item', 'jetpack' ),  
  178. 'menu_name' => __( 'Food Menus', 'jetpack' ),  
  179. 'all_items' => __( 'Menu Items', 'jetpack' ),  
  180. 'add_new' => __( 'Add One Item', 'jetpack' ),  
  181. 'add_new_item' => __( 'Add Menu Item', 'jetpack' ),  
  182. 'edit_item' => __( 'Edit Menu Item', 'jetpack' ),  
  183. 'new_item' => __( 'New Menu Item', 'jetpack' ),  
  184. 'view_item' => __( 'View Menu Item', 'jetpack' ),  
  185. 'search_items' => __( 'Search Menu Items', 'jetpack' ),  
  186. 'not_found' => __( 'No Menu Items found', 'jetpack' ),  
  187. 'not_found_in_trash' => __( 'No Menu Items found in Trash', 'jetpack' ),  
  188. 'filter_items_list' => __( 'Filter menu items list', 'jetpack' ),  
  189. 'items_list_navigation' => __( 'Menu item list navigation', 'jetpack' ),  
  190. 'items_list' => __( 'Menu items list', 'jetpack' ),  
  191. ),  
  192. 'supports' => array( 
  193. 'title',  
  194. 'editor',  
  195. 'thumbnail',  
  196. 'excerpt',  
  197. ),  
  198. 'rewrite' => array( 
  199. 'slug' => 'item',  
  200. 'with_front' => false,  
  201. 'feeds' => false,  
  202. 'pages' => false,  
  203. ),  
  204. 'register_meta_box_cb' => array( $this, 'register_menu_item_meta_boxes' ),  
  205.  
  206. 'public' => true,  
  207. 'show_ui' => true, // set to false to replace with custom UI 
  208. 'menu_position' => 20, // below Pages 
  209. 'capability_type' => 'page',  
  210. 'map_meta_cap' => true,  
  211. 'has_archive' => false,  
  212. 'query_var' => 'item',  
  213. ) ); 
  214.  
  215.  
  216. /** 
  217. * Update messages for the Menu Item admin. 
  218. */ 
  219. function updated_messages( $messages ) { 
  220. global $post; 
  221.  
  222. $messages[self::MENU_ITEM_POST_TYPE] = array( 
  223. 0 => '', // Unused. Messages start at index 1. 
  224. 1 => sprintf( __( 'Menu item updated. <a href="%s">View item</a>', 'jetpack' ), esc_url( get_permalink( $post->ID ) ) ),  
  225. 2 => esc_html__( 'Custom field updated.', 'jetpack' ),  
  226. 3 => esc_html__( 'Custom field deleted.', 'jetpack' ),  
  227. 4 => esc_html__( 'Menu item updated.', 'jetpack' ),  
  228. /** translators: %s: date and time of the revision */ 
  229. 5 => isset( $_GET['revision'] ) ? sprintf( esc_html__( 'Menu item restored to revision from %s', 'jetpack' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,  
  230. 6 => sprintf( __( 'Menu item published. <a href="%s">View item</a>', 'jetpack' ), esc_url( get_permalink( $post->ID ) ) ),  
  231. 7 => esc_html__( 'Menu item saved.', 'jetpack' ),  
  232. 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 ) ) ) ),  
  233. 9 => sprintf( __( 'Menu item scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview item</a>', 'jetpack' ),  
  234. // translators: Publish box date format, see http://php.net/date 
  235. date_i18n( __( 'M j, Y @ G:i', 'jetpack' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post->ID) ) ),  
  236. 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 ) ) ) ),  
  237. ); 
  238.  
  239. return $messages; 
  240.  
  241.  
  242. /** 
  243. * Nova Styles and Scripts 
  244. */ 
  245. function enqueue_nova_styles( $hook ) { 
  246. global $post_type; 
  247. $pages = array( 'edit.php', 'post.php', 'post-new.php' ); 
  248.  
  249. if ( in_array( $hook, $pages ) && $post_type == self::MENU_ITEM_POST_TYPE ) { 
  250. wp_enqueue_style( 'nova-style', plugins_url( 'css/nova.css', __FILE__ ), array(), $this->version ); 
  251.  
  252. wp_enqueue_style( 'nova-font', plugins_url( 'css/nova-font.css', __FILE__ ), array(), $this->version ); 
  253.  
  254.  
  255. /** 
  256. * Change *Enter Title Here* text for the Menu Item. 
  257. */ 
  258. function change_default_title( $title ) { 
  259. $screen = get_current_screen(); 
  260.  
  261. if ( self::MENU_ITEM_POST_TYPE == $screen->post_type ) 
  262. $title = esc_html__( "Enter the menu item's name here", 'jetpack' ); 
  263.  
  264. return $title; 
  265.  
  266.  
  267. /** 
  268. * Add to Dashboard At A Glance 
  269. */ 
  270. function add_to_dashboard() { 
  271. $number_menu_items = wp_count_posts( self::MENU_ITEM_POST_TYPE ); 
  272.  
  273. if ( current_user_can( 'administrator' ) ) { 
  274. $number_menu_items_published = sprintf( '<a href="%1$s">%2$s</a>',  
  275. esc_url( get_admin_url( get_current_blog_id(), 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) ),  
  276. 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 ) ) 
  277. ); 
  278. else { 
  279. $number_menu_items_published = sprintf( '<span>%1$s</span>',  
  280. 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 ) ) 
  281. ); 
  282.  
  283. echo '<li class="nova-menu-count">' . $number_menu_items_published . '</li>'; 
  284.  
  285.  
  286. /** 
  287. * Query 
  288. */ 
  289. function is_menu_item_query( $query ) { 
  290. if ( 
  291. ( isset( $query->query_vars['taxonomy'] ) && self::MENU_TAX == $query->query_vars['taxonomy'] ) 
  292. || 
  293. ( isset( $query->query_vars['post_type'] ) && self::MENU_ITEM_POST_TYPE == $query->query_vars['post_type'] ) 
  294. ) { 
  295. return true; 
  296.  
  297. return false; 
  298.  
  299. function sort_menu_item_queries_by_menu_order( $query ) { 
  300. if ( ! $this->is_menu_item_query( $query ) ) { 
  301. return; 
  302.  
  303. $query->query_vars['orderby'] = 'menu_order'; 
  304. $query->query_vars['order'] = 'ASC'; 
  305.  
  306. // For now, just turn off paging so we can sort by taxonmy later 
  307. // 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) 
  308. $query->query_vars['posts_per_page'] = -1; 
  309.  
  310. function sort_menu_item_queries_by_menu_taxonomy( $posts, $query ) { 
  311. if ( !$posts ) { 
  312. return $posts; 
  313.  
  314. if ( !$this->is_menu_item_query( $query ) ) { 
  315. return $posts; 
  316.  
  317. $grouped_by_term = array(); 
  318.  
  319. foreach ( $posts as $post ) { 
  320. $term = $this->get_menu_item_menu_leaf( $post->ID ); 
  321. if ( !$term || is_wp_error( $term ) ) { 
  322. $term_id = 0; 
  323. } else { 
  324. $term_id = $term->term_id; 
  325.  
  326. if ( !isset( $grouped_by_term["$term_id"] ) ) { 
  327. $grouped_by_term["$term_id"] = array(); 
  328.  
  329. $grouped_by_term["$term_id"][] = $post; 
  330.  
  331. $term_order = get_option( 'nova_menu_order', array() ); 
  332.  
  333. $return = array(); 
  334. foreach ( $term_order as $term_id ) { 
  335. if ( isset( $grouped_by_term["$term_id"] ) ) { 
  336. $return = array_merge( $return, $grouped_by_term["$term_id"] ); 
  337. unset( $grouped_by_term["$term_id"] ); 
  338.  
  339. foreach ( $grouped_by_term as $term_id => $posts ) { 
  340. $return = array_merge( $return, $posts ); 
  341.  
  342. return $return; 
  343.  
  344.  
  345. /** 
  346. * Add Many Items 
  347. */ 
  348. function add_admin_menus() { 
  349. $hook = add_submenu_page( 
  350. 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE,  
  351. __( 'Add Many Items', 'jetpack' ),  
  352. __( 'Add Many Items', 'jetpack' ),  
  353. 'edit_pages',  
  354. 'add_many_nova_items',  
  355. array( $this, 'add_many_new_items_page' ) 
  356. ); 
  357.  
  358. add_action( "load-$hook", array( $this, 'add_many_new_items_page_load' ) ); 
  359.  
  360. add_action( 'current_screen', array( $this, 'current_screen_load' ) ); 
  361.  
  362. //Adjust 'Add Many Items' submenu position 
  363. $submenu_item = array_pop( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] ); 
  364. $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE][11] = $submenu_item; 
  365. ksort( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] ); 
  366.  
  367. $this->setup_menu_item_columns(); 
  368.  
  369. wp_register_script( 'nova-menu-checkboxes', plugins_url( 'js/menu-checkboxes.js', __FILE__ ), array( 'jquery' ), $this->version, true ); 
  370.  
  371.  
  372. /** 
  373. * Custom Nova Icon CSS 
  374. */ 
  375. function set_custom_font_icon() { 
  376. ?> 
  377. <style type="text/css"> 
  378. #menu-posts-nova_menu_item .wp-menu-image:before { 
  379. font-family: 'nova-font' !important; 
  380. content: '\e603' !important; 
  381. </style> 
  382. <?php 
  383.  
  384. function current_screen_load() { 
  385. $screen = get_current_screen(); 
  386. if ( 'edit-nova_menu_item' !== $screen->id ) { 
  387. return; 
  388.  
  389. $this->edit_menu_items_page_load(); 
  390. add_filter( 'admin_notices', array( $this, 'admin_notices' ) ); 
  391.  
  392. /** Edit Items List */ 
  393.  
  394. function admin_notices() { 
  395. if ( isset( $_GET['nova_reordered'] ) ) 
  396. printf( '<div class="updated"><p>%s</p></div>', __( 'Menu Items re-ordered.', 'jetpack' ) ); 
  397.  
  398. function no_title_sorting( $columns ) { 
  399. if ( isset( $columns['title'] ) ) 
  400. unset( $columns['title'] ); 
  401. return $columns; 
  402.  
  403. function setup_menu_item_columns() { 
  404. add_filter( sprintf( 'manage_edit-%s_sortable_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'no_title_sorting' ) ); 
  405. add_filter( sprintf( 'manage_%s_posts_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_columns' ) ); 
  406.  
  407. add_action( sprintf( 'manage_%s_posts_custom_column', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_column_callback' ), 10, 2 ); 
  408.  
  409. function menu_item_columns( $columns ) { 
  410. unset( $columns['date'], $columns['likes'] ); 
  411.  
  412. $columns['thumbnail'] = __( 'Thumbnail', 'jetpack' ); 
  413. $columns['labels'] = __( 'Labels', 'jetpack' ); 
  414. $columns['price'] = __( 'Price', 'jetpack' ); 
  415. $columns['order'] = __( 'Order', 'jetpack' ); 
  416.  
  417. return $columns; 
  418.  
  419. function menu_item_column_callback( $column, $post_id ) { 
  420. $screen = get_current_screen(); 
  421.  
  422. switch ( $column ) { 
  423. case 'thumbnail': 
  424. echo get_the_post_thumbnail( $post_id, array( 50, 50 ) ); 
  425. break; 
  426. case 'labels' : 
  427. $this->list_admin_labels( $post_id ); 
  428. break; 
  429. case 'price' : 
  430. $this->display_price( $post_id ); 
  431. break; 
  432. case 'order' : 
  433. $url = admin_url( $screen->parent_file ); 
  434.  
  435. $up_url = add_query_arg( array( 
  436. 'action' => 'move-item-up',  
  437. 'post_id' => (int) $post_id,  
  438. ), wp_nonce_url( $url, 'nova_move_item_up_' . $post_id ) ); 
  439.  
  440. $down_url = add_query_arg( array( 
  441. 'action' => 'move-item-down',  
  442. 'post_id' => (int) $post_id,  
  443. ), wp_nonce_url( $url, 'nova_move_item_down_' . $post_id ) ); 
  444. $menu_item = get_post($post_id); 
  445. $this->get_menu_by_post_id( $post_id ); 
  446. ?> 
  447. <input type="hidden" class="menu-order-value" name="nova_order[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $menu_item->menu_order ) ?>" /> 
  448. <input type="hidden" class='nova-menu-term' name="nova_menu_term[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $this->get_menu_by_post_id( $post_id )->term_id ); ?>"> 
  449.  
  450. <span class="hide-if-js"> 
  451.     — <a class="nova-move-item-up" data-post-id="<?php echo (int) $post_id; ?>" href="<?php echo esc_url( $up_url ); ?>">up</a> 
  452. <br /> 
  453.     — <a class="nova-move-item-down" data-post-id="<?php echo (int) $post_id; ?>" href="<?php echo esc_url( $down_url ); ?>">down</a> 
  454. </span> 
  455. <?php 
  456. break; 
  457.  
  458. function get_menu_by_post_id( $post_id = null ) { 
  459. if ( ! $post_id ) 
  460. return false; 
  461.  
  462. $terms = get_the_terms( $post_id, self::MENU_TAX ); 
  463.  
  464. if ( ! is_array( $terms ) ) 
  465. return false; 
  466.  
  467. return array_pop( $terms ); 
  468.  
  469. /** 
  470. * Fires on a menu edit page. We might have drag-n-drop reordered 
  471. */ 
  472. function maybe_reorder_menu_items() { 
  473. // make sure we clicked our button 
  474. if ( ! ( isset( $_REQUEST['menu_reorder_submit'] ) && $_REQUEST['menu_reorder_submit'] === __( 'Save New Order', 'jetpack' ) ) ) 
  475. return; 
  476.  
  477. // make sure we have the nonce 
  478. if ( ! ( isset( $_REQUEST['drag-drop-reorder'] ) && wp_verify_nonce( $_REQUEST['drag-drop-reorder'], 'drag-drop-reorder' ) ) ) 
  479. return; 
  480.  
  481. $term_pairs = array_map( 'absint', $_REQUEST['nova_menu_term'] ); 
  482. $order_pairs = array_map( 'absint', $_REQUEST['nova_order'] ); 
  483.  
  484. foreach( $order_pairs as $ID => $menu_order ) { 
  485. $ID = absint( $ID ); 
  486. unset( $order_pairs[$ID] ); 
  487. if ( $ID < 0 ) 
  488. continue; 
  489.  
  490. $post = get_post( $ID ); 
  491. if ( ! $post ) 
  492. continue; 
  493.  
  494. // save a write if the order hasn't changed 
  495. if ( $menu_order != $post->menu_order ) 
  496. wp_update_post( compact( 'ID', 'menu_order' ) ); 
  497.  
  498. // save a write if the term hasn't changed 
  499. if ( $term_pairs[$ID] != $this->get_menu_by_post_id( $ID )->term_id ) 
  500. wp_set_object_terms( $ID, $term_pairs[$ID], self::MENU_TAX ); 
  501.  
  502.  
  503. $redirect = add_query_arg( array( 
  504. 'post_type' => self::MENU_ITEM_POST_TYPE,  
  505. 'nova_reordered' => '1' 
  506. ), admin_url( 'edit.php' ) ); 
  507. wp_safe_redirect( $redirect ); 
  508. exit; 
  509.  
  510.  
  511. function edit_menu_items_page_load() { 
  512. if ( isset( $_GET['action'] ) ) { 
  513. $this->handle_menu_item_actions(); 
  514.  
  515. $this->maybe_reorder_menu_items(); 
  516.  
  517. wp_enqueue_script( 'nova-drag-drop', plugins_url( 'js/nova-drag-drop.js', __FILE__ ), array( 'jquery-ui-sortable' ), $this->version, true ); 
  518. wp_localize_script( 'nova-drag-drop', '_novaDragDrop', array( 
  519. 'nonce' => wp_create_nonce( 'drag-drop-reorder' ),  
  520. 'nonceName' => 'drag-drop-reorder',  
  521. 'reorder' => __( 'Save New Order', 'jetpack' ),  
  522. 'reorderName' => 'menu_reorder_submit' 
  523. ) ); 
  524. add_action( 'the_post', array( $this, 'show_menu_titles_in_menu_item_list' ) ); 
  525.  
  526. function handle_menu_item_actions() { 
  527. $action = (string) $_GET['action']; 
  528.  
  529. switch ( $action ) { 
  530. case 'move-item-up' : 
  531. case 'move-item-down' : 
  532. $reorder = false; 
  533.  
  534. $post_id = (int) $_GET['post_id']; 
  535.  
  536. $term = $this->get_menu_item_menu_leaf( $post_id ); 
  537.  
  538. // Get all posts in that term 
  539. $query = new WP_Query( array( 
  540. 'taxonomy' => self::MENU_TAX,  
  541. 'term' => $term->slug,  
  542. ) ); 
  543.  
  544. $order = array(); 
  545. foreach ( $query->posts as $post ) { 
  546. $order[] = $post->ID; 
  547.  
  548. if ( 'move-item-up' == $action ) { 
  549. check_admin_referer( 'nova_move_item_up_' . $post_id ); 
  550.  
  551. $first_post_id = $order[0]; 
  552. if ( $post_id == $first_post_id ) { 
  553. break; 
  554.  
  555. foreach ( $order as $menu_order => $order_post_id ) { 
  556. if ( $post_id != $order_post_id ) { 
  557. continue; 
  558.  
  559. $swap_post_id = $order[$menu_order - 1]; 
  560. $order[$menu_order - 1] = $post_id; 
  561. $order[$menu_order] = $swap_post_id; 
  562.  
  563. $reorder = true; 
  564. break; 
  565. } else { 
  566. check_admin_referer( 'nova_move_item_down_' . $post_id ); 
  567.  
  568. $last_post_id = end( $order ); 
  569. if ( $post_id == $last_post_id ) { 
  570. break; 
  571.  
  572. foreach ( $order as $menu_order => $order_post_id ) { 
  573. if ( $post_id != $order_post_id ) { 
  574. continue; 
  575.  
  576. $swap_post_id = $order[$menu_order + 1]; 
  577. $order[$menu_order + 1] = $post_id; 
  578. $order[$menu_order] = $swap_post_id; 
  579.  
  580. $reorder = true; 
  581.  
  582. if ( $reorder ) { 
  583. foreach ( $order as $menu_order => $ID ) { 
  584. wp_update_post( compact( 'ID', 'menu_order' ) ); 
  585.  
  586. break; 
  587. case 'move-menu-up' : 
  588. case 'move-menu-down' : 
  589. $reorder = false; 
  590.  
  591. $term_id = (int) $_GET['term_id']; 
  592.  
  593. $terms = $this->get_menus(); 
  594.  
  595. $order = array(); 
  596. foreach ( $terms as $term ) { 
  597. $order[] = $term->term_id; 
  598.  
  599. if ( 'move-menu-up' == $action ) { 
  600. check_admin_referer( 'nova_move_menu_up_' . $term_id ); 
  601.  
  602. $first_term_id = $order[0]; 
  603. if ( $term_id == $first_term_id ) { 
  604. break; 
  605.  
  606. foreach ( $order as $menu_order => $order_term_id ) { 
  607. if ( $term_id != $order_term_id ) { 
  608. continue; 
  609.  
  610. $swap_term_id = $order[$menu_order - 1]; 
  611. $order[$menu_order - 1] = $term_id; 
  612. $order[$menu_order] = $swap_term_id; 
  613.  
  614. $reorder = true; 
  615. break; 
  616. } else { 
  617. check_admin_referer( 'nova_move_menu_down_' . $term_id ); 
  618.  
  619. $last_term_id = end( $order ); 
  620. if ( $term_id == $last_term_id ) { 
  621. break; 
  622.  
  623. foreach ( $order as $menu_order => $order_term_id ) { 
  624. if ( $term_id != $order_term_id ) { 
  625. continue; 
  626.  
  627. $swap_term_id = $order[$menu_order + 1]; 
  628. $order[$menu_order + 1] = $term_id; 
  629. $order[$menu_order] = $swap_term_id; 
  630.  
  631. $reorder = true; 
  632.  
  633. if ( $reorder ) { 
  634. update_option( 'nova_menu_order', $order ); 
  635.  
  636. break; 
  637. default : 
  638. return; 
  639.  
  640. $redirect = add_query_arg( array( 
  641. 'post_type' => self::MENU_ITEM_POST_TYPE,  
  642. 'nova_reordered' => '1' 
  643. ), admin_url( 'edit.php' ) ); 
  644. wp_safe_redirect( $redirect ); 
  645. exit; 
  646.  
  647. /** 
  648. * Add menu title rows to the list table 
  649. */ 
  650. function show_menu_titles_in_menu_item_list( $post ) { 
  651. global $wp_list_table; 
  652.  
  653. static $last_term_id = false; 
  654.  
  655. $term = $this->get_menu_item_menu_leaf( $post->ID ); 
  656.  
  657. if ( false !== $last_term_id && $last_term_id === $term->term_id ) 
  658. return; 
  659.  
  660. $last_term_id = $term->term_id; 
  661.  
  662. $parent_count = 0; 
  663. $current_term = $term; 
  664. while ( $current_term->parent ) { 
  665. $parent_count++; 
  666. $current_term = get_term( $current_term->parent, self::MENU_TAX ); 
  667.  
  668. $non_order_column_count = $wp_list_table->get_column_count() - 1; 
  669.  
  670. $screen = get_current_screen(); 
  671.  
  672. $url = admin_url( $screen->parent_file ); 
  673.  
  674. $up_url = add_query_arg( array( 
  675. 'action' => 'move-menu-up',  
  676. 'term_id' => (int) $term->term_id,  
  677. ), wp_nonce_url( $url, 'nova_move_menu_up_' . $term->term_id ) ); 
  678.  
  679. $down_url = add_query_arg( array( 
  680. 'action' => 'move-menu-down',  
  681. 'term_id' => (int) $term->term_id,  
  682. ), wp_nonce_url( $url, 'nova_move_menu_down_' . $term->term_id ) ); 
  683.  
  684. ?> 
  685. <tr class="no-items menu-label-row" data-term_id="<?php echo esc_attr( $term->term_id ) ?>"> 
  686. <td class="colspanchange" colspan="<?php echo (int) $non_order_column_count; ?>"> 
  687. <h3><?php 
  688. echo str_repeat( ' — ', (int) $parent_count ); 
  689.  
  690. if ( ! is_wp_error( $term ) ) { 
  691. echo esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, self::MENU_TAX, 'display' ) ); 
  692. edit_term_link( __( 'edit', 'jetpack' ), '<span class="edit-nova-section"><span class="dashicon dashicon-edit"></span>', '</span>', $term ); 
  693.  
  694. } else { 
  695. _e( 'Uncategorized' , 'jetpack' ); 
  696. ?></h3> 
  697. </td> 
  698. <td> 
  699. <?php if ( ! is_wp_error( $term ) ) { ?> 
  700. <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> 
  701. <br /> 
  702. <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> 
  703. <?php } ?> 
  704. </td> 
  705. </tr> 
  706. <?php 
  707.  
  708. /** Edit Many Items */ 
  709.  
  710. function add_many_new_items_page_load() { 
  711. if ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { 
  712. $this->process_form_request(); 
  713. exit; 
  714.  
  715. $this->enqueue_many_items_scripts(); 
  716.  
  717. function enqueue_many_items_scripts() { 
  718. wp_enqueue_script( 'nova-many-items', plugins_url( 'js/many-items.js', __FILE__ ), array( 'jquery' ), $this->version, true ); 
  719.  
  720. function process_form_request() { 
  721. if ( !isset( $_POST['nova_title'] ) || !is_array( $_POST['nova_title'] ) ) { 
  722. return; 
  723.  
  724. $is_ajax = !empty( $_POST['ajax'] ); 
  725.  
  726. if ( $is_ajax ) { 
  727. check_ajax_referer( 'nova_many_items' ); 
  728. } else { 
  729. check_admin_referer( 'nova_many_items' ); 
  730.  
  731. foreach ( array_keys( $_POST['nova_title'] ) as $key ) : 
  732. // $_POST is already slashed 
  733. $post_details = array( 
  734. 'post_status' => 'publish',  
  735. 'post_type' => self::MENU_ITEM_POST_TYPE,  
  736. 'post_content' => $_POST['nova_content'][$key],  
  737. 'post_title' => $_POST['nova_title'][$key],  
  738. 'tax_input' => array( 
  739. self::MENU_ITEM_LABEL_TAX => $_POST['nova_labels'][$key],  
  740. self::MENU_TAX => $_POST['nova_menu_tax'],  
  741. ),  
  742. ); 
  743.  
  744. $post_id = wp_insert_post( $post_details ); 
  745. if ( !$post_id || is_wp_error( $post_id ) ) { 
  746. continue; 
  747.  
  748. $this->set_price( $post_id, isset( $_POST['nova_price'][$key] ) ? stripslashes( $_POST['nova_price'][$key] ) : '' ); 
  749.  
  750. if ( $is_ajax ) : 
  751. $post = get_post( $post_id ); 
  752. $GLOBALS['post'] = $post; 
  753. setup_postdata( $post ); 
  754.  
  755. ?> 
  756. <td><?php the_title(); ?></td> 
  757. <td class="nova-price"><?php $this->display_price(); ?></td> 
  758. <td><?php $this->list_labels( $post_id ); ?></td> 
  759. <td><?php the_content(); ?></td> 
  760. <?php 
  761. endif; 
  762.  
  763. endforeach; 
  764.  
  765. if ( $is_ajax ) { 
  766. exit; 
  767.  
  768. wp_safe_redirect( admin_url( 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) ); 
  769. exit; 
  770.  
  771. function add_many_new_items_page() { 
  772. ?> 
  773. <div class="wrap"> 
  774. <h2><?php esc_html_e( 'Add Many Items', 'jetpack' ); ?></h2> 
  775.  
  776. <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> 
  777.  
  778. <form method="post" action="" enctype="multipart/form-data"> 
  779. <p><h3><?php esc_html_e( 'Add to section:', 'jetpack' ); ?> <?php wp_dropdown_categories( array( 
  780. 'id' => 'nova-menu-tax',  
  781. 'name' => 'nova_menu_tax',  
  782. 'taxonomy' => self::MENU_TAX,  
  783. 'hide_empty' => false,  
  784. 'hierarchical' => true,  
  785. ) ); ?></h3></p> 
  786.  
  787. <table class="many-items-table wp-list-table widefat"> 
  788. <thead> 
  789. <tr> 
  790. <th scope="col"><?php esc_html_e( 'Name', 'jetpack' ); ?></th> 
  791. <th scope="col" class="nova-price"><?php esc_html_e( 'Price', 'jetpack' ); ?></th> 
  792. <th scope="col"><?php _e( 'Labels: <small>spicy, favorite, etc. <em>Separate Labels with commas</em></small>', 'jetpack' ); ?></th> 
  793. <th scope="col"><?php esc_html_e( 'Description', 'jetpack' ); ?></th> 
  794. </tr> 
  795. </thead> 
  796. <tbody> 
  797. <tr> 
  798. <td><input type="text" name="nova_title[]" aria-required="true" /></td> 
  799. <td class="nova-price"><input type="text" name="nova_price[]" /></td> 
  800. <td><input type="text" name="nova_labels[]" /></td> 
  801. <td><textarea name="nova_content[]" cols="20" rows="1"></textarea> 
  802. </tr> 
  803. </tbody> 
  804. <tbody> 
  805. <tr> 
  806. <td><input type="text" name="nova_title[]" aria-required="true" /></td> 
  807. <td class="nova-price"><input type="text" name="nova_price[]" /></td> 
  808. <td><input type="text" name="nova_labels[]" /></td> 
  809. <td><textarea name="nova_content[]" cols="20" rows="1"></textarea> 
  810. </tr> 
  811. </tbody> 
  812. <tfoot> 
  813. <tr> 
  814. <th><a class="button button-secondary nova-new-row"><span class="dashicon dashicon-plus"></span> <?php esc_html_e( 'New Row' , 'jetpack' ); ?></a></th> 
  815. <th class="nova-price"></th> 
  816. <th></th> 
  817. <th></th> 
  818. </tr> 
  819. </tfoot> 
  820. </table> 
  821.  
  822. <p class="submit"> 
  823. <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Add These New Menu Items', 'jetpack' ); ?>" /> 
  824. <?php wp_nonce_field( 'nova_many_items' ); ?> 
  825. </p> 
  826. </form> 
  827. </div> 
  828. <?php 
  829.  
  830. /** Edit One Item */ 
  831.  
  832. function register_menu_item_meta_boxes() { 
  833. wp_enqueue_script( 'nova-menu-checkboxes' ); 
  834.  
  835. add_meta_box( 'menu_item_price', __( 'Price', 'jetpack' ), array( $this, 'menu_item_price_meta_box' ), null, 'side', 'high' ); 
  836.  
  837. function menu_item_price_meta_box( $post, $meta_box ) { 
  838. $price = $this->get_price( $post->ID ); 
  839. ?> 
  840. <label for="nova-price-<?php echo (int) $post->ID; ?>" class="screen-reader-text"><?php esc_html_e( 'Price', 'jetpack' ); ?></label> 
  841. <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 ); ?>" /> 
  842. <?php 
  843.  
  844. function add_post_meta( $post_id ) { 
  845. if ( !isset( $_POST['nova_price'][$post_id] ) ) { 
  846. return; 
  847.  
  848. $this->set_price( $post_id, stripslashes( $_POST['nova_price'][$post_id] ) ); 
  849.  
  850. /** Data */ 
  851.  
  852. function get_menus( $args = array() ) { 
  853. $args = wp_parse_args( $args, array( 
  854. 'hide_empty' => false,  
  855. ) ); 
  856.  
  857. $terms = get_terms( self::MENU_TAX, $args ); 
  858. if ( !$terms || is_wp_error( $terms ) ) { 
  859. return array(); 
  860.  
  861. $terms_by_id = array(); 
  862. foreach ( $terms as $term ) { 
  863. $terms_by_id["{$term->term_id}"] = $term; 
  864.  
  865. $term_order = get_option( 'nova_menu_order', array() ); 
  866.  
  867. $return = array(); 
  868. foreach ( $term_order as $term_id ) { 
  869. if ( isset( $terms_by_id["$term_id"] ) ) { 
  870. $return[] = $terms_by_id["$term_id"]; 
  871. unset( $terms_by_id["$term_id"] ); 
  872.  
  873. foreach ( $terms_by_id as $term_id => $term ) { 
  874. $return[] = $term; 
  875.  
  876. return $return; 
  877.  
  878. function get_menu_item_menu_leaf( $post_id ) { 
  879. // Get first menu taxonomy "leaf" 
  880. $term_ids = wp_get_object_terms( $post_id, self::MENU_TAX, array( 'fields' => 'ids' ) ); 
  881.  
  882. foreach ( $term_ids as $term_id ) { 
  883. $children = get_term_children( $term_id, self::MENU_TAX ); 
  884. if ( ! $children ) { 
  885. break; 
  886.  
  887. if ( ! isset( $term_id ) ) { 
  888. return false; 
  889.  
  890. return get_term( $term_id, self::MENU_TAX ); 
  891.  
  892.  
  893. function list_labels( $post_id = 0 ) { 
  894. $post = get_post( $post_id ); 
  895. echo get_the_term_list( $post->ID, self::MENU_ITEM_LABEL_TAX, '', _x( ', ', 'Nova label separator', 'jetpack' ), '' ); 
  896.  
  897. function list_admin_labels( $post_id = 0 ) { 
  898. $post = get_post( $post_id ); 
  899. $labels = get_the_terms( $post->ID, self::MENU_ITEM_LABEL_TAX ); 
  900. if ( !empty( $labels ) ) { 
  901. $out = array(); 
  902. foreach ( $labels as $label ) { 
  903. $out[] = sprintf( '<a href="%s">%s</a>',  
  904. esc_url( add_query_arg( array( 
  905. 'post_type' => self::MENU_ITEM_POST_TYPE,  
  906. 'taxonomy' => self::MENU_ITEM_LABEL_TAX,  
  907. 'term' => $label->slug 
  908. ), 'edit.php' ) ),  
  909. esc_html( sanitize_term_field( 'name', $label->name, $label->term_id, self::MENU_ITEM_LABEL_TAX, 'display' ) ) 
  910. ); 
  911.  
  912. echo join( _x( ', ', 'Nova label separator', 'jetpack' ), $out ); 
  913. } else { 
  914. esc_html_e( 'No Labels', 'jetpack' ); 
  915.  
  916. function set_price( $post_id = 0, $price = '' ) { 
  917. $post = get_post( $post_id ); 
  918.  
  919. return update_post_meta( $post->ID, 'nova_price', $price ); 
  920.  
  921. function get_price( $post_id = 0 ) { 
  922. $post = get_post( $post_id ); 
  923.  
  924. return get_post_meta( $post->ID, 'nova_price', true ); 
  925.  
  926. function display_price( $post_id = 0 ) { 
  927. echo esc_html( $this->get_price( $post_id ) ); 
  928.  
  929. /** Menu Item Loop Markup */ 
  930.  
  931. /** Does not support nested loops */ 
  932.  
  933. function get_menu_item_loop_markup( $field = null ) { 
  934. return $this->menu_item_loop_markup; 
  935.  
  936. /** 
  937. * Sets up the loop markup. 
  938. * Attached to the 'template_include' *filter*,  
  939. * which fires only during a real blog view (not in admin, feeds, etc.) 
  940. * 
  941. * @param string Template File 
  942. * @return string Template File. VERY Important. 
  943. */ 
  944. function setup_menu_item_loop_markup__in_filter( $template ) { 
  945. add_action( 'loop_start', array( $this, 'start_menu_item_loop' ) ); 
  946.  
  947. return $template; 
  948.  
  949. /** 
  950. * If the Query is a Menu Item Query, start outputing the Menu Item Loop Marku 
  951. * Attached to the 'loop_start' action. 
  952. * 
  953. * @param WP_Query 
  954. */ 
  955. function start_menu_item_loop( $query ) { 
  956. if ( !$this->is_menu_item_query( $query ) ) { 
  957. return; 
  958.  
  959. $this->menu_item_loop_last_term_id = false; 
  960. $this->menu_item_loop_current_term = false; 
  961.  
  962. add_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) ); 
  963. add_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) ); 
  964.  
  965. /** 
  966. * Outputs the Menu Item Loop Marku 
  967. * Attached to the 'the_post' action. 
  968. * 
  969. * @param WP_Post 
  970. */ 
  971. function menu_item_loop_each_post( $post ) { 
  972. $this->menu_item_loop_current_term = $this->get_menu_item_menu_leaf( $post->ID ); 
  973.  
  974. if ( false === $this->menu_item_loop_last_term_id ) { 
  975. // We're at the very beginning of the loop 
  976.  
  977. $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section 
  978. $this->menu_item_loop_header(); // Output the menu's header 
  979. } elseif ( $this->menu_item_loop_last_term_id != $this->menu_item_loop_current_term->term_id ) { 
  980. // We're not at the very beginning but still need to start a new menu section. End the previous menu section first. 
  981.  
  982. $this->menu_item_loop_close_element( 'menu' ); // End the previous menu section 
  983. $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section 
  984. $this->menu_item_loop_header(); // Output the menu's header 
  985.  
  986. $this->menu_item_loop_last_term_id = $this->menu_item_loop_current_term->term_id; 
  987.  
  988. /** 
  989. * If the Query is a Menu Item Query, stop outputing the Menu Item Loop Marku 
  990. * Attached to the 'loop_end' action. 
  991. * 
  992. * @param WP_Query 
  993. */ 
  994. function stop_menu_item_loop( $query ) { 
  995. if ( !$this->is_menu_item_query( $query ) ) { 
  996. return; 
  997.  
  998. remove_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) ); 
  999. remove_action( 'loop_start', array( $this, 'start_menu_item_loop' ) ); 
  1000. remove_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) ); 
  1001.  
  1002. $this->menu_item_loop_close_element( 'menu' ); // End the last menu section 
  1003.  
  1004. /** 
  1005. * Outputs the Menu Group Header 
  1006. */ 
  1007. function menu_item_loop_header() { 
  1008. $this->menu_item_loop_open_element( 'menu_header' ); 
  1009. $this->menu_item_loop_open_element( 'menu_title' ); 
  1010. echo esc_html( $this->menu_item_loop_current_term->name ); // @todo tax filter 
  1011. $this->menu_item_loop_close_element( 'menu_title' ); 
  1012. if ( $this->menu_item_loop_current_term->description ) : 
  1013. $this->menu_item_loop_open_element( 'menu_description' ); 
  1014. echo esc_html( $this->menu_item_loop_current_term->description ); // @todo kses, tax filter 
  1015. $this->menu_item_loop_close_element( 'menu_description' ); 
  1016. endif; 
  1017. $this->menu_item_loop_close_element( 'menu_header' ); 
  1018.  
  1019. /** 
  1020. * Outputs a Menu Item Markup element opening tag 
  1021. * 
  1022. * @param string $field - Menu Item Markup settings field 
  1023. */ 
  1024. function menu_item_loop_open_element( $field ) { 
  1025. $markup = $this->get_menu_item_loop_markup(); 
  1026. echo '<' . tag_escape( $markup["{$field}_tag"] ) . $this->menu_item_loop_class( $markup["{$field}_class"] ) . ">\n"; 
  1027.  
  1028. /** 
  1029. * Outputs a Menu Item Markup element closing tag 
  1030. * 
  1031. * @param string $field - Menu Item Markup settings field 
  1032. */ 
  1033. function menu_item_loop_close_element( $field ) { 
  1034. $markup = $this->get_menu_item_loop_markup(); 
  1035. echo '</' . tag_escape( $markup["{$field}_tag"] ) . ">\n"; 
  1036.  
  1037. /** 
  1038. * Returns a Menu Item Markup element's class attribute 
  1039. * 
  1040. * @param string $class 
  1041. * @return string HTML class attribute with leading whitespace 
  1042. */ 
  1043. function menu_item_loop_class( $class ) { 
  1044. if ( !$class ) { 
  1045. return ''; 
  1046.  
  1047. return ' class="' . esc_attr( $class ) . '"'; 
  1048.  
  1049. add_action( 'init', array( 'Nova_Restaurant', 'init' ) ); 
.