Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 105
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Settings
0.00% covered (danger)
0.00%
0 / 105
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 register_abilities
0.00% covered (danger)
0.00%
0 / 104
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2declare( strict_types=1 );
3
4namespace BLU\Abilities;
5
6/**
7 * Settings abilities for WordPress site settings.
8 */
9class Settings {
10
11    /**
12     * Constructor - registers settings abilities.
13     */
14    public function __construct() {
15        $this->register_abilities();
16    }
17
18    /**
19     * Register settings abilities.
20     */
21    private function register_abilities(): void {
22        // Get settings
23        blu_register_ability(
24            'blu/get-general-settings',
25            array(
26                'label'               => 'Get General Settings',
27                'description'         => 'Get WordPress general site settings',
28                'category'            => 'blu-mcp',
29                'input_schema'        => array(
30                    'type' => 'object',
31                ),
32                'execute_callback'    => function () {
33                    $request = new \WP_REST_Request( 'GET', '/wp/v2/settings' );
34                    $response = rest_do_request( $request );
35                    return blu_standardize_rest_response( $response );
36                },
37                'permission_callback' => fn() => current_user_can( 'manage_options' ),
38                'meta'                => array(
39                    'annotations' => array(
40                        'readonly'     => true,
41                        'destructive'  => false,
42                        'idempotent'   => true,
43                    ),
44                ),
45            )
46        );
47
48        // Update settings
49        blu_register_ability(
50            'blu/update-general-settings',
51            array(
52                'label'               => 'Update General Settings',
53                'description'         => 'Update WordPress general site settings',
54                'category'            => 'blu-mcp',
55                'input_schema'        => array(
56                    'type'       => 'object',
57                    'properties' => array(
58                        'title'                  => array(
59                            'type'        => 'string',
60                            'description' => 'Site title',
61                        ),
62                        'description'            => array(
63                            'type'        => 'string',
64                            'description' => 'Site tagline/description',
65                        ),
66                        'timezone_string'        => array(
67                            'type'        => 'string',
68                            'description' => 'Site timezone',
69                        ),
70                        'date_format'            => array(
71                            'type'        => 'string',
72                            'description' => 'Date format',
73                        ),
74                        'time_format'            => array(
75                            'type'        => 'string',
76                            'description' => 'Time format',
77                        ),
78                        'start_of_week'          => array(
79                            'type'        => 'integer',
80                            'description' => 'Start of week (0 = Sunday, 1 = Monday, etc.)',
81                        ),
82                        'language'               => array(
83                            'type'        => 'string',
84                            'description' => 'Site language',
85                        ),
86                        'use_smilies'            => array(
87                            'type'        => 'boolean',
88                            'description' => 'Convert emoticons to graphics',
89                        ),
90                        'default_category'       => array(
91                            'type'        => 'integer',
92                            'description' => 'Default post category',
93                        ),
94                        'default_post_format'    => array(
95                            'type'        => 'string',
96                            'description' => 'Default post format',
97                        ),
98                        'posts_per_page'         => array(
99                            'type'        => 'integer',
100                            'description' => 'Number of posts to show per page',
101                        ),
102                        'default_comment_status' => array(
103                            'type'        => 'string',
104                            'description' => 'Default comment status (open/closed)',
105                        ),
106                        'default_ping_status'    => array(
107                            'type'        => 'string',
108                            'description' => 'Default ping status (open/closed)',
109                        ),
110                    ),
111                ),
112                'execute_callback'    => function ( $input = null ) {
113                    $request = new \WP_REST_Request( 'POST', '/wp/v2/settings' );
114                    if ( $input ) {
115                        $request->set_body_params( $input );
116                    }
117                    $response = rest_do_request( $request );
118                    return blu_standardize_rest_response( $response );
119                },
120                'permission_callback' => fn() => current_user_can( 'manage_options' ),
121                'meta'                => array(
122                    'annotations' => array(
123                        'readonly'     => false,
124                        'destructive'  => false,
125                        'idempotent'   => true,
126                    ),
127                ),
128            )
129        );
130    }
131}