PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.9.8
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.9.8
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 0.9.8, at includes/agents/my-wordpress.php

72 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — Agents: site folder integration.
4 *
5 * Adds the "Agents" entity to the site folder window (via the
6 * `desktop_mode_my_wordpress_entities` filter) and ships the agents
7 * section config on the window's `config` payload (via
8 * `desktop_mode_my_wordpress_window_args`). The bundle side registers
9 * the `agent` entity-kind renderer.
10 *
11 * @package WPDesktopMode
12 */
13
14 defined( 'ABSPATH' ) || exit;
15
16 /**
17 * Append the Agents entity to the site folder's entity list.
18 *
19 * @param array $entities Existing entity descriptors.
20 * @return array
21 */
22 function desktop_mode_agents_my_wordpress_entity( $entities ) {
23 if ( ! is_array( $entities ) || ! desktop_mode_agents_user_can_read() ) {
24 return $entities;
25 }
26
27 $entities[] = array(
28 'id' => 'agents',
29 'label' => __( 'Agents', 'desktop-mode' ),
30 'icon' => desktop_mode_agent_avatar_url(),
31 'restPath' => 'desktop-mode/v1/agents',
32 'kind' => 'agent',
33 );
34
35 return $entities;
36 }
37 add_filter( 'desktop_mode_my_wordpress_entities', 'desktop_mode_agents_my_wordpress_entity' );
38
39 /**
40 * Ship the agents section config on the site folder window config.
41 *
42 * `aiAvailable` is the cheap structural check (WP 7.0 AI Client +
43 * Abilities API present); whether a connector is actually configured
44 * is probed live by the renderer against `aiStatusUrl`, mirroring the
45 * OS Settings Features tab, so a freshly configured connector is
46 * picked up without a reload.
47 *
48 * @param array $window_args Args passed to `desktop_mode_register_window()`.
49 * @return array
50 */
51 function desktop_mode_agents_my_wordpress_window_args( $window_args ) {
52 if ( ! is_array( $window_args ) || ! desktop_mode_agents_user_can_read() ) {
53 return $window_args;
54 }
55
56 if ( ! isset( $window_args['config'] ) || ! is_array( $window_args['config'] ) ) {
57 $window_args['config'] = array();
58 }
59
60 $window_args['config']['agents'] = array(
61 'canManage' => desktop_mode_agents_user_can_manage(),
62 'canInvoke' => desktop_mode_agents_user_can_invoke(),
63 'aiAvailable' => function_exists( 'desktop_mode_ai_is_available' ) && desktop_mode_ai_is_available(),
64 'aiStatusUrl' => esc_url_raw( rest_url( 'desktop-mode/v1/ai/status' ) ),
65 'connectorsUrl' => esc_url_raw( admin_url( 'options-connectors.php' ) ),
66 'runWindowId' => 'desktop-mode-agent-run',
67 );
68
69 return $window_args;
70 }
71 add_filter( 'desktop_mode_my_wordpress_window_args', 'desktop_mode_agents_my_wordpress_window_args' );
72