Yoast\WP\SEO\Elementor\Infrastructure

Request_Post::get_post_idpublicYoast 1.0

Retrieves the post ID, applicable to the current request.

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

Хуков нет.

Возвращает

int|null. The post ID.

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

$Request_Post = new Request_Post();
$Request_Post->get_post_id(): ?int;

Код Request_Post::get_post_id() Yoast 26.9

public function get_post_id(): ?int {
	switch ( $this->get_server_request_method() ) {
		case 'GET':
			// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
			if ( isset( $_GET['post'] ) && \is_numeric( $_GET['post'] ) ) {
				// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended -- Reason: No sanitization needed because we cast to an integer,We are not processing form information.
				return (int) \wp_unslash( $_GET['post'] );
			}

			break;
		case 'POST':
			// Only allow POST requests when doing AJAX.
			if ( ! \wp_doing_ajax() ) {
				break;
			}

			switch ( $this->get_post_action() ) {
				// Our Yoast SEO form submission, it should include `post_id`.
				case 'wpseo_elementor_save':
					// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information.
					if ( isset( $_POST['post_id'] ) && \is_numeric( $_POST['post_id'] ) ) {
						// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Missing -- Reason: No sanitization needed because we cast to an integer,We are not processing form information.
						return (int) \wp_unslash( $_POST['post_id'] );
					}

					break;
				// Elementor editor AJAX request.
				case 'elementor_ajax':
					return $this->get_document_id();
			}

			break;
	}

	return null;
}