| Server IP : 43.141.50.122 / Your IP : 113.219.202.173 Web Server : Apache System : Linux VM-8-5-opencloudos 6.6.34-9.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 19 19:35:45 CST 2024 x86_64 User : www ( 1000) PHP Version : 8.1.27 Disable Function : 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 MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/wordpress/wordpress/wp-content/plugins/wpjam-basic/extends/ |
Upload File : |
<?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',
'callback' => 'wpjam_duplicate_post',
'post_type' => fn($ptype) => apply_filters('wpjam_post_type_duplicatable', $ptype != 'attachment', $ptype),
]);
}
function wpjam_duplicate_post($post_id){
$post_arr = get_post($post_id, ARRAY_A);
$post_arr = wpjam_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;
}