'WooCommerce Addons Page' ) ); if ( ! is_wp_error( $raw_sections ) ) { $sections = json_decode( wp_remote_retrieve_body( $raw_sections ) ); if ( $sections ) { set_transient( 'wc_addons_sections', $sections, WEEK_IN_SECONDS ); } } } $addon_sections = array(); if ( $sections ) { foreach ( $sections as $sections_id => $section ) { if ( empty( $sections_id ) ) { continue; } $addon_sections[ $sections_id ] = new stdClass; $addon_sections[ $sections_id ]->title = wc_clean( $section->title ); $addon_sections[ $sections_id ]->endpoint = wc_clean( $section->endpoint ); } } return apply_filters( 'woocommerce_addons_sections', $addon_sections ); } /** * Get section for the addons screen. * * @param string $section_id * * @return object|bool */ public static function get_section( $section_id ) { $sections = self::get_sections(); if ( isset( $sections[ $section_id ] ) ) { return $sections[ $section_id ]; } return false; } /** * Get section content for the addons screen. * * @param string $section_id * * @return array */ public static function get_section_data( $section_id ) { $section = self::get_section( $section_id ); $section_data = ''; if ( ! empty( $section->endpoint ) ) { if ( false === ( $section_data = get_transient( 'wc_addons_section_' . $section_id ) ) ) { $raw_section = wp_safe_remote_get( esc_url_raw( $section->endpoint ), array( 'user-agent' => 'WooCommerce Addons Page' ) ); if ( ! is_wp_error( $raw_section ) ) { $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); if ( ! empty( $section_data->products ) ) { set_transient( 'wc_addons_section_' . $section_id, $section_data, WEEK_IN_SECONDS ); } } } } return apply_filters( 'woocommerce_addons_section_data', $section_data->products, $section_id ); } /** * Handles the outputting of a contextually aware Storefront link (points to child themes if Storefront is already active). */ public static function output_storefront_button() { $template = get_option( 'template' ); $stylesheet = get_option( 'stylesheet' ); if ( 'storefront' === $template ) { if ( 'storefront' === $stylesheet ) { $url = 'http:///www.woothemes.com/product-category/themes/storefront-child-theme-themes/'; $text = __( 'Need a fresh look? Try Storefront child themes', 'woocommerce' ); $utm_content = 'nostorefrontchildtheme'; } else { $url = 'http:///www.woothemes.com/product-category/themes/storefront-child-theme-themes/'; $text = __( 'View more Storefront child themes', 'woocommerce' ); $utm_content = 'hasstorefrontchildtheme'; } } else { $url = 'http://www.woothemes.com/storefront/'; $text = __( 'Need a theme? Try Storefront', 'woocommerce' ); $utm_content = 'nostorefront'; } $url = add_query_arg( array( 'utm_source' => 'addons', 'utm_medium' => 'product', 'utm_campaign' => 'woocommerceplugin', 'utm_content' => $utm_content, ), $url ); echo '' . esc_html( $text ) . '' . "\n"; } /** * Handles output of the addons page in admin. */ public static function output() { $sections = self::get_sections(); $theme = wp_get_theme(); $section_keys = array_keys( $sections ); $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); include_once( 'views/html-admin-page-addons.php' ); } }