wp_ajax_query_themes

Ajax handler for getting themes from themes_api().

Description

wp_ajax_query_themes(); 

Usage

  1. if ( !function_exists( 'wp_ajax_query_themes' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_ajax_query_themes(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_query_themes() { 
  2. global $themes_allowedtags, $theme_field_defaults; 
  3.  
  4. if ( ! current_user_can( 'install_themes' ) ) { 
  5.  
  6. $args = wp_parse_args( wp_unslash( $_REQUEST['request'] ), array( 
  7. 'per_page' => 20,  
  8. 'fields' => $theme_field_defaults 
  9. ) ); 
  10.  
  11. if ( isset( $args['browse'] ) && 'favorites' === $args['browse'] && ! isset( $args['user'] ) ) { 
  12. $user = get_user_option( 'wporg_favorites' ); 
  13. if ( $user ) { 
  14. $args['user'] = $user; 
  15.  
  16. $old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search'; 
  17.  
  18. /** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */ 
  19.  
  20. $api = themes_api( 'query_themes', $args ); 
  21.  
  22. if ( is_wp_error( $api ) ) { 
  23.  
  24. $update_php = network_admin_url( 'update.php?action=install-theme' ); 
  25. foreach ( $api->themes as &$theme ) { 
  26. $theme->install_url = add_query_arg( array( 
  27. 'theme' => $theme->slug,  
  28. '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ) 
  29. ), $update_php ); 
  30.  
  31. if ( current_user_can( 'switch_themes' ) ) { 
  32. if ( is_multisite() ) { 
  33. $theme->activate_url = add_query_arg( array( 
  34. 'action' => 'enable',  
  35. '_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ),  
  36. 'theme' => $theme->slug,  
  37. ), network_admin_url( 'themes.php' ) ); 
  38. } else { 
  39. $theme->activate_url = add_query_arg( array( 
  40. 'action' => 'activate',  
  41. '_wpnonce' => wp_create_nonce( 'switch-theme_' . $theme->slug ),  
  42. 'stylesheet' => $theme->slug,  
  43. ), admin_url( 'themes.php' ) ); 
  44.  
  45. if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { 
  46. $theme->customize_url = add_query_arg( array( 
  47. 'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),  
  48. ), wp_customize_url( $theme->slug ) ); 
  49.  
  50. $theme->name = wp_kses( $theme->name, $themes_allowedtags ); 
  51. $theme->author = wp_kses( $theme->author, $themes_allowedtags ); 
  52. $theme->version = wp_kses( $theme->version, $themes_allowedtags ); 
  53. $theme->description = wp_kses( $theme->description, $themes_allowedtags ); 
  54. $theme->stars = wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings, 'echo' => false ) ); 
  55. $theme->num_ratings = number_format_i18n( $theme->num_ratings ); 
  56. $theme->preview_url = set_url_scheme( $theme->preview_url ); 
  57.