wp_xmlrpc_server::mt_getPostCategories()publicWP 1.5.0

Retrieves post categories.

Method of the class: wp_xmlrpc_server{}

Hooks from the method

Return

Array|IXR_Error.

Usage

$wp_xmlrpc_server = new wp_xmlrpc_server();
$wp_xmlrpc_server->mt_getPostCategories( $args );
$args(array) (required)

Method arguments. Note: arguments must be ordered as documented.

  • 0(int)
    Post ID.

  • 1(string)
    Username.

  • 2(string)
    Password.

Changelog

Since 1.5.0 Introduced.

wp_xmlrpc_server::mt_getPostCategories() code WP 6.5.2

public function mt_getPostCategories( $args ) {
	$this->escape( $args );

	$post_id  = (int) $args[0];
	$username = $args[1];
	$password = $args[2];

	$user = $this->login( $username, $password );
	if ( ! $user ) {
		return $this->error;
	}

	if ( ! get_post( $post_id ) ) {
		return new IXR_Error( 404, __( 'Invalid post ID.' ) );
	}

	if ( ! current_user_can( 'edit_post', $post_id ) ) {
		return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
	}

	/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
	do_action( 'xmlrpc_call', 'mt.getPostCategories', $args, $this );

	$categories = array();
	$catids     = wp_get_post_categories( (int) $post_id );
	// First listed category will be the primary category.
	$isPrimary = true;
	foreach ( $catids as $catid ) {
		$categories[] = array(
			'categoryName' => get_cat_name( $catid ),
			'categoryId'   => (string) $catid,
			'isPrimary'    => $isPrimary,
		);
		$isPrimary    = false;
	}

	return $categories;
}