Home › Forums › Plugin Support › Can't set custom taxonomy terms via User meta form
Tagged: custom taxonomy terms
- This topic has 14 replies, 2 voices, and was last updated 10 years, 10 months ago by pixel016.
-
AuthorPosts
-
January 24, 2014 at 3:45 pm #4671January 24, 2014 at 5:16 pm #4673pixel016Member
I found part of the solution : The function.php file is loaded beafore the init of wordpress, so custom taxonomy are not “available”.
I have tried to change
add_action( 'user_meta_after_user_register', 'createNewPost' );
toadd_action( 'init', 'createNewPost' );
but i have errors (header already send).The plugin support can help me ?
January 24, 2014 at 5:34 pm #4675KhaledMemberHi,
You can use following to load user_meta_after_user_register into init hook.
add_action( 'init', 'loadAfterUserRegistrationHook' ); function loadAfterUserRegistrationHook(){ add_action( 'user_meta_after_user_register', 'createNewPost' ); }
Thanks.
January 24, 2014 at 5:42 pm #4677pixel016MemberThanks Khaled but it’s not working, function createNewPost is not executed.
January 24, 2014 at 5:49 pm #4678KhaledMemberI have just tested it. It is working here.
add_action( 'init', 'loadAfterUserRegistrationHook' ); function loadAfterUserRegistrationHook(){ add_action( 'user_meta_after_user_register', 'createNewPost' ); } function createNewPost( $response ){ echo $response->user_login; }
January 24, 2014 at 5:55 pm #4679pixel016Memberhmmm me too : in my function.php here is :
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' ){ // Assume you have custom role named 'artist' $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'); } }
And no new post and no Post id log.
- This reply was modified 10 years, 10 months ago by pixel016.
January 24, 2014 at 7:50 pm #4682pixel016MemberAnd when i copy paste your code `add_action( ‘init’, ‘loadAfterUserRegistrationHook’ );
function loadAfterUserRegistrationHook(){
add_action( ‘user_meta_after_user_register’, ‘createNewPost’ );
}function createNewPost( $response ){
echo $response->user_login;
}`i don’t have the echo … so weird
January 25, 2014 at 6:00 pm #4718pixel016MemberPlease i need help
January 25, 2014 at 7:15 pm #4719KhaledMemberHi,
Can you please send ftp and wp login data to support(at)user-meta.com
Thanks.
January 25, 2014 at 8:25 pm #4722pixel016MemberI work in local so i don’t have ftp login for the moment.
January 26, 2014 at 1:41 am #4729KhaledMemberHello, You can try wp default action “user_register” which accept one parameter ($user_id) and triggered every time when a new user has registered.
January 27, 2014 at 9:53 am #4732pixel016Memberi’m not sure to understand, i’m trying something like this but i think it’s not that you say :
add_action( 'user_register', 'loadAfterUserRegistrationHook' ); function loadAfterUserRegistrationHook($user_id){ 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'); } }
January 27, 2014 at 3:25 pm #4735pixel016MemberI can’t add my script to another page that will be called after the init ? it will solve all the problems no ?
January 27, 2014 at 8:18 pm #4741KhaledMemberAction: user_meta_after_user_register are loaded on admin-ajax.php(for ajax) or inside init hook. So it suppose to load after init. To make sure, the action are loaded later, you can try following changes.
If you are using 1.1.5rc1, replace line 54,55 on user-meta/framework/init.php
add_action( 'wp_ajax_pf_ajax_request', array( $this, 'pfAjaxRequest' ) ); add_action( 'wp_ajax_nopriv_pf_ajax_request', array( $this, 'pfAjaxRequest' ) );
with
add_action( 'wp_ajax_pf_ajax_request', array( $this, 'pfAjaxRequest' ), 80 ); add_action( 'wp_ajax_nopriv_pf_ajax_request', array( $this, 'pfAjaxRequest' ), 80 );
And line 35 on controllers/umPreloadsController.php
add_action( 'init', array( $this, 'processPostRequest' ) );
with
add_action( 'init', array( $this, 'processPostRequest' ), 80 );
Try those changes with your earlier code http://user-meta.com/forums/topic/cant-set-custom-taxonomy-terms-via-user-meta-form/#post-4671
And although functions.php load before init but you are executing your code by calling action, those action will load after init.
Thanks.
January 27, 2014 at 9:30 pm #4742pixel016MemberHooooo thanks you so so so so much Khaled it is working perfectly !
It has not been easy, thank you for your patience and participation.
-
AuthorPosts
- You must be logged in to reply to this topic.