diff --git a/class-jobs.php b/class-jobs.php index f0d6691..af997c7 100755 --- a/class-jobs.php +++ b/class-jobs.php @@ -29,7 +29,7 @@ public function __construct() { add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_action( 'add_meta_boxes_bbl_job', array( $this, 'add_meta_boxes_bbl_job' ), 999 ); add_action( 'admin_init', array( $this, 'admin_init' ) ); - add_action( 'babble_create_empty_translation', array( $this, 'create_empty_translation' ) ); + add_action( 'bbl_cron_create_empty_translations', array( $this, 'create_empty_translations' ) ); add_action( 'bbl_translation_post_meta_boxes', array( $this, 'bbl_translation_post_meta_boxes' ), 10, 3 ); add_action( 'bbl_translation_submit_meta_boxes', array( $this, 'bbl_translation_submit_meta_boxes' ), 10, 2 ); add_action( 'bbl_translation_terms_meta_boxes', array( $this, 'bbl_translation_terms_meta_boxes' ), 10, 2 ); @@ -1081,11 +1081,11 @@ public function get_job_objects( $job ) { } /** - * Create empty translations of a post for all languages. Called via WP-Cron on the `babble_create_empty_translation` hook. + * Create empty translations of a post for all languages. Called via WP-Cron on the `bbl_cron_create_empty_translations` hook. * * @param array $args Args array containing a `post_id` element. */ - public function create_empty_translation( array $args ) { + public function create_empty_translations( array $args ) { global $bbl_post_public; if ( !$post = get_post( $args['post_id'] ) ) { @@ -1130,9 +1130,9 @@ public function create_post_jobs( $post_id, array $lang_codes ) { if ( bbl_get_default_lang_code() == $lang_code ) continue; - if ( apply_filters( 'bbl_create_empty_translation', false, $post ) ) { + if ( apply_filters( 'bbl_trigger_create_empty_translations', false, $post ) ) { - wp_schedule_single_event( time(), 'babble_create_empty_translation', array( + wp_schedule_single_event( time(), 'bbl_cron_create_empty_translations', array( array( 'post_id' => $post->ID, ) diff --git a/class-post-public.php b/class-post-public.php index 889afac..0c2cb4f 100644 --- a/class-post-public.php +++ b/class-post-public.php @@ -1298,6 +1298,9 @@ public function get_shadow_post_types( $base_post_type ) { * Returns the post in a particular language, or the fallback content * if there's no post available. * + * @FIXME: Currently this function is broken by Babble_Jobs::create_empty_translations + * See: test_canonical_content_fallback + * * @param int|WP_Post $post Either a WP Post object, or a post ID * @param string $lang_code The language code for the required language * @param boolean $fallback If true: if a post is not available, fallback to the default language content (defaults to true) diff --git a/tests/test-translations.php b/tests/test-translations.php index 4a8f28f..8cb5342 100644 --- a/tests/test-translations.php +++ b/tests/test-translations.php @@ -133,4 +133,18 @@ public function test_term_translations() { } + public function test_canonical_content_fallback() { + $this->assertSame( 'en_US', get_locale() ); + + $en = $this->factory->post->create_and_get(); + // In normal operation, the create_empty_translations method is called on an immediate single cron job + $GLOBALS['bbl_jobs']->create_empty_translations($en->ID); + $fr = bbl_get_post_in_lang( $en->ID, 'fr_FR', true ); + + // @FIXME: These tests fail due to the interaction of Babble_Post_Public::get_post_in_lang and Babble_Jobs::create_empty_translations + $this->assertSame( $en->post_title, $fr->post_title ); + $this->assertSame( $en->post_content, $fr->post_content ); + + } + } diff --git a/translation-show-pre-translation.php b/translation-show-pre-translation.php index 99c337f..ea8a62e 100644 --- a/translation-show-pre-translation.php +++ b/translation-show-pre-translation.php @@ -26,4 +26,4 @@ */ -add_action( 'bbl_create_empty_translation', '__return_true' ); \ No newline at end of file +add_action( 'bbl_trigger_create_empty_translations', '__return_true' ); \ No newline at end of file