PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.3
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.3
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / includes / agents / my-wordpress.php

my-wordpress.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.3, at includes/agents/my-wordpress.php

88 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Agents: WP Explorer integration.
4 *
5 * Adds the "Agents" entity to the WP Explorer window (via the
6 * `openstation_my_wordpress_entities` filter) and ships the agents
7 * section config on the window's `config` payload (via
8 * `openstation_my_wordpress_window_args`). The bundle side registers
9 * the `agent` entity-kind renderer.
10 *
11 * This file loads regardless of the `agents` extended option (see
12 * bootstrap.php) so the section is always discoverable. While the flag
13 * is off the config carries `enabled => false` and the renderer paints
14 * the section read-only — no REST call is attempted, because the
15 * routes are not registered.
16 *
17 * @package OpenStation
18 */
19
20 defined( 'ABSPATH' ) || exit;
21
22 /**
23 * Append the Agents entity to WP Explorer's entity list.
24 *
25 * @param array $entities Existing entity descriptors.
26 * @return array
27 */
28 function openstation_agents_my_wordpress_entity( $entities ) {
29 if ( ! is_array( $entities ) || ! openstation_agents_user_can_read() ) {
30 return $entities;
31 }
32
33 $entities[] = array(
34 'id' => 'agents',
35 'label' => __( 'Agents', 'desktop-mode' ),
36 'icon' => openstation_agent_avatar_url(),
37 'restPath' => 'desktop-mode/v1/agents',
38 'kind' => 'agent',
39 );
40
41 return $entities;
42 }
43 add_filter( 'openstation_my_wordpress_entities', 'openstation_agents_my_wordpress_entity' );
44
45 /**
46 * Ship the agents section config on the WP Explorer window config.
47 *
48 * `enabled` mirrors the `agents` extended option. When it is false the
49 * section still renders — every control disabled, nothing fetched —
50 * and offers `canEnable` users a way into the Features tab that turns
51 * the framework on. `canManage` / `canInvoke` stay the raw capability
52 * answers so that shell renders the same controls it would when the
53 * flag is on, just inert; the real gate is that the REST routes do not
54 * exist while off.
55 *
56 * `aiAvailable` is the cheap structural check (WP 7.0 AI Client +
57 * Abilities API present); whether a connector is actually configured
58 * is probed live by the renderer against `aiStatusUrl`, mirroring the
59 * OS Settings Features tab, so a freshly configured connector is
60 * picked up without a reload.
61 *
62 * @param array $window_args Args passed to `openstation_register_window()`.
63 * @return array
64 */
65 function openstation_agents_my_wordpress_window_args( $window_args ) {
66 if ( ! is_array( $window_args ) || ! openstation_agents_user_can_read() ) {
67 return $window_args;
68 }
69
70 if ( ! isset( $window_args['config'] ) || ! is_array( $window_args['config'] ) ) {
71 $window_args['config'] = array();
72 }
73
74 $window_args['config']['agents'] = array(
75 'enabled' => openstation_agents_enabled(),
76 'canEnable' => current_user_can( 'manage_options' ),
77 'canManage' => openstation_agents_user_can_manage(),
78 'canInvoke' => openstation_agents_user_can_invoke(),
79 'aiAvailable' => function_exists( 'openstation_ai_is_available' ) && openstation_ai_is_available(),
80 'aiStatusUrl' => esc_url_raw( rest_url( 'desktop-mode/v1/ai/status' ) ),
81 'connectorsUrl' => esc_url_raw( admin_url( 'options-connectors.php' ) ),
82 'runWindowId' => 'desktop-mode-agent-run',
83 );
84
85 return $window_args;
86 }
87 add_filter( 'openstation_my_wordpress_window_args', 'openstation_agents_my_wordpress_window_args' );
88