wp_xmlrpc_server::mt_getPostCategories
Retrieves post categories.
Метод класса: wp_xmlrpc_server{}
Хуки из метода
Возвращает
Массив|IXR_Error.
Использование
$wp_xmlrpc_server = new wp_xmlrpc_server(); $wp_xmlrpc_server->mt_getPostCategories( $args );
- $args(массив) (обязательный)
Method arguments. Note: arguments must be ordered as documented.
-
0(int)
Post ID. -
1(строка)
Username. - 2(строка)
Password.
-
Список изменений
| С версии 1.5.0 | Введена. |
Код wp_xmlrpc_server::mt_getPostCategories() wp xmlrpc server::mt getPostCategories WP 6.8.3
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();
$cat_ids = wp_get_post_categories( (int) $post_id );
// First listed category will be the primary category.
$is_primary = true;
foreach ( $cat_ids as $cat_id ) {
$categories[] = array(
'categoryName' => get_cat_name( $cat_id ),
'categoryId' => (string) $cat_id,
'isPrimary' => $is_primary,
);
$is_primary = false;
}
return $categories;
}