Yoast\WP\SEO\Bulk_Editor\User_Interface

Bulk_Editor_Integration::get_initial_selection │ private │ Yoast 1.0

Returns the selection carried over from a post overview bulk action, if any.

The parameters only decide which rows start out selected in the app; the REST endpoints enforce the actual per-post edit access when anything is saved.

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

Хуков нет.

Возвращает

array<string,. string|int|array<int>> The content type, post IDs and overview selection count.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_initial_selection( $content_types ): array;
$content_types(массив) (обязательный)
.

Код Bulk_Editor_Integration::get_initial_selection() Yoast 28.9

private function get_initial_selection( array $content_types ): array {
	$initial_selection = [
		'contentType'   => '',
		'postIds'       => [],
		'selectedCount' => 0,
	];

	// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Reason: read-only display state, no action is taken.
	if ( ! isset( $_GET[ self::CONTENT_TYPE_PARAM ] ) || ! \is_string( $_GET[ self::CONTENT_TYPE_PARAM ] ) ) {
		return $initial_selection;
	}

	$content_type = \sanitize_text_field( \wp_unslash( $_GET[ self::CONTENT_TYPE_PARAM ] ) );
	if ( ! \in_array( $content_type, \array_column( $content_types, 'name' ), true ) ) {
		return $initial_selection;
	}
	$initial_selection['contentType'] = $content_type;

	if ( isset( $_GET[ self::POST_IDS_PARAM ] ) && \is_string( $_GET[ self::POST_IDS_PARAM ] ) ) {
		$post_ids = \explode( ',', \sanitize_text_field( \wp_unslash( $_GET[ self::POST_IDS_PARAM ] ) ) );
		$post_ids = \array_values(
			\array_unique(
				\array_filter(
					\array_map( 'intval', $post_ids ),
					static function ( $id ) {
						return $id > 0;
					},
				),
			),
		);
		$post_ids = \array_slice( $post_ids, 0, Batch_Limit::MAX_ITEMS );

		$initial_selection['postIds']       = $post_ids;
		$initial_selection['selectedCount'] = \count( $post_ids );
	}

	if (
		$initial_selection['postIds'] !== []
		&& isset( $_GET[ self::SELECTED_COUNT_PARAM ] )
		&& \is_string( $_GET[ self::SELECTED_COUNT_PARAM ] )
	) {
		// The count can only grow beyond the carried IDs, never shrink below them.
		$initial_selection['selectedCount'] = \max(
			$initial_selection['selectedCount'],
			\absint( \wp_unslash( $_GET[ self::SELECTED_COUNT_PARAM ] ) ),
		);
	}
	// phpcs:enable WordPress.Security.NonceVerification.Recommended

	return $initial_selection;
}