ID ); $enabled = get_post_meta( $post->ID, GeoBlock::META_ENABLED, true ); $lock = (bool) get_post_meta( $post->ID, GeoBlock::META_LOCK, true ); $generated_at = get_post_meta( $post->ID, GeoBlock::META_GENERATED, true ); $prompt_addon = get_post_meta( $post->ID, GeoBlock::META_ADDON, true ) ?: ''; $global = SettingsPage::getSettings(); $has_api_key = ! empty( $global['api_keys'][ $global['provider'] ] ?? '' ); wp_nonce_field( 'bre_geo_save_' . $post->ID, 'bre_geo_nonce' ); ?>

trim( $parts[0] ), 'a' => trim( $parts[1] ), ); } } update_post_meta( $post_id, GeoBlock::META_FAQ, wp_json_encode( $faq, JSON_UNESCAPED_UNICODE ) ); if ( isset( $_POST['bre_geo_prompt_addon'] ) ) { update_post_meta( $post_id, GeoBlock::META_ADDON, sanitize_textarea_field( wp_unslash( $_POST['bre_geo_prompt_addon'] ) ) ); } } public function enqueue( string $hook ): void { if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ), true ) ) { return; } wp_enqueue_script( 'bre-geo-editor', BRE_URL . 'assets/geo-editor.js', array( 'jquery' ), BRE_VERSION, true ); } public function ajax_generate(): void { check_ajax_referer( 'bre_admin', 'nonce' ); if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error( __( 'Insufficient permissions.', 'bavarian-rank-engine' ) ); } $post_id = absint( wp_unslash( $_POST['post_id'] ?? 0 ) ); if ( ! $post_id || ! get_post( $post_id ) ) { wp_send_json_error( __( 'Post not found.', 'bavarian-rank-engine' ) ); } $geo = new GeoBlock(); if ( $geo->generate( $post_id, true ) ) { $meta = GeoBlock::getMeta( $post_id ); wp_send_json_success( array( 'summary' => $meta['summary'], 'bullets' => $meta['bullets'], 'faq' => $meta['faq'], ) ); } else { wp_send_json_error( __( 'Generation failed. Check API key and provider settings.', 'bavarian-rank-engine' ) ); } } public function ajax_clear(): void { check_ajax_referer( 'bre_admin', 'nonce' ); if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error( __( 'Insufficient permissions.', 'bavarian-rank-engine' ) ); } $post_id = absint( wp_unslash( $_POST['post_id'] ?? 0 ) ); if ( ! $post_id ) { wp_send_json_error( 'Invalid post ID' ); } delete_post_meta( $post_id, GeoBlock::META_SUMMARY ); delete_post_meta( $post_id, GeoBlock::META_BULLETS ); delete_post_meta( $post_id, GeoBlock::META_FAQ ); delete_post_meta( $post_id, GeoBlock::META_GENERATED ); wp_send_json_success(); } }