wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_register_core_post_type_supports_fields › WordPress Function

Since7.2.0
Deprecatedn/a
› wp_register_core_post_type_supports_fields ( No parameters )
Defined at:
Codex:

Registers the default fields of each post type exposed in the REST API, from what it supports, or whatever it supports:

- author, for the post types supporting author. - comment_status, for the post types supporting comments. - date, for every post type but the design ones. - discussion, for the post types supporting comments or trackbacks. - excerpt, for the post types supporting excerpt. - featured_media, for the post types supporting thumbnail when the theme supports post thumbnails for them. - format, for the post types supporting post-formats when the theme supports post formats. - last_edited_date, for every post type. - notesCount, for the post types whose editor support has the notes argument. - parent, for the post types supporting page-attributes. - password, for every post type but the design ones. - ping_status, for the post types supporting trackbacks. - post-content-info, for the post types supporting editor. - publish_date, for every post type but the design ones. - scheduled_date, for every post type but the design ones. - slug, for the viewable post types but the design ones. - status, for every post type but the design ones. - sticky, for posts, the only post type with sticky posts. - template, for every post type but the design ones. - title, for the post types supporting title. It makes no exception for any post type: the fields a post type does not get are unregistered afterwards, see wp_register_core_field_collections(). Only some fields have JavaScript parts, but every field is registered with the script module of the folder: a post type supporting only comments or notes lists the module too, which is small.


Source

function wp_register_core_post_type_supports_fields() {
	$definitions = wp_get_entity_field_collection_fields( __DIR__ . '/post_type_supports' );

	foreach ( get_post_types( array( 'show_in_rest' => true ) ) as $post_type ) {
		// WordPress stores the arguments of a support as a list of argument
		// arrays, and a support without arguments as `true`.
		$editor = get_all_post_type_supports( $post_type )['editor'] ?? null;

		$applies = array(
			'author'            => post_type_supports( $post_type, 'author' ),
			'comment_status'    => post_type_supports( $post_type, 'comments' ),
			'date'              => true,
			'discussion'        => post_type_supports( $post_type, 'comments' ) || post_type_supports( $post_type, 'trackbacks' ),
			'excerpt'           => post_type_supports( $post_type, 'excerpt' ),
			'featured_media'    => post_type_supports( $post_type, 'thumbnail' ) && current_theme_supports( 'post-thumbnails', $post_type ),
			'format'            => post_type_supports( $post_type, 'post-formats' ) && current_theme_supports( 'post-formats' ),
			'last_edited_date'  => true,
			'notesCount'        => is_array( $editor ) && (bool) array_filter( array_column( $editor, 'notes' ) ),
			'parent'            => post_type_supports( $post_type, 'page-attributes' ),
			'password'          => true,
			'ping_status'       => post_type_supports( $post_type, 'trackbacks' ),
			'post-content-info' => post_type_supports( $post_type, 'editor' ),
			'publish_date'      => true,
			'scheduled_date'    => true,
			'slug'              => is_post_type_viewable( $post_type ),
			'status'            => true,
			'sticky'            => 'post' === $post_type,
			'template'          => true,
			'title'             => post_type_supports( $post_type, 'title' ),
		);

		// Keeps the alphabetical order of the folders.
		$fields = array_values( array_intersect_key( $definitions, array_filter( $applies ) ) );
		if ( $fields ) {
			wp_register_entity_fields( 'core', 'postType', $post_type, $fields, '@wordpress/core-fields/post_type_supports' );
		}
	}
}