Remove Buttons From Distraction-Free Writing

Want even fewer distractions in DFW? Remove some of the buttons

add_filter( 'wp_fullscreen_buttons', 'remove_fullscreen_buttons' );
function remove_fullscreen_buttons( $buttons ) {
	unset($buttons['bullist']);
	unset($buttons['numlist']);
	unset($buttons['1']);
	return $buttons;
}

Here are the buttons you have to work with:

$buttons = array(
	// format: title, onclick, show in both editors
	'bold' => array( 'title' => __('Bold (Ctrl + B)'), 'onclick' => 'fullscreen.b();', 'both' => false ),
	'italic' => array( 'title' => __('Italic (Ctrl + I)'), 'onclick' => 'fullscreen.i();', 'both' => false ),
	'0' => 'separator',
	'bullist' => array( 'title' => __('Unordered list (Alt + Shift + U)'), 'onclick' => 'fullscreen.ul();', 'both' => false ),
	'numlist' => array( 'title' => __('Ordered list (Alt + Shift + O)'), 'onclick' => 'fullscreen.ol();', 'both' => false ),
	'1' => 'separator',
	'blockquote' => array( 'title' => __('Blockquote (Alt+Shift+Q)'), 'onclick' => 'fullscreen.blockquote();', 'both' => false ),
	'image' => array( 'title' => __('Insert/edit image (Alt + Shift + M)'), 'onclick' => "fullscreen.medialib();", 'both' => true ),
	'2' => 'separator',
	'link' => array( 'title' => __('Insert/edit link (Alt + Shift + A)'), 'onclick' => 'fullscreen.link();', 'both' => true ),
	'unlink' => array( 'title' => __('Unlink (Alt + Shift + S)'), 'onclick' => 'fullscreen.unlink();', 'both' => false ),
	'3' => 'separator',
	'help' => array( 'title' => __('Help (Alt + Shift + H)'), 'onclick' => 'fullscreen.help();', 'both' => false )
);

Allow Non-Standard Tags in the Editor

If you find yourself needing to add non-standard tags to the WordPress editor, you may also find yourself feeling very frustrated. With just a little bit of code, you can tell the editor to accept extra tags

add_filter( 'tiny_mce_before_init', 'mce_extended_valid_elements', 10, 2);
function mce_extended_valid_elements( $mceInit, $editor_id ) {
	//allow only the basic tag
	//$mceInit['extended_valid_elements'] .= ',sometag';
	//allow the tag and a attribute
	$mceInit['extended_valid_elements'] .= ',sometag[someattribute]';
	//allow the tag and multiple attribute
	//$mceInit['extended_valid_elements'] .= ',sometag[someattribute|anotherattribute]';
	//allow the tag and any attribute
	//$mceInit['extended_valid_elements'] .= ',sometag[*]';
	return $mceInit;
}

Limit Spellchecker Languages

If you don’t want your spellchecker dropdown to be too big, you can limit the available languages. Cut it down to only a few, or even just one.

add_filter('mce_spellchecker_languages', 'limit_spellchecker_languages');
function limit_spellchecker_languages() {
	//original: +English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv
	return '+English=en';
}

Allow HTML in User Descriptions

By default, WordPress will remove any HTMl from the user bio field on the edit user/profile screen.

It’s very easy to stop WordPress from doing this

remove_filter( 'pre_user_description', 'wp_filter_kses' );

However, you probably don’t want to leave it at that, as users could then add any code (iframes, scripts, etc.) and it wouldn’t be removed.

add_filter( 'pre_user_description', 'wp_filter_post_kses' );

Change the “Enter title here” Placeholder Text

If “Enter title here” is just to boring for you, change it.

Could be especially useful for custom post types that use the title field in an untraditional manner.

add_filter( 'enter_title_here', 'change_enter_title_text', 10, 2 );
function change_enter_title_text( $text, $post ) {
        return 'The title. Don't forget to double-check your spelling before publishing.';
}

Require Additional Profile Fields at Registration

<?php

add_action( 'register_form', 'additional_profile_fields' );
function additional_profile_fields() { ?>
    <p>
        <label><?php _e('First Name') ?><br />
        <input type="text" name="first_name" id="first_name" class="input" size="25" tabindex="20" /></label>
    </p>
    <p>
        <label><?php _e('Last Name') ?><br />
        <input type="text" name="last_name" id="last_name" class="input" size="25" tabindex="20" /></label>
    </p>
<?php }
 
add_action( 'register_post', 'add_register_field_validate_first_name', 10, 3 );
function add_register_field_validate_first_name( $sanitized_user_login, $user_email, $errors) {
    if (!isset($_POST[ 'first_name' ]) || empty($_POST[ 'first_name' ])) {
    	return $errors->add( 'firstnameempty', '<strong>ERROR</strong>: Please provide a first name.' );
    }    
}
add_action( 'register_post', 'add_register_field_validate_last_name', 10, 3 );
function add_register_field_validate_last_name( $sanitized_user_login, $user_email, $errors) {
    if (!isset($_POST[ 'last_name' ]) || empty($_POST[ 'last_name' ])) {
    	return $errors->add( 'lastnameempty', '<strong>ERROR</strong>: Please provide a last name.' );
    }    
}

add_action( 'user_register', 'insert_register_fields' );
function insert_register_fields( $user_id ) {
	
	$first_name = apply_filters('pre_user_first_name', $_POST['first_name']);
	$last_name = apply_filters('pre_user_last_name', $_POST['last_name']);
	
	update_user_meta( $user_id, 'first_name', $first_name );
	update_user_meta( $user_id, 'last_name', $last_name );
}