functions.php
26.8 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
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
<?php
error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
@ini_set( 'upload_max_size' , '64M' );
@ini_set( 'post_max_size', '64M');
@ini_set( 'max_execution_time', '300' );
require_once __DIR__ . '/vendor/autoload.php';
require_once 'inc/users.php';
require_once 'inc/learn.php';
require_once 'inc/menus_widgets.php';
require_once 'inc/custom_post_type.php';
add_action('wp_enqueue_scripts', 'theme_broker_enqueue_scripts');
function theme_broker_enqueue_scripts()
{
if (
is_page_template("broker_landing_page.php")
|| is_page_template("broker_pages.php")
|| is_page_template("default.php")
|| is_page_template("SearchWpResult.php")
|| is_page_template("SearchWp.php")
|| is_page_template("broker_notifications_archive.php")
|| is_page_template("broker_account_pages.php")
|| is_page_template("marketing_masters.php")
|| get_post_type() == 'notifications'
|| get_post_type() == 'sfwd-courses'
|| get_post_type() == 'sfwd-lessons'
|| get_post_type() == 'sfwd-quiz'
|| get_post_type() == 'badges'
) {
wp_enqueue_style('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css');
wp_enqueue_style('fontawsome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css');
wp_enqueue_style('Material', 'https://fonts.googleapis.com/icon?family=Material+Icons');
wp_enqueue_style('bxslider', get_bloginfo('template_url') . '/styles/vendor/jquery.bxslider.css');
wp_enqueue_script( 'bxslider', get_bloginfo('template_url') . '/scripts/vendor/jquery.bxslider.js',[], "0.0.1", true );
wp_enqueue_script('cookies', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js');
wp_enqueue_script('moblie_menu', get_bloginfo('template_url') . '/scripts/moblie_menu.js');
wp_enqueue_script('jQmobile', get_bloginfo('template_url') . '/scripts/vendor/jquery.mobile.custom.min.js');
wp_enqueue_script('colorbox', '//cdnjs.cloudflare.com/ajax/libs/jquery.colorbox/1.6.4/jquery.colorbox.js');
wp_enqueue_script('bootstrap','https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js',[], false, true );
wp_enqueue_script('jquery-ui', get_bloginfo('template_url') . '/scripts/jquery-ui.min.js', [], false, true);
// qTip
wp_enqueue_style('qtip', get_bloginfo('template_url') . '/styles/vendor/jquery.qtip.css');
wp_enqueue_script('qtip', get_bloginfo('template_url') . '/scripts/vendor/jquery.qtip.js', [], "0.0.1", true);
wp_enqueue_style('jqdataTables', 'https://cdn.datatables.net/1.10.18/css/dataTables.bootstrap.min.css');
wp_enqueue_script('jqdataTables', 'https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTables', 'https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablesbuttons', 'https://cdn.datatables.net/buttons/1.7.0/js/dataTables.buttons.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablesbuttonshtml5', 'https://cdn.datatables.net/buttons/1.7.0/js/buttons.html5.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablespdf', 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablesbuttonsfonts', 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js', [], "0.0.1", true);
wp_enqueue_script('bsdataTablesbuttonszip', 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js', [], "0.0.1", true);
// Tooltipster
wp_enqueue_style('tooltipster', get_bloginfo('template_url') . '/styles/vendor/tooltipster.bundle.min.css');
wp_enqueue_script( 'tooltipster', get_bloginfo('template_url') . '/scripts/vendor/tooltipster.bundle.min.js',[], "0.0.1",true );
wp_enqueue_script('show-more', get_bloginfo('template_url') . '/scripts/show-more.js', [], "0.0.3", true);
wp_enqueue_script('accessibility_script', get_bloginfo('template_url') . '/scripts/accessibility.js', true);
wp_enqueue_style('input_skins', get_bloginfo('template_url') . '/styles/input_skins/all.css', [], "0.0.61");
wp_enqueue_script('icheck', get_bloginfo('template_url') . '/scripts/icheck.min.js', [], "0.0.1", true);
wp_enqueue_script('script', get_bloginfo('template_url') . '/scripts/script.js', [], "0.11", true);
}
if (
is_page_template("broker_landing_page.php")
|| is_page_template("default.php")
|| is_page_template("broker_notifications_archive.php")
|| is_page_template("broker_account_pages.php")
|| get_post_type() == 'notifications'
) {
wp_enqueue_style('global', get_bloginfo('template_url') . '/styles/brokers/landing-page/broker_landing.css', [], "0.0.67");
wp_enqueue_style('broker_new', get_bloginfo('template_url') . '/styles/broker_new.css', [], "0.0.72");
wp_enqueue_script('script', get_bloginfo('template_url') . '/scripts/script.js', [], "0.0.12", true);
wp_enqueue_style('main', get_bloginfo('template_url') . '/styles/main.css', [], "0.0.830");
}
if (
is_page_template("broker_landing_page.php")
|| is_page_template("broker_pages.php")
|| is_page_template("default.php")
|| is_page_template("SearchWpResult.php")
|| is_page_template("SearchWp.php")
|| is_page_template("broker_notifications_archive.php")
|| is_page_template("broker_account_pages.php")
|| is_page_template("marketing_masters.php")
|| get_post_type() == 'notifications'
|| get_post_type() == 'sfwd-courses'
|| get_post_type() == 'sfwd-lessons'
|| get_post_type() == 'sfwd-quiz'
|| get_post_type() == 'badges'
) {
wp_enqueue_style('global', get_bloginfo('template_url') . '/styles/brokers/secondary-page/broker.css', array(), '0.0.64');
wp_enqueue_style('broker_new', get_bloginfo('template_url') . '/styles/broker_new.css', [], "0.0.7");
}
if (
is_page_template("broker_landing_page.php")
|| is_page_template("broker_pages.php")
|| is_page_template("default.php")
|| is_page_template("SearchWpResult.php")
|| is_page_template("broker_notifications_archive.php")
|| is_page_template("broker_account_pages.php")
|| is_page_template("marketing_masters.php")
|| get_post_type() == 'notifications'
|| get_post_type() == 'sfwd-courses'
|| get_post_type() == 'sfwd-lessons'
|| get_post_type() == 'sfwd-quiz'
|| get_post_type() == 'badges'
) {
wp_enqueue_style('mobile_menu', get_bloginfo('template_url') . '/styles/brokers/mobile/broker_moblie_menu.css');
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_script('jquery-ui-position');
}
if (is_page_template("badge-share.php"))
{
wp_enqueue_script('sharerbox', get_bloginfo('template_url') . '/scripts/sharerbox.js', [], false, true);
}
}
function wp_disable_emojis()
{
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
add_filter('tiny_mce_plugins', 'disable_emojis_tinymce');
add_filter('wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2);
}
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles(){
if ( ! is_user_logged_in() ) {
wp_deregister_style( 'dashicons' );
}
}
add_action('init', 'wp_disable_emojis');
add_filter('the_content', 'attachment_image_link_remove_filter');
function attachment_image_link_remove_filter($content)
{
$content =
preg_replace(
array(
'{<a(.*?)(wp-att|wp-content/uploads)[^>]*><img}',
'{ wp-image-[0-9]*" /></a>}',
),
array('<img', '" />'),
$content
);
return $content;
}
/**
* WP: Unwrap images from <p> tag
* @param $content
* @return mixed
*/
function so226099_filter_p_tags_on_images($content)
{
$content = preg_replace('/<p>\\s*?(<a .*?><img.*?>
<\\/a>| <img.*?>)?\\s*<\\/p>/s', '\1', $content);
return $content;
}
add_filter('the_content', 'so226099_filter_p_tags_on_images'); //Add Featured Image Support add_theme_support('post-thumbnails'); // Clean up the <head>
function removeHeadLinks()
{
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
}
add_action('init', 'removeHeadLinks');
remove_action('wp_head', 'wp_generator');
add_theme_support( 'post-thumbnails' );
add_theme_support('custom-header');
add_action('admin_head', 'my_custom_css');
function my_custom_css() {
echo '<style>
.ui-widget.ui-widget-content{
z-index: 99999;
}
</style>';
}
/**
* To login with either username or Email address
*/
add_filter('authenticate', 'bainternet_allow_email_login', 20, 3);
/**
* bainternet_allow_email_login filter to the authenticate filter hook, to fetch a username based on entered email
*
* @param obj $user
* @param string $username [description]
* @param string $password [description]
*
* @return boolean
*/
function bainternet_allow_email_login($user, $username, $password)
{
if (is_email($username)) {
$user = get_user_by_email($username);
if ($user) {
$username = $user->user_login;
}
}
return wp_authenticate_username_password(null, $username, $password);
}
add_filter('gettext', 'addEmailToLogin', 20, 3);
/**
* addEmailToLogin function to add email address to the username label
*
* @param string $translated_text translated text
* @param string $text original text
* @param string $domain text domain
*/
function addEmailToLogin($translated_text, $text, $domain)
{
if ("Username" == $translated_text) {
$translated_text .= __(' Or Email');
}
return $translated_text;
}
function send_headers()
{
if (is_user_logged_in() && is_page(399)) {
wp_redirect(get_permalink(6104));
exit;
}
}
add_action('template_redirect', 'send_headers');
/**
* Redirect always homepage after logout
*/
add_filter('logout_url', 'projectivemotion_logout_home', 10, 2);
function projectivemotion_logout_home($logouturl, $redir)
{
$redir = get_option('siteurl');
return $logouturl . '&redirect_to=' . urlencode($redir);
}
add_filter('mandrill_payload', 'sendEmailThroughMandrillSubaccount', 100);
function sendEmailThroughMandrillSubaccount(array $message)
{
$message['subaccount'] = 'Thecommonwell';
return $message;
}
add_filter('wp_mail_from_name', 'custom_wp_mail_from_name');
function custom_wp_mail_from_name($original_email_from)
{
return 'The Commonwell';
}
add_action('wp_ajax_nopriv_ajax-callback', 'ajax_callback');
add_action('wp_ajax_ajax-callback', 'ajax_callback');
add_action('init', 'handle_preflight');
function handle_preflight()
{
header("Access-Control-Allow-Origin: * ");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
// header("Access-Control-Allow-Credentials: true");
if ('OPTIONS' == $_SERVER['REQUEST_METHOD']) {
status_header(200);
exit();
}
}
/**
* Remove roles
*
* Author, Editor, Contributor
*
*/
$wp_roles = new WP_Roles();
$wp_roles->remove_role("author");
$wp_roles->remove_role("editor");
$wp_roles->remove_role("contributor");
add_role(
'cwl_staff', __('CWL Staff'),
array(
'read' => true, // Allows user to read
'create_posts' => true, // Allows user to create new posts
'edit_posts' => true, // Allows user to edit their own posts
)
);
/*
* Creating a function to create our CPT
*/
add_action('after_setup_theme', 'ja_theme_setup');
function ja_theme_setup()
{
add_theme_support('post-thumbnails', array('post', 'notifications'));
}
function enable_extended_upload($mime_types = array())
{
$mime_types['gz'] = 'application/x-gzip';
$mime_types['zip'] = 'application/zip';
$mime_types['rtf'] = 'application/rtf';
$mime_types['ppt'] = 'application/mspowerpoint';
$mime_types['ps'] = 'application/postscript';
$mime_types['flv'] = 'video/x-flv';
$mime_types['svg'] = 'image/svg+xml';
$mime_types['xlsm'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
unset($mime_types['exe']);
unset($mime_types['bin']);
return $mime_types;
}
add_filter('upload_mimes', 'enable_extended_upload');
add_action('admin_menu', 'add_broker_options');
function add_broker_options()
{
add_options_page('Broker Options', 'Broker Options', 'manage_options', 'functions', 'broker_options');
add_settings_field('Info Message', 'Info Message', 'broker_info_message', __FILE__, 'main_section');
add_settings_field('No Team Meassage', 'No Team Meassage', 'no_team_message', __FILE__, 'main_section');
}
function broker_options()
{
?>
<div class="wrap">
<h2>Broker Options</h2>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options')?>
<p><strong>Info Message</strong><br />
<textarea type="textarea" name="broker_info_message" rows="10" cols="100">
<?php echo get_option('broker_info_message'); ?>
</textarea>
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="broker_info_message" />
</form>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options')?>
<p><strong>No Team Meassage</strong><br />
<textarea type="textarea" name="no_team_message" rows="10" cols="100">
<?php echo get_option('no_team_message'); ?>
</textarea>
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="no_team_message" />
</form>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options')?>
<p><strong>Fall Back Team</strong><br />
<input type="text" name="fall_back_team" value="<?php echo get_option('fall_back_team'); ?>" rows="10" cols="100">
</textarea>
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="fall_back_team" />
</form>
</div>
<?php
}
add_action("wp_ajax_seen_urgent_note", "seen_urgent_note");
function seen_urgent_note()
{
$user_id = get_current_user_id();
update_user_meta($user_id, 'seen_urgent_note', $_REQUEST["note_id"], false);
}
function my_searchwp_xpdf_path()
{
return '/usr/bin/pdftotext'; // path to the binary NOT A FOLDER
}
add_filter('searchwp_xpdf_path', 'my_searchwp_xpdf_path');
function my_force_direct_pdf_links($permalink)
{
global $post;
if (is_search() && 'application/pdf' == get_post_mime_type($post->ID)) {
// if the result is a PDF, link directly to the file not the attachment page
$permalink = wp_get_attachment_url($post->ID);
}
return esc_url($permalink);
}
add_filter('the_permalink', 'my_force_direct_pdf_links');
add_filter('attachment_link', 'my_force_direct_pdf_links');
/**
* @return array|mixed
*/
function getBrokerageList()
{
$brokerList = get_option('broker_list') ? unserialize(get_option('broker_list')) : [];
// Sort it by broker name
usort($brokerList, function ($a, $b) {
if ($a['brokerage'] == $b['brokerage']) {
return 0;
}
return ($a['brokerage'] < $b['brokerage']) ? -1 : 1;
});
return $brokerList;
}
function custom_pagination($numpages = '', $pagerange = '', $paged = '')
{
if (empty($pagerange)) {
$pagerange = 2;
}
/**
* This first part of our function is a fallback
* for custom pagination inside a regular loop that
* uses the global $paged and global $wp_query variables.
*
* It's good because we can now override default pagination
* in our theme, and use this function in default quries
* and custom queries.
*/
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if (!$numpages) {
$numpages = 1;
}
}
/**
* We construct the pagination arguments to enter into our paginate_links
* function.
*/
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => false,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => true,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => '',
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='custom-pagination'>";
// echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
}
add_shortcode("WaveButton", "WaveButton");
function WaveButton()
{
$button = '<div class="promer-banner-cont">';
$button .= '<div class="promer-banner">';
//$button .= '<div class="promer-text">GIVE “WAVE” A TRY</div>';
$button .= '<div class="promer-button" style="transform: matrix(1, 0, 0, 1, 0, 0);"><a href="http://rating.thecommonwell.ca" class="rating-engine-link-button" target="_blank">COMMERCIAL RATING TOOL</a></div></div></div>';
return $button;
}
// Hide admin bar for broker
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar()
{
if (current_user_can('subscriber')) {
show_admin_bar(false);
}
}
// localize wp-ajax, notice the path to our theme-ajax.js file
wp_enqueue_script('rsclean-request-script', get_stylesheet_directory_uri() . '/scripts/src/theme-ajax.js', array('jquery'));
wp_localize_script('rsclean-request-script', 'theme_ajax', array(
'url' => admin_url('admin-ajax.php'),
'site_url' => get_bloginfo('url'),
'theme_url' => get_bloginfo('template_directory'),
));
function get_custom_mail($args)
{
// Modify the options here
$template = get_mail_template();
$output = str_replace("[url]", get_template_directory_uri(), $template);
$output1 = str_replace("[title]", $args["subject"], $output);
$output2 = str_replace("[content]", $args["html"], $output1);
$custom_mail = array(
'to' => $args['to'],
'subject' => $args['subject'],
'html' => $output2,
'headers' => $args['headers'],
'attachments' => $args['attachments'],
);
// Return the value to the original function to send the email
return $custom_mail;
}
//add_filter('wp_mail', 'get_custom_mail');
function get_mail_template()
{
include( get_stylesheet_directory() . '/' . '/mail_template.php');
}
function custom_login_stylesheet()
{
wp_enqueue_style('custom-login', get_stylesheet_directory_uri() . '/style.css');
}
add_action('login_enqueue_scripts', 'custom_login_stylesheet');
function getMemberOfGroup($group_id)
{
// initiaze curl which is used to make the http request.
$available_members = get_users(
array(
'meta_query' => array(
array(
'key' => 'group_id',
'value' => $group_id,
'compare' => '=',
),
),
)
);
foreach ($available_members as $available_member) {
$user_info[] = get_user_meta($available_member->ID);
}
// There is a field for odata metadata that we ignore and just consume the value
return $user_info;
}
add_action('delete_attachment', 'DontDeleteMedia', 11, 1);
function DontDeleteMedia($postID)
{
//exit('You cannot delete media.');
}
//P.S. That was a long train ride! Lol
/**
* Disable the emoji's
*/
function disable_emojis()
{
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
add_filter('tiny_mce_plugins', 'disable_emojis_tinymce');
add_filter('wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2);
}
add_action('init', 'disable_emojis');
/**
* Filter function used to remove the tinymce emoji plugin.
*
* @param array $plugins
* @return array Difference betwen the two arrays
*/
function disable_emojis_tinymce($plugins)
{
if (is_array($plugins)) {
return array_diff($plugins, array('wpemoji'));
} else {
return array();
}
}
/**
* Remove emoji CDN hostname from DNS prefetching hints.
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed for.
* @return array Difference betwen the two arrays.
*/
function disable_emojis_remove_dns_prefetch($urls, $relation_type)
{
if ('dns-prefetch' == $relation_type) {
/** This filter is documented in wp-includes/formatting.php */
$emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/');
$urls = array_diff($urls, array($emoji_svg_url));
}
return $urls;
}
add_shortcode('add_hr', 'add_hr_shortcode');
function add_hr_shortcode()
{
ob_start();?>
<div class="hr"></div>
<?php return ob_get_clean();
}
add_action('wp_logout', 'remove_custom_cookie_admin');
function remove_custom_cookie_admin()
{
setcookie('dialog_cookie', '', time() - 96400, '/');
}
if (!function_exists('str_contains')) {
function str_contains(string $haystack, string $needle): bool
{
return '' === $needle || false !== strpos($haystack, $needle);
}
}
if (!function_exists('str_starts_with')) {
function str_starts_with(string $haystack, string $needle): bool {
return \strncmp($haystack, $needle, \strlen($needle)) === 0;
}
}
if (!function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle): bool {
return $needle === '' || $needle === \substr($haystack, - \strlen($needle));
}
}
add_filter('manage_posts_columns', 'posts_columns_id', 5);
add_action('manage_posts_custom_column', 'posts_custom_id_columns', 5, 2);
add_filter('manage_pages_columns', 'posts_columns_id', 5);
add_action('manage_pages_custom_column', 'posts_custom_id_columns', 5, 2);
function posts_columns_id($defaults){
$defaults['wps_post_id'] = __('ID');
return $defaults;
}
function posts_custom_id_columns($column_name, $id){
if($column_name === 'wps_post_id'){
echo $id;
}
}
add_action( 'wp', 'prefix_setup_schedule' );
/**
* On an early action hook, check if the hook is scheduled - if not, schedule it.
*/
function prefix_setup_schedule() {
if ( ! wp_next_scheduled( 'prefix_daily_event' ) ) {
wp_schedule_event( time(), 'daily', 'prefix_daily_event');
}
}
function get_excerpt($limit, $source = null){
$excerpt = $source == "content" ? get_the_content() : get_the_excerpt();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$strlen = strlen($excerpt) ;
if( $strlen <= $limit){
return $excerpt;
}
$excerpt = substr($excerpt, 0, $limit);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = $excerpt.'... <a class="share_read_more" data-id="'.get_the_ID().'" href="javascript:void(0);">READ MORE >></a>';
// $excerpt = $excerpt.'... <a href="'.get_permalink($post->ID).'">READ MORE >></a>';
return $excerpt;
}
add_action('wp_ajax_nopriv_ajax_request', 'ajax_handle_request');
add_action('wp_ajax_ajax_request', 'ajax_handle_request');
function ajax_handle_request(){
$postID = $_POST['post_id'];
global $post;
$post = get_post($postID);
$date = get_post_meta($postID,'date',true);
$date2 = date("F j, Y", strtotime($date));
$response = array(
'sucess' => true,
'post' => $post,
'id' => $postID,
'date' => $date2,
);
// generate the response
echo json_encode($response);
// IMPORTANT: don't forget to "exit"
exit;
}
// retrieves the attachment ID from the file URL
function pippin_get_image_id($filename) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid like'%$filename'",));
return $attachment[0];
}
function schedule_cron_jobs()
{
wp_clear_scheduled_hook('notification_for_project_follow_up');
//daily
// if(!wp_next_scheduled("notification_for_project_follow_up")){
// error_log('schedule_cron_jobs');
// wp_schedule_event(time(), 'daily', 'notification_for_project_follow_up');
// }
}
add_action("admin_init", "schedule_cron_jobs");
function ParseXML($xml) {
// Gets XML in a string and parses it into an array.
// Create the parser object
if (!($parser = xml_parser_create())) {
print "cannot create parser!";
exit();
}
// if we didn't get the argument then give them an error.
if ($xml == "") {
print "No XML Was found!";
exit;
}
xml_parse_into_struct($parser, trim($xml), $structure, $index);
xml_parser_free($parser);
// the parsed array will go here.
// Hack up the XML and put it into the array
foreach($structure as $s)
{
if ($s["tag"] == "FOUND") {
$found = $s['value'];
}
}
return $found;
}
// Disable User Notification of Password Change Confirmation
add_filter( 'send_password_change_email', '__return_false' );
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
// Disables the block editor from managing widgets.
add_filter( 'use_widgets_block_editor', '__return_false' );