bp_groupblog_blog_defaults

The BP Groupblog bp groupblog blog defaults function.

Description

bp_groupblog_blog_defaults( $blog_id ); 

Parameters (1)

0. $blog_id
The blog id.

Usage

  1. if ( !function_exists( 'bp_groupblog_blog_defaults' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bp-groupblog/bp-groupblog-admin.php'; 
  3.  
  4. // The blog id. 
  5. $blog_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_groupblog_blog_defaults($blog_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-groupblog-admin.php  
  1. function bp_groupblog_blog_defaults( $blog_id ) { 
  2. global $bp, $wp_rewrite; 
  3.  
  4. // only apply defaults to groupblog blogs 
  5.  
  6. switch_to_blog( $blog_id ); 
  7.  
  8. // get the site options 
  9. $options = get_site_option( 'bp_groupblog_blog_defaults_options' ); 
  10.  
  11. foreach( (array)$options as $key => $value ) 
  12. update_option( $key, $value ); 
  13.  
  14. // override default themes 
  15. if ( ! empty( $options['theme'] ) ) { 
  16. // we want something other than the default theme 
  17. $values = explode( "|", $options['theme'] ); 
  18. switch_theme( $values[0], $values[1] ); 
  19.  
  20. // groupblog bonus options 
  21. if ( strlen( $options['default_cat_name'] ) > 0 ) { 
  22. global $wpdb; 
  23. $cat = $options['default_cat_name']; 
  24. $slug = str_replace( ' ', '-', strtolower( $cat ) ); 
  25. $results = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->terms SET name = %s, slug = %s WHERE term_id = 1", $cat, $slug ) ); 
  26. if ( strlen( $options['default_link_cat'] ) > 0 ) { 
  27. global $wpdb; 
  28. $cat = $options['default_link_cat']; 
  29. $slug = str_replace( ' ', '-', strtolower( $cat ) ); 
  30. $results = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->terms SET name = %s, slug = %s WHERE term_id = 2", $cat, $slug ) ); 
  31. if ( isset( $options['delete_first_post'] ) && $options['delete_first_post'] == 1 ) { 
  32. global $wpdb; 
  33. $statement = "UPDATE $wpdb->posts SET post_status = 'draft' WHERE id = 1"; 
  34. $results = $wpdb->query( $statement ); 
  35. if ( isset( $options['delete_first_comment'] ) && $options['delete_first_comment'] == 1 ) { 
  36. wp_delete_comment( 1 ); 
  37. if ( $options['delete_blogroll_links'] == 1 ) { 
  38. wp_delete_link( 1 ); //delete Wordpress.com blogroll link 
  39. wp_delete_link( 2 ); //delete Wordpress.org blogroll link 
  40. if ( $options['redirectblog'] == 2 ) { 
  41. $blog_page = array( 
  42. 'comment_status' => 'closed', // 'closed' means no comments. 
  43. 'ping_status' => 'closed', // 'closed' means pingbacks or trackbacks turned off 
  44. 'post_status' => 'publish', //Set the status of the new post. 
  45. 'post_name' => $options['pageslug'], // The name (slug) for your post 
  46. 'post_title' => $options['pagetitle'], //The title of your post. 
  47. 'post_type' => 'page', //Sometimes you want to post a page. 
  48. 'post_content' => __( '<p><strong>This page has been created automatically by the BuddyPress GroupBlog plugin.</strong></p><p>Please contact the site admin if you see this message instead of your blog posts. Possible solution: please advise your site admin to create the <a href="http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates">page template</a> needed for the BuddyPress GroupBlog plugin.<p>', 'groupblog' ) //The full text of the post. 
  49.  
  50. ); 
  51. $blog_page_id = wp_insert_post( $blog_page ); 
  52.  
  53. if ( $blog_page_id ) 
  54. add_post_meta($blog_page_id, '_wp_page_template', 'blog.php'); 
  55. add_post_meta($blog_page_id, 'created_by_groupblog_dont_change', '1'); 
  56.  
  57. // Set the Blog Reading Settings to load the template page as front page 
  58. if ( $options['deep_group_integration'] == 1 ) { 
  59. update_option('show_on_front', 'page'); 
  60. update_option('page_on_front', $blog_page_id); 
  61.  
  62. restore_current_blog(); 
  63.