wp_xmlrpc_server::wp_getUsersBlogs()publicWP 2.6.0

Retrieves the blogs of the user.

Метод класса: wp_xmlrpc_server{}

Хуки из метода

Возвращает

Массив|IXR_Error. Array contains:

  • 'isAdmin'
  • 'isPrimary' - whether the blog is the user's primary blog
  • 'url'
  • 'blogid'
  • 'blogName'
  • 'xmlrpc' - url of xmlrpc endpoint

Использование

$wp_xmlrpc_server = new wp_xmlrpc_server();
$wp_xmlrpc_server->wp_getUsersBlogs( $args );
$args(массив) (обязательный)

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

  • 0(строка)
    Username.

  • 1(строка)
    Password.

Список изменений

С версии 2.6.0 Введена.

Код wp_xmlrpc_server::wp_getUsersBlogs() WP 6.6.2

public function wp_getUsersBlogs( $args ) {
	if ( ! $this->minimum_args( $args, 2 ) ) {
		return $this->error;
	}

	// If this isn't on WPMU then just use blogger_getUsersBlogs().
	if ( ! is_multisite() ) {
		array_unshift( $args, 1 );
		return $this->blogger_getUsersBlogs( $args );
	}

	$this->escape( $args );

	$username = $args[0];
	$password = $args[1];

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

	/**
	 * Fires after the XML-RPC user has been authenticated but before the rest of
	 * the method logic begins.
	 *
	 * All built-in XML-RPC methods use the action xmlrpc_call, with a parameter
	 * equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc.
	 *
	 * @since 2.5.0
	 * @since 5.7.0 Added the `$args` and `$server` parameters.
	 *
	 * @param string           $name   The method name.
	 * @param array|string     $args   The escaped arguments passed to the method.
	 * @param wp_xmlrpc_server $server The XML-RPC server instance.
	 */
	do_action( 'xmlrpc_call', 'wp.getUsersBlogs', $args, $this );

	$blogs           = (array) get_blogs_of_user( $user->ID );
	$struct          = array();
	$primary_blog_id = 0;
	$active_blog     = get_active_blog_for_user( $user->ID );
	if ( $active_blog ) {
		$primary_blog_id = (int) $active_blog->blog_id;
	}

	foreach ( $blogs as $blog ) {
		// Don't include blogs that aren't hosted at this site.
		if ( get_current_network_id() != $blog->site_id ) {
			continue;
		}

		$blog_id = $blog->userblog_id;

		switch_to_blog( $blog_id );

		$is_admin   = current_user_can( 'manage_options' );
		$is_primary = ( (int) $blog_id === $primary_blog_id );

		$struct[] = array(
			'isAdmin'   => $is_admin,
			'isPrimary' => $is_primary,
			'url'       => home_url( '/' ),
			'blogid'    => (string) $blog_id,
			'blogName'  => get_option( 'blogname' ),
			'xmlrpc'    => site_url( 'xmlrpc.php', 'rpc' ),
		);

		restore_current_blog();
	}

	return $struct;
}