PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.64
Timetics – Appointment Booking Calendar & Scheduling v1.0.64
1.0.64 1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 All 65 releases
← All changes | base/role.php +13 -14 1.0.15 → 1.0.64 View file →
@@ -5,8 +5,10 @@
5 5 * @package Timetics
6 6 */
7 7 namespace Timetics\Base;
8 8
9 +defined( 'ABSPATH' ) || exit;
10 +
9 11 use Timetics\Utils\Singleton;
10 12
11 13 /**
12 14 * Class Role
@@ -33,13 +35,24 @@
33 35 public function register_role() {
34 36 $roles = $this->get_roles();
35 37
36 38 foreach ( $roles as $role ) {
39 + // add_role() is a no-op if the role already exists, so on upgrade an
40 + // existing timetics-staff role keeps whatever caps it had before —
41 + // prune anything no longer in the definition below.
42 + $existing = get_role( $role['name'] );
43 +
37 44 add_role(
38 45 $role['name'],
39 46 $role['display_name'],
40 47 $role['capabilities']
41 48 );
49 +
50 + if ( $existing ) {
51 + foreach ( array_diff( array_keys( $existing->capabilities ), array_keys( $role['capabilities'] ) ) as $stale_cap ) {
52 + $existing->remove_cap( $stale_cap );
53 + }
54 + }
42 55 }
43 56 }
44 57
45 58 /**
@@ -53,17 +66,9 @@
53 66 'name' => 'timetics-staff',
54 67 'display_name' => esc_html__( 'Staff', 'timetics' ),
55 68 'capabilities' => [
56 69 'read' => true,
57 - 'delete_posts' => true,
58 - 'delete_published_posts' => true,
59 - 'edit_posts' => true,
60 - 'publish_posts' => true,
61 70 'upload_files' => true,
62 - 'edit_pages' => true,
63 - 'edit_published_pages' => true,
64 - 'publish_pages' => true,
65 - 'delete_published_pages' => false,
66 71 'read_booking' => true,
67 72 'read_meeting' => true,
68 73 'edit_profile' => true,
69 74 'manage_timetics' => true,
@@ -147,13 +152,7 @@
147 152 $users = get_users( ['role' => 'timetics-staff'] );
148 153
149 154 foreach ( $users as $user ) {
150 155 $user->add_role('timetics-customer');
151 - }
152 -
153 - foreach ( $users as $user ) {
154 - if ( ! user_can( $user, 'delete_published_pages' ) ) {
155 - $user->add_cap( 'delete_published_pages', true );
156 - }
157 156 }
158 157 }
159 158 }