apply_filters( 'wpml_copy_post_to_language', int $post_id, string $target_language, bool $mark_as_duplicate )
- النوع
- filter
- الفئة
- إدراج المحتوى
- إصدار WPML
- 4.0.0
الوصف
يتيح خطّاف المرشِّح هذا للمطورين نسخ مقالة إلى لغة محددة باستخدام WPML. إذ يكرر المقالة إلى اللغة الهدف ويوفر خيار تعيينها كتكرار أو كترجمة.
الوسطاء
مثال على الاستخدام
في المثال أدناه، نستخدم المرشِّح لنسخ مقالة بالمعرف 1 إلى الفرنسية وتعيينها كنسخة مكررة من المقالة الأصلية.
مثال
$duplicate_post_id = apply_filters( 'wpml_copy_post_to_language', 1, 'fr', true );
في المثال المتقدم الذي تراه أدناه، نوضح كيفية تكرار مقالة معينة تلقائياً إلى جميع اللغات النشطة الأخرى على موقع WPML الخاص بك، باستثناء اللغة الأصلية للمقالة.
مثال متقدم
function myplugin_duplicate_copy_post_to_secondary_languages( $post_id, $mark_as_duplicate = false ) {
// Retrieve the post's element type, trid, and existing translations
$element_type = apply_filters( 'wpml_element_type', get_post_type( $post_id ) );
$trid = apply_filters( 'wpml_element_trid', null, $post_id, $element_type );
$translations = (array) apply_filters( 'wpml_get_element_translations', [], $trid, $element_type );
if ( ! $translations ) {
// Handle error or invalid values accordingly
return;
}
// Retrieve the active languages
$wpml_languages = (array) apply_filters('wpml_active_languages', [], 'orderby=id&order=desc');
foreach ( $wpml_languages as $language ) {
// Duplicate the post if no translation exists for the given language
if ( ! isset( $translations[ $language['language_code'] ] ) ) {
apply_filters(
'wpml_copy_post_to_language',
$post_id,
$language['language_code'],
$mark_as_duplicate
);
}
}
}
خطاطيف ذات صلة
wpml_set_element_language_details, wpml_make_post_duplicates, wpml_admin_make_post_duplicates, wpml_delete_package, wpml_import_get_trid_from_imported_translations, wpml_register_string, wpml_register_single_string, wpml_show_package_language_ui, wpml_delete_package_action