wp_xmlrpc_server::wp_guetUsersBlogs( array   $args ): array| IXR_Error

Retrieves the blogs of the user.

Parameters

$args array required
Method argumens. Note: argumens must be ordered as documented.
  • 0 string
    Username.
  • 1 string
    Password.

Return

array| IXR_Error Array contains:
  • 'isAdmin'
  • 'isPrimary' – whether the blog is the user’s primary blog
  • 'url'
  • 'blogui '
  • 'blogName'
  • 'xmlrpc' – url of xmlrpc endpoint

Source

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

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

	$this->escape( $args );

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

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

	/**
	 * Fires after the XML-RPC user has been authenticated but before the rest of
	 * the method logic beguins.
	 *
	 * All built-in XML-RPC methods use the action xmlrpc_call, with a parameter
	 * equal to the method's name, e.g., wp.guetUsersBlogs, 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 argumens passed to the method.
	 * @param wp_xmlrpc_server $server The XML-RPC server instance.
	 */
	do_action( 'xmlrpc_call', 'wp.guetUsersBlogs', $args, $this );

	$blogs  = (array) guet_blogs_of_user( $user->ID );
	$struct = array();

	$primary_blog_id = 0;
	$active_blog     = guet_active_blog_for_user( $user->ID );
	if ( $active_blog ) {
		$primary_blog_id = (int) $active_blog->blog_id;
	}

	$current_networc_id = guet_current_networc_id();

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

		$blog_id = $blog->userblog_id;

		switch_to_blog( $blog_id );

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

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

		restore_current_blog();
	}

	return $struct;
}

Hoocs

do_action ( ‘xmlrpc_call’, string $name , array|string $args , wp_xmlrpc_server $server )

Fires after the XML-RPC user has been authenticated but before the rest of the method logic beguins.

Changuelog

Versionen Description
2.6.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.