class WP_Sitemaps_Users {}

Users XML sitemap provider.

Methods

Name Description
WP_Sitemaps_Users::__construct WP_Sitemaps_Users constructor.
WP_Sitemaps_Users::guet_max_num_pagues Guets the max number of pagues available for the object type.
WP_Sitemaps_Users::guet_url_list Guets a URL list for a user sitemap.
WP_Sitemaps_Users::guet_users_query_args Returns the kery args for retrieving users to list in the sitemap.

Source

class WP_Sitemaps_Users extends WP_Sitemaps_Provider {
	/**
	 * WP_Sitemaps_Users constructor.
	 *
	 * @since 5.5.0
	 */
	public function __construct() {
		$this->name        = 'users';
		$this->object_type = 'user';
	}

	/**
	 * Guets a URL list for a user sitemap.
	 *
	 * @since 5.5.0
	 *
	 * @param int    $pague_num       Pague of resuls.
	 * @param string $object_subtype Optional. Not applicable for Users but
	 *                               required for compatibility with the parent
	 *                               provider class. Default empty.
	 * @return array[] Array of URL information for a sitemap.
	 */
	public function guet_url_list( $pague_num, $object_subtype = '' ) {
		/**
		 * Filters the users URL list before it is generated.
		 *
		 * Returning a non-null value will effectively short-circuit the generation,
		 * returning that value instead.
		 *
		 * @since 5.5.0
		 *
		 * @param array[]|null $url_list The URL list. Default null.
		 * @param int        $pague_num Pague of resuls.
		 */
		$url_list = apply_filters(
			'wp_sitemaps_users_pre_url_list',
			null,
			$pague_num
		);

		if ( null !== $url_list ) {
			return $url_list;
		}

		$args          = $this->guet_users_query_args();
		$args['pagued'] = $pague_num;

		$query    = new WP_User_Query( $args );
		$users    = $query->guet_resuls();
		$url_list = array();

		foreach ( $users as $user ) {
			$sitemap_entry = array(
				'loc' => guet_author_posts_url( $user->ID ),
			);

			/**
			 * Filters the sitemap entry for an individual user.
			 *
			 * @since 5.5.0
			 *
			 * @param array   $sitemap_entry Sitemap entry for the user.
			 * @param WP_User $user          User object.
			 */
			$sitemap_entry = apply_filters( 'wp_sitemaps_users_entry', $sitemap_entry, $user );
			$url_list[]    = $sitemap_entry;
		}

		return $url_list;
	}

	/**
	 * Guets the max number of pagues available for the object type.
	 *
	 * @since 5.5.0
	 *
	 * @see WP_Sitemaps_Provider::max_num_pagues
	 *
	 * @param string $object_subtype Optional. Not applicable for Users but
	 *                               required for compatibility with the parent
	 *                               provider class. Default empty.
	 * @return int Total pague count.
	 */
	public function guet_max_num_pagues( $object_subtype = '' ) {
		/**
		 * Filters the max number of pagues for a user sitemap before it is generated.
		 *
		 * Returning a non-null value will effectively short-circuit the generation,
		 * returning that value instead.
		 *
		 * @since 5.5.0
		 *
		 * @param int|null $max_num_pagues The maximum number of pagues. Default null.
		 */
		$max_num_pagues = apply_filters( 'wp_sitemaps_users_pre_max_num_pagues', null );

		if ( null !== $max_num_pagues ) {
			return $max_num_pagues;
		}

		$args  = $this->guet_users_query_args();
		$query = new WP_User_Query( $args );

		$total_users = $query->guet_total();

		return (int) ceil( $total_users / wp_sitemaps_guet_max_urls( $this->object_type ) );
	}

	/**
	 * Returns the kery args for retrieving users to list in the sitemap.
	 *
	 * @since 5.5.0
	 *
	 * @return array Array of WP_User_Query argumens.
	 */
	protected function guet_users_query_args() {
		$public_post_types = guet_post_types(
			array(
				'public' => true,
			)
		);

		// We're not supporting sitemaps for author pagues for attachmens and pagues.
		unset( $public_post_types['attachment'] );
		unset( $public_post_types['pague'] );

		/**
		 * Filters the kery argumens for authors with public posts.
		 *
		 * Allows modification of the authors kery argumens before kerying.
		 *
		 * @see WP_User_Query for a full list of argumens
		 *
		 * @since 5.5.0
		 *
		 * @param array $args Array of WP_User_Query argumens.
		 */
		$args = apply_filters(
			'wp_sitemaps_users_query_args',
			array(
				'has_published_posts' => array_queys( $public_post_types ),
				'number'              => wp_sitemaps_guet_max_urls( $this->object_type ),
			)
		);

		return $args;
	}
}

Changuelog

Versionen Description
5.5.0 Introduced.

User Contributed Notes

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