PluginProbe
WP Job Manager / 1.26.2.1
WP Job Manager v1.26.2.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
250 lines 9.1 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.26.2.1
7 * Author: Automattic
8 * Author URI: https://wpjobmanager.com/
9 * Requires at least: 4.1
10 * Tested up to: 4.7
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
31 */
32 private static $_instance = null;
33
34 /**
35 * Main WP Job Manager Instance.
36 *
37 * Ensures only one instance of WP Job Manager is loaded or can be loaded.
38 *
39 * @since 1.26
40 * @static
41 * @see WPJM()
42 * @return self Main instance.
43 */
44 public static function instance() {
45 if ( is_null( self::$_instance ) ) {
46 self::$_instance = new self();
47 }
48 return self::$_instance;
49 }
50
51 /**
52 * Constructor.
53 */
54 public function __construct() {
55 // Define constants
56 define( 'JOB_MANAGER_VERSION', '1.26.2.1' );
57 define( 'JOB_MANAGER_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
58 define( 'JOB_MANAGER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
59
60 // Includes
61 include( 'includes/class-wp-job-manager-install.php' );
62 include( 'includes/class-wp-job-manager-post-types.php' );
63 include( 'includes/class-wp-job-manager-ajax.php' );
64 include( 'includes/class-wp-job-manager-shortcodes.php' );
65 include( 'includes/class-wp-job-manager-api.php' );
66 include( 'includes/class-wp-job-manager-forms.php' );
67 include( 'includes/class-wp-job-manager-geocode.php' );
68 include( 'includes/class-wp-job-manager-cache-helper.php' );
69
70 if ( is_admin() ) {
71 include( 'includes/admin/class-wp-job-manager-admin.php' );
72 }
73
74 // Load 3rd party customizations
75 require_once( 'includes/3rd-party/3rd-party.php' );
76
77 // Init classes
78 $this->forms = WP_Job_Manager_Forms::instance();
79 $this->post_types = WP_Job_Manager_Post_Types::instance();
80
81 // Activation - works with symlinks
82 register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), array( $this, 'activate' ) );
83
84 // Switch theme
85 add_action( 'after_switch_theme', array( 'WP_Job_Manager_Ajax', 'add_endpoint' ), 10 );
86 add_action( 'after_switch_theme', array( $this->post_types, 'register_post_types' ), 11 );
87 add_action( 'after_switch_theme', 'flush_rewrite_rules', 15 );
88
89 // Actions
90 add_action( 'after_setup_theme', array( $this, 'load_plugin_textdomain' ) );
91 add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
92 add_action( 'widgets_init', array( $this, 'widgets_init' ) );
93 add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
94 add_action( 'admin_init', array( $this, 'updater' ) );
95 }
96
97 /**
98 * Performs plugin activation steps.
99 */
100 public function activate() {
101 WP_Job_Manager_Ajax::add_endpoint();
102 $this->post_types->register_post_types();
103 WP_Job_Manager_Install::install();
104 flush_rewrite_rules();
105 }
106
107 /**
108 * Handles tasks after plugin is updated.
109 */
110 public function updater() {
111 if ( version_compare( JOB_MANAGER_VERSION, get_option( 'wp_job_manager_version' ), '>' ) ) {
112 WP_Job_Manager_Install::install();
113 flush_rewrite_rules();
114 }
115 }
116
117 /**
118 * Loads textdomain for plugin.
119 */
120 public function load_plugin_textdomain() {
121 load_textdomain( 'wp-job-manager', WP_LANG_DIR . '/wp-job-manager/wp-job-manager-' . apply_filters( 'plugin_locale', get_locale(), 'wp-job-manager' ) . '.mo' );
122 load_plugin_textdomain( 'wp-job-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
123 }
124
125 /**
126 * Loads plugin's core helper functions.
127 */
128 public function include_template_functions() {
129 include( 'wp-job-manager-functions.php' );
130 include( 'wp-job-manager-template.php' );
131 }
132
133 /**
134 * Loads plugin's widgets.
135 */
136 public function widgets_init() {
137 include_once( 'includes/class-wp-job-manager-widget.php' );
138 include_once( 'includes/widgets/class-wp-job-manager-widget-recent-jobs.php' );
139 include_once( 'includes/widgets/class-wp-job-manager-widget-featured-jobs.php' );
140 }
141
142 /**
143 * Registers and enqueues scripts and CSS.
144 */
145 public function frontend_scripts() {
146 global $post;
147
148 $ajax_url = WP_Job_Manager_Ajax::get_endpoint();
149 $ajax_filter_deps = array( 'jquery', 'jquery-deserialize' );
150 $ajax_data = array(
151 'ajax_url' => $ajax_url,
152 'is_rtl' => is_rtl() ? 1 : 0,
153 'i18n_load_prev_listings' => __( 'Load previous listings', 'wp-job-manager' ),
154 );
155
156 /**
157 * Retrieves the current language for use when caching requests.
158 *
159 * @since 1.26.0
160 *
161 * @param string|null $lang
162 */
163 $ajax_data['lang'] = apply_filters( 'wpjm_lang', null );
164
165 if ( apply_filters( 'job_manager_chosen_enabled', true ) ) {
166 wp_register_script( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-chosen/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
167 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 );
168 wp_register_script( 'wp-job-manager-multiselect', JOB_MANAGER_PLUGIN_URL . '/assets/js/multiselect.min.js', array( 'jquery', 'chosen' ), JOB_MANAGER_VERSION, true );
169 wp_enqueue_style( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/css/chosen.css', array(), '1.1.0' );
170 $ajax_filter_deps[] = 'chosen';
171
172 wp_localize_script( 'chosen', 'job_manager_chosen_multiselect_args',
173 apply_filters( 'job_manager_chosen_multiselect_args', array(
174 'search_contains' => true,
175 ) )
176 );
177 }
178
179 if ( apply_filters( 'job_manager_ajax_file_upload_enabled', true ) ) {
180 wp_register_script( 'jquery-iframe-transport', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.iframe-transport.js', array( 'jquery' ), '1.8.3', true );
181 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 );
182 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 );
183
184 ob_start();
185 get_job_manager_template( 'form-fields/uploaded-file-html.php', array(
186 'name' => '',
187 'value' => '',
188 'extension' => 'jpg',
189 ) );
190 $js_field_html_img = ob_get_clean();
191
192 ob_start();
193 get_job_manager_template( 'form-fields/uploaded-file-html.php', array(
194 'name' => '',
195 'value' => '',
196 'extension' => 'zip',
197 ) );
198 $js_field_html = ob_get_clean();
199
200 wp_localize_script( 'wp-job-manager-ajax-file-upload', 'job_manager_ajax_file_upload', array(
201 'ajax_url' => $ajax_url,
202 'js_field_html_img' => esc_js( str_replace( "\n", '', $js_field_html_img ) ),
203 'js_field_html' => esc_js( str_replace( "\n", '', $js_field_html ) ),
204 'i18n_invalid_file_type' => __( 'Invalid file type. Accepted types:', 'wp-job-manager' ),
205 ) );
206 }
207
208 wp_register_script( 'jquery-deserialize', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-deserialize/jquery.deserialize.js', array( 'jquery' ), '1.2.1', true );
209 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 );
210 wp_register_script( 'wp-job-manager-job-dashboard', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-dashboard.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
211 wp_register_script( 'wp-job-manager-job-application', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-application.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
212 wp_register_script( 'wp-job-manager-job-submission', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-submission.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
213 wp_localize_script( 'wp-job-manager-ajax-filters', 'job_manager_ajax_filters', $ajax_data );
214 wp_localize_script( 'wp-job-manager-job-dashboard', 'job_manager_job_dashboard', array(
215 'i18n_confirm_delete' => __( 'Are you sure you want to delete this listing?', 'wp-job-manager' ),
216 ) );
217
218 wp_enqueue_style( 'wp-job-manager-frontend', JOB_MANAGER_PLUGIN_URL . '/assets/css/frontend.css', array(), JOB_MANAGER_VERSION );
219 if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'submit_job_form' ) ) {
220 wp_enqueue_style( 'wp-job-manager-job-submission', JOB_MANAGER_PLUGIN_URL . '/assets/css/job-submission.css', array(), JOB_MANAGER_VERSION );
221 }
222 }
223 }
224
225 /**
226 * Add post type for Job Manager.
227 *
228 * @param array $types
229 * @return array
230 */
231 function job_manager_add_post_types( $types ) {
232 $types[] = 'job_listing';
233 return $types;
234 }
235 add_filter( 'post_types_to_delete_with_user', 'job_manager_add_post_types', 10 );
236
237 /**
238 * Main instance of WP Job Manager.
239 *
240 * Returns the main instance of WP Job Manager to prevent the need to use globals.
241 *
242 * @since 1.26
243 * @return WP_Job_Manager
244 */
245 function WPJM() {
246 return WP_Job_Manager::instance();
247 }
248
249 $GLOBALS['job_manager'] = WPJM();
250