PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.4.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.4.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / WordPress / ThemeService.php
ThemeService.php
103 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\WordPress;
4
5 use SureCart\Models\Form;
6
7 /**
8 * Register translations.
9 */
10 class ThemeService {
11 /**
12 * Bootstrap the service.
13 *
14 * @param \Pimple\Container $container Service container.
15 * @return void
16 */
17 public function bootstrap() {
18 // add the "Brand" color to the theme's color palette.
19 add_action( 'after_setup_theme', [ $this, 'addColorToPalette' ], 99999 );
20 add_action( 'after_setup_theme', [ $this, 'addAppearanceToolsSupport' ], 99999 );
21 // add the theme class to the body tag.
22 add_filter( 'body_class', [ $this, 'themeBodyClass' ] );
23 add_filter( 'admin_body_class', [ $this, 'themeBodyClassAdmin' ] );
24 }
25
26 /**
27 * Add support for Appearance Tools.
28 *
29 * @return void
30 */
31 public function addAppearanceToolsSupport() {
32 add_theme_support( 'appearance-tools' );
33 add_theme_support( 'border' );
34 }
35
36 /**
37 * Add Theme to body class admin.
38 *
39 * @param string $classes String of classes.
40 *
41 * @return string
42 */
43 public function themeBodyClassAdmin( $classes ) {
44 global $pagenow;
45 if ( 'post.php' === $pagenow ) {
46 $classes .= ' surecart-theme-' . get_option( 'surecart_theme', 'light' );
47 }
48 return $classes;
49 }
50
51 /**
52 * Add our theme class to the body tag.
53 *
54 * @param array $classes Array of body classes.
55 *
56 * @return array
57 */
58 public function themeBodyClass( $classes ) {
59 $classes[] = 'surecart-theme-' . get_option( 'surecart_theme', 'light' );
60 return $classes;
61 }
62
63 /**
64 * Add our color to the palette.
65 *
66 * @return void
67 */
68 public function addColorToPalette() {
69 // Try to get the current theme default color palette.
70 $old_color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
71
72 // Get default core color palette from wp-includes/theme.json.
73 if ( false === $old_color_palette && class_exists( 'WP_Theme_JSON_Resolver' ) ) {
74 $settings = \WP_Theme_JSON_Resolver::get_core_data()->get_settings();
75 // wp 6.0+.
76 if ( isset( $settings['color']['palette']['default'] ) ) {
77 $old_color_palette = $settings['color']['palette']['default'];
78 }
79 // pre wp 6.0.
80 if ( isset( $settings['color']['palette']['core'] ) ) {
81 $old_color_palette = $settings['color']['palette']['default'];
82 }
83 }
84
85 // The new colors we are going to add.
86 $new_color_palette = [
87 [
88 'name' => esc_attr__( 'SureCart', 'surecart' ),
89 'slug' => 'surecart',
90 'color' => 'var(--sc-color-primary-500)',
91 ],
92 ];
93
94 // Merge the old and new color palettes.
95 if ( ! empty( $old_color_palette ) ) {
96 $new_color_palette = array_merge( $old_color_palette, $new_color_palette );
97 }
98
99 // Apply the color palette containing the original colors and 2 new colors.
100 add_theme_support( 'editor-color-palette', $new_color_palette );
101 }
102 }
103