'WooCommerce Addons Page' ) ); if ( ! is_wp_error( $raw_featured ) ) { $featured = json_decode( wp_remote_retrieve_body( $raw_featured ) ); if ( $featured ) { set_transient( 'wc_addons_featured', $featured, WEEK_IN_SECONDS ); } } } if ( is_object( $featured ) ) { self::output_featured_sections( $featured->sections ); return $featured; } } /** * Get sections for the addons screen * * @return array of objects */ public static function get_sections() { if ( false === ( $sections = get_transient( 'wc_addons_sections' ) ) ) { $raw_sections = wp_safe_remote_get( 'https://d3t0oesq8995hv.cloudfront.net/addon-sections.json', array( 'user-agent' => '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 = 'https://woocommerce.com/product-category/themes/storefront-child-theme-themes/'; $text = __( 'Need a fresh look? Try Storefront child themes', 'woocommerce' ); $utm_content = 'nostorefrontchildtheme'; } else { $url = 'https://woocommerce.com/product-category/themes/storefront-child-theme-themes/'; $text = __( 'View more Storefront child themes', 'woocommerce' ); $utm_content = 'hasstorefrontchildtheme'; } } else { $url = 'https://woocommerce.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 the outputting of a banner block. * * @param object $block */ public static function output_banner_block( $block ) { ?>

title ); ?>

description ); ?>

items as $item ) : ?>

title ); ?>

description ); ?>

href, $item->button, 'addons-button-solid', $item->plugin ); ?>
container ) && 'column_container_start' === $block->container ) { ?>
module ) { ?>
container ) && 'column_container_end' === $block->container ) { ?>

title ); ?>

description ); ?>

items as $item ) : ?>

title ); ?>

href, $item->button, 'addons-button-solid', $item->plugin ); ?>

description ); ?>

title ); ?>

description ); ?>

buttons as $button ) : ?> href, $button->text, 'addons-button-solid' ); ?>

title ); ?>

description ); ?>

items as $item ) : ?>
image ) ) : ?>
href, $item->button, 'addons-button-outline-white' ); ?>
'woocommerce-services', ) ), 'install-addon_woocommerce-services' ); $defaults = array( 'image' => WC()->plugin_url() . '/assets/images/wcs-extensions-banner-3x.png', 'image_alt' => __( 'WooCommerce Services', 'woocommerce' ), 'title' => __( 'Buy discounted shipping labels, print them from your dashboard.', 'woocommerce' ), 'description' => __( 'WooCommerce Services makes shipping a breeze. Get discounted rates and print labels – all from the convenience of your WordPress dashboard.', 'woocommerce' ), 'button' => __( 'Free - Install now', 'woocommerce' ), 'href' => $button_url, ); $block_data = wp_parse_args( $block, $defaults ); ?>
<?php echo esc_attr( $block_data['image_alt'] ); ?>

module ) { case 'banner_block': self::output_banner_block( $section ); break; case 'column_start': self::output_column( $section ); break; case 'column_end': self::output_column( $section ); break; case 'column_block': self::output_column_block( $section ); break; case 'small_light_block': self::output_small_light_block( $section ); break; case 'small_dark_block': self::output_small_dark_block( $section ); break; case 'wcs_banner_block': self::output_wcs_banner_block( $section ); break; } } } /** * Outputs a button. * * @param string $url * @param string $text * @param string $theme * @param string $plugin */ public static function output_button( $url, $text, $theme, $plugin = '' ) { $theme = __( 'Free', 'woocommerce' ) === $text ? 'addons-button-outline-green' : $theme; $theme = is_plugin_active( $plugin ) ? 'addons-button-installed' : $theme; $text = is_plugin_active( $plugin ) ? __( 'Installed', 'woocommerce' ) : $text; ?> __( 'WooCommerce Services', 'woocommerce' ), 'repo-slug' => 'woocommerce-services', ); WC_Install::background_installer( $services_plugin_id, $services_plugin ); wp_safe_redirect( remove_query_arg( array( 'install-addon', '_wpnonce' ) ) ); exit; } }