HEX
Server: nginx/1.16.1
System: Linux VM-0-14-centos 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User: www (1000)
PHP: 8.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/www.sceytyg.com/wp-content/plugins/wpjam-basic/extends/duplicate-post.php
<?php
/*
Name: 文章快速复制
URI: https://mp.weixin.qq.com/s/0W73N71wNJv10kMEjbQMGw
Description: 在后台文章列表添加一个快速复制按钮,复制一篇草稿用于快速新建。
Version: 1.0
*/
is_admin() && wpjam_register_list_table_action('quick_duplicate', [
	'title'		=> '快速复制',
	'response'	=> 'duplicate',
	'direct'	=> true,
	'data_type'	=> 'post_type',
	'callback'	=> 'wpjam_duplicate_post',
	'post_type'	=> fn($v) => $v != 'attachment' && wpjam_get_post_type_setting($v, 'duplicatable') !== false,
]);

function wpjam_duplicate_post($post_id){
	$data	= wpjam_except(get_post($post_id, ARRAY_A), ['ID', 'post_date_gmt', 'post_modified_gmt', 'post_name']);
	$added	= wpjam_try('WPJAM_Post::insert', array_merge($data, [
		'post_status'	=> 'draft',
		'post_author'	=> get_current_user_id(),
		'post_date'		=> wpjam_date('Y-m-d H:i:s'),
		'post_modified'	=> wpjam_date('Y-m-d H:i:s'),
		'tax_input'		=> wpjam_fill(get_object_taxonomies($data['post_type']), fn($tax)=> wp_get_object_terms($post_id, $tax, ['fields'=>'ids']))
	]));

	foreach(get_post_custom_keys($post_id) ?: [] as $key){
		if($key == '_thumbnail_id' || ($key != 'views' && !is_protected_meta($key, 'post'))){
			foreach(get_post_meta($post_id, $key) as $value){
				add_post_meta($added, $key, $value, false);
			}
		}
	}

	return $added;
}