admin管理员组

文章数量:1122846

I have wroted a function and hooked it to set_user_role action hook. here is my snippet:

add_action( 'set_user_role', 'createTeacherPage', 10, 3);

           function createTeacherPage($user_id, $role, $old_roles) {
    $postTitle= wp_strip_all_tags(get_userdata($user_id)->data->user_nicename) . ' page';
    wp_insert_post(array(
        'ID'=> $user_id,
        'post_type'=> 'Teacher',
        'post_status'=> 'publish',
        'post_content'=> '',
        'post_title'=> $postTitle
    ), true);
           }

this function creates my custom post_type called teacher once successfully when i changed one of user's role as test. after that I deleted that new Post and I tried again to change user role but the post didn't created anymore. It seems that's related some kind of issues about still existing post or something like that. I will appreciate any idea or guide. thank you.

本文标签: wpinsertpost() function doesn39t create posts after I deleted the first created Post by this function