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

Php WordPress:批准后将评论转换为帖子,php,wordpress,plugins,comments,posts,Php,Wordpress,Plugins,Comments,Posts,我正在使用下面的功能将WP评论转换为WP帖子。我希望在“批准”评论时将其解雇。(现在是在WP中激活插件时)。 因此,我真的想知道如何在edit-comments.php的第47行将我的函数添加到这个操作中: foreach ( $comment_ids as $comment_id ) { // Check the permissions on each if ( !current_user_can( 'edit_comment', $comment_id ) )

我正在使用下面的功能将WP评论转换为WP帖子。我希望在“批准”评论时将其解雇。(现在是在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 );
        }

    }