wp-job-manager.php
| 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.21.4 |
| 7 | Author: Mike Jolley |
| 8 | Author URI: http://mikejolley.com |
| 9 | Requires at least: 4.1 |
| 10 | Tested up to: 4.1 |
| 11 | Text Domain: wp-job-manager |
| 12 | Domain Path: /languages |
| 13 | |
| 14 | Copyright: 2013 Mike Jolley |
| 15 | License: GNU General Public License v3.0 |
| 16 | License URI: http://www.gnu.org/licenses/gpl-3.0.html |
| 17 | */ |
| 18 | |
| 19 | // Exit if accessed directly |
| 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 21 | exit; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * WP_Job_Manager class. |
| 26 | */ |
| 27 | class WP_Job_Manager { |
| 28 | |
| 29 | /** |
| 30 | * Constructor - get the plugin hooked in and ready |
| 31 | */ |
| 32 | public function __construct() { |
| 33 | // Define constants |
| 34 | define( 'JOB_MANAGER_VERSION', '1.21.4' ); |
| 35 | define( 'JOB_MANAGER_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
| 36 | define( 'JOB_MANAGER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
| 37 | |
| 38 | // Includes |
| 39 | include( 'includes/class-wp-job-manager-post-types.php' ); |
| 40 | include( 'includes/class-wp-job-manager-ajax.php' ); |
| 41 | include( 'includes/class-wp-job-manager-shortcodes.php' ); |
| 42 | include( 'includes/class-wp-job-manager-api.php' ); |
| 43 | include( 'includes/class-wp-job-manager-forms.php' ); |
| 44 | include( 'includes/class-wp-job-manager-geocode.php' ); |
| 45 | include( 'includes/class-wp-job-manager-cache-helper.php' ); |
| 46 | |
| 47 | if ( is_admin() ) { |
| 48 | include( 'includes/admin/class-wp-job-manager-admin.php' ); |
| 49 | } |
| 50 | |
| 51 | // Init classes |
| 52 | $this->forms = new WP_Job_Manager_Forms(); |
| 53 | $this->post_types = new WP_Job_Manager_Post_Types(); |
| 54 | |
| 55 | // Activation - works with symlinks |
| 56 | register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), array( $this->post_types, 'register_post_types' ), 10 ); |
| 57 | register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), create_function( "", "include_once( 'includes/class-wp-job-manager-install.php' );" ), 10 ); |
| 58 | register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), 'flush_rewrite_rules', 15 ); |
| 59 | |
| 60 | // Actions |
| 61 | add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) ); |
| 62 | add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 ); |
| 63 | add_action( 'switch_theme', array( $this->post_types, 'register_post_types' ), 10 ); |
| 64 | add_action( 'switch_theme', 'flush_rewrite_rules', 15 ); |
| 65 | add_action( 'widgets_init', create_function( "", "include_once( 'includes/class-wp-job-manager-widgets.php' );" ) ); |
| 66 | add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) ); |
| 67 | add_action( 'admin_init', array( $this, 'updater' ) ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Handle Updates |
| 72 | */ |
| 73 | public function updater() { |
| 74 | if ( version_compare( JOB_MANAGER_VERSION, get_option( 'wp_job_manager_version' ), '>' ) ) { |
| 75 | include_once( 'includes/class-wp-job-manager-install.php' ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Localisation |
| 81 | */ |
| 82 | public function load_plugin_textdomain() { |
| 83 | $locale = apply_filters( 'plugin_locale', get_locale(), 'wp-job-manager' ); |
| 84 | |
| 85 | load_textdomain( 'wp-job-manager', WP_LANG_DIR . "/wp-job-manager/wp-job-manager-$locale.mo" ); |
| 86 | load_plugin_textdomain( 'wp-job-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Load functions |
| 91 | */ |
| 92 | public function include_template_functions() { |
| 93 | include( 'wp-job-manager-functions.php' ); |
| 94 | include( 'wp-job-manager-template.php' ); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Register and enqueue scripts and css |
| 99 | */ |
| 100 | public function frontend_scripts() { |
| 101 | $ajax_url = admin_url( 'admin-ajax.php', 'relative' ); |
| 102 | $ajax_filter_deps = array( 'jquery', 'jquery-deserialize' ); |
| 103 | |
| 104 | // WPML workaround until this is standardized |
| 105 | if ( defined( 'ICL_LANGUAGE_CODE' ) ) { |
| 106 | $ajax_url = add_query_arg( 'lang', ICL_LANGUAGE_CODE, $ajax_url ); |
| 107 | } |
| 108 | |
| 109 | if ( apply_filters( 'job_manager_chosen_enabled', true ) ) { |
| 110 | wp_register_script( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-chosen/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true ); |
| 111 | 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 ); |
| 112 | wp_register_script( 'wp-job-manager-multiselect', JOB_MANAGER_PLUGIN_URL . '/assets/js/multiselect.min.js', array( 'jquery', 'chosen' ), JOB_MANAGER_VERSION, true ); |
| 113 | wp_enqueue_style( 'chosen', JOB_MANAGER_PLUGIN_URL . '/assets/css/chosen.css' ); |
| 114 | $ajax_filter_deps[] = 'chosen'; |
| 115 | } |
| 116 | |
| 117 | if ( apply_filters( 'job_manager_ajax_file_upload_enabled', true ) ) { |
| 118 | wp_register_script( 'jquery-iframe-transport', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.iframe-transport.js', array( 'jquery' ), '1.8.3', true ); |
| 119 | wp_register_script( 'jquery-fileupload', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.fileupload.js', array( 'jquery', 'jquery-iframe-transport', 'jquery-ui-widget' ), '5.42.3', true ); |
| 120 | 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 ); |
| 121 | |
| 122 | ob_start(); |
| 123 | get_job_manager_template( 'form-fields/uploaded-file-html.php', array( 'name' => '', 'value' => '', 'extension' => 'jpg' ) ); |
| 124 | $js_field_html_img = ob_get_clean(); |
| 125 | |
| 126 | ob_start(); |
| 127 | get_job_manager_template( 'form-fields/uploaded-file-html.php', array( 'name' => '', 'value' => '', 'extension' => 'zip' ) ); |
| 128 | $js_field_html = ob_get_clean(); |
| 129 | |
| 130 | wp_localize_script( 'wp-job-manager-ajax-file-upload', 'job_manager_ajax_file_upload', array( |
| 131 | 'ajax_url' => $ajax_url, |
| 132 | 'js_field_html_img' => esc_js( str_replace( "\n", "", $js_field_html_img ) ), |
| 133 | 'js_field_html' => esc_js( str_replace( "\n", "", $js_field_html ) ), |
| 134 | 'i18n_invalid_file_type' => __( 'Invalid file type. Accepted types:', 'wp-job-manager' ) |
| 135 | ) ); |
| 136 | } |
| 137 | |
| 138 | wp_register_script( 'jquery-deserialize', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-deserialize/jquery.deserialize.js', array( 'jquery' ), '1.2.1', true ); |
| 139 | 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 ); |
| 140 | wp_register_script( 'wp-job-manager-job-dashboard', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-dashboard.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true ); |
| 141 | wp_register_script( 'wp-job-manager-job-application', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-application.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true ); |
| 142 | wp_register_script( 'wp-job-manager-job-submission', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-submission.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true ); |
| 143 | wp_localize_script( 'wp-job-manager-ajax-filters', 'job_manager_ajax_filters', array( |
| 144 | 'ajax_url' => $ajax_url, |
| 145 | 'is_rtl' => is_rtl() ? 1 : 0, |
| 146 | 'i18n_load_prev_listings' => __( 'Load previous listings', 'wp-job-manager' ) |
| 147 | ) ); |
| 148 | wp_localize_script( 'wp-job-manager-job-dashboard', 'job_manager_job_dashboard', array( |
| 149 | 'i18n_confirm_delete' => __( 'Are you sure you want to delete this listing?', 'wp-job-manager' ) |
| 150 | ) ); |
| 151 | |
| 152 | wp_enqueue_style( 'wp-job-manager-frontend', JOB_MANAGER_PLUGIN_URL . '/assets/css/frontend.css' ); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | $GLOBALS['job_manager'] = new WP_Job_Manager(); |