Admin
2 years ago
Assets
2 years ago
Pages
3 years ago
PostTypes
3 years ago
Shortcodes
2 years ago
Sitemap
3 years ago
Templates
2 years ago
Users
3 years ago
ActionsService.php
3 years ago
CompatibilityService.php
2 years ago
HealthService.php
2 years ago
PluginService.php
3 years ago
PluginServiceProvider.php
2 years ago
RecaptchaValidationService.php
2 years ago
ThemeService.php
3 years ago
ThemeServiceProvider.php
3 years ago
TranslationsServiceProvider.php
3 years ago
ThemeService.php
92 lines
| 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 the theme class to the body tag. |
| 21 | add_filter( 'body_class', [ $this, 'themeBodyClass' ] ); |
| 22 | add_filter( 'admin_body_class', [ $this, 'themeBodyClassAdmin' ] ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Add Theme to body class admin. |
| 27 | * |
| 28 | * @param string $classes String of classes. |
| 29 | * |
| 30 | * @return string |
| 31 | */ |
| 32 | public function themeBodyClassAdmin( $classes ) { |
| 33 | global $pagenow; |
| 34 | if ( 'post.php' === $pagenow ) { |
| 35 | $classes .= ' surecart-theme-' . get_option( 'surecart_theme', 'light' ); |
| 36 | } |
| 37 | return $classes; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Add our theme class to the body tag. |
| 42 | * |
| 43 | * @param array $classes Array of body classes. |
| 44 | * |
| 45 | * @return array |
| 46 | */ |
| 47 | public function themeBodyClass( $classes ) { |
| 48 | $classes[] = 'surecart-theme-' . get_option( 'surecart_theme', 'light' ); |
| 49 | return $classes; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Add our color to the palette. |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | public function addColorToPalette() { |
| 58 | // Try to get the current theme default color palette. |
| 59 | $old_color_palette = current( (array) get_theme_support( 'editor-color-palette' ) ); |
| 60 | |
| 61 | // Get default core color palette from wp-includes/theme.json. |
| 62 | if ( false === $old_color_palette && class_exists( 'WP_Theme_JSON_Resolver' ) ) { |
| 63 | $settings = \WP_Theme_JSON_Resolver::get_core_data()->get_settings(); |
| 64 | // wp 6.0+. |
| 65 | if ( isset( $settings['color']['palette']['default'] ) ) { |
| 66 | $old_color_palette = $settings['color']['palette']['default']; |
| 67 | } |
| 68 | // pre wp 6.0. |
| 69 | if ( isset( $settings['color']['palette']['core'] ) ) { |
| 70 | $old_color_palette = $settings['color']['palette']['default']; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // The new colors we are going to add. |
| 75 | $new_color_palette = [ |
| 76 | [ |
| 77 | 'name' => esc_attr__( 'SureCart', 'surecart' ), |
| 78 | 'slug' => 'surecart', |
| 79 | 'color' => 'var(--sc-color-primary-500)', |
| 80 | ], |
| 81 | ]; |
| 82 | |
| 83 | // Merge the old and new color palettes. |
| 84 | if ( ! empty( $old_color_palette ) ) { |
| 85 | $new_color_palette = array_merge( $old_color_palette, $new_color_palette ); |
| 86 | } |
| 87 | |
| 88 | // Apply the color palette containing the original colors and 2 new colors. |
| 89 | add_theme_support( 'editor-color-palette', $new_color_palette ); |
| 90 | } |
| 91 | } |
| 92 |