Advertisement
Guest User

WordPress Moderate New Blogs with patch appliesd

a guest
May 14th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.10 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Moderate New Blogs
  4. Plugin URI: http://wordpress.org/extend/plugins/moderate-new-blogs/
  5. Description: New blogs(aka sites) await a final click from a Network Admin to activate in Network-->Sites "Awaiting Moderation". WP3.1+ only
  6. Author: D Sader
  7. Version: 3.1
  8. Author URI: http://dsader.snowotherway.org
  9.  
  10.  
  11.  This program is free software; you can redistribute it and/or modify
  12.  it under the terms of the GNU General Public License as published by
  13.  the Free Software Foundation; either version 2 of the License, or
  14.  (at your option) any later version.
  15.  
  16.  This program is distributed in the hope that it will be useful,
  17.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  GNU General Public License for more details.
  20.  
  21.  
  22. Notes:
  23. To change the default message for an inactive blog use a drop-in plugin as described in wp-includes/ms-load.php:
  24. if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) )
  25. return WP_CONTENT_DIR . '/blog-inactive.php';
  26.  
  27. */
  28.  
  29. class ds_moderate_blog_signup {
  30.  
  31.   function ds_moderate_blog_signup() {
  32.   }
  33.   function admin_notices() {
  34.     if( !is_network_admin() ) return;
  35.     global $wpdb;
  36.     // blogs awaiting activation
  37.     $blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND deleted = '2' ", $wpdb->siteid ) , ARRAY_A );
  38.     if( is_array( $blogs ) ) {
  39.       echo '<div id="update-nag">The following blogs are "Awaiting Moderation" at <a href="'.network_admin_url().'sites.php">Site Admin->Blogs</a> (or click to activate): ';
  40.       $list= array();
  41.       foreach( $blogs as $details ) {
  42.     $blogname = get_blog_option( $details[ 'blog_id' ], 'blogname' );
  43.     $list[]= '<a class="delete" href="sites.php?action=confirm&amp;action2=activateblog&amp;ref='. urlencode( $_SERVER['REQUEST_URI'] ) .'&amp;id='. $details['blog_id'] .'&amp;msg='. urlencode( sprintf( __( "You are about to activate the blog %s" ), $blogname ) ) .'&amp;_wpnonce='. wp_create_nonce('confirm') .'">'. $blogname .'</a>';
  44.       }
  45.       if (count($list))  
  46.     echo implode(' | ', $list);
  47.       echo '</div>';
  48.     }
  49.     // blogs waiting to be deleted
  50.     $blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND deleted = '1' ", $wpdb->siteid ) , ARRAY_A );
  51.     if( is_array( $blogs ) ) {
  52.       echo '<div id="update-nag">The following blogs are "Awaiting Deletion" at <a href="'.network_admin_url().'sites.php">Site Admin->Blogs</a> (or click to delete): ';
  53.       $list= array();
  54.       foreach( $blogs as $details ) {
  55.     $blogname = get_blog_option( $details[ 'blog_id' ], 'blogname' );
  56.    
  57.     $list[]= '<a class="delete" href="sites.php?action=confirm&amp;action2=deleteblog&amp;id=' . $details['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( "You are about to delete the blog %s" ), $blogname ) ) . '&amp;_wpnonce=' . wp_create_nonce('confirm') .'">' . $blogname . '</a>';
  58.       }
  59.       if (count($list))  
  60.     echo implode(' | ', $list);
  61.       echo '</div>';
  62.     }
  63.   }
  64.   function moderated($blog_id) {
  65.     $number = intval(get_site_option('ds_moderate_blog_signup'));
  66.     if ( $number == '2' ) {
  67.       update_blog_status( $blog_id, "deleted", $number);
  68.     } else {
  69.       return;
  70.     }
  71.   }
  72.  
  73.   function wpmu_blogs_actions($blog_id) {
  74.     //global $blog, $blogname;
  75.  
  76.     $blogname = get_blog_option( $blog_id, 'blogname' );
  77.     if ( get_blog_status( $blog_id, "deleted" ) == '2' ) {
  78.      
  79.       echo '<span class="delete"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'edit.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog_id . '&amp;msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Awaiting Moderation' ) . '</a></span>';
  80.     }
  81.   }
  82.  
  83.   function options_page() {
  84.     $number = intval(get_site_option('ds_moderate_blog_signup'));
  85.     $checked = ( $number == '2' ) ? ' checked=""' : '';
  86.     echo '<h3>' . __('Moderate New Sites') . '</h3>';
  87.     echo '
  88. <table class="form-table">
  89. <tr valign="top">
  90. <th scope="row">' . __('Moderation Enabled') . '</th>
  91. <td><input type="checkbox" name="ds_moderate_blog_signup" value="2" ' . $checked . ' /><br /><small>' . __('New sites await a final click from a Network Admin to <a href="'.network_admin_url().'sites.php">Activate</a>') . '</small>
  92. </td>
  93. </tr>
  94. </table>
  95. ';
  96.   }
  97.  
  98.   function update() {
  99.     update_site_option('ds_moderate_blog_signup', $_POST['ds_moderate_blog_signup']);
  100.   }
  101. }
  102.  
  103. if (class_exists("ds_moderate_blog_signup")) {
  104.   $ds_moderate_blog_signup = new ds_moderate_blog_signup();
  105. }
  106.  
  107. if (isset($ds_moderate_blog_signup)) {
  108.   add_action( 'wpmu_new_blog', array(&$ds_moderate_blog_signup, 'moderated'), 10, 1);
  109.   add_action( 'wpmublogsaction',  array(&$ds_moderate_blog_signup, 'wpmu_blogs_actions'), 10, 1);
  110.   add_action( 'update_wpmu_options', array(&$ds_moderate_blog_signup, 'update'));
  111.   add_action( 'wpmu_options', array(&$ds_moderate_blog_signup, 'options_page'));
  112.   add_action( 'mu_rightnow_end', array(&$ds_moderate_blog_signup, 'admin_notices'));
  113. }
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement