wp_ajax_query_themes() - WordPress 函数参考中文文档

返回介绍

wp_ajax_query_themes()

发布于 2017-09-11 字数4416 浏览 874 评论 0

wp_ajax_query_themes()

Ajax handler for getting themes from themes_api().


描述


源代码

File: wp-admin/includes/ajax-actions.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'   => $theme_field_defaults
	) );

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

	$old_filter = isset( $args['browse'] ) ? $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' );
	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' ) );
			}
		}

		if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
			$theme->customize_url = add_query_arg( array(
				'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
			), wp_customize_url( $theme->slug ) );
		}

		$theme->name        = wp_kses( $theme->name, $themes_allowedtags );
		$theme->author      = wp_kses( $theme->author, $themes_allowedtags );
		$theme->version     = wp_kses( $theme->version, $themes_allowedtags );
		$theme->描述 = wp_kses( $theme->描述, $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 );
	}

	wp_send_json_success( $api );
}

更新日志

Version 描述
3.9.0 Introduced.

相关函数

Uses

  • wp-admin/includes/theme.php:
    themes_api()
  • wp-admin/includes/template.php:
    wp_star_rating()
  • wp-includes/capabilities.php:
    current_user_can()
  • wp-includes/theme.php:
    wp_customize_url()
  • wp-includes/formatting.php:
    wp_unslash()
  • wp-includes/pluggable.php:
    wp_create_nonce()
  • wp-includes/kses.php:
    wp_kses()
  • wp-includes/load.php:
    is_multisite()
  • wp-includes/functions.php:
    wp_send_json_error()
  • wp-includes/functions.php:
    wp_parse_args()
  • wp-includes/functions.php:
    wp_send_json_success()
  • wp-includes/functions.php:
    add_query_arg()
  • wp-includes/functions.php:
    number_format_i18n()
  • wp-includes/link-template.php:
    set_url_scheme()
  • wp-includes/link-template.php:
    network_admin_url()
  • wp-includes/link-template.php:
    admin_url()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/user.php:
    get_user_option()
  • wp-includes/load.php:
    is_wp_error()
  • Show 14 more uses
    Hide more uses


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!