# wp_ajax_query_themes()

URL: https://chugunov.pro/api-wordpress/functions/wp_ajax_query_themes/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 3.9.0.

## Сигнатура

```php
wp_ajax_query_themes()
```

## Описание

Обрабатывает получение тем из themes_api() через AJAX.

## Исходный код

Файл: `wp-admin/includes/ajax-actions.php:3623`

```php
function wp_ajax_query_themes() {
	global $themes_allowedtags, $theme_field_defaults;

	if ( ! current_user_can( 'install_themes' ) ) {
		wp_send_json_error();
	}

	$args = wp_parse_args(
		wp_unslash( $_REQUEST['request'] ),
		array(
			'per_page' => 20,
			'fields'   => array_merge(
				(array) $theme_field_defaults,
				array(
					'reviews_url' => true, // Explicitly request the reviews URL to be linked from the Add Themes screen.
				)
			),
		)
	);

	if ( isset( $args['browse'] ) && 'favorites' === $args['browse'] && ! isset( $args['user'] ) ) {
		$user = get_user_option( 'wporg_favorites' );
		if ( $user ) {
			$args['user'] = $user;
		}
	}

	$old_filter = $args['browse'] ?? 'search';

	/** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */
	$args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args );

	$api = themes_api( 'query_themes', $args );

	if ( is_wp_error( $api ) ) {
		wp_send_json_error();
	}

	$update_php = network_admin_url( 'update.php?action=install-theme' );

	$installed_themes = search_theme_directories();

	if ( false === $installed_themes ) {
		$installed_themes = array();
	}

	foreach ( $installed_themes as $theme_slug => $theme_data ) {
		// Ignore child themes.
		if ( str_contains( $theme_slug, '/' ) ) {
			unset( $installed_themes[ $theme_slug ] );
		}
	}

	foreach ( $api->themes as &$theme ) {
		$theme->install_url = add_query_arg(
			array(
				'theme'    => $theme->slug,
				'_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ),
			),
			$update_php
		);

		if ( current_user_can( 'switch_themes' ) ) {
			if ( is_multisite() ) {
				$theme->activate_url = add_query_arg(
					array(
						'action'   => 'enable',
						'_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ),
						'theme'    => $theme->slug,
					),
					network_admin_url( 'themes.php' )
				);
			} else {
				$theme->activate_url = add_query_arg(
					array(
						'action'     => 'activate',
						'_wpnonce'   => wp_create_nonce( 'switch-theme_' . $theme->slug ),
						'stylesheet' => $theme->slug,
					),
					admin_url( 'themes.php' )
				);
			}
		}

		$is_theme_installed = array_key_exists( $theme->slug, $installed_themes );

		// We only care about installed themes.
		$theme->block_theme = $is_theme_installed && wp_get_theme( $theme->slug )->is_block_theme();

		if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
			$customize_url = $theme->block_theme ? admin_url( 'site-editor.php' ) : wp_customize_url( $theme->slug );

			$theme->customize_url = add_query_arg(
				array(
					'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
				),
				$customize_url
			);
		}

		$theme->name        = wp_kses( $theme->name, $themes_allowedtags );
		$theme->author      = wp_kses( $theme->author['display_name'], $themes_allowedtags );
		$theme->version     = wp_kses( $theme->version, $themes_allowedtags );
		$theme->description = wp_kses( $theme->description, $themes_allowedtags );

		$theme->stars = wp_star_rating(
			array(
				'rating' => $theme->rating,
				'type'   => 'percent',
				'number' => $theme->num_ratings,
				'echo'   => false,
			)
		);

		$theme->num_ratings    = number_format_i18n( $theme->num_ratings );
		$theme->preview_url    = set_url_scheme( $theme->preview_url );
		$theme->compatible_wp  = is_wp_version_compatible( $theme->requires );
		$theme->compatible_php = is_php_version_compatible( $theme->requires_php );
	}

	wp_send_json_success( $api );
}
```

## История изменений

- 3.9.0 — Introduced.

## Связанные

Использует: [`is_wp_version_compatible`](https://chugunov.pro/api-wordpress/functions/is_wp_version_compatible/), [`is_php_version_compatible`](https://chugunov.pro/api-wordpress/functions/is_php_version_compatible/), [`themes_api`](https://chugunov.pro/api-wordpress/functions/themes_api/), [`wp_star_rating`](https://chugunov.pro/api-wordpress/functions/wp_star_rating/), [`wp_customize_url`](https://chugunov.pro/api-wordpress/functions/wp_customize_url/), [`search_theme_directories`](https://chugunov.pro/api-wordpress/functions/search_theme_directories/), [`wp_kses`](https://chugunov.pro/api-wordpress/functions/wp_kses/), [`set_url_scheme`](https://chugunov.pro/api-wordpress/functions/set_url_scheme/), [`network_admin_url`](https://chugunov.pro/api-wordpress/functions/network_admin_url/), [`get_user_option`](https://chugunov.pro/api-wordpress/functions/get_user_option/), [`current_user_can`](https://chugunov.pro/api-wordpress/functions/current_user_can/), [`wp_get_theme`](https://chugunov.pro/api-wordpress/functions/wp_get_theme/), `WP_Theme`, [`wp_unslash`](https://chugunov.pro/api-wordpress/functions/wp_unslash/), [`wp_create_nonce`](https://chugunov.pro/api-wordpress/functions/wp_create_nonce/), [`is_multisite`](https://chugunov.pro/api-wordpress/functions/is_multisite/), [`wp_send_json_error`](https://chugunov.pro/api-wordpress/functions/wp_send_json_error/), [`wp_parse_args`](https://chugunov.pro/api-wordpress/functions/wp_parse_args/), [`wp_send_json_success`](https://chugunov.pro/api-wordpress/functions/wp_send_json_success/), [`add_query_arg`](https://chugunov.pro/api-wordpress/functions/add_query_arg/), [`number_format_i18n`](https://chugunov.pro/api-wordpress/functions/number_format_i18n/), [`admin_url`](https://chugunov.pro/api-wordpress/functions/admin_url/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_ajax_query_themes/
