2017年5月

投稿者ユーザー登録時に自動でユーザー専用の固定ページをつくる

2017年5月8日 月曜日

(条件)
固定ページのスラッグはinfo-(ユーザー名)で、user-info_template.phpというページテンプレートを使う。
ページタイトルは「名」。
functions.php

function create_user_page ( $user_id ) {
	$user_info = get_userdata($user_id);
	$user_name = $user_info->user_login;

    $new_page = array(
                'post_type' => 'page',
                'post_title' => $user_info->first_name,
                'post_name' => 'info-' . $user_name,
                'post_status' => 'publish',
                'post_author' => $user_id,
		'page_template' => 'user-info_template.php'
    );
    
	wp_insert_post($new_page);

}
add_action('user_register', 'create_user_page' );

ユーザーにこのページだけを編集させる制限などはUser Roll Editorなどで設定、紐付けしてください。

過日の投稿(「投稿者ユーザー登録時にユーザー名をスラッグでカテゴリーをつくる」)のコードとまとめて使うと便利です。

ページトップへ