Making WordPress.org

Changeset 3810


Ignore:
Timestamp:
08/15/2016 06:46:02 PM (8 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Make get_uses() and get_used_by() consistently and properly honor $post argument.

File:
1 edited

Legend:

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

    r3809 r3810  
    10071007
    10081008    /**
    1009      * Retrieve a WP_Query object for the posts that the current post uses
    1010      *
    1011      * @return WP_Query A WP_Query object for the posts the current post uses
    1012      */
    1013     function get_uses() {
    1014         $post_type = get_post_type();
     1009     * Retrieves a WP_Query object for the posts that the current post uses.
     1010     *
     1011     * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post.
     1012     * @return WP_Query|null   The WP_Query if the post's post type supports 'uses', null otherwise.
     1013     */
     1014    function get_uses( $post = null ) {
     1015        $post_id   = get_post_field( 'ID', $post );
     1016        $post_type = get_post_type( $post );
    10151017
    10161018        if ( 'wp-parser-class' === $post_type ) {
    1017             $extends = get_post_meta( get_the_ID(), '_wp-parser_extends', true );
     1019            $extends = get_post_meta( $post_id, '_wp-parser_extends', true );
    10181020            if ( ! $extends ) {
    10191021                return;
     
    10341036            'connected_type'      => $connection_types,
    10351037            'connected_direction' => array( 'from', 'from', 'from' ),
    1036             'connected_items'     => get_the_ID(),
     1038            'connected_items'     => $post_id,
    10371039            'nopaging'            => true,
    10381040        ) );
     
    10411043    }
    10421044
    1043     function get_used_by( $post_id = null ) {
    1044 
    1045         if ( empty( $post_id ) ) {
    1046             $post_id = get_the_ID();
    1047         }
    1048 
    1049         switch ( get_post_type() ) {
     1045    /**
     1046     * Retrieves a WP_Query object for the posts that use the specified post.
     1047     *
     1048     * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post.
     1049     * @return WP_Query|null   The WP_Query if the post's post type supports 'used by', null otherwise.
     1050     */
     1051    function get_used_by( $post = null ) {
     1052
     1053        switch ( get_post_type( $post ) ) {
    10501054
    10511055            case 'wp-parser-function':
     
    10651069                    'post_type'  => array( 'wp-parser-class' ),
    10661070                    'meta_key'   => '_wp-parser_extends',
    1067                     'meta_value' => get_post_field( 'post_name', get_post( $post_id ) ),
     1071                    'meta_value' => get_post_field( 'post_name', $post ),
    10681072                ) );
    1069                 return $connected; 
     1073                return $connected;
    10701074                break;
    10711075
     
    10791083            'connected_type'      => $connection_types,
    10801084            'connected_direction' => array( 'to', 'to' ),
    1081             'connected_items'     => $post_id,
     1085            'connected_items'     => get_post_field( 'ID', $post ),
    10821086            'nopaging'            => true,
    10831087        ) );
Note: See TracChangeset for help on using the changeset viewer.