Caldera_Forms_Admin_Feed

Mini CalderaWP.com API client for feeds to admin.

Defined (1)

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

/classes/admin/feed.php  
  1. class Caldera_Forms_Admin_Feed { 
  2.  
  3. /** 
  4. * URL for the API 
  5. * @since 1.4.2 
  6. * @var string 
  7. */ 
  8. protected static $api_url = 'https://calderaforms.com/wp-json/calderawp_api/v2/'; 
  9.  
  10. /** 
  11. * Get the data for the request from remote site 
  12. * @since 1.4.2 
  13. * @param string $endpoint Endpoint for request. 
  14. * @return string 
  15. */ 
  16. protected static function request_data( $endpoint ) { 
  17. $url = self::$api_url . $endpoint; 
  18.  
  19. $request = wp_remote_get( $url ); 
  20. $data = ''; 
  21. if ( ! is_wp_error( $request ) ) { 
  22. $data = wp_remote_retrieve_body( $request ); 
  23. $data = json_decode( $data ); 
  24.  
  25. return $data; 
  26.  
  27.  
  28. /** 
  29. * Get the data for the request from remote site or cache 
  30. * @since 1.4.2 
  31. * @param string $endpoint Endpoint for request. 
  32. * @param null|array $args Optional. Additional query vars to add to request. 
  33. * @return string 
  34. */ 
  35. protected static function get_data( $endpoint, $args = null ) { 
  36. if ( is_array( $args ) ) { 
  37. $endpoint = add_query_arg( $args, $endpoint ); 
  38.  
  39. $key = md5( 'cf_feed' . $endpoint . CFCORE_VER ); 
  40.  
  41. if ( false == ( $data = get_transient( $key ) ) ) { 
  42. $data = self::request_data( $endpoint ); 
  43. foreach ( $data as &$datum ) { 
  44. $datum = self::prepare_item( $datum ); 
  45.  
  46. set_transient( $key, $data, HOUR_IN_SECONDS ); 
  47.  
  48. return $data; 
  49.  
  50. /** 
  51. * Get featured plugins 
  52. * @since 1.4.2 
  53. * @return array|string 
  54. */ 
  55. public static function get_featured() { 
  56. return self::get_data( 'products/featured' ); 
  57.  
  58.  
  59. /** 
  60. * Get Caldera Forms add-on 
  61. * @since 1.4.2 
  62. * @return array|string 
  63. */ 
  64. public static function get_cf_addons() { 
  65. return self::get_data( 'products/cf-addons', array( 'per_page' => 50 ) ); 
  66.  
  67. /** 
  68. * Setup each item 
  69. * @since 1.4.8 
  70. * @param stdClass $data API response item 
  71. * @return stdClass 
  72. */ 
  73. protected static function prepare_item( $data ) { 
  74. if ( isset( $data->link ) ) { 
  75. $data->link = add_query_arg( array( 
  76. 'utm_source' => 'wordpress',  
  77. 'utm_medium' => 'extend-page',  
  78. 'utm_term' => 'v' . CFCORE_VER,  
  79. 'utm_campaign' => $data->slug 
  80. ), $data->link ); 
  81.  
  82. /** 
  83. * Specify an Affiliate ID to add to items in extend tab 
  84. * @since 1.4.8 
  85. * @param int|null ID of affiliate 
  86. */ 
  87. $affiliate_id = apply_filters( 'caldera_forms_affiliate_id', null ); 
  88. if ( 0 < absint( $affiliate_id ) ) { 
  89. $data->link = add_query_arg( 'thnx', $affiliate_id, $data->link ); 
  90.  
  91. return $data; 
  92.  
  93.