PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
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 / Frontend.php

Frontend.php in Extendify 2.2.0, at app/Library/Frontend.php

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