76c01e44df
對齊 A v3.2.0。型別強制會把隱式轉換變成 TypeError,所以一次全檔加入 並跑完整測試(unit 451 / integration 398 全綠,無迴歸)。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
92 lines
2.7 KiB
PHP
92 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* TMDO_Adapter_Term - Term 實體適配器
|
|
*
|
|
* @package WP_Data_Optimizer
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
// phpcs:disable Squiz.Commenting,Generic.Commenting,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber,Generic.CodeAnalysis.UnusedFunctionParameter,Generic.CodeAnalysis.EmptyStatement,Squiz.PHP.DisallowMultipleAssignments,Squiz.PHP.DisallowSizeFunctionsInLoops,WordPress.WP.I18n.MissingTranslatorsComment,WordPress.PHP.NoSilencedErrors,WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents,Squiz.PHP.CommentedOutCode,Universal.NamingConventions.NoReservedKeywordParameterNames,WordPress.PHP.YodaConditions,Squiz.Commenting.InlineComment.InvalidEndChar -- PR-1 ported from UAE; cleanup PR scheduled.
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
final class TMDO_Adapter_Term implements TMDO_Entity_Adapter_Interface {
|
|
|
|
public function get_entity_type(): string {
|
|
return 'term';
|
|
}
|
|
|
|
public function get_native_meta_table(): string {
|
|
global $wpdb;
|
|
return $wpdb->termmeta;
|
|
}
|
|
|
|
public function get_entity_id_column(): string {
|
|
return 'term_id';
|
|
}
|
|
|
|
public function get_primary_table(): string {
|
|
global $wpdb;
|
|
return $wpdb->terms;
|
|
}
|
|
|
|
public function get_primary_id_column(): string {
|
|
return 'term_id';
|
|
}
|
|
|
|
public function get_cache_group(): string {
|
|
return 'wpdo_term_profile';
|
|
}
|
|
|
|
public function get_delete_hook(): string {
|
|
return 'delete_term';
|
|
}
|
|
|
|
public function extend_native_query( $query_object ): void {
|
|
// Term 查詢使用 terms_clauses filter,不使用 $query_object
|
|
}
|
|
|
|
/**
|
|
* Term 特有:透過 terms_clauses filter 注入
|
|
*/
|
|
public function extend_term_clauses( array $clauses, array $taxonomies, array $args ): array {
|
|
if ( empty( $args['wpdo_meta_query'] ) || ! is_array( $args['wpdo_meta_query'] ) ) {
|
|
return $clauses;
|
|
}
|
|
return TMDO_Query_Compiler::inject_into_terms_clauses( $clauses, $args['wpdo_meta_query'] );
|
|
}
|
|
|
|
public function get_entity_ids_after( int $after_id, int $limit ): array {
|
|
global $wpdb;
|
|
|
|
return array_map(
|
|
'intval',
|
|
$wpdb->get_col(
|
|
$wpdb->prepare(
|
|
"SELECT term_id FROM `{$wpdb->terms}` WHERE term_id > %d ORDER BY term_id ASC LIMIT %d",
|
|
$after_id,
|
|
$limit
|
|
)
|
|
) ?: array()
|
|
);
|
|
}
|
|
}
|
|
|
|
// 註冊 terms_clauses filter(unit test 下 add_filter 未載入時跳過)
|
|
if ( function_exists( 'add_filter' ) ) {
|
|
add_filter(
|
|
'terms_clauses',
|
|
function ( $clauses, $taxonomies, $args ) {
|
|
$adapter = TMDO_Entity_Registry::get_adapter( 'term' );
|
|
if ( $adapter instanceof TMDO_Adapter_Term ) {
|
|
return $adapter->extend_term_clauses( $clauses, $taxonomies, $args );
|
|
}
|
|
return $clauses;
|
|
},
|
|
10,
|
|
3
|
|
);
|
|
}
|