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.