{"id":2305,"date":"2012-11-24T16:32:15","date_gmt":"2012-11-24T16:32:15","guid":{"rendered":"http:\/\/blog.ed.gs\/?p=2305"},"modified":"2012-11-24T16:32:15","modified_gmt":"2012-11-24T16:32:15","slug":"wpmu-power-tools","status":"publish","type":"post","link":"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/","title":{"rendered":"WPMU Power Tools"},"content":{"rendered":"

I read about a plugin for WPMU, yes WPMU, that also works with Multisite 3.0+ so far to clean up old spam blogs, users, posts and comments. It was called WPMU Power Tools by Paid To Blog<\/a> but it has since vanished from the web, but I managed to find a copy.<\/p>\n

Code is below, it needs activating per site instead of network wide, I have just activated it on the primary blog.<\/p>\n

user_login.'<br>';\n}\n \n//Migrate all users of one wordpress theme to another one\n$old_theme = get_option('current_theme');\nif($old_theme == 'Old Theme Name')\nupdate_option('current_theme', 'New Theme Name');\n \n//For Donncha's Sitewide Tags plugin: Populate tags blog with all posts made before the plugin was added\n$posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish'" );\nif ( !empty($posts) ) {\n    foreach ( $posts as $post ) {\n        $post_id = $post['ID'];\n        if($post_id != 1 && $post_id != 2)\n            sitewide_tags_post($post_id, get_post($post_id));\n    }\n}\n \n*\n*/\n \n//------------------------------------------------------------------------//\n//---Hook-----------------------------------------------------------------//\n//------------------------------------------------------------------------//\nadd_action( 'admin_menu', 'power_tools_plug_pages' );\n//------------------------------------------------------------------------//\n//---Functions------------------------------------------------------------//\n//------------------------------------------------------------------------//\n \nfunction power_tools_plug_pages()\n{\n    add_submenu_page( 'ms-admin.php', 'Power Tools', 'Power Tools', 'manage_options', 'power-tools', 'power_tools_page_output' );\n}\n \n//------------------------------------------------------------------------//\n//---Page Output Functions------------------------------------------------//\n//------------------------------------------------------------------------//\n \nfunction power_tools_page_output()\n{\n    global $blog_id, $wpdb, $wp_roles, $wp_rewrite, $current_user, $current_site;\n    \n    if ( !isset( $_GET['action'] ) )\n\t\t$_GET['action'] = '';\n \n?>\n<div class="wrap">\n\n\t\t\t<h2></h2>\n\t\t\t<h3></h3>\n\t\t\t<div class="wrap">\n            <form method="post" action="ms-admin.php?page=power-tools&action=phpexec">\n            <p>\n            You can use the form below to execute lines of PHP code on the server once or for each and every blog. This can be highly usefull, for example, if you need make changes to each and every blog automagically. <strong>This tool is intended for advanced users only!</strong></p>\n            <table class="form-table">\n            <tr valign="top">\n            <th scope="row"></th>\n            <td>\n            <?php echo htmlentities( '\n            <br>\n            <textarea name="power_tools_phpexec_code" rows="5" id="power_tools_phpexec_code" style="width: 95%"></textarea>\n            <br>\n            ' ); ?>\n            <br>\n            \t\t\t<b>Globals available:</b> $blog_id, $wpdb, $wp_roles, $wp_rewrite, $current_user, $current_site</td>\n            </tr>\n            <tr>\n            <th scope="row"></th>\n\t\t\t<td>\n\t\t\t Run this code once (Blog ID: <b></b>)\n      <br>\n\t\t\t Execute this code on all blogs\n\t\t\t</td>\n\t\t\t</tr>\n            </table>\n            <p class="submit">\n            <input type="submit" name="Submit" value="" />\n            </p>\n            </form>\n            </div>\n            \n            <br>\n            \n\t\t\t<h3></h3>\n\t\t\t<div class="wrap">\n            <form method="post" action="ms-admin.php?page=power-tools&action=cleanup">\n            <p>This is a very powerful cleanup tool that will remove unnecessary data left over by WPMU. Select the options below that you want and hit PowerClean to start! <b>Be sure to do a full backup before running this operation!</b></p>\n            <table class="form-table">\n            <tr valign="top">\n            <th scope="row"></th>\n\t\t\t<td>\n\t\t\t Blogs marked as spam<br>\n\t\t\t Users marked as spam<br>\n\t\t\t Comments marked as spam/delete <b>(intensive)</b><br>\n\t\t\t Blogs that have been marked for deletion by their owners<br>\n\t\t\t Blogs with 0 posts that are older than 30 days <b>(intensive)</b><br>\n\t\t\t Blog/user signups older than 30 days and still awaiting activation via email<br>\n\t\t\t</td>\n\t\t\t</tr>\n            </table>\n            <p class="submit">\n            <input type="submit" name="Submit" value="" />\n            </p>\n            </form>\n            </div>\n\t\t\t<?php\n            break;\n            //---------------------------------------------------//\n        case "phpexec":\n            @set_time_limit(0);\n            @ini_set('display_errors','1');\n \n            $phpexec_code = stripslashes( $_POST["power_tools_phpexec_code"] );\n            echo '<p>Executing...</p>';\n            if ( $_POST['power_tools_phpexec_option'] == 'runonce' ) {\n                eval ( $phpexec_code );\n                echo '<p>Completed.   <a href="ms-admin.php?page=power-tools">« Go back</a></p>';\n            } else {\n                $blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );\n                $blog_count = count( $blogs );\n                foreach ( $blogs as $blog ) {\n                  $blog_exec_count++;\n                  power_tools_progress_bar( $blog_exec_count, $blog_count, "Current blog ID: <b>$blog</b>" );\n                  switch_to_blog( $blog );\n                  eval ( $phpexec_code );\n                }\n                echo '<p>Completed operation on ' . number_format( $blog_count ) .\n                    ' blogs.   <a href="ms-admin.php?page=power-tools">« Go back</a></p>';\n            }\n            break;\n        case "cleanup":\n            @set_time_limit(0);\n            @ini_set('display_errors','1');\n \n            $cleanup_spamblogs = isset( $_POST['power_tools_blogcleanup_option_spamblogs'] ) ? true:\n            false;\n            $cleanup_spamusers = isset( $_POST['power_tools_blogcleanup_option_spamusers'] ) ? true:\n            false;\n            $cleanup_spamcomments = isset( $_POST['power_tools_blogcleanup_option_spamcomments'] ) ? true:\n            false;\n            $cleanup_deletedblogs = isset( $_POST['power_tools_blogcleanup_option_deletedblogs'] ) ? true:\n            false;\n            $cleanup_oldblogs = isset( $_POST['power_tools_blogcleanup_option_oldblogs'] ) ? true:\n            false;\n            $cleanup_oldsignups = isset( $_POST['power_tools_blogcleanup_option_oldsignups'] ) ? true:\n            false;\n \n            if ( $cleanup_spamblogs ) {\n                $blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs WHERE spam = 1" );\n                $cnt = count($blogs);\n                if ( !empty($blogs) ) {\n                    foreach ( $blogs as $blog ) {\n                        power_tools_progress_bar( $cleanup_spamblogs_count, $cnt, 'Cleaning blogs marked as spam... (blog ID: <b>' . $blog . '</b>)' );\n                        wpmu_delete_blog( $blog, true );\n                        $cleanup_spamblogs_count++;\n                    }\n                }\n            }\n \n            if ( $cleanup_spamusers ) {\n                $users = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE spam = 1" );\n                $cnt = count($users);\n                if ( !empty($users) ) {\n                    foreach ( $users as $user ) {\n                        power_tools_progress_bar( $cleanup_spamusers_count, $cnt, 'Cleaning users marked as spam... (user ID: <b>' . $user . '</b>)' );\n                        wpmu_delete_user( $user );\n                        $cleanup_spamusers_count++;\n                    }\n                }\n            }\n \n            if ( $cleanup_spamcomments ) {\n                $blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );\n                $cnt = count($blogs);\n                if ( !empty($blogs) ) {\n                    foreach ( $blogs as $blog ) {\n                        power_tools_progress_bar( $cleanup_spamcomments_count, $cnt, 'Cleaning comments marked as spam... (blog ID: <b>' . $blog . '</b>)' );\n                        $wpdb->query( "DELETE FROM {$wpdb->base_prefix}{$blog}_comments WHERE comment_approved = 'spam' OR comment_approved = 'delete'" );\n                        $cleanup_spamcomments_count = ( $cleanup_spamcomments_count + $wpdb->rows_affected );\n                    }\n                }\n            }\n \n \n            if ( $cleanup_deletedblogs ) {\n                $blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs WHERE deleted = 1" );\n                $cnt = count($blogs);\n                if ( !empty($blogs) ) {\n                    foreach ( $blogs as $blog ) {\n                        power_tools_progress_bar( $cleanup_deletedblogs_count, $cnt, 'Cleaning blogs marked for deletion... (blog ID: <b>' . $blog . '</b>)' );\n                        wpmu_delete_blog( $blog, true );\n                        $cleanup_deletedblogs_count++;\n                    }\n                }\n            }\n \n            if ( $cleanup_oldblogs ) {\n                $blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs WHERE DATE(registered) < DATE_SUB(curdate(), INTERVAL 30 DAY)" );\n                $cnt = count($blogs);\n                if ( !empty($blogs) ) {\n                    foreach ( $blogs as $blog ) {\n                        power_tools_progress_bar( $cleanup_oldblogs_count, $cnt, 'Cleaning blogs older than 30 days with 0 posts... (checking blog ID: <b>' . $blog . '</b>)' );\n                        $posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->base_prefix}{$blog}_posts" );\n                        if ($posts[0]['post_title'] == 'Hello world!' && $posts[1]['post_title'] == 'About' && count($posts) == 2) { //wordpress by default adds one post and one page, so we check for a post ID of 3\n                            wpmu_delete_blog( $blog, true );\n                            $cleanup_oldblogs_count++;\n                        }\n                    }\n                }\n            }\n \n            if ( $cleanup_oldsignups ) {\n                power_tools_progress_bar( 1, 100, 'Cleaning stale signups...' );\n                $wpdb->query( "DELETE FROM $wpdb->signups WHERE active = 0 AND DATE(registered) rows_affected;\n                power_tools_progress_bar( 1, 100, 'Finished.' );\n            }\n \n            echo '<br>-----Results of cleanup-----<br>';\n            echo number_format( $cleanup_spamblogs_count ) . ' spam blogs.<br>';\n            echo number_format( $cleanup_spamusers_count ) . ' spam users.<br>';\n            echo number_format( $cleanup_spamcomments_count ) . ' spam comments.<br>';\n            echo number_format( $cleanup_deletedblogs_count ) . ' deleted blogs.<br>';\n            echo number_format( $cleanup_oldblogs_count ) . ' abandoned blogs.<br>';\n            echo number_format( $cleanup_oldsignups_count ) . ' old inactive signups.<br>';\n            echo '<p><a href="ms-admin.php?page=power-tools">« Go back</a></p>';\n    }\n?>\n</div>\n<?php\n}\n \nfunction power_tools_progress_bar( $intCurrentCount = 1, $intTotalCount = 100, $strStatus )\n{\n    static $intNumberRuns = 0;\n    static $intDisplayedCurrentPercent = 0;\n    $strProgressBar = '';\n    $dblPercentIncrease = ( 100 / $intTotalCount );\n    $intCurrentPercent = intval( $intCurrentCount * $dblPercentIncrease );\n    $intNumberRuns++;\n \n    if ( 1 == $intNumberRuns ) {\n        $strProgressBar = <<< BAR\n<table width='50%' id='progress_bar' summary='progress_bar' align='center'><tbody><tr>\n<td id='progress_bar_complete' width='0%' align='center' style='background:#CCFFCC'> </td>\n<td style='background:#FFCCCC'> </td>\n</tr></tbody></table>\n<p id='progress_bar_status'> </p>\n\nfunction power_tools_progress_bar_update(intCurrentPercent,strStatus)\n{\n    document.getElementById('progress_bar_complete').style.width = intCurrentPercent+'%';\n    document.getElementById('progress_bar_complete').innerHTML = intCurrentPercent+'%';\n    document.getElementById('progress_bar_status').innerHTML = strStatus;\n}\n\nBAR;\n    }\n    else\n        if ( $intDisplayedCurrentPercent  $intCurrentPercent ) {\n            $intDisplayedCurrentPercent = $intCurrentPercent;\n            $strProgressBar = <<< BAR\n\npower_tools_progress_bar_update($intCurrentPercent,'$strStatus');\n\nBAR;\n        }\n    echo $strProgressBar;\n    flush();\n    ob_flush();\n}\n \n?><\/pre>\n","protected":false},"excerpt":{"rendered":"

I read about a plugin for WPMU, yes WPMU, that also works with Multisite 3.0+ so far to clean up old spam blogs, users, posts and comments. It was called WPMU Power Tools by Paid To Blog but it has since vanished from the web, but I managed to find a copy. Code is below, […]<\/p>\n","protected":false},"author":2,"featured_media":3520,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false},"categories":[26,66,75,76],"tags":[],"yoast_head":"\nWPMU Power Tools - E<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WPMU Power Tools - E\" \/>\n<meta property=\"og:description\" content=\"I read about a plugin for WPMU, yes WPMU, that also works with Multisite 3.0+ so far to clean up old spam blogs, users, posts and comments. It was called WPMU Power Tools by Paid To Blog but it has since vanished from the web, but I managed to find a copy. Code is below, […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/\" \/>\n<meta property=\"og:site_name\" content=\"E\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-24T16:32:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.ed.gs\/wp-content\/uploads\/2012\/11\/235H.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2048\" \/>\n\t<meta property=\"og:image:height\" content=\"1365\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ed\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ed\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/\",\"url\":\"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/\",\"name\":\"WPMU Power Tools - E\",\"isPartOf\":{\"@id\":\"https:\/\/ed.gs\/#website\"},\"datePublished\":\"2012-11-24T16:32:15+00:00\",\"dateModified\":\"2012-11-24T16:32:15+00:00\",\"author\":{\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ed.gs\/#website\",\"url\":\"https:\/\/ed.gs\/\",\"name\":\"E\",\"description\":\"automation, consultancy, project management, web\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ed.gs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\",\"name\":\"Ed\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"caption\":\"Ed\"},\"url\":\"https:\/\/ed.gs\/author\/ed\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WPMU Power Tools - E","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/","og_locale":"en_GB","og_type":"article","og_title":"WPMU Power Tools - E","og_description":"I read about a plugin for WPMU, yes WPMU, that also works with Multisite 3.0+ so far to clean up old spam blogs, users, posts and comments. It was called WPMU Power Tools by Paid To Blog but it has since vanished from the web, but I managed to find a copy. Code is below, […]","og_url":"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/","og_site_name":"E","article_published_time":"2012-11-24T16:32:15+00:00","og_image":[{"width":2048,"height":1365,"url":"https:\/\/static.ed.gs\/wp-content\/uploads\/2012\/11\/235H.jpg","type":"image\/jpeg"}],"author":"Ed","twitter_misc":{"Written by":"Ed","Estimated reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/","url":"https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/","name":"WPMU Power Tools - E","isPartOf":{"@id":"https:\/\/ed.gs\/#website"},"datePublished":"2012-11-24T16:32:15+00:00","dateModified":"2012-11-24T16:32:15+00:00","author":{"@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ed.gs\/2012\/11\/24\/wpmu-power-tools\/"]}]},{"@type":"WebSite","@id":"https:\/\/ed.gs\/#website","url":"https:\/\/ed.gs\/","name":"E","description":"automation, consultancy, project management, web","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ed.gs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628","name":"Ed","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/ed.gs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","caption":"Ed"},"url":"https:\/\/ed.gs\/author\/ed\/"}]}},"_links":{"self":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/2305"}],"collection":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/comments?post=2305"}],"version-history":[{"count":0,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/2305\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media\/3520"}],"wp:attachment":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media?parent=2305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/categories?post=2305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/tags?post=2305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}