I’m building a network with multi-site.
When create a new site, I want some data for site: category, tag, post, active plugin… also create as default data.
Who can show me how to do?
Write a plugin and add data as I want, direct modification function create?
1 Answer
You could use a run-once plugin. The following is just some made-up code, not even tested. See it as a guide, not as a solution. 🙂
<?php
/* Plugin Name: T5 Default Site Settings */
/*
* Don't start on every page, the plugin page is enough.
*/
if ( ! empty ( $GLOBALS['pagenow'] ) && 'plugins.php' === $GLOBALS['pagenow'] )
add_action( 'admin_notices', 't5_default_site_settings', 0 );
function t5_default_site_settings()
{
// Set some options
$options = array(
'avatar_default' => 'blank',
'avatar_rating' => 'G',
'category_base' => '/topic',
'comment_max_links' => 0,
'comments_per_page' => 0,
'date_format' => 'd.m.Y',
'default_ping_status' => 'closed',
'default_post_edit_rows' => 30,
'links_updated_date_format' => 'j. F Y, H:i',
'permalink_structure' => '/%year%/%postname%/',
'rss_language' => 'en',
'timezone_string' => 'Etc/GMT-1',
'use_smilies' => 0,
);
foreach ( $options as $name => $value )
update_option( $name, $value );
// Delete dummy post and comment
wp_delete_post( 1, TRUE );
wp_delete_comment( 1 );
// create a category and a tag
$cat = wp_insert_term( 'WordPress', 'category' );
$tag = wp_insert_term( 'plugins', 'post_tag' );
// Create a post
$first_post = wp_insert_post(
array(
'post_status' => 'publish',
'post_excerpt' => 'This is a custom excerpt for a post.',
'post_content' => 'This is the post content.<!--nextpage-->Page two.',
'post_title' => 'The first post'
)
);
// Create a page
$first_page = wp_insert_post(
array(
'post_status' => 'publish',
'post_type' => 'page',
'post_excerpt' => 'This is a custom excerpt for a page.',
'post_content' => sprintf(
'This is the page content. We have <a href="https://wordpress.stackexchange.com/questions/96276/%s">a post</a> too!',
get_permalink( $first_post )
),
'post_title' => 'The first page'
)
);
// Now deactvate this plugin:
// Suppress "Plugin activated" notice.
unset ( $_GET['activate'] );
// this plugin's name
$name = get_file_data( __FILE__, array ( 'Plugin Name' ), 'plugin' );
printf(
'<div class="notice"><p>All defaults are set!</p>
<p><i>%s</i> has been deactivated.</p></div>',
$name[0]
);
deactivate_plugins( plugin_basename( __FILE__ ) );
}