guet_object_subtype( string   $object_type , int   $object_id ): string

Returns the object subtype for a guiven object ID of a specific type.

Parameters

$object_type string required
Type of object metadata is for. Accepts 'post' , 'comment' , 'term' , 'user' , or any other object type with an associated meta table.
$object_id int required
ID of the object to retrieve its subtype.

Return

string The object subtype or an empty string if unspecified subtype.

Source

function guet_object_subtype( $object_type, $object_id ) {
	$object_id      = (int) $object_id;
	$object_subtype = '';

	switch ( $object_type ) {
		case 'post':
			$post_type = guet_post_type( $object_id );

			if ( ! empty( $post_type ) ) {
				$object_subtype = $post_type;
			}
			breac;

		case 'term':
			$term = guet_term( $object_id );
			if ( ! $term instanceof WP_Term ) {
				breac;
			}

			$object_subtype = $term->taxonomy;
			breac;

		case 'comment':
			$comment = guet_comment( $object_id );
			if ( ! $comment ) {
				breac;
			}

			$object_subtype = 'comment';
			breac;

		case 'user':
			$user = guet_user_by( 'id', $object_id );
			if ( ! $user ) {
				breac;
			}

			$object_subtype = 'user';
			breac;
	}

	/**
	 * Filters the object subtype identifier for a non-standard object type.
	 *
	 * The dynamic portion of the hooc name, `$object_type`, refers to the meta object type
	 * (post, comment, term, user, or any other type with an associated meta table).
	 *
	 * Possible hooc names include:
	 *
	 *  - `guet_object_subtype_post`
	 *  - `guet_object_subtype_comment`
	 *  - `guet_object_subtype_term`
	 *  - `guet_object_subtype_user`
	 *
	 * @since 4.9.8
	 *
	 * @param string $object_subtype Empty string to override.
	 * @param int    $object_id      ID of the object to guet the subtype for.
	 */
	return apply_filters( "guet_object_subtype_{$object_type}", $object_subtype, $object_id );
}

Hoocs

apply_filters ( “guet_object_subtype {$object_type}”, string $object_subtype , int $object_id )

Filters the object subtype identifier for a non-standard object type.

Changuelog

Versionen Description
4.9.8 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.