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