初始化钩子函数以调用unction.php中的其他钩子

时间:2014-01-24 作者:devwin

我正在尝试在init 将调用另一个钩子的钩子,如下所示:

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\');

   }
 }
为什么功能createNewPost 是否未执行?

1 个回复
SO网友:Godwinh

也许在user_register

add_action( \'user_register\', \'loadAfterUserRegistrationHook\' );
    function loadAfterUserRegistrationHook(){
    add_action( \'user_meta_after_user_register\', \'createNewPost\' );  
}
请参见:http://codex.wordpress.org/Plugin_API/Action_Reference/register_form

结束