-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
747 lines (604 loc) · 19.3 KB
/
functions.php
File metadata and controls
747 lines (604 loc) · 19.3 KB
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
<?php
/**
* The theme's functions file that loads on EVERY page, used for uniform functionality.
*
* @since 0.1.0
* @package RealBigPlugins
*/
// Don't load directly
if ( ! defined( 'ABSPATH' ) ) {
die;
}
// Make sure PHP version is correct
if ( ! version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
wp_die( 'ERROR in RealBigPlugins theme: PHP version 5.3 or greater is required.' );
}
// Make sure no theme constants are already defined (realistically, there should be no conflicts)
if ( defined( 'THEME_VERSION' ) || defined( 'THEME_ID' ) || isset( $theme_fonts ) ) {
wp_die( 'ERROR in Real Big Plugins theme: There is a conflicting constant. Please either find the conflict or rename the constant.' );
}
define( 'EDD_SLUG', 'plugins' );
/**
* Define Constants based on our Stylesheet Header. Update things only once!
*/
$theme_header = wp_get_theme();
define( 'THEME_ID', $theme_header->get( 'TextDomain' ) );
define( 'THEME_VERSION', $theme_header->get( 'Version' ) );
/**
* Fonts for the theme. Must be hosted font (Google fonts for example).
*/
$theme_fonts = array(
'open-sans' => '//fonts.googleapis.com/css?family=Open+Sans:400italic,700,400,800',
'font-awesome' => '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css',
'leckerli-one' => '//fonts.googleapis.com/css?family=Leckerli+One',
);
/**
* Setup theme properties and stuff.
*
* @since 0.1.0
*/
add_action( 'after_setup_theme', function () {
// Add theme support
require_once __DIR__ . '/includes/theme-support.php';
// Allow shortcodes in text widget
add_filter( 'widget_text', 'do_shortcode' );
} );
/**
* Register theme files.
*
* @since 0.1.0
*/
add_action( 'init', function () {
global $theme_fonts;
// Theme styles
wp_register_style(
THEME_ID,
get_template_directory_uri() . '/dist/assets/css/app.css',
null,
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION
);
// Theme script
wp_register_script(
THEME_ID,
get_template_directory_uri() . '/dist/assets/js/script.js',
array( 'jquery' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION,
true
);
// Theme fonts
if ( ! empty( $theme_fonts ) ) {
foreach ( $theme_fonts as $ID => $link ) {
wp_register_style(
THEME_ID . "-font-$ID",
$link
);
}
}
} );
/**
* Enqueue theme files.
*
* @since 0.1.0
*/
add_action( 'wp_enqueue_scripts', function () {
global $theme_fonts;
// Theme styles
wp_enqueue_style( THEME_ID );
// Theme script
wp_enqueue_script( THEME_ID );
// Theme fonts
if ( ! empty( $theme_fonts ) ) {
foreach ( $theme_fonts as $ID => $link ) {
wp_enqueue_style( THEME_ID . "-font-$ID" );
}
}
} );
/**
* Register nav menus.
*
* @since 0.1.0
*/
add_action( 'after_setup_theme', function () {
register_nav_menu( 'primary', 'Primary Menu' );
} );
/**
* Register sidebars.
*
* @since 0.1.0
*/
add_action( 'widgets_init', function () {
// Footer left
register_sidebar( array(
'name' => 'Footer Left',
'id' => 'footer-left',
'description' => 'Displays in the left side of the footer.',
'before_title' => '<h3 class="footer-widget-title">',
'after_title' => '</h3>',
) );
// Footer center
register_sidebar( array(
'name' => 'Footer Center',
'id' => 'footer-center',
'description' => 'Displays in the center of the footer.',
'before_title' => '<h3 class="footer-widget-title">',
'after_title' => '</h3>',
) );
// Footer right
register_sidebar( array(
'name' => 'Footer Right',
'id' => 'footer-right',
'description' => 'Displays in the right side of the footer.',
'before_title' => '<h3 class="footer-widget-title">',
'after_title' => '</h3>',
) );
} );
add_action( 'wp_footer', function () {
if ( ! is_user_logged_in() ) :
?>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-37145568-3', 'auto');
ga('send', 'pageview');
</script>
<?php
endif;
} );
/**
* Setup theme properties and stuff
*
* @since 1.0.0
* @return void
*/
add_action( 'after_setup_theme', function () {
// Add theme support
require_once __DIR__ . '/includes/theme-support.php';
// Add miscellaneous helper functions
require_once __DIR__ . '/includes/theme-functions.php';
// Nav Walker for Foundation
require_once __DIR__ . '/includes/class-foundation_nav_walker.php';
// Walker for Foundation Magellan via wp_list_pages()
require_once __DIR__ . '/includes/class-foundation_magellan_walker.php';
// Allow shortcodes in text widget
add_filter( 'widget_text', 'do_shortcode' );
} );
/**
* Register our CSS/JS
*
* @since 1.0.0
* @return void
*/
add_action( 'init', function() {
global $theme_fonts;
// Theme styles
wp_register_style(
THEME_ID,
get_template_directory_uri() . '/dist/assets/css/style.css',
null,
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION
);
// Login styles
wp_register_style(
THEME_ID . '-login',
get_template_directory_uri() . '/dist/assets/css/login.css',
null,
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION
);
// Theme fonts
if ( ! empty( $theme_fonts ) ) {
foreach ( $theme_fonts as $ID => $link ) {
wp_register_style(
THEME_ID . "-font-$ID",
$link
);
}
}
} );
/**
* Enqueue our CSS/JS on the Frontend
*
* @since 1.0.0
* @return void
*/
add_action( 'wp_enqueue_scripts', function() {
global $theme_fonts;
wp_enqueue_style( THEME_ID );
// Theme fonts
if ( ! empty( $theme_fonts ) ) {
foreach ( $theme_fonts as $ID => $link ) {
wp_enqueue_style( THEME_ID . "-font-$ID" );
}
}
} );
/**
* Enqueue our CSS/JS on the Login Screen
*
* @since 1.0.0
* @return void
*/
add_action( 'login_enqueue_scripts', function() {
wp_enqueue_style( THEME_ID . '-login' );
} );
/**
* Register Nav Menus
*
* @since 1.0.0
* @return void
*/
add_action( 'after_setup_theme', function () {
register_nav_menu( 'primary-left', 'Primary Left Menu' );
register_nav_menu( 'primary-right', 'Primary Right Menu' );
} );
add_action( 'after_setup_theme', function() {
// Add featured image sizes
//
// Sizes are optimized and cropped for landscape aspect ratio
// and optimized for HiDPI displays on 'small' and 'medium' screen sizes.
add_image_size( 'featured-small', 640, 200, true ); // name, width, height, crop
add_image_size( 'featured-medium', 1280, 400, true );
add_image_size( 'featured-large', 1440, 400, true );
add_image_size( 'featured-xlarge', 1920, 400, true );
} );
/**
* Change number of posts per page on download archive page
*
* @param array $query archive query
*
* @since {{ VERSION }}
* @return void
*/
function rbp_download_query( $query ) {
if ( $query->is_post_type_archive( 'download' ) && ! is_admin() && $query->is_main_query() ) {
$query->set( 'posts_per_page', '-1' );
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'rbp_download_query' );
/**
* Run Big Brother scripts only for non-logged in Users
*
* @since 1.0.0
* @return void
*/
add_action( 'wp_footer', function () {
if ( ! is_user_logged_in() ) :
?>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-37145568-3', 'auto');
ga('send', 'pageview');
</script>
<?php
endif;
} );
/**
* Make YouTube videos not show suggested videos at the end
*
* @param string $return HTML
* @param object $data Data Object returned from oEmbed provider
* @param string $url URL String
*
* @since 1.1.0
* @return HTML
*/
add_filter( 'oembed_dataparse', function( $return, $data, $url ) {
if ( $data->provider_name == 'YouTube' ) {
$return = str_replace( '?feature=oembed"', '?feature=oembed&rel=0" class="youtube-embed"', $return );
}
return $return;
}, 10, 3 );
/**
* Register Customizer Controls
* @param object $wp_customize WP Customizer Object
*
* @since 1.1.0
* @return void
*/
add_action( 'customize_register', function( $wp_customize ) {
$wp_customize->add_section( 'rbp_home_section' , array(
'title' => __( 'Home Page Settings', THEME_ID ),
'priority' => 30,
)
);
$wp_customize->add_setting( 'home_background', array(
'default' => 1,
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'home_background', array(
'label' => __( 'Home Page Background', THEME_ID ),
'section' => 'rbp_home_section',
'settings' => 'home_background',
'mime_type' => 'image',
'active_callback' => 'is_front_page',
) ) );
$wp_customize->add_setting( 'home_tagline', array(
'default' => __( 'Quality WordPress Plugins<br />Built With Love', THEME_ID ),
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'home_tagline', array(
'label' => __( 'Home Page Tagline', THEME_ID ),
'section' => 'rbp_home_section',
'settings' => 'home_tagline',
'active_callback' => 'is_front_page',
) ) );
$wp_customize->add_setting( 'home_button_text', array(
'default' => __( 'View Our Plugins', THEME_ID ),
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'home_button_text', array(
'label' => __( 'Home Page Tagline', THEME_ID ),
'section' => 'rbp_home_section',
'settings' => 'home_button_text',
'active_callback' => 'is_front_page',
) ) );
} );
/**
* Conditionally Add Account or Login Links to the Menu
*
* @param string $items The HTML list content for the menu items
* @param object $args An object containing wp_nav_menu() arguments
*
* @since 1.2.1
* @return string The HTML list content for the menu items
*/
add_filter( 'wp_nav_menu_items', 'rbp_conditional_menu_items', 10, 2 );
function rbp_conditional_menu_items( $items, $args ) {
if ( is_user_logged_in() && $args->theme_location == 'primary-right' ) {
$items .= '<li><a href="/checkout/purchase-history/">' . _x( 'My Account', 'My Account Menu Item Text', THEME_ID ) . '</a></li>';
}
else if ( ! is_user_logged_in() && $args->theme_location == 'primary-right' ) {
$items .= '<li><a href="/login/">' . _x( 'Login', 'Login Menu Item Text', THEME_ID ) . '</a></li>';
}
return $items;
}
/**
* Adds MailChimp JS to <head>
*
* @since 1.3.2
* @return void
*/
add_action( 'wp_head', function() {
?>
<script id="mcjs">!function(c,h,i,m,p){m=c.createElement(h),p=c.getElementsByTagName(h)[0],m.async=1,m.src=i,p.parentNode.insertBefore(m,p)}(document,"script","https://chimpstatic.com/mcjs-connected/js/users/82db87321b6e03e3d7c4d9445/91d077eb907a6caf00fcf02d2.js");</script>
<?php
} );
/**
* Google Site Verification
*
* @since 1.3.4
* @return void
*/
add_action( 'wp_head', function() {
?>
<meta name="google-site-verification" content="3Nq8ltyd1lGWOrfOU-TUAmX5hjC6Ap0UMxap8URgK0o" />
<?php
} );
// Include other static files
require_once __DIR__ . '/includes/shortcodes/mailchimp-embed.php';
add_action( 'enqueue_block_assets', function() {
if ( ! is_admin() ) return;
$l10n = apply_filters( 'rbp_gutenberg_l10n', array(
'rbpButton' => array(
'buttonURL' => array(
'label' => __( 'Button URL', 'real-big-plugins' ),
),
'content' => array(
'label' => __( 'Button Text', 'real-big-plugins' ),
'placeholder' => __( 'Your Text Here', 'real-big-plugins' ),
),
'buttonColor' => array(
'label' => __( 'Button Color', 'real-big-plugins' ),
'colors' => array(
array(
'color' => '#12538f',
'name' => 'primary',
),
array(
'color' => '#5b9d1a',
'name' => 'secondary',
),
),
),
'buttonSize' => array(
'label' => __( 'Button Size', 'real-big-plugins' ),
'options' => array(
array(
'label' => __( 'Default', 'real-big-plugins' ),
'value' => '',
),
array(
'label' => __( 'Tiny','real-big-plugins' ),
'value' => 'tiny',
),
array(
'label' => __( 'Medium','real-big-plugins' ),
'value' => 'medium',
),
array(
'label' => __( 'Large','real-big-plugins' ),
'value' => 'large',
),
),
),
'expand' => array(
'label' => __( 'Full width?', 'real-big-plugins' ),
),
'hollow' => array(
'label' => __( 'Hollow/Ghost button?', 'real-big-plugins' ),
),
'invert' => array(
'label' => __( 'White button with colored hover? (Does not show in editor)', 'real-big-plugins' ),
),
'slideDirection' => array(
'label' => __( 'Slide fill animation? (Does not show in editor)', 'real-big-plugins' ),
'options' => array(
array(
'label' => __( 'None', 'real-big-plugins' ),
'value' => '',
),
array(
'label' => __( 'To Left', 'real-big-plugins' ),
'value' => 'left',
),
array(
'label' => __( 'To Right', 'real-big-plugins' ),
'value' => 'right',
),
array(
'label' => __( 'To Top', 'real-big-plugins' ),
'value' => 'top',
),
array(
'label' => __( 'To Bottom', 'real-big-plugins' ),
'value' => 'bottom',
),
)
),
'newTab' => array(
'label' => __( 'Open in a new tab?', 'real-big-plugins' ),
),
),
) );
foreach ( $l10n as $key => $value ) {
if ( ! is_scalar( $value ) )
continue;
$l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
}
$script = "var rbpBlocks = " . wp_json_encode( $l10n ) . ';';
$script = "/* <![CDATA[ */\n" . $script . "\n/* ]]> */";
?>
<script type="text/javascript"><?php echo $script; ?></script>
<?php
} );
add_action( 'init', function() {
// Blocks
require_once( 'includes/blocks/class-rbp-block.php' );
require_once( 'includes/blocks/rbp-button/class-rbp-button-block.php' );
new RBP_Button_Block( trailingslashit( __DIR__ ) . 'includes/blocks/rbp-button/' );
} );
require_once __DIR__ . '/includes/facetwp.php';
add_filter( 'gform_get_form_filter_3', 'realbigplugins_add_form_response_time_notice', 10, 2 );
/**
* Add notice above our Support Form about our hours
*
* @param string $form_string The form markup, including the init scripts (unless the gform_init_scripts_footer filter was used to move them to the footer)
* @param array $form The form currently being processed
*
* @since 1.3.9
* @return string HTML
*/
function realbigplugins_add_form_response_time_notice( $form_html, $form ) {
?>
<div class="callout secondary">
<h4>
Support Turnaround
</h4>
<p>
Support hours are Monday through Friday, 9:00 a.m. to 5:00 p.m. Eastern Time. Tickets are answered in the order in which they are received. Average response time is one business day.
</p>
</div>
<div class="callout info">
<h4>
Gradebook Support
</h4>
<p>
LearnDash has acquired Gradebook, and they have begun providing support as of April 4th of 2023. Real Big Plugins is no longer providing support through this website.
</p>
<p>
Instead, please go to the following links:
<ul>
<li>
<a href="https://www.learndash.com/support/docs/add-ons/gradebook-add-on/" target="_blank">
For documentation
</a>
</li>
<li>
<a href="https://www.learndash.com/help/" target="_blank">
To search support
</a>
</li>
<li>
<a href="https://account.learndash.com/?tab=support" target="_blank">
To create a ticket
</a>
<ul>
<li>
You should be able to log in to their website using the same email address that you used to create an account on <a href="<?php echo esc_attr( site_url() ); ?>">
<?php echo esc_html( site_url() ); ?>
</a>
</li>
</ul>
</li>
</ul>
</p>
</div>
<?php
$callout = ob_get_clean();
return $callout . $form_html;
}
add_action( 'rbp_after_body_open', function() {
?>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-P328K96"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<?php
} );
add_action( 'wp_head', function() {
?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-P328K96');</script>
<!-- End Google Tag Manager -->
<?php
} );
/**
* Enable Gutenberg for Downloads
*
* @since 2.0.0
* @return boolean
*/
add_filter( 'use_block_editor_for_post_type', function( $bool, $post_type ) {
if ( $post_type !== 'download' ) return $bool;
return true;
}, 999, 2 );
/**
* This arg needs to be true for Gutenberg to load
*
* @param array $args Register Post Type Args
* @param string $post_type Post Type
*
* @since 2.0.0
* @return array Register Post Type Args
*/
add_filter( 'register_post_type_args', function( $args, $post_type ) {
if ( $post_type !== 'download' ) return $args;
$args['show_in_rest'] = true;
return $args;
}, 10, 2 );