*/ public static function abilities(): array { return [ new Ability( 'sarcio/site-info', __('Look at the site settings', 'sarcio'), Ability::READ, 'Basic facts about this WordPress site: name, tagline, URLs, WordPress version, active theme, whether WooCommerce is active, whether plugins may be installed (fileMods), the permalink structure and which pages are the front page and the posts page.', ['properties' => [], 'type' => 'object'], static fn (array $args): bool => current_user_can('edit_posts'), static fn (array $args): array => self::info(), ), ]; } public static function fileModsAllowed(): bool { return !(defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS); } public static function woocommerceActive(): bool { return class_exists('WooCommerce') && function_exists('wc_get_product'); } /** @return array */ public static function info(): array { $theme = function_exists('wp_get_theme') ? wp_get_theme() : null; return [ 'adminUrl' => admin_url(), 'fileMods' => self::fileModsAllowed(), 'frontPageId' => (int) get_option('page_on_front', 0), 'homeUrl' => home_url('/'), 'locale' => function_exists('get_locale') ? get_locale() : 'en_US', 'name' => html_entity_decode((string) get_bloginfo('name'), ENT_QUOTES | ENT_HTML5, 'UTF-8'), 'permalinkStructure' => (string) get_option('permalink_structure', ''), 'postsPageId' => (int) get_option('page_for_posts', 0), 'showOnFront' => (string) get_option('show_on_front', 'posts'), 'tagline' => html_entity_decode((string) get_bloginfo('description'), ENT_QUOTES | ENT_HTML5, 'UTF-8'), 'theme' => $theme !== null ? (string) $theme->get('Name') : '', 'timezone' => function_exists('wp_timezone_string') ? wp_timezone_string() : 'UTC', 'woocommerce' => self::woocommerceActive(), 'wpVersion' => (string) get_bloginfo('version'), ]; } /** What Sarcio is told about the site with every turn. */ public static function context(): array { $info = self::info(); $user = wp_get_current_user(); $roles = is_object($user) && isset($user->roles) && is_array($user->roles) ? array_values($user->roles) : []; return [ 'adminUrl' => $info['adminUrl'], 'applies' => Requests::canApply() ? 'self' : 'agency', 'fileMods' => $info['fileMods'], 'homeUrl' => $info['homeUrl'], 'locale' => $info['locale'], 'role' => (string) ($roles[0] ?? ''), 'siteName' => $info['name'], 'theme' => $info['theme'], 'timezone' => $info['timezone'], 'woocommerce' => $info['woocommerce'], 'wpVersion' => $info['wpVersion'], ]; } }