-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSiteManagementTools.php
More file actions
89 lines (81 loc) · 3.73 KB
/
Copy pathSiteManagementTools.php
File metadata and controls
89 lines (81 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Site management MCP tools.
*
* @package WP_Forge
*/
namespace WP_Forge\Tools;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Registers user, settings, site info, and theme tools.
*/
trait SiteManagementTools {
/**
* Site management abilities.
*
* @return void
*/
private function add_site_abilities() {
$users_search_schema = function () {
return $this->schema(
array(
'search' => $this->string_prop( 'Search term.' ),
'role' => $this->enum_string_prop( 'Editable user role slug.', $this->get_editable_role_slugs() ),
'page' => $this->int_prop( 'Page number.', 1 ),
'per_page' => $this->int_prop( 'Users per page.', 10 ),
)
);
};
$this->add_ability( self::INTERNAL_PREFIX . 'user-search', 'Search Users', 'Search and filter WordPress users with pagination', $users_search_schema, function ( $params ) {
return $this->search_users( $params );
}, true, 'list_users' );
$user_get_schema = $this->schema( array( 'id' => $this->int_prop( 'User ID.' ) ), array( 'id' ) );
$user_write_schema = function () {
return $this->schema(
array(
'id' => $this->int_prop( 'User ID. Omit to create a new user.' ),
'username' => $this->string_prop( 'Username.' ),
'email' => $this->string_prop( 'Email address. Required when creating a user.' ),
'password' => $this->string_prop( 'Password. Required when creating a user.' ),
'first_name' => $this->string_prop( 'First name.' ),
'last_name' => $this->string_prop( 'Last name.' ),
'role' => $this->enum_string_prop( 'Editable user role slug.', $this->get_editable_role_slugs() ),
)
);
};
$this->add_ability( self::INTERNAL_PREFIX . 'user-get', 'Get User', 'Get a WordPress user by ID', $user_get_schema, function ( $params ) {
return $this->get_user( (int) $params['id'] );
}, true, 'list_users' );
$this->add_ability( self::INTERNAL_PREFIX . 'user-save', 'Save User', 'Create or update a WordPress user', $user_write_schema, function ( $params ) {
return $this->save_user( $params );
}, false, 'edit_users' );
$this->add_ability( self::INTERNAL_PREFIX . 'user-delete', 'Delete User', 'Delete a WordPress user by ID', $user_get_schema, function ( $params ) {
return $this->delete_user( (int) $params['id'] );
}, false, 'delete_users', array( 'destructive' => true, 'idempotent' => true ) );
$settings_schema = $this->schema(
array(
'blogname' => $this->string_prop( 'Site title.' ),
'blogdescription' => $this->string_prop( 'Tagline.' ),
'admin_email' => $this->string_prop( 'Administration email address.' ),
'timezone_string' => $this->string_prop( 'Timezone.' ),
'date_format' => $this->string_prop( 'Date format.' ),
'time_format' => $this->string_prop( 'Time format.' ),
'start_of_week' => $this->int_prop( 'Start of week.' ),
)
);
$this->add_ability( self::INTERNAL_PREFIX . 'general-settings-get', 'Get General Settings', 'Get WordPress general site settings', $this->schema(), function () {
return $this->get_general_settings();
}, true, 'manage_options' );
$this->add_ability( self::INTERNAL_PREFIX . 'general-settings-save', 'Save General Settings', 'Save WordPress general site settings', $settings_schema, function ( $params ) {
return $this->update_general_settings( $params );
}, false, 'manage_options', array( 'idempotent' => true ) );
$this->add_ability( self::INTERNAL_PREFIX . 'site-info-get', 'Get Site Info', 'Get detailed site information', $this->schema(), function () {
return $this->get_site_info();
} );
$this->add_ability( self::INTERNAL_PREFIX . 'theme-active-get', 'Get Active Theme', 'Get the active theme information', $this->schema(), function () {
return $this->get_active_theme();
} );
}
}