Admin
2 years ago
Assets
2 years ago
Pages
3 years ago
PostTypes
2 years ago
Shortcodes
2 years ago
Sitemap
2 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
LineItemStateService.php
2 years ago
PluginService.php
3 years ago
PluginServiceProvider.php
2 years ago
RecaptchaValidationService.php
2 years ago
StateService.php
2 years ago
ThemeService.php
2 years ago
ThemeServiceProvider.php
3 years ago
TranslationsServiceProvider.php
3 years ago
ThemeService.php
103 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_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 |