Making WordPress.org

Changeset 3608


Ignore:
Timestamp:
06/30/2016 09:41:04 PM (9 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Expose the explanations post type for administration.

  • Allow post type to appear in admin menu.
  • Assign menu icon.
  • Prevent "Explanations" from being listed in the admin bar "New" menu.
  • Remove "Add New" from admin submenu.
  • Remove "Add New" from head of "Explanations" admin pages.
  • Add count of pending explanations to admin menu.
  • Prevent access to the admin page for creating a new explanation.

Fixes #1781.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php

    r3607 r3608  
    4242        add_action( 'edit_form_top',           array( $this, 'expl_to_post_controls'  )        );
    4343        add_action( 'admin_bar_menu',          array( $this, 'toolbar_edit_link'      ), 100   );
     44        add_action( 'admin_menu',              array( $this, 'admin_menu'             )        );
     45        add_action( 'load-post-new.php',       array( $this, 'prevent_direct_creation')        );
    4446
    4547        // Permissions.
     
    7981            'hierarchical'      => false,
    8082            'show_ui'           => true,
    81             'show_in_menu'      => false,
     83            'show_in_menu'      => true,
     84            'menu_icon'         => 'dashicons-info',
     85            'show_in_admin_bar' => false,
    8286            'show_in_nav_menus' => false,
    8387            'capability_type'   => 'explanation',
     
    97101        foreach ( $this->post_types as $type ) {
    98102            remove_post_type_support( $type, 'editor' );
     103        }
     104    }
     105
     106    /**
     107     * Customizes admin menu.
     108     *
     109     * - Removes "Add new".
     110     * - Adds count of pending explanations.
     111     *
     112     * @access public
     113     */
     114    public function admin_menu() {
     115        global $menu;
     116
     117        $menu_slug = 'edit.php?post_type=' . $this->exp_post_type;
     118
     119        // Remove 'Add New' from submenu.
     120        remove_submenu_page( $menu_slug, 'post-new.php?post_type=' . $this->exp_post_type );
     121
     122        // Add pending posts count.
     123        $counts = wp_count_posts( $this->exp_post_type );
     124        $count = $counts->pending;
     125        if ( $count ) {
     126            // Find the explanations menu item.
     127            foreach ( $menu as $i => $item ) {
     128                if ( $menu_slug == $item[2] ) {
     129                    // Modify it to include the pending count.
     130                    $menu[ $i ][0] = sprintf(
     131                        __( 'Explanations %s', 'wporg' ),
     132                        "<span class='update-plugins count-{$count}'><span class='plugin-count'>" . number_format_i18n( $count ) . "</span></span>"
     133                    );
     134                    break;
     135                }
     136            }
     137        }
     138    }
     139
     140    /**
     141     * Prevents direct access to the admin page for creating a new explanation.
     142     *
     143     * Only prevents admin UI access to directly create a new explanation. It does
     144     * not attempt to prevent direct programmatic creation of a new explanation.
     145     *
     146     * @access public
     147     */
     148    public function prevent_direct_creation() {
     149        if ( $this->exp_post_type == $_GET['post_type'] ) {
     150            wp_safe_redirect( admin_url() );
     151            exit;
    99152        }
    100153    }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/admin.scss

    r1909 r3608  
    2626/* Explanations */
    2727
    28 .post-type-wporg_explanations .add-new-h2 {
     28.post-type-wporg_explanations .page-title-action {
    2929    display: none;
    3030}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/admin.css

    r1909 r3608  
    2323
    2424/* Explanations */
    25 .post-type-wporg_explanations .add-new-h2 {
     25.post-type-wporg_explanations .page-title-action {
    2626  display: none;
    2727}
Note: See TracChangeset for help on using the changeset viewer.