Making WordPress.org

Changeset 3809


Ignore:
Timestamp:
08/15/2016 05:43:19 PM (8 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: For wp-parser-class, list parent class under 'Uses' and list extending classes under 'Used By'.

  • Change post_type_has_uses_info() and post_type_has_usage_info() to return true for 'wp-parser-class' post type.
  • In template-related.php, check that $uses has a value before using it.
  • In get_uses() and get_used_by()`, find classes related via the custom field '_wp-parser_extends', which notes the class being extended.

Fixes #1855.

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

Legend:

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

    r3796 r3809  
    987987    function post_type_has_usage_info( $post_type = null ) {
    988988        $post_type             = $post_type ? $post_type : get_post_type();
    989         $post_types_with_usage = array( 'wp-parser-function', 'wp-parser-method', 'wp-parser-hook' );
     989        $post_types_with_usage = array( 'wp-parser-function', 'wp-parser-method', 'wp-parser-hook', 'wp-parser-class' );
    990990
    991991        return in_array( $post_type, $post_types_with_usage );
     
    10011001    function post_type_has_uses_info( $post_type = null ) {
    10021002        $post_type             = $post_type ? $post_type : get_post_type();
    1003         $post_types_with_uses  = array( 'wp-parser-function', 'wp-parser-method' );
     1003        $post_types_with_uses  = array( 'wp-parser-function', 'wp-parser-method', 'wp-parser-class' );
    10041004
    10051005        return in_array( $post_type, $post_types_with_uses );
     
    10121012     */
    10131013    function get_uses() {
    1014 
    1015         if ( 'wp-parser-function' === get_post_type() ) {
     1014        $post_type = get_post_type();
     1015
     1016        if ( 'wp-parser-class' === $post_type ) {
     1017            $extends = get_post_meta( get_the_ID(), '_wp-parser_extends', true );
     1018            if ( ! $extends ) {
     1019                return;
     1020            }
     1021            $connected = new \WP_Query( array(
     1022                'post_type' => array( 'wp-parser-class' ),
     1023                'name'      => $extends,
     1024            ) );
     1025            return $connected;
     1026        } elseif ( 'wp-parser-function' === $post_type ) {
    10161027            $connection_types = array( 'functions_to_functions', 'functions_to_methods', 'functions_to_hooks' );
    10171028        } else {
     
    10481059            case 'wp-parser-hook':
    10491060                $connection_types = array( 'functions_to_hooks', 'methods_to_hooks' );
     1061                break;
     1062
     1063            case 'wp-parser-class':
     1064                $connected = new \WP_Query( array(
     1065                    'post_type'  => array( 'wp-parser-class' ),
     1066                    'meta_key'   => '_wp-parser_extends',
     1067                    'meta_value' => get_post_field( 'post_name', get_post( $post_id ) ),
     1068                ) );
     1069                return $connected; 
    10501070                break;
    10511071
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/reference/template-related.php

    r3660 r3809  
    2222                    $uses = get_uses();
    2323                    $uses_to_show = 5;
    24                     while ( $uses->have_posts() ) : $uses->the_post()
     24                    if ( $uses ) : while ( $uses->have_posts() ) : $uses->the_post()
    2525                        ?>
    2626                        <li>
     
    3737                            ?></a>
    3838                        <a href="#" class="hide-more"><?php _e( 'Hide more uses', 'wporg' ); ?></a>
    39                     <?php endif; ?>
     39                    <?php endif; endif; ?>
    4040                </ul>
    4141            </article>
Note: See TracChangeset for help on using the changeset viewer.