ajax_get_term_keyword_usage()Yoast 1.0

Retrieves the keyword for the keyword doubles of the termpages.

Хуков нет.

Возвращает

null. Ничего (null).

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

ajax_get_term_keyword_usage();

Код ajax_get_term_keyword_usage() Yoast 22.3

function ajax_get_term_keyword_usage() {
	check_ajax_referer( 'wpseo-keyword-usage', 'nonce' );

	if ( ! isset( $_POST['post_id'], $_POST['keyword'], $_POST['taxonomy'] ) || ! is_string( $_POST['keyword'] ) || ! is_string( $_POST['taxonomy'] ) ) {
		wp_die( -1 );
	}

	// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are casting the unsafe input to an integer.
	$post_id = (int) wp_unslash( $_POST['post_id'] );

	if ( $post_id === 0 ) {
		wp_die( -1 );
	}

	$keyword       = sanitize_text_field( wp_unslash( $_POST['keyword'] ) );
	$taxonomy_name = sanitize_text_field( wp_unslash( $_POST['taxonomy'] ) );

	$taxonomy = get_taxonomy( $taxonomy_name );

	if ( ! $taxonomy ) {
		wp_die( 0 );
	}

	if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) {
		wp_die( -1 );
	}

	$usage = WPSEO_Taxonomy_Meta::get_keyword_usage( $keyword, $post_id, $taxonomy_name );

	// Normalize the result so it is the same as the post keyword usage AJAX request.
	$usage = $usage[ $keyword ];

	wp_die(
		// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
		WPSEO_Utils::format_json_encode( $usage )
	);
}