~canonical-sysadmins/wordpress/4.5.2

« back to all changes in this revision

Viewing changes to wp-admin/menu.php

  • Committer: Manuel Seelaus
  • Date: 2015-12-09 17:47:18 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: manuel.seelaus@canonical.com-20151209174718-coxethm2swbeqksy
Merge WP4.4 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
$menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
46
46
 
47
 
$menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-post', 'menu-posts', 'dashicons-admin-post' );
48
 
        $submenu['edit.php'][5]  = array( __('All Posts'), 'edit_posts', 'edit.php' );
49
 
        /* translators: add new post */
50
 
        $submenu['edit.php'][10]  = array( _x('Add New', 'post'), get_post_type_object( 'post' )->cap->create_posts, 'post-new.php' );
51
 
 
52
 
        $i = 15;
53
 
        foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
54
 
                if ( ! $tax->show_ui || ! $tax->show_in_menu || ! in_array('post', (array) $tax->object_type, true) )
55
 
                        continue;
56
 
 
57
 
                $submenu['edit.php'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name );
58
 
        }
59
 
        unset($tax);
 
47
// $menu[5] = Posts
60
48
 
61
49
$menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' );
62
50
        $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');
63
51
        /* translators: add new file */
64
52
        $submenu['upload.php'][10] = array( _x('Add New', 'file'), 'upload_files', 'media-new.php');
 
53
        $i = 15;
65
54
        foreach ( get_taxonomies_for_attachments( 'objects' ) as $tax ) {
66
55
                if ( ! $tax->show_ui || ! $tax->show_in_menu )
67
56
                        continue;
68
57
 
69
58
                $submenu['upload.php'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&post_type=attachment' );
70
59
        }
71
 
        unset($tax);
 
60
        unset( $tax, $i );
72
61
 
73
62
$menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'dashicons-admin-links' );
74
63
        $submenu['link-manager.php'][5] = array( _x('All Links', 'admin menu'), 'manage_links', 'link-manager.php' );
76
65
        $submenu['link-manager.php'][10] = array( _x('Add New', 'link'), 'manage_links', 'link-add.php' );
77
66
        $submenu['link-manager.php'][15] = array( __('Link Categories'), 'manage_categories', 'edit-tags.php?taxonomy=link_category' );
78
67
 
79
 
$menu[20] = array( __('Pages'), 'edit_pages', 'edit.php?post_type=page', '', 'menu-top menu-icon-page', 'menu-pages', 'dashicons-admin-page' );
80
 
        $submenu['edit.php?post_type=page'][5] = array( __('All Pages'), 'edit_pages', 'edit.php?post_type=page' );
81
 
        /* translators: add new page */
82
 
        $submenu['edit.php?post_type=page'][10] = array( _x('Add New', 'page'), get_post_type_object( 'page' )->cap->create_posts, 'post-new.php?post_type=page' );
83
 
        $i = 15;
84
 
        foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
85
 
                if ( ! $tax->show_ui || ! $tax->show_in_menu  || ! in_array('page', (array) $tax->object_type, true) )
86
 
                        continue;
87
 
 
88
 
                $submenu['edit.php?post_type=page'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&post_type=page' );
89
 
        }
90
 
        unset($tax);
91
 
 
92
 
$awaiting_mod = wp_count_comments();
93
 
$awaiting_mod = $awaiting_mod->moderated;
94
 
$menu[25] = array( sprintf( __('Comments %s'), "<span class='awaiting-mod count-$awaiting_mod'><span class='pending-count'>" . number_format_i18n($awaiting_mod) . "</span></span>" ), 'edit_posts', 'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments', 'dashicons-admin-comments' );
95
 
unset($awaiting_mod);
 
68
// $menu[20] = Pages
 
69
 
 
70
// Avoid the comment count query for users who cannot edit_posts.
 
71
if ( current_user_can( 'edit_posts' ) ) {
 
72
        $awaiting_mod = wp_count_comments();
 
73
        $awaiting_mod = $awaiting_mod->moderated;
 
74
        $menu[25] = array(
 
75
                sprintf( __( 'Comments %s' ), '<span class="awaiting-mod count-' . absint( $awaiting_mod ) . '"><span class="pending-count">' . number_format_i18n( $awaiting_mod ) . '</span></span>' ),
 
76
                'edit_posts',
 
77
                'edit-comments.php',
 
78
                '',
 
79
                'menu-top menu-icon-comments',
 
80
                'menu-comments',
 
81
                'dashicons-admin-comments',
 
82
        );
 
83
        unset( $awaiting_mod );
 
84
}
96
85
 
97
86
$submenu[ 'edit-comments.php' ][0] = array( __('All Comments'), 'edit_posts', 'edit-comments.php' );
98
87
 
99
88
$_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group
100
89
 
101
 
foreach ( (array) get_post_types( array('show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ) as $ptype ) {
 
90
$types = (array) get_post_types( array('show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) );
 
91
$builtin = array( 'post', 'page' );
 
92
foreach ( array_merge( $builtin, $types ) as $ptype ) {
102
93
        $ptype_obj = get_post_type_object( $ptype );
103
94
        // Check if it should be a submenu.
104
95
        if ( $ptype_obj->show_in_menu !== true )
106
97
        $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first.
107
98
        $ptype_for_id = sanitize_html_class( $ptype );
108
99
 
 
100
        $menu_icon = 'dashicons-admin-post';
109
101
        if ( is_string( $ptype_obj->menu_icon ) ) {
110
102
                // Special handling for data:image/svg+xml and Dashicons.
111
103
                if ( 0 === strpos( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || 0 === strpos( $ptype_obj->menu_icon, 'dashicons-' ) ) {
113
105
                } else {
114
106
                        $menu_icon = esc_url( $ptype_obj->menu_icon );
115
107
                }
116
 
                $ptype_class = $ptype_for_id;
117
 
        } else {
118
 
                $menu_icon   = 'dashicons-admin-post';
119
 
                $ptype_class = 'post';
120
 
        }
121
 
 
 
108
        } elseif ( in_array( $ptype, $builtin ) ) {
 
109
                $menu_icon = 'dashicons-admin-' . $ptype;
 
110
        }
 
111
 
 
112
        $menu_class = 'menu-top menu-icon-' . $ptype_for_id;
 
113
        // 'post' special case
 
114
        if ( 'post' === $ptype ) {
 
115
                $menu_class .= ' open-if-no-js';
 
116
                $ptype_file = "edit.php";
 
117
                $post_new_file = "post-new.php";
 
118
                $edit_tags_file = "edit-tags.php?taxonomy=%s";
 
119
        } else {
 
120
                $ptype_file = "edit.php?post_type=$ptype";
 
121
                $post_new_file = "post-new.php?post_type=$ptype";
 
122
                $edit_tags_file = "edit-tags.php?taxonomy=%s&amp;post_type=$ptype";
 
123
        }
 
124
 
 
125
        if ( in_array( $ptype, $builtin ) ) {
 
126
                $ptype_menu_id = 'menu-' . $ptype_for_id . 's';
 
127
        } else {
 
128
                $ptype_menu_id = 'menu-posts-' . $ptype_for_id;
 
129
        }
122
130
        /*
123
131
         * If $ptype_menu_position is already populated or will be populated
124
132
         * by a hard-coded value below, increment the position.
127
135
        while ( isset($menu[$ptype_menu_position]) || in_array($ptype_menu_position, $core_menu_positions) )
128
136
                $ptype_menu_position++;
129
137
 
130
 
        $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-' . $ptype_class, 'menu-posts-' . $ptype_for_id, $menu_icon );
131
 
        $submenu["edit.php?post_type=$ptype"][5]  = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts,  "edit.php?post_type=$ptype");
132
 
        $submenu["edit.php?post_type=$ptype"][10]  = array( $ptype_obj->labels->add_new, $ptype_obj->cap->create_posts, "post-new.php?post_type=$ptype" );
 
138
        $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, $ptype_file, '', $menu_class, $ptype_menu_id, $menu_icon );
 
139
        $submenu[ $ptype_file ][5]  = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts,  $ptype_file );
 
140
        $submenu[ $ptype_file ][10]  = array( $ptype_obj->labels->add_new, $ptype_obj->cap->create_posts, $post_new_file );
133
141
 
134
142
        $i = 15;
135
143
        foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
136
144
                if ( ! $tax->show_ui || ! $tax->show_in_menu || ! in_array($ptype, (array) $tax->object_type, true) )
137
145
                        continue;
138
146
 
139
 
                $submenu["edit.php?post_type=$ptype"][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" );
 
147
                $submenu[ $ptype_file ][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, sprintf( $edit_tags_file, $tax->name ) );
140
148
        }
141
149
}
142
 
unset($ptype, $ptype_obj, $ptype_class, $ptype_for_id, $ptype_menu_position, $menu_icon, $i, $tax);
 
150
unset( $ptype, $ptype_obj, $ptype_for_id, $ptype_menu_position, $menu_icon, $i, $tax, $post_new_file );
143
151
 
144
152
$menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' );
145
153