WordPress.org

Ready to get started?Download WordPress

Forums

Init hook function to call other hook in function.php (1 post)

  1. pixel016
    Member
    Posted 5 months ago #

    I am trying to add a function in the init hook that will call another hook like this but the function createNewPost is not being executed why ? :

    add_action( 'init', 'loadAfterUserRegistrationHook' );
        function loadAfterUserRegistrationHook(){
        add_action( 'user_meta_after_user_register', 'createNewPost' );
    }    
    
    function createNewPost( $response ){
    global $userMeta;
    
    $userID = $response->ID;
    $user = new WP_User( $userID );
    
    $role = $userMeta->getUserRole();
    
    if( $role = 'artiste' ){ 
    
        $newPost = array(
          'post_title'    => $user->nickname,
          'post_content'  => $user->description,
          'post_status'   => 'pending',
          'post_author'   => $userID,
          'post_type'     => 'cpt_artists'
        );
    
        $post_id = wp_insert_post( $newPost );
        error_log('Post ID : '.$post_id);
    
        wp_set_object_terms( $post_id, array('dj'), 'artist-category');
    
       }
     }

Reply

You must log in to post.

About this Topic