| 1 |
<?php |
| 2 |
|
| 3 |
namespace Templately\Admin; |
| 4 |
|
| 5 |
use Templately\Utils\Base; |
| 6 |
use Templately\Utils\Database; |
| 7 |
use Templately\Utils\Options; |
| 8 |
|
| 9 |
class Roles extends Base { |
| 10 |
/** |
| 11 |
* Database class |
| 12 |
* @var Database |
| 13 |
*/ |
| 14 |
protected $database; |
| 15 |
|
| 16 |
/** |
| 17 |
* Options class |
| 18 |
* @var Options |
| 19 |
*/ |
| 20 |
protected $options; |
| 21 |
|
| 22 |
public function __construct() { |
| 23 |
$this->database = new Database(); |
| 24 |
$this->options = new Options(); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Default Roles Capabilities |
| 29 |
* |
| 30 |
* @return array |
| 31 |
*/ |
| 32 |
public function defaults_capabilities(): array { |
| 33 |
$default_capabilities = [ |
| 34 |
'administrator' => [ |
| 35 |
'edit_templately_builder', |
| 36 |
'edit_templately_settings' |
| 37 |
], |
| 38 |
'editor' => [ |
| 39 |
], |
| 40 |
'author' => [ |
| 41 |
], |
| 42 |
'contributor' => [ |
| 43 |
] |
| 44 |
]; |
| 45 |
|
| 46 |
return apply_filters( 'templately_default_caps', $default_capabilities ); |
| 47 |
} |
| 48 |
|
| 49 |
public function setup( $remove = false ) { |
| 50 |
if ( $this->options->get_option( '_templately_caps_initialized', false ) && ! $remove ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
global $wp_roles; |
| 55 |
|
| 56 |
$capabilities = $this->defaults_capabilities(); |
| 57 |
|
| 58 |
if( $remove ) { |
| 59 |
unset( $capabilities['administrator'] ); |
| 60 |
} |
| 61 |
|
| 62 |
foreach ( $capabilities as $role => $caps ) { |
| 63 |
foreach ( $caps as $cap ) { |
| 64 |
if ( $remove ) { |
| 65 |
$wp_roles->remove_cap( $role, $cap ); |
| 66 |
continue; |
| 67 |
} |
| 68 |
|
| 69 |
$wp_roles->add_cap( $role, $cap ); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
$this->options->get_option( '_betterdocs_caps_initialized', ! $remove ); |
| 74 |
} |
| 75 |
} |