| @@ -1,89 +1,90 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace Booktics; | |
| 4 | - | |
| 5 | -class Role { | |
| 6 | - | |
| 7 | - /** | |
| 8 | - * Initialize roles and set them for users | |
| 9 | - * | |
| 10 | - * @return void | |
| 11 | - */ | |
| 12 | - public function init() { | |
| 13 | - $this->register_role(); | |
| 14 | - $this->set_role(); | |
| 15 | - } | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * Register role for team member | |
| 19 | - * | |
| 20 | - * @return void | |
| 21 | - */ | |
| 22 | - public function register_role() { | |
| 23 | - $roles = $this->get_roles(); | |
| 24 | - | |
| 25 | - foreach ( $roles as $role ) { | |
| 26 | - add_role( | |
| 27 | - $role['name'], | |
| 28 | - $role['display_name'], | |
| 29 | - $role['capabilities'] | |
| 30 | - ); | |
| 31 | - } | |
| 32 | - } | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * Get roles | |
| 36 | - * | |
| 37 | - * @return array | |
| 38 | - */ | |
| 39 | - public function get_roles() { | |
| 40 | - $roles = array( | |
| 41 | - array( | |
| 42 | - 'name' => 'booktics_team_member', | |
| 43 | - 'display_name' => esc_html__( 'Team Member', 'booktics' ), | |
| 44 | - 'capabilities' => array( | |
| 45 | - 'read' => true, | |
| 46 | - 'delete_posts' => true, | |
| 47 | - 'delete_published_posts' => true, | |
| 48 | - 'edit_posts' => true, | |
| 49 | - 'publish_posts' => true, | |
| 50 | - 'upload_files' => true, | |
| 51 | - 'edit_pages' => true, | |
| 52 | - 'edit_published_pages' => true, | |
| 53 | - 'publish_pages' => true, | |
| 54 | - 'delete_published_pages' => false, | |
| 55 | - 'read_booking' => true, | |
| 56 | - 'read_meeting' => true, | |
| 57 | - 'edit_profile' => true, | |
| 58 | - 'manage_options' => true, | |
| 59 | - | |
| 60 | - ), | |
| 61 | - ), | |
| 62 | - array( | |
| 63 | - 'name' => 'booktics_customer', | |
| 64 | - 'display_name' => esc_html__( 'Customer', 'booktics' ), | |
| 65 | - 'capabilities' => array( | |
| 66 | - 'read' => true, | |
| 67 | - ), | |
| 68 | - ), | |
| 69 | - ); | |
| 70 | - | |
| 71 | - return apply_filters( 'booktics_team_member_roles', $roles ); | |
| 72 | - } | |
| 73 | - | |
| 74 | - /** | |
| 75 | - * Set user role | |
| 76 | - * | |
| 77 | - * @return void | |
| 78 | - */ | |
| 79 | - public function set_role() { | |
| 80 | - $users = get_users( array( 'role' => 'administrator' ) ); | |
| 81 | - | |
| 82 | - foreach ( $users as $user ) { | |
| 83 | - $user->add_role( 'booktics_team_member' ); | |
| 84 | - $nickname = get_user_meta( $user->ID, 'nickname', true ); | |
| 85 | - update_user_meta( $user->ID, '_team_member_first_name', $nickname ); | |
| 86 | - update_user_meta( $user->ID, '_team_member_status', 'active' ); | |
| 87 | - } | |
| 88 | - } | |
| 89 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Booktics; | |
| 4 | + | |
| 5 | +class Role { | |
| 6 | + | |
| 7 | + /** | |
| 8 | + * Initialize roles and set them for users | |
| 9 | + * | |
| 10 | + * @return void | |
| 11 | + */ | |
| 12 | + public function init() { | |
| 13 | + $this->register_role(); | |
| 14 | + $this->set_role(); | |
| 15 | + } | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Register role for team member | |
| 19 | + * | |
| 20 | + * @return void | |
| 21 | + */ | |
| 22 | + public function register_role() { | |
| 23 | + $roles = $this->get_roles(); | |
| 24 | + | |
| 25 | + foreach ( $roles as $role ) { | |
| 26 | + add_role( | |
| 27 | + $role['name'], | |
| 28 | + $role['display_name'], | |
| 29 | + $role['capabilities'] | |
| 30 | + ); | |
| 31 | + } | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Get roles | |
| 36 | + * | |
| 37 | + * @return array | |
| 38 | + */ | |
| 39 | + public function get_roles() { | |
| 40 | + $roles = array( | |
| 41 | + array( | |
| 42 | + 'name' => 'booktics_team_member', | |
| 43 | + 'display_name' => esc_html__( 'Team Member', 'booktics' ), | |
| 44 | + 'capabilities' => array( | |
| 45 | + 'read' => true, | |
| 46 | + 'delete_posts' => true, | |
| 47 | + // 'delete_published_posts' => true, | |
| 48 | + 'edit_posts' => true, | |
| 49 | + 'publish_posts' => true, | |
| 50 | + 'upload_files' => true, | |
| 51 | + 'edit_pages' => true, | |
| 52 | + 'edit_published_pages' => true, | |
| 53 | + 'publish_pages' => true, | |
| 54 | + // 'delete_published_pages' => true, | |
| 55 | + 'read_booking' => true, | |
| 56 | + 'read_meeting' => true, | |
| 57 | + 'edit_profile' => true, | |
| 58 | + 'manage_options' => true, | |
| 59 | + | |
| 60 | + ), | |
| 61 | + ), | |
| 62 | + array( | |
| 63 | + 'name' => 'booktics_customer', | |
| 64 | + 'display_name' => esc_html__( 'Booktics Customer', 'booktics' ), | |
| 65 | + 'capabilities' => array( | |
| 66 | + 'read' => true, | |
| 67 | + 'edit_profile' => true, | |
| 68 | + ), | |
| 69 | + ), | |
| 70 | + ); | |
| 71 | + | |
| 72 | + return apply_filters( 'booktics_team_member_roles', $roles ); | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Set user role | |
| 77 | + * | |
| 78 | + * @return void | |
| 79 | + */ | |
| 80 | + public function set_role() { | |
| 81 | + $users = get_users( array( 'role' => 'administrator' ) ); | |
| 82 | + | |
| 83 | + foreach ( $users as $user ) { | |
| 84 | + $user->add_role( 'booktics_team_member' ); | |
| 85 | + $nickname = get_user_meta( $user->ID, 'nickname', true ); | |
| 86 | + update_user_meta( $user->ID, '_team_member_first_name', $nickname ); | |
| 87 | + update_user_meta( $user->ID, '_team_member_status', 'active' ); | |
| 88 | + } | |
| 89 | + } | |
| 90 | +} | |