commentmeta; } public function get_entity_id_column(): string { return 'comment_id'; } public function get_primary_table(): string { global $wpdb; return $wpdb->comments; } public function get_primary_id_column(): string { return 'comment_ID'; } public function get_cache_group(): string { return 'wpdo_comment_profile'; } public function get_delete_hook(): string { return 'delete_comment'; } public function extend_native_query( $query_object ): void { if ( ! ( $query_object instanceof WP_Comment_Query ) ) { return; } $wpdo_query = $query_object->query_vars['wpdo_meta_query'] ?? null; if ( empty( $wpdo_query ) || ! is_array( $wpdo_query ) ) { return; } // WP_Comment_Query 使用 comments_clauses filter add_filter( 'comments_clauses', function ( $clauses ) use ( $wpdo_query ) { $compiled = TMDO_Query_Compiler::compile( 'comment', $wpdo_query ); if ( ! empty( $compiled['joins'] ) ) { $clauses['join'] .= ' ' . implode( ' ', $compiled['joins'] ); } if ( ! empty( $compiled['where'] ) ) { $clauses['where'] .= ' AND (' . implode( ' AND ', $compiled['where'] ) . ')'; } return $clauses; }, 10, 1 ); } public function get_entity_ids_after( int $after_id, int $limit ): array { global $wpdb; return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM `{$wpdb->comments}` WHERE comment_ID > %d ORDER BY comment_ID ASC LIMIT %d", $after_id, $limit ) ) ?: array() ); } } // 註冊 pre_get_comments hook(unit test 下 add_action 未載入時跳過) if ( function_exists( 'add_action' ) ) { add_action( 'pre_get_comments', function ( $query ) { $adapter = TMDO_Entity_Registry::get_adapter( 'comment' ); if ( $adapter ) { $adapter->extend_native_query( $query ); } }, 10, 1 ); }