Make WordPress Core

Ticket #38323: 38323-improved-filter.diff

File 38323-improved-filter.diff, 1.9 KB (added by spacedmonkey, 5 years ago)
  • src/wp-includes/meta.php

     
    12981298}
    12991299
    13001300/**
     1301 * /**
    13011302 * Returns the object subtype for a given object ID of a specific type.
    13021303 *
    13031304 * @since 5.0.0
     
    13091310function get_object_subtype( $object_type, $object_id ) {
    13101311        $object_id      = (int) $object_id;
    13111312        $object_subtype = '';
    1312 
     1313        $object = null;
    13131314        switch ( $object_type ) {
    13141315                case 'post':
    1315                         $post_type = get_post_type( $object_id );
     1316                        $object = get_post( $object_id );
     1317                        if ( ! $object instanceof WP_Post ) {
     1318                                break;
     1319                        }
    13161320
    1317                         if ( ! empty( $post_type ) ) {
    1318                                 $object_subtype = $post_type;
    1319                         }
     1321                        $object_subtype = $object->post_type;
    13201322                        break;
    13211323
    13221324                case 'term':
    1323                         $term = get_term( $object_id );
    1324                         if ( ! $term instanceof WP_Term ) {
     1325                        $object = get_term( $object_id );
     1326                        if ( ! $object instanceof WP_Term ) {
    13251327                                break;
    13261328                        }
    13271329
    1328                         $object_subtype = $term->taxonomy;
     1330                        $object_subtype = $object->taxonomy;
    13291331                        break;
    13301332
    13311333                case 'comment':
    1332                         $comment = get_comment( $object_id );
    1333                         if ( ! $comment ) {
     1334                        $object = get_comment( $object_id );
     1335                        if ( ! $object ) {
    13341336                                break;
    13351337                        }
    13361338
     
    13381340                        break;
    13391341
    13401342                case 'user':
    1341                         $user = get_user_by( 'id', $object_id );
    1342                         if ( ! $user ) {
     1343                        $object = get_user_by( 'id', $object_id );
     1344                        if ( ! $object ) {
    13431345                                break;
    13441346                        }
    13451347
     
    13571359         *
    13581360         * @param string $object_subtype Empty string to override.
    13591361         * @param int    $object_id      ID of the object to get the subtype for.
     1362         * @param WP_Post|WP_Term|WP_Comment|WP_User|null $object The object to get the subtype for
    13601363         */
    1361         return apply_filters( "get_object_subtype_{$object_type}", $object_subtype, $object_id );
     1364        return apply_filters( "get_object_subtype_{$object_type}", $object_subtype, $object_id, $object );
    13621365}