post_type ] ) ) { return; } $path = AJACO_DIR . 'assets/js/llms-editor.js'; if ( ! file_exists( $path ) ) { return; } wp_enqueue_script( 'ajaco-llms-editor', AJACO_URL . 'assets/js/llms-editor.js', array( 'wp-plugins', 'wp-editor', 'wp-element', 'wp-components', 'wp-data', 'wp-i18n' ), (string) filemtime( $path ), true ); wp_set_script_translations( 'ajaco-llms-editor', 'aj-agent-crawl-optimizer', AJACO_DIR . 'languages' ); // wp_localize_script() stringifies top-level scalars ('enabled' => false // would arrive as ""), and the panel needs a real boolean to tell "feature // is off" from "no payload" — so hand the data over as JSON instead. $data = array( 'enabled' => is_feature_enabled( 'llms_txt' ), 'llmsUrl' => esc_url_raw( home_url( '/llms.txt' ) ), ); wp_add_inline_script( 'ajaco-llms-editor', 'window.AjacoLlmsEditor = ' . wp_json_encode( $data ) . ';', 'before' ); } /** * Register the classic-editor metabox. * * Skipped when the screen is running the block editor — the sidebar panel is * already there, and two sets of controls writing the same meta is a bug farm. * * @param string $post_type Post type of the post being edited. * @param mixed $post The post being edited (unused). * @return void */ function add_llms_meta_box( string $post_type, $post = null ): void { unset( $post ); $types = llms_curatable_post_types(); if ( ! isset( $types[ $post_type ] ) ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( $screen instanceof \WP_Screen && method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) { return; } add_meta_box( LLMS_METABOX_ID, __( 'Agent Ready (llms.txt)', 'aj-agent-crawl-optimizer' ), __NAMESPACE__ . '\\render_llms_meta_box', $post_type, 'side', 'default' ); } /** * Render the classic-editor metabox: the same two controls as the block editor * sidebar panel. * * @param \WP_Post $post The post being edited. * @return void */ function render_llms_meta_box( \WP_Post $post ): void { wp_nonce_field( 'ajaco_llms_meta_' . $post->ID, LLMS_METABOX_NONCE ); $excluded = (bool) get_post_meta( $post->ID, LLMS_META_EXCLUDE, true ); $summary = (string) get_post_meta( $post->ID, LLMS_META_SUMMARY, true ); ?>
post_type ] ) ) { return; } // An unchecked checkbox is simply absent from the POST body. if ( empty( $_POST['ajaco_llms_include'] ) ) { update_post_meta( $post_id, LLMS_META_EXCLUDE, true ); } else { // Deleting (rather than storing a falsy value) keeps the default — // false — as the single source of truth for "not excluded". delete_post_meta( $post_id, LLMS_META_EXCLUDE ); } $raw = isset( $_POST['ajaco_llms_summary'] ) ? sanitize_textarea_field( wp_unslash( $_POST['ajaco_llms_summary'] ) ) : ''; $summary = sanitize_llms_summary_meta( $raw ); if ( '' === $summary ) { delete_post_meta( $post_id, LLMS_META_SUMMARY ); } else { update_post_meta( $post_id, LLMS_META_SUMMARY, $summary ); } // The meta hooks in llms-config.php flush the llms.txt caches for us. }