bp_groupblog_update_defaults

The BP Groupblog bp groupblog update defaults function.

Description

bp_groupblog_update_defaults(); 

Usage

  1. if ( !function_exists( 'bp_groupblog_update_defaults' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bp-groupblog/bp-groupblog-admin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_groupblog_update_defaults(); 
  7.  

Defined (1)

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

/bp-groupblog-admin.php  
  1. function bp_groupblog_update_defaults() { 
  2.  
  3. // retrieve the old landing page slug so we know which pages to delete 
  4. $oldoptions = get_site_option('bp_groupblog_blog_defaults_options'); 
  5.  
  6. // create an array to hold the chosen options 
  7. $newoptions = array(); 
  8. $newoptions['theme'] = $_POST['theme']; 
  9.  
  10. // groupblog validation settings 
  11. $newoptions['allowdashes'] = !empty( $_POST['bp_groupblog_allowdashes'] ) ? 1 : 0; 
  12. $newoptions['allowunderscores'] = !empty( $_POST['bp_groupblog_allowunderscores'] ) ? 1 : 0; 
  13. $newoptions['allownumeric'] = !empty( $_POST['bp_groupblog_allownumeric'] ) ? 1 : 0; 
  14. $newoptions['minlength'] = isset( $_POST['bp_groupblog_minlength'] ) && is_numeric( $_POST['bp_groupblog_minlength'] ) == true ? $_POST['bp_groupblog_minlength'] : 4; 
  15.  
  16. // groupblog default settings 
  17. $newoptions['default_cat_name'] = isset( $_POST['default_cat_name'] ) ? $_POST['default_cat_name'] : ''; 
  18. $newoptions['default_link_cat'] = isset( $_POST['default_link_cat'] ) ? $_POST['default_link_cat'] : ''; 
  19.  
  20. if ( !empty( $_POST['delete_first_post'] ) ) 
  21. $newoptions['delete_first_post'] = 1; 
  22. else 
  23. $newoptions['delete_first_post'] = 0; 
  24.  
  25. if ( !empty( $_POST['delete_first_comment'] ) ) 
  26. $newoptions['delete_first_comment'] = 1; 
  27. else 
  28. $newoptions['delete_first_comment'] = 0; 
  29.  
  30. if ( !empty( $_POST['delete_blogroll_links'] ) ) 
  31. $newoptions['delete_blogroll_links'] = 1; 
  32. else 
  33. $newoptions['delete_blogroll_links'] = 0; 
  34.  
  35. // groupblog layout settings 
  36. if ( !empty( $_POST['group_admin_layout'] ) ) 
  37. $newoptions['group_admin_layout'] = 1; 
  38. else 
  39. $newoptions['group_admin_layout'] = 0; 
  40.  
  41. // redirect group home to blog home 
  42. if ( !empty( $_POST['deep_group_integration'] ) ) 
  43. $newoptions['deep_group_integration'] = 1; 
  44. else 
  45. $newoptions['deep_group_integration'] = 0; 
  46.  
  47. // groupblog redirect option 
  48. $newoptions['redirectblog'] = isset( $_POST['bp_groupblog_redirect_blog'] ) ? $_POST['bp_groupblog_redirect_blog'] : ''; 
  49. $newoptions['pagetitle'] = isset( $_POST['bp_groupblog_page_title'] ) ? $_POST['bp_groupblog_page_title'] : __( 'Blog', 'bp-groupblog' ); 
  50. $newoptions['pageslug'] = isset( $_POST['bp_groupblog_page_title'] ) ? sanitize_title( $_POST['bp_groupblog_page_title'] ) : ''; 
  51. $newoptions['page_template_layout'] = isset( $_POST['page_template_layout'] ) ? $_POST['page_template_layout'] : 'magazine'; 
  52.  
  53. $newoptions['rerun'] = 0; 
  54.  
  55. if ( ($newoptions['redirectblog'] == 2) ) { 
  56.  
  57. if ( bp_has_groups( ) ) : while ( bp_groups() ) : bp_the_group(); 
  58. if ( $blog_id = get_groupblog_blog_id( bp_get_group_id() ) ) { 
  59. switch_to_blog ( $blog_id ); 
  60. $change_front = new WP_Query( 'pagename=' . $newoptions['pageslug'] ); 
  61. if ( $change_front->have_posts() ) : while ( $change_front->have_posts() ) : $change_front->the_post(); 
  62. $blog_page_id = get_the_ID(); 
  63. endwhile; endif; 
  64. if ( $newoptions['deep_group_integration'] == 1 ) { 
  65. $page_or_posts = 'page'; 
  66. update_option('page_on_front', $blog_page_id); 
  67. } else { 
  68. $page_or_posts = 'posts'; 
  69. update_option('show_on_front', $page_or_posts); 
  70. endwhile; endif; 
  71.  
  72. update_site_option ('bp_groupblog_blog_defaults_options', $newoptions); 
  73.  
  74. $get_out = false; 
  75.  
  76. if ( $newoptions['redirectblog'] != 2 ) { 
  77. $get_out = true; 
  78.  
  79. if ( ( $oldoptions['pageslug'] == $newoptions['pageslug'] ) && ( $oldoptions['redirectblog'] == 2 ) ) { 
  80. $get_out = true; 
  81.  
  82. if ( $get_out && ( $oldoptions['rerun'] == 0 ) ) { 
  83. return false; 
  84.  
  85. echo '<div id="message" class="updated fade">'; 
  86. echo '<p><strong>The following blogs were updated</strong></p>'; 
  87.  
  88. $exists_in = array(); 
  89. $updated_blogs = array(); 
  90. if ( bp_has_groups( ) ) : while ( bp_groups() ) : bp_the_group(); 
  91. if ( $blog_id = get_groupblog_blog_id( bp_get_group_id() ) ) { 
  92. switch_to_blog ( $blog_id ); 
  93. $create = new WP_Query( 'pagename=' . $newoptions['pageslug'] ); 
  94.  
  95. if ( $create->have_posts()) { 
  96. $get_lost = 1; 
  97. while ( $create->have_posts() ) : $create->the_post(); 
  98. if ( !get_post_meta( get_the_ID(), 'created_by_groupblog_dont_change' ) ) { 
  99. $exists_in[] = get_bloginfo('name'); 
  100. $page_found = 1; 
  101. $newoptions['rerun'] = 1; 
  102. endwhile; 
  103. } else { 
  104.  
  105. if ( !$get_lost ) { 
  106. $blog_page = array( 
  107. 'comment_status' => 'closed', // 'closed' means no comments. 
  108. 'ping_status' => 'closed', // 'closed' means pingbacks or trackbacks turned off 
  109. 'post_status' => 'publish', //Set the status of the new post. 
  110. 'post_name' => $newoptions['pageslug'], // The name (slug) for your post 
  111. 'post_title' => $newoptions['pagetitle'], //The title of your post. 
  112. 'post_type' => 'page', //Sometimes you want to post a page. 
  113. '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. 
  114. ); 
  115. $blog_page_id = wp_insert_post( $blog_page ); 
  116.  
  117. if ( $blog_page_id ) { 
  118. add_post_meta($blog_page_id, '_wp_page_template', 'blog.php'); 
  119. // add a special meta key so if we have to clean it up later we know the difference between pages 
  120. // created by us and ones created by the user so we don't delete their pages. 
  121. add_post_meta($blog_page_id, 'created_by_groupblog_dont_change', '1'); 
  122. $updated_blogs[] = get_bloginfo('name'); 
  123.  
  124. // find the page created previously and delete it, checking first to see if it was one we created or not 
  125. if ( $oldoptions['pageslug'] != $newoptions['pageslug'] ) { 
  126. $cleanup = new WP_Query( 'pagename=' . $oldoptions['pageslug'] ); 
  127.  
  128. if ( $cleanup->have_posts() ) : while ( $cleanup->have_posts() ) : $cleanup->the_post(); 
  129. if ( get_post_meta( get_the_ID(), 'created_by_groupblog_dont_change' ) ) { 
  130. wp_delete_post( get_the_ID(), $force_delete = true ); 
  131. endwhile; endif; //cleanup 
  132. $get_lost = 0; 
  133.  
  134. endwhile; endif; 
  135.  
  136. foreach ( $updated_blogs as $blog ) { 
  137. echo '<p>- ' . $blog . '</p>'; 
  138.  
  139. if ( $page_found ) { 
  140. echo '<div class="error">'; 
  141. echo '<p style="line-height: 16px;"><strong>We skipped the following blogs</strong></p>'; 
  142. foreach ( $exists_in as $blog ) { 
  143. echo '<p>- ' . $blog . '</p>'; 
  144. echo '<p><em>These blogs already had a page named <strong>"'. $newoptions["pagetitle"] .'"</strong> which was not created by us. Please check and delete that page permanently after which you should return here and click save once more to finalize the process. Alternatively you can choose another template page name.</em></p></div>'; 
  145.  
  146. echo '</div>'; 
  147.  
  148. elseif ( $newoptions['redirectblog'] != 2 ) { 
  149. if ( bp_has_groups( ) ) : while ( bp_groups() ) : bp_the_group(); 
  150. if ( $blog_id = get_groupblog_blog_id( bp_get_group_id() ) ) { 
  151. switch_to_blog ( $blog_id ); 
  152. update_option('show_on_front', 'posts'); 
  153. endwhile; endif; 
  154.  
  155. // override the site option 
  156. update_site_option ('bp_groupblog_blog_defaults_options', $newoptions); 
  157.  
  158. $options = get_site_option('bp_groupblog_blog_defaults_options');