Автоматически создавать сообщение для каждого пользователя и присваивать ему шаблон

Я пытаюсь заставить WordPress создать новую страницу или пост для каждого пользователя и присвоить ему определенный шаблон. Он создает сообщение / страницу, как и ожидалось, но не привязывает к нему ни один шаблон. Любые идеи о том, как это может помочь. Мой код, как показано ниже.

function my_create_page($user_id){
$the_user = get_userdata($user_id);
$new_user_name = $the_user->user_login;
$my_post = array();
$my_post['post_title'] = $new_user_name;
$my_post['post_type'] = 'page';
$my_post['post_content'] = '';
$my_post['post_status'] = 'publish';
$my_post['post_theme'] = 'user-profile';
wp_insert_post( $my_post );
}
add_action('user_register', 'my_create_page', 'user-profile.php');

0

Решение

Вам просто не хватает одной строки:

function my_create_page($user_id){
$the_user = get_userdata($user_id);
$new_user_name = $the_user->user_login;
$my_post = array();
$my_post['post_title'] = $new_user_name;
$my_post['post_type'] = 'page';
$my_post['post_content'] = '';
$my_post['post_status'] = 'publish';
$my_post['post_theme'] = 'user-profile';

$my_post['page_template'] = 'name-of-template.php';

wp_insert_post( $my_post );
}
add_action('user_register', 'my_create_page', 'user-profile.php');

Кодекс: wp_insert_post

0

Другие решения

Других решений пока нет …