WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#18436 closed feature request (fixed)

Retrieve post type information in XML-RPC

Reported by: nprasath002 Owned by:
Milestone: 3.4 Priority: normal
Severity: normal Version:
Component: XML-RPC Keywords: has-patch
Focuses: Cc:

Description


Attachments (6)

wp.getPostType.patch (3.2 KB) - added by nprasath002 3 years ago.
wp.getPostType.2.patch (2.3 KB) - added by maxcutler 2 years ago.
wp.getPostType.3.patch (5.2 KB) - added by markoheijnen 2 years ago.
wp.getPostType.4.patch (6.0 KB) - added by markoheijnen 2 years ago.
New get all theme support function, updated PHPDoc and little changes to _prepare_post_type
wp.getPostType.5.patch (6.4 KB) - added by markoheijnen 2 years ago.
wp_getOptions can also returns post thumbnail theme support
wp.getPostType.6.patch (6.5 KB) - added by maxcutler 2 years ago.

Download all attachments as: .zip

Change History (20)

nprasath0023 years ago

comment:1 maxcutler3 years ago

  • Cc max@… added

This and the plural version (#18437) should probably include the 'name' field in the returned array. The name may be supplied as a method parameter (or an array key in the plural version), but that forces the API consumer to keep track of it separately. It would be much easier if all the fields were returned in the same struct.

I'm also curious as to how you selected the subset of fields to return. Some that could be useful like 'public', 'export', 'menu_icon' are missing. If you don't want to add them by default, it might be nice to have the list of fields be put through a filter so that plugins can modify what gets returned.

comment:2 nacin3 years ago

Seems like it should just return get_post_type_object(). That said, some values like 'taxonomies' are only for registration, and I don't think they'd be accurate. (Not positive.) For that you'd need to consult get_object_taxonomies() and also return that value.

comment:3 nprasath0023 years ago

Returning all the information (using get_post_type_object) is costlier.
The response time of the clients will be huge for slow net connections.
We need to to have a lighter version which returns a subset of fields
and put through a filter so that plugins can extend it.

I will work on a patch and add.

maxcutler2 years ago

comment:4 maxcutler2 years ago

Cleaned up the patch formatting and implemented tweaks recommended by nacin, using the prepare_post_type method from #18437.

nprasath002, if you are still concerned about the size of the response, perhaps we can implement a fields parameter like in #18433 and have the default value be a smaller subset. But in any case, plugins can use the xmlrpc_prepare_post_type filter to refine the response.

comment:5 markoheijnen2 years ago

  • Cc marko@… added

Created a new patch that combines this ticket with #18437. I also added filter parameter for getPostTypes and fields parameter for both.
I'm not sure how the naming should be. It's most likely it can be better grouped.

comment:6 maxcutler2 years ago

  • Cc max@… removed

comment:7 maxcutler2 years ago

  • Cc max@… added

markoheijnen2 years ago

New get all theme support function, updated PHPDoc and little changes to _prepare_post_type

markoheijnen2 years ago

wp_getOptions can also returns post thumbnail theme support

comment:8 markoheijnen2 years ago

After some discussion in the IRC chat on 2 March I decided only to return the theme support for now. That shows if the WordPress installation supports.

For all post type support you can include a new option that includes all post types with thumbnail support like the following code:

$posttype_supports = array();
foreach ( get_post_types() as $post_type ) {
	if ( post_type_supports( $post_type, 'thumbnail' ) ) {
		$posttype_supports[] = $post_type;
	}
}

comment:9 westi2 years ago

The patch in wp.getPostType.5.patch looks good.

It would be nice to have some unit tests before we commit the new functions wp.getPostType and wp.getPostTypes adding the extra "option" seems like a no-brainer.

Would you be able to write some test cases for the new functions?

comment:10 westi2 years ago

  • Milestone changed from Awaiting Review to 3.4

Test case for the featured image option added in [UT568].

comment:11 westi2 years ago

Option added in [20155] props markoheijnen (which I forgot)

maxcutler2 years ago

comment:12 maxcutler2 years ago

Refreshed patch with some minor fixes found while writing unit tests in [UT587].

comment:13 westi2 years ago

In [20271]:

XMLRPC: Add new wp.getPostType and wp.getPostTypes apis. See #18436 props maxcutler, markoheijnen and nprasath002.

comment:14 maxcutler2 years ago

  • Resolution set to fixed
  • Status changed from new to closed

New bugs or enhancements on new tickets.

Note: See TracTickets for help on using tickets.