Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 60 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| SiteInfo | |
0.00% |
0 / 60 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| register_abilities | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
2 | |||
| get_plugins_info | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| get_active_theme_info | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| get_users_info | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | |
| 4 | namespace BLU\Abilities; |
| 5 | |
| 6 | /** |
| 7 | * SiteInfo ability for WordPress site information. |
| 8 | */ |
| 9 | class SiteInfo { |
| 10 | |
| 11 | /** |
| 12 | * Constructor - registers site info ability. |
| 13 | */ |
| 14 | public function __construct() { |
| 15 | $this->register_abilities(); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Register site info ability. |
| 20 | */ |
| 21 | private function register_abilities(): void { |
| 22 | blu_register_ability( |
| 23 | 'blu/get-site-info', |
| 24 | array( |
| 25 | 'label' => 'Get Site Info', |
| 26 | 'description' => 'Provides detailed information about the WordPress site like site name, url, description, admin email, plugins, themes, users, and more', |
| 27 | 'category' => 'blu-mcp', |
| 28 | 'input_schema' => array( |
| 29 | 'type' => 'object', |
| 30 | ), |
| 31 | 'execute_callback' => function () { |
| 32 | return blu_prepare_ability_response( 200, array( |
| 33 | 'site_name' => get_bloginfo( 'name' ), |
| 34 | 'site_url' => get_bloginfo( 'url' ), |
| 35 | 'site_description' => get_bloginfo( 'description' ), |
| 36 | 'site_admin_email' => get_bloginfo( 'admin_email' ), |
| 37 | 'wordpress_version' => get_bloginfo( 'version' ), |
| 38 | 'language' => get_bloginfo( 'language' ), |
| 39 | 'plugins' => $this->get_plugins_info(), |
| 40 | 'themes' => array( |
| 41 | 'active' => $this->get_active_theme_info(), |
| 42 | 'all' => wp_get_themes(), |
| 43 | ), |
| 44 | 'users' => $this->get_users_info(), |
| 45 | )); |
| 46 | }, |
| 47 | 'permission_callback' => fn() => current_user_can( 'manage_options' ), |
| 48 | 'meta' => array( |
| 49 | 'annotations' => array( |
| 50 | 'readonly' => true, |
| 51 | 'destructive' => false, |
| 52 | 'idempotent' => true, |
| 53 | ), |
| 54 | ), |
| 55 | ) |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get plugins information. |
| 61 | * |
| 62 | * @return array |
| 63 | */ |
| 64 | private function get_plugins_info(): array { |
| 65 | if ( ! function_exists( 'get_plugins' ) ) { |
| 66 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 67 | } |
| 68 | |
| 69 | $all_plugins = get_plugins(); |
| 70 | $active_plugins = get_option( 'active_plugins', array() ); |
| 71 | |
| 72 | $plugins = array(); |
| 73 | foreach ( $all_plugins as $plugin_path => $plugin_data ) { |
| 74 | $plugins[] = array( |
| 75 | 'name' => $plugin_data['Name'], |
| 76 | 'version' => $plugin_data['Version'], |
| 77 | 'active' => in_array( $plugin_path, $active_plugins, true ), |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | return $plugins; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Get active theme information. |
| 86 | * |
| 87 | * @return array |
| 88 | */ |
| 89 | private function get_active_theme_info(): array { |
| 90 | $theme = wp_get_theme(); |
| 91 | return array( |
| 92 | 'name' => $theme->get( 'Name' ), |
| 93 | 'version' => $theme->get( 'Version' ), |
| 94 | 'author' => $theme->get( 'Author' ), |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Get users information. |
| 100 | * |
| 101 | * @return array |
| 102 | */ |
| 103 | private function get_users_info(): array { |
| 104 | $users = get_users(); |
| 105 | $user_counts = count_users(); |
| 106 | |
| 107 | return array( |
| 108 | 'total' => $user_counts['total_users'], |
| 109 | 'roles' => $user_counts['avail_roles'], |
| 110 | ); |
| 111 | } |
| 112 | } |