Making WordPress.org

Changeset 1063


Ignore:
Timestamp:
12/23/2014 07:43:48 PM (10 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Add get_parsed_post_types() and is_parsed_post_type() and use them rather than explicitly defining the post types all over the place

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

Legend:

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

    r1057 r1063  
    351351function register_taxonomies() {
    352352    // Files
    353     register_taxonomy( 'wp-parser-source-file', array( 'wp-parser-class', 'wp-parser-function', 'wp-parser-hook', 'wp-parser-method' ), array(
     353    register_taxonomy( 'wp-parser-source-file', get_parsed_post_types(), array(
    354354        'label'                 => __( 'Files', 'wporg' ),
    355355        'labels'                => array(
     
    379379
    380380    // Package
    381     register_taxonomy( 'wp-parser-package', array( 'wp-parser-class', 'wp-parser-function', 'wp-parser-hook', 'wp-parser-method' ), array(
     381    register_taxonomy( 'wp-parser-package', get_parsed_post_types(), array(
    382382        'hierarchical'          => true,
    383383        'label'                 => '@package',
     
    389389
    390390    // @since
    391     register_taxonomy( 'wp-parser-since', array( 'wp-parser-class', 'wp-parser-function', 'wp-parser-hook', 'wp-parser-method' ), array(
     391    register_taxonomy( 'wp-parser-since', get_parsed_post_types(), array(
    392392        'hierarchical'          => true,
    393393        'label'                 => __( '@since', 'wporg' ),
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php

    r1057 r1063  
    3434     */
    3535    public function __construct() {
    36         $this->post_types = array( 'wp-parser-function', 'wp-parser-class', 'wp-parser-hook', 'wp-parser-method' );
     36        $this->post_types = DevHub\get_parsed_post_types();
    3737
    3838        // Setup.
     
    239239    public function admin_enqueue_scripts() {
    240240
    241         if ( in_array( get_current_screen()->id, array(
    242                 'wp-parser-function', 'wp-parser-class', 'wp-parser-hook', 'wp-parser-method',
    243                 'wporg_explanations', 'edit-wporg_explanations',
     241        if ( in_array( get_current_screen()->id, array_merge(
     242                DevHub\get_parsed_post_types(),
     243                array( 'wporg_explanations', 'edit-wporg_explanations' )
    244244        ) ) ) {
    245245            wp_enqueue_style( 'wporg-admin', get_template_directory_uri() . '/stylesheets/admin.css', array(), '20141218' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/parsed-content.php

    r1057 r1063  
    2828     */
    2929    public function __construct() {
    30         $this->post_types = array( 'wp-parser-function', 'wp-parser-class', 'wp-parser-hook', 'wp-parser-method' );
     30        $this->post_types = DevHub\get_parsed_post_types();
    3131
    3232        // Data.
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r1062 r1063  
    412412
    413413        return $version[0];
     414    }
     415
     416    /**
     417     * Get an array of all parsed post types.
     418     *
     419     * @return array
     420     */
     421    function get_parsed_post_types() {
     422        return array(
     423            'wp-parser-class',
     424            'wp-parser-function',
     425            'wp-parser-hook',
     426            'wp-parser-method',
     427        );
     428    }
     429
     430    /**
     431     * Checks if given post type is one of the parsed post types.
     432     *
     433     * @param  null|string Optional. The post type. Default null.
     434     * @return bool True if post has a parsed post type
     435     */
     436    function is_parsed_post_type( $post_type = null ) {
     437        $post_type = $post_type ? $post_type : get_post_type();
     438
     439        return in_array( $post_type, get_parsed_post_types() );
    414440    }
    415441
     
    871897     * Does the post type support having user notes?
    872898     *
    873      * @param  string  Optional. The post type name. If blank, assumes current post type.
    874      *
    875      * @return boolean
     899     * Currently all parsed post types support user notes.
     900     *
     901     * @param  null|string $post_type Optional. The post type name. If null, assumes current post type. Default null.
     902     *
     903     * @return bool
    876904     */
    877905    function post_type_supports_user_notes( $post_type = null ) {
    878         $post_type = $post_type ? $post_type : get_post_type();
    879 
    880         return ( 0 === strpos( $post_type, 'wp-parser-' ) );
     906        return is_parsed_post_type( $post_type );
    881907    }
    882908
     
    967993     * Indicates if the current user can post a user contibuted note.
    968994     *
    969      * This only affects post types wp-parser-* as they are the only things
     995     * This only affects parsed post types as they are the only things
    970996     * that can have user contributed notes.
    971997     *
     
    11021128     */
    11031129    function should_show_search_bar() {
    1104         $post_types = array( 'wp-parser-class', 'wp-parser-function', 'wp-parser-method', 'wp-parser-hook' );
     1130        $post_types = get_parsed_post_types();
    11051131        $taxonomies = array( 'wp-parser-since', 'wp-parser-package', 'wp-parser-source-file' );
    11061132
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/page-reference-landing.php

    r835 r1063  
    1111
    1212    <div id="primary" class="content-area">
     13
     14        <div id="content-area">
     15            <?php breadcrumb_trail(); ?>
     16        </div>
     17
    1318        <main id="main" class="site-main" role="main">
    14 
    1519            <div class="reference-landing">
    1620                <div class="search-guide section clear">
     
    3943                                $list = new WP_Query( array(
    4044                                    'posts_per_page' => 13,
    41                                     'post_type'      => array( 'wp-parser-function', 'wp-parser-hook', 'wp-parser-class', 'wp-parser-method' ),
     45                                    'post_type'      => DevHub\get_parsed_post_types(),
    4246                                    'orderby'        => 'title',
    4347                                    'order'          => 'ASC',
Note: See TracChangeset for help on using the changeset viewer.