~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-admin/includes/nav-menu.php

  • Committer: Barry Price
  • Date: 2016-08-17 04:50:12 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: barry.price@canonical.com-20160817045012-qfui81zhqnqv2ba9
Merge WP4.6 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
 
71
71
        } elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) {
72
72
                if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) {
73
 
                        query_posts(array(
74
 
                                'posts_per_page' => 10,
75
 
                                'post_type' => $matches[2],
76
 
                                's' => $query,
77
 
                        ));
78
 
                        if ( ! have_posts() )
 
73
                        $search_results_query = new WP_Query( array(
 
74
                                'no_found_rows'          => true,
 
75
                                'update_post_meta_cache' => false,
 
76
                                'update_post_term_cache' => false,
 
77
                                'posts_per_page'         => 10,
 
78
                                'post_type'              => $matches[2],
 
79
                                's'                      => $query,
 
80
                        ) );
 
81
                        if ( ! $search_results_query->have_posts() ) {
79
82
                                return;
80
 
                        while ( have_posts() ) {
81
 
                                the_post();
 
83
                        }
 
84
                        while ( $search_results_query->have_posts() ) {
 
85
                                $post = $search_results_query->next_post();
82
86
                                if ( 'markup' == $response_format ) {
83
 
                                        $var_by_ref = get_the_ID();
 
87
                                        $var_by_ref = $post->ID;
84
88
                                        echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
85
89
                                } elseif ( 'json' == $response_format ) {
86
90
                                        echo wp_json_encode(
87
91
                                                array(
88
 
                                                        'ID' => get_the_ID(),
89
 
                                                        'post_title' => get_the_title(),
90
 
                                                        'post_type' => get_post_type(),
 
92
                                                        'ID' => $post->ID,
 
93
                                                        'post_title' => get_the_title( $post->ID ),
 
94
                                                        'post_type' => $matches[2],
91
95
                                                )
92
96
                                        );
93
97
                                        echo "\n";
119
123
}
120
124
 
121
125
/**
122
 
 * Register nav menu metaboxes and advanced menu items
 
126
 * Register nav menu meta boxes and advanced menu items.
123
127
 *
124
128
 * @since 3.0.0
125
129
 **/
174
178
}
175
179
 
176
180
/**
177
 
 * Creates metaboxes for any post type menu item.
 
181
 * Creates meta boxes for any post type menu item..
178
182
 *
179
183
 * @since 3.0.0
180
184
 */
186
190
 
187
191
        foreach ( $post_types as $post_type ) {
188
192
                /**
189
 
                 * Filter whether a menu items meta box will be added for the current
 
193
                 * Filters whether a menu items meta box will be added for the current
190
194
                 * object type.
191
195
                 *
192
196
                 * If a falsey value is returned instead of an object, the menu items
208
212
}
209
213
 
210
214
/**
211
 
 * Creates metaboxes for any taxonomy menu item.
 
215
 * Creates meta boxes for any taxonomy menu item.
212
216
 *
213
217
 * @since 3.0.0
214
218
 */
248
252
}
249
253
 
250
254
/**
251
 
 * Displays a metabox for the custom links menu item.
 
255
 * Displays a meta box for the custom links menu item.
252
256
 *
253
257
 * @since 3.0.0
254
258
 *
285
289
}
286
290
 
287
291
/**
288
 
 * Displays a metabox for a post type menu item.
 
292
 * Displays a meta box for a post type menu item.
289
293
 *
290
294
 * @since 3.0.0
291
295
 *
293
297
 * @global int|string $nav_menu_selected_id
294
298
 *
295
299
 * @param string $object Not used.
296
 
 * @param string $post_type The post type object.
 
300
 * @param array  $box {
 
301
 *     Post type menu item meta box arguments.
 
302
 *
 
303
 *     @type string       $id       Meta box 'id' attribute.
 
304
 *     @type string       $title    Meta box title.
 
305
 *     @type string       $callback Meta box display callback.
 
306
 *     @type WP_Post_Type $args     Extra meta box arguments (the post type object for this meta box).
 
307
 * }
297
308
 */
298
 
function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
 
309
function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
299
310
        global $_nav_menu_placeholder, $nav_menu_selected_id;
300
311
 
301
 
        $post_type_name = $post_type['args']->name;
 
312
        $post_type_name = $box['args']->name;
302
313
 
303
314
        // Paginate browsing for large numbers of post objects.
304
315
        $per_page = 50;
316
327
                'update_post_meta_cache' => false
317
328
        );
318
329
 
319
 
        if ( isset( $post_type['args']->_default_query ) )
320
 
                $args = array_merge($args, (array) $post_type['args']->_default_query );
 
330
        if ( isset( $box['args']->_default_query ) )
 
331
                $args = array_merge($args, (array) $box['args']->_default_query );
321
332
 
322
333
        // @todo transient caching of these results with proper invalidation on updating of a post of this type
323
334
        $get_posts = new WP_Query;
400
411
                                $args['walker'] = $walker;
401
412
 
402
413
                                /**
403
 
                                 * Filter the posts displayed in the 'Most Recent' tab of the current
 
414
                                 * Filters the posts displayed in the 'Most Recent' tab of the current
404
415
                                 * post type's menu items meta box.
405
416
                                 *
406
417
                                 * The dynamic portion of the hook name, `$post_type_name`, refers to the post type name.
407
418
                                 *
408
419
                                 * @since 4.3.0
409
420
                                 *
410
 
                                 * @param array  $most_recent An array of post objects being listed.
411
 
                                 * @param array  $args        An array of WP_Query arguments.
412
 
                                 * @param object $post_type   The current post type object for this menu item meta box.
 
421
                                 * @param array $most_recent An array of post objects being listed.
 
422
                                 * @param array $args        An array of WP_Query arguments.
 
423
                                 * @param array $box         Arguments passed to wp_nav_menu_item_post_type_meta_box().
413
424
                                 */
414
 
                                $most_recent = apply_filters( "nav_menu_items_{$post_type_name}_recent", $most_recent, $args, $post_type );
 
425
                                $most_recent = apply_filters( "nav_menu_items_{$post_type_name}_recent", $most_recent, $args, $box );
415
426
 
416
427
                                echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $most_recent), 0, (object) $args );
417
428
                                ?>
508
519
                                }
509
520
 
510
521
                                /**
511
 
                                 * Filter the posts displayed in the 'View All' tab of the current
 
522
                                 * Filters the posts displayed in the 'View All' tab of the current
512
523
                                 * post type's menu items meta box.
513
524
                                 *
514
525
                                 * The dynamic portion of the hook name, `$post_type_name`, refers
515
526
                                 * to the slug of the current post type.
516
527
                                 *
517
528
                                 * @since 3.2.0
 
529
                                 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
518
530
                                 *
519
531
                                 * @see WP_Query::query()
520
532
                                 *
521
 
                                 * @param array  $posts     The posts for the current post type.
522
 
                                 * @param array  $args      An array of WP_Query arguments.
523
 
                                 * @param object $post_type The current post type object for this menu item meta box.
 
533
                                 * @param array        $posts     The posts for the current post type.
 
534
                                 * @param array        $args      An array of WP_Query arguments.
 
535
                                 * @param WP_Post_Type $post_type The current post type object for this menu item meta box.
524
536
                                 */
525
537
                                $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
 
538
 
526
539
                                $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
527
540
 
528
541
                                if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
564
577
}
565
578
 
566
579
/**
567
 
 * Displays a metabox for a taxonomy menu item.
 
580
 * Displays a meta box for a taxonomy menu item.
568
581
 *
569
582
 * @since 3.0.0
570
583
 *
571
584
 * @global int|string $nav_menu_selected_id
572
585
 *
573
586
 * @param string $object Not used.
574
 
 * @param string $taxonomy The taxonomy object.
 
587
 * @param array  $box {
 
588
 *     Taxonomy menu item meta box arguments.
 
589
 *
 
590
 *     @type string $id       Meta box 'id' attribute.
 
591
 *     @type string $title    Meta box title.
 
592
 *     @type string $callback Meta box display callback.
 
593
 *     @type object $args     Extra meta box arguments (the taxonomy object for this meta box).
 
594
 * }
575
595
 */
576
 
function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
 
596
function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
577
597
        global $nav_menu_selected_id;
578
 
        $taxonomy_name = $taxonomy['args']->name;
 
598
        $taxonomy_name = $box['args']->name;
579
599
 
580
600
        // Paginate browsing for large numbers of objects.
581
601
        $per_page = 50;
888
908
                        return $result . ' <ul class="menu" id="menu-to-edit"> </ul>';
889
909
 
890
910
                /**
891
 
                 * Filter the Walker class used when adding nav menu items.
 
911
                 * Filters the Walker class used when adding nav menu items.
892
912
                 *
893
913
                 * @since 3.0.0
894
914
                 *
916
936
                                $some_invalid_menu_items = true;
917
937
                }
918
938
 
919
 
                if ( $some_pending_menu_items )
920
 
                        $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>';
 
939
                if ( $some_pending_menu_items ) {
 
940
                        $result .= '<div class="notice notice-info notice-alt inline"><p>' . __( 'Click Save Menu to make pending menu items public.' ) . '</p></div>';
 
941
                }
921
942
 
922
 
                if ( $some_invalid_menu_items )
923
 
                        $result .= '<div class="error inline"><p>' . __('There are some invalid menu items. Please check or delete them.') . '</p></div>';
 
943
                if ( $some_invalid_menu_items ) {
 
944
                        $result .= '<div class="notice notice-error notice-alt inline"><p>' . __( 'There are some invalid menu items. Please check or delete them.' ) . '</p></div>';
 
945
                }
924
946
 
925
947
                $result .= '<ul class="menu" id="menu-to-edit"> ';
926
948
                $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
1057
1079
 
1058
1080
        return $messages;
1059
1081
}
 
1082
 
 
1083
/**
 
1084
 * If a JSON blob of navigation menu data is in POST data, expand it and inject
 
1085
 * it into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134.
 
1086
 *
 
1087
 * @ignore
 
1088
 * @since 4.5.3
 
1089
 * @access private
 
1090
 */
 
1091
function _wp_expand_nav_menu_post_data() {
 
1092
        if ( ! isset( $_POST['nav-menu-data'] ) ) {
 
1093
                return;
 
1094
        }
 
1095
 
 
1096
        $data = json_decode( stripslashes( $_POST['nav-menu-data'] ) );
 
1097
 
 
1098
        if ( ! is_null( $data ) && $data ) {
 
1099
                foreach ( $data as $post_input_data ) {
 
1100
                        // For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
 
1101
                        // derive the array path keys via regex and set the value in $_POST.
 
1102
                        preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
 
1103
 
 
1104
                        $array_bits = array( $matches[1] );
 
1105
 
 
1106
                        if ( isset( $matches[3] ) ) {
 
1107
                                $array_bits = array_merge( $array_bits, explode( '][', $matches[3] ) );
 
1108
                        }
 
1109
 
 
1110
                        $new_post_data = array();
 
1111
 
 
1112
                        // Build the new array value from leaf to trunk.
 
1113
                        for ( $i = count( $array_bits ) - 1; $i >= 0; $i -- ) {
 
1114
                                if ( $i == count( $array_bits ) - 1 ) {
 
1115
                                        $new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
 
1116
                                } else {
 
1117
                                        $new_post_data = array( $array_bits[ $i ] => $new_post_data );
 
1118
                                }
 
1119
                        }
 
1120
 
 
1121
                        $_POST = array_replace_recursive( $_POST, $new_post_data );
 
1122
                }
 
1123
        }
 
1124
}