Skip to content

Commit 16178aa

Browse files
authored
WPML: Add custom fields to the config (#7588)
1 parent ae239a2 commit 16178aa

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

includes/wpml/class-custom-fields.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function init() {
3030
add_filter( 'wpml_sync_custom_field_copied_value', array( $this, 'update_lesson_course_before_copied' ), 10, 4 );
3131
add_filter( 'wpml_sync_custom_field_copied_value', array( $this, 'update_course_prerequisite_before_copied' ), 10, 4 );
3232
add_filter( 'wpml_sync_custom_field_copied_value', array( $this, 'update_quiz_id_before_copied' ), 10, 4 );
33+
add_filter( 'wpml_sync_custom_field_copied_value', array( $this, 'update_course_woocommerce_product_before_copied' ), 10, 4 );
3334
}
3435

3536
/**
@@ -133,4 +134,36 @@ public function update_quiz_id_before_copied( $copied_value, $post_id_from, $pos
133134

134135
return $this->get_object_id( $quiz_id, 'quiz', false, $target_language_code );
135136
}
137+
138+
/**
139+
* Update course WooCommerce product before copied.
140+
*
141+
* @since $$next-version$$
142+
*
143+
* @internal
144+
*
145+
* @param mixed $copied_value Copied value.
146+
* @param int $post_id_from Post ID from.
147+
* @param int $post_id_to Post ID to.
148+
* @param string $meta_key Meta key.
149+
* @return mixed
150+
*/
151+
public function update_course_woocommerce_product_before_copied( $copied_value, $post_id_from, $post_id_to, $meta_key ) {
152+
if ( '_course_woocommerce_product' !== $meta_key ) {
153+
return $copied_value;
154+
}
155+
156+
if ( empty( $copied_value ) ) {
157+
return $copied_value;
158+
}
159+
160+
$product_id = (int) $copied_value;
161+
162+
$target_language_code = $this->get_element_language_code( $post_id_to, 'course' );
163+
if ( ! $target_language_code ) {
164+
$target_language_code = $this->get_current_language();
165+
}
166+
167+
return $this->get_object_id( $product_id, 'product', false, $target_language_code );
168+
}
136169
}

tests/unit-tests/wpml/test-class-custom-fields.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,28 @@ public function testUpdateQuizIdBeforeCopied_WhenCalled_ReturnsMatchingCourseFor
100100

101101
$this->assertSame( 4, $actual );
102102
}
103+
104+
public function testUpdateCourseWooCommerceProductBeforeCopied_WhenCalled_ReturnsMatchingCourseForNewLesson() {
105+
/* Arrange. */
106+
$custom_fields = new Custom_Fields();
107+
108+
$language_code_filter = function () {
109+
return 'a';
110+
};
111+
add_filter( 'wpml_element_language_code', $language_code_filter, 10, 0 );
112+
113+
$object_id_fitler = function () {
114+
return 4;
115+
};
116+
add_filter( 'wpml_object_id', $object_id_fitler, 10, 0 );
117+
118+
/* Act. */
119+
$actual = $custom_fields->update_course_woocommerce_product_before_copied( 1, 2, 3, '_course_woocommerce_product' );
120+
121+
/* Clean up & Assert. */
122+
remove_filter( 'wpml_element_language_code', $language_code_filter );
123+
remove_filter( 'wpml_object_id', $object_id_fitler );
124+
125+
$this->assertSame( 4, $actual );
126+
}
103127
}

wpml-config.xml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
<wpml-config>
22
<custom-fields>
3+
<custom-field action="translate">_question_right_answer</custom-field>
4+
<custom-field action="translate">_question_wrong_answers</custom-field>
5+
<custom-field action="translate">_sensei_email_description</custom-field>
6+
<custom-field action="ignore">_quiz_id</custom-field>
7+
<custom-field action="ignore">category</custom-field>
8+
<custom-field action="ignore">number</custom-field>
9+
<custom-field action="ignore">_lesson_order</custom-field>
10+
<custom-field action="ignore">_question_order</custom-field>
311
<custom-field action="copy">_lesson_complexity</custom-field>
412
<custom-field action="copy">_lesson_length</custom-field>
513
<custom-field action="copy">_lesson_prerequisite</custom-field>
614
<custom-field action="copy">_lesson_course</custom-field>
715
<custom-field action="copy">_quiz_lesson</custom-field>
816
<custom-field action="copy">_lesson_quiz</custom-field>
9-
<custom-field action="ignore">_quiz_id</custom-field>
1017
<custom-field action="copy">_course_prerequisite</custom-field>
1118
<custom-field action="copy">_course_video_embed</custom-field>
1219
<custom-field action="copy">_course_featured</custom-field>
@@ -16,6 +23,35 @@
1623
<custom-field action="copy">_sensei_self_enrollment_not_allowed</custom-field>
1724
<custom-field action="copy">_open_access</custom-field>
1825
<custom-field action="copy">disable_notification</custom-field>
26+
<custom-field action="copy">_pagination</custom-field>
27+
<custom-field action="copy">_pass_required</custom-field>
28+
<custom-field action="copy">_question_grade</custom-field>
29+
<custom-field action="copy">_quiz_grade_type</custom-field>
30+
<custom-field action="copy">_quiz_has_questions</custom-field>
31+
<custom-field action="copy">_random_order</custom-field>
32+
<custom-field action="copy">_right_answer_count</custom-field>
33+
<custom-field action="copy">_show_questions</custom-field>
34+
<custom-field action="copy">_wrong_answer_count</custom-field>
35+
<custom-field action="copy">_lesson_preview</custom-field>
36+
<custom-field action="copy">_enable_quiz_reset</custom-field>
37+
<custom-field action="copy">_course_enrolment_version</custom-field>
38+
<custom-field action="copy">_answer_order</custom-field>
39+
<custom-field action="copy">_quiz_timer</custom-field>
40+
<custom-field action="copy">_enable_quiz_timer</custom-field>
41+
<custom-field action="copy">_course_woocommerce_product</custom-field>
42+
<custom-field action="copy">sensei_course_audience</custom-field>
43+
<custom-field action="copy">sensei_course_skill_level</custom-field>
44+
<custom-field action="copy">_course_expiration_length</custom-field>
45+
<custom-field action="copy">_course_expires_on_date</custom-field>
46+
<custom-field action="copy">_course_starts_on_date</custom-field>
47+
<custom-field action="copy">_sensei_email_identifier</custom-field>
48+
<custom-field action="copy">_sensei_email_is_pro</custom-field>
49+
<custom-field action="copy">_sensei_email_type</custom-field>
50+
<custom-field action="copy">_random_question_order</custom-field>
51+
<custom-field action="copy">_quiz_passmark</custom-field>
52+
<custom-field action="copy">_sensei_content_drip_type</custom-field>
53+
<custom-field action="copy">_sensei_already_published</custom-field>
54+
<custom-field action="copy">sensei_course_publish_lessons</custom-field>
1955
</custom-fields>
2056
<custom-types>
2157
<custom-type translate="1">course</custom-type>

0 commit comments

Comments
 (0)