PluginProbe ʕ •ᴥ•ʔ
WP Job Manager / 2.4.7
WP Job Manager v2.4.7
2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.11.0 1.11.1 1.12.0 1.12.1 1.13.0 1.14.0 1.15.0 1.16.0 1.16.1 1.17.0 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.21.0 1.21.1 1.21.2 1.21.3 1.21.4 1.22.0 1.22.1 1.22.2 1.22.3 1.23.0 1.23.1 1.23.10 1.23.11 1.23.12 1.23.13 1.23.2 1.23.3 1.23.4 1.23.5 1.23.6 1.23.7 1.23.8 1.23.9 1.24.0 1.24.0.1 1.25.0 1.25.0.1 1.25.1 1.25.1.1 1.25.2 1.25.2.1 1.25.3 1.25.3.1 1.26.0 1.26.0.1 1.26.1 1.26.1.1 1.26.2 1.26.2.1 1.27.0 1.27.0.1 1.28.0 1.28.0.1 1.29.0 1.29.0.1 1.29.1 1.29.1.1 1.29.2 1.29.2.1 1.29.3 1.29.3.1 1.3.0 1.3.1 1.30.0 1.30.0.1 1.30.1 1.30.1.1 1.30.2 1.30.2.1 1.31.0 1.31.0.1 1.31.1 1.31.1.1 1.31.2 1.31.3 1.32.0 1.32.1 1.32.2 1.32.3 1.33.0 1.33.1 1.33.2 1.33.3 1.33.4 1.33.5 1.34.0 1.34.1 1.34.2 1.34.3 1.34.4 1.34.5 1.35.0 1.35.1 1.35.2 1.35.3 1.36.0 1.36.1 1.36.2 1.37.0 1.38.0 1.38.1 1.39.0 1.4.0 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.7.1 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 1.9.1 1.9.2 1.9.3 2.0.0 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.4.1
wp-job-manager / includes / class-wp-job-manager.php
wp-job-manager / includes Last commit date
3rd-party 4 days ago abstracts 3 months ago admin 2 weeks ago emails 2 weeks ago forms 4 days ago helper 3 months ago promoted-jobs 4 days ago ui 2 weeks ago widgets 2 weeks ago class-access-token.php 2 years ago class-dev-tools.php 2 years ago class-guest-session.php 2 years ago class-guest-user.php 2 years ago class-job-dashboard-shortcode.php 6 months ago class-job-listing-stats.php 2 years ago class-job-overlay.php 2 years ago class-stats-dashboard.php 2 years ago class-stats-script.php 3 months ago class-stats.php 3 months ago class-wp-job-manager-ajax.php 2 months ago class-wp-job-manager-api.php 6 years ago class-wp-job-manager-blocks.php 2 weeks ago class-wp-job-manager-cache-helper.php 3 months ago class-wp-job-manager-category-walker.php 6 years ago class-wp-job-manager-com-api.php 2 years ago class-wp-job-manager-data-cleaner.php 2 years ago class-wp-job-manager-data-exporter.php 3 months ago class-wp-job-manager-dependency-checker.php 2 years ago class-wp-job-manager-email-notifications.php 2 years ago class-wp-job-manager-forms.php 5 years ago class-wp-job-manager-geocode.php 2 weeks ago class-wp-job-manager-install.php 2 years ago class-wp-job-manager-post-types.php 4 days ago class-wp-job-manager-recaptcha.php 6 months ago class-wp-job-manager-rest-api.php 2 months ago class-wp-job-manager-shortcodes.php 2 weeks ago class-wp-job-manager-usage-tracking-data.php 2 years ago class-wp-job-manager-usage-tracking.php 2 years ago class-wp-job-manager-widget.php 2 weeks ago class-wp-job-manager.php 3 months ago trait-singleton.php 2 years ago
class-wp-job-manager.php
645 lines
1 <?php
2 /**
3 * File containing the class WP_Job_Manager.
4 *
5 * @package wp-job-manager
6 * @since 1.33.0
7 */
8
9 use WP_Job_Manager\Job_Overlay;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Handles core plugin hooks and action setup.
17 *
18 * @since 1.0.0
19 */
20 class WP_Job_Manager {
21 /**
22 * The single instance of the class.
23 *
24 * @var self
25 * @since 1.26.0
26 */
27 private static $instance = null;
28
29 /**
30 * Forms.
31 *
32 * @var WP_Job_Manager_Forms
33 */
34 public $forms;
35
36 /**
37 * Post types.
38 *
39 * @var WP_Job_Manager_Post_Types
40 */
41 public $post_types;
42
43 /**
44 * Stats.
45 *
46 * @var WP_Job_Manager\Stats
47 */
48 public $stats;
49
50 /**
51 * Main WP Job Manager Instance.
52 *
53 * Ensures only one instance of WP Job Manager is loaded or can be loaded.
54 *
55 * @since 1.26.0
56 * @static
57 * @see WPJM()
58 * @return self Main instance.
59 */
60 public static function instance() {
61 if ( is_null( self::$instance ) ) {
62 self::$instance = new self();
63 }
64 return self::$instance;
65 }
66
67 /**
68 * Constructor.
69 */
70 public function __construct() {
71 // Includes.
72 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/trait-singleton.php';
73 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-install.php';
74 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-post-types.php';
75 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-ajax.php';
76 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-shortcodes.php';
77 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-api.php';
78 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-forms.php';
79 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-geocode.php';
80 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-blocks.php';
81 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-cache-helper.php';
82 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/helper/class-wp-job-manager-helper.php';
83 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/abstracts/abstract-wp-job-manager-email.php';
84 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/abstracts/abstract-wp-job-manager-email-template.php';
85 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-email-notifications.php';
86 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-data-exporter.php';
87 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-settings.php';
88 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-com-api.php';
89
90 /**
91 * Controls whether promoted jobs are enabled.
92 *
93 * @since 2.3.0
94 *
95 * @param bool $enable_promoted_jobs Whether promoted jobs are enabled.
96 */
97 if ( apply_filters( 'job_manager_enable_promoted_jobs', true ) ) {
98 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/promoted-jobs/class-wp-job-manager-promoted-jobs.php';
99 }
100
101 if ( is_admin() ) {
102 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-admin.php';
103 }
104
105 \WP_Job_Manager\UI\UI::instance();
106 \WP_Job_Manager\UI\UI_Settings::instance();
107
108 // Load 3rd party customizations.
109 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/3rd-party/3rd-party.php';
110
111 // Init classes.
112 $this->forms = WP_Job_Manager_Forms::instance();
113 $this->post_types = WP_Job_Manager_Post_Types::instance();
114 $this->stats = WP_Job_Manager\Stats::instance();
115
116 WP_Job_Manager\Dev_Tools::init();
117
118 // Schedule cron jobs.
119 add_action( 'init', [ __CLASS__, 'maybe_schedule_cron_jobs' ] );
120
121 // Switch theme.
122 add_action( 'after_switch_theme', [ 'WP_Job_Manager_Ajax', 'add_endpoint' ], 10 );
123 add_action( 'after_switch_theme', [ $this->post_types, 'register_post_types' ], 11 );
124 add_action( 'after_switch_theme', 'flush_rewrite_rules', 15 );
125
126 // Actions.
127 add_action( 'after_setup_theme', [ $this, 'load_plugin_textdomain' ] );
128 add_action( 'after_setup_theme', [ $this, 'include_template_functions' ], 11 );
129 add_action( 'widgets_init', [ $this, 'widgets_init' ] );
130 add_action( 'wp_loaded', [ $this, 'register_shared_assets' ] );
131 add_action( 'wp_enqueue_scripts', [ $this, 'frontend_scripts' ] );
132 add_action( 'wp_footer', [ $this, 'maybe_localize_jquery_ui_datepicker' ], 1 );
133 add_action( 'admin_init', [ $this, 'updater' ] );
134 add_action( 'admin_init', [ $this, 'add_privacy_policy_content' ] );
135 add_action( 'wp_logout', [ $this, 'cleanup_job_posting_cookies' ] );
136 add_action( 'init', [ 'WP_Job_Manager_Email_Notifications', 'init' ] );
137 add_action( 'rest_api_init', [ $this, 'rest_init' ] );
138 add_action( 'plugins_loaded', [ $this, 'include_admin_files' ] );
139
140 // Filters.
141 add_filter( 'wp_privacy_personal_data_exporters', [ 'WP_Job_Manager_Data_Exporter', 'register_wpjm_user_data_exporter' ] );
142 add_filter( 'allowed_redirect_hosts', [ $this, 'add_to_allowed_redirect_hosts' ] );
143
144 add_action( 'init', [ $this, 'usage_tracking_init' ] );
145
146 // Defaults for WPJM core actions.
147 add_action( 'wpjm_notify_new_user', 'wp_job_manager_notify_new_user', 10, 2 );
148 }
149
150 /**
151 * Add the WPJMCOM host to the array of allowed redirect hosts.
152 *
153 * @param array $hosts Allowed redirect hosts.
154 * @return array Updated array of allowed redirect hosts.
155 */
156 public function add_to_allowed_redirect_hosts( $hosts ) {
157 $hosts[] = wp_parse_url( WP_Job_Manager_Helper_API::get_wpjmcom_url(), PHP_URL_HOST );
158 return $hosts;
159 }
160
161 /**
162 * Performs plugin activation steps.
163 */
164 public function activate() {
165 WP_Job_Manager_Ajax::add_endpoint();
166 unregister_post_type( \WP_Job_Manager_Post_Types::PT_LISTING );
167 add_filter( 'pre_option_job_manager_enable_types', '__return_true' );
168 $this->post_types->register_post_types();
169 remove_filter( 'pre_option_job_manager_enable_types', '__return_true' );
170 WP_Job_Manager_Install::install();
171 flush_rewrite_rules();
172 }
173
174 /**
175 * Handles tasks after plugin is updated.
176 */
177 public function updater() {
178 if ( version_compare( JOB_MANAGER_VERSION, get_option( 'wp_job_manager_version' ), '>' ) ) {
179 WP_Job_Manager_Install::install();
180
181 flush_rewrite_rules();
182 }
183 }
184
185 /**
186 * Adds Privacy Policy suggested content.
187 */
188 public function add_privacy_policy_content() {
189 if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
190 return;
191 }
192
193 $content = sprintf(
194 // translators: Placeholders %1$s and %2$s are the names of the two cookies used in WP Job Manager.
195 __(
196 'This site adds the following cookies to help users resume job submissions that they
197 have started but have not completed: %1$s and %2$s',
198 'wp-job-manager'
199 ),
200 '<code>wp-job-manager-submitting-job-id</code>',
201 '<code>wp-job-manager-submitting-job-key</code>'
202 );
203
204 wp_add_privacy_policy_content(
205 'WP Job Manager',
206 wp_kses_post( wpautop( $content, false ) )
207 );
208 }
209
210 /**
211 * Loads textdomain for plugin.
212 */
213 public function load_plugin_textdomain() {
214 load_textdomain( 'wp-job-manager', WP_LANG_DIR . '/wp-job-manager/wp-job-manager-' . apply_filters( 'plugin_locale', get_locale(), 'wp-job-manager' ) . '.mo' );
215 load_plugin_textdomain( 'wp-job-manager', false, JOB_MANAGER_PLUGIN_DIR . '/languages/' );
216 }
217
218 /**
219 * Loads plugin's core helper template functions.
220 */
221 public function include_template_functions() {
222 include_once JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-deprecated.php';
223 include_once JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-functions.php';
224 include_once JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-template.php';
225 }
226
227 /**
228 * Loads the REST API functionality.
229 */
230 public function rest_init() {
231 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-rest-api.php';
232 WP_Job_Manager_REST_API::init();
233 }
234
235 /**
236 * Loads plugin's widgets.
237 */
238 public function widgets_init() {
239 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-widget.php';
240 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/widgets/class-wp-job-manager-widget-recent-jobs.php';
241 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/widgets/class-wp-job-manager-widget-featured-jobs.php';
242 }
243
244 /**
245 * Initialize the Usage Tracking system.
246 */
247 public function usage_tracking_init() {
248 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-usage-tracking.php';
249 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-usage-tracking-data.php';
250
251 WP_Job_Manager_Usage_Tracking::get_instance()->set_callback(
252 [ 'WP_Job_Manager_Usage_Tracking_Data', 'get_usage_data' ]
253 );
254
255 if ( is_admin() ) {
256 WP_Job_Manager_Usage_Tracking::get_instance()->schedule_tracking_task();
257 }
258 }
259
260 /**
261 * Cleanup the Usage Tracking system for plugin deactivation.
262 */
263 public function usage_tracking_cleanup() {
264 WP_Job_Manager_Usage_Tracking::get_instance()->unschedule_tracking_task();
265 }
266
267 /**
268 * Schedule cron jobs for WPJM events.
269 */
270 public static function maybe_schedule_cron_jobs() {
271 if ( ! wp_next_scheduled( 'job_manager_check_for_expired_jobs' ) ) {
272 wp_schedule_event( time(), 'hourly', 'job_manager_check_for_expired_jobs' );
273 }
274 if ( ! wp_next_scheduled( 'job_manager_delete_old_previews' ) ) {
275 wp_schedule_event( time(), 'daily', 'job_manager_delete_old_previews' );
276 }
277 if ( ! wp_next_scheduled( 'job_manager_email_daily_notices' ) ) {
278 wp_schedule_event( time(), 'daily', 'job_manager_email_daily_notices' );
279 }
280 if ( class_exists( 'WP_Job_Manager_Promoted_Jobs_Status_Handler' ) && ! wp_next_scheduled( WP_Job_Manager_Promoted_Jobs_Status_Handler::CRON_HOOK ) ) {
281 wp_schedule_event( time(), 'hourly', WP_Job_Manager_Promoted_Jobs_Status_Handler::CRON_HOOK );
282 }
283 }
284
285 /**
286 * Unschedule cron jobs. This is run on plugin deactivation.
287 */
288 public static function unschedule_cron_jobs() {
289 wp_clear_scheduled_hook( 'job_manager_check_for_expired_jobs' );
290 wp_clear_scheduled_hook( 'job_manager_delete_old_previews' );
291 wp_clear_scheduled_hook( 'job_manager_email_daily_notices' );
292 wp_clear_scheduled_hook( 'job_manager_promoted_jobs_notification' );
293 wp_clear_scheduled_hook( WP_Job_Manager_Promoted_Jobs_Status_Handler::CRON_HOOK );
294 }
295
296 /**
297 * Cleanup job posting cookies.
298 */
299 public function cleanup_job_posting_cookies() {
300 $cookie_options = [
301 'expires' => 0,
302 'path' => COOKIEPATH,
303 'domain' => COOKIE_DOMAIN,
304 'secure' => is_ssl(),
305 'httponly' => true,
306 'samesite' => 'Lax',
307 ];
308
309 if ( isset( $_COOKIE['wp-job-manager-submitting-job-id'] ) ) {
310 setcookie( 'wp-job-manager-submitting-job-id', '', $cookie_options );
311 }
312 if ( isset( $_COOKIE['wp-job-manager-submitting-job-key'] ) ) {
313 setcookie( 'wp-job-manager-submitting-job-key', '', $cookie_options );
314 }
315 }
316
317 /**
318 * Registers assets used in both the frontend and WP admin.
319 */
320 public function register_shared_assets() {
321 global $wp_scripts;
322
323 $jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2';
324 $jquery_version = preg_replace( '/-wp/', '', $jquery_version );
325 wp_register_style( 'jquery-ui', '//code.jquery.com/ui/' . $jquery_version . '/themes/smoothness/jquery-ui.min.css', [], $jquery_version );
326
327 // Register datepicker JS. It will be enqueued if needed when a date field is used.
328 self::register_script( 'wp-job-manager-datepicker', 'js/datepicker.js', [ 'jquery', 'jquery-ui-datepicker' ], true );
329 }
330
331 /**
332 * Registers select2 assets when needed.
333 */
334 public static function register_select2_assets() {
335 wp_register_script( 'select2', JOB_MANAGER_PLUGIN_URL . '/assets/lib/select2/select2.full.min.js', [ 'jquery' ], '4.0.10', false );
336 wp_register_style( 'select2', JOB_MANAGER_PLUGIN_URL . '/assets/lib/select2/select2.min.css', [], '4.0.10' );
337 }
338
339 /**
340 * Register a built script file.
341 *
342 * @param string $script_handle The script handle to register.
343 * @param string $script_path The script path within the assets/dist directory.
344 * @param array $dependencies The script dependencies. If set, this will override what is included in the `[script].asset.php` file.
345 * @param bool $in_footer Whether to enqueue the script before </body> instead of in the <head>.
346 *
347 * @return bool
348 */
349 public static function register_script( $script_handle, $script_path, $dependencies = null, $in_footer = false ) {
350 $script_asset_path = realpath(
351 JOB_MANAGER_PLUGIN_DIR . '/assets/dist/' .
352 substr_replace( $script_path, '.asset.php', - strlen( '.js' ) )
353 );
354
355 if ( ! file_exists( $script_asset_path ) ) {
356 return false;
357 }
358
359 $script_asset = require $script_asset_path;
360 $result = wp_register_script(
361 $script_handle,
362 JOB_MANAGER_PLUGIN_URL . '/assets/dist/' . $script_path,
363 null !== $dependencies ? $dependencies : $script_asset['dependencies'],
364 $script_asset['version'],
365 $in_footer
366 );
367
368 return $result;
369 }
370
371 /**
372 * Register a built stylesheet file.
373 *
374 * @param string $style_handle The stylesheet handle to register.
375 * @param string $style_path The stylesheet path within the assets/dist directory.
376 * @param array $dependencies The script dependencies. If set, this will override what is included in the `[script].asset.php` file.
377 * @param string $media The media for which this stylesheet has been defined.
378 *
379 * @return bool
380 */
381 public static function register_style( $style_handle, $style_path, $dependencies = null, $media = 'all' ) {
382 $script_asset_path = realpath(
383 JOB_MANAGER_PLUGIN_DIR . '/assets/dist/' .
384 substr_replace( $style_path, '.asset.php', - strlen( '.css' ) )
385 );
386
387 if ( ! file_exists( $script_asset_path ) ) {
388 return false;
389 }
390
391 $script_asset = require $script_asset_path;
392 $result = wp_register_style(
393 $style_handle,
394 JOB_MANAGER_PLUGIN_URL . '/assets/dist/' . $style_path,
395 null !== $dependencies ? $dependencies : $script_asset['dependencies'],
396 $script_asset['version'],
397 $media
398 );
399
400 return $result;
401 }
402
403 /**
404 * WordPress localizes this script late in `wp_head`. We sometimes enqueue the datepicker later on.
405 *
406 * @access private
407 * @since 1.34.1
408 */
409 public function maybe_localize_jquery_ui_datepicker() {
410 // Check if this data has already been added. Prevents outputting localization data multiple times.
411 if ( wp_scripts()->get_data( 'jquery-ui-datepicker', 'after' ) ) {
412 return;
413 }
414
415 wp_localize_jquery_ui_datepicker();
416 }
417
418 /**
419 * Registers and enqueues scripts and CSS.
420 *
421 * Note: For enhanced select, 1.32.0 moved to Select2. Chosen is currently packaged but will be removed in an
422 * upcoming release.
423 */
424 public function frontend_scripts() {
425 $ajax_url = WP_Job_Manager_Ajax::get_endpoint();
426 $ajax_filter_deps = [ 'jquery', 'jquery-deserialize' ];
427 $ajax_data = [
428 'ajax_url' => $ajax_url,
429 'is_rtl' => is_rtl() ? 1 : 0,
430 'i18n_load_prev_listings' => __( 'Load previous listings', 'wp-job-manager' ),
431 ];
432 /**
433 * Retrieves the current language for use when caching requests.
434 *
435 * @since 1.26.0
436 *
437 * @param string|null $lang
438 */
439 $ajax_data['lang'] = apply_filters( 'wpjm_lang', null );
440
441 $enhanced_select_shortcodes = [ 'submit_job_form', 'job_dashboard', 'jobs' ];
442 $enhanced_select_used_on_page = has_wpjm_shortcode( null, $enhanced_select_shortcodes );
443
444 /**
445 * Set the constant `JOB_MANAGER_DISABLE_CHOSEN_LEGACY_COMPAT` to true to test for future behavior once
446 * this legacy code is removed and `chosen` is no longer packaged with the plugin.
447 */
448 if ( ! defined( 'JOB_MANAGER_DISABLE_CHOSEN_LEGACY_COMPAT' ) || ! JOB_MANAGER_DISABLE_CHOSEN_LEGACY_COMPAT ) {
449 if ( is_wpjm_taxonomy() || is_wpjm_job_listing() || is_wpjm_page() ) {
450 $enhanced_select_used_on_page = true;
451 }
452
453 // Register the script for dependencies that still require it.
454 if ( ! wp_script_is( 'chosen', 'registered' ) ) {
455 wp_register_script( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/lib/jquery-chosen/chosen.jquery.min.js', [ 'jquery' ], '1.1.0', true );
456 wp_register_style( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/lib/jquery-chosen/chosen.css', [], '1.1.0' );
457 }
458
459 // Backwards compatibility for third-party themes/plugins while they transition to Select2.
460 wp_localize_script(
461 'chosen',
462 'job_manager_chosen_multiselect_args',
463 apply_filters(
464 'job_manager_chosen_multiselect_args',
465 [
466 'search_contains' => true,
467 ]
468 )
469 );
470
471 /**
472 * Filter the use of the deprecated chosen library. Themes and plugins should migrate to Select2. This will be
473 * removed in an upcoming major release.
474 *
475 * @since 1.19.0
476 * @deprecated 1.32.0 Migrate to job_manager_select2_enabled and enable only on pages that need it.
477 *
478 * @param bool $chosen_used_on_page
479 */
480 if ( apply_filters( 'job_manager_chosen_enabled', false ) ) {
481 _deprecated_hook( 'job_manager_chosen_enabled', '1.32.0', 'job_manager_select2_enabled' );
482
483 // Assume if this filter returns true that the current page should have the multi-select scripts.
484 $enhanced_select_used_on_page = true;
485
486 wp_enqueue_script( 'chosen' );
487 wp_enqueue_style( 'chosen' );
488 }
489 }
490
491 /**
492 * Filter the use of the enhanced select.
493 *
494 * Note: Don't depend on `select2` being registered/enqueued in customizations.
495 *
496 * @since 1.32.0
497 *
498 * @param bool $enhanced_select_used_on_page Defaults to only when there are known shortcodes on the page.
499 */
500 if ( apply_filters( 'job_manager_enhanced_select_enabled', $enhanced_select_used_on_page ) ) {
501 self::register_select2_assets();
502 self::register_script( 'wp-job-manager-term-multiselect', 'js/term-multiselect.js', [ 'jquery', 'select2' ], true );
503 self::register_script( 'wp-job-manager-multiselect', 'js/multiselect.js', [ 'jquery', 'select2' ], true );
504 wp_enqueue_style( 'select2' );
505
506 $ajax_filter_deps[] = 'select2';
507
508 $select2_args = [];
509 if ( is_rtl() ) {
510 $select2_args['dir'] = 'rtl';
511 }
512
513 $select2_args['width'] = '100%';
514
515 wp_localize_script(
516 'select2',
517 'job_manager_select2_args',
518 apply_filters( 'job_manager_select2_args', $select2_args )
519 );
520 }
521
522 if ( job_manager_user_can_upload_file_via_ajax() ) {
523 wp_register_script( 'jquery-iframe-transport', JOB_MANAGER_PLUGIN_URL . '/assets/lib/jquery-fileupload/jquery.iframe-transport.js', [ 'jquery' ], '10.1.0', true );
524 wp_register_script( 'jquery-fileupload', JOB_MANAGER_PLUGIN_URL . '/assets/lib/jquery-fileupload/jquery.fileupload.js', [ 'jquery', 'jquery-iframe-transport', 'jquery-ui-widget' ], '10.1.0', true );
525
526 self::register_script( 'wp-job-manager-ajax-file-upload', 'js/ajax-file-upload.js', [ 'jquery', 'jquery-fileupload' ], true );
527
528 ob_start();
529 get_job_manager_template(
530 'form-fields/uploaded-file-html.php',
531 [
532 'name' => '',
533 'value' => '',
534 'extension' => 'jpg',
535 ]
536 );
537 $js_field_html_img = ob_get_clean();
538
539 ob_start();
540 get_job_manager_template(
541 'form-fields/uploaded-file-html.php',
542 [
543 'name' => '',
544 'value' => '',
545 'extension' => 'zip',
546 ]
547 );
548 $js_field_html = ob_get_clean();
549
550 wp_localize_script(
551 'wp-job-manager-ajax-file-upload',
552 'job_manager_ajax_file_upload',
553 [
554 'ajax_url' => $ajax_url,
555 'js_field_html_img' => esc_js( str_replace( "\n", '', $js_field_html_img ) ),
556 'js_field_html' => esc_js( str_replace( "\n", '', $js_field_html ) ),
557 'i18n_invalid_file_type' => esc_html__( 'Invalid file type. Accepted types:', 'wp-job-manager' ),
558 ]
559 );
560 }
561
562 wp_register_script( 'jquery-deserialize', JOB_MANAGER_PLUGIN_URL . '/assets/lib/jquery-deserialize/jquery.deserialize.js', [ 'jquery' ], '1.2.1', true );
563 self::register_script( 'wp-job-manager-ajax-filters', 'js/ajax-filters.js', $ajax_filter_deps, true );
564 self::register_script( 'wp-job-manager-job-application', 'js/job-application.js', [ 'jquery' ], true );
565 self::register_script( 'wp-job-manager-job-submission', 'js/job-submission.js', [ 'jquery' ], true );
566 wp_localize_script( 'wp-job-manager-ajax-filters', 'job_manager_ajax_filters', $ajax_data );
567
568 if ( isset( $select2_args ) ) {
569 $select2_filters_args = array_merge(
570 $select2_args,
571 [
572 'allowClear' => true,
573 'minimumResultsForSearch' => 10,
574 'placeholder' => __( 'Any Category', 'wp-job-manager' ),
575 ]
576 );
577
578 wp_localize_script(
579 'select2',
580 'job_manager_select2_filters_args',
581 apply_filters( 'job_manager_select2_filters_args', $select2_filters_args )
582 );
583 }
584
585 wp_localize_script(
586 'wp-job-manager-job-submission',
587 'job_manager_job_submission',
588 [
589 // translators: Placeholder %d is the number of files to that users are limited to.
590 'i18n_over_upload_limit' => esc_html__( 'You are only allowed to upload a maximum of %d files.', 'wp-job-manager' ),
591 ]
592 );
593
594 wp_localize_script(
595 'wp-job-manager-job-submission',
596 'job_manager_job_submission',
597 [
598 'i18n_required_field' => __( 'This field is required.', 'wp-job-manager' ),
599 ]
600 );
601
602 /**
603 * Filter whether to enqueue WPJM core's frontend scripts. By default, they will only be enqueued on WPJM related
604 * pages.
605 *
606 * If your theme or plugin depend on `frontend.css` from WPJM core, you can use the
607 * `job_manager_enqueue_frontend_style` filter.
608 *
609 * Example code for a custom shortcode that depends on the frontend style:
610 *
611 * add_filter( 'job_manager_enqueue_frontend_style', function( $frontend_used_on_page ) {
612 * global $post;
613 * if ( is_singular()
614 * && is_a( $post, 'WP_Post' )
615 * && has_shortcode( $post->post_content, 'resumes' )
616 * ) {
617 * $frontend_used_on_page = true;
618 * }
619 * return $frontend_used_on_page;
620 * } );
621 *
622 * @since 1.30.0
623 *
624 * @param bool $is_frontend_style_enabled
625 */
626 if ( apply_filters( 'job_manager_enqueue_frontend_style', is_wpjm() ) ) {
627 self::register_style( 'wp-job-manager-frontend', 'css/frontend.css', [] );
628 wp_enqueue_style( 'wp-job-manager-frontend' );
629 } else {
630 self::register_style( 'wp-job-manager-job-listings', 'css/job-listings.css', [] );
631 wp_enqueue_style( 'wp-job-manager-job-listings' );
632 }
633 }
634
635 /**
636 * This solves a loading order issue which occurs when is_admin() starts to return true at a point after plugin
637 * load. See the below issue for more information: https://github.com/Automattic/evergreen/issues/136
638 */
639 public function include_admin_files() {
640 if ( is_admin() && ! class_exists( 'WP_Job_Manager_Admin' ) ) {
641 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-admin.php';
642 }
643 }
644 }
645