Yoast\WP\SEO\Elementor\Infrastructure

Request_Post::get_document_id()privateYoast 1.0

Retrieves the document ID from the POST request.

Note: this is specific to Elementor' elementor_ajax action. And then the get_document_config internal action. Currently, you can see this in play when:

  • showing the Site Settings in the Elementor editor
  • going to another Recent post/page in the Elementor editor V2

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

Хуков нет.

Возвращает

int|null. The document ID or null if not found.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_document_id(): ?int;

Код Request_Post::get_document_id() Yoast 24.3

private function get_document_id(): ?int {
	// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information.
	if ( ! ( isset( $_POST['actions'] ) && \is_string( $_POST['actions'] ) ) ) {
		return null;
	}

	// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Missing -- Reason: No sanitization needed because we cast to an integer (after JSON decode and type/exist checks),We are not processing form information.
	$actions = \json_decode( \wp_unslash( $_POST['actions'] ), true );
	if ( ! \is_array( $actions ) ) {
		return null;
	}

	// Elementor sends everything in a `document-{ID}` format.
	$action = \array_shift( $actions );
	if ( $action === null ) {
		return null;
	}

	// There are multiple action types. We only care about the "get_document_config" one.
	if ( ! ( isset( $action['action'] ) && $action['action'] === 'get_document_config' ) ) {
		return null;
	}

	// Return the ID from the data, if it is set and numeric.
	if ( isset( $action['data']['id'] ) && \is_numeric( $action['data']['id'] ) ) {
		return (int) $action['data']['id'];
	}

	return null;
}