fix: wpai_meta_description
This commit is contained in:
@@ -26,6 +26,7 @@ class WPT_Content_Controller {
|
||||
add_filter( 'term_description', array( $this, 'translate_term_description' ), 20, 3 );
|
||||
add_filter( 'document_title_parts', array( $this, 'translate_document_title_parts' ), 20 );
|
||||
add_filter( 'wpai_meta_description', array( $this, 'translate_wordpress_ai_meta_description' ), 20 );
|
||||
add_filter( 'get_post_metadata', array( $this, 'translate_wordpress_ai_meta_description_metadata' ), 20, 4 );
|
||||
add_filter( 'wpseo_title', array( $this, 'translate_seo_title' ), 20 );
|
||||
add_filter( 'wpseo_metadesc', array( $this, 'translate_seo_description' ), 20 );
|
||||
add_filter( 'rank_math/frontend/title', array( $this, 'translate_seo_title' ), 20 );
|
||||
@@ -226,6 +227,14 @@ class WPT_Content_Controller {
|
||||
return $this->translated_value( $description, 'post:' . $post_id . ':meta:wpai_meta_description' );
|
||||
}
|
||||
|
||||
public function translate_wordpress_ai_meta_description_metadata( $value, $post_id, $meta_key, $single ) {
|
||||
if ( 'wpai_meta_description' !== $meta_key || ! $single || ! is_string( $value ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $this->translated_value( $value, 'post:' . $post_id . ':meta:wpai_meta_description' );
|
||||
}
|
||||
|
||||
public function translate_term_object( $term, $taxonomy, $context = '' ) {
|
||||
if ( ! $term instanceof WP_Term || ! in_array( $term->taxonomy, array( 'category', 'post_tag' ), true ) ) {
|
||||
return $term;
|
||||
|
||||
@@ -15,4 +15,19 @@ class DocumentTitleTest extends TestCase {
|
||||
|
||||
$this->assertSame( $parts, $controller->translate_document_title_parts( $parts ) );
|
||||
}
|
||||
|
||||
public function test_wordpress_ai_meta_description_metadata_uses_persisted_translation() {
|
||||
$store = new WPT_Test_Translation_Store();
|
||||
$description = 'Original description';
|
||||
$identity_key = WPT_Translation_Identity::key( $description, 'zh', 'en', 'post:42:meta:wpai_meta_description', 'baidu-vip-v1' );
|
||||
$store->values[ $identity_key ] = array( 'translated_value' => 'Translated description' );
|
||||
$controller = new WPT_Content_Controller( $store, new WPT_Test_Language_Router() );
|
||||
|
||||
$this->assertSame(
|
||||
'Translated description',
|
||||
$controller->translate_wordpress_ai_meta_description_metadata( $description, 42, 'wpai_meta_description', true )
|
||||
);
|
||||
$this->assertNull( $controller->translate_wordpress_ai_meta_description_metadata( null, 42, 'wpai_meta_description', true ) );
|
||||
$this->assertSame( $description, $controller->translate_wordpress_ai_meta_description_metadata( $description, 42, '_unrelated_meta', true ) );
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,20 @@ function is_singular() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_option( $option, $default = false ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
function wp_parse_args( $args, $defaults = array() ) {
|
||||
return array_merge( $defaults, $args );
|
||||
}
|
||||
|
||||
require_once dirname( __DIR__ ) . '/includes/interface-wpt-translation-provider.php';
|
||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-translation-result.php';
|
||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-translation-identity.php';
|
||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-translation-store.php';
|
||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-translation-service.php';
|
||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-baidu-provider.php';
|
||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-content-translator.php';
|
||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-settings.php';
|
||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-language-router.php';
|
||||
|
||||
Reference in New Issue
Block a user