PluginProbe
Extendify / 0.2.0
Extendify v0.2.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Shared.php

Shared.php in Extendify 0.2.0, at app/Shared.php

299 lines 10.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Manage any shared assets that load within the editor and the front-end.
4 */
5
6 namespace Extendify\Library;
7
8 use Extendify\Library\App;
9
10 /**
11 * This class handles assets that load within the editor and the front-end.
12 */
13 class Shared
14 {
15
16 /**
17 * The instance
18 *
19 * @var $instance
20 */
21 public static $instance = null;
22
23 /**
24 * Current theme
25 *
26 * @var string
27 */
28 // phpcs:ignore
29 private $theme;
30
31 /**
32 * Adds various actions to set up the page
33 *
34 * @return self|void
35 */
36 public function __construct()
37 {
38 if (self::$instance) {
39 return self::$instance;
40 }
41
42 self::$instance = $this;
43
44 // Load only if a compatible theme is active.
45 $this->theme = get_option('template');
46 if (in_array( $this->theme, $this->compatibleThemes(), true )) {
47 $this->loadScripts();
48 }
49 }
50
51 /**
52 * Themes with additional compatibility
53 *
54 * @return array
55 */
56 public function compatibleThemes()
57 {
58 $themes = [
59 'kadence',
60 'neve',
61 'blocksy',
62 'go',
63 'astra',
64 'oceanwp',
65 'generatepress',
66 'twentytwentyone',
67 'twentytwentytwo',
68 'twentytwenty',
69 'twentynineteen',
70 ];
71
72 return $themes;
73 }
74
75 /**
76 * Adds styles to the front-end and editor
77 *
78 * @return void
79 */
80 public function loadScripts()
81 {
82 \add_action(
83 'wp_enqueue_scripts',
84 function () {
85 $this->themeCompatInlineStyles();
86 }
87 );
88
89 \add_action(
90 'admin_enqueue_scripts',
91 function () {
92 $this->themeCompatInlineStyles();
93 }
94 );
95 }
96
97 /**
98 * Inline styles to be applied for compatible themes
99 *
100 * @return void
101 */
102 // phpcs:ignore
103 public function themeCompatInlineStyles()
104 {
105 $css = '';
106
107 if ($this->theme === 'kadence') {
108 $css = 'body, .editor-styles-wrapper {
109 --wp--preset--color--background: var(--global-palette8);
110 --wp--preset--color--foreground: var(--global-palette4);
111 --wp--preset--color--primary: var(--global-palette1);
112 --wp--preset--color--secondary: var(--global-palette2);
113 --wp--preset--color--tertiary: var(--global-palette7);
114 --wp--custom--spacing--large: clamp(var(--global-sm-spacing), 5vw, var(--global-xxl-spacing));
115 --wp--preset--font-size--large: var(--h2FontSize);
116 --wp--preset--font-size--huge: var(--h1FontSize);
117 }';
118 }
119
120 if ($this->theme === 'neve') {
121 $css = 'body, .editor-styles-wrapper {
122 --wp--preset--color--background: var(--nv-site-bg);
123 --wp--preset--color--foreground: var(--nv-text-color);
124 --wp--preset--color--primary: var(--nv-primary-accent);
125 --wp--preset--color--secondary: var(--nv-secondary-accent);
126 --wp--preset--color--tertiary: var(--nv-light-bg);
127 --wp--custom--spacing--large: clamp(15px, 5vw, 80px);
128 --wp--preset--font-size--large: var(--h2FontSize);
129 --wp--preset--font-size--huge: var(--h1FontSize);
130 }';
131 }
132
133 if ($this->theme === 'blocksy') {
134 $css = 'body, .editor-styles-wrapper {
135 --wp--preset--color--background: var(--paletteColor7);
136 --wp--preset--color--foreground: var(--color);
137 --wp--preset--color--primary: var(--paletteColor1);
138 --wp--preset--color--secondary: var(--paletteColor4);
139 }';
140 }
141
142 if ($this->theme === 'go') {
143 $css = 'body, .editor-styles-wrapper {
144 --wp--preset--color--background: var(--go--color--background);
145 --wp--preset--color--foreground: var(--go--color--text);
146 }';
147 }
148
149 if ($this->theme === 'astra') {
150 $css = 'body, .editor-styles-wrapper {
151 --wp--preset--color--background: #ffffff;
152 --wp--preset--color--foreground: var(--ast-global-color-2);
153 --wp--preset--color--primary: var(--ast-global-color-0);
154 --wp--preset--color--secondary: var(--ast-global-color-2);
155 }';
156 }
157
158 if ($this->theme === 'oceanwp') {
159 $background = get_theme_mod( 'ocean_background_color', '#ffffff' );
160 $primary = get_theme_mod( 'ocean_primary_color', '#13aff0' );
161 $secondary = get_theme_mod( 'ocean_hover_primary_color', '#0b7cac' );
162 $gap = get_theme_mod( 'ocean_separate_content_padding', '30px' );
163
164 $css = 'body, .editor-styles-wrapper {
165 --wp--preset--color--background: ' . $background . ';
166 --wp--preset--color--foreground: #1B1B1B;
167 --wp--preset--color--primary: ' . $primary . ';
168 --wp--preset--color--secondary: ' . $secondary . ';
169 --wp--style--block-gap: ' . $gap . ';
170 --wp--custom--spacing--large: clamp(2rem, 7vw, 8rem);
171 }';
172 }
173
174 if ($this->theme === 'generatepress') {
175 $settings = (array) get_option( 'generate_settings', [] );
176
177 if (! array_key_exists( 'background_color', $settings )) {
178 $background = '#f7f8f9';
179 } else {
180 $background = $settings['background_color'];
181 }
182
183 if (! array_key_exists( 'text_color', $settings )) {
184 $foreground = '#222222';
185 } else {
186 $foreground = $settings['text_color'];
187 }
188
189 if (! array_key_exists( 'link_color', $settings )) {
190 $primary = '#1e73be';
191 } else {
192 $primary = $settings['link_color'];
193 }
194
195 if (! array_key_exists( 'link_color', $settings )) {
196 $primary = '#1e73be';
197 } else {
198 $primary = $settings['link_color'];
199 }
200
201 $css = 'body, .editor-styles-wrapper {
202 --wp--preset--color--background: ' . $background . ';
203 --wp--preset--color--foreground: ' . $foreground . ';
204 --wp--preset--color--primary: ' . $primary . ';
205 --wp--preset--color--secondary: #636363;
206 --wp--style--block-gap: 3rem;
207 --wp--custom--spacing--large: clamp(2rem, 7vw, 8rem);
208 --responsive--alignwide-width: 1120px;
209 }';
210 }//end if
211
212 if ($this->theme === 'twentytwentytwo') {
213 $css = 'body, .editor-styles-wrapper {
214 --extendify--spacing--large: clamp(2rem,8vw,8rem);
215 }';
216 }
217
218 if ($this->theme === 'twentytwentyone') {
219 $css = 'body, .editor-styles-wrapper {
220 --wp--preset--color--background: var(--global--color-background);
221 --wp--preset--color--foreground: var(--global--color-primary);
222 --wp--preset--color--primary: var(--global--color-gray);
223 --wp--preset--color--secondary: #464b56;
224 --wp--preset--color--tertiary: var(--global--color-light-gray);
225 --wp--style--block-gap: var(--global--spacing-unit);
226 --wp--preset--font-size--large: 2.5rem;
227 --wp--preset--font-size--huge: var(--global--font-size-xxl);
228 }
229 .has-foreground-background-color,
230 .has-primary-background-color,
231 .has-secondary-background-color {
232 --local--color-primary: var(--wp--preset--color--background);
233 --local--color-background: var(--wp--preset--color--primary);
234 }';
235 }
236
237 if ($this->theme === 'twentytwenty') {
238 $background = sanitize_hex_color_no_hash( get_theme_mod( 'background_color', 'f5efe0' ) );
239 $primary = get_theme_mod(
240 'accent_accessible_colors',
241 [
242 'content' => [ 'accent' => '#cd2653' ],
243 ]
244 );
245 $primary = $primary['content']['accent'];
246 $css = 'body, .editor-styles-wrapper {
247 --wp--preset--color--background: #' . $background . ';
248 --wp--preset--color--foreground: #000;
249 --wp--preset--color--primary: ' . $primary . ';
250 --wp--preset--color--secondary: #69603e;
251 --wp--style--block-gap: 3rem;
252 --wp--custom--spacing--large: clamp(2rem, 7vw, 8rem);
253 --responsive--alignwide-width: 120rem;
254 }';
255 }//end if
256
257 if ($this->theme === 'twentynineteen') {
258 /**
259 * Use the color from Twenty Nineteen's customizer value.
260 */
261 $primary = 199;
262 if (get_theme_mod( 'primary_color', 'default' ) !== 'default') {
263 $primary = absint( get_theme_mod( 'primary_color_hue', 199 ) );
264 }
265
266 /**
267 * Filters Twenty Nineteen default saturation level.
268 *
269 * @since Twenty Nineteen 1.0
270 *
271 * @param int $saturation Color saturation level.
272 */
273 // phpcs:ignore
274 $saturation = apply_filters( 'twentynineteen_custom_colors_saturation', 100 );
275 $saturation = absint( $saturation ) . '%';
276
277 /**
278 * Filters Twenty Nineteen default lightness level.
279 *
280 * @since Twenty Nineteen 1.0
281 *
282 * @param int $lightness Color lightness level.
283 */
284 // phpcs:ignore
285 $lightness = apply_filters( 'twentynineteen_custom_colors_lightness', 33 );
286 $lightness = absint( $lightness ) . '%';
287
288 $css = 'body, .editor-styles-wrapper {
289 --wp--preset--color--foreground: #111;
290 --wp--preset--color--primary: hsl( ' . $primary . ', ' . $saturation . ', ' . $lightness . ' );
291 --wp--preset--color--secondary: #767676;
292 --wp--preset--color--tertiary: #f7f7f7;
293 }';
294 }//end if
295
296 wp_add_inline_style( App::$slug . '-utilities', $css );
297 }
298 }
299