最合适的回答,由SO网友:Frank P. Walentynowicz 整理而成
而不是使用wp_mail
筛选器使用操作user_register
:
function fpw_new_user_post( $user_id ) {
global $wpdb;
update_user_meta( $user_id, $wpdb->base_prefix . \'capabilities\', array( \'author\' => TRUE ) );
$new_post = array (
\'post_title\' => \'User \' . get_user_by( \'id\', $user_id )->user_login . \' registered @ \' . date( \'Y-m-d H:i:s\', current_time( \'timestamp\' ) ),
\'post_content\' => \'This is my first post.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id,
\'post_category\' => array( 0 )
);
$post_id = wp_insert_post( $new_post );
if ( 0 == $post_id ) {
// do some error action
}
}
add_action( \'user_register\', \'fpw_new_user_post\', 10, 1 );
基于您希望该用户稍后发布其他帖子的假设,我将其角色更改为
author
. 当然,你可以根据自己的需要设置一个新职位。