Tag Archives: wordpress

“Table marked as crashed”

I encountered a pretty scary error on the WordPress Multisite network I manage yesterday, which turned out to be something relatively minor. I thought I’d blog it in case someone else found themselves in a similar situation and began frantically Googling… which is what I was doing last night as my wife (thankfully) handled getting the kids to bed.

We think we’ve been having some brute force attacks on our server over the past few months, and while our server mostly weathers them, we had one yesterday morning that required a manual restart of the virtual machine where our system is housed. We were back online in no time and all looked good. I then had a pretty busy day, and wasn’t spending much time on the system, but got no notices that there were problems (usually I’ll hear from users if something’s amiss).

Towards the end of the day, on either side of my commute, I saw the following symptoms emerge:

  • I noticed that it was taking a long time to access my dashboard even though the site load was normal. I was though still able to eventually get in.
  • On my way out of the office, I noticed that the BuddyPress admin bar was visible even though I had set it to be hidden for logged out users. I noted to take a look at this when I got home. When I did, I found that I couldn’t change that or any other BP setting… when I clicked “save,” the setting reverted to “not hidden.”
  • While going back and forth between the front and back ends, I suddenly lost the super admin capability on my personal account, though I was still able to access the super admin menu with the “admin” user.
  • I then noticed several plugins — including BuddyPress, WP-Super Cache — had been suddenly deactivated, and I couldn’t reactivate them.
  • Then, I noticed that no network themes were available in the Appearance>Themes menu, and that the “enabled” setting on all themes on the wp-admin/ms-themes.php page had been toggled to “no”
  • The home site went white, probably because BuddyPress was no longer enabled and that site runs a BP theme
  • All subdirectory sites seemed fine and were accepting posts.

I’ve never seen this collection of problems before, and began to worry that perhaps the system got hacked…although the pattern of symptoms suggested something was interfering with the database. I first deleted all plugins (except the shar-db plugin), but doing so changed nothing.

Then, I thought, if this is really bad, I need to make sure I have a current MYSQL dump. When running the dump, I got this error:

mysqldump: Got error: 145: Table ‘./wpmu_global/wp_sitemeta’ is marked as crashed and should be repaired when using LOCK TABLES

Ah… crashed database table! I repaired that table via PhpMyAdmin, and, voila, problem resolved.

It seems as though the hard reset that the system required in the morning corrupted the database, and led to the gradual emergence of these symptoms.

Live, learn, and make sure you check your database.

Blogs@Baruch, now with BuddyPress!

I recently completed a significant upgrade to Blogs@Baruch, and I thought I’d blog my hacks and some of the thinking behind them for teh Google to index.

The goal of the upgrade was to get BuddyPress up and running, which will create additional avenues for social publishing and networking around academic interests across the College. The upgrade included two new WordPress child themes, one that uses bp-default (for the home site and all BuddyPress functionality) and one that uses TwentyTen (a new default theme).

if ( is_user_logged_in() )

Since we’re rolling BuddyPress into a system that’s been active for almost two years already, and which has more than four thousand users, I was hesitant to just automatically give everybody public profiles or to make the member list publicly visible. The following simple argument came in very handy in these cases:


<?php if ( is_user_logged_in() ) : ?>
<?php else : ?>
<?php endif; ?>			

I snaked this code through functions in a number of places:

  • in header of the BP child theme to hide the Members list (by excluding the page id for the Members page in the “else” statement)
  • in sidebar.php file of my child theme, to give logged-in users relevant quick links
  • in members/index.php of my child theme, to hide the Members directory
  • in members/single/home.php to hide individual Profile pages

I also hide the BP admin bar for logged out users (which is an option built into BP)… So if you’re a visitor to the site, BuddyPress won’t be visible to you.

Logged out:

Logged in:

This is the way we’re going to keep it for now, and I think such a structure reflects our sense of BuddyPress primarily as a tool for the community to get to know itself a little better. Rumor has it that some more granular privacy control will be coming down the pike in future versions of BuddyPress, and we’ll revisit this issue as appropriate.

bp-custom.php etc.

Every BuddyPress install should have a bp-custom.php file located in wp-content/plugins/ which houses customizations. I used this file to change the order of the tabs on Profile pages, and to insert additional menus on the BuddyPress admin bar.

One of the great challenges I’ve had is the fact that one of my good buddies and partners in pizza-eating crime has become one of the top BuddyPress/WordPress developers around, and Boone’s on my IM rolls. I’m often faced with the dilemma of taking an hour to figure something out, or bothering him and getting some code in about 3 minutes. He helped me with code for the tab order:


function change_profile_tab_order() {
	global $bp;

	$bp->bp_nav['profile']['position'] = 10;
	$bp->bp_nav['activity']['position'] = 20;
	$bp->bp_nav['blogs']['position'] = 30;
	$bp->bp_nav['friends']['position'] = 40;
	$bp->bp_nav['messages']['position'] = 50;
	$bp->bp_nav['groups']['position'] = 60;
	$bp->bp_nav['settings']['position'] = 70;
}

add_action( 'bp_setup_nav', 'change_profile_tab_order', 999 );

The additional menus in the admin bar, I figured out with help from the Codex:


function my_help_link(){
  ?>
  <li><a href="http://blsciblogs.baruch.cuny.edu/support/explanation-of-buddypress/">HELP!</a>

 <ul class="wp-admin-bar">
<li><a href="http://blsciblogs.baruch.cuny.edu/support/guide-to-buddypress/">Guide to Buddypress</a></li>
  <li><a href="http://blsciblogs.baruch.cuny.edu/support/for-blog-authors/">Support for Students</a></li>
  <li><a href="http://blsciblogs.baruch.cuny.edu/support/for-blog-administrators/">Support for Faculty</a></li>
  <li><a href="http://blsciblogs.baruch.cuny.edu/contact/">Contact</a></li>
  </ul>
  </li>
  <?php
}
add_action( 'bp_adminbar_menus', 'my_help_link', 14 );

function quick_links(){
  ?>
  <li><a href="http://blsciblogs.baruch.cuny.edu/support/explanation-of-buddypress/">Quick Links</a>

 <ul class="wp-admin-bar">
  <li><a href="http://blsciblogs.baruch.cuny.edu/about-blogsbaruch/terms-of-service/">Terms of Service</a></li>
  <li><a href="http://www.baruch.cuny.edu/blsci">BLSCI</a></li>
  <li><a href="http://www.baruch.cuny.edu/bctc">BCTC</a></li>
  <li><a href="http://www.baruch.cuny.edu/">Baruch College</a></li>
  </ul>
  </li>
  <?php
}


And, with Boone’s help, I made a change to my wp-config.php file so that Profile (rather than the Activity Stream) became the default component loaded when you visited a member’s page. (I located this line of code just beneath the “/* That’s all, stop editing! Happy blogging. */” comment, as it didn’t work when I put it at the end of the wp-config.php file).


 /** Sets BP Nav to load Profile first */
define( 'BP_DEFAULT_COMPONENT', 'profile' );

These changes are intended to prioritize Profiles. We want our users to share information about themselves and to use Boone’s Custom Profile Filters to connect with others at the College with similar interests. While the CUNY Academic Commons, for which that plugin was written, hopes to connect CUNYs across campuses, we want do this on a more local scale. When all of our incoming students get their Blogs@Baruch accounts next week, they will be asked to fill out their profiles and to begin exploring.

New Default Theme

I also used the upgrade opportunity to create a new default theme for sites created on Blogs@Baruch, a child of TwentyTen which features some Baruch College and CUNY branding/linking and altered css. Aided by this tutorial, I swapped out the built-in header images that ship with TwentyTen for images taken from Baruch College’s library of photographs. Here’s the code for that, placed into the theme’s functions.php file:


define( 'HEADER_IMAGE', get_bloginfo('stylesheet_directory') .'/images/headers/baruchcollege.jpg' );

add_action( 'after_setup_theme', 'blogsatbaruch_setup' );
function blogsatbaruch_setup(){

/* Add additional default headers: All Photos are from Baruch College Visual Standards Library: http://www.baruch.cuny.edu/visualstandards/photos.htm */

	$blogsatbaruch_dir =	get_bloginfo('stylesheet_directory');
	register_default_headers( array (
		'Baruch' => array (
			'url' => "$blogsatbaruch_dir/images/headers/baruchcollege.jpg",
			'thumbnail_url' => "$blogsatbaruch_dir/images/headers/baruchcollege-thumbnail.jpg",
			'description' => __( 'Baruch College', 'blogsatbaruch' )
		),
		'Elevators' => array (
			'url' => "$blogsatbaruch_dir/images/headers/elevators.jpg",
			'thumbnail_url' => "$blogsatbaruch_dir/images/headers/elevators-thumbnail.jpg",
			'description' => __( 'Elevators', 'blogsatbaruch' )
		),
		'Reading' => array (
			'url' => "$blogsatbaruch_dir/images/headers/reading.jpg",
			'thumbnail_url' => "$blogsatbaruch_dir/images/headers/reading-thumbnail.jpg",
			'description' => __( 'Reading', 'blogsatbaruch' )
		),
		'Streetsign' => array (
			'url' => "$blogsatbaruch_dir/images/headers/streetsign.jpg",
			'thumbnail_url' => "$blogsatbaruch_dir/images/headers/streetsign-thumbnail.jpg",
			'description' => __( 'Street Sign', 'blogsatbaruch' )
		),
		'Turnstiles' => array (
			'url' => "$blogsatbaruch_dir/images/headers/turnstiles.jpg",
			'thumbnail_url' => "$blogsatbaruch_dir/images/headers/turnstiles-thumbnail.jpg",
			'description' => __( 'Turnstiles', 'blogsatbaruch' )
		),
		'VC View' => array (
			'url' => "$blogsatbaruch_dir/images/headers/vcview.jpg",
			'thumbnail_url' => "$blogsatbaruch_dir/images/headers/vcview-thumbnail.jpg",
			'description' => __( 'View from VC', 'blogsatbaruch' )
		),
		'Windows' => array (
			'url' => "$blogsatbaruch_dir/images/headers/windows.jpg",
			'thumbnail_url' => "$blogsatbaruch_dir/images/headers/windows-thumbnail.jpg",
			'description' => __( 'Windows', 'blogsatbaruch' )
		),

	));
}

function remove_twenty_ten_headers(){
	unregister_default_headers( array(
		'berries',
		'cherryblossom',
		'concave',
		'fern',
		'forestfloor',
		'inkwell',
		'path' ,
		'sunset')
	);
}

add_action( 'after_setup_theme', 'remove_twenty_ten_headers', 11 );

And here’s what it looks like:

This new theme is sharper than what previously loaded, and TwentyTen is customizable enough that I think a lot of our users will just keep it as their primary theme.

Bye Bye Userthemes

Finally, I’ve done away Userthemes on Blogs@Baruch. The last two WP upgrades have required hacks to keep the plugin only half-working (I’ve never been able to turn off Userthemes on blogs… once you go Userthemes you’ll never go back!). It’s such an important part of what we do on the system that I wanted to cease relying on such an unstable plugin. Instead, with Tom Harbison’s help, we copied all of our custom themes into the theme library and renamed their folders to the site id for which they were intended. We didn’t activate these themes site wide, but rather went one by one through the blogs, editing the template, stylesheet, and theme settings for each. Not the perfect solution, but it feels more stable than relying on Userthemes.

Those are the hacks that I remember. I’m sure there are a few that I missed.

If you’d like to take a look at the child themes, here they are: Blogs at Baruch BP (child of bp-default) and Blogs at Baruch (child of TwentyTen).