WordPress:批准后将评论转换为帖子

时间:2016-05-04 07:48:02

标签: php wordpress plugins comments posts

我正在使用下面的功能将WP-comments转换为WP-posts。我希望在“批准”评论时将其解雇。 (现在只要在WP中激活插件)。 所以我真的想知道如何从edit-comments.php的第47行向我的函数添加函数:

foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
        if ( !current_user_can( 'edit_comment', $comment_id ) )
            continue;

        switch ( $doaction ) {
            case 'approve' :
                wp_set_comment_status( $comment_id, 'approve' );
                $approved++;
                break;
    [...]
   }
}

插件功能:

register_activation_hook( __FILE__, 'convert_to_posts' );

function convert_to_posts(){

        $comments = get_comments();

        foreach($comments as $comment) 
        {


                $post = get_post($comment->comment_post_ID);
                $title = get_comment_meta( $comment->comment_ID, 'title', true );
                $content = $comment->comment_content;
                $my_post = array(
                     'post_title' => $title,
                     'post_content' => $content,
                     'post_status' => 'publish',
                     'post_author' => 1
                );      
               wp_insert_post( $my_post );
               // wp_delete_comment( $comment->comment_ID );
        }

    }

0 个答案:

没有答案