PluginProbe
Authorsy – Author Box, Multiple Authors, Guest Authors & Post Rating / trunk
Authorsy – Author Box, Multiple Authors, Guest Authors & Post Rating vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8
authorsy / base / role.php

role.php in Authorsy – Author Box, Multiple Authors, Guest Authors & Post Rating trunk, at base/role.php

94 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Register Custom Role
4 *
5 * @package Authorsy
6 */
7 namespace Authorsy\Base;
8 defined( 'ABSPATH' ) || exit;
9 use Authorsy\Utils\Singleton;
10
11 /**
12 * Class Role
13 */
14 class Role {
15 use Singleton;
16
17 /**
18 * Initialize
19 *
20 * @return void
21 */
22 public function init() {
23 $this->register_role();
24 $this->add_cap();
25 $this->set_role();
26 }
27
28 /**
29 * Register role for guest
30 *
31 * @return void
32 */
33 public function register_role() {
34 $roles = $this->get_roles();
35
36 foreach ( $roles as $role ) {
37 add_role(
38 $role['name'],
39 $role['display_name'],
40 $role['capabilities']
41 );
42 }
43 }
44
45 /**
46 * Get roles
47 *
48 * @return array
49 */
50 public function get_roles() {
51 $roles = [
52 [
53 'name' => 'authorsy-guest',
54 'display_name' => esc_html__( 'Guest', 'authorsy' ),
55 'capabilities' => [
56 'read' => true,
57 ],
58
59 ],
60 ];
61
62 return apply_filters( 'authorsy_guest_roles', $roles );
63 }
64
65 /**
66 * Add capabilites to a role
67 *
68 * @return void
69 */
70 public function add_cap() {
71 global $wp_roles;
72 $wp_roles->add_cap( 'administrator', 'manage_options' );
73
74 }
75
76
77
78 /**
79 * Set user role
80 *
81 * @return void
82 */
83 public function set_role() {
84
85 $users = get_users( ['role' => 'authorsy-guest'] );
86
87 foreach ( $users as $user ) {
88 if ( ! user_can( $user, 'delete_published_pages' ) ) {
89 $user->add_cap( 'delete_published_pages', true );
90 }
91 }
92 }
93 }
94