~ubuntu-branches/debian/sid/wordpress/sid

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2014-09-05 20:58:06 UTC
  • mfrom: (1.2.38)
  • Revision ID: package-import@ubuntu.com-20140905205806-e4h6dkg4190n0svf
Tags: 4.0+dfsg-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
         * @param int    $depth  Depth of menu item. Used for padding.
20
20
         * @param array  $args   Not used.
21
21
         */
22
 
        function start_lvl( &$output, $depth = 0, $args = array() ) {}
 
22
        public function start_lvl( &$output, $depth = 0, $args = array() ) {}
23
23
 
24
24
        /**
25
25
         * Ends the list of after the elements are added.
32
32
         * @param int    $depth  Depth of menu item. Used for padding.
33
33
         * @param array  $args   Not used.
34
34
         */
35
 
        function end_lvl( &$output, $depth = 0, $args = array() ) {}
 
35
        public function end_lvl( &$output, $depth = 0, $args = array() ) {}
36
36
 
37
37
        /**
38
38
         * Start the element output.
46
46
         * @param array  $args   Not used.
47
47
         * @param int    $id     Not used.
48
48
         */
49
 
        function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
 
49
        public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
50
50
                global $_wp_nav_menu_max_depth;
51
51
                $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
52
52
 
235
235
 * @uses Walker_Nav_Menu
236
236
 */
237
237
class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
238
 
        function __construct( $fields = false ) {
 
238
        public function __construct( $fields = false ) {
239
239
                if ( $fields ) {
240
240
                        $this->db_fields = $fields;
241
241
                }
252
252
         * @param int    $depth  Depth of page. Used for padding.
253
253
         * @param array  $args   Not used.
254
254
         */
255
 
        function start_lvl( &$output, $depth = 0, $args = array() ) {
 
255
        public function start_lvl( &$output, $depth = 0, $args = array() ) {
256
256
                $indent = str_repeat( "\t", $depth );
257
257
                $output .= "\n$indent<ul class='children'>\n";
258
258
        }
268
268
         * @param int    $depth  Depth of page. Used for padding.
269
269
         * @param array  $args   Not used.
270
270
         */
271
 
        function end_lvl( &$output, $depth = 0, $args = array() ) {
 
271
        public function end_lvl( &$output, $depth = 0, $args = array() ) {
272
272
                $indent = str_repeat( "\t", $depth );
273
273
                $output .= "\n$indent</ul>";
274
274
        }
286
286
         * @param array  $args   Not used.
287
287
         * @param int    $id     Not used.
288
288
         */
289
 
        function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
 
289
        public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
290
290
                global $_nav_menu_placeholder;
291
291
 
292
292
                $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
356
356
                                if ( 'markup' == $response_format ) {
357
357
                                        echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args );
358
358
                                } elseif ( 'json' == $response_format ) {
359
 
                                        $post_obj = get_post( $object_id );
360
359
                                        echo json_encode(
361
360
                                                array(
362
361
                                                        'ID' => $object_id,
503
502
 
504
503
        foreach ( $post_types as $post_type ) {
505
504
                /**
506
 
                 * Filter whether a menu items meta box will be added for the current post type.
 
505
                 * Filter whether a menu items meta box will be added for the current
 
506
                 * object type.
507
507
                 *
508
 
                 * If a falsey value is returned instead of a post type object,
509
 
                 * the post type menu items meta box will not be added.
 
508
                 * If a falsey value is returned instead of an object, the menu items
 
509
                 * meta box for the current meta box object will not be added.
510
510
                 *
511
511
                 * @since 3.0.0
512
512
                 *
513
 
                 * @param object $post_type The post type object to be used as a meta box.
 
513
                 * @param object $meta_box_object The current object to add a menu items
 
514
                 *                                meta box for.
514
515
                 */
515
516
                $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
516
517
                if ( $post_type ) {
517
518
                        $id = $post_type->name;
518
 
                        // give pages a higher priority
 
519
                        // Give pages a higher priority.
519
520
                        $priority = ( 'page' == $post_type->name ? 'core' : 'default' );
520
521
                        add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type );
521
522
                }
534
535
                return;
535
536
 
536
537
        foreach ( $taxonomies as $tax ) {
537
 
                /**
538
 
                 * Filter whether a menu items meta box will be added for the current taxonomy.
539
 
                 *
540
 
                 * If a falsey value is returned instead of a taxonomy object,
541
 
                 * the taxonomy menu items meta box will not be added.
542
 
                 *
543
 
                 * @since 3.0.0
544
 
                 *
545
 
                 * @param object $tax The taxonomy object to be used as a meta box.
546
 
                 */
 
538
                /** This filter is documented in wp-admin/includes/nav-menu.php */
547
539
                $tax = apply_filters( 'nav_menu_meta_box_object', $tax );
548
540
                if ( $tax ) {
549
541
                        $id = $tax->name;
623
615
 
624
616
        $post_type_name = $post_type['args']->name;
625
617
 
626
 
        // paginate browsing for large numbers of post objects
 
618
        // Paginate browsing for large numbers of post objects.
627
619
        $per_page = 50;
628
620
        $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
629
621
        $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
650
642
                return;
651
643
        }
652
644
 
653
 
        $post_type_object = get_post_type_object($post_type_name);
654
 
 
655
645
        $num_pages = $get_posts->max_num_pages;
656
646
 
657
647
        $page_links = paginate_links( array(
670
660
                'current' => $pagenum
671
661
        ));
672
662
 
673
 
        if ( !$posts )
674
 
                $error = '<li id="error">'. $post_type['args']->labels->not_found .'</li>';
675
 
 
676
663
        $db_fields = false;
677
664
        if ( is_post_type_hierarchical( $post_type_name ) ) {
678
665
                $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
775
762
                                <?php
776
763
                                $args['walker'] = $walker;
777
764
 
778
 
                                // if we're dealing with pages, let's put a checkbox for the front page at the top of the list
 
765
                                /*
 
766
                                 * If we're dealing with pages, let's put a checkbox for the front
 
767
                                 * page at the top of the list.
 
768
                                 */
779
769
                                if ( 'page' == $post_type_name ) {
780
770
                                        $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0;
781
771
                                        if ( ! empty( $front_page ) ) {
867
857
        global $nav_menu_selected_id;
868
858
        $taxonomy_name = $taxonomy['args']->name;
869
859
 
870
 
        // paginate browsing for large numbers of objects
 
860
        // Paginate browsing for large numbers of objects.
871
861
        $per_page = 50;
872
862
        $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
873
863
        $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
1058
1048
 
1059
1049
        if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) {
1060
1050
 
1061
 
                // Loop through all the menu items' POST values
 
1051
                // Loop through all the menu items' POST values.
1062
1052
                foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
1063
1053
                        if (
1064
 
                                empty( $_item_object_data['menu-item-object-id'] ) && // checkbox is not checked
 
1054
                                // Checkbox is not checked.
 
1055
                                empty( $_item_object_data['menu-item-object-id'] ) &&
1065
1056
                                (
1066
 
                                        ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set
1067
 
                                        in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default
 
1057
                                        // And item type either isn't set.
 
1058
                                        ! isset( $_item_object_data['menu-item-type'] ) ||
 
1059
                                        // Or URL is the default.
 
1060
                                        in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) ||
1068
1061
                                        ! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || // or it's not a custom menu item (but not the custom home page)
1069
 
                                        ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists
 
1062
                                        // Or it *is* a custom menu item that already exists.
 
1063
                                        ! empty( $_item_object_data['menu-item-db-id'] )
1070
1064
                                )
1071
1065
                        ) {
1072
 
                                continue; // then this potential menu item is not getting added to this menu
 
1066
                                // Then this potential menu item is not getting added to this menu.
 
1067
                                continue;
1073
1068
                        }
1074
1069
 
1075
 
                        // if this possible menu item doesn't actually have a menu database ID yet
 
1070
                        // If this possible menu item doesn't actually have a menu database ID yet.
1076
1071
                        if (
1077
1072
                                empty( $_item_object_data['menu-item-db-id'] ) ||
1078
1073
                                ( 0 > $_possible_db_id ) ||
1125
1120
                                'post_status' => 'publish',
1126
1121
                        );
1127
1122
 
1128
 
                // posts should show only published items
 
1123
                // Posts should show only published items.
1129
1124
                } elseif ( 'post' == $object->name ) {
1130
1125
                        $object->_default_query = array(
1131
1126
                                'post_status' => 'publish',
1132
1127
                        );
1133
1128
 
1134
 
                // cats should be in reverse chronological order
 
1129
                // Categories should be in reverse chronological order.
1135
1130
                } elseif ( 'category' == $object->name ) {
1136
1131
                        $object->_default_query = array(
1137
1132
                                'orderby' => 'id',
1138
1133
                                'order' => 'DESC',
1139
1134
                        );
1140
1135
 
1141
 
                // custom post types should show only published items
 
1136
                // Custom post types should show only published items.
1142
1137
                } else {
1143
1138
                        $object->_default_query = array(
1144
1139
                                'post_status' => 'publish',
1172
1167
                        return $result . ' <ul class="menu" id="menu-to-edit"> </ul>';
1173
1168
 
1174
1169
                /**
1175
 
                 * Filter the Walker class used to render a menu formatted for editing.
 
1170
                 * Filter the Walker class used when adding nav menu items.
1176
1171
                 *
1177
1172
                 * @since 3.0.0
1178
1173
                 *
1179
 
                 * @param string $walker_class_name The Walker class used to render a menu formatted for editing.
1180
 
                 * @param int    $menu_id           The ID of the menu being rendered.
 
1174
                 * @param string $class   The walker class to use. Default 'Walker_Nav_Menu_Edit'.
 
1175
                 * @param int    $menu_id ID of the menu being rendered.
1181
1176
                 */
1182
1177
                $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );
1183
1178
 
1239
1234
        global $wpdb;
1240
1235
        $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
1241
1236
 
1242
 
        // delete orphaned draft menu items
 
1237
        // Delete orphaned draft menu items.
1243
1238
        $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) );
1244
1239
 
1245
1240
        foreach( (array) $menu_items_to_delete as $menu_item_id )