Update posta meta
-
Hi,
I’m creating a client portal and your video tutorial has been very helpful, now i’m trying to make my customer’s life easier and i would like to create automatically new page and custom capabilities when user register to the web site. I found some code here:
http://www.s2member.com/forums/topic/updating-page-meta-data/and my code is:
// Add page after new user registered
add_action(‘user_register’, ‘registration_newpage’);function registration_newpage($user_id) {
$user_info = get_userdata($user_id);
$username = $user_info->user_login;
$post = array();
$post[‘post_name’] = ‘Members-Page-for-‘.$username; // The name (slug) for the page
$post[‘post_type’] = ‘page’; //sets type
$post[‘post_content’] = esc_attr($username.’ – This page was created for you and any messages that we need to send you with regards to any products, services or changes to your membership will be posted here.’.$userid);
$post[‘post_author’] = $username;
$post[‘post_status’] = ‘publish’; //status
$post[‘post_title’] = $username;
$post_id = wp_insert_post ($post);
if (!$post_id) {
wp_die(‘Error creating user page’);
} else {
update_post_meta($post_id, ‘_wp_page_template’, ‘page-members.php’);
$user = new WP_User($user_id);
$user->add_cap(“access_s2member_ccap_$username”);
update_post_meta($post_id, ‘s2member_ccaps_req’, “$username”);
$new_options = Array(); // s2member array for security level
$new_options[“ws_plugin__s2member_level0_pages”] = $post_id; // set Level0 for this Page
c_ws_plugin__s2member_menu_pages::update_all_options ($new_options, true, false, array (“page-conflict-warnings”), true); // s2member update}
return;
}It works great, it creates a new page and populate user custom capability and page custom capability with the username, the only problem is that it doesn’t protect the page, i mean if user1 is logged and he types wwww.mysite.com/user2 he can see user2 content and it shouldn’t be because i’m using custom capabilities.
Hope someone can help me,
Many thanks
Vincenzo
The topic ‘Update posta meta’ is closed to new replies.