Add Font-Select Drop Down to Visual Editor

Add the font-select menu to the 2nd row of buttons (revealed with the Kitchen Sink button)

If some items aren’t removed from the second row, the buttons won’t fit nicely on a 1024×768 screen.

See WordPress’s default buttons in wp_tiny_mce()

add_filter('mce_buttons_2', 'add_fontselect_row_2' );

function add_fontselect_row_2( $mce_buttons ) {
    /*
        find the keys of the buttons to be sacrificed
    */
    $pastetext = array_search( 'pastetext', $mce_buttons );
    $pasteword = array_search( 'pasteword', $mce_buttons );
    $removeformat = array_search( 'removeformat', $mce_buttons );

    unset( $mce_buttons[ $pastetext ] );
    unset( $mce_buttons[ $pasteword ] );
    unset( $mce_buttons[ $removeformat ] );

    /*
        insert the new dropdown where the sacrificed buttons used to be
        alter as needed
    */
    array_splice( $mce_buttons, $pastetext, 0, 'fontselect' );
    return $mce_buttons;
}

But if you’re adding the 3rd row, you’re probably clear (unless you have other plugins that are adding buttons).

add_filter('mce_buttons_3', 'add_fontselect_row_3' );

function add_fontselect_row_3( $mce_buttons ) {
    $mce_buttons[] = 'fontselect';
    return $mce_buttons;
}

Currently, any buttons added to the 3rd or 4th rows will always be visible (Kitchen Sink only shows/hides the 2nd row) – but a patch has been submitted to correct this, hopefully it’ll be committed.

However, if you’ll probably want to clean up the font options – remove fonts that you’ll never use (or should never be used).

add_filter('tiny_mce_before_init', 'restrict_font_choices' );
function restrict_font_choices( $initArray ) {
    $initArray['theme_advanced_fonts'] = 
        'Andale Mono=andale mono,times;'.
        'Arial=arial,helvetica,sans-serif;'.
        //'Arial Black=arial black,avant garde;'.
        'Book Antiqua=book antiqua,palatino;'.
        //'Comic Sans MS=comic sans ms,sans-serif;'.
        'Courier New=courier new,courier;'.
        'Georgia=georgia,palatino;'.
        'Helvetica=helvetica;'.
        //'Impact=impact,chicago;'.
        //'Symbol=symbol;'.
        'Tahoma=tahoma,arial,helvetica,sans-serif;'.
        'Terminal=terminal,monaco;'.
        'Times New Roman=times new roman,times;'.
        'Trebuchet MS=trebuchet ms,geneva;'.
        'Verdana=verdana,geneva;'.
        //'Webdings=webdings;'.
        //'Wingdings=wingdings,zapf dingbats'.
        '';
    return $initArray;
}

Using WordPress, MultiSite, P2 and More

Expanding on this tweet.

My department at work has been using WordPress with the P2 theme for discussion recently. It has helped manage stop bulky reply-all emails between the 4 of us.

Besides limiting email, it’s encouraged more discussion. Before, we knew email was annoying, so we limited what we contributed, and certain things went unsaid – and some discussions were never even started. But now we can quickly comment on posts, even if it’s just “+1,” and start new topics on a whim.

We really like what P2 has done for us, so we decided that this would be great to use with the entire office. And not just for general discussion, but for planning bigger projects, keeping track of tasks, asking for help, sharing news, and anything else we can think of. We’re working in some CRM features, but we’re still planning that part (using the P2 of course).

Continue reading Using WordPress, MultiSite, P2 and More

Show Authors Their Own Posts in Admin

You can redirect the normal All Posts pages to a version that only displays the current user’s posts. (Similar to this post). Users will not be able to get back to the ‘all’ view, as in the other sample. Users are not prevented from changing the author ID in the URL and viewing another user’s posts.

add_action( 'load-edit.php', 'posts_for_current_author' );
function posts_for_current_author() {
	global $user_ID;

	/*if current user is an 'administrator' do nothing*/
	//if ( current_user_can( 'add_users' ) ) return;

	/*if current user is an 'administrator' or 'editor' do nothing*/
	//if ( current_user_can( 'edit_others_pages' ) ) return;

	if ( ! isset( $_GET['author'] ) ) {
		wp_redirect( add_query_arg( 'author', $user_ID ) );
		exit;
	}

}

Removed Categories Dropdown Filter

On the All Posts page, there are a series of filters for narrowing down what posts are displayed.

To remove the categories filter, use this:

add_action( 'load-edit.php', 'no_category_dropdown' );
function no_category_dropdown() {
	add_filter( 'wp_dropdown_cats', '__return_false' );
}

In the action hook, change ‘edit.php’ if you want to remove the dropdown on other pages.

Remove Bulk Actions Dropdown

To remove the bulk actions dropdown menu, you simply need to remove all actions! Just hook in and replace the default actions array with an empty array.

add_filter( 'bulk_actions-' . 'edit-post', '__return_empty_array' );

In this case, only the bulk actions menu on the All Posts page will be removed. To use elsewhere, replace ‘edit-post’ with the screen ID.

Default All Posts to the Current User’s Posts

When clicking on All Posts in the main menu, Administrators and Editors will normall see all posts. Use this to change the default view to the user’s own posts. See comments to limit the change to users of a certain roll.

add_action( 'admin_menu', 'show_users_posts_by_default' );
function show_users_posts_by_default() {

	/*if current user is an 'administrator' do nothing*/
	//if ( current_user_can( 'add_users' ) ) return;

	/*if current user is an 'administrator' or 'editor' do nothing*/
	//if ( current_user_can( 'edit_others_pages' ) ) return;

	global $submenu, $user_ID;
	$submenu['edit.php'][5][2] = 'edit.php?author='. $user_ID;
}

Disable the Auto-Scroll/Internal Anchors in Read More Links

If you don’t like that the ‘read more’ links automatically scroll you down the page (to the beginning of what ever comes after the <–more--> tag), you can so a little pattern matching to remove the internal anchor.

add_filter( 'the_content_more_link', 'read_more_no_jump', 10, 2 );
function read_more_no_jump( $link, $text ) {
	$no_more = preg_replace( '/#more-([0-9]*)/', '', $link );
	return $no_more;
}

Force Default Editor Mode

Normally, WordPress will remember which editor mode you were in (Visual or HTML). So if you were using the HTML editor and you save a page, you’ll be returned to the HTML editor.

If you (or your clients) would benefit from always returning to particular mode, you can set that up

add_filter( 'wp_default_editor', 'force_default_editor' );
function force_default_editor() { 
	//allowed: tinymce, html, test
	return 'tinymce';
}

*Functionality is there but quirky in pre-3.3

Change Protected Posts Prefix

If you’ve marked a post as “Protected” it is automatically prefixed with “Protected: ”

You may not like that. Here’s how you can change it:

add_filter('protected_title_format', 'change_protected_title_format');
function change_protected_title_format() {
	return 'Members Only: %s';
}

*If this seems oddly familiar, check out yesterday’s post.