Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 加上「;“重复”;自定义post类型管理菜单_Php_Wordpress_Custom Post Type - Fatal编程技术网

Php 加上「;“重复”;自定义post类型管理菜单

Php 加上「;“重复”;自定义post类型管理菜单,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,我正在尝试将“复制”post选项添加到名为“事件”的自定义post类型管理菜单中。我在网上搜索过,但是关于如何将此函数添加到自定义帖子类型的文档很少。也许我在搜索时使用了不正确的术语 下面的代码添加了“复制”功能,但是当单击它时,它实际上并不复制文章,而是返回一个白色屏幕。你能给我一些建议或提示吗 function rd_duplicate_post_link( $actions, $post ) { if (current_user_can('edit_posts') || $post

我正在尝试将“复制”post选项添加到名为“事件”的自定义post类型管理菜单中。我在网上搜索过,但是关于如何将此函数添加到自定义帖子类型的文档很少。也许我在搜索时使用了不正确的术语

下面的代码添加了“复制”功能,但是当单击它时,它实际上并不复制文章,而是返回一个白色屏幕。你能给我一些建议或提示吗

function rd_duplicate_post_link( $actions, $post ) {
    if (current_user_can('edit_posts') || $post->post_type=='events') {
        $actions['duplicate'] = '<a href="' . wp_nonce_url('admin.php?action=rd_duplicate_post_as_draft&post=' . $post->ID, basename(__FILE__), 'duplicate_nonce' ) . '" title="Duplicate this item" rel="permalink">Duplicate</a>';
    }
    return $actions;
}

add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2)
函数rd\u duplicate\u post\u链接($actions,$post){
如果(当前用户可以('edit_posts')||$post->post_type=='events')){
$actions['duplicate']='';
}
返回$actions;
}
添加过滤器(“页面、行、动作”、“重复、发布链接”,10,2)

您需要调用
管理操作\u rd\u复制\u post\u as\u草稿
hook

function rd_duplicate_post_link( $actions, $post ) {

    //print_r($actions);
    //if (current_user_can('edit_posts') || $post->post_type=='movies') {
        $actions['duplicate'] = '<a href="' . wp_nonce_url('admin.php?action=rd_duplicate_post_as_draft&post=' . $post->ID, basename(__FILE__), 'duplicate_nonce' ) . '" title="Duplicate this item" rel="permalink">Duplicate</a>';
   // }
    return $actions;
}

add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);



add_action( 'admin_action_rd_duplicate_post_as_draft', 'dt_dpp_post_as_draft' ); 

  function dt_dpp_post_as_draft()
    {
          global $wpdb;

          /*sanitize_GET POST REQUEST*/
          $post_copy = sanitize_text_field( $_POST["post"] );
          $get_copy = sanitize_text_field( $_GET['post'] );
          $request_copy = sanitize_text_field( $_REQUEST['action'] );

          $opt = get_option('dpp_wpp_page_options');
          $suffix = !empty($opt['dpp_post_suffix']) ? ' -- '.$opt['dpp_post_suffix'] : '';
          $post_status = !empty($opt['dpp_post_status']) ? $opt['dpp_post_status'] : 'draft';
          $redirectit = !empty($opt['dpp_post_redirect']) ? $opt['dpp_post_redirect'] : 'to_list';

            if (! ( isset( $get_copy ) || isset( $post_copy ) || ( isset($request_copy) && 'dt_dpp_post_as_draft' == $request_copy ) ) ) {
            wp_die('No post!');
            }
            $returnpage = '';

            /* Get post id */
            $post_id = (isset($get_copy) ? $get_copy : $post_copy );

            $post = get_post( $post_id );

            $current_user = wp_get_current_user();
            $new_post_author = $current_user->ID;

            /*Create the post Copy */
            if (isset( $post ) && $post != null) {
                /* Post data array */
                $args = array('comment_status' => $post->comment_status,
                'ping_status' => $post->ping_status,
                'post_author' => $new_post_author,
                'post_content' => $post->post_content,
                'post_excerpt' => $post->post_excerpt,
                'post_name' => $post->post_name,
                'post_parent' => $post->post_parent,
                'post_password' => $post->post_password,
                'post_status' => $post_status,
                'post_title' => $post->post_title.$suffix,
                'post_type' => $post->post_type,
                'to_ping' => $post->to_ping,
                'menu_order' => $post->menu_order

               );
               $new_post_id = wp_insert_post( $args );

               $taxonomies = get_object_taxonomies($post->post_type);
               if(!empty($taxonomies) && is_array($taxonomies)):
               foreach ($taxonomies as $taxonomy) {
                  $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs'));
                  wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);}
               endif;

               $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id");
               if (count($post_meta_infos)!=0) {
               $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
               foreach ($post_meta_infos as $meta_info) {
                  $meta_key = $meta_info->meta_key;
                  $meta_value = addslashes($meta_info->meta_value);
                  $sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'";
                  }
                    $sql_query.= implode(" UNION ALL ", $sql_query_sel);
                    $wpdb->query($sql_query);
                  }

                 /*choice redirect */
                 if($post->post_type != 'post'):$returnpage = '?post_type='.$post->post_type;  endif;
                 if(!empty($redirectit) && $redirectit == 'to_list'):wp_redirect( admin_url( 'edit.php'.$returnpage ) );
                 elseif(!empty($redirectit) && $redirectit == 'to_page'):wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
                 else:
                 wp_redirect( admin_url( 'edit.php'.$returnpage ) );
                 endif;
                 exit;
                 } else {
                 wp_die('Error! Post creation failed: ' . $post_id);
                 }
   }
函数rd\u duplicate\u post\u链接($actions,$post){
//打印(操作);
//如果(当前用户可以(“编辑帖子”)||$post->post_type==“电影”){
$actions['duplicate']='';
// }
返回$actions;
}
添加过滤器(“页面、行、动作”、“重复、发布链接”,10,2);
添加行动(“管理行动”重复“发布为草案”、“dt dpp发布为草案”);
功能dt_dpp_post_as_草稿()
{
全球$wpdb;
/*清理\u获取POST请求*/
$post_copy=清理文本_字段($_post[“post”]);
$get\u copy=sanitize\u text\u字段($\u get['post']);
$request_copy=sanitize_text_字段($_request['action']);
$opt=get_选项(“dpp_wpp_页面_选项”);
$suffix=!empty($opt['dpp\u post\u suffix'])?“--”。$opt['dpp\u post\u suffix']:”;
$post_status=!空($opt['dpp_post_status'])?$opt['dpp_post_status']:'draft';
$redirectit=!empty($opt['dpp_post_redirect'])?$opt['dpp_post_redirect']:'to_list';
如果(!(isset($get_copy)| | isset($post_copy)| | |(isset($request_copy)&&&“dt_dpp_post_as_草稿”=$request_copy))){
wp_die(“无职位”);
}
$returnpage='';
/*获取邮政id*/
$post\u id=(设置($get\u copy)?$get\u copy:$post\u copy);
$post=get\u post($post\u id);
$current_user=wp_get_current_user();
$new\u post\u author=$current\u user->ID;
/*创建帖子副本*/
如果(isset($post)&&$post!=null){
/*后置数据数组*/
$args=array('comment\u status'=>$post->comment\u status),
“ping_状态”=>$post->ping_状态,
“post_author”=>$new_post_author,
“发布内容”=>$post->post内容,
'post_extract'=>$post->post_extract,
'post\u name'=>$post->post\u name,
“post\u parent”=>$post->post\u parent,
“post_密码”=>$post->post_密码,
“post_状态”=>$post_状态,
'post_title'=>$post->post_title.$suffix,
“post\u type”=>$post->post\u type,
'to_ping'=>$post->to_ping,
“菜单顺序”=>$post->菜单顺序
);
$new\u post\u id=wp\u insert\u post($args);
$taxonomies=get\u object\u分类($post->post\u type);
如果(!empty($taxonomies)&&is_数组($taxonomies)):
foreach($taxonomy作为$taxonomy){
$post_terms=wp_get_object_terms($post_id,$taxonomy,array('fields'=>'slugs');
wp_set_object_terms($new_post_id,$post_terms,$taxonomy,false);}
endif;
$post_meta_infos=$wpdb->get_results(“从$wpdb中选择meta_键,meta_值->postETA,其中post_id=$post_id”);
如果(计数($post\u meta\u infos)!=0){
$sql_query=“插入$wpdb->postETA(post_id,meta_key,meta_value)”;
foreach($post_meta_infos作为$meta_info){
$meta_key=$meta_info->meta_key;
$meta_value=addslashes($meta_info->meta_value);
$sql_query_sel[]=“选择$new_post_id,$meta_key',$meta_value'”;
}
$sql\u query.=内爆(“全部联合”,$sql\u query\u sel);
$wpdb->query($sql\u query);
}
/*选择重定向*/
if($post->post_-type!='post'):$returnpage='?post_-type='。$post->post_-type;endif;
如果(!empty($redirectit)&&$redirectit==“to_list”):wp_redirect(admin_url('edit.php.$returnpage));
elseif(!empty($redirectit)&&$redirectit='to_page'):wp_重定向(admin_url('post.php?action=edit&post='.$new_post_id));
其他:
wp_重定向(admin_url('edit.php.$returnpage));
endif;
出口
}否则{
wp_die('错误!后期创建失败:'。$Post_id);
}
}

噢,哇,谢谢。我刚刚搜索了
admin\u action\u rd\u duplicate\u post\u as\u draft
,找到了一些包含更多信息的文章。谢谢你的回答。很高兴帮助你