PluginProbe ʕ •ᴥ•ʔ
WP Job Manager / 2.4.7
WP Job Manager v2.4.7
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 1.16.0 1.16.1 1.17.0 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.21.0 1.21.1 1.21.2 1.21.3 1.21.4 1.22.0 1.22.1 1.22.2 1.22.3 1.23.0 1.23.1 1.23.10 1.23.11 1.23.12 1.23.13 1.23.2 1.23.3 1.23.4 1.23.5 1.23.6 1.23.7 1.23.8 1.23.9 1.24.0 1.24.0.1 1.25.0 1.25.0.1 1.25.1 1.25.1.1 1.25.2 1.25.2.1 1.25.3 1.25.3.1 1.26.0 1.26.0.1 1.26.1 1.26.1.1 1.26.2 1.26.2.1 1.27.0 1.27.0.1 1.28.0 1.28.0.1 1.29.0 1.29.0.1 1.29.1 1.29.1.1 1.29.2 1.29.2.1 1.29.3 1.29.3.1 1.3.0 1.3.1 1.30.0 1.30.0.1 1.30.1 1.30.1.1 1.30.2 1.30.2.1 1.31.0 1.31.0.1 1.31.1 1.31.1.1 1.31.2 1.31.3 1.32.0 1.32.1 1.32.2 1.32.3 1.33.0 1.33.1 1.33.2 1.33.3 1.33.4 1.33.5 1.34.0 1.34.1 1.34.2 1.34.3 1.34.4 1.34.5 1.35.0 1.35.1 1.35.2 1.35.3 1.36.0 1.36.1 1.36.2 1.37.0 1.38.0 1.38.1 1.39.0 1.4.0 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.7.1 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 1.9.1 1.9.2 1.9.3 2.0.0 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.4.1
wp-job-manager / includes / class-wp-job-manager-install.php
wp-job-manager / includes Last commit date
3rd-party 3 days ago abstracts 3 months ago admin 2 weeks ago emails 2 weeks ago forms 3 days ago helper 3 months ago promoted-jobs 3 days ago ui 2 weeks ago widgets 2 weeks ago class-access-token.php 2 years ago class-dev-tools.php 2 years ago class-guest-session.php 2 years ago class-guest-user.php 2 years ago class-job-dashboard-shortcode.php 6 months ago class-job-listing-stats.php 2 years ago class-job-overlay.php 2 years ago class-stats-dashboard.php 2 years ago class-stats-script.php 3 months ago class-stats.php 3 months ago class-wp-job-manager-ajax.php 2 months ago class-wp-job-manager-api.php 6 years ago class-wp-job-manager-blocks.php 2 weeks ago class-wp-job-manager-cache-helper.php 3 months ago class-wp-job-manager-category-walker.php 6 years ago class-wp-job-manager-com-api.php 2 years ago class-wp-job-manager-data-cleaner.php 2 years ago class-wp-job-manager-data-exporter.php 3 months ago class-wp-job-manager-dependency-checker.php 2 years ago class-wp-job-manager-email-notifications.php 2 years ago class-wp-job-manager-forms.php 5 years ago class-wp-job-manager-geocode.php 2 weeks ago class-wp-job-manager-install.php 2 years ago class-wp-job-manager-post-types.php 3 days ago class-wp-job-manager-recaptcha.php 6 months ago class-wp-job-manager-rest-api.php 2 months ago class-wp-job-manager-shortcodes.php 2 weeks ago class-wp-job-manager-usage-tracking-data.php 2 years ago class-wp-job-manager-usage-tracking.php 2 years ago class-wp-job-manager-widget.php 2 weeks ago class-wp-job-manager.php 3 months ago trait-singleton.php 2 years ago
class-wp-job-manager-install.php
220 lines
1 <?php
2 /**
3 * File containing the class WP_Job_Manager_Install.
4 *
5 * @package wp-job-manager
6 */
7
8 use WP_Job_Manager\Admin\Release_Notice;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Handles the installation of the WP Job Manager plugin.
16 *
17 * @since 1.0.0
18 */
19 class WP_Job_Manager_Install {
20
21 /**
22 * Installs WP Job Manager.
23 */
24 public static function install() {
25 global $wpdb;
26
27 self::init_user_roles();
28 self::default_terms();
29
30 $is_new_install = false;
31
32 // Fresh installs should be prompted to set up their instance.
33 if ( ! get_option( 'wp_job_manager_version' ) ) {
34 include_once JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-admin-notices.php';
35 WP_Job_Manager_Admin_Notices::add_notice( WP_Job_Manager_Admin_Notices::NOTICE_CORE_SETUP );
36 $is_new_install = true;
37 }
38
39 require_once __DIR__ . '/../lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php';
40
41 // On new installs display the usage tracking notice with one week delay and for existing installs display it right away.
42 if ( false === get_option( WP_Job_Manager_Usage_Tracking_Base::DISPLAY_ONCE_OPTION ) ) {
43 $time_to_show_notice = $is_new_install ? time() + WEEK_IN_SECONDS : time() - 10;
44 update_option( WP_Job_Manager_Usage_Tracking_Base::DISPLAY_ONCE_OPTION, $time_to_show_notice );
45 }
46
47 // Update featured posts ordering.
48 if ( version_compare( get_option( 'wp_job_manager_version', JOB_MANAGER_VERSION ), '1.22.0', '<' ) ) {
49 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- One time data update.
50 $wpdb->query( "UPDATE {$wpdb->posts} p SET p.menu_order = 0 WHERE p.post_type='job_listing';" );
51 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- One time data update.
52 $wpdb->query( "UPDATE {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id SET p.menu_order = -1 WHERE pm.meta_key = '_featured' AND pm.meta_value='1' AND p.post_type='job_listing';" );
53 }
54
55 // Update default term meta with employment types.
56 if ( version_compare( get_option( 'wp_job_manager_version', JOB_MANAGER_VERSION ), '1.28.0', '<' ) ) {
57 self::add_employment_types();
58 }
59
60 // Update legacy options.
61 if ( false === get_option( 'job_manager_submit_job_form_page_id', false ) && get_option( 'job_manager_submit_page_slug' ) ) {
62 $page_id = get_page_by_path( get_option( 'job_manager_submit_page_slug' ) )->ID;
63 update_option( 'job_manager_submit_job_form_page_id', $page_id );
64 }
65 if ( false === get_option( 'job_manager_job_dashboard_page_id', false ) && get_option( 'job_manager_job_dashboard_page_slug' ) ) {
66 $page_id = get_page_by_path( get_option( 'job_manager_job_dashboard_page_slug' ) )->ID;
67 update_option( 'job_manager_job_dashboard_page_id', $page_id );
68 }
69
70 // Scheduled hook was removed in 1.33.4.
71 if ( wp_next_scheduled( 'job_manager_clear_expired_transients' ) ) {
72 wp_clear_scheduled_hook( 'job_manager_clear_expired_transients' );
73 }
74
75 if ( $is_new_install ) {
76 $permalink_options = (array) json_decode( get_option( 'job_manager_permalinks', '[]' ), true );
77 $permalink_options['jobs_archive'] = '';
78 update_option( 'job_manager_permalinks', wp_json_encode( $permalink_options ) );
79
80 update_option( \WP_Job_Manager\Stats::OPTION_ENABLE_STATS, true );
81 \WP_Job_Manager_Admin_Notices::dismiss_notice( Release_Notice::NOTICE_ID );
82 }
83
84 \WP_Job_Manager\Stats::instance()->migrate_db();
85
86 delete_transient( 'wp_job_manager_addons_html' );
87 update_option( 'wp_job_manager_version', JOB_MANAGER_VERSION );
88 }
89
90 /**
91 * Initializes user roles.
92 */
93 private static function init_user_roles() {
94 $roles = wp_roles();
95
96 if ( is_object( $roles ) ) {
97 add_role(
98 'employer',
99 __( 'Employer', 'wp-job-manager' ),
100 [
101 'read' => true,
102 'edit_posts' => false,
103 'delete_posts' => false,
104 ]
105 );
106
107 $capabilities = self::get_core_capabilities();
108
109 foreach ( $capabilities as $cap_group ) {
110 foreach ( $cap_group as $cap ) {
111 $roles->add_cap( 'administrator', $cap );
112 }
113 }
114 }
115 }
116
117 /**
118 * Returns capabilities.
119 *
120 * @return array
121 */
122 private static function get_core_capabilities() {
123 return [
124 'core' => [
125 \WP_Job_Manager_Post_Types::CAP_MANAGE_LISTINGS,
126 ],
127 \WP_Job_Manager_Post_Types::PT_LISTING => [
128 \WP_Job_Manager_Post_Types::CAP_EDIT_LISTING,
129 \WP_Job_Manager_Post_Types::CAP_READ_LISTING,
130 \WP_Job_Manager_Post_Types::CAP_DELETE_LISTING,
131 \WP_Job_Manager_Post_Types::CAP_EDIT_LISTINGS,
132 \WP_Job_Manager_Post_Types::CAP_EDIT_OTHERS_LISTINGS,
133 \WP_Job_Manager_Post_Types::CAP_PUBLISH_LISTINGS,
134 \WP_Job_Manager_Post_Types::CAP_READ_PRIVATE_LISTINGS,
135 \WP_Job_Manager_Post_Types::CAP_DELETE_LISTINGS,
136 \WP_Job_Manager_Post_Types::CAP_DELETE_PRIVATE_LISTINGS,
137 \WP_Job_Manager_Post_Types::CAP_DELETE_PUBLISHED_LISTINGS,
138 \WP_Job_Manager_Post_Types::CAP_DELETE_OTHERS_LISTINGS,
139 \WP_Job_Manager_Post_Types::CAP_EDIT_PRIVATE_LISTINGS,
140 \WP_Job_Manager_Post_Types::CAP_EDIT_PUBLISHED_LISTINGS,
141 \WP_Job_Manager_Post_Types::CAP_MANAGE_LISTING_TERMS,
142 \WP_Job_Manager_Post_Types::CAP_EDIT_LISTING_TERMS,
143 \WP_Job_Manager_Post_Types::CAP_DELETE_LISTING_TERMS,
144 \WP_Job_Manager_Post_Types::CAP_ASSIGN_LISTING_TERMS,
145 ],
146 ];
147 }
148
149 /**
150 * Sets up the default WP Job Manager terms.
151 */
152 private static function default_terms() {
153 if ( 1 === intval( get_option( 'job_manager_installed_terms' ) ) ) {
154 return;
155 }
156
157 $taxonomies = self::get_default_taxonomy_terms();
158 foreach ( $taxonomies as $taxonomy => $terms ) {
159 foreach ( $terms as $term => $meta ) {
160 if ( ! get_term_by( 'slug', sanitize_title( $term ), $taxonomy ) ) {
161 $tt_package = wp_insert_term( $term, $taxonomy );
162 if ( is_array( $tt_package ) && isset( $tt_package['term_id'] ) && ! empty( $meta ) ) {
163 foreach ( $meta as $meta_key => $meta_value ) {
164 add_term_meta( $tt_package['term_id'], $meta_key, $meta_value );
165 }
166 }
167 }
168 }
169 }
170
171 update_option( 'job_manager_installed_terms', 1 );
172 }
173
174 /**
175 * Default taxonomy terms to set up in WP Job Manager.
176 *
177 * @return array Default taxonomy terms.
178 */
179 private static function get_default_taxonomy_terms() {
180 return [
181 \WP_Job_Manager_Post_Types::TAX_LISTING_TYPE => [
182 'Full Time' => [
183 'employment_type' => 'FULL_TIME',
184 ],
185 'Part Time' => [
186 'employment_type' => 'PART_TIME',
187 ],
188 'Temporary' => [
189 'employment_type' => 'TEMPORARY',
190 ],
191 'Freelance' => [
192 'employment_type' => 'CONTRACTOR',
193 ],
194 'Internship' => [
195 'employment_type' => 'INTERN',
196 ],
197 ],
198 ];
199 }
200
201 /**
202 * Adds the employment type to default job types when updating from a previous WP Job Manager version.
203 */
204 private static function add_employment_types() {
205 $taxonomies = self::get_default_taxonomy_terms();
206 $terms = $taxonomies[ \WP_Job_Manager_Post_Types::TAX_LISTING_TYPE ];
207
208 foreach ( $terms as $term => $meta ) {
209 $term = get_term_by( 'slug', sanitize_title( $term ), \WP_Job_Manager_Post_Types::TAX_LISTING_TYPE );
210 if ( $term ) {
211 foreach ( $meta as $meta_key => $meta_value ) {
212 if ( ! get_term_meta( (int) $term->term_id, $meta_key, true ) ) {
213 add_term_meta( (int) $term->term_id, $meta_key, $meta_value );
214 }
215 }
216 }
217 }
218 }
219 }
220