-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-job-manager-applications.php
227 lines (199 loc) · 7.09 KB
/
wp-job-manager-applications.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/**
* Plugin Name: WP Job Manager - Applications
* Plugin URI: https://wpjobmanager.com/add-ons/applications/
* Description: Lets candidates submit applications to jobs which are stored on the employers jobs page, rather than simply emailed. Works standalone with it's built in application form.
* Version: 2.4.0
* Author: Automattic
* Author URI: https://wpjobmanager.com
* Requires at least: 4.1
* Tested up to: 4.9
*
* WPJM-Product: wp-job-manager-applications
*
* Copyright: 2018 Automattic
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WP_Job_Manager_Applications class.
*/
class WP_Job_Manager_Applications {
const JOB_MANAGER_CORE_MIN_VERSION = '1.29.0';
/**
* __construct function.
*/
public function __construct() {
// Define constants
define( 'JOB_MANAGER_APPLICATIONS_VERSION', '2.4.0' );
define( 'JOB_MANAGER_APPLICATIONS_FILE', __FILE__ );
define( 'JOB_MANAGER_APPLICATIONS_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'JOB_MANAGER_APPLICATIONS_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
// Check requirements
if ( version_compare( phpversion(), '5.3', '<' ) ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
add_action( 'admin_notices', array( $this, 'php_admin_notice' ) );
}
return;
}
// Set up startup actions
add_action( 'plugins_loaded', array( $this, 'load_text_domain' ), 12 );
add_action( 'plugins_loaded', array( $this, 'init_plugin' ), 13 );
add_action( 'admin_notices', array( $this, 'version_check' ) );
// Activate
register_activation_hook( __FILE__, array( $this, 'install' ) );
}
/**
* Initializes plugin.
*/
public function init_plugin() {
if ( ! class_exists( 'WP_Job_Manager' ) ) {
return;
}
// Includes
include_once( 'includes/class-wp-job-manager-applications-post-types.php' );
include_once( 'includes/class-wp-job-manager-applications-apply.php' );
include_once( 'includes/class-wp-job-manager-applications-dashboard.php' );
include_once( 'includes/class-wp-job-manager-applications-past.php' );
include_once( 'includes/wp-job-manager-applications-functions.php' );
include_once( 'includes/class-wp-job-manager-applications-integration.php' );
include_once( 'includes/class-wp-job-manager-applications-privacy.php' );
// Init classes
$this->post_types = new WP_Job_Manager_Applications_Post_Types();
WP_Job_Manager_Applications_Privacy::init();
// Add actions
add_action( 'init', array( $this, 'load_admin' ), 12 );
add_action( 'after_setup_theme', array( $this, 'template_functions' ) );
add_action( 'admin_init', array( $this, 'updater' ) );
}
/**
* Checks WPJM core version.
*/
public function version_check() {
if ( ! class_exists( 'WP_Job_Manager' ) || ! defined( 'JOB_MANAGER_VERSION' ) ) {
$screen = get_current_screen();
if ( null !== $screen && 'plugins' === $screen->id ) {
$this->display_error( __( '<em>WP Job Manager - Applications</em> requires WP Job Manager to be installed and activated.', 'wp-job-manager-applications' ) );
}
} elseif (
/**
* Filters if WPJM core's version should be checked.
*
* @since 2.3.0
*
* @param bool $do_check True if the add-on should do a core version check.
* @param string $minimum_required_core_version Minimum version the plugin is reporting it requires.
*/
apply_filters( 'job_manager_addon_core_version_check', true, self::JOB_MANAGER_CORE_MIN_VERSION )
&& version_compare( JOB_MANAGER_VERSION, self::JOB_MANAGER_CORE_MIN_VERSION, '<' )
) {
$this->display_error( sprintf( __( '<em>WP Job Manager - Applications</em> requires WP Job Manager %s (you are using %s).', 'wp-job-manager-applications' ), self::JOB_MANAGER_CORE_MIN_VERSION, JOB_MANAGER_VERSION ) );
}
}
/**
* Display error message notice in the admin.
*
* @param string $message
*/
private function display_error( $message ) {
echo '<div class="error">';
echo '<p>' . $message . '</p>';
echo '</div>';
}
/**
* Output a notice when using an old non-supported version of PHP
*/
public function php_admin_notice() {
echo '<div class="error">';
echo '<p>Unfortunately, WP Job Manager Applications can not run on PHP versions older than 5.3. Read more information about <a href="http://www.wpupdatephp.com/update/">how you can update</a>.</p>';
echo '</div>';
}
/**
* Load template functions
*/
public function template_functions() {
include( 'includes/wp-job-manager-applications-template.php' );
}
/**
* Handle Updates
*/
public function updater() {
if ( version_compare( JOB_MANAGER_APPLICATIONS_VERSION, get_option( 'wp_job_manager_applications_version' ), '>' ) ) {
$this->install();
}
}
/**
* Install
*/
public function install() {
global $wp_roles;
if ( class_exists( 'WP_Roles' ) && ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
if ( is_object( $wp_roles ) ) {
$capabilities = $this->get_core_capabilities();
foreach ( $capabilities as $cap_group ) {
foreach ( $cap_group as $cap ) {
$wp_roles->add_cap( 'administrator', $cap );
}
}
}
wp_clear_scheduled_hook( 'job_applications_purge' );
wp_schedule_event( time(), 'daily', 'job_applications_purge' );
update_option( 'wp_job_manager_applications_version', JOB_MANAGER_APPLICATIONS_VERSION );
}
/**
* Get capabilities
*
* @return array
*/
public function get_core_capabilities() {
$capabilities = array();
$capability_types = array( 'job_application' );
foreach ( $capability_types as $capability_type ) {
$capabilities[ $capability_type ] = array(
// Post type
"edit_{$capability_type}",
"read_{$capability_type}",
"delete_{$capability_type}",
"edit_{$capability_type}s",
"edit_others_{$capability_type}s",
"publish_{$capability_type}s",
"read_private_{$capability_type}s",
"delete_{$capability_type}s",
"delete_private_{$capability_type}s",
"delete_published_{$capability_type}s",
"delete_others_{$capability_type}s",
"edit_private_{$capability_type}s",
"edit_published_{$capability_type}s",
// Terms
"manage_{$capability_type}_terms",
"edit_{$capability_type}_terms",
"delete_{$capability_type}_terms",
"assign_{$capability_type}_terms"
);
}
return $capabilities;
}
/**
* Localisation
*/
public function load_text_domain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'wp-job-manager-applications' );
load_textdomain( 'wp-job-manager-applications', WP_LANG_DIR . "/wp-job-manager-applications/wp-job-manager-applications-$locale.mo" );
load_plugin_textdomain( 'wp-job-manager-applications', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Init the admin area
*/
public function load_admin() {
if ( is_admin() && class_exists( 'WP_Job_Manager' ) ) {
include_once( 'includes/class-wp-job-manager-applications-admin.php' );
}
}
}
$GLOBALS['job_manager_applications'] = new WP_Job_Manager_Applications();