PluginProbe
WP Job Manager / 1.29.3
WP Job Manager v1.29.3
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
309 lines 11.6 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.29.3
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.29.3' );
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 // Defaults for WPJM core actions
109 add_action( 'wpjm_notify_new_user', 'wp_job_manager_notify_new_user', 10, 2 );
110 }
111
112 /**
113 * Performs plugin activation steps.
114 */
115 public function activate() {
116 WP_Job_Manager_Ajax::add_endpoint();
117 unregister_post_type( 'job_listing' );
118 add_filter( 'pre_option_job_manager_enable_types', '__return_true' );
119 $this->post_types->register_post_types();
120 remove_filter( 'pre_option_job_manager_enable_types', '__return_true' );
121 WP_Job_Manager_Install::install();
122 flush_rewrite_rules();
123 }
124
125 /**
126 * Handles tasks after plugin is updated.
127 */
128 public function updater() {
129 if ( version_compare( JOB_MANAGER_VERSION, get_option( 'wp_job_manager_version' ), '>' ) ) {
130 WP_Job_Manager_Install::install();
131 flush_rewrite_rules();
132 }
133 }
134
135 /**
136 * Loads textdomain for plugin.
137 */
138 public function load_plugin_textdomain() {
139 load_textdomain( 'wp-job-manager', WP_LANG_DIR . '/wp-job-manager/wp-job-manager-' . apply_filters( 'plugin_locale', get_locale(), 'wp-job-manager' ) . '.mo' );
140 load_plugin_textdomain( 'wp-job-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
141 }
142
143 /**
144 * Initialize our REST API.
145 *
146 * @return WP_Job_Manager_REST_API|WP_Error
147 */
148 public function rest_api() {
149 if ( null === $this->rest_api ) {
150 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/rest-api/class-wp-job-manager-rest-api.php' );
151 $this->rest_api = new WP_Job_Manager_REST_API( dirname( __FILE__ ) );
152 }
153 return $this->rest_api;
154 }
155
156 /**
157 * Loads plugin's core helper template functions.
158 */
159 public function include_template_functions() {
160 include_once( JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-deprecated.php' );
161 include_once( JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-functions.php' );
162 include_once( JOB_MANAGER_PLUGIN_DIR . '/wp-job-manager-template.php' );
163 }
164
165 /**
166 * Loads plugin's widgets.
167 */
168 public function widgets_init() {
169 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-widget.php' );
170 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/widgets/class-wp-job-manager-widget-recent-jobs.php' );
171 include_once( JOB_MANAGER_PLUGIN_DIR . '/includes/widgets/class-wp-job-manager-widget-featured-jobs.php' );
172 }
173
174 /**
175 * Schedule cron jobs for WPJM events.
176 */
177 public static function maybe_schedule_cron_jobs() {
178 if ( ! wp_next_scheduled( 'job_manager_check_for_expired_jobs' ) ) {
179 wp_schedule_event( time(), 'hourly', 'job_manager_check_for_expired_jobs' );
180 }
181 if ( ! wp_next_scheduled( 'job_manager_delete_old_previews' ) ) {
182 wp_schedule_event( time(), 'daily', 'job_manager_delete_old_previews' );
183 }
184 if ( ! wp_next_scheduled( 'job_manager_clear_expired_transients' ) ) {
185 wp_schedule_event( time(), 'twicedaily', 'job_manager_clear_expired_transients' );
186 }
187 }
188
189 /**
190 * Cleanup job posting cookies.
191 */
192 public function cleanup_job_posting_cookies() {
193 if ( isset( $_COOKIE['wp-job-manager-submitting-job-id'] ) ) {
194 setcookie( 'wp-job-manager-submitting-job-id', '', 0, COOKIEPATH, COOKIE_DOMAIN, false );
195 }
196 if ( isset( $_COOKIE['wp-job-manager-submitting-job-key'] ) ) {
197 setcookie( 'wp-job-manager-submitting-job-key', '', 0, COOKIEPATH, COOKIE_DOMAIN, false );
198 }
199 }
200
201 /**
202 * Registers and enqueues scripts and CSS.
203 */
204 public function frontend_scripts() {
205 global $post;
206
207 $ajax_url = WP_Job_Manager_Ajax::get_endpoint();
208 $ajax_filter_deps = array( 'jquery', 'jquery-deserialize' );
209 $ajax_data = array(
210 'ajax_url' => $ajax_url,
211 'is_rtl' => is_rtl() ? 1 : 0,
212 'i18n_load_prev_listings' => __( 'Load previous listings', 'wp-job-manager' ),
213 );
214
215 /**
216 * Retrieves the current language for use when caching requests.
217 *
218 * @since 1.26.0
219 *
220 * @param string|null $lang
221 */
222 $ajax_data['lang'] = apply_filters( 'wpjm_lang', null );
223
224 if ( apply_filters( 'job_manager_chosen_enabled', true ) ) {
225 wp_register_script( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-chosen/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
226 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 );
227 wp_register_script( 'wp-job-manager-multiselect', JOB_MANAGER_PLUGIN_URL . '/assets/js/multiselect.min.js', array( 'jquery', 'chosen' ), JOB_MANAGER_VERSION, true );
228 wp_enqueue_style( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/css/chosen.css', array(), '1.1.0' );
229 $ajax_filter_deps[] = 'chosen';
230
231 wp_localize_script( 'chosen', 'job_manager_chosen_multiselect_args',
232 apply_filters( 'job_manager_chosen_multiselect_args', array(
233 'search_contains' => true,
234 ) )
235 );
236 }
237
238 if ( apply_filters( 'job_manager_ajax_file_upload_enabled', true ) ) {
239 wp_register_script( 'jquery-iframe-transport', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.iframe-transport.js', array( 'jquery' ), '1.8.3', true );
240 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 );
241 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 );
242
243 ob_start();
244 get_job_manager_template( 'form-fields/uploaded-file-html.php', array(
245 'name' => '',
246 'value' => '',
247 'extension' => 'jpg',
248 ) );
249 $js_field_html_img = ob_get_clean();
250
251 ob_start();
252 get_job_manager_template( 'form-fields/uploaded-file-html.php', array(
253 'name' => '',
254 'value' => '',
255 'extension' => 'zip',
256 ) );
257 $js_field_html = ob_get_clean();
258
259 wp_localize_script( 'wp-job-manager-ajax-file-upload', 'job_manager_ajax_file_upload', array(
260 'ajax_url' => $ajax_url,
261 'js_field_html_img' => esc_js( str_replace( "\n", '', $js_field_html_img ) ),
262 'js_field_html' => esc_js( str_replace( "\n", '', $js_field_html ) ),
263 'i18n_invalid_file_type' => __( 'Invalid file type. Accepted types:', 'wp-job-manager' ),
264 ) );
265 }
266
267 wp_register_script( 'jquery-deserialize', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-deserialize/jquery.deserialize.js', array( 'jquery' ), '1.2.1', true );
268 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 );
269 wp_register_script( 'wp-job-manager-job-dashboard', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-dashboard.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
270 wp_register_script( 'wp-job-manager-job-application', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-application.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
271 wp_register_script( 'wp-job-manager-job-submission', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-submission.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
272 wp_localize_script( 'wp-job-manager-ajax-filters', 'job_manager_ajax_filters', $ajax_data );
273 wp_localize_script( 'wp-job-manager-job-dashboard', 'job_manager_job_dashboard', array(
274 'i18n_confirm_delete' => __( 'Are you sure you want to delete this listing?', 'wp-job-manager' ),
275 ) );
276
277 wp_enqueue_style( 'wp-job-manager-frontend', JOB_MANAGER_PLUGIN_URL . '/assets/css/frontend.css', array(), JOB_MANAGER_VERSION );
278 if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'submit_job_form' ) ) {
279 wp_enqueue_style( 'wp-job-manager-job-submission', JOB_MANAGER_PLUGIN_URL . '/assets/css/job-submission.css', array(), JOB_MANAGER_VERSION );
280 }
281 }
282 }
283
284 /**
285 * Add post type for Job Manager.
286 *
287 * @param array $types
288 * @return array
289 */
290 function job_manager_add_post_types( $types ) {
291 $types[] = 'job_listing';
292 return $types;
293 }
294 add_filter( 'post_types_to_delete_with_user', 'job_manager_add_post_types', 10 );
295
296 /**
297 * Main instance of WP Job Manager.
298 *
299 * Returns the main instance of WP Job Manager to prevent the need to use globals.
300 *
301 * @since 1.26
302 * @return WP_Job_Manager
303 */
304 function WPJM() {
305 return WP_Job_Manager::instance();
306 }
307
308 $GLOBALS['job_manager'] = WPJM();
309