New WordPress Plugin: Hide Inactive Sites

At work, we setup a blog server back in 2009. One of our goals was to make sure if people weren’t keeping their blogs up-to-date their site would be hidden from the listing of blogs. Well, I finally took the time to work out an automated solution.

Introducing, Hide Inactive Sites; this baby is a blog server administrator’s dream come true!

It’s setup to be extendable. If you need to edit the query of blogs being returned, fine, change it using a filter. Need more time options or privacy options, done…add your own using hooks.

It slices, it dices, and it even hides your old, out-dated blogs.

Enjoy!

WordPress Multisite Suggestions

At work I’m currently trying to migrate away from our CMS and move us to WordPress Multisite. To me it seems like there are a few different ways to use WordPress Multisite, and I’m starting to think that should be a question when installing it. Some of the uses could be:

  1. A network of blogs owned by different users
  2. A large CMS with each separate site in the network being used to separate user permissions for editing (how I’m setting up our work install)
  3. CMS setup with each separate site as a different language (en.mysite.com, fr.mysite.com)

Based on the option you choose, it would be nice to customize WordPress for your needs. For example, say you select option 2 for your site (as I have for work). The entire site’s pages are spread out across multiple sites in the network. This is a pain in the neck when it comes to managing a custom menu using WordPress’s built-in menu system. I can only see the pages for the current site I’m on, not all the pages in the entire network.

Site Structure pluginAlso, in WordPress Multisite, there is no idea of subsites; they are all at the top level in the navigation. For my site, I’d like to “nest” some sites underneath others. Currently there was no way to do this, so I created a plugin called Site Structure to manage the hierarchy of sites (this is only for WordPress Multisite) across the network. You click and drag the site to it’s proper location in the hierarchy and save. Just a note, I haven’t released this plugin because I wasn’t sure anyone else had a need for it. If someone does, please post a comment and we’ll talk.

Left NavigationOn the front-end, I had to do a few extra queries to get it to work, but our left navigation functions just as it currently does on our site (it shows 3 levels of navigation). Site Structure (my plugin) stores all of the sites in an array that’s easily accessible from your theme files; this way you can query it however you need to from the front-end of your site. The only thing I haven’t quite figured out is how to layer pages from these sites in the mix. Currently, they just fall to the bottom of the list below the subsites. For example, if Academics had a page called Academic Affairs, that page would fall below School of Health Professions in the menu. I have not made it smart enough to have the subsites fall under pages in the navigation. Maybe in the future.

WordPress: Get All Users Having a Specific Role

I was searching online for a quick solution to retrieving a list of users from WordPress by role. I found a solution but decided to check the core user functions for a better alternative. As of WordPress 3.1, you can use the handy get_users() function.

Old Way
You had to create your own function that used the WP_User_Search() object.

function getUsersWithRole($role) {
    $wp_user_search = new WP_User_Search($usersearch, $userspage, $role);
    return $wp_user_search->get_results();
}
$editors = getUsersWithRole('editor');

New Way

$editors = get_users('role=editor');

St. Louis WordPress Users Group

Lately I’ve been thinking it would be good to start a St. Louis WordPress users group. I’d love to attend some of these and meet some other WordPress people in the St. Louis area. The idea of having a St. Louis WordCamp is also appealing, but I think it would be beneficial to find out how many people are interested in WordPress before investing the time for a WordCamp.

So who out there has a place to host such an event and would want to put it on? I’d be happy to help, but I’m not sure I’d be able to make it to every meeting. I wouldn’t want to be the point person, I’m just trying to get the ball rolling.

EDIT: I did come across a group on Facebook, the St. Louis and St. Charles WordPress Users Group. I signed up, but it doesn’t seem very active.

EDIT x2: I just found a meetup group for STL WordPress: http://www.meetup.com/stlwordpress/

WordPress 3.0 and Menu Dropdown Box

I’ve started to play around with WordPress 3.0 Beta 2 and the new menu system it has. While playing around with it, I thought it might be nice to include a dropdown box of menu choices on a settings page for a theme. So I made a function similar to that of the dropdown box for categories (wp_dropdown_categories). I called this one wp_dropdown_nav_menus.

function wp_dropdown_nav_menus($args = ''){
	$defaults = array(
		'echo' => 1,
		'id' => '',
		'orderby' => 'name',
		'order' => 'ASC',
		'hide_empty' => 1,
		'selected' => 0,
		'class' => 'postform',
		'tab_index' => 0,
		'show_option_all' => '',
		'show_option_none' => '',
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r );

	$tab_index_attribute = '';
	if ( (int) $tab_index > 0 )
		$tab_index_attribute = " tabindex="$tab_index"";

	$terms = get_terms( 'nav_menu', array( 'hide_empty' => $r['hide_if_empty'], 'orderby' => $r['orderby'], 'order' => $r['order'] ));

	if(! empty($terms)){
		$output = "";
	}

	if ($echo){
		echo $output;
	}

	return $output;
}

If you want to use this in your code, please change the prefix of the function from wp_ to something more useful for your purpose. Just in case WordPress comes out with a function similar to this one.

Piwik Analytics

Has anyone messed with Piwik Analytics? I just got it setup on thejudens.com yesterday, and so far it seems pretty slick. The one thing I like most about it is that the data is mine! I don’t have to share it with google! Right now we have both google analytics and piwik running on the server. I’m going to let them run and see how they compare with each other. I’m just kind of curious how close the results will be with the other. I’ll report back later and let everyone know.

In the meantime, you better go check out Piwik. It runs on php/mysql and you can most likely install it on your hosting account.

WordPress MU List Blogs

I recently had to make a list of all the active blogs for the university’s blog site running WordPress MU. Here’s the code to do so:

Blog Directory

You’ll notice the query is set to filter out blogs that are marked as archived, spam, private. Also, it hides the main blog from the list.

UPDATE: As posted in the comments by Brad, you can sort these in alphabetical order by the site name by using the following code: