纯代码实现给WordPress添加文章复制功能

[复制链接]
发表于 2025-11-7 20:41:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
在给wordpress添加内容时,偶然会碰到文章复制的功能,但是wordpress又没有这个功能。把下面一段代码添加到functions.php文件中,就可以实现这个功能
  1. /*
  2. * Function for post duplication. Dups appear as drafts. User is redirected to the edit screen
  3. */
  4. function rd_duplicate_post_as_draft(){
  5.   global $wpdb;
  6.   if (! ( isset( $_GET['post']) || isset( $_POST['post'])  || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) {
  7.     wp_die('No post to duplicate has been supplied!');
  8.   }
  9.   /*
  10.    * Nonce verification
  11.    */
  12.   if ( !isset( $_GET['duplicate_nonce'] ) || !wp_verify_nonce( $_GET['duplicate_nonce'], basename( __FILE__ ) ) )
  13.     return;
  14.   /*
  15.    * get the original post id
  16.    */
  17.   $post_id = (isset($_GET['post']) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
  18.   /*
  19.    * and all the original post data then
  20.    */
  21.   $post = get_post( $post_id );
  22.   /*
  23.    * if you don't want current user to be the new post author,
  24.    * then change next couple of lines to this: $new_post_author = $post
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
继续阅读请点击广告
回复

使用道具 举报

×
登录参与点评抽奖,加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表