/** * Plugin Name: Genesis Aiko Forum & QAPage Engine (v5.5-Stable-Schema) * Description: Original v5.5 rendering engine with surgical schema upgrades. */ // ... [Keep gfe_initialize_forum_engine, gfe_enqueue_assets, gfe_handle_canonical_protection EXACTLY as in v5.5] ... function gfe_render_forum_layout_and_schema() { $post_id = get_the_ID(); if ( ! $post_id ) return; $post = get_post( $post_id ); $paged = isset( $_GET['cpage'] ) && (int) $_GET['cpage'] === 2 ? 2 : 1; $sort = sanitize_key( $_GET['comment_sort'] ?? '' ); $sort_order = ( $sort === 'oldest' ) ? 'ASC' : 'DESC'; $is_qa_mode = filter_var( get_post_meta( $post_id, 'gfe_is_qa_mode', true ), FILTER_VALIDATE_BOOLEAN ); $args = [ 'post_id' => $post_id, 'status' => 'approve', 'orderby' => 'comment_date_gmt', 'order' => $sort_order, ]; if ( $paged === 1 ) { $args['number'] = 50; $args['offset'] = 0; } else { $args['offset'] = 50; } $comments_query = new WP_Comment_Query(); $raw_comments = $comments_query->query( $args ); // Count top-level comments for accurate schema answerCount $total_top_level = get_comments( [ 'post_id' => $post_id, 'status' => 'approve', 'parent' => 0, 'count' => true ] ); if ( empty( $raw_comments ) ) return; // --- SCHEMA COMPILATION STEP (Modified) --- if ( $paged === 1 && $is_qa_mode ) { $permalink = esc_url_raw( get_permalink( $post ) ); $site_url = esc_url_raw( home_url( '/' ) ); $post_author_id = (int) $post->post_author; $admin_author_id = $site_url . '#author/' . $post_author_id; $qa_graph = [ "@context" => "https://schema.org", "@graph" => [ [ "@type" => "QAPage", "@id" => $permalink . '#qapage', "url" => $permalink, "isPartOf" => [ "@id" => $permalink . '#webpage' ], "mainEntity" => [ "@id" => $permalink . '#question' ] ], [ "@type" => "Question", "@id" => $permalink . '#question', "name" => wp_strip_all_tags( get_the_title( $post ) ), "text" => wp_strip_all_tags( get_the_excerpt( $post ) ?: wp_html_excerpt( $post->post_content, 160 ) ), "answerCount" => (int) $total_top_level, "dateCreated" => get_the_date( 'c', $post ), "author" => [ "@id" => $admin_author_id ] ] ] ]; $suggested_answers = []; $accepted_assigned = false; foreach ( $raw_comments as $s_comment ) { // Only include top-level answers in schema if ( (int)$s_comment->comment_parent !== 0 ) continue; $is_accepted = filter_var( get_comment_meta( $s_comment->comment_ID, 'gfe_accepted_answer', true ), FILTER_VALIDATE_BOOLEAN ); $answer_node = [ "@type" => "Answer", "@id" => $permalink . '#comment-' . $s_comment->comment_ID, "url" => get_comment_link( $s_comment ), "text" => wp_trim_words( wp_strip_all_tags( $s_comment->comment_content ), 80, '...' ), "datePublished" => get_comment_date( 'c', $s_comment ), "upvoteCount" => (int) get_comment_meta( $s_comment->comment_ID, 'gfe_comment_upvotes', true ) ]; $c_uid = (int) $s_comment->user_id; if ( $c_uid === $post_author_id ) { $answer_node['author'] = [ "@id" => $admin_author_id ]; } else { $answer_node['author'] = [ "@type" => "Person", "name" => wp_strip_all_tags( get_comment_author( $s_comment ) ) ]; if ( $c_author_url = get_comment_author_url( $s_comment ) ) { $answer_node['author']['url'] = esc_url_raw( $c_author_url ); } } if ( $is_accepted && ! $accepted_assigned ) { $qa_graph['@graph'][1]['acceptedAnswer'] = $answer_node; $accepted_assigned = true; } else { $suggested_answers[] = $answer_node; } } if ( ! empty( $suggested_answers ) ) { $qa_graph['@graph'][1]['suggestedAnswer'] = $suggested_answers; } echo "\n" . '' . "\n"; } // --- RECURSIVE HIERARCHICAL TREE COMPILER (Untouched v5.5) --- // ... [Original v5.5 logic follows] ... }5 Useful Motor Dry Run Protector Circuits Explained – Homemade Circuit Projects