$post_id, 'restPath' => '/outercite/v1/post/' . $post_id, 'restRoot' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'logoUrl' => OUTERCITE_URL . 'assets/logo.png', 'changesUrl' => admin_url( 'admin.php?page=outercite' ), ); } // Block editor. /** * Load the sidebar panel in the block editor for a linked post. */ public static function block_editor(): void { $post = get_post(); if ( ! $post || ! Links::change_for_post( $post->ID ) || ! current_user_can( Roles::BRIEFS ) ) { return; } wp_enqueue_script( 'outercite-editor-sidebar', OUTERCITE_URL . 'assets/editor-sidebar.js', array( 'wp-plugins', 'wp-element', 'wp-components', 'wp-data', 'wp-api-fetch', 'wp-edit-post', 'wp-editor', 'wp-notices', 'wp-dom-ready' ), outercite_asset_version( 'assets/editor-sidebar.js' ), true ); wp_localize_script( 'outercite-editor-sidebar', 'OutercitePost', self::script_data( $post->ID ) ); wp_enqueue_style( 'outercite-brief', OUTERCITE_URL . 'assets/brief.css', array(), outercite_asset_version( 'assets/brief.css' ) ); } // Classic editor. /** * Add the brief box to the classic editor for a linked post. * * @param string $post_type Post type being edited. * @param \WP_Post $post The post. */ public static function meta_box( $post_type, $post ): void { if ( ! $post instanceof \WP_Post || ! Links::change_for_post( $post->ID ) || ! current_user_can( Roles::BRIEFS ) ) { return; } add_meta_box( 'outercite-brief', __( 'Outercite brief', 'outercite' ), array( __CLASS__, 'render_meta_box' ), null, 'side', 'high', // The block editor has its own sidebar panel instead. array( '__back_compat_meta_box' => true ) ); } /** * Render the brief box in the classic editor. * * @param \WP_Post $post The post. */ public static function render_meta_box( \WP_Post $post ): void { $change_id = (string) Links::change_for_post( $post->ID ); echo '
' . esc_html( (string) get_post_meta( $post->ID, Links::TITLE, true ) ) . '
'; if ( Links::is_shipped( $post->ID ) ) { echo '' . esc_html__( 'Marked live. Outercite is checking the page and measuring AI answers.', 'outercite' ) . '
'; } if ( ! Connection::is_linked() ) { echo '' . esc_html__( 'This site is not connected to Outercite.', 'outercite' ) . '
' . esc_html( $brief['error'] ) . '
'; } echo '' . esc_html__( 'Open the full brief', 'outercite' ) . ''; if ( current_user_can( Roles::DRAFTS ) ) { echo ' | ' . esc_html__( 'Write it for me', 'outercite' ) . ''; } echo '
'; echo ''; } /** * Classic editor: the publish result, and the "is it live now?" question. */ public static function classic_notices(): void { $screen = get_current_screen(); if ( ! $screen || 'post' !== $screen->base || ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) ) { return; } $post_id = self::post_id_in_request(); if ( ! $post_id || ! Links::change_for_post( $post_id ) ) { return; } $notice = Publish::take_notice(); if ( $notice ) { printf( '%2$s
' . esc_html__( 'Is this change live now?', 'outercite' ) . ' '; echo esc_html( sprintf( /* translators: %s: change title */ __( 'You updated a page linked to "%s". Say yes once the change is on the published page. A small fix or typo does not need it.', 'outercite' ), (string) get_post_meta( $post_id, Links::TITLE, true ) ) ); echo '
'; foreach ( array( 'yes' => __( 'Yes, mark it live', 'outercite' ), 'no' => __( 'Not yet', 'outercite' ), ) as $answer => $label ) { echo '' . esc_html( $label ) . ' '; } echo '
' . esc_html( (string) get_post_meta( $post_id, Links::TITLE, true ) ) . '
'; $html .= $brief['ok'] && isset( $brief['data']['brief'] ) ? '' . esc_html( $brief['error'] ) . '
'; $html .= '' . esc_html__( 'Open the full brief', 'outercite' ) . ''; if ( current_user_can( Roles::DRAFTS ) ) { $html .= ' | ' . esc_html__( 'Write it for me', 'outercite' ) . ''; } $html .= '