-
Notifications
You must be signed in to change notification settings - Fork 134
/
class-llms-twenty-twenty.php
476 lines (399 loc) · 12.4 KB
/
class-llms-twenty-twenty.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<?php
/**
* Theme Support: Twenty Twenty
*
* @package LifterLMS/ThemeSupport/Classes
*
* @since 3.37.0
* @version 4.10.0
*/
defined( 'ABSPATH' ) || exit;
/**
* LLMS_Twenty_Twenty class..
*
* @since 3.37.0
* @since 3.37.1 Fixed course information block misalignment.
* @since 3.37.2 Updated to use `background-color` property instead of `background` shorthand
* when adding custom elements to style.
* @since 3.37.3 Hide site header and footer, and set a white body background in
* single certificates.
*/
class LLMS_Twenty_Twenty {
/**
* Constructor.
*
* @since 3.37.0
*
* @return void
*/
public static function init() {
// This theme doesn't have a sidebar.
remove_action( 'lifterlms_sidebar', 'lifterlms_get_sidebar', 10 );
// Handle content wrappers.
remove_action( 'lifterlms_before_main_content', 'lifterlms_output_content_wrapper', 10 );
remove_action( 'lifterlms_after_main_content', 'lifterlms_output_content_wrapper_end', 10 );
add_action( 'lifterlms_before_main_content', array( __CLASS__, 'output_content_wrapper' ), 10 );
add_action( 'lifterlms_after_main_content', array( __CLASS__, 'output_content_wrapper_end' ), 10 );
// Add the proper Twenty Twenty Body class on the catalogs.
add_filter( 'body_class', array( __CLASS__, 'body_classes' ) );
// Modify catalog & checkout columns when the catalog page isn't full width.
add_filter( 'lifterlms_loop_columns', array( __CLASS__, 'modify_columns_count' ) );
add_filter( 'llms_checkout_columns', array( __CLASS__, 'modify_columns_count' ) );
// Prevent meta output for LifterLMS custom Post Types.
add_filter( 'twentytwenty_disallowed_post_types_for_meta_output', array( __CLASS__, 'hide_meta_output' ) );
add_filter( 'twentytwenty_get_elements_array', array( __CLASS__, 'add_elements' ) );
add_action( 'wp_head', array( __CLASS__, 'add_inline_styles' ), 100 );
}
/**
* Generate inline CSS using colors from the TwenyTwenty Theme settings.
*
* @since 3.37.0
* @since 3.37.1 Fixed course information block misalignment.
* @since 3.37.3 Hide site header and footer, and set a white body background in single certificates.
*
* @return void
*/
public static function add_inline_styles() {
global $post_type;
$accent = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'accent' ) );
?>
<style id="llms-twentytweny-style">
.llms-access-plan.featured .llms-access-plan-content,
.llms-access-plan.featured .llms-access-plan-footer {
border-left-color: <?php echo $accent; ?>;
border-right-color: <?php echo $accent; ?>;
}
.llms-access-plan.featured .llms-access-plan-footer {
border-bottom-color: <?php echo $accent; ?>;
}
.llms-form-field.type-radio input[type=radio]:checked+label:before {
background-image: -webkit-radial-gradient(center,ellipse,<?php echo $accent; ?> 0,<?php echo $accent; ?> 40%,#fafafa 45%);
background-image: radial-gradient(ellipse at center,<?php echo $accent; ?> 0,<?php echo $accent; ?> 40%,#fafafa 45%);
}
.llms-checkout-section,
.llms-lesson-preview section.llms-main {
padding-bottom: 0;
padding-top: 0;
}
.llms-lesson-link .llms-pre-text,
.llms-access-plan .llms-access-plan-title {
margin-top: 0;
}
.llms-donut svg path {
stroke: <?php echo $accent; ?>;
}
.llms-notification,
.llms-instructor-info .llms-instructors .llms-author {
border-top-color: <?php echo $accent; ?>;
}
.llms-pagination ul li:first-of-type,
.llms-pagination ul {
margin-left: 0;
margin-right: 0;
}
.course .llms-meta-info {
margin-left: auto;
margin-right: auto;
}
<?php if ( 'llms_my_certificate' === $post_type || 'llms_certificate' === $post_type ) : ?>
body {
background-color: #fff;
background-image: none;
}
#site-header,
#site-footer {
display: none;
}
<?php endif; ?>
</style>
<?php
}
/**
* Add LifterLMS Elments to the array of Twenty Twenty elements.
*
* This is used to automatically generate inline CSS via the Twenty Twenty Theme.
*
* @since 3.37.0
* @since 3.37.2 Updated to use `background-color` property instead of `background` shorthand.
*
* @param array $elements Multidimensional array of CSS selectors.
* @return array
*/
public static function add_elements( $elements ) {
// Accent Background.
$elements['content']['accent']['background-color'] = array_merge(
$elements['content']['accent']['background-color'],
self::add_elements_content_accent_background()
);
// Accent Border Color.
$elements['content']['accent']['border-color'] = array_merge(
$elements['content']['accent']['border-color'],
self::add_elements_content_accent_border()
);
// Accent Color.
$elements['content']['accent']['color'] = array_merge(
$elements['content']['accent']['color'],
self::add_elements_content_accent_color()
);
// Background Text Color.
$elements['content']['background']['color'] = array_merge(
$elements['content']['background']['color'],
self::add_elements_content_background_color()
);
// Background Background Color.
$elements['content']['background']['background-color'] = array_merge(
$elements['content']['background']['background-color'],
array( '.llms-checkout' )
);
// Text Color.
$elements['content']['text']['color'] = array_merge(
$elements['content']['text']['color'],
array(
'.llms-notice.llms-debug',
'.llms-notice.llms-debug a',
)
);
return $elements;
}
/**
* Get an array of selectors for items that have the accent color as the background.
*
* @since 3.37.0
* @since 4.10.0 Use LLMS_Theme_Support utility classes.
*
* @return string[]
*/
protected static function add_elements_content_accent_background() {
return LLMS_Theme_Support::get_selectors_primary_color_background();
}
/**
* Get an array of selectors for items that have the accent color as the border.
*
* @since 3.37.0
* @since 4.10.0 Use LLMS_Theme_Support utility classes.
*
* @return string[]
*/
protected static function add_elements_content_accent_border() {
return LLMS_Theme_Support::get_selectors_primary_color_border();
}
/**
* Get an array of selectors for items that have the accent color as the text color.
*
* @since 3.37.0
* @since 4.10.0 Use LLMS_Theme_Support utility classes.
*
* @return string[]
*/
protected static function add_elements_content_accent_color() {
return LLMS_Theme_Support::get_selectors_primary_color_text();
}
/**
* Get an array of selectors for items that have the background color as the text color.
*
* @since 3.37.0
*
* @return string[]
*/
protected static function add_elements_content_background_color() {
return array(
// Buttons.
'.llms-button-primary',
'.llms-button-primary:hover',
'.llms-button-primary.clicked',
'.llms-button-primary:focus',
'.llms-button-primary:active',
'.llms-button-action',
'.llms-button-action:hover',
'.llms-button-action.clicked',
'.llms-button-action:focus',
'.llms-button-action:active',
// Pricing Tables.
'.llms-access-plan-title',
'.llms-access-plan .stamp',
'.llms-access-plan.featured .llms-access-plan-featured',
// Checkout.
'.llms-checkout-wrapper .llms-form-heading',
// Notices.
'.llms-notice',
'.llms-notice a',
// My Grades.
'.llms-sd-widgets .llms-sd-widget .llms-sd-widget-title',
);
}
/**
* Add Twenty Twenty's full-width template body class on catalogs where the page is set to use the Full Width template.
*
* @since 3.37.0
*
* @param string[] $classes Array of body classes.
* @return string[]
*/
public static function body_classes( $classes ) {
$page_id = self::get_archive_page_id();
if ( $page_id && self::is_page_full_width( $page_id ) ) {
$classes[] = 'template-full-width';
}
return $classes;
}
/**
* Retrieve the page ID of a a catalog page.
*
* @since 3.37.0
*
* @return int|false
*/
protected static function get_archive_page_id() {
$page_id = false;
if ( is_courses() ) {
$page_id = llms_get_page_id( 'courses' );
} elseif ( is_memberships() ) {
$page_id = llms_get_page_id( 'memberships' );
}
return $page_id;
}
/**
* Get the twenty twenty theme's "width" class for use in wrapper elements.
*
* If the "Full Width" template is utilized, there's no class, otherwise the class `thin` is used.
*
* @since 3.37.0
*
* @return string
*/
protected static function get_page_template_class() {
$template_class = 'thin';
$page_id = self::get_archive_page_id();
if ( $page_id ) {
$template_class = self::is_page_full_width( $page_id ) ? '' : 'thin';
} else {
$template_class = is_page_template( 'templates/template-full-width.php' ) ? '' : 'thin';
}
return $template_class;
}
/**
* Prevent theme meta information from being output on LifterLMS Custom Post Types.
*
* @since 3.37.0
*
* @param string[] $post_types Array of post type names.
* @return string[]
*/
public static function hide_meta_output( $post_types ) {
return array_merge( $post_types, array( 'course', 'llms_membership', 'lesson', 'llms_quiz' ) );
}
/**
* Determine if the given page is utilizing the twenty twenty full-width page template.
*
* @since 3.37.0
*
* @param int $page_id WP_Post ID of the catalog page.
* @return bool
*/
protected static function is_page_full_width( $page_id ) {
return 'templates/template-full-width.php' === get_page_template_slug( $page_id );
}
/**
* Modify the number of catalog & checkout columns.
*
* If the default template is used, drop to a single column.
*
* @since 3.37.0
*
* @param int $cols Number of columns.
* @return int
*/
public static function modify_columns_count( $cols ) {
if ( 'thin' === self::get_page_template_class() ) {
return 1;
}
return $cols;
}
/**
* Output the opening wrapper for the content description element in the theme's header.
*
* @since 3.37.0
*
* @return void
*/
public static function output_archive_description_wrapper() {
echo '<div class="archive-subtitle section-inner thin max-percentage intro-text">';
}
/**
* Output the closing wrapper for the content description element in the theme's header.
*
* @since 3.37.0
*
* @return void
*/
public static function output_archive_description_wrapper_end() {
echo '</div><!-- .archive-subtitle -->';
}
/**
* Output Twenty Twenty theme wrapper openers
*
* @since 3.37.0
*
* @return void
*/
public static function output_content_wrapper() {
$show_title = apply_filters( 'lifterlms_show_page_title', true );
$has_desc = has_action( 'lifterlms_archive_description' );
if ( $has_desc ) {
add_action( 'lifterlms_archive_description', array( __CLASS__, 'output_archive_description_wrapper' ), -1 );
add_action( 'lifterlms_archive_description', array( __CLASS__, 'output_archive_description_wrapper_end' ), 99999999 );
}
if ( $show_title ) {
add_filter( 'lifterlms_show_page_title', '__return_false' );
}
?>
<main id="site-content" role="main">
<?php if ( $show_title || $has_desc ) : ?>
<header class="archive-header has-text-align-center header-footer-group">
<div class="archive-header-inner section-inner medium">
<?php if ( $show_title ) : ?>
<h1 class="archive-title"><?php lifterlms_page_title(); ?></h1>
<?php endif; ?>
<?php endif; ?>
<?php
// If there's no description, output the end wrapper now.
if ( $show_title && ! $has_desc ) {
self::output_content_wrapper_part_two();
} else {
// Otherwise output the wrapper after the end wrapper for the description wrapper div.
add_action( 'lifterlms_archive_description', array( __CLASS__, 'output_content_wrapper_part_two' ), 99999999 );
}
}
/**
* Outputs header closing wrappers and inner element opening wrappers for the theme wrappers.
*
* @since 3.37.0
*
* @return void
*/
public static function output_content_wrapper_part_two() {
?>
</div><!-- .archive-header-inner -->
</header><!-- .archive-header -->
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<div class="post-inner section-inner <?php echo self::get_page_template_class(); ?> ">
<div class="entry-content">
<?php
}
/**
* Output Twenty Twenty theme wrapper closers
*
* @since 3.37.0
*
* @return void
*/
public static function output_content_wrapper_end() {
?>
</div><!-- .entry-content -->
</div><!-- .post-inner -->
</article><!-- .post -->
</main><!-- #site-content -->
<?php
}
}
return LLMS_Twenty_Twenty::init();