PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.12
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.12
1.1.12 1.1.11 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 All 36 releases
← All changes | includes/ai-copilot/jobs.php +37 -32 0.9.7 → 1.1.12 View file →
@@ -1,14 +1,17 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — AI Copilot WP-Cron jobs.
3 + * OpenStation — AI Copilot WP-Cron jobs.
4 4 *
5 5 * Registers the async comment-analysis hook that scores a comment for
6 - * spam/harmful content and stores the verdict in comment meta. The job is
7 - * scheduled by the Comments-window moderation feature (which is opt-in and
8 - * off by default) with a short delay so it runs outside the HTTP request that
9 - * triggered the comment.
6 + * spam/harmful content and stores the verdict in comment meta.
10 7 *
8 + * Nothing in the plugin schedules this hook: automatic comment scoring was
9 + * removed (`docs/migration-comments-ai-scoring.md`). The callback is kept
10 + * because the hook name is a frozen identifier that a site may still have
11 + * queued events for, and because an external plugin re-implementing the
12 + * feature can schedule it rather than re-deriving the prompt and schema.
13 + *
11 14 * Generation routes through the WordPress AI Client (`wp_ai_client_prompt()`),
12 15 * which sources credentials from Settings → Connectors — the copilot never
13 16 * handles an API key.
14 17 *
@@ -14,9 +17,9 @@
14 17 *
15 18 * Hook name:
16 19 * desktop_mode_ai_analyze_comment ($comment_id, $user_id)
17 20 *
18 - * @package WPDesktopMode
21 + * @package OpenStation
19 22 */
20 23
21 24 defined( 'ABSPATH' ) || exit;
22 25
@@ -26,21 +29,19 @@
26 29
27 30 /**
28 31 * Analyzes a comment and stores the result in comment meta.
29 32 *
30 - * @since 0.5.0
31 - *
32 33 * @param int $comment_id The comment ID.
33 34 * @param int $user_id The user to attribute the request to.
34 35 */
35 -function desktop_mode_ai_job_analyze_comment( $comment_id, $user_id ) {
36 +function openstation_ai_job_analyze_comment( $comment_id, $user_id ) {
36 37 $comment_id = (int) $comment_id;
37 38 $user_id = (int) $user_id;
38 39
39 40 // No usable text-generation provider is configured in Connectors — nothing
40 - // to do. The scheduler already checks this, but the job runs async so we
41 - // re-check to avoid emitting failed requests if the provider was removed.
42 - if ( ! desktop_mode_ai_provider_configured() ) {
41 + // to do. Whoever queued the event may have checked already, but the job runs
42 + // async, so re-check to avoid failed requests if the provider was removed.
43 + if ( ! openstation_ai_provider_configured() ) {
43 44 return;
44 45 }
45 46
46 47 $comment = get_comment( $comment_id );
@@ -47,17 +48,17 @@
47 48 if ( ! $comment instanceof WP_Comment ) {
48 49 return;
49 50 }
50 51
51 - $result = desktop_mode_ai_analyze_comment_now( $comment, $user_id );
52 + $result = openstation_ai_analyze_comment_now( $comment, $user_id );
52 53
53 54 if ( is_wp_error( $result ) ) {
54 55 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
55 - error_log( '[WP Desktop Mode AI] Comment ' . $comment_id . ' analysis failed: ' . $result->get_error_message() );
56 + error_log( '[WP OpenStation AI] Comment ' . $comment_id . ' analysis failed: ' . $result->get_error_message() );
56 57 return;
57 58 }
58 59
59 - desktop_mode_ai_save_meta( 'comment', $comment_id, $result );
60 + openstation_ai_save_meta( 'comment', $comment_id, $result );
60 61
61 62 /**
62 63 * Fires after a comment has been successfully analyzed by the AI copilot.
63 64 *
@@ -64,37 +65,30 @@
64 65 * The `$result` array always contains `topic`, `ai_summary`, `harmful`,
65 66 * and `spam`. Downstream plugins (e.g. a moderation helper) can act on
66 67 * `harmful` or `spam` here rather than polling meta.
67 68 *
68 - * @since 0.5.0
69 - *
70 69 * @param int $comment_id The comment ID.
71 70 * @param array $result The structured analysis result.
72 71 * @param WP_Comment $comment The comment object.
73 72 */
74 - do_action( 'desktop_mode_ai_comment_analyzed', $comment_id, $result, $comment );
73 + do_action( 'openstation_ai_comment_analyzed', $comment_id, $result, $comment );
75 74 }
76 -add_action( 'desktop_mode_ai_analyze_comment', 'desktop_mode_ai_job_analyze_comment', 10, 2 );
75 +add_action( 'desktop_mode_ai_analyze_comment', 'openstation_ai_job_analyze_comment', 10, 2 );
77 76
78 77 /**
79 78 * Runs the structured comment analysis through the AI Client.
80 79 *
81 - * Converts the chat-style prompt from {@see desktop_mode_ai_messages_for_comment()}
80 + * Converts the chat-style prompt from {@see openstation_ai_messages_for_comment()}
82 81 * into a system instruction + user prompt, requests JSON constrained to the
83 82 * comment schema, and decodes the result.
84 83 *
85 - * @since 0.9.4
86 - *
87 84 * @param WP_Comment $comment The comment to analyze.
88 - * @param int $user_id Requesting user id. Currently unused — the builder
89 - * is built from the prompt alone and the provider
90 - * comes from Connectors; retained for signature
91 - * stability and future attribution.
85 + * @param int $user_id Requesting user id.
92 86 * @return array|WP_Error Structured `{ topic, ai_summary, harmful, spam }` or an error.
93 87 */
94 -function desktop_mode_ai_analyze_comment_now( WP_Comment $comment, $user_id ) {
95 - $messages = desktop_mode_ai_messages_for_comment( $comment );
96 - $schema = desktop_mode_ai_schema_comment();
88 +function openstation_ai_analyze_comment_now( WP_Comment $comment, $user_id ) {
89 + $messages = openstation_ai_messages_for_comment( $comment );
90 + $schema = openstation_ai_schema_comment();
97 91
98 92 $system = '';
99 93 $prompt = '';
100 94 foreach ( $messages as $message ) {
@@ -109,11 +103,22 @@
109 103 $builder = wp_ai_client_prompt( $prompt );
110 104 if ( '' !== $system ) {
111 105 $builder = $builder->using_system_instruction( $system );
112 106 }
113 - // Provider + model are chosen by the Core AI Client; Desktop Mode pins neither.
107 + // Provider + model are chosen by the Core AI Client unless the
108 + // model-config filter says otherwise.
114 109
115 - $json = $builder->as_json_response( $schema )->generate_text();
110 + $builder = $builder->as_json_response( openstation_ai_normalize_response_schema( $schema ) );
111 + $builder = openstation_ai_apply_model_config(
112 + $builder,
113 + array(
114 + 'user_id' => (int) $user_id,
115 + 'source' => 'ai-copilot/comment-analysis',
116 + 'has_schema' => true,
117 + )
118 + );
119 +
120 + $json = $builder->generate_text();
116 121 if ( is_wp_error( $json ) ) {
117 122 return $json;
118 123 }
119 124
@@ -118,9 +123,9 @@
118 123 }
119 124
120 125 $result = json_decode( (string) $json, true );
121 126 if ( ! is_array( $result ) ) {
122 - return new WP_Error( 'desktop_mode_ai_bad_json', 'The AI response was not valid JSON.' );
127 + return new WP_Error( 'openstation_ai_bad_json', 'The AI response was not valid JSON.' );
123 128 }
124 129
125 130 return $result;
126 131 }