PluginProbe
WP Job Manager / 1.31.0.1
WP Job Manager v1.31.0.1
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 All 154 releases
wp-job-manager / wp-job-manager.php
wp-job-manager.php
422 lines 16.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WP Job Manager
4 * Plugin URI: https://wpjobmanager.com/
5 * Description: Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
6 * Version: 1.31.0.1
7 * Author: Automattic
8 * Author URI: https://wpjobmanager.com/
9 * Requires at least: 4.7.0
10 * Tested up to: 4.9
11 * Text Domain: wp-job-manager
12 * Domain Path: /languages/
13 * License: GPL2+
14 */
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Handles core plugin hooks and action setup.
21 *
22 * @package wp-job-manager
23 * @since 1.0.0
24 */
25 class WP_Job_Manager {
26 /**
27 * The single instance of the class.
28 *
29 * @var self
30 * @since 1.26.0
31 */
32 private static $_instance = null;
33
34 /**
35 * @var WP_Job_Manager_REST_API
36 */
37 private $rest_api = null;
38
39 /**
40 * Main WP Job Manager Instance.
41 *
42 * Ensures only one instance of WP Job Manager is loaded or can be loaded.
43 *
44 * @since 1.26.0
45 * @static
46 * @see WPJM()
47 * @return self Main instance.
48 */
49 public static function instance() {
50 if ( is_null( self::$_instance ) ) {
51 self::$_instance = new self();
52 }
53 return self::$_instance;
54 }
55
56 /**
57 * Constructor.
58 */
59 public function __construct() {
60 // Define constants
61 define( 'JOB_MANAGER_VERSION', '1.31.0.1' );
62 define( 'JOB_MANAGER_MINIMUM_WP_VERSION', '4.7.0' );
63 define( 'JOB_MANAGER_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
64 define( 'JOB_MANAGER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
65 define( 'JOB_MANAGER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
66
67 // Includes
68 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-install.php' );
69 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-post-types.php' );
70 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-ajax.php' );
71 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-shortcodes.php' );
72 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-api.php' );
73 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-forms.php' );
74 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-geocode.php' );
75 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-cache-helper.php' );
76 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/helper/class-wp-job-manager-helper.php' );
77 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/abstracts/abstract-wp-job-manager-email.php' );
78 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/abstracts/abstract-wp-job-manager-email-template.php' );
79 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-email-notifications.php' );
80
81 add_action( 'rest_api_init', array( $this, 'rest_api' ) );
82
83 if ( is_admin() ) {
84 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-admin.php' );
85 }
86
87 // Load 3rd party customizations
88 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/3rd-party/3rd-party.php' );
89
90 // Init classes
91 $this->forms = WP_Job_Manager_Forms::instance();
92 $this->post_types = WP_Job_Manager_Post_Types::instance();
93
94 // Schedule cron jobs
95 self::maybe_schedule_cron_jobs();
96
97 // Activation - works with symlinks
98 register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), array( $this, 'activate' ) );
99
100 // Switch theme
101 add_action( 'after_switch_theme', array( 'WP_Job_Manager_Ajax', 'add_endpoint' ), 10 );
102 add_action( 'after_switch_theme', array( $this->post_types, 'register_post_types' ), 11 );
103 add_action( 'after_switch_theme', 'flush_rewrite_rules', 15 );
104
105 // Actions
106 add_action( 'after_setup_theme', array( $this, 'load_plugin_textdomain' ) );
107 add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
108 add_action( 'widgets_init', array( $this, 'widgets_init' ) );
109 add_action( 'wp_loaded', array( $this, 'register_shared_assets' ) );
110 add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
111 add_action( 'admin_init', array( $this, 'updater' ) );
112 add_action( 'wp_logout', array( $this, 'cleanup_job_posting_cookies' ) );
113 add_action( 'init', array( 'WP_Job_Manager_Email_Notifications', 'init' ) );
114
115 add_action( 'init', array( $this, 'usage_tracking_init' ) );
116 register_deactivation_hook( __FILE__, array( $this, 'usage_tracking_cleanup' ) );
117
118 // Other cleanup
119 register_deactivation_hook( __FILE__, array( $this, 'unschedule_cron_jobs' ) );
120
121 // Defaults for WPJM core actions
122 add_action( 'wpjm_notify_new_user', 'wp_job_manager_notify_new_user', 10, 2 );
123 }
124
125 /**
126 * Performs plugin activation steps.
127 */
128 public function activate() {
129 WP_Job_Manager_Ajax::add_endpoint();
130 unregister_post_type( 'job_listing' );
131 add_filter( 'pre_option_job_manager_enable_types', '__return_true' );
132 $this->post_types->register_post_types();
133 remove_filter( 'pre_option_job_manager_enable_types', '__return_true' );
134 WP_Job_Manager_Install::install();
135 flush_rewrite_rules();
136 }
137
138 /**
139 * Handles tasks after plugin is updated.
140 */
141 public function updater() {
142 if ( version_compare( JOB_MANAGER_VERSION, get_option( 'wp_job_manager_version' ), '>' ) ) {
143 WP_Job_Manager_Install::install();
144 flush_rewrite_rules();
145 }
146 }
147
148 /**
149 * Loads textdomain for plugin.
150 */
151 public function load_plugin_textdomain() {
152 load_textdomain( 'wp-job-manager', WP_LANG_DIR . '/wp-job-manager/wp-job-manager-' . apply_filters( 'plugin_locale', get_locale(), 'wp-job-manager' ) . '.mo' );
153 load_plugin_textdomain( 'wp-job-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
154 }
155
156 /**
157 * Initialize our REST API.
158 *
159 * @return WP_Job_Manager_REST_API|WP_Error
160 */
161 public function rest_api() {
162 if ( null === $this->rest_api ) {
163 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/rest-api/class-wp-job-manager-rest-api.php' );
164 $this->rest_api = new WP_Job_Manager_REST_API( dirname( __FILE__ ) );
165 }
166 return $this->rest_api;
167 }
168
169 /**
170 * Loads plugin's core helper template functions.
171 */
172 public function include_template_functions() {
173 include_once( JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-deprecated.php' );
174 include_once( JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-functions.php' );
175 include_once( JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-template.php' );
176 }
177
178 /**
179 * Loads plugin's widgets.
180 */
181 public function widgets_init() {
182 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-widget.php' );
183 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/widgets/class-wp-job-manager-widget-recent-jobs.php' );
184 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/widgets/class-wp-job-manager-widget-featured-jobs.php' );
185 }
186
187 /**
188 * Initialize the Usage Tracking system.
189 */
190 public function usage_tracking_init() {
191 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-usage-tracking.php' );
192 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-usage-tracking-data.php' );
193
194 WP_Job_Manager_Usage_Tracking::get_instance()->set_callback(
195 array( 'WP_Job_Manager_Usage_Tracking_Data', 'get_usage_data' )
196 );
197 WP_Job_Manager_Usage_Tracking::get_instance()->schedule_tracking_task();
198 }
199
200 /**
201 * Cleanup the Usage Tracking system for plugin deactivation.
202 */
203 public function usage_tracking_cleanup() {
204 WP_Job_Manager_Usage_Tracking::get_instance()->unschedule_tracking_task();
205 }
206
207 /**
208 * Schedule cron jobs for WPJM events.
209 */
210 public static function maybe_schedule_cron_jobs() {
211 if ( ! wp_next_scheduled( 'job_manager_check_for_expired_jobs' ) ) {
212 wp_schedule_event( time(), 'hourly', 'job_manager_check_for_expired_jobs' );
213 }
214 if ( ! wp_next_scheduled( 'job_manager_delete_old_previews' ) ) {
215 wp_schedule_event( time(), 'daily', 'job_manager_delete_old_previews' );
216 }
217 if ( ! wp_next_scheduled( 'job_manager_clear_expired_transients' ) ) {
218 wp_schedule_event( time(), 'twicedaily', 'job_manager_clear_expired_transients' );
219 }
220 if ( ! wp_next_scheduled( 'job_manager_email_daily_notices' ) ) {
221 wp_schedule_event( time(), 'daily', 'job_manager_email_daily_notices' );
222 }
223 }
224
225 /**
226 * Unschedule cron jobs. This is run on plugin deactivation.
227 */
228 public static function unschedule_cron_jobs() {
229 wp_clear_scheduled_hook( 'job_manager_check_for_expired_jobs' );
230 wp_clear_scheduled_hook( 'job_manager_delete_old_previews' );
231 wp_clear_scheduled_hook( 'job_manager_clear_expired_transients' );
232 wp_clear_scheduled_hook( 'job_manager_email_daily_notices' );
233 }
234
235 /**
236 * Cleanup job posting cookies.
237 */
238 public function cleanup_job_posting_cookies() {
239 if ( isset( $_COOKIE['wp-job-manager-submitting-job-id'] ) ) {
240 setcookie( 'wp-job-manager-submitting-job-id', '', 0, COOKIEPATH, COOKIE_DOMAIN, false );
241 }
242 if ( isset( $_COOKIE['wp-job-manager-submitting-job-key'] ) ) {
243 setcookie( 'wp-job-manager-submitting-job-key', '', 0, COOKIEPATH, COOKIE_DOMAIN, false );
244 }
245 }
246
247 /**
248 * Registers assets used in both the frontend and WP admin.
249 */
250 public function register_shared_assets() {
251 global $wp_scripts;
252
253 $jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2';
254 wp_register_style( 'jquery-ui', '//code.jquery.com/ui/' . $jquery_version . '/themes/smoothness/jquery-ui.css', array(), $jquery_version );
255 }
256
257 /**
258 * Registers and enqueues scripts and CSS.
259 */
260 public function frontend_scripts() {
261 global $post;
262
263 /**
264 * Starting in WP Job Manager 1.32.0, the chosen JS library and core frontend WPJM CSS will only be enqueued
265 * when used on a particular page. Theme and plugin authors as well as people who have overloaded WPJM's default
266 * template files should test this upcoming behavior.
267 *
268 * To test this behavior before 1.32.0, add this to your `wp-config.php`:
269 * define( 'JOB_MANAGER_TEST_NEW_ASSET_BEHAVIOR', true );
270 *
271 * Unless this constant is defined, WP Job Manager will default to its old behavior: chosen JS library and
272 * frontend styles are always enqueued.
273 *
274 * If your theme or plugin depend on the `frontend.css` or chosen JS library from WPJM core, you can use the
275 * `job_manager_chosen_enabled` and `job_manager_enqueue_frontend_style` filters.
276 *
277 * Example code for a custom shortcode that depends on the chosen library:
278 *
279 * add_filter( 'job_manager_chosen_enabled', function( $chosen_used_on_page ) {
280 * global $post;
281 * if ( is_singular()
282 * && is_a( $post, 'WP_Post' )
283 * && has_shortcode( $post->post_content, 'resumes' )
284 * ) {
285 * $chosen_used_on_page = true;
286 * }
287 * return $chosen_used_on_page;
288 * } );
289 *
290 */
291 if ( ! defined( 'JOB_MANAGER_TEST_NEW_ASSET_BEHAVIOR' ) || true !== JOB_MANAGER_TEST_NEW_ASSET_BEHAVIOR ) {
292 add_filter( 'job_manager_chosen_enabled', '__return_true' );
293 add_filter( 'job_manager_enqueue_frontend_style', '__return_true' );
294 }
295
296 $ajax_url = WP_Job_Manager_Ajax::get_endpoint();
297 $ajax_filter_deps = array( 'jquery', 'jquery-deserialize' );
298 $ajax_data = array(
299 'ajax_url' => $ajax_url,
300 'is_rtl' => is_rtl() ? 1 : 0,
301 'i18n_load_prev_listings' => __( 'Load previous listings', 'wp-job-manager' ),
302 );
303
304 /**
305 * Retrieves the current language for use when caching requests.
306 *
307 * @since 1.26.0
308 *
309 * @param string|null $lang
310 */
311 $ajax_data['lang'] = apply_filters( 'wpjm_lang', null );
312
313 $chosen_shortcodes = array( 'submit_job_form', 'job_dashboard', 'jobs' );
314 $chosen_used_on_page = has_wpjm_shortcode( null, $chosen_shortcodes );
315
316 /**
317 * Filter the use of the chosen library.
318 *
319 * NOTE: See above. Before WP Job Manager 1.32.0 is released, `job_manager_enqueue_frontend_style` will be filtered to `true` by default.
320 *
321 * @since 1.19.0
322 *
323 * @param bool $chosen_used_on_page Defaults to only when there are known shortcodes on the page.
324 */
325 if ( apply_filters( 'job_manager_chosen_enabled', $chosen_used_on_page ) ) {
326 wp_register_script( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-chosen/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
327 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 );
328 wp_register_script( 'wp-job-manager-multiselect', JOB_MANAGER_PLUGIN_URL . '/assets/js/multiselect.min.js', array( 'jquery', 'chosen' ), JOB_MANAGER_VERSION, true );
329 wp_enqueue_style( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/css/chosen.css', array(), '1.1.0' );
330 $ajax_filter_deps[] = 'chosen';
331
332 wp_localize_script( 'chosen', 'job_manager_chosen_multiselect_args',
333 apply_filters( 'job_manager_chosen_multiselect_args', array(
334 'search_contains' => true,
335 ) )
336 );
337 }
338
339 if ( job_manager_user_can_upload_file_via_ajax() ) {
340 wp_register_script( 'jquery-iframe-transport', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.iframe-transport.js', array( 'jquery' ), '1.8.3', true );
341 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 );
342 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 );
343
344 ob_start();
345 get_job_manager_template( 'form-fields/uploaded-file-html.php', array(
346 'name' => '',
347 'value' => '',
348 'extension' => 'jpg',
349 ) );
350 $js_field_html_img = ob_get_clean();
351
352 ob_start();
353 get_job_manager_template( 'form-fields/uploaded-file-html.php', array(
354 'name' => '',
355 'value' => '',
356 'extension' => 'zip',
357 ) );
358 $js_field_html = ob_get_clean();
359
360 wp_localize_script( 'wp-job-manager-ajax-file-upload', 'job_manager_ajax_file_upload', array(
361 'ajax_url' => $ajax_url,
362 'js_field_html_img' => esc_js( str_replace( "\n", '', $js_field_html_img ) ),
363 'js_field_html' => esc_js( str_replace( "\n", '', $js_field_html ) ),
364 'i18n_invalid_file_type' => __( 'Invalid file type. Accepted types:', 'wp-job-manager' ),
365 ) );
366 }
367
368 wp_register_script( 'jquery-deserialize', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-deserialize/jquery.deserialize.js', array( 'jquery' ), '1.2.1', true );
369 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 );
370 wp_register_script( 'wp-job-manager-job-dashboard', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-dashboard.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
371 wp_register_script( 'wp-job-manager-job-application', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-application.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
372 wp_register_script( 'wp-job-manager-job-submission', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-submission.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
373 wp_localize_script( 'wp-job-manager-ajax-filters', 'job_manager_ajax_filters', $ajax_data );
374 wp_localize_script( 'wp-job-manager-job-dashboard', 'job_manager_job_dashboard', array(
375 'i18n_confirm_delete' => __( 'Are you sure you want to delete this listing?', 'wp-job-manager' ),
376 ) );
377
378
379 /**
380 * Filter whether to enqueue WPJM core's frontend scripts. By default, they will only be enqueued on WPJM related
381 * pages.
382 *
383 * NOTE: See above. Before WP Job Manager 1.32.0 is released, `job_manager_enqueue_frontend_style` will be filtered to `true` by default.
384 *
385 * @since 1.30.0
386 *
387 * @param bool $is_frontend_style_enabled
388 */
389 if ( apply_filters( 'job_manager_enqueue_frontend_style', is_wpjm() ) ) {
390 wp_enqueue_style( 'wp-job-manager-frontend', JOB_MANAGER_PLUGIN_URL . '/assets/css/frontend.css', array(), JOB_MANAGER_VERSION );
391 } else {
392 wp_register_style( 'wp-job-manager-job-listings', JOB_MANAGER_PLUGIN_URL . '/assets/css/job-listings.css', array(), JOB_MANAGER_VERSION );
393 }
394 }
395 }
396
397 /**
398 * Add post type for Job Manager.
399 *
400 * @param array $types
401 * @return array
402 */
403 function job_manager_add_post_types( $types ) {
404 $types[] = 'job_listing';
405 return $types;
406 }
407 add_filter( 'post_types_to_delete_with_user', 'job_manager_add_post_types', 10 );
408
409 /**
410 * Main instance of WP Job Manager.
411 *
412 * Returns the main instance of WP Job Manager to prevent the need to use globals.
413 *
414 * @since 1.26
415 * @return WP_Job_Manager
416 */
417 function WPJM() {
418 return WP_Job_Manager::instance();
419 }
420
421 $GLOBALS['job_manager'] = WPJM();
422