$status ); if ( 'snoozed' === $status ) { $body['snoozeDays'] = 14; } if ( '' !== $reason ) { $body['feedback'] = $reason; } $res = Api::request( 'PATCH', '/api/v1/recommendations/' . rawurlencode( $id ), $body ); self::flush(); return $res; } /** * Mark a change live with up to 10 public page addresses. Never from a * staging copy; Outercite would refuse it anyway, since this call names * this copy's own address. * * @param string $id Outercite change id. * @param string[] $urls Public page addresses, up to 10. */ public static function mark_live( string $id, array $urls ): array { if ( Site::is_staging() ) { return array( 'ok' => false, 'status' => 0, 'data' => null, 'error' => __( 'This is a copy of the site at another address, so it never marks a change live.', 'outercite' ), ); } $urls = array_slice( array_values( array_unique( array_filter( array_map( 'trim', $urls ) ) ) ), 0, 10 ); $res = Api::request( 'POST', '/api/v1/changes/' . rawurlencode( $id ) . '/shipped', array( 'urls' => $urls ), Api::SITE_CURRENT ); self::flush(); return $res; } /** * The kinds of draft Outercite can write for a change, their credits, and * how the latest attempt since a moment ended. Never cached: it is polled. * * @param string $id Outercite change id. * @param string $since ISO time the attempt started, or empty. */ public static function drafts( string $id, string $since = '' ): array { $path = '/api/v1/changes/' . rawurlencode( $id ) . '/draft'; if ( '' !== $since ) { $path .= '?since=' . rawurlencode( $since ); } return Api::request( 'GET', $path ); } /** * Ask Outercite to write a draft. It answers at once and writes in the * background; poll drafts() with the start time it returns. * * @param string $id Outercite change id. * @param string $kind Kind of draft, such as page or faq. * @param string|null $existing The page's current text, to write only its missing sections. */ public static function start_draft( string $id, string $kind, ?string $existing = null ): array { $body = array( 'kind' => $kind ); if ( null !== $existing ) { $body['existingPage'] = $existing; } return Api::request( 'POST', '/api/v1/changes/' . rawurlencode( $id ) . '/draft', $body ); } /** * Which AI engines cited each page since it went live. Cached for an hour. * * @param array $pages Pages, up to 50. */ public static function results( array $pages ): array { if ( ! $pages ) { return array( 'ok' => true, 'status' => 200, 'data' => array(), 'error' => '', ); } $key = 'results:' . md5( (string) wp_json_encode( $pages ) ); $hit = get_transient( 'outercite_c_' . md5( $key ) ); if ( is_array( $hit ) ) { return $hit; } $res = Api::request( 'POST', '/api/v1/wordpress/results', array( 'pages' => array_slice( $pages, 0, 50 ) ) ); if ( $res['ok'] ) { set_transient( 'outercite_c_' . md5( $key ), $res, HOUR_IN_SECONDS ); self::remember_key( $key ); } return $res; } /** * The business facts Outercite holds, for markup and llms.txt. Cached for a day. */ public static function profile(): array { return self::cached( 'profile', '/api/v1/wordpress/profile', DAY_IN_SECONDS ); } /** * Whether AI visitor tracking is on for this workspace. */ public static function tracking(): array { return Api::request( 'GET', '/api/v1/wordpress/tracking' ); } /** * Turn AI visitor tracking on for this workspace. */ public static function enable_tracking(): array { return Api::request( 'POST', '/api/v1/wordpress/tracking', array() ); } }