~canonical-sysadmins/wordpress/5.1

« back to all changes in this revision

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

  • Committer: Nick Moffitt
  • Date: 2016-04-14 10:43:32 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: nick.moffitt@canonical.com-20160414104332-61kvsia27qpmjquk
new upstream release 4.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
}
78
78
 
79
79
/**
80
 
 * Register navigation menus for a theme.
 
80
 * Registers navigation menu locations for a theme.
81
81
 *
82
82
 * @since 3.0.0
83
83
 *
94
94
}
95
95
 
96
96
/**
97
 
 * Unregisters a navigation menu for a theme.
 
97
 * Unregisters a navigation menu location for a theme.
98
98
 *
99
99
 * @global array $_wp_registered_nav_menus
100
100
 *
115
115
}
116
116
 
117
117
/**
118
 
 * Register a navigation menu for a theme.
 
118
 * Registers a navigation menu location for a theme.
119
119
 *
120
120
 * @since 3.0.0
121
121
 *
126
126
        register_nav_menus( array( $location => $description ) );
127
127
}
128
128
/**
129
 
 * Returns an array of all registered navigation menus in a theme
 
129
 * Returns all registered navigation menu locations in a theme.
130
130
 *
131
131
 * @since 3.0.0
132
132
 *
154
154
}
155
155
 
156
156
/**
157
 
 * Whether a registered nav menu location has a menu assigned to it.
 
157
 * Determines whether a registered nav menu location has a menu assigned to it.
158
158
 *
159
159
 * @since 3.0.0
160
160
 *
182
182
}
183
183
 
184
184
/**
185
 
 * Determine whether the given ID is a nav menu item.
 
185
 * Determines whether the given ID is a nav menu item.
186
186
 *
187
187
 * @since 3.0.0
188
188
 *
194
194
}
195
195
 
196
196
/**
197
 
 * Create a Navigation Menu.
 
197
 * Creates a navigation menu.
 
198
 *
 
199
 * Note that `$menu_name` is expected to be pre-slashed.
198
200
 *
199
201
 * @since 3.0.0
200
202
 *
202
204
 * @return int|WP_Error Menu ID on success, WP_Error object on failure.
203
205
 */
204
206
function wp_create_nav_menu( $menu_name ) {
 
207
        // expected_slashed ($menu_name)
205
208
        return wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) );
206
209
}
207
210
 
252
255
/**
253
256
 * Save the properties of a menu or create a new menu with those properties.
254
257
 *
 
258
 * Note that `$menu_data` is expected to be pre-slashed.
 
259
 *
255
260
 * @since 3.0.0
256
261
 *
257
262
 * @param int   $menu_id   The ID of the menu or "0" to create a new menu.
259
264
 * @return int|WP_Error Menu ID on success, WP_Error object on failure.
260
265
 */
261
266
function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
 
267
        // expected_slashed ($menu_data)
262
268
        $menu_id = (int) $menu_id;
263
269
 
264
270
        $_menu = wp_get_nav_menu_object( $menu_id );
344
350
/**
345
351
 * Save the properties of a menu item or create a new one.
346
352
 *
 
353
 * The menu-item-title, menu-item-description, and menu-item-attr-title are expected
 
354
 * to be pre-slashed since they are passed directly into `wp_insert_post()`.
 
355
 *
347
356
 * @since 3.0.0
348
357
 *
349
358
 * @param int   $menu_id         The ID of the menu. Required. If "0", makes the menu item a draft orphan.
417
426
                        $original_title = $original_object->post_title;
418
427
                } elseif ( 'post_type_archive' == $args['menu-item-type'] ) {
419
428
                        $original_object = get_post_type_object( $args['menu-item-object'] );
420
 
                        $original_title = $original_object->labels->archives;
 
429
                        if ( $original_object ) {
 
430
                                $original_title = $original_object->labels->archives;
 
431
                        }
421
432
                }
422
433
 
423
434
                if ( $args['menu-item-title'] == $original_title )
664
675
 
665
676
        $items = array_map( 'wp_setup_nav_menu_item', $items );
666
677
 
667
 
        if ( ! is_admin() ) { // Remove invalid items only in frontend
 
678
        if ( ! is_admin() ) { // Remove invalid items only in front end
668
679
                $items = array_filter( $items, '_is_valid_nav_menu_item' );
669
680
        }
670
681
 
737
748
                                $menu_item->url = get_permalink( $menu_item->object_id );
738
749
 
739
750
                                $original_object = get_post( $menu_item->object_id );
740
 
                                $original_title = $original_object->post_title;
 
751
                                /** This filter is documented in wp-includes/post-template.php */
 
752
                                $original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID );
741
753
 
742
754
                                if ( '' === $original_title ) {
743
755
                                        /* translators: %d: ID of a post */
750
762
                                $object =  get_post_type_object( $menu_item->object );
751
763
                                if ( $object ) {
752
764
                                        $menu_item->title = '' == $menu_item->post_title ? $object->labels->archives : $menu_item->post_title;
 
765
                                        $post_type_description = $object->description;
753
766
                                } else {
754
767
                                        $menu_item->_invalid = true;
 
768
                                        $post_type_description = '';
755
769
                                }
756
770
 
757
771
                                $menu_item->type_label = __( 'Post Type Archive' );
758
 
                                $menu_item->description = '';
 
772
                                $post_content = wp_trim_words( $menu_item->post_content, 200 );
 
773
                                $post_type_description = '' == $post_content ? $post_type_description : $post_content; 
759
774
                                $menu_item->url = get_post_type_archive_link( $menu_item->object );
760
775
                        } elseif ( 'taxonomy' == $menu_item->type ) {
761
776
                                $object = get_taxonomy( $menu_item->object );
928
943
}
929
944
 
930
945
/**
931
 
 * Callback for handling a menu item when its original object is deleted.
 
946
 * Serves as a callback for handling a menu item when its original object is deleted.
932
947
 *
933
948
 * @since 3.0.0
934
949
 * @access private
935
950
 *
936
 
 * @param int $object_id The ID of the original object being trashed.
937
 
 *
 
951
 * @param int    $object_id Optional. The ID of the original object being trashed. Default 0.
 
952
 * @param int    $tt_id     Term taxonomy ID. Unused.
 
953
 * @param string $taxonomy  Taxonomy slug.
938
954
 */
939
955
function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) {
940
956
        $object_id = (int) $object_id;