HEX
Server: nginx/1.22.1
System: Linux VM-16-9-centos 3.10.0-1160.99.1.el7.x86_64 #1 SMP Wed Sep 13 14:19:20 UTC 2023 x86_64
User: www (1001)
PHP: 7.3.31
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/softfox.com.cn/wp-content/plugins/wpjam-basic/extends/duplicate-post.php
<?php
/*
Name: 文章快速复制
URI: https://mp.weixin.qq.com/s/0W73N71wNJv10kMEjbQMGw
Description: 在后台文章列表添加一个快速复制按钮,复制一篇草稿用于快速新建。
Version: 1.0
*/
if(is_admin()){
	wpjam_register_list_table_action('quick_duplicate', [
		'title'		=> '快速复制',
		'response'	=> 'duplicate',
		'direct'	=> true,
		'data_type'	=> 'post_type',
		'post_type'	=> 'wpjam_post_type_duplicatable',
		'callback'	=> 'wpjam_duplicate_post'
	]);
}

function wpjam_post_type_duplicatable($post_type){
	if($post_type == 'attachment'){
		return false;
	}

	return apply_filters('wpjam_post_type_duplicatable', true, $post_type);
}

function wpjam_duplicate_post($post_id){
	$post_arr	= get_post($post_id, ARRAY_A);
	$post_arr	= array_except($post_arr, ['ID', 'post_date_gmt', 'post_modified_gmt', 'post_name']);

	$post_arr['post_status']	= 'draft';
	$post_arr['post_author']	= get_current_user_id();
	$post_arr['post_date']		= $post_arr['post_modified']	= wpjam_date('Y-m-d H:i:s');

	$post_arr['tax_input']		= [];

	foreach(get_object_taxonomies($post_arr['post_type']) as $taxonomy){
		$post_arr['tax_input'][$taxonomy]	= wp_get_object_terms($post_id, $taxonomy, ['fields' => 'ids']);
	}

	$new_post_id	= WPJAM_Post::insert($post_arr);

	if(!is_wp_error($new_post_id)){
		$meta_keys	= get_post_custom_keys($post_id) ?: [];

		foreach($meta_keys as $meta_key){
			if($meta_key == '_thumbnail_id' || ($meta_key != 'views' && !is_protected_meta($meta_key, 'post'))){
				foreach(get_post_meta($post_id, $meta_key) as $meta_value){
					add_post_meta($new_post_id, $meta_key, $meta_value, false);
				}
			}
		}
	}

	return $new_post_id;
}