PluginProbe
Extendify / 0.9.3
Extendify v0.9.3
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 0.7.0 All 126 releases
extendify / app / Library / Shared.php

Shared.php in Extendify 0.9.3, at app/Library/Shared.php

248 lines 9.5 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\Config;
9
10 /**
11 * This class handles assets that load within the editor and the front-end.
12 */
13 class Shared
14 {
15
16 /**
17 * Adds various actions to set up the page
18 *
19 * @return self|void
20 */
21 public function __construct()
22 {
23 \add_action(
24 'wp_enqueue_scripts',
25 function () {
26 $this->themeCompatInlineStyles();
27 }
28 );
29
30 \add_action(
31 'admin_init',
32 function () {
33 $this->themeCompatInlineStyles();
34 }
35 );
36 }
37
38 /**
39 * Inline styles to be applied for compatible themes
40 *
41 * @return void
42 */
43 // phpcs:ignore
44 public function themeCompatInlineStyles()
45 {
46 $css = '';
47 $theme = get_option('template');
48
49 if ($theme === 'kadence') {
50 $css = 'body, .editor-styles-wrapper {
51 --wp--preset--color--background: var(--global-palette8);
52 --wp--preset--color--foreground: var(--global-palette4);
53 --wp--preset--color--primary: var(--global-palette1);
54 --wp--preset--color--secondary: var(--global-palette2);
55 --wp--preset--color--tertiary: var(--global-palette7);
56 --wp--custom--spacing--large: clamp(var(--global-sm-spacing), 5vw, var(--global-xxl-spacing));
57 --wp--preset--font-size--large: var(--h2FontSize);
58 --wp--preset--font-size--huge: var(--h1FontSize);
59 }';
60 }
61
62 if ($theme === 'neve') {
63 $css = 'body, .editor-styles-wrapper {
64 --wp--preset--color--background: var(--nv-site-bg);
65 --wp--preset--color--foreground: var(--nv-text-color);
66 --wp--preset--color--primary: var(--nv-primary-accent);
67 --wp--preset--color--secondary: var(--nv-secondary-accent);
68 --wp--preset--color--tertiary: var(--nv-light-bg);
69 --wp--custom--spacing--large: clamp(15px, 5vw, 80px);
70 --wp--preset--font-size--large: var(--h2FontSize);
71 --wp--preset--font-size--huge: var(--h1FontSize);
72 }';
73 }
74
75 if ($theme === 'blocksy') {
76 $css = 'body, .editor-styles-wrapper {
77 --wp--preset--color--background: var(--paletteColor7);
78 --wp--preset--color--foreground: var(--color);
79 --wp--preset--color--primary: var(--paletteColor1);
80 --wp--preset--color--secondary: var(--paletteColor4);
81 }';
82 }
83
84 if ($theme === 'go') {
85 $css = 'body, .editor-styles-wrapper {
86 --wp--preset--color--background: var(--go--color--background);
87 --wp--preset--color--foreground: var(--go--color--text);
88 }';
89 }
90
91 if ($theme === 'astra') {
92 $css = 'body, .editor-styles-wrapper {
93 --wp--preset--color--background: #ffffff;
94 --wp--preset--color--foreground: var(--ast-global-color-2);
95 --wp--preset--color--primary: var(--ast-global-color-0);
96 --wp--preset--color--secondary: var(--ast-global-color-2);
97 }';
98 }
99
100 if ($theme === 'oceanwp') {
101 $background = get_theme_mod('ocean_background_color', '#ffffff');
102 $primary = get_theme_mod('ocean_primary_color', '#13aff0');
103 $secondary = get_theme_mod('ocean_hover_primary_color', '#0b7cac');
104 $gap = get_theme_mod('ocean_separate_content_padding', '30px');
105
106 $css = 'body, .editor-styles-wrapper {
107 --wp--preset--color--background: ' . $background . ';
108 --wp--preset--color--foreground: #1B1B1B;
109 --wp--preset--color--primary: ' . $primary . ';
110 --wp--preset--color--secondary: ' . $secondary . ';
111 --wp--style--block-gap: ' . $gap . ';
112 --wp--custom--spacing--large: clamp(2rem, 7vw, 8rem);
113 }';
114 }
115
116 if ($theme === 'generatepress') {
117 $settings = (array) get_option('generate_settings', []);
118
119 if (! array_key_exists('background_color', $settings)) {
120 $background = '#f7f8f9';
121 } else {
122 $background = $settings['background_color'];
123 }
124
125 if (! array_key_exists('text_color', $settings)) {
126 $foreground = '#222222';
127 } else {
128 $foreground = $settings['text_color'];
129 }
130
131 if (! array_key_exists('link_color', $settings)) {
132 $primary = '#1e73be';
133 } else {
134 $primary = $settings['link_color'];
135 }
136
137 if (! array_key_exists('link_color', $settings)) {
138 $primary = '#1e73be';
139 } else {
140 $primary = $settings['link_color'];
141 }
142
143 $css = 'body, .editor-styles-wrapper {
144 --wp--preset--color--background: ' . $background . ';
145 --wp--preset--color--foreground: ' . $foreground . ';
146 --wp--preset--color--primary: ' . $primary . ';
147 --wp--preset--color--secondary: #636363;
148 --wp--style--block-gap: 3rem;
149 --wp--custom--spacing--large: clamp(2rem, 7vw, 8rem);
150 --responsive--alignwide-width: 1120px;
151 }';
152 }//end if
153
154 if ($theme === 'twentytwentytwo') {
155 $css = 'body, .editor-styles-wrapper {
156 --extendify--spacing--large: clamp(2rem,8vw,8rem);
157 }';
158 }
159
160 if ($theme === 'twentytwentyone') {
161 $css = 'body, .editor-styles-wrapper {
162 --wp--preset--color--background: var(--global--color-background);
163 --wp--preset--color--foreground: var(--global--color-primary);
164 --wp--preset--color--primary: var(--global--color-gray);
165 --wp--preset--color--secondary: #464b56;
166 --wp--preset--color--tertiary: var(--global--color-light-gray);
167 --wp--style--block-gap: var(--global--spacing-unit);
168 --wp--preset--font-size--large: 2.5rem;
169 --wp--preset--font-size--huge: var(--global--font-size-xxl);
170 }
171 .has-foreground-background-color,
172 .has-primary-background-color,
173 .has-secondary-background-color {
174 --local--color-primary: var(--wp--preset--color--background);
175 --local--color-background: var(--wp--preset--color--primary);
176 }';
177 }
178
179 if ($theme === 'twentytwenty') {
180 $background = sanitize_hex_color_no_hash(get_theme_mod('background_color', 'f5efe0'));
181 $primary = get_theme_mod(
182 'accent_accessible_colors',
183 [
184 'content' => [ 'accent' => '#cd2653' ],
185 ]
186 );
187 $primary = $primary['content']['accent'];
188 $css = 'body, .editor-styles-wrapper {
189 --wp--preset--color--background: #' . $background . ';
190 --wp--preset--color--foreground: #000;
191 --wp--preset--color--primary: ' . $primary . ';
192 --wp--preset--color--secondary: #69603e;
193 --wp--style--block-gap: 3rem;
194 --wp--custom--spacing--large: clamp(2rem, 7vw, 8rem);
195 --responsive--alignwide-width: 120rem;
196 }';
197 }//end if
198
199 if ($theme === 'twentynineteen') {
200 /**
201 * Use the color from Twenty Nineteen's customizer value.
202 */
203 $primary = 199;
204 if (get_theme_mod('primary_color', 'default') !== 'default') {
205 $primary = absint(get_theme_mod('primary_color_hue', 199));
206 }
207
208 /**
209 * Filters Twenty Nineteen default saturation level.
210 *
211 * @since Twenty Nineteen 1.0
212 *
213 * @param int $saturation Color saturation level.
214 */
215 // phpcs:ignore
216 $saturation = apply_filters('twentynineteen_custom_colors_saturation', 100);
217 $saturation = absint($saturation) . '%';
218
219 /**
220 * Filters Twenty Nineteen default lightness level.
221 *
222 * @since Twenty Nineteen 1.0
223 *
224 * @param int $lightness Color lightness level.
225 */
226 // phpcs:ignore
227 $lightness = apply_filters('twentynineteen_custom_colors_lightness', 33);
228 $lightness = absint($lightness) . '%';
229
230 $css = 'body, .editor-styles-wrapper {
231 --wp--preset--color--foreground: #111;
232 --wp--preset--color--primary: hsl( ' . $primary . ', ' . $saturation . ', ' . $lightness . ' );
233 --wp--preset--color--secondary: #767676;
234 --wp--preset--color--tertiary: #f7f7f7;
235 }';
236 }//end if
237
238 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
239 $content = file_get_contents(EXTENDIFY_PATH . 'public/build/extendify-utilities.css');
240 $version = Config::$environment === 'PRODUCTION' ? Config::$version : uniqid();
241 \wp_register_style(Config::$slug . '-utilities', false, [], $version);
242 \wp_enqueue_style(Config::$slug . '-utilities');
243 \wp_add_inline_style(Config::$slug . '-utilities', $content . $css);
244 // Adds inline to the live preview.
245 \wp_add_inline_style('wp-components', $content . $css);
246 }
247 }
248