Splog Snippets
<?php
/**
* Get External JSON and Parse to Array
*/
# Get the JSON
$response = file_get_contents('https://gist.githubusercontent.com/rveitch/2deeed2b14046f7497e8/raw/4aed0fa64e1717bf9bbaf62ba4a6c88f46b577f7/json_splog_list.json');
# Decode to ARRAY
$array = json_decode( $response, TRUE );
# Convert array to OBJECT
$blogs = new stdClass();
foreach ($array as $key => $value) {
$blogs->$key = $value;
}
### Debug Test Print ###
if (!empty($blogs)) {
foreach ($blogs as $blog) {
echo 'Blog ID: ' . $blog . ' would have been deleted.<br>';
}
}
/* Get All Blogs Marked as Spam (JSON ARRAY) */
$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE spam = '1'");
echo '<pre>';
print_r( json_encode( $blogs, JSON_PRETTY_PRINT ) );
echo '</pre>';
/* WPMU Delete Blog Permanently */
$input = '999998,999999'; //Use Comma Separated String of Blog ID's
$array = explode( ',', $input );
for ($i = 0; $i < count($array); ++$i) {
$blog = $array[$i];
wpmu_delete_blog( $blog, true );
echo 'Blog Deleted';
}
/* Get All Blogs Marked as Public */
$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE public = '1'");
$cnt = count($blogs);
$index = 0;
if (!empty($blogs)) {
foreach ($blogs as $blog) {
$blogarray .= $index." => '".$blog."', ";
++$index;
}
echo '<li>Total blogs marked as public: '.$cnt.'</li><br>';
echo 'array( '.$blogarray.');';
}
/* Get All Blogs JP Master User */
$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE public = '1'");
$results = '';
if ( !empty($blogs) ) {
foreach ( $blogs as $blog ) {
switch_to_blog( $blog );
$master_user = Jetpack_Options::get_option( 'master_user' );
$results .= $blog . ',' . $master_user . '<br>';
restore_current_blog();
}
echo $results;
}
/* Get Users for Each Site */
$input = '81,1254,1331,1539,2902,11886,13235,15878';
$array = explode( ',', $input );
for ($i = 0; $i < count($array); ++$i) {
$blog = $array[$i];
$blogusers = get_users( array( 'blog_id' => $blog ) );
$user_id = $blogusers[0]->ID;
$user_last = get_user_meta( $user_id, 'last_activity' );
echo $blog . ',' . $user_id . ',' . $blogusers[0]->user_email . ',' . $user_last[0] . '<br>';
}
/* Set User Status to 'Spam' */
$input = ''; //Use Comma Separated String of Blog ID's
$array = explode( ',', $input );
for ($i = 0; $i < count($array); ++$i) {
$user_id = $array[$i];
update_user_status( $user_id, 'spam', 1 );
echo 'User ' . $user_id . ' status set to SPAM<br>';
}
/*******************************************************/
/* Get Number of Users for Each Site */64234
$input = ''; //Use Comma Separated String of Blog ID's
$array = explode( ',', $input );
for ($i = 0; $i < count($array); ++$i) {
$blog = $array[$i];
$args = array( 'blog_id' => $blog );
$blogusers = get_users( $args );
//echo 'Blog ' . $blog . ': ' . count($blogusers) . '<br>';
echo $blog . ',' . count($blogusers) . '<br>';
}
wangguard_report(userid , false);
wangguard_report_blog(blogid , false);
$userid = '63575';
$userdata = get_userdata( $userid );
echo '<pre>';
print_r($userdata);
echo '</pre>';
/* GET USER LAST ACTIVITY */
$user_id = 64234;
$key = 'last_activity';
$user_last = get_user_meta( $user_id, $key, $single );
echo '<pre>';
print_r($user_last);
echo '</pre>';
/* GET ALL USER METADATA*/
$userid = '63575';
$all_meta_for_user = array_map( function( $a ){ return $a[0]; }, get_user_meta( $userid ) );
echo '<pre>';
print_r( $all_meta_for_user );
echo '</pre>';
/* GET USER SOURCE DOMAIN */
$user_id = 64234;
$key = 'source_domain';
//$key = 'primary_blog';
$user_last = get_user_meta( $user_id, $key, $single );
echo '<pre>';
print_r($user_last);
echo '</pre>';
/* Set Splog Blogs to 'Spam' */
$input = ''; //Use Comma Separated String of Blog ID's
$array = explode( ',', $input );
for ($i = 0; $i < count($array); ++$i) {
$blog = $array[$i];
update_blog_status( $blog, 'spam', '1' );
update_blog_status( $blog, 'public', '0' );
update_blog_option ($blog, 'av-verified-site', '' );
echo 'Blog ' . $blog . ' status set to SPAM<br>';
}
/* Set Blogs to 'Archived' */
$input = '67585,67557,67556';
$array = explode( ',', $input );
for ($i = 0; $i < count($array); ++$i) {
$blog = $array[$i];
update_blog_status( $blog, 'archived', '1' );
update_blog_status( $blog, 'public', '0' );
update_blog_option ($blog, 'av-verified-site', '' );
echo 'Blog ' . $blog . ' status set to Archived<br>';
}
/* Set Blogs to 'Verified' */
$input = '67585,67557,67556';
$array = explode( ',', $input );
for ($i = 0; $i < count($array); ++$i) {
$blog = $array[$i];
update_blog_option ($blog, 'av-verified-site', '1' );
echo 'Blog ' . $blog . ' status set to ' . get_blog_option ($blog, 'av-verified-site' ) . '<br>';
}
/******************************************************************************/
/* Get Splogs Themes */
$input = '67585,67557,67556';
$array = explode( ',', $input );
for ($i = 0; $i < count($array); ++$i) {
$blog = $array[$i];
switch_to_blog($blog);
$blogthemeinfo .= get_bloginfo('name').','.wp_get_theme().'<br>';
restore_current_blog();
}
echo $blogthemeinfo;
/******************************************************************************/
/* Get All Blogs Marked as Spam */
$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE spam = '1'");
$cnt = count($blogs);
$index = 0;
if (!empty($blogs)) {
foreach ($blogs as $blog) {
$blogarray .= $index." => '".$blog."', ";
++$index;
}
echo '<li>Total blogs marked as spam: '.$cnt.'</li><br>';
echo 'array( '.$blogarray.');';
}
/* Get Splogs Themes */
$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE spam = '1'");
if (!empty($blogs)) {
foreach ($blogs as $blog) {
switch_to_blog($blog);
//$blogthemeinfo .= '<li>Blog: ' . get_bloginfo ( 'name' ) . ', Theme: ' . wp_get_theme() . '</li>';
$blogthemeinfo .= get_bloginfo('name').','.wp_get_theme().'<br>';
restore_current_blog();
}
echo $blogthemeinfo;
}
/* Find Twenty Eleven Blogs v1 */
$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE spam != '1'");
$index = 0;
if (!empty($blogs)) {
foreach ($blogs as $blog) {
switch_to_blog($blog);
if (wp_get_theme() == 'Twenty Eleven') {
$blogarray .= $index." => '".$blog."', ";
}
++$index;
restore_current_blog();
}
echo 'array( '.$blogarray.');';
}
/* Find Twenty Eleven Blogs v2 */
$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE spam != '1'");
$index = 0;
if (!empty($blogs)) {
foreach ($blogs as $blog) {
switch_to_blog($blog);
if($index > 0) {
$blogarray .= ",";
}
if (wp_get_theme() == 'Twenty Eleven') {
$blogarray .= $blog;
}
++$index;
}
restore_current_blog();
echo $blogarray;
}
/* Verified Blogs */
$blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs WHERE DATE(last_updated) > DATE_SUB(curdate(), INTERVAL 30 DAY) AND spam = '0'" );
$index = 0;
if ( !empty($blogs) ) {
foreach ( $blogs as $blog ) {
switch_to_blog( $blog );
$verified = get_option( 'av-verified-site' );
if ( !$verified ) {
echo $blog . ',';
}
restore_current_blog();
}
//echo "";
}
/* WPMU Delete Blog Permanently */
wpmu_delete_blog( '67582', true );
echo 'Blog Deleted';
/* Get Blogs Name and Tagline */
$input = '67585,67557,67556';
$array = explode( ',', $input );
for ($i = 0; $i < count($array); ++$i) {
$blog = $array[$i];
$blogname = get_blog_option ($blog, 'blogname' );
$blogdescription = get_blog_option ($blog, 'blogdescription' );
echo $array[$i] . ';' . $blogname . ';' . $blogdescription . '<br>';
}
/* Check for Deleted Sites */