WC_Admin_Addons

WC_Admin_Addons Class.

Defined (1)

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

/includes/admin/class-wc-admin-addons.php  
  1. class WC_Admin_Addons { 
  2.  
  3. /** 
  4. * Get sections for the addons screen 
  5. * @return array of objects 
  6. */ 
  7. public static function get_sections() { 
  8. if ( false === ( $sections = get_transient( 'wc_addons_sections' ) ) ) { 
  9. $raw_sections = wp_safe_remote_get( 'https://d3t0oesq8995hv.cloudfront.net/addon-sections.json', array( 'user-agent' => 'WooCommerce Addons Page' ) ); 
  10. if ( ! is_wp_error( $raw_sections ) ) { 
  11. $sections = json_decode( wp_remote_retrieve_body( $raw_sections ) ); 
  12.  
  13. if ( $sections ) { 
  14. set_transient( 'wc_addons_sections', $sections, WEEK_IN_SECONDS ); 
  15.  
  16. $addon_sections = array(); 
  17.  
  18. if ( $sections ) { 
  19. foreach ( $sections as $sections_id => $section ) { 
  20. if ( empty( $sections_id ) ) { 
  21. continue; 
  22. $addon_sections[ $sections_id ] = new stdClass; 
  23. $addon_sections[ $sections_id ]->title = wc_clean( $section->title ); 
  24. $addon_sections[ $sections_id ]->endpoint = wc_clean( $section->endpoint ); 
  25.  
  26. return apply_filters( 'woocommerce_addons_sections', $addon_sections ); 
  27.  
  28. /** 
  29. * Get section for the addons screen. 
  30. * @param string $section_id 
  31. * @return object|bool 
  32. */ 
  33. public static function get_section( $section_id ) { 
  34. $sections = self::get_sections(); 
  35. if ( isset( $sections[ $section_id ] ) ) { 
  36. return $sections[ $section_id ]; 
  37. return false; 
  38.  
  39. /** 
  40. * Get section content for the addons screen. 
  41. * @param string $section_id 
  42. * @return array 
  43. */ 
  44. public static function get_section_data( $section_id ) { 
  45. $section = self::get_section( $section_id ); 
  46. $section_data = ''; 
  47.  
  48. if ( ! empty( $section->endpoint ) ) { 
  49. if ( false === ( $section_data = get_transient( 'wc_addons_section_' . $section_id ) ) ) { 
  50. $raw_section = wp_safe_remote_get( esc_url_raw( $section->endpoint ), array( 'user-agent' => 'WooCommerce Addons Page' ) ); 
  51.  
  52. if ( ! is_wp_error( $raw_section ) ) { 
  53. $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); 
  54.  
  55. if ( ! empty( $section_data->products ) ) { 
  56. set_transient( 'wc_addons_section_' . $section_id, $section_data, WEEK_IN_SECONDS ); 
  57.  
  58. return apply_filters( 'woocommerce_addons_section_data', $section_data->products, $section_id ); 
  59.  
  60. /** 
  61. * Handles the outputting of a contextually aware Storefront link (points to child themes if Storefront is already active). 
  62. */ 
  63. public static function output_storefront_button() { 
  64. $template = get_option( 'template' ); 
  65. $stylesheet = get_option( 'stylesheet' ); 
  66.  
  67. if ( 'storefront' === $template ) { 
  68. if ( 'storefront' === $stylesheet ) { 
  69. $url = 'https://woocommerce.com/product-category/themes/storefront-child-theme-themes/'; 
  70. $text = __( 'Need a fresh look? Try Storefront child themes', 'woocommerce' ); 
  71. $utm_content = 'nostorefrontchildtheme'; 
  72. } else { 
  73. $url = 'https://woocommerce.com/product-category/themes/storefront-child-theme-themes/'; 
  74. $text = __( 'View more Storefront child themes', 'woocommerce' ); 
  75. $utm_content = 'hasstorefrontchildtheme'; 
  76. } else { 
  77. $url = 'https://woocommerce.com/storefront/'; 
  78. $text = __( 'Need a theme? Try Storefront', 'woocommerce' ); 
  79. $utm_content = 'nostorefront'; 
  80.  
  81. $url = add_query_arg( array( 
  82. 'utm_source' => 'addons',  
  83. 'utm_medium' => 'product',  
  84. 'utm_campaign' => 'woocommerceplugin',  
  85. 'utm_content' => $utm_content,  
  86. ), $url ); 
  87.  
  88. echo '<a href="' . esc_url( $url ) . '" class="add-new-h2">' . esc_html( $text ) . '</a>' . "\n"; 
  89.  
  90. /** 
  91. * Handles output of the addons page in admin. 
  92. */ 
  93. public static function output() { 
  94. $sections = self::get_sections(); 
  95. $theme = wp_get_theme(); 
  96. $section_keys = array_keys( $sections ); 
  97. $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); 
  98. include_once( 'views/html-admin-page-addons.php' );