WPSEO_Metabox::get_metabox_post()protectedYoast 1.0

Returns post in metabox context.

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

Хуков нет.

Возвращает

WP_Post|Массив<Строку|int|true|false>.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_metabox_post();

Код WPSEO_Metabox::get_metabox_post() Yoast 22.4

protected function get_metabox_post() {
	if ( $this->post !== null ) {
		return $this->post;
	}

	// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
	if ( isset( $_GET['post'] ) && is_string( $_GET['post'] ) ) {
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, Sanitization happens in the validate_int function.
		$post_id = (int) WPSEO_Utils::validate_int( wp_unslash( $_GET['post'] ) );

		$this->post = get_post( $post_id );

		return $this->post;
	}

	if ( isset( $GLOBALS['post'] ) ) {
		$this->post = $GLOBALS['post'];

		return $this->post;
	}

	return [];
}