WPML
do_action( 'wpml_admin_make_post_duplicates', int $master_post_id )
类型
action
类别
插入内容
WPML 版本
3.2

说明

从“主”文章构建或更新复制的文章。此操作钩子专用于管理后台调用。

参数

$master_post_id
(int) (必填) 要从中复制的文章的 ID。它可以是文章、页面或自定义文章的 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

所有 10 个 插入内容 钩子 →