How to have sample page for each new register users in a membership website

I have a membership website where my users can create their own page. I have some pages which I want every new users to have them (duplicate my page as their own).

For every new users I have to instruct them about how to copy past my page & publish them. Is their any way or plugin or codes by which whenever some one register in my website he will have some pre-published page.

It is like new WordPress registration. When someone install WordPress 1st time, he always have 1 sample page. Like this is their any way to have such sample or copy of a page for new users.

Any helps will be highly appreciated.

Solutions

There's a hook called user_register() that you could use. It happens during the creation of the new user - right after they are added to the database and have an ID, but before the usermeta like first_name has been saved. You can then use wp_insert_post() to add the new post and assign them as the "author."

<?php
// When a user first registers, run our function
add_action('user_register', 'wpse_293428_create_user_post', 10, 1);
function wpse_293428_create_user_post($user_id) {
    // Set up a simple post array
    $sample_post = array(
        // Set to desired post type: post, page, etc.
        'post_type' => 'post',
        'post_title' => 'Sample Post',
        // Post content can get much more complex if you need html etc.
        'post_content' => 'This is a test post',
        // Choose post status you want: could be a draft, or could be published
        'post_status' => 'publish',
        // Use the User ID that WP just created for this user
        'post_author' => $user_id,
        // Only if it's a Post, set Category - requires an array
        'post_category' => array(1)
    );
    wp_insert_post($sample_post);
}
?>

You may want to change what category(ies) the new post appears in, or if you switch to creating a Page make sure to remove post_category. Depending on your needs, filling in more complex post_content may get a bit tricky so start simple and then slowly build out what you want.

Tags: Plugins / Pages / Shortcode

Similar questions

how to disable all browser not save my website cached data for all my website users and all time new updated and fresh website open
how to disable all browser not save my Wordpress website cached data for all my website users and all time new updated and fresh website open because when i publish new posts chrome,opera don't show new posts and show old post
Wordpress SQL dump to restore sample data on new sites
I have set up a wordpress site, installed a theme, imported the sample data xml file, and did a sqldump of the database after completing these steps. I have a script that will automate the creation of the wordpress directory and database for a new site. I would like to add restoring the new database with the dump file. I have been able to do this b...
If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
One custom post type that i've created has 5 custom fields that display specific content for a template that displays them in different areas on the page. My question is if i would have to create another loop for each custom field i'm referencing on my template or if one would suffice? Thanks.
How to register a post type so I have archive page, but don't have single pages?
I think the question is straight forward. I want to have archive page, but want the single pages gone. Is there a way with custom post type options?
Can I create users that have access to *some* other users posts instead of all other users posts?
I’ve been using basic user rights functionality on a multi-user WP site for a while and its worked out great, having most user accounts just have access to their own posts but a few “editors” having access to everyone’s posts. This was assisted by the wp-front plugin that allows you to easily define user roles. However I now have a scenario where I...
Let users register weight each day and save it in DB
I need a way that lets my users register they're weight (kg) and maybe % of bodyfat and save that information on each user in the DB. Then i need a way to output that number again on the logged in user What would be the easiest approach to do something like this?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.