Completed
Push — master ( 15aa29...17da96 )
by Claudio
18:39 queued 11s
created

theme-support/class-wc-twenty-nineteen.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Twenty Nineteen support.
4
 *
5
 * @since   3.5.X
6
 * @package WooCommerce/Classes
7
 */
8
9
defined( 'ABSPATH' ) || exit;
10
11
/**
12
 * WC_Twenty_Nineteen class.
13
 */
14
class WC_Twenty_Nineteen {
15
16
	/**
17
	 * Theme init.
18
	 */
19
	public static function init() {
20
21
		// Change WooCommerce wrappers.
22
		remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
23
		remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
24
25
		add_action( 'woocommerce_before_main_content', array( __CLASS__, 'output_content_wrapper' ), 10 );
26
		add_action( 'woocommerce_after_main_content', array( __CLASS__, 'output_content_wrapper_end' ), 10 );
27
28
		// This theme doesn't have a traditional sidebar.
29
		remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
30
31
		// Enqueue theme compatibility styles.
32
		add_filter( 'woocommerce_enqueue_styles', array( __CLASS__, 'enqueue_styles' ) );
33
34
		// Register theme features.
35
		add_theme_support( 'wc-product-gallery-zoom' );
36
		add_theme_support( 'wc-product-gallery-lightbox' );
37
		add_theme_support( 'wc-product-gallery-slider' );
38
		add_theme_support( 'woocommerce', array(
39
			'thumbnail_image_width' => 300,
40
			'single_image_width'    => 450,
41
		) );
42
43
		// Tweak Twenty Nineteen features.
44
		add_action( 'wp', array( __CLASS__, 'tweak_theme_features' ) );
45
46
		// Color scheme CSS
47
		add_filter( 'twentynineteen_custom_colors_css', array( __CLASS__, 'custom_colors_css' ), 10, 3 );
48
	}
49
50
	/**
51
	 * Open the Twenty Nineteen wrapper.
52
	 */
53
	public static function output_content_wrapper() {
54
		echo '<section id="primary" class="content-area">';
55
		echo '<main id="main" class="site-main">';
56
	}
57
58
	/**
59
	 * Close the Twenty Nineteen wrapper.
60
	 */
61
	public static function output_content_wrapper_end() {
62
		echo '</main>';
63
		echo '</section>';
64
	}
65
66
	/**
67
	 * Enqueue CSS for this theme.
68
	 *
69
	 * @param  array $styles Array of registered styles.
70
	 * @return array
71
	 */
72 View Code Duplication
	public static function enqueue_styles( $styles ) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
		unset( $styles['woocommerce-general'] );
74
75
		$styles['woocommerce-general'] = array(
76
			'src'     => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/twenty-nineteen.css',
77
			'deps'    => '',
78
			'version' => WC_VERSION,
79
			'media'   => 'all',
80
			'has_rtl' => true,
81
		);
82
83
		return apply_filters( 'woocommerce_twenty_nineteen_styles', $styles );
84
	}
85
86
	/**
87
	 * Tweak Twenty Nineteen features.
88
	 */
89
	public static function tweak_theme_features() {
90
		if ( is_woocommerce() ) {
91
			add_filter( 'twentynineteen_can_show_post_thumbnail', '__return_false' );
92
		}
93
	}
94
95
	/**
96
	 * Filters Twenty Nineteen custom colors CSS.
97
	 *
98
	 * @param string $css           Base theme colors CSS.
99
	 * @param int    $primary_color The user's selected color hue.
100
	 * @param string $saturation    Filtered theme color saturation level.
101
	 */
102
	public static function custom_colors_css( $css, $primary_color, $saturation ) {
103
		if ( function_exists( 'register_block_type' ) && is_admin() ) {
104
			return $css;
105
		}
106
107
		$lightness = absint( apply_filters( 'twentynineteen_custom_colors_lightness', 33 ) );
108
		$lightness = $lightness . '%';
109
110
		$css .= '
111
			.onsale,
112
			.woocommerce-info,
113
			.woocommerce-store-notice {
114
				background-color: hsl( ' . $primary_color . ', ' . $saturation . ', ' . $lightness . ' );
115
			}
116
117
			.woocommerce-tabs ul li.active a {
118
				color: hsl( ' . $primary_color . ', ' . $saturation . ', ' . $lightness . ' );
119
				box-shadow: 0 2px 0 hsl( ' . $primary_color . ', ' . $saturation . ', ' . $lightness . ' );
120
			}
121
		';
122
123
		return $css;
124
	}
125
}
126
127
WC_Twenty_Nineteen::init();
128