forked from Automattic/WP-Job-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-job-manager.php
481 lines (429 loc) · 17.9 KB
/
wp-job-manager.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
<?php
/**
* Plugin Name: WP Job Manager
* Plugin URI: https://github.com/pioniergarage/WP-Job-Manager
* Description: Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
* Version: 1.31.2
* Author: Dominic Seitz, Automattic
* Author URI: https://github.com/pioniergarage/WP-Job-Manager
* Requires at least: 4.7.0
* Tested up to: 4.9
* Text Domain: wp-job-manager
* Domain Path: /languages/
* License: GPL2+
*
* @package wp-job-manager
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Handles core plugin hooks and action setup.
*
* @package wp-job-manager
* @since 1.0.0
*/
class WP_Job_Manager {
/**
* The single instance of the class.
*
* @var self
* @since 1.26.0
*/
private static $_instance = null;
/**
* REST API instance.
*
* @var WP_Job_Manager_REST_API
*/
private $rest_api = null;
/**
* Main WP Job Manager Instance.
*
* Ensures only one instance of WP Job Manager is loaded or can be loaded.
*
* @since 1.26.0
* @static
* @see WPJM()
* @return self Main instance.
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Constructor.
*/
public function __construct() {
// Define constants.
define( 'JOB_MANAGER_VERSION', '1.31.2' );
define( 'JOB_MANAGER_MINIMUM_WP_VERSION', '4.7.0' );
define( 'JOB_MANAGER_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'JOB_MANAGER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
define( 'JOB_MANAGER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
// Includes.
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-install.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-post-types.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-ajax.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-shortcodes.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-api.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-forms.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-geocode.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-blocks.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-cache-helper.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/helper/class-wp-job-manager-helper.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/abstracts/abstract-wp-job-manager-email.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/abstracts/abstract-wp-job-manager-email-template.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-email-notifications.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-data-exporter.php';
add_action( 'rest_api_init', array( $this, 'rest_api' ) );
if ( is_admin() ) {
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-admin.php';
}
// Load 3rd party customizations.
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/3rd-party/3rd-party.php';
// Init classes.
$this->forms = WP_Job_Manager_Forms::instance();
$this->post_types = WP_Job_Manager_Post_Types::instance();
// Schedule cron jobs.
self::maybe_schedule_cron_jobs();
// Activation - works with symlinks.
register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), array( $this, 'activate' ) );
// Switch theme.
add_action( 'after_switch_theme', array( 'WP_Job_Manager_Ajax', 'add_endpoint' ), 10 );
add_action( 'after_switch_theme', array( $this->post_types, 'register_post_types' ), 11 );
add_action( 'after_switch_theme', 'flush_rewrite_rules', 15 );
// Actions.
add_action( 'after_setup_theme', array( $this, 'load_plugin_textdomain' ) );
add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
add_action( 'widgets_init', array( $this, 'widgets_init' ) );
add_action( 'wp_loaded', array( $this, 'register_shared_assets' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_action( 'admin_init', array( $this, 'updater' ) );
add_action( 'admin_init', array( $this, 'add_privacy_policy_content' ) );
add_action( 'wp_logout', array( $this, 'cleanup_job_posting_cookies' ) );
add_action( 'init', array( 'WP_Job_Manager_Email_Notifications', 'init' ) );
// Filters.
add_filter( 'wp_privacy_personal_data_exporters', array( 'WP_Job_Manager_Data_Exporter', 'register_wpjm_user_data_exporter' ) );
add_action( 'init', array( $this, 'usage_tracking_init' ) );
register_deactivation_hook( __FILE__, array( $this, 'usage_tracking_cleanup' ) );
// Other cleanup.
register_deactivation_hook( __FILE__, array( $this, 'unschedule_cron_jobs' ) );
// Defaults for WPJM core actions.
add_action( 'wpjm_notify_new_user', 'wp_job_manager_notify_new_user', 10, 2 );
}
/**
* Performs plugin activation steps.
*/
public function activate() {
WP_Job_Manager_Ajax::add_endpoint();
unregister_post_type( 'job_listing' );
add_filter( 'pre_option_job_manager_enable_types', '__return_true' );
$this->post_types->register_post_types();
remove_filter( 'pre_option_job_manager_enable_types', '__return_true' );
WP_Job_Manager_Install::install();
flush_rewrite_rules();
}
/**
* Handles tasks after plugin is updated.
*/
public function updater() {
if ( version_compare( JOB_MANAGER_VERSION, get_option( 'wp_job_manager_version' ), '>' ) ) {
WP_Job_Manager_Install::install();
flush_rewrite_rules();
}
}
/**
* Adds Privacy Policy suggested content.
*/
public function add_privacy_policy_content() {
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
return;
}
$content = sprintf(
// translators: Placeholders %1$s and %2$s are the names of the two cookies used in WP Job Manager.
__( 'This site adds the following cookies to help users resume job submissions that they
have started but have not completed: %1$s and %2$s', 'wp-job-manager'
),
'<code>wp-job-manager-submitting-job-id</code>', '<code>wp-job-manager-submitting-job-key</code>'
);
wp_add_privacy_policy_content(
'WP Job Manager',
wp_kses_post( wpautop( $content, false ) )
);
}
/**
* Loads textdomain for plugin.
*/
public function load_plugin_textdomain() {
load_textdomain( 'wp-job-manager', WP_LANG_DIR . '/wp-job-manager/wp-job-manager-' . apply_filters( 'plugin_locale', get_locale(), 'wp-job-manager' ) . '.mo' );
load_plugin_textdomain( 'wp-job-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Initialize our REST API.
*
* @return WP_Job_Manager_REST_API|WP_Error
*/
public function rest_api() {
if ( null === $this->rest_api ) {
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/rest-api/class-wp-job-manager-rest-api.php';
$this->rest_api = new WP_Job_Manager_REST_API( dirname( __FILE__ ) );
}
return $this->rest_api;
}
/**
* Loads plugin's core helper template functions.
*/
public function include_template_functions() {
include_once JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-deprecated.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-functions.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-template.php';
}
/**
* Loads plugin's widgets.
*/
public function widgets_init() {
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-widget.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/widgets/class-wp-job-manager-widget-recent-jobs.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/widgets/class-wp-job-manager-widget-featured-jobs.php';
}
/**
* Initialize the Usage Tracking system.
*/
public function usage_tracking_init() {
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-usage-tracking.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-usage-tracking-data.php';
WP_Job_Manager_Usage_Tracking::get_instance()->set_callback(
array( 'WP_Job_Manager_Usage_Tracking_Data', 'get_usage_data' )
);
WP_Job_Manager_Usage_Tracking::get_instance()->schedule_tracking_task();
}
/**
* Cleanup the Usage Tracking system for plugin deactivation.
*/
public function usage_tracking_cleanup() {
WP_Job_Manager_Usage_Tracking::get_instance()->unschedule_tracking_task();
}
/**
* Schedule cron jobs for WPJM events.
*/
public static function maybe_schedule_cron_jobs() {
if ( ! wp_next_scheduled( 'job_manager_check_for_expired_jobs' ) ) {
wp_schedule_event( time(), 'hourly', 'job_manager_check_for_expired_jobs' );
}
if ( ! wp_next_scheduled( 'job_manager_delete_old_previews' ) ) {
wp_schedule_event( time(), 'daily', 'job_manager_delete_old_previews' );
}
if ( ! wp_next_scheduled( 'job_manager_clear_expired_transients' ) ) {
wp_schedule_event( time(), 'twicedaily', 'job_manager_clear_expired_transients' );
}
if ( ! wp_next_scheduled( 'job_manager_email_daily_notices' ) ) {
wp_schedule_event( time(), 'daily', 'job_manager_email_daily_notices' );
}
}
/**
* Unschedule cron jobs. This is run on plugin deactivation.
*/
public static function unschedule_cron_jobs() {
wp_clear_scheduled_hook( 'job_manager_check_for_expired_jobs' );
wp_clear_scheduled_hook( 'job_manager_delete_old_previews' );
wp_clear_scheduled_hook( 'job_manager_clear_expired_transients' );
wp_clear_scheduled_hook( 'job_manager_email_daily_notices' );
}
/**
* Cleanup job posting cookies.
*/
public function cleanup_job_posting_cookies() {
if ( isset( $_COOKIE['wp-job-manager-submitting-job-id'] ) ) {
setcookie( 'wp-job-manager-submitting-job-id', '', 0, COOKIEPATH, COOKIE_DOMAIN, false );
}
if ( isset( $_COOKIE['wp-job-manager-submitting-job-key'] ) ) {
setcookie( 'wp-job-manager-submitting-job-key', '', 0, COOKIEPATH, COOKIE_DOMAIN, false );
}
}
/**
* Registers assets used in both the frontend and WP admin.
*/
public function register_shared_assets() {
global $wp_scripts;
$jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2';
wp_register_style( 'jquery-ui', '//code.jquery.com/ui/' . $jquery_version . '/themes/smoothness/jquery-ui.css', array(), $jquery_version );
}
/**
* Registers and enqueues scripts and CSS.
*/
public function frontend_scripts() {
global $post;
/**
* Starting in WP Job Manager 1.32.0, the chosen JS library and core frontend WPJM CSS will only be enqueued
* when used on a particular page. Theme and plugin authors as well as people who have overloaded WPJM's default
* template files should test this upcoming behavior.
*
* To test this behavior before 1.32.0, add this to your `wp-config.php`:
* define( 'JOB_MANAGER_TEST_NEW_ASSET_BEHAVIOR', true );
*
* Unless this constant is defined, WP Job Manager will default to its old behavior: chosen JS library and
* frontend styles are always enqueued.
*
* If your theme or plugin depend on the `frontend.css` or chosen JS library from WPJM core, you can use the
* `job_manager_chosen_enabled` and `job_manager_enqueue_frontend_style` filters.
*
* Example code for a custom shortcode that depends on the chosen library:
*
* add_filter( 'job_manager_chosen_enabled', function( $chosen_used_on_page ) {
* global $post;
* if ( is_singular()
* && is_a( $post, 'WP_Post' )
* && has_shortcode( $post->post_content, 'resumes' )
* ) {
* $chosen_used_on_page = true;
* }
* return $chosen_used_on_page;
* } );
*/
if ( ! defined( 'JOB_MANAGER_TEST_NEW_ASSET_BEHAVIOR' ) || true !== JOB_MANAGER_TEST_NEW_ASSET_BEHAVIOR ) {
add_filter( 'job_manager_chosen_enabled', '__return_true' );
add_filter( 'job_manager_enqueue_frontend_style', '__return_true' );
}
$ajax_url = WP_Job_Manager_Ajax::get_endpoint();
$ajax_filter_deps = array( 'jquery', 'jquery-deserialize' );
$ajax_data = array(
'ajax_url' => $ajax_url,
'is_rtl' => is_rtl() ? 1 : 0,
'i18n_load_prev_listings' => __( 'Load previous listings', 'wp-job-manager' ),
);
/**
* Retrieves the current language for use when caching requests.
*
* @since 1.26.0
*
* @param string|null $lang
*/
$ajax_data['lang'] = apply_filters( 'wpjm_lang', null );
$chosen_shortcodes = array( 'submit_job_form', 'job_dashboard', 'jobs' );
$chosen_used_on_page = has_wpjm_shortcode( null, $chosen_shortcodes );
/**
* Filter the use of the chosen library.
*
* NOTE: See above. Before WP Job Manager 1.32.0 is released, `job_manager_enqueue_frontend_style` will be filtered to `true` by default.
*
* @since 1.19.0
*
* @param bool $chosen_used_on_page Defaults to only when there are known shortcodes on the page.
*/
if ( apply_filters( 'job_manager_chosen_enabled', $chosen_used_on_page ) ) {
wp_register_script( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-chosen/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
wp_register_script( 'wp-job-manager-term-multiselect', JOB_MANAGER_PLUGIN_URL . '/assets/js/term-multiselect.min.js', array( 'jquery', 'chosen' ), JOB_MANAGER_VERSION, true );
wp_register_script( 'wp-job-manager-multiselect', JOB_MANAGER_PLUGIN_URL . '/assets/js/multiselect.min.js', array( 'jquery', 'chosen' ), JOB_MANAGER_VERSION, true );
wp_enqueue_style( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/css/chosen.css', array(), '1.1.0' );
$ajax_filter_deps[] = 'chosen';
wp_localize_script(
'chosen', 'job_manager_chosen_multiselect_args',
apply_filters(
'job_manager_chosen_multiselect_args', array(
'search_contains' => true,
)
)
);
}
if ( job_manager_user_can_upload_file_via_ajax() ) {
wp_register_script( 'jquery-iframe-transport', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.iframe-transport.js', array( 'jquery' ), '1.8.3', true );
wp_register_script( 'jquery-fileupload', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.fileupload.js', array( 'jquery', 'jquery-iframe-transport', 'jquery-ui-widget' ), '9.11.2', true );
wp_register_script( 'wp-job-manager-ajax-file-upload', JOB_MANAGER_PLUGIN_URL . '/assets/js/ajax-file-upload.min.js', array( 'jquery', 'jquery-fileupload' ), JOB_MANAGER_VERSION, true );
ob_start();
get_job_manager_template(
'form-fields/uploaded-file-html.php',
array(
'name' => '',
'value' => '',
'extension' => 'jpg',
)
);
$js_field_html_img = ob_get_clean();
ob_start();
get_job_manager_template(
'form-fields/uploaded-file-html.php',
array(
'name' => '',
'value' => '',
'extension' => 'zip',
)
);
$js_field_html = ob_get_clean();
wp_localize_script(
'wp-job-manager-ajax-file-upload',
'job_manager_ajax_file_upload',
array(
'ajax_url' => $ajax_url,
'js_field_html_img' => esc_js( str_replace( "\n", '', $js_field_html_img ) ),
'js_field_html' => esc_js( str_replace( "\n", '', $js_field_html ) ),
'i18n_invalid_file_type' => __( 'Invalid file type. Accepted types:', 'wp-job-manager' ),
)
);
}
wp_register_script( 'jquery-deserialize', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-deserialize/jquery.deserialize.js', array( 'jquery' ), '1.2.1', true );
wp_register_script( 'wp-job-manager-ajax-filters', JOB_MANAGER_PLUGIN_URL . '/assets/js/ajax-filters.min.js', $ajax_filter_deps, JOB_MANAGER_VERSION, true );
wp_register_script( 'wp-job-manager-job-dashboard', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-dashboard.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
wp_register_script( 'wp-job-manager-job-application', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-application.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
wp_register_script( 'wp-job-manager-job-submission', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-submission.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
wp_localize_script( 'wp-job-manager-ajax-filters', 'job_manager_ajax_filters', $ajax_data );
wp_localize_script(
'wp-job-manager-job-dashboard',
'job_manager_job_dashboard',
array(
'i18n_confirm_delete' => __( 'Are you sure you want to delete this listing?', 'wp-job-manager' ),
)
);
/**
* Filter whether to enqueue WPJM core's frontend scripts. By default, they will only be enqueued on WPJM related
* pages.
*
* NOTE: See above. Before WP Job Manager 1.32.0 is released, `job_manager_enqueue_frontend_style` will be filtered to `true` by default.
*
* @since 1.30.0
*
* @param bool $is_frontend_style_enabled
*/
if ( apply_filters( 'job_manager_enqueue_frontend_style', is_wpjm() ) ) {
wp_enqueue_style( 'wp-job-manager-frontend', JOB_MANAGER_PLUGIN_URL . '/assets/css/frontend.css', array(), JOB_MANAGER_VERSION );
} else {
wp_register_style( 'wp-job-manager-job-listings', JOB_MANAGER_PLUGIN_URL . '/assets/css/job-listings.css', array(), JOB_MANAGER_VERSION );
}
}
}
/**
* Add post type for Job Manager.
*
* @param array $types
* @return array
*/
function job_manager_add_post_types( $types ) {
$types[] = 'job_listing';
return $types;
}
add_filter( 'post_types_to_delete_with_user', 'job_manager_add_post_types', 10 );
/**
* disable auto update for wp job manager
*
* @param $value
* @return mixed
*/
function disable_plugin_updates( $value ) {
unset( $value->response['wp-job-manager/wp-job-manager.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'disable_plugin_updates' );
/**
* Main instance of WP Job Manager.
*
* Returns the main instance of WP Job Manager to prevent the need to use globals.
*
* @since 1.26
* @return WP_Job_Manager
*/
function WPJM() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName
return WP_Job_Manager::instance();
}
$GLOBALS['job_manager'] = WPJM();