• I am making a multisite that lets users sign up for blogs.

    What I need to do is that when a new user signs up for a new website I want a new post to be made with a link to that blog that appears in my blog posts section on the main page.

    Im sure there is a plugin that can do this, but as of now I have not been able to find one.

    Does anyone have an idea as to how I would go about doing this?

    Thanks in advanced!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Probably via wpmu_new_blog

    wpmu_create_blog does this:

    * This function runs when a user self-registers a new site as well
    * as when a Super Admin creates a new site. Hook to ‘wpmu_new_blog’
    * for events that should affect all new sites.

    do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );

    So you want to hook that and have it name a new post 🙂

    … like this.

    <?php
    function ds_new_site_post( $blog_id ) {
    
    	switch_to_blog( $blog_id );
    		$blogname = get_option( 'blogname' );
    		$siteurl = site_url();
    	restore_current_blog();
    
    	$post_content = sprintf( __( 'New Site: <a href="%2$s">%1$s</a>' ), $blogname, $siteurl);
    	$post_title = sprintf( __( 'New Site: %1$s' ), $blogname);
    
    	$post = array(
    		'post_content'   => $post_content,
    		'post_title'     => $post_title,
    		'post_status'   => 'publish'
    		);
    
    	wp_insert_post( $post );
    
    }
    
    add_action( 'wpmu_new_blog', 'ds_new_site_post' );

    Thread Starter willmero

    (@willmero)

    Ah okay thank you guys, David, would I be able to just copy and paste that code into my functions file? I’m sorry, I am kind of a noob to this coding with wordpress thing 🙁

    https://codex.wordpress.org/Writing_a_Plugin

    Add what you like to the plugin header and add to your wp-content/plugins.

    (easy peasy tutorial)

    Thread Starter willmero

    (@willmero)

    Okay so I put the above code into a php document, and uploaded it to my multisites plugin directory and enabled it on the site I wanted it to work on and when a user creates a site it doesn’t pop up as a post, is there something I need to configure?

    Thread Starter willmero

    (@willmero)

    Actually I was able to figure it out! Thank you again! But just one more thing, if I wanted to setup the post with a specific format (I have 4 formats, standard audio, video, and quote) how would I code that in there?

    Custom post types? Add post_type to the $post array. See codex for more details on using wp_insert_post.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Making new blogs appear as posts’ is closed to new replies.