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