class-wc-twenty-eleven.php
5 years ago
class-wc-twenty-fifteen.php
5 years ago
class-wc-twenty-fourteen.php
5 years ago
class-wc-twenty-nineteen.php
5 years ago
class-wc-twenty-seventeen.php
5 years ago
class-wc-twenty-sixteen.php
5 years ago
class-wc-twenty-ten.php
5 years ago
class-wc-twenty-thirteen.php
5 years ago
class-wc-twenty-twelve.php
2 years ago
class-wc-twenty-twenty-one.php
5 years ago
class-wc-twenty-twenty-three.php
3 years ago
class-wc-twenty-twenty-two.php
4 years ago
class-wc-twenty-twenty.php
5 years ago
class-wc-twenty-twenty.php
108 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Twenty Twenty support. |
| 4 | * |
| 5 | * @since 3.8.1 |
| 6 | * @package WooCommerce\Classes |
| 7 | */ |
| 8 | |
| 9 | use Automattic\Jetpack\Constants; |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * WC_Twenty_Twenty class. |
| 15 | */ |
| 16 | class WC_Twenty_Twenty { |
| 17 | |
| 18 | /** |
| 19 | * Theme init. |
| 20 | */ |
| 21 | public static function init() { |
| 22 | |
| 23 | // Change WooCommerce wrappers. |
| 24 | remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); |
| 25 | remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); |
| 26 | |
| 27 | add_action( 'woocommerce_before_main_content', array( __CLASS__, 'output_content_wrapper' ), 10 ); |
| 28 | add_action( 'woocommerce_after_main_content', array( __CLASS__, 'output_content_wrapper_end' ), 10 ); |
| 29 | |
| 30 | // This theme doesn't have a traditional sidebar. |
| 31 | remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 ); |
| 32 | |
| 33 | // Enqueue theme compatibility styles. |
| 34 | add_filter( 'woocommerce_enqueue_styles', array( __CLASS__, 'enqueue_styles' ) ); |
| 35 | |
| 36 | // Register theme features. |
| 37 | add_theme_support( 'wc-product-gallery-zoom' ); |
| 38 | add_theme_support( 'wc-product-gallery-lightbox' ); |
| 39 | add_theme_support( 'wc-product-gallery-slider' ); |
| 40 | add_theme_support( |
| 41 | 'woocommerce', |
| 42 | array( |
| 43 | 'thumbnail_image_width' => 450, |
| 44 | 'single_image_width' => 600, |
| 45 | ) |
| 46 | ); |
| 47 | |
| 48 | // Background color change. |
| 49 | add_action( 'after_setup_theme', array( __CLASS__, 'set_white_background' ), 10 ); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Open the Twenty Twenty wrapper. |
| 55 | */ |
| 56 | public static function output_content_wrapper() { |
| 57 | echo '<section id="primary" class="content-area">'; |
| 58 | echo '<main id="main" class="site-main">'; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Close the Twenty Twenty wrapper. |
| 63 | */ |
| 64 | public static function output_content_wrapper_end() { |
| 65 | echo '</main>'; |
| 66 | echo '</section>'; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Set background color to white if it's default, otherwise don't touch it. |
| 71 | */ |
| 72 | public static function set_white_background() { |
| 73 | $background = sanitize_hex_color_no_hash( get_theme_mod( 'background_color' ) ); |
| 74 | $background_default = 'f5efe0'; |
| 75 | |
| 76 | // Don't change user's choice of background color. |
| 77 | if ( ! empty( $background ) && $background !== $background_default ) { |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | // In case default background is found, change it to white. |
| 82 | set_theme_mod( 'background_color', 'fff' ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Enqueue CSS for this theme. |
| 87 | * |
| 88 | * @param array $styles Array of registered styles. |
| 89 | * @return array |
| 90 | */ |
| 91 | public static function enqueue_styles( $styles ) { |
| 92 | unset( $styles['woocommerce-general'] ); |
| 93 | |
| 94 | $styles['woocommerce-general'] = array( |
| 95 | 'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/twenty-twenty.css', |
| 96 | 'deps' => '', |
| 97 | 'version' => Constants::get_constant( 'WC_VERSION' ), |
| 98 | 'media' => 'all', |
| 99 | 'has_rtl' => true, |
| 100 | ); |
| 101 | |
| 102 | return apply_filters( 'woocommerce_twenty_twenty_styles', $styles ); |
| 103 | } |
| 104 | |
| 105 | } |
| 106 | |
| 107 | WC_Twenty_Twenty::init(); |
| 108 |