Init hook function to call other hook in function.php
-
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'); } }
- The topic ‘Init hook function to call other hook in function.php’ is closed to new replies.