Yoast_Network_Admin::get_site_choices()publicYoast 1.0

Gets the available sites as choices, e.g. for a dropdown.

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

Хуков нет.

Возвращает

Массив. Choices as $site_id => $site_label pairs.

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

$Yoast_Network_Admin = new Yoast_Network_Admin();
$Yoast_Network_Admin->get_site_choices( $include_empty, $show_title );
$include_empty(true|false)
Whether to include an initial placeholder choice.
По умолчанию: false
$show_title(true|false)
Whether to show the title for each site. This requires switching through the sites, so has performance implications for sites that do not use a persistent cache.
По умолчанию: false

Код Yoast_Network_Admin::get_site_choices() Yoast 22.4

public function get_site_choices( $include_empty = false, $show_title = false ) {
	$choices = [];

	if ( $include_empty ) {
		$choices['-'] = __( 'None', 'wordpress-seo' );
	}

	$criteria = [
		'deleted'    => 0,
		'network_id' => get_current_network_id(),
	];
	$sites    = get_sites( $criteria );

	foreach ( $sites as $site ) {
		$site_name = $site->domain . $site->path;
		if ( $show_title ) {
			$site_name = $site->blogname . ' (' . $site->domain . $site->path . ')';
		}
		$choices[ $site->blog_id ] = $site->blog_id . ': ' . $site_name;

		$site_states = $this->get_site_states( $site );
		if ( ! empty( $site_states ) ) {
			$choices[ $site->blog_id ] .= ' [' . implode( ', ', $site_states ) . ']';
		}
	}

	return $choices;
}