Author Archives: RavanH

Advanced options for Easy FancyBox

It’s finally going live: The long awaited extension to bring advanced options to the regular Easy FancyBox plugin for WordPress. Read all about the new options and order online on http://status301.net/wordpress-plugins/easy-fancybox-pro/.

How to customise Jetpack’s Infinite Scroll footer – the proper way

Browsing the interwebs for info on how to change the footer that comes with the Infinite Scroll module in Jetpack I found, to my horror, several how-to’s that all involved hacking core plugin files. This is, obviously, not right. You’ll be modifying Jetpack files after each update (and these seem to be quite regular) untill the end of days… So here is the right way™ of doing it. Continue reading

WordPress 3.7 “Basie”

The Status 301 Network has just been upgraded successfully to the latest stable WordPress release: 3.7.1 “Basie”. Moreover, the admin theme MP6 has been added in preparation of the expected 3.8 release in December, providing a cleaner admin interface.

mp6 dashboard

Read more about new features in WordPress 3.7 “Basie” on the WordPress News blog.

Remove buttons from the WordPress Rich Text Editor toolbar

A simple task for someone up to his shoulders in WordPress code on a weekly basis, one would guess. And as the WordPress codex suggests, there is an easy filter available where you can use unset to remove the undesired buttons by name from an array.

The arrays for the different (advanced) toolbars can be found in class-wp-editor.php (just hit Ctrl+F and enter “mce_buttons_”) about half way down the page. In the following example, I try to remove buttons from the advanced toolbar which are defined by default as

array( 'formatselect', 'underline', 'justifyfull', 'forecolor', 'pastetext', 'pasteword', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' )

The WordPress Codex page on MCE Toolbar filters gave me (NOTE: It won’t anymore, I updated the codex page) this example:

function myplugin_tinymce_buttons($buttons) {
      //Remove the text color selector
      unset($buttons['forecolor']);

      return $buttons;
}
add_filter('mce_buttons_2','myplugin_tinymce_buttons')

But no. This simple example does not cut it. It simply had NO effect 🙁

After a long hard search, I found that unset() needs to reference an array value by its key while in the example the value ‘forecolor’ is used. So unset($buttons[‘forecolor’]) does not do anything while unset($buttons[3]) (3 is the key for the 4th value in the default array) would work fine. But it’s no fun like that and if the order of buttons would ever change, this solution would remove another button.

This example, using array_search() to get the appropriate key would solve that issue:

function myplugin_tinymce_buttons($buttons) {
	//Remove the text color selector
	if ( ( $key = array_search('forecolor',$buttons) ) !== false )
		unset($buttons[$key]);

	return $buttons;
}
add_filter('mce_buttons_2','myplugin_tinymce_buttons');

But here is a simpler example that will work, while also allowing other buttons to be removed at the same time. Just add their name — see the default array above — to the $remove array.

function myplugin_tinymce_buttons($buttons) {
	//Remove the format dropdown select and text color selector
	$remove = array('formatselect','forecolor');

	return array_diff($buttons,$remove);;
}
add_filter('mce_buttons_2','myplugin_tinymce_buttons');

By the way, if you need to add a new button or element, use for example array_unshift($buttons,’styleselect’); to place it at the start of the toolbar or array_push($buttons,’styleselect’); to place it at the end. In both cases, the second argument can also be an array to append multiple elements at the same time.

Have fun!