Created
September 22, 2012 05:11
-
-
Save torounit/3765200 to your computer and use it in GitHub Desktop.
WordPressのマルチサイトでブログが追加されたときに、フロントページ・投稿ページを自動追加するクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mu_Set_Front { | |
public function __construct() { | |
add_action( 'wpmu_new_blog', array(&$this, 'create_front_page'), 10 ,2 ); | |
} | |
public function create_front_page( $blog_id, $user_id ) { | |
switch_to_blog( $blog_id ); | |
if( !get_page_by_path('front-page') ) { | |
update_option( 'show_on_front', 'page' ); | |
$front_page = $defaults = array( | |
'post_status' => 'publish', | |
'post_type' => 'page', | |
'post_title' => 'フロントページ', | |
'post_name' => 'front-page', | |
'post_author' => $user_id | |
); | |
$id = wp_insert_post( $front_page ); | |
update_option( 'page_on_front' , $id ); | |
} | |
if( !get_page_by_path('posts-page') ) { | |
$post_page = $defaults = array( | |
'post_status' => 'publish', | |
'post_type' => 'page', | |
'post_title' => '投稿一覧ページ', | |
'post_name' => 'posts-page', | |
'post_author' => $user_id | |
); | |
$id = wp_insert_post( $post_page ); | |
update_option( 'page_for_posts' , $id ); | |
} | |
restore_current_blog(); | |
} | |
} | |
$mu_set_front = new Mu_Set_Front; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment