多站点中新站点的默认内容

时间:2013-04-18 作者:thienhaxanh2405

我正在建立一个多站点的网络<创建新站点时,我需要一些站点数据:类别、标记、帖子、活动插件。。。还创建为默认数据。

谁能教我怎么做?

写一个插件并添加我想要的数据,直接修改函数创建?

1 个回复
SO网友:fuxia

您可以使用run once插件。以下只是一些编造的代码,甚至没有经过测试。将其视为指南,而不是解决方案。:)

<?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="%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__ ) );
}

结束

相关推荐

WP MultiSite:默认添加关于博客创建的页面

我希望在使用WP Multisite创建新站点时,在默认情况下添加一个页面。因此,我有一个创建两个页面的函数:function my_default_pages() { $default_pages = array(\'Impress\', \'Contact\'); $existing_pages = get_pages(); foreach($existing_pages as $page) { $temp[] = $p