forked from awsmin/wp-job-openings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-job-openings.php
1548 lines (1406 loc) · 56.8 KB
/
wp-job-openings.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
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WP Job Openings Plugin
*
* Super simple Job Listing plugin to manage Job Openings and Applicants on your WordPress site.
*
* @package wp-job-openings
*/
/**
* Plugin Name: WP Job Openings
* Plugin URI: https://wordpress.org/plugins/wp-job-openings/
* Description: Super simple Job Listing plugin to manage Job Openings and Applicants on your WordPress site.
* Author: AWSM Innovations
* Author URI: https://awsm.in/
* Version: 2.1.0
* License: GPLv2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text domain: wp-job-openings
* Domain Path: /languages
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Plugin Constants
if ( ! defined( 'AWSM_JOBS_PLUGIN_BASENAME' ) ) {
define( 'AWSM_JOBS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
}
if ( ! defined( 'AWSM_JOBS_PLUGIN_DIR' ) ) {
define( 'AWSM_JOBS_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
}
if ( ! defined( 'AWSM_JOBS_PLUGIN_URL' ) ) {
define( 'AWSM_JOBS_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
}
if ( ! defined( 'AWSM_JOBS_PLUGIN_VERSION' ) ) {
define( 'AWSM_JOBS_PLUGIN_VERSION', '2.1.0' );
}
if ( ! defined( 'AWSM_JOBS_UPLOAD_DIR_NAME' ) ) {
define( 'AWSM_JOBS_UPLOAD_DIR_NAME', 'awsm-job-openings' );
}
// Helper functions
require_once AWSM_JOBS_PLUGIN_DIR . '/inc/helper-functions.php';
class AWSM_Job_Openings {
private static $instance = null;
private static $rating_notice_active = false;
public function __construct() {
// Require Classes
self::load_classes();
// Initialize Classes
$this->awsm_core = AWSM_Job_Openings_Core::init();
$this->awsm_form = AWSM_Job_Openings_Form::init();
AWSM_Job_Openings_Filters::init();
if ( is_admin() ) {
AWSM_Job_Openings_Meta::init();
AWSM_Job_Openings_Settings::init( $this->awsm_core );
AWSM_Job_Openings_Info::init();
}
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
add_action( 'after_setup_theme', array( $this, 'template_functions' ) );
add_action( 'init', array( $this, 'init_actions' ) );
add_action( 'wp_head', array( $this, 'awsm_wp_head' ) );
add_action( 'awsm_check_for_expired_jobs', array( $this, 'check_date_and_change_status' ) );
add_action( 'awsm_jobs_email_digest', array( $this, 'send_email_digest' ) );
add_action( 'awsm_job_application_submitted', array( $this, 'plugin_rating_check' ) );
add_action( 'wp_loaded', array( $this, 'register_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'awsm_enqueue_scripts' ) );
add_action( 'template_redirect', array( $this, 'redirect_attachment_page' ), 1 );
add_action( 'widgets_init', array( $this, 'register_widgets' ) );
add_action( 'wp_ajax_awsm_view_count', array( $this, 'job_views_handler' ) );
add_action( 'wp_ajax_nopriv_awsm_view_count', array( $this, 'job_views_handler' ) );
add_action( 'wp_footer', array( $this, 'display_structured_data' ) );
$this->admin_actions();
add_filter( 'body_class', array( $this, 'body_classes' ) );
add_filter( 'the_content', array( $this, 'awsm_jobs_content' ), 100 );
add_filter( 'single_template', array( $this, 'jobs_single_template' ) );
add_filter( 'archive_template', array( $this, 'jobs_archive_template' ) );
$this->admin_filters();
add_shortcode( 'awsmjobs', array( $this, 'awsm_jobs_shortcode' ) );
}
public static function init() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
public static function load_classes() {
$prefix = 'class-awsm-job-openings';
$classes = array( 'core', 'filters', 'form' );
foreach ( $classes as $class ) {
require_once AWSM_JOBS_PLUGIN_DIR . "/inc/{$prefix}-{$class}.php";
}
if ( is_admin() ) {
$classes = array( 'meta', 'settings', 'info' );
foreach ( $classes as $class ) {
require_once AWSM_JOBS_PLUGIN_DIR . "/admin/{$prefix}-{$class}.php";
}
}
}
public function activate() {
$this->register_default_settings();
$this->awsm_core->register();
$this->create_page_when_activate();
flush_rewrite_rules();
$this->setup_page_init();
}
public function deactivate() {
$this->clear_transients();
$this->clear_cron_jobs();
$this->awsm_core->unregister();
flush_rewrite_rules();
}
private function register_default_settings() {
if ( ! class_exists( 'AWSM_Job_Openings_Settings' ) ) {
require_once AWSM_JOBS_PLUGIN_DIR . '/admin/class-awsm-job-openings-settings.php';
}
AWSM_Job_Openings_Settings::register_defaults();
}
public function setup_page_init() {
$plugin_version = get_option( 'awsm_jobs_plugin_version' );
$company_name = get_option( 'awsm_job_company_name' );
if ( empty( $plugin_version ) && empty( $company_name ) ) {
set_transient( '_awsm_activation_redirect', true, MINUTE_IN_SECONDS );
}
}
private function clear_transients() {
delete_transient( '_awsm_activation_redirect' );
delete_transient( '_awsm_add_ons_data' );
}
public function load_textdomain() {
load_plugin_textdomain( 'wp-job-openings', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
public function template_functions() {
include_once AWSM_JOBS_PLUGIN_DIR . '/inc/template-functions.php';
}
public function init_actions() {
$this->awsm_openings_cron_job();
$this->unregister_awsm_jobs_taxonomies();
$this->awsm_jobs_taxonomies();
$this->awsm_custom_expired_status();
}
public function admin_actions() {
if ( is_admin() ) {
add_action( 'admin_enqueue_scripts', array( $this, 'awsm_admin_enqueue_scripts' ) );
add_action( 'admin_head', array( $this, 'admin_head_actions' ) );
add_action( 'edit_form_top', array( $this, 'awsm_admin_single_subtitle' ) );
add_action( 'save_post', array( $this, 'awsm_job_save_post' ), 100, 2 );
add_action( 'before_delete_post', array( $this, 'delete_attachment_post' ) );
add_action( 'restrict_manage_posts', array( $this, 'awsm_admin_filtering_posts' ) );
add_action( 'before_awsm_job_settings_init', array( $this, 'no_script_msg' ) );
add_action( 'wp_ajax_awsm_plugin_rating', array( $this, 'plugin_rating' ) );
add_action( 'admin_notices', array( $this, 'plugin_rating_notice_handler' ) );
// Add custom status to status dropdown under post submit meta box (existing and new) for job openings.
add_action( 'admin_footer-post.php', array( $this, 'job_submit_meta_box_custom_status' ) );
add_action( 'admin_footer-post-new.php', array( $this, 'job_submit_meta_box_custom_status' ) );
}
}
public function admin_head_actions() {
$this->awsm_admin_single_title();
$this->awsm_job_application_screen_layout();
}
public function admin_filters() {
if ( is_admin() ) {
add_filter( 'plugin_action_links_' . AWSM_JOBS_PLUGIN_BASENAME, array( $this, 'awsm_quick_settings' ) );
add_filter( 'manage_awsm_job_openings_posts_columns', array( $this, 'awsm_job_custom_column_member' ) );
add_filter( 'manage_awsm_job_openings_posts_custom_column', array( $this, 'awsm_job_custom_column_member_data' ), 10, 2 );
add_filter( 'manage_awsm_job_application_posts_columns', array( $this, 'awsm_job_application_manage' ) );
add_filter( 'manage_awsm_job_application_posts_custom_column', array( $this, 'awsm_job_application_manage_custom_data' ), 10, 2 );
add_filter( 'parse_query', array( $this, 'awsm_admin_filter_posts' ) );
add_filter( 'months_dropdown_results', array( $this, 'awsm_job_month_dropdown' ), 10, 2 );
add_filter( 'views_edit-awsm_job_openings', array( $this, 'modified_post_status_filter' ) );
add_filter( 'views_edit-awsm_job_application', array( $this, 'awsm_job_application_action_links' ) );
add_filter( 'bulk_actions-edit-awsm_job_application', array( $this, 'awsm_job_application_bulk_actions' ) );
add_filter( 'post_row_actions', array( $this, 'awsm_posts_row_actions' ), 10, 2 );
}
}
public function create_page_when_activate() {
$default_page_id = get_option( 'awsm_jobs_default_listing_page_id' );
if ( empty( $default_page_id ) ) {
$user = get_current_user_id();
$post = array(
'post_author' => $user,
'post_name' => 'job-openings',
'post_status' => 'publish',
'post_content' => '<p>[awsmjobs]</p>',
'post_title' => esc_html__( 'Jobs', 'wp-job-openings' ),
'post_type' => 'page',
);
$post_id = wp_insert_post( $post );
if ( ! empty( $post_id ) && ! is_wp_error( $post_id ) ) {
update_option( 'awsm_jobs_default_listing_page_id', $post_id );
}
}
}
public static function add_shortcode_to_page( $page_id ) {
$post_content = get_post_field( 'post_content', $page_id );
if ( ! has_shortcode( $post_content, 'awsmjobs' ) ) {
$post_content .= '<p>[awsmjobs]</p>';
}
$page_data = array(
'ID' => $page_id,
'post_content' => $post_content,
);
wp_update_post( $page_data );
}
public function awsm_jobs_shortcode( $atts ) {
if ( ! function_exists( 'awsm_jobs_query' ) ) {
return;
}
/**
* Filters the shortcode attributes and their defaults.
*
* @since 1.6.0
*
* @param array $pairs List of supported attributes and their defaults.
*/
$pairs = apply_filters(
'awsm_jobs_shortcode_defaults',
array(
'filters' => get_option( 'awsm_enable_job_filter_listing' ) !== 'enabled' ? 'no' : 'yes',
'listings' => get_option( 'awsm_jobs_list_per_page' ),
'loadmore' => 'yes',
'specs' => '',
)
);
$shortcode_atts = shortcode_atts( $pairs, $atts, 'awsmjobs' );
ob_start();
include self::get_template_path( 'job-openings-view.php' );
$content = ob_get_clean();
/**
* Filters the shortcode output content.
*
* @since 1.6.0
*
* @param string $content Shortcode content.
* @param array $shortcode_atts Combined and filtered shortcode attribute list.
*/
return apply_filters( 'awsm_jobs_shortcode_output_content', $content, $shortcode_atts );
}
public function register_widgets() {
$widgets = array( 'recent-jobs', 'dashboard' );
foreach ( $widgets as $widget ) {
include_once AWSM_JOBS_PLUGIN_DIR . "/inc/widgets/class-awsm-job-openings-{$widget}-widget.php";
}
}
public function awsm_quick_settings( $links ) {
$links[] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( admin_url( 'edit.php?post_type=awsm_job_openings&page=awsm-jobs-settings' ) ), esc_html__( 'Settings', 'wp-job-openings' ) );
return $links;
}
public function awsm_job_custom_column_member( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => esc_attr__( 'Job Title', 'wp-job-openings' ),
'job_id' => esc_attr__( 'Job ID', 'wp-job-openings' ),
'awsm_job_applications' => esc_attr__( 'Applications', 'wp-job-openings' ),
'awsm_job_expiry' => esc_attr__( 'Expiry', 'wp-job-openings' ),
'awsm_job_post_views' => esc_attr__( 'Views', 'wp-job-openings' ),
'awsm_job_conversion' => esc_attr__( 'Conversion', 'wp-job-openings' ),
);
return $columns;
}
public static function get_application_edit_link( $id ) {
$link = '';
$post_type_object = get_post_type_object( 'awsm_job_application' );
if ( ! empty( $post_type_object ) && $post_type_object->_edit_link ) {
$link = admin_url( sprintf( $post_type_object->_edit_link . '&action=edit', $id ) );
}
return $link;
}
public static function get_recent_applications( $number_posts = 5, $most_recent = true, $fields = 'all' ) {
$args = array(
'post_type' => 'awsm_job_application',
'numberposts' => $number_posts,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
'fields' => $fields,
);
if ( $most_recent ) {
$args['date_query'] = array(
array(
'after' => '1 day ago',
'inclusive' => true,
),
);
}
$applications = get_posts( $args );
return $applications;
}
public static function get_applications( $job_id, $fields = 'all' ) {
$applications = get_children(
array(
'post_parent' => $job_id,
'post_type' => 'awsm_job_application',
'numberposts' => -1,
'orderby' => 'date',
'order' => 'DESC',
'fields' => $fields,
)
);
return $applications;
}
public function awsm_job_custom_column_member_data( $column, $post_id ) {
$application_count = count( self::get_applications( $post_id, 'ids' ) );
$job_views = get_post_meta( $post_id, 'awsm_views_count', true );
$default_display = '<span aria-hidden="true">—</span>';
switch ( $column ) {
case 'job_id':
edit_post_link( esc_html( $post_id ) );
break;
case 'awsm_job_applications':
$output = $default_display;
if ( $application_count > 0 ) {
$output = sprintf( '<a href="%1$s">%2$s</a>', esc_url( admin_url( 'edit.php?post_type=awsm_job_application&awsm_filter_posts=' . $post_id ) ), $application_count );
}
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
case 'awsm_job_expiry':
$expiry_on_list = get_post_meta( $post_id, 'awsm_set_exp_list', true );
$job_expiry = get_post_meta( $post_id, 'awsm_job_expiry', true );
echo ( $expiry_on_list === 'set_listing' && ! empty( $job_expiry ) ) ? esc_html( date_i18n( get_awsm_jobs_date_format( 'expiry-admin' ), strtotime( $job_expiry ) ) ) : $default_display; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
case 'awsm_job_post_views':
echo ( ! empty( $job_views ) ) ? esc_html( $job_views ) : $default_display; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
case 'awsm_job_conversion':
$output = $default_display;
if ( $job_views > 0 ) {
$conversion_rate = ( $application_count / $job_views ) * 100;
$output = round( $conversion_rate, 2 ) . '%';
}
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
}
}
public function awsm_job_application_manage( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'awsm-photo' => '',
'title' => esc_attr__( 'Applicant', 'wp-job-openings' ),
'application_id' => esc_attr__( 'ID', 'wp-job-openings' ),
'applied_for' => esc_attr__( 'Job', 'wp-job-openings' ),
'submisssion_time' => esc_attr__( 'Applied on', 'wp-job-openings' ),
);
return $columns;
}
public function awsm_job_application_manage_custom_data( $columns, $post_id ) {
global $submission;
$job_id = get_post_meta( $post_id, 'awsm_job_id', true );
$job_name = get_post_meta( $post_id, 'awsm_apply_for', true );
switch ( $columns ) {
case 'awsm-photo':
$applicant_email = esc_attr( get_post_meta( $post_id, 'awsm_applicant_email', true ) );
$avatar = apply_filters( 'awsm_applicant_photo', get_avatar( $applicant_email, 32 ) );
echo $avatar; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
case 'application_id':
edit_post_link( esc_html( $post_id ) );
break;
case 'applied_for':
printf( '<a href="%2$s" title="%3$s">%1$s</a>', esc_html( $job_name ), esc_url( get_edit_post_link( $job_id ) ), esc_attr( __( 'View Job: ', 'wp-job-openings' ) . $job_name ) );
break;
case 'submisssion_time':
$submission = human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ' . __( 'ago', 'wp-job-openings' );
echo esc_html( $submission );
break;
}
}
public function awsm_custom_expired_status() {
register_post_status(
'expired',
array(
'label' => esc_attr__( 'Expired', 'wp-job-openings' ),
'public' => true,
'protected' => true,
'exclude_from_search' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
/* translators: %s: posts count with expired status */
'label_count' => _n_noop( 'Expired <span class="count">(%s)</span>', 'Expired <span class="count">(%s)</span>', 'wp-job-openings' ),
)
);
}
public function job_submit_meta_box_custom_status() {
global $post_type;
if ( $post_type !== 'awsm_job_openings' ) {
return;
}
$status = array(
'publish' => __( 'Published', 'default' ),
'expired' => __( 'Expired', 'wp-job-openings' ),
'future' => __( 'Scheduled', 'default' ),
'pending' => __( 'Pending Review', 'default' ),
'draft' => __( 'Draft', 'default' ),
);
/**
* Filters the status array for submit meta box for job openings.
*
* @since 2.1.0
*
* @param array $status Job status array.
*/
$status = apply_filters( 'awsm_job_post_status', $status );
global $post;
if ( $post->post_status === 'future' ) {
unset( $status['publish'], $status['expired'] );
} else {
unset( $status['future'] );
}
$options = '';
$display_status = '';
foreach ( $status as $name => $label ) {
$selected = selected( $post->post_status, $name, false );
if ( ! empty( $selected ) ) {
$display_status = $label;
}
$options .= sprintf( '<option value="%2$s"%3$s>%1$s</option>', esc_html( $label ), esc_attr( $name ), $selected );
}
?>
<script>
jQuery(document).ready(function($) {
<?php if ( ! empty( $display_status ) ) : ?>
$('#post-status-display').text('<?php echo esc_html( $display_status ); ?>');
<?php endif; ?>
$('#post_status').html('<?php echo wp_slash( $options ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>');
});
</script>
<?php
}
public function awsm_openings_cron_job() {
if ( ! wp_next_scheduled( 'awsm_check_for_expired_jobs' ) ) {
wp_schedule_event( time(), 'hourly', 'awsm_check_for_expired_jobs' );
}
// Email digest.
$email_digest = get_option( 'awsm_jobs_email_digest', 'enable' );
if ( $email_digest === 'enable' && ! wp_next_scheduled( 'awsm_jobs_email_digest' ) ) {
wp_schedule_event( time() + DAY_IN_SECONDS, 'daily', 'awsm_jobs_email_digest' );
}
}
public function clear_cron_jobs() {
wp_clear_scheduled_hook( 'awsm_check_for_expired_jobs' );
wp_clear_scheduled_hook( 'awsm_jobs_email_digest' );
}
public function check_date_and_change_status() {
$args = array(
'post_type' => 'awsm_job_openings',
'post_status' => array( 'publish', 'private' ),
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'awsm_set_exp_list',
'value' => 'set_listing',
),
array(
'key' => 'awsm_job_expiry',
'value' => gmdate( 'Y-m-d' ),
'type' => 'DATE',
'compare' => '<',
),
),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// still doing some usual checking even if meta query is used!
$expiry_on_list = get_post_meta( get_the_ID(), 'awsm_set_exp_list', true );
$expiration_date = get_post_meta( get_the_ID(), 'awsm_job_expiry', true );
if ( $expiry_on_list === 'set_listing' && ! empty( $expiration_date ) ) {
$expiration_date_time = strtotime( $expiration_date );
if ( $expiration_date_time < ( time() - ( 24 * 60 * 60 ) ) ) {
$jobs = array();
$jobs['ID'] = get_the_ID();
$jobs['post_status'] = 'expired';
wp_update_post( $jobs );
}
}
}
}
}
public function send_email_digest() {
$to = get_option( 'awsm_hr_email_address' );
if ( ! empty( $to ) ) {
$applications = self::get_recent_applications( 3 );
if ( ! empty( $applications ) ) {
$company_name = get_option( 'awsm_job_company_name', '' );
$from = ( ! empty( $company_name ) ) ? $company_name : get_option( 'blogname' );
$from_email = get_option( 'admin_email' );
/**
* Filters the daily email digest headers.
*
* @since 2.0.0
*
* @param array $headers Additional headers
*/
$headers = apply_filters(
'awsm_jobs_email_digest_mail_headers',
array(
'content_type' => 'Content-Type: text/html; charset=UTF-8',
'from' => sprintf( 'From: %1$s <%2$s>', $from, $from_email ),
)
);
ob_start();
include self::get_template_path( 'email-digest.php', 'mail' );
$mail_content = ob_get_clean();
/**
* Filters the daily email digest template content.
*
* @since 2.0.0
*
* @param string $mail_content Mail template content.
*/
$mail_content = apply_filters( 'awsm_jobs_email_digest_template_content', $mail_content );
if ( ! empty( $mail_content ) ) {
$tags = self::get_mail_generic_template_tags(
array(
'admin_email' => $from_email,
'hr_email' => $to,
'company_name' => $company_name,
)
);
$tag_names = array_keys( $tags );
$tag_values = array_values( $tags );
$mail_content = str_replace( $tag_names, $tag_values, $mail_content );
/**
* Filters the daily email digest subject.
*
* @since 2.0.0
*
* @param string $subject Email subject.
*/
$subject = apply_filters( 'awsm_jobs_email_digest_subject', esc_html__( 'Email Digest - WP Job Openings', 'wp-job-openings' ) );
wp_mail( $to, $subject, $mail_content, array_values( $headers ) );
}
}
}
}
public static function get_mail_generic_template_tags( $options = array() ) {
$company_name = isset( $options['company_name'] ) ? $options['company_name'] : get_option( 'awsm_job_company_name' );
$admin_email = isset( $options['admin_email'] ) ? $options['admin_email'] : get_option( 'admin_email' );
$hr_email = isset( $options['hr_email'] ) ? $options['hr_email'] : get_option( 'awsm_hr_email_address', '' );
$tags = array(
'{site-title}' => esc_html( get_bloginfo( 'name' ) ),
'{site-tagline}' => esc_html( get_bloginfo( 'description' ) ),
'{site-url}' => esc_url( site_url( '/' ) ),
'{company}' => esc_html( $company_name ),
'{admin-email}' => esc_html( $admin_email ),
'{hr-email}' => esc_html( $hr_email ),
);
/**
* Filters the mail generic template tags.
*
* @since 2.0.0
*
* @param array $tags Mail template tags.
* @param array $options Settings values.
*/
return apply_filters( 'awsm_jobs_mail_generic_template_tags', $tags, $options );
}
public static function get_overview_data() {
$jobs_count = (array) wp_count_posts( 'awsm_job_openings' );
$applications_count = (array) wp_count_posts( 'awsm_job_application' );
unset( $jobs_count['auto-draft'], $applications_count['auto-draft'] );
$total_jobs = array_sum( $jobs_count );
$total_applications = array_sum( $applications_count );
$data = array(
'active_jobs' => $jobs_count['publish'],
'total_jobs' => $total_jobs,
'new_applications' => $applications_count['publish'],
'total_applications' => $total_applications,
);
return $data;
}
public function modified_post_status_filter( $views ) {
if ( isset( $views['publish'] ) ) {
$views['publish'] = str_replace( esc_html__( 'Published', 'wp-job-openings' ), esc_html__( 'Current Openings', 'wp-job-openings' ), $views['publish'] );
}
if ( isset( $views['expired'] ) ) {
$views['expired'] = str_replace( esc_html__( 'Expired', 'wp-job-openings' ), esc_html__( 'Inactive', 'wp-job-openings' ), $views['expired'] );
}
return $views;
}
public function awsm_admin_filtering_posts() {
global $typenow;
if ( $typenow === 'awsm_job_application' ) {
$jobs_post_filter = '';
if ( isset( $_GET['awsm_filter_posts'] ) ) {
$jobs_post_filter = intval( $_GET['awsm_filter_posts'] );
}
$custom_posts = array(
'posts_per_page' => -1,
'post_type' => 'awsm_job_openings',
'post_status' => array( 'publish', 'expired' ),
'suppress_filters' => false,
);
$job_posts = get_posts( $custom_posts );
echo "<select name='awsm_filter_posts'>";
echo "<option value=''>" . esc_html__( 'All Jobs', 'wp-job-openings' ) . '</option>';
foreach ( $job_posts as $jobs ) {
$selected = '';
$post_id = $jobs->ID;
$post_title = $jobs->post_title;
if ( $jobs_post_filter === $post_id ) {
$selected = ' selected';
}
printf( '<option value="%1$d"%3$s>%2$s</option>', intval( $post_id ), esc_html( $post_title ), esc_attr( $selected ) );
}
echo '</select>';
}
}
public function awsm_admin_filter_posts( $query ) {
global $pagenow;
$type = 'awsm_job_application';
if ( isset( $_GET['post_type'] ) ) {
$type = $_GET['post_type'];
}
if ( $type === 'awsm_job_application' && is_admin() && $pagenow === 'edit.php' && isset( $_GET['awsm_filter_posts'] ) && $query->is_main_query() ) {
$meta_value = intval( $_GET['awsm_filter_posts'] );
if ( $meta_value ) {
$query->query_vars['meta_key'] = 'awsm_job_id';
$query->query_vars['meta_value'] = $meta_value;
}
}
}
public function awsm_job_month_dropdown( $months, $post_type ) {
if ( $post_type === 'awsm_job_openings' || $post_type === 'awsm_job_application' ) {
$months = array();
}
return $months;
}
public function awsm_wp_head() {
global $post;
if ( is_singular( 'awsm_job_openings' ) ) {
// block search engine robots to expired jobs
if ( function_exists( 'wp_no_robots' ) && $post->post_status === 'expired' && get_option( 'awsm_jobs_expired_jobs_block_search' ) === 'block_expired' ) {
wp_no_robots();
}
}
}
public function job_views_handler() {
// phpcs:disable WordPress.Security.NonceVerification.Missing
if ( isset( $_POST['awsm_job_id'] ) ) {
$post_id = intval( $_POST['awsm_job_id'] );
if ( $post_id && get_post_type( $post_id ) === 'awsm_job_openings' ) {
$count = 1;
$post_view_count = get_post_meta( $post_id, 'awsm_views_count', true );
if ( ! empty( $post_view_count ) ) {
$count = $post_view_count + 1;
}
update_post_meta( $post_id, 'awsm_views_count', $count );
}
}
wp_die();
// phpcs:enable
}
public function no_script_msg() {
?>
<noscript>
<div class="notice notice-error">
<p><?php esc_html_e( 'JavaScript is required! Please enable it in your browser.', 'wp-job-openings' ); ?></p>
</div>
</noscript>
<?php
}
public static function plugin_rating_notice( $rating_url, $rating_env, $context = 'job' ) {
if ( ! self::$rating_notice_active ) :
$posts_count = get_option( "awsm_plugin_rating_{$context}_count" );
$rate_later = get_transient( "_awsm_{$context}_ctx_plugin_rate_later" );
if ( is_array( $posts_count ) && $posts_count['active'] && $rate_later !== 'later' ) :
if ( ! wp_script_is( 'awsm-job-admin' ) ) {
wp_enqueue_script( 'awsm-job-admin' );
}
self::$rating_notice_active = true;
/* translators: %1$s: opening html tag, %2$s: closing html tag, %3$s: Jobs count, %4$s: Plugin rating site */
$notice = esc_html__( 'That\'s awesome! You have just published %3$sth job posting on your wesbite using %1$sWP Job Openings%2$s. Could you please do us a BIG favor and give it a %1$s5-star%2$s rating on %4$s? Just to help us spread the word and boost our motivation.', 'wp-job-openings' );
if ( $context === 'application' ) {
/* translators: %1$s: opening html tag, %2$s: closing html tag, %3$s: Applications count, %4$s: Plugin rating site */
$notice = esc_html__( 'You have received over %1$s%3$s%2$s job applications through %1$sWP Job Openings%2$s. That\'s awesome! May we ask you to give it a %1$s5-Star%2$s rating on %4$s. It will help us spread the word and boost our motivation.', 'wp-job-openings' );
}
?>
<div class='awsm-job-plugin-rating-wrapper notice notice-info notice'>
<?php printf( '<p>' . $notice . '</p>', '<strong>', '</strong>', esc_html( $posts_count['current'] ), esc_html( $rating_env ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<p>
<a class="button button-primary" href='<?php echo esc_url( $rating_url ); ?>' target="_blank"><?php echo esc_html__( 'Ok, you deserve it', 'wp-job-openings' ); ?></a>
<a class="awsm-job-plugin-rating-action button button-secondary" href='#' data-status="done" data-context="<?php echo esc_attr( $context ); ?>"><?php echo esc_html__( 'I already did', 'wp-job-openings' ); ?></a>
<a class="awsm-job-plugin-rating-action button button-secondary" href='#' data-status="later" data-context="<?php echo esc_attr( $context ); ?>"><?php echo esc_html__( 'Maybe later', 'wp-job-openings' ); ?></a>
</p>
</div>
<?php
endif;
endif;
}
public function plugin_rating_notice_handler() {
$rating_url = 'https://wordpress.org/support/plugin/wp-job-openings/reviews/?filter=5';
$rating_env = 'WordPress';
if ( class_exists( 'AWSM_Job_Openings_Pro_Pack' ) ) {
$rating_env = 'CodeCanyon';
$rating_url = 'https://codecanyon.net/item/wp-job-openings-pro/reviews/23889418';
}
$rating_url = apply_filters( 'awsm_jobs_plugin_rating_url', $rating_url );
$rated = intval( get_option( 'awsm_jobs_plugin_rating' ) );
if ( $rated !== 1 ) {
// Job Context.
self::plugin_rating_notice( $rating_url, $rating_env );
// Application context.
self::plugin_rating_notice( $rating_url, $rating_env, 'application' );
}
}
public function enable_plugin_rating( $posts_count, $context = 'job' ) {
if ( $posts_count >= 10 ) {
$ctx_count = get_option( "awsm_plugin_rating_{$context}_count" );
if ( empty( $ctx_count ) || ! is_array( $ctx_count ) ) {
$count_details = array(
'active' => true,
'current' => $posts_count,
'previous' => $posts_count,
);
update_option( "awsm_plugin_rating_{$context}_count", $count_details );
} else {
$ctx_count['current'] = $posts_count;
$rate_later = get_transient( "_awsm_{$context}_ctx_plugin_rate_later" );
if ( $rate_later !== 'later' ) {
$prev_count = intval( $ctx_count['previous'] );
if ( ( $posts_count - $prev_count ) >= 25 || $posts_count < $prev_count ) {
$ctx_count['active'] = true;
$ctx_count['previous'] = $posts_count;
}
} else {
$ctx_count['active'] = false;
}
update_option( "awsm_plugin_rating_{$context}_count", $ctx_count );
}
}
}
public function plugin_rating_check() {
$rated_status = intval( get_option( 'awsm_jobs_plugin_rating' ) );
if ( $rated_status !== 1 ) {
$count_details = wp_count_posts( 'awsm_job_application' );
$applications_count = $count_details->publish;
$other_status = array( 'progress', 'shortlist', 'reject', 'select' );
foreach ( $other_status as $status ) {
$applications_count += isset( $count_details->$status ) ? $count_details->$status : 0;
}
$this->enable_plugin_rating( $applications_count, 'application' );
}
}
public function plugin_rating() {
$response = array(
'code' => 'error',
'errors' => array(),
);
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'awsm-admin-nonce' ) ) {
$response['errors'][] = esc_html__( 'Invalid request!', 'wp-job-openings' );
}
$contexts = array( 'job', 'application' );
$context = isset( $_POST['context'] ) ? sanitize_text_field( $_POST['context'] ) : '';
if ( empty( $context ) || ! in_array( $context, $contexts ) ) {
$response['errors'][] = esc_html__( 'Invalid context!', 'wp-job-openings' );
}
if ( count( $response['errors'] ) === 0 ) {
if ( isset( $_POST['status'] ) && $_POST['status'] === 'done' ) {
update_option( 'awsm_jobs_plugin_rating', 1 );
} else {
set_transient( "_awsm_{$context}_ctx_plugin_rate_later", 'later', WEEK_IN_SECONDS );
$ctx_count = get_option( "awsm_plugin_rating_{$context}_count" );
if ( is_array( $ctx_count ) ) {
$ctx_count['active'] = false;
update_option( "awsm_plugin_rating_{$context}_count", $ctx_count );
}
}
$response['code'] = 'success';
}
wp_send_json( $response );
}
public function register_scripts() {
wp_register_style( 'awsm-jobs-general', AWSM_JOBS_PLUGIN_URL . '/assets/css/general.min.css', array(), AWSM_JOBS_PLUGIN_VERSION, 'all' );
}
public function awsm_enqueue_scripts() {
wp_enqueue_style( 'awsm-jobs-general' );
wp_enqueue_style( 'awsm-jobs-style', AWSM_JOBS_PLUGIN_URL . '/assets/css/style.min.css', array( 'awsm-jobs-general' ), AWSM_JOBS_PLUGIN_VERSION, 'all' );
$is_recaptcha_set = $this->awsm_form->is_recaptcha_set();
if ( is_singular( 'awsm_job_openings' ) && $is_recaptcha_set ) {
wp_enqueue_script( 'g-recaptcha', 'https://www.google.com/recaptcha/api.js', array(), '2.0', false );
}
wp_enqueue_script( 'awsm-job-scripts', AWSM_JOBS_PLUGIN_URL . '/assets/js/script.min.js', array( 'jquery' ), AWSM_JOBS_PLUGIN_VERSION, true );
$enable_search = get_option( 'awsm_enable_job_search' ) === 'enable' && isset( $_GET['jq'] );
global $post;
wp_localize_script(
'awsm-job-scripts',
'awsmJobsPublic',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'is_tax_archive' => is_tax(),
'is_search' => $enable_search ? sanitize_text_field( $_GET['jq'] ) : '',
'job_id' => is_singular( 'awsm_job_openings' ) ? $post->ID : 0,
'wp_max_upload_size' => ( wp_max_upload_size() ) ? ( wp_max_upload_size() ) : 0,
'i18n' => array(
'loading_text' => esc_html__( 'Loading...', 'wp-job-openings' ),
'form_error_msg' => array(
'general' => esc_html__( 'Error in submitting your application. Please try again later!', 'wp-job-openings' ),
'file_validation' => esc_html__( 'The file you have selected is too large.', 'wp-job-openings' ),
),
),
)
);
}
public function awsm_admin_enqueue_scripts() {
$screen = get_current_screen();
wp_register_style( 'awsm-job-admin-global', AWSM_JOBS_PLUGIN_URL . '/assets/css/admin-global.min.css', array(), AWSM_JOBS_PLUGIN_VERSION, 'all' );
wp_register_style( 'awsm-job-admin', AWSM_JOBS_PLUGIN_URL . '/assets/css/admin.min.css', array( 'awsm-jobs-general', 'awsm-job-admin-global' ), AWSM_JOBS_PLUGIN_VERSION, 'all' );
wp_register_script( 'awsm-job-admin', AWSM_JOBS_PLUGIN_URL . '/assets/js/admin.min.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'wp-util' ), AWSM_JOBS_PLUGIN_VERSION, true );
wp_enqueue_style( 'awsm-job-admin-global' );
if ( ! empty( $screen ) ) {
$post_type = $screen->post_type;
if ( ( $post_type === 'awsm_job_openings' ) || ( $post_type === 'awsm_job_application' ) ) {
wp_enqueue_style( 'awsm-jobs-general' );
wp_enqueue_style( 'awsm-job-admin' );
wp_enqueue_script( 'awsm-job-admin' );
}
}
wp_localize_script(
'awsm-job-admin',
'awsmJobsAdmin',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'plugin_url' => AWSM_JOBS_PLUGIN_URL,
'nonce' => wp_create_nonce( 'awsm-admin-nonce' ),
'i18n' => array(
'select2_no_page' => esc_html__( 'Select a page', 'wp-job-openings' ),
),
)
);
}
public static function get_template_path( $template_name, $sub_dir_name = false ) {
$path = $rel_path = ''; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
$plugin_base = 'wp-job-openings';
if ( ! empty( $sub_dir_name ) ) {
$rel_path .= "/{$sub_dir_name}";
}
$rel_path .= "/{$template_name}";
$theme_base_dir = trailingslashit( get_stylesheet_directory() );
if ( file_exists( $theme_base_dir . $plugin_base . $rel_path ) ) {
$path = $theme_base_dir . $plugin_base . $rel_path;
} else {
$path = AWSM_JOBS_PLUGIN_DIR . '/inc/templates' . $rel_path;
}
return $path;
}
public function body_classes( $classes ) {
global $wp_query;
if ( is_page() ) {
$job_listing_page_id = get_option( 'awsm_select_page_listing', get_option( 'awsm_jobs_default_listing_page_id' ) );
$current_page_id = $wp_query->get_queried_object_id();
if ( $current_page_id == $job_listing_page_id ) {
$classes[] = 'listing-page-awsm_job_openings';
}
}
if ( is_singular( 'awsm_job_openings' ) ) {
$job_details_template = get_option( 'awsm_jobs_details_page_template', 'default' );
if ( $job_details_template === 'custom' ) {
$key = array_search( 'awsm_job_openings-template-default', $classes );
if ( $key !== false ) {
$classes[ $key ] = 'awsm_job_openings-template-custom';
}
}
}
return $classes;
}
public function awsm_jobs_content( $content ) {
if ( ! is_singular( 'awsm_job_openings' ) || ! in_the_loop() || ! is_main_query() ) {
return $content;
}
ob_start();
include self::get_template_path( 'job-content.php' );
return ob_get_clean();
}
public function jobs_single_template( $single_template ) {
global $post;
$job_details_template = get_option( 'awsm_jobs_details_page_template', 'default' );
if ( is_object( $post ) && $post->post_type === 'awsm_job_openings' && $job_details_template === 'custom' ) {
$single_template = self::get_template_path( 'single-job.php' );
}
return $single_template;
}
public function jobs_archive_template( $archive_template ) {
global $post;
if ( is_object( $post ) && $post->post_type === 'awsm_job_openings' ) {
$archive_template = self::get_template_path( 'archive-job.php' );
}
return $archive_template;
}
public function awsm_admin_single_title() {
global $post, $title, $action, $current_screen;
if ( isset( $current_screen->post_type ) && $current_screen->post_type === 'awsm_job_application' && $action === 'edit' ) {
/* translators: %1$s: application id, %2$s: job title */
$title = esc_html( sprintf( __( 'Application #%1$s for %2$s', 'wp-job-openings' ), $post->ID, get_post_meta( $post->ID, 'awsm_apply_for', true ) ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
}
}
public function awsm_admin_single_subtitle( $post ) {
global $action;
if ( $post->post_type === 'awsm_job_application' && $action === 'edit' ) {
$date = date_i18n( get_awsm_jobs_time_format( 'application-view' ) . ', ' . get_awsm_jobs_date_format( 'application-view' ), strtotime( $post->post_date ) );