Multi-site signup_defualt to sample page.

Hi.

Sorry if the answer to this is obvious!!!!

How can I set the default (upon multi-site sign-up) 'Front Page' of a fresh sign-up, to be the 'Sample Page' rather than the 'Hello World' post page?

I wish to avoid using a template, just for now!!!!

A piece of code somewhere perhaps.

Thanks in advance.

Regards

johnv

  • Michelle Shull
    • DEV MAN’s Apprentice

    Hi there, johnv!

    There are some great options out there for creating new sites in your network that are exactly what you want, but I understand wanting a simple option, too.

    I did some digging, and I found this (untested) function I think will work here.

    add_action( 'wpmu_new_blog' );
    function $homepage = get_page_by_title( 'Sample Page' );
    
    if ( $homepage )
    {
        update_option( 'page_on_front', $homepage->ID );
        update_option( 'show_on_front', 'page' );
    }

    This would go in an MU plugin, described here: http://codex.wordpress.org/Must_Use_Plugins

    I've not tested this on my own site, but the logic seems sound to me.

    Thanks for your question!

  • john
    • Site Builder, Child of Zeus

    Hi Michelle.

    Thanks. Just the job: I think!!!

    I created a File in :- wp content/mu-plugins.

    I called it :- sample-page-default.php. Then entered the code.

    But the code appears at the top of my pages in standard text!!

    Have I done something incorrect??

    Thanks

    Johnv

  • john
    • Site Builder, Child of Zeus

    Hi Michelle.

    Wonder if you could have a look at the above code for me? Think something is missing! I tried my self, but am a total novice and so only made things worse!!!!

    Thanking you in advance.

    Regards

    Johnv

  • Sajid
    • DEV MAN’s Sidekick

    Hi @Johnv

    Hope you are doing good today :slight_smile:

    I modified the above provided code slightly and added starting PHP tag that is required for server to execute this piece of code rather just throwing off to the browser.

    <?php
    add_action( 'wpmu_new_blog', 'wpmudev_new_blog_page' );
    if(!function_exists('wpmudev_new_blog_page')):
    	function wpmudev_new_blog_page(){
    		$homepage = get_page_by_title( 'Sample Page' );
    
    		if ( $homepage )
    		{
    			update_option( 'page_on_front', $homepage->ID );
    			update_option( 'show_on_front', 'page' );
    		}
    	}
    endif;

    Please add above code in "sample-page-default.php" created by you in above setep and let me know how it goes :slight_smile:

    Cheers, Sajid

  • Sajid
    • DEV MAN’s Sidekick

    Hi johnv! Hope you are doing good today and welcome back :slight_smile:

    Its weird! The action hook "wpmu_new_blog" should work for any user regardless of their role, according to WordPress docs.

    wpmu_new_blog is an action triggered whenever a new blog is created within a multisite network.

    Are you using this snippet as a mu-plugin ?

    You are using default wp-signup.php form for signups ?

    Take care and have a nice weekend :slight_smile:

    Cheers, Sajid

  • john
    • Site Builder, Child of Zeus

    Hi Sajid.

    Hope you are well?

    Yes to both questions.

    I deleted and re-created the file (sample-page-default.php)
    in mu-plugins: entered the 'full' code!

    I get a post page, as apposed to the 'default sample page'

    I was incorrect is saying it worked for super admin!!

    The 'settings' / 'reading' shows the default to be a 'post'.

    Should we be looking at changing this default setting?

    Thanks

    johnv

  • Jude
    • DEV MAN

    Hi there @john

    Can you try with this code instead ?

    <?php
    add_action( 'wpmu_new_blog', 'wpmudev_new_blog_page' );
    if(!function_exists('wpmudev_new_blog_page')):
    	function wpmudev_new_blog_page(){
    		$homepage = get_page_by_title( 'Sample Page' );
    
    		if ( $homepage )
    		{
    			update_site_option( 'page_on_front', $homepage->ID );
    			update_site_option( 'show_on_front', 'page' );
    		}
    	}
    endif;

    I basically used a WPMS function update_site_option instead of update_option which is for single sites.

    Cheers
    Jude

  • Anang
    • New Recruit

    Hi @johnv

    Trying to help here :slight_smile:

    I think the script above just lack switch blog command.

    add_action( 'wpmu_new_blog', 'process_extra_field_on_blog_signup', 10, 6 );
    
    function process_extra_field_on_blog_signup( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
        switch_to_blog($blog_id);
        $homepage = get_page_by_title( 'Sample Page' );
        if ( $homepage )
        {
            update_blog_option( $blog_id, 'page_on_front', $homepage->ID );
            update_blog_option( $blog_id, 'show_on_front', 'page' );
        }
        restore_current_blog();
    }

    Credit to this article : http://wordpress.stackexchange.com/questions/106377/set-static-page-as-default-front-page-on-newly-created-sites-in-multisite

    I have tested it on my side, and it's worked :slight_smile:

    Let me know if it's worked on you too :slight_smile:

    Best Regards

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.