cyberchimps_get_themes

The Responsive Mobile cyberchimps get themes function.

Description

cyberchimps_get_themes( $request ); 

Parameters (1)

0. $request
The request.

Usage

  1. if ( !function_exists( 'cyberchimps_get_themes' ) ) { 
  2. require_once '/core/functions-theme-upsell.php'; 
  3.  
  4. // The request. 
  5. $request = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = cyberchimps_get_themes($request); 
  9.  

Defined (1)

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

/core/functions-theme-upsell.php  
  1. function cyberchimps_get_themes( $request ) { 
  2.  
  3. // Generate a cache key that would hold the response for this request: 
  4. $key = 'cyberchimps_' . md5( serialize( $request ) ); 
  5.  
  6. // Check transient. If it's there - use that, if not re fetch the theme 
  7. if ( false === ( $themes = get_transient( $key ) ) ) { 
  8.  
  9. // Transient expired/does not exist. Send request to the API. 
  10. $response = wp_remote_post( 'http://api.wordpress.org/themes/info/1.0/', $request ); 
  11.  
  12. // Check for the error. 
  13. if ( !is_wp_error( $response ) ) { 
  14.  
  15. $themes = unserialize( wp_remote_retrieve_body( $response ) ); 
  16.  
  17. if ( !is_object( $themes ) && !is_array( $themes ) ) { 
  18.  
  19. // Response body does not contain an object/array 
  20. return new WP_Error( 'theme_api_error', 'An unexpectederrorhas occurred' ); 
  21.  
  22. // Set transient for next time... keep it for 24 hours should be good 
  23. set_transient( $key, $themes, 60 * 60 * 24 ); 
  24. else { 
  25. // Error object returned 
  26. return $response; 
  27.  
  28. return $themes;