do_action( 'wpml_admin_make_post_duplicates', int $master_post_id )
- ประเภท
- action
- หมวดหมู่
- การแทรกเนื้อหา
- เวอร์ชันของ WPML
- 3.2
คำอธิบาย
สร้างหรืออัปเดตโพสต์ที่ทำสำเนาจากโพสต์ “master” ฮุก action นี้สงวนไว้สำหรับการเรียกใช้งาน backend ของหน้าจัดการเว็บไซต์
อาร์กิวเมนต์
- $master_post_id
- (int) (จำเป็น) ID ของโพสต์ที่จะทำสำเนา ซึ่งอาจเป็นโพสต์ หน้า หรือโพสต์แบบกำหนดเอง “โพสต์หลัก” ไม่จำเป็นต้องอยู่ในภาษาเริ่มต้น
ตัวอย่างการใช้งาน
ตัวอย่าง
// this will create duplicates for the "Hello World!" post do_action( 'wpml_admin_make_post_duplicates', 1 );
ในตัวอย่างด้านล่าง เราจะทำสำเนาสำหรับโพสต์ หน้า หรือโพสต์แบบกำหนดเอง เมื่อเราคลิก “เผยแพร่” จากหน้าจัดการเว็บไซต์ “edit-post”
ตัวอย่างขั้นสูงเพิ่มเติม
add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
function my_duplicate_on_publish( $post_id ) {
global $post;
// don't save for autosave
if (is_null($post))
{
return $post_id;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
// dont save for revisions
if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
return $post_id;
}
// we need this to avoid recursion see add_action at the end
remove_action( 'wp_insert_post', 'my_duplicate_on_publish' );
// make duplicates if the post being saved:
// #1. is not a duplicate of another or
// #2. does not already have translations
$is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type );
if ( !$is_translated ) {
do_action( 'wpml_admin_make_post_duplicates', $post_id );
}
// must hook again - see remove_action further up
add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
}
ฮุกที่เกี่ยวข้อง
wpml_set_element_language_details, wpml_make_post_duplicates, wpml_copy_post_to_language, 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