Make WordPress Core

Ticket #15406: 15406.2.diff

File 15406.2.diff, 3.0 KB (added by nikolov.tmw, 9 years ago)

Same patch, but created from the root directory

  • src/wp-admin/menu.php

     
    4646
    4747$menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
    4848
    49 $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-post', 'menu-posts', 'dashicons-admin-post' );
     49$menu[5] = array( __('Posts') . pending_posts_bubble( 'post' ), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-post', 'menu-posts', 'dashicons-admin-post' );
    5050        $submenu['edit.php'][5]  = array( __('All Posts'), 'edit_posts', 'edit.php' );
    5151        /* translators: add new post */
    5252        $submenu['edit.php'][10]  = array( _x('Add New', 'post'), get_post_type_object( 'post' )->cap->create_posts, 'post-new.php' );
     
    129129        while ( isset($menu[$ptype_menu_position]) || in_array($ptype_menu_position, $core_menu_positions) )
    130130                $ptype_menu_position++;
    131131
    132         $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 );
     132        $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->menu_name ) . pending_posts_bubble( $ptype ), $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-' . $ptype_class, 'menu-posts-' . $ptype_for_id, $menu_icon );
    133133        $submenu["edit.php?post_type=$ptype"][5]  = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts,  "edit.php?post_type=$ptype");
    134134        $submenu["edit.php?post_type=$ptype"][10]  = array( $ptype_obj->labels->add_new, $ptype_obj->cap->create_posts, "post-new.php?post_type=$ptype" );
    135135
  • src/wp-admin/includes/post.php

     
    16591659                return wp_create_post_autosave( wp_slash( $post_data ) );
    16601660        }
    16611661}
     1662
     1663/**
     1664 * Generates a bubble with the number of "pending" posts from a given post type.
     1665 *
     1666 * @param string $post_type The post type slug for which we're displaying the bubble
     1667 *
     1668 * @return mixed NULL on non-existing post type, false if user can't publish posts,
     1669 *               empty string if there are no pending posts, HTML with count otherwise.
     1670 */
     1671function pending_posts_bubble( $post_type ) {
     1672        $post_type_object = get_post_type_object( $post_type );
     1673
     1674        if ( ! $post_type_object ) {
     1675                return null;
     1676        }
     1677
     1678        if ( ! current_user_can( $post_type_object->cap->publish_posts ) ) {
     1679                return false;
     1680        }
     1681
     1682        $counts = wp_count_posts( $post_type, 'readable' );
     1683
     1684        $bubble = '';
     1685
     1686        // Make sure there are pending posts
     1687        if ( isset( $counts->pending ) ) {
     1688                $bubble = " <span class='update-plugins count-{$counts->pending}'><span class='update-count'>" . number_format_i18n( $counts->pending ) . "</span></span>";
     1689        }
     1690
     1691        return $bubble;
     1692}