Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Nova_Restaurant often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Nova_Restaurant, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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 | // Enable Omnisearch for Menu Items. |
||
| 75 | if ( class_exists( 'Jetpack_Omnisearch_Posts' ) ) |
||
| 76 | new Jetpack_Omnisearch_Posts( self::MENU_ITEM_POST_TYPE ); |
||
| 77 | |||
| 78 | // Always sort menu items correctly |
||
| 79 | add_action( 'parse_query', array( $this, 'sort_menu_item_queries_by_menu_order' ) ); |
||
| 80 | add_filter( 'posts_results', array( $this, 'sort_menu_item_queries_by_menu_taxonomy' ), 10, 2 ); |
||
| 81 | |||
| 82 | add_action( 'wp_insert_post', array( $this, 'add_post_meta' ) ); |
||
| 83 | |||
| 84 | $this->menu_item_loop_markup = $this->default_menu_item_loop_markup; |
||
| 85 | |||
| 86 | // Only output our Menu Item Loop Markup on a real blog view. Not feeds, XML-RPC, admin, etc. |
||
| 87 | add_filter( 'template_include', array( $this, 'setup_menu_item_loop_markup__in_filter' ) ); |
||
| 88 | |||
| 89 | add_filter( 'enter_title_here', array( $this, 'change_default_title' ) ); |
||
| 90 | add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); |
||
| 91 | add_filter( 'dashboard_glance_items', array( $this, 'add_to_dashboard' ) ); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Should this Custom Post Type be made available? |
||
| 96 | */ |
||
| 97 | function site_supports_nova() { |
||
| 98 | // If we're on WordPress.com, and it has the menu site vertical. |
||
| 99 | if ( function_exists( 'site_vertical' ) && 'nova_menu' == site_vertical() ) |
||
| 100 | return true; |
||
| 101 | |||
| 102 | // Else, if the current theme requests it. |
||
| 103 | if ( current_theme_supports( self::MENU_ITEM_POST_TYPE ) ) |
||
| 104 | return true; |
||
| 105 | |||
| 106 | // Otherwise, say no unless something wants to filter us to say yes. |
||
| 107 | /** |
||
| 108 | * Allow something else to hook in and enable this CPT. |
||
| 109 | * |
||
| 110 | * @module custom-content-types |
||
| 111 | * |
||
| 112 | * @since 2.6.0 |
||
| 113 | * |
||
| 114 | * @param bool false Whether or not to enable this CPT. |
||
| 115 | * @param string $var The slug for this CPT. |
||
| 116 | */ |
||
| 117 | return (bool) apply_filters( 'jetpack_enable_cpt', false, self::MENU_ITEM_POST_TYPE ); |
||
| 118 | } |
||
| 119 | |||
| 120 | /* Setup */ |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Register Taxonomies and Post Type |
||
| 124 | */ |
||
| 125 | function register_taxonomies() { |
||
| 126 | if ( ! taxonomy_exists( self::MENU_ITEM_LABEL_TAX ) ) { |
||
| 127 | register_taxonomy( self::MENU_ITEM_LABEL_TAX, self::MENU_ITEM_POST_TYPE, array( |
||
| 128 | 'labels' => array( |
||
| 129 | /* translators: this is about a food menu */ |
||
| 130 | 'name' => __( 'Menu Item Labels', 'jetpack' ), |
||
| 131 | /* translators: this is about a food menu */ |
||
| 132 | 'singular_name' => __( 'Menu Item Label', 'jetpack' ), |
||
| 133 | /* translators: this is about a food menu */ |
||
| 134 | 'search_items' => __( 'Search Menu Item Labels', 'jetpack' ), |
||
| 135 | 'popular_items' => __( 'Popular Labels', 'jetpack' ), |
||
| 136 | /* translators: this is about a food menu */ |
||
| 137 | 'all_items' => __( 'All Menu Item Labels', 'jetpack' ), |
||
| 138 | /* translators: this is about a food menu */ |
||
| 139 | 'edit_item' => __( 'Edit Menu Item Label', 'jetpack' ), |
||
| 140 | /* translators: this is about a food menu */ |
||
| 141 | 'view_item' => __( 'View Menu Item Label', 'jetpack' ), |
||
| 142 | /* translators: this is about a food menu */ |
||
| 143 | 'update_item' => __( 'Update Menu Item Label', 'jetpack' ), |
||
| 144 | /* translators: this is about a food menu */ |
||
| 145 | 'add_new_item' => __( 'Add New Menu Item Label', 'jetpack' ), |
||
| 146 | /* translators: this is about a food menu */ |
||
| 147 | 'new_item_name' => __( 'New Menu Item Label Name', 'jetpack' ), |
||
| 148 | 'separate_items_with_commas' => __( 'For example, spicy, favorite, etc. <br /> Separate Labels with commas', 'jetpack' ), |
||
| 149 | 'add_or_remove_items' => __( 'Add or remove Labels', 'jetpack' ), |
||
| 150 | 'choose_from_most_used' => __( 'Choose from the most used Labels', 'jetpack' ), |
||
| 151 | 'items_list_navigation' => __( 'Menu item label list navigation', 'jetpack' ), |
||
| 152 | 'items_list' => __( 'Menu item labels list', 'jetpack' ), |
||
| 153 | ), |
||
| 154 | 'no_tagcloud' => __( 'No Labels found', 'jetpack' ), |
||
| 155 | 'hierarchical' => false, |
||
| 156 | ) ); |
||
| 157 | } |
||
| 158 | |||
| 159 | if ( ! taxonomy_exists( self::MENU_TAX ) ) { |
||
| 160 | register_taxonomy( self::MENU_TAX, self::MENU_ITEM_POST_TYPE, array( |
||
| 161 | 'labels' => array( |
||
| 162 | /* translators: this is about a food menu */ |
||
| 163 | 'name' => __( 'Menu Sections', 'jetpack' ), |
||
| 164 | /* translators: this is about a food menu */ |
||
| 165 | 'singular_name' => __( 'Menu Section', 'jetpack' ), |
||
| 166 | /* translators: this is about a food menu */ |
||
| 167 | 'search_items' => __( 'Search Menu Sections', 'jetpack' ), |
||
| 168 | /* translators: this is about a food menu */ |
||
| 169 | 'all_items' => __( 'All Menu Sections', 'jetpack' ), |
||
| 170 | /* translators: this is about a food menu */ |
||
| 171 | 'parent_item' => __( 'Parent Menu Section', 'jetpack' ), |
||
| 172 | /* translators: this is about a food menu */ |
||
| 173 | 'parent_item_colon' => __( 'Parent Menu Section:', 'jetpack' ), |
||
| 174 | /* translators: this is about a food menu */ |
||
| 175 | 'edit_item' => __( 'Edit Menu Section', 'jetpack' ), |
||
| 176 | /* translators: this is about a food menu */ |
||
| 177 | 'view_item' => __( 'View Menu Section', 'jetpack' ), |
||
| 178 | /* translators: this is about a food menu */ |
||
| 179 | 'update_item' => __( 'Update Menu Section', 'jetpack' ), |
||
| 180 | /* translators: this is about a food menu */ |
||
| 181 | 'add_new_item' => __( 'Add New Menu Section', 'jetpack' ), |
||
| 182 | /* translators: this is about a food menu */ |
||
| 183 | 'new_item_name' => __( 'New Menu Sections Name', 'jetpack' ), |
||
| 184 | 'items_list_navigation' => __( 'Menu section list navigation', 'jetpack' ), |
||
| 185 | 'items_list' => __( 'Menu section list', 'jetpack' ), |
||
| 186 | ), |
||
| 187 | 'rewrite' => array( |
||
| 188 | 'slug' => 'menu', |
||
| 189 | 'with_front' => false, |
||
| 190 | 'hierarchical' => true, |
||
| 191 | ), |
||
| 192 | 'hierarchical' => true, |
||
| 193 | 'show_tagcloud' => false, |
||
| 194 | 'query_var' => 'menu', |
||
| 195 | ) ); |
||
| 196 | } |
||
| 197 | } |
||
| 198 | |||
| 199 | View Code Duplication | function register_post_types() { |
|
| 200 | if ( post_type_exists( self::MENU_ITEM_POST_TYPE ) ) { |
||
| 201 | return; |
||
| 202 | } |
||
| 203 | |||
| 204 | register_post_type( self::MENU_ITEM_POST_TYPE, array( |
||
| 205 | 'description' => __( "Items on your restaurant's menu", 'jetpack' ), |
||
| 206 | |||
| 207 | 'labels' => array( |
||
| 208 | /* translators: this is about a food menu */ |
||
| 209 | 'name' => __( 'Menu Items', 'jetpack' ), |
||
| 210 | /* translators: this is about a food menu */ |
||
| 211 | 'singular_name' => __( 'Menu Item', 'jetpack' ), |
||
| 212 | /* translators: this is about a food menu */ |
||
| 213 | 'menu_name' => __( 'Food Menus', 'jetpack' ), |
||
| 214 | /* translators: this is about a food menu */ |
||
| 215 | 'all_items' => __( 'Menu Items', 'jetpack' ), |
||
| 216 | /* translators: this is about a food menu */ |
||
| 217 | 'add_new' => __( 'Add One Item', 'jetpack' ), |
||
| 218 | /* translators: this is about a food menu */ |
||
| 219 | 'add_new_item' => __( 'Add Menu Item', 'jetpack' ), |
||
| 220 | /* translators: this is about a food menu */ |
||
| 221 | 'edit_item' => __( 'Edit Menu Item', 'jetpack' ), |
||
| 222 | /* translators: this is about a food menu */ |
||
| 223 | 'new_item' => __( 'New Menu Item', 'jetpack' ), |
||
| 224 | /* translators: this is about a food menu */ |
||
| 225 | 'view_item' => __( 'View Menu Item', 'jetpack' ), |
||
| 226 | /* translators: this is about a food menu */ |
||
| 227 | 'search_items' => __( 'Search Menu Items', 'jetpack' ), |
||
| 228 | /* translators: this is about a food menu */ |
||
| 229 | 'not_found' => __( 'No Menu Items found', 'jetpack' ), |
||
| 230 | /* translators: this is about a food menu */ |
||
| 231 | 'not_found_in_trash' => __( 'No Menu Items found in Trash', 'jetpack' ), |
||
| 232 | 'filter_items_list' => __( 'Filter menu items list', 'jetpack' ), |
||
| 233 | 'items_list_navigation' => __( 'Menu item list navigation', 'jetpack' ), |
||
| 234 | 'items_list' => __( 'Menu items list', 'jetpack' ), |
||
| 235 | ), |
||
| 236 | 'supports' => array( |
||
| 237 | 'title', |
||
| 238 | 'editor', |
||
| 239 | 'thumbnail', |
||
| 240 | 'excerpt', |
||
| 241 | ), |
||
| 242 | 'rewrite' => array( |
||
| 243 | 'slug' => 'item', |
||
| 244 | 'with_front' => false, |
||
| 245 | 'feeds' => false, |
||
| 246 | 'pages' => false, |
||
| 247 | ), |
||
| 248 | 'register_meta_box_cb' => array( $this, 'register_menu_item_meta_boxes' ), |
||
| 249 | |||
| 250 | 'public' => true, |
||
| 251 | 'show_ui' => true, // set to false to replace with custom UI |
||
| 252 | 'menu_position' => 20, // below Pages |
||
| 253 | 'capability_type' => 'page', |
||
| 254 | 'map_meta_cap' => true, |
||
| 255 | 'has_archive' => false, |
||
| 256 | 'query_var' => 'item', |
||
| 257 | ) ); |
||
| 258 | } |
||
| 259 | |||
| 260 | |||
| 261 | /** |
||
| 262 | * Update messages for the Menu Item admin. |
||
| 263 | */ |
||
| 264 | View Code Duplication | function updated_messages( $messages ) { |
|
| 293 | |||
| 294 | |||
| 295 | /** |
||
| 296 | * Nova Styles and Scripts |
||
| 297 | */ |
||
| 298 | function enqueue_nova_styles( $hook ) { |
||
| 299 | global $post_type; |
||
| 300 | $pages = array( 'edit.php', 'post.php', 'post-new.php' ); |
||
| 301 | |||
| 302 | if ( in_array( $hook, $pages ) && $post_type == self::MENU_ITEM_POST_TYPE ) { |
||
| 303 | wp_enqueue_style( 'nova-style', plugins_url( 'css/nova.css', __FILE__ ), array(), $this->version ); |
||
| 304 | } |
||
| 305 | |||
| 306 | wp_enqueue_style( 'nova-font', plugins_url( 'css/nova-font.css', __FILE__ ), array(), $this->version ); |
||
| 307 | } |
||
| 308 | |||
| 309 | |||
| 310 | /** |
||
| 311 | * Change ‘Enter Title Here’ text for the Menu Item. |
||
| 312 | */ |
||
| 313 | View Code Duplication | function change_default_title( $title ) { |
|
| 322 | |||
| 323 | |||
| 324 | /** |
||
| 325 | * Add to Dashboard At A Glance |
||
| 326 | */ |
||
| 327 | function add_to_dashboard() { |
||
| 328 | $number_menu_items = wp_count_posts( self::MENU_ITEM_POST_TYPE ); |
||
| 329 | |||
| 330 | if ( current_user_can( 'administrator' ) ) { |
||
| 331 | $number_menu_items_published = sprintf( '<a href="%1$s">%2$s</a>', |
||
| 332 | esc_url( get_admin_url( get_current_blog_id(), 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) ), |
||
| 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 | else { |
||
| 337 | $number_menu_items_published = sprintf( '<span>%1$s</span>', |
||
| 338 | 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 ) ) |
||
| 339 | ); |
||
| 340 | } |
||
| 341 | |||
| 342 | echo '<li class="nova-menu-count">' . $number_menu_items_published . '</li>'; |
||
| 343 | } |
||
| 344 | |||
| 345 | |||
| 346 | /** |
||
| 347 | * Query |
||
| 348 | */ |
||
| 349 | function is_menu_item_query( $query ) { |
||
| 350 | if ( |
||
| 351 | ( isset( $query->query_vars['taxonomy'] ) && self::MENU_TAX == $query->query_vars['taxonomy'] ) |
||
| 352 | || |
||
| 353 | ( isset( $query->query_vars['post_type'] ) && self::MENU_ITEM_POST_TYPE == $query->query_vars['post_type'] ) |
||
| 354 | ) { |
||
| 355 | return true; |
||
| 356 | } |
||
| 357 | |||
| 358 | return false; |
||
| 359 | } |
||
| 360 | |||
| 361 | function sort_menu_item_queries_by_menu_order( $query ) { |
||
| 362 | if ( ! $this->is_menu_item_query( $query ) ) { |
||
| 363 | return; |
||
| 364 | } |
||
| 365 | |||
| 366 | $query->query_vars['orderby'] = 'menu_order'; |
||
| 367 | $query->query_vars['order'] = 'ASC'; |
||
| 368 | |||
| 369 | // For now, just turn off paging so we can sort by taxonmy later |
||
| 370 | // 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) |
||
| 371 | $query->query_vars['posts_per_page'] = -1; |
||
| 372 | } |
||
| 373 | |||
| 374 | function sort_menu_item_queries_by_menu_taxonomy( $posts, $query ) { |
||
| 375 | if ( !$posts ) { |
||
| 376 | return $posts; |
||
| 377 | } |
||
| 378 | |||
| 379 | if ( !$this->is_menu_item_query( $query ) ) { |
||
| 380 | return $posts; |
||
| 381 | } |
||
| 382 | |||
| 383 | $grouped_by_term = array(); |
||
| 384 | |||
| 385 | foreach ( $posts as $post ) { |
||
| 386 | $term = $this->get_menu_item_menu_leaf( $post->ID ); |
||
| 387 | if ( !$term || is_wp_error( $term ) ) { |
||
| 388 | $term_id = 0; |
||
| 389 | } else { |
||
| 390 | $term_id = $term->term_id; |
||
| 391 | } |
||
| 392 | |||
| 393 | if ( !isset( $grouped_by_term["$term_id"] ) ) { |
||
| 394 | $grouped_by_term["$term_id"] = array(); |
||
| 395 | } |
||
| 396 | |||
| 397 | $grouped_by_term["$term_id"][] = $post; |
||
| 398 | } |
||
| 399 | |||
| 400 | $term_order = get_option( 'nova_menu_order', array() ); |
||
| 401 | |||
| 402 | $return = array(); |
||
| 403 | View Code Duplication | foreach ( $term_order as $term_id ) { |
|
| 404 | if ( isset( $grouped_by_term["$term_id"] ) ) { |
||
| 405 | $return = array_merge( $return, $grouped_by_term["$term_id"] ); |
||
| 406 | unset( $grouped_by_term["$term_id"] ); |
||
| 407 | } |
||
| 408 | } |
||
| 409 | |||
| 410 | foreach ( $grouped_by_term as $term_id => $posts ) { |
||
| 411 | $return = array_merge( $return, $posts ); |
||
| 412 | } |
||
| 413 | |||
| 414 | return $return; |
||
| 415 | } |
||
| 416 | |||
| 417 | |||
| 418 | /** |
||
| 419 | * Add Many Items |
||
| 420 | */ |
||
| 421 | function add_admin_menus() { |
||
| 422 | $hook = add_submenu_page( |
||
| 423 | 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE, |
||
| 424 | __( 'Add Many Items', 'jetpack' ), |
||
| 425 | __( 'Add Many Items', 'jetpack' ), |
||
| 426 | 'edit_pages', |
||
| 427 | 'add_many_nova_items', |
||
| 428 | array( $this, 'add_many_new_items_page' ) |
||
| 429 | ); |
||
| 430 | |||
| 431 | add_action( "load-$hook", array( $this, 'add_many_new_items_page_load' ) ); |
||
| 432 | |||
| 433 | add_action( 'current_screen', array( $this, 'current_screen_load' ) ); |
||
| 434 | |||
| 435 | //Adjust 'Add Many Items' submenu position |
||
| 436 | $submenu_item = array_pop( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] ); |
||
| 437 | $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE][11] = $submenu_item; |
||
| 438 | ksort( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] ); |
||
| 439 | |||
| 440 | $this->setup_menu_item_columns(); |
||
| 441 | |||
| 442 | wp_register_script( 'nova-menu-checkboxes', plugins_url( 'js/menu-checkboxes.js', __FILE__ ), array( 'jquery' ), $this->version, true ); |
||
| 443 | } |
||
| 444 | |||
| 445 | |||
| 446 | /** |
||
| 447 | * Custom Nova Icon CSS |
||
| 448 | */ |
||
| 449 | function set_custom_font_icon() { |
||
| 450 | ?> |
||
| 451 | <style type="text/css"> |
||
| 452 | #menu-posts-nova_menu_item .wp-menu-image:before { |
||
| 453 | font-family: 'nova-font' !important; |
||
| 454 | content: '\e603' !important; |
||
| 455 | } |
||
| 456 | </style> |
||
| 457 | <?php |
||
| 458 | } |
||
| 459 | |||
| 460 | function current_screen_load() { |
||
| 461 | $screen = get_current_screen(); |
||
| 462 | if ( 'edit-nova_menu_item' !== $screen->id ) { |
||
| 463 | return; |
||
| 464 | } |
||
| 465 | |||
| 466 | $this->edit_menu_items_page_load(); |
||
| 467 | add_filter( 'admin_notices', array( $this, 'admin_notices' ) ); |
||
| 468 | } |
||
| 469 | |||
| 470 | /* Edit Items List */ |
||
| 471 | |||
| 472 | function admin_notices() { |
||
| 477 | |||
| 478 | function no_title_sorting( $columns ) { |
||
| 479 | if ( isset( $columns['title'] ) ) |
||
| 480 | unset( $columns['title'] ); |
||
| 481 | return $columns; |
||
| 482 | } |
||
| 483 | |||
| 484 | function setup_menu_item_columns() { |
||
| 485 | add_filter( sprintf( 'manage_edit-%s_sortable_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'no_title_sorting' ) ); |
||
| 486 | add_filter( sprintf( 'manage_%s_posts_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_columns' ) ); |
||
| 487 | |||
| 488 | add_action( sprintf( 'manage_%s_posts_custom_column', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_column_callback' ), 10, 2 ); |
||
| 489 | } |
||
| 490 | |||
| 491 | function menu_item_columns( $columns ) { |
||
| 492 | unset( $columns['date'], $columns['likes'] ); |
||
| 501 | |||
| 502 | function menu_item_column_callback( $column, $post_id ) { |
||
| 542 | |||
| 543 | function get_menu_by_post_id( $post_id = null ) { |
||
| 554 | |||
| 555 | /** |
||
| 556 | * Fires on a menu edit page. We might have drag-n-drop reordered |
||
| 557 | */ |
||
| 558 | function maybe_reorder_menu_items() { |
||
| 599 | |||
| 600 | function edit_menu_items_page_load() { |
||
| 616 | |||
| 617 | function handle_menu_item_actions() { |
||
| 758 | |||
| 759 | /* |
||
| 760 | * Add menu title rows to the list table |
||
| 761 | */ |
||
| 762 | function show_menu_titles_in_menu_item_list( $post ) { |
||
| 822 | |||
| 823 | /* Edit Many Items */ |
||
| 824 | |||
| 825 | function add_many_new_items_page_load() { |
||
| 833 | |||
| 834 | function enqueue_many_items_scripts() { |
||
| 837 | |||
| 838 | function process_form_request() { |
||
| 893 | |||
| 894 | function add_many_new_items_page() { |
||
| 953 | |||
| 954 | /* Edit One Item */ |
||
| 955 | |||
| 956 | function register_menu_item_meta_boxes() { |
||
| 961 | |||
| 962 | function menu_item_price_meta_box( $post, $meta_box ) { |
||
| 969 | |||
| 970 | function add_post_meta( $post_id ) { |
||
| 977 | |||
| 978 | /* Data */ |
||
| 979 | |||
| 980 | function get_menus( $args = array() ) { |
||
| 1011 | |||
| 1012 | function get_menu_item_menu_leaf( $post_id ) { |
||
| 1030 | |||
| 1031 | function list_labels( $post_id = 0 ) { |
||
| 1035 | |||
| 1036 | function list_admin_labels( $post_id = 0 ) { |
||
| 1057 | |||
| 1058 | function set_price( $post_id = 0, $price = '' ) { |
||
| 1063 | |||
| 1064 | function get_price( $post_id = 0 ) { |
||
| 1069 | |||
| 1070 | function display_price( $post_id = 0 ) { |
||
| 1073 | |||
| 1074 | /* Menu Item Loop Markup */ |
||
| 1075 | |||
| 1076 | /* Does not support nested loops */ |
||
| 1077 | |||
| 1078 | function get_menu_item_loop_markup( $field = null ) { |
||
| 1081 | |||
| 1082 | /** |
||
| 1083 | * Sets up the loop markup. |
||
| 1084 | * Attached to the 'template_include' *filter*, |
||
| 1085 | * which fires only during a real blog view (not in admin, feeds, etc.) |
||
| 1086 | * |
||
| 1087 | * @param string Template File |
||
| 1088 | * @return string Template File. VERY Important. |
||
| 1089 | */ |
||
| 1090 | function setup_menu_item_loop_markup__in_filter( $template ) { |
||
| 1095 | |||
| 1096 | /** |
||
| 1097 | * If the Query is a Menu Item Query, start outputing the Menu Item Loop Marku |
||
| 1098 | * Attached to the 'loop_start' action. |
||
| 1099 | * |
||
| 1100 | * @param WP_Query |
||
| 1101 | */ |
||
| 1102 | function start_menu_item_loop( $query ) { |
||
| 1113 | |||
| 1114 | /** |
||
| 1115 | * Outputs the Menu Item Loop Marku |
||
| 1116 | * Attached to the 'the_post' action. |
||
| 1117 | * |
||
| 1118 | * @param WP_Post |
||
| 1119 | */ |
||
| 1120 | function menu_item_loop_each_post( $post ) { |
||
| 1138 | |||
| 1139 | /** |
||
| 1140 | * If the Query is a Menu Item Query, stop outputing the Menu Item Loop Marku |
||
| 1141 | * Attached to the 'loop_end' action. |
||
| 1142 | * |
||
| 1143 | * @param WP_Query |
||
| 1144 | */ |
||
| 1145 | function stop_menu_item_loop( $query ) { |
||
| 1156 | |||
| 1157 | /** |
||
| 1158 | * Outputs the Menu Group Header |
||
| 1159 | */ |
||
| 1160 | function menu_item_loop_header() { |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Outputs a Menu Item Markup element opening tag |
||
| 1175 | * |
||
| 1176 | * @param string $field - Menu Item Markup settings field |
||
| 1177 | */ |
||
| 1178 | function menu_item_loop_open_element( $field ) { |
||
| 1182 | |||
| 1183 | /** |
||
| 1184 | * Outputs a Menu Item Markup element closing tag |
||
| 1185 | * |
||
| 1186 | * @param string $field - Menu Item Markup settings field |
||
| 1187 | */ |
||
| 1188 | function menu_item_loop_close_element( $field ) { |
||
| 1192 | |||
| 1193 | /** |
||
| 1194 | * Returns a Menu Item Markup element's class attribute |
||
| 1195 | * |
||
| 1196 | * @param string $class |
||
| 1197 | * @return string HTML class attribute with leading whitespace |
||
| 1198 | */ |
||
| 1199 | function menu_item_loop_class( $class ) { |
||
| 1206 | } |
||
| 1207 | |||
| 1209 |
This check looks
TODOcomments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.