1

I need to set some defaults for my multisite sites as they are created but It's not quite working. I have this in the install.php file in /wp-content:

function wporg_wpmu_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
    update_blog_option( $blog_id, 'upload_url_path', 'http://mycdn.net/newsite' );
    update_blog_option( $blog_id, 'upload_path', '/home/www/myfiles/newsite' );
    update_blog_option( $blog_id, 'blog_public', '0' );

    switch_to_blog($blog_id);

    // Remove the default post & page
    wp_delete_post(1, true);
    wp_delete_post(2, true);

    // Remove the first comment
    wp_delete_comment( 1, true );

    restore_current_blog();
}
add_action( 'wpmu_new_blog', 'wporg_wpmu_new_blog', 10, 6 );

Am I missing anything?

4
  • what part is not "quite working"?
    – user47133
    Dec 27, 2016 at 22:34
  • None of it. I forgot to mention this code is in my index.php file in the wp-content folder. (updated question)
    – dcp3450
    Dec 27, 2016 at 22:35
  • In your question you say you have it in "install.php", in wp-content
    – user47133
    Dec 27, 2016 at 22:36
  • I just updated it for anyone else who comes across the question
    – dcp3450
    Dec 27, 2016 at 22:38

1 Answer 1

2

install.php is only run during installation, it wont be run during new site creation.

You'd need to put that code in a mu-plugin to have any chance of running.

(I guess it could also exist in a network-activated plugin, but I'm not 100% sure of that)

Add the following before your code, and put your file in wp-content/mu-plugins:

<?php
/*
Plugin Name: Yourmultisite options
Description: Foobar
Version: 1.0.0
Author: You
Author URI: http://www.examplecom
*/
6
  • mu-plugins don't run any activation hooks. I placed the code for that in the directory and it didn't have any effect either.
    – dcp3450
    Dec 27, 2016 at 22:55
  • Did you create a plugin file in mu-plugins? Does it appear on the list of 'must use' plugins?
    – user47133
    Dec 27, 2016 at 22:59
  • mu-plugins don't run "activation" hooks, but the action you want to hook onto, it's not an activation hook.
    – user47133
    Dec 27, 2016 at 23:00
  • Ah, ok. I created the mu-plugins folder set permissions to 755 and loaded a php file in there with the above script but nothing changes when I view the site's settings.
    – dcp3450
    Dec 27, 2016 at 23:04
  • You need to create an actual plugin file. It needs its plugin header. Update my answer with an example.
    – user47133
    Dec 27, 2016 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.