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 +22 -10 1.0.2 → 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 /**
@@ -50,20 +63,12 @@
50 63 public function get_roles() {
51 64 $roles = [
52 65 [
53 66 'name' => 'timetics-staff',
54 - 'display_name' => __( 'Staff', 'timetics' ),
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,
@@ -71,9 +76,9 @@
71 76 ],
72 77 ],
73 78 [
74 79 'name' => 'timetics-customer',
75 - 'display_name' => __( 'Timetics Customer', 'timetics' ),
80 + 'display_name' => esc_html__( 'Timetics Customer', 'timetics' ),
76 81 'capabilities' => [
77 82 'read' => true,
78 83 ],
79 84 ],
@@ -140,7 +145,14 @@
140 145 $users = get_users( ['role' => 'administrator'] );
141 146
142 147 foreach( $users as $user ) {
143 148 $user->add_role('timetics-staff');
149 + $user->add_role('timetics-customer');
150 + }
151 +
152 + $users = get_users( ['role' => 'timetics-staff'] );
153 +
154 + foreach ( $users as $user ) {
155 + $user->add_role('timetics-customer');
144 156 }
145 157 }
146 158 }