Tag Archives: WPMu

Safely delete spam comments across a large WP network

I’m currently working on a university WordPress network that’s been running for four or five years (an MU veteran!) and has almost 5000 blogs, most of which are defunct (because they’re from previous semesters). Akismet is activated across the network, so there’s not much of a public spam problem. However, even spam comments are stored in the database, and some of the blogs have tens of thousands of spam comments sitting in their tables. I’m going to implement a couple of tricks to keep this from happening in the future (a lightweight honeypot for non-logged-in users, tell Akismet to auto-delete spam comments on old posts). But for now, I’ve got to clean up this mess, because the very large comment and commentmeta tables are causing resource issues.

I wrote a simple script that gradually cycles through all the blogs on the network and deletes comments that have been marked as spam by Akismet. Here it is, with some comments afterward:

Notes:

  • The number of blogs is hardcoded (4980)
  • The ‘qw_delete_in_progress’ key is a throttle, ensuring that only one of these routines is running at a time. You might call this the poor man’s poor man’s cron.
  • I’ve limited it to 10 comments per pageload, but you could change that if you wanted
  • Put it in an mu-plugins file. When it’s finished running (check the ‘qw_delete_next_blog’ flag in the wp_sitemeta table – it’s done if it’s greater than the total number of blogs on the system), be sure to remove it, or at least comment out the register_shutdown_function line.

Use at your own risk – I’m posting here primarily for my own records 🙂

Importing Ning users into WP

Today Ning announced that it would be ending its free social networking service. I tweeted something to the effect that this event is a wake-up call: When you use closed-source, third-party hosted solutions for something as valuable as community connections, you are leaving yourself open to the whims and sways of corporate boards. It’s not that Ning is evil or anything – it goes without saying that they need to make a profit – but their priorities are importantly different from those of their users. In the same way that Ning moves from a freemium model to a paid model, Facebook could start selling your crap, Twitter could crash, Tumblr could go out of business, etc.

All this is a good argument to be using software solutions that are more under your control. Like – drumroll – WordPress and BuddyPress.

Enough moralizing. I whipped together a plugin this afternoon called Import From Ning that will allow you to get a CSV export of your Ning community’s member list (the only content that Ning has a handy export feature for, alas) and use it to import members into a WordPress installation.

As of right now, it does not have any BuddyPress-specific functionality. But the data that it does import – display name, username, email address – are enough to populate at least the beginnings of a BuddyPress profile. The next thing to add is the auto-import of certain profile fields. I might try to do this tomorrow. The plugin is based on DDImportUsers – thanks!

Instructions:

  • Download the zip file and unzip into your WP plugins directory
  • Look for the Import from Ning menu under Dashboard > Users (unless you’re running a recent trunk version of BuddyPress, in which case it will be under the BuddyPress menu)
  • Follow the instructions on that page

Download the plugin here.

Big new version of Invite Anyone for BuddyPress

My BuddyPress function Invite Anyone has always been misleadingly named. It expanded on BuddyPress’s default setup, which only allows members to send group invitations to people who they’re friends with, by allowing individuals to send invitations to anyone in the entire installation. This only qualifies as inviting anyone on a, er, very austere ontology of personhood. The new version of Invite Anyone, version 0.4, adds a new tab to BuddyPress profile tabs that allows invitation both to groups and to the site in general via email. It’s a big update, both in terms of features and in terms of sheer code (pretty sure the number of lines of code is close to triple what it was before).

And now you know what I did on my spring break.

If you know what’s good for you, you will Check It Out.

New BuddyPress plugin: BP Group Management

Another day, another plugin for BuddyPress. In BP < 1.2, it was impossible for site admins to manage group membership in groups where they weren't also the local admin. This is good in a lot of situations, but in some applications of BP it can be a pain – the system administrator needs more power in order to correct problem, wreak havoc, and so on. In BP 1.2+ the situation is better – admins can manage groups more – but it's still not all that easy to see everything in one place. This plugin rectifies the situation by allowing site admins to manage the members of groups across their BP installation from a single screen.

Read more about it.

New BuddyPress plugin: BP Import Blog Activity

I wrote a BuddyPress plugin today that is very ugly. It imports activity into BuddyPress from blog posts and comments that occurred before you had BuddyPress installed. It’s ugly because it’s sloppily coded and extremely inefficient and likely to hit PHP memory limits every time you run it. But it does the job, so I thought I’d post it and share it with others.

Read more about it, along with a bunch of warnings, here.

New BuddyPress plugin: BP MPO Activity Filter

In the past I and others have experienced some problems with the way that More Privacy Options for WPMu interacts with BuddyPress – or, to be more exact, with the way that the two don’t recognize each other. Blogs marked as private via MPO were getting plastered all over the public activity streams. In the past I have suggested some unpleasant but more or less functional core hacks, but now I’ve developed a plugin that does the job in the right way. It’s called … drumroll … BP MPO Activity Filter.

Check it out here.

Class blogrolls: No sweat

Last week, in the post where I announced my new WPMU plugin Shared Blogroll, I briefly mentioned the use case that I had in mind, which was of course education-focused. Yesterday and today I did some more work on the plugin itself (MORE AJAX 4EVA) and some of the supporting players. I thought I’d spell it out a little more so that others could implement what is probably the coolest system for shared blogrolls on earth, or at least on WPMU, which amounts to pretty much the same thing.

The plugins

  • Shared Blogroll. This creates a widget that allows bloggers to embed a link category from any other blog on the system on their own blog.
  • Add Users Sidebar Widget. This plugin is already pretty great, as well it should be seeing as it’s written by good-looking Canadians. I made some edits to the plugin to make it a bit more flexible.
    1. First I removed the RSS box from the Add User widget. For most of my users, it’ll confuse; for all of them, it’ll be redundant, since they’ll all be using Wordpress blogs and thus will have feeds that are very auto-discoverable.
    2. As the plugin stands in the repository, links are automatically put into the blog’s default link category (or, if they’re using FeedWordPress, the FWP link category). For most users, that’s something unhelpful like “Links” or “Uncategorized”. I altered the plugin so that the blog owner can choose which link category the added links will be put into. As I’ll discuss below, I think that this will add a lot of flexibility to the way that the plugins can be used together. You can download the text of my modified version of Add Users Sidebar Widget here: add-link-sidebar-widget.txt. Save as .php before uploading – and make sure that you uninstall previous versions of the plugin before uploading, or you might get whitescreened to death.
  • Optional step. The default WP Links widget is set up so that you can’t select to display an empty category of links. As you’ll see below, I want to have instructors create a new category for their blogrolls, and I figured it’d be pretty confusing if they couldn’t create a sidebar widget corresponding to a link category until at least one student had posted a link (thus populating the category). So I wrote a little plugin that replaces the default Links widget with one that allows you to pick an empty links category. Drop this into mu-plugins: link_widget_allow_empty_cat. Be warned, though, that this plugin deregisters the default Links widget, which might have the effect of removing every links widget on your installation of WPMU. (I haven’t tested it.) For me, it’s OK, because I don’t have any active users yet. As an alternative, you could edit the core of WP (making sure to back up, take note of where you made the edit for future upgrades, blah blah blah) in the following way. In wp-includes/default-widgets.php, line 139 reads [code language=”php”]$link_cats = get_terms( ‘link_category’);[/code] Replace it with [code language=”php”]$link_cats = get_terms( ‘link_category’, ‘hide_empty=0’);[/code] That should leave all of your pre-existing links widgets in place.

The process

The immediate goal of this setup is to allow a class blogroll to be shared effortlessly between members of a class. (Though I can imagine lots of other very cool uses.) Here are the directions I’m going to give to instructors and students on how to leverage these two plugins to make it happen.

Instructors

  • Create a new Link Category for your class blogroll – let’s say you call it “ENG 110 Blogroll”.
  • Add a Links widget to the sidebar, making sure to select “ENG 110 Blogroll” from the category dropdown.
  • Add an Add Links widget to the sidebar. Again, be sure to select “ENG 110” blogroll as the target category for added links.
  • Give your blog’s ID number to your students and give them the following directions.

Students

  • After creating a blog, visit the professor’s blog and enter your site’s URL into the Add Link sidebar widget.
  • Add a Shared Blogroll widget to your own blog’s sidebar. Enter the professor’s blog ID number as the source blog, select “ENG 110 Blogroll” from the dropdown list, and Save.

I hope that the instructors and students get into this blogroll sharing thing. It distributes what would otherwise be a huge amount of work for the instructor, or *worse yet*, for me.

New WPMU plugin: Shared Blogroll

I just wrote a widget that lets a blog admin pull a link category from any blog on the same WPMU installation. It is pretty much the bomb, and you are going to love using it so much that you may have to take downers in order to get yourself under control.

Check it out.

Side note: I’m going to start creating separate pages (as opposed to posts) for each of my software releases. That way all comments/support regarding a given plugin will be in the same place, with a pretty URL. That’s why I’m turning off comments on this post.

Blog-specific email plugin for WPMU users

A quick WPMU hack that I think will help a lot of people using an installation of WPMU for multiple classes.

The plugin Email Users by Vincent Prat allows blog authors/admins to email users in two different ways: 1) by emailing a group of users (such as those corresponding a particular role on your blog), or 2) by emailing individual users. The problem, though, is that this second option brings up a list of every single user on the installation of WPMU. This can be a bit of a pain for the normal blog user, as teachers or students in a class would probably only want to see a list of those people who are in the class, or on the blog.

Here’s a hack that will make the Email Users plugin show list only the members of the current blog for everyone except for the site admin:

  1. In the main plugin file (email-users.php), find the function mailusers_get_users. It should start around line 404.
  2. Look for the lines of code (414-417 in my version) that define the variable $users in the first conditional clause:
    [code language=”php”]
    $users = $wpdb->get_results(
    “SELECT id, user_email, display_name ”
    . “FROM $wpdb->users ”
    . $additional_sql_filter );
    [/code]
  3. Replace that line with the following code:
    [code language=”php”]
    if ( is_site_admin() ) {
    $users = $wpdb->get_results(
    “SELECT id, user_email, display_name ”
    . “FROM $wpdb->users ”
    . $additional_sql_filter );
    } else {
    $wp_user_search = new WP_User_Search(”, ”, ”);
    $user_list = $wp_user_search->get_results();
    $user_array = join(‘,’, $user_list);
    $users = $wpdb->get_results(
    “SELECT id, user_email, display_name ”
    . “FROM $wpdb->users ”
    . “WHERE id IN ( $user_array ) ” );
    }
    [/code]

Here’s the use case I envision. The instructor for a class places the Add User Sidebar Widget (by my boys at UBC’s OLT!) in the sidebar of his or her blog. As part of the first assignment of the semester, the instructor asks each student to register for an account, and click the “Add Me” button on the instructor’s blog. That will automatically populate the email list above.

File this tip under “who needs Blackboard?”.