Contact Kailey Lampert

x Cancel
posted 1 month ago

Customizing the WordPress Toolbar

                <?php

add_action('admin_bar_menu', 'customize_admin_bar', 11 );
function customize_admin_bar( $wp_admin_bar ) {

	/*
		Change "Howdy"
	*/
	//get the node that contains "howdy"
	$my_account = $wp_admin_bar->get_node('my-account');
	//change the "howdy"
	$my_account->title = str_replace( 'Howdy,', "'ello", $my_account->title );
	//remove the original node
	$wp_admin_bar->remove_node('my-account');
	//add back our modified version
	$wp_admin_bar->add_node( $my_account );
	
	/*
		Removing the "W" menu
		I have nothing against it,
		but I *never* use it
	*/
	$wp_admin_bar->remove_menu( 'wp-logo' );

	/*
		Create a "Favorites" menu
		First, just create the parent menu item
	*/
	$wp_admin_bar->add_menu( array(
		'id' => 'favorites',
		'parent'    => 'top-secondary', //puts it on the right-hand side
		'title' => 'Favorites',
	) );

	/*
		Then add links to it
		This link goes to the All Settings page,
		so only show it to users that have appropriate privileges
	*/
	if ( current_user_can( 'manage_options' ) )
	$wp_admin_bar->add_menu( array(
		'id' => 'all-settings',
		'parent'    => 'favorites',
		'title' => 'All Settings',
		'href' => admin_url('options.php')
	) );

	/*
		This one goes to the list of the current user's posts
	*/
	$wp_admin_bar->add_menu( array(
		'id' => 'my-posts',
		'parent'    => 'favorites',
		'title' => 'My Posts',
		'href' => admin_url( 'edit.php?post_type=post&author=' . get_current_user_id() )
	) );
	
}
                
Raw

Some time ago, I posted code that showed how to add any link to the built-in WordPress favorites menu - but that has since been removed from core.

So I've been playing around with ways to replicate this feature and otherwise customize the new Toolbar in WordPress 3.3. It's pretty neat in part because it's a permanent feature of the admin area. Since it can't be turned off (okay, maybe it can with some code - but it's not recommended) it can be a great place to stash some shortcuts. While adding things we do want, we can get rid of other things.

So in the code above, as you can see in the comments, I've changed "Howdy" removed the "W"/logo menu, and added a menu to hold my shortcuts.

Have better ideas? Let me know!

posted 4 months ago

Domain Mapping + Nginx + WordPress

Been tinkering with WordPress Multisite + domain mapping + nginx this evening, and for the most part (as far as I can tell) everything is going wonderfully.

Except for one thing.

mapped.com/wp-admin (note the lack of trailing slash) redirects to domain.com/wp-admin/
(mapped.com/wp-admin/ works just fine)

Both domain.com/wp-admin and sub.domain.com/wp-admin are correctly rewritten with the trailing slash.

I'm certainly not a server admin, so I may very well have an error in my conf files, but everything else seems to be working just fine...

Here's my conf file for domain.com:

server {
        listen  80 default;
        server_name _;
        access_log  /var/www/domain.com/logs/access.log;
        error_log   /var/www/domain.com/logs/error.log;

        rewrite /wp-admin$ $scheme://$host$uri/ permanent;

        location / {
                root   /var/www/domain.com/html;
                try_files $uri $uri/ /index.php?$args;
                index  index.html index.php;

                # this serves static files that exist without running other rewrite tests
                if (-f $request_filename) {
                        expires 30d;
                        break;
                }

                # this sends all non-existing file or directory requests to index.php
                if (!-e $request_filename) {
                        rewrite ^(.+)$ /index.php?q=$1 last;
                }

        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www/domain.com/html$fastcgi_script$
                include fastcgi_params;
        }

}

Please let me know if you have any questions for me, but it's closing in on 1am, so I may not respond for a few hours :)

posted 7 months ago

Add Font-Select Dropdown to WordPress Visual Editor

                /*
	use only one of these filters, not both
*/
add_filter('mce_buttons_2', 'add_fontselect_row_2' );
//add_filter('mce_buttons_3', 'add_fontselect_row_3' );

function add_fontselect_row_2( $mce_buttons ) {
	/*
		if some items aren't removed from the second row
		the buttons won't fit nicely on a 1024x768 screen
		
		find the keys of the buttons to be sacrificed

		see WordPress's default buttons in wp_tiny_mce()
		http://phpxref.ftwr.co.uk/wordpress/wp-admin/includes/post.php.source.html#l1415
	*/
	$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;
}
function add_fontselect_row_3( $mce_buttons ) {
	/*
		nothing appears in the third row (or forth) by default, so no magic needed
	*/
	$mce_buttons[] = 'fontselect';
	return $mce_buttons;
}

/*
	customize available fonts
	edit as needed to modify the available fonts
*/
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;
}
                
Raw

font-select dropdown

For those that can be trusted with font-family choices, you can use this to add the font-select dropdown to the Visual Editor toolbar in WordPress.

The dropdown can be added to the third row of buttons very easily. But if you want to add it to the second row, you should make some room.

Also, you'll probably want to adjust the available fonts (i.e. don't allow Comic Sans).

Update: If you want it as a plugin, it appears to have been released by @priteshgupta - get it here

posted 8 months ago

Color Slider with jQuery

http://jsfiddle.net/trepmal/WvjJZ/

color sliders

Unfortunately, not Firefox friendly :(

I made this partly so that I would get more familiar with jsFiddle, and partly so I could build a prototype of some controls I needed on another project.

I think it turned out pretty well, but I'm sure there's room for improvement.

I'm not particularly fluent with JS, so I'd love to get some feedback from those of you who are pretty savvy with it.

posted 8 months ago

Sharing color palettes

http://colorto.me/

This started as a little project on a subdomain with the sole purpose of previewing colors based on a hex code.

But geek that I am, I kept tinkering with it and ended up with a bit more - and I think it's pretty neat.

I'd love to here your feedback on it.

You can either put together color palettes and simply link to it colorto.me/aaa/000/ff9/3a9057/

or create an image of the palette and embed that:

tri-color

  • only really tested on Chrome 13 and Firefox 5 for Mac... I'll get to the others eventually.
  • be kind, I don't think my server can take too much
  • inspired in part by @kingkool68's dummyimage.com/
posted 8 months ago

Remove links from the WordPress 3.2 Footer

                    add_filter( 'admin_footer_text', 'change_footer_text' );
    function change_footer_text( $text ) {
        $text = explode( ' &bull; ', $text );
        // [0] => Thank you for creating with WordPress.
        // [1] => Documentation
        // [2] => Freedoms
        // [3] => Feedback
        // [4] => Credits
        unset( $text[2] );
        unset( $text[3] );
        unset( $text[4] );
        return implode( ' &bull; ', $text );
    }                
Raw

In WordPress 3.2, there are some fancy new links in the footer, like Freedoms and Credits.

WordPress 3.2 Footer

I don't have anything against them, but I can see how a client might be confused by them (if they even look down there...).

So with the code above, you can clean up some of the links

WordPress 3.2 Footer, after

Of course, you can remove the footer entirely or completely change the text

//remove it entirely
add_filter( 'admin_footer_text', '__return_false' );

//completely custom footer
add_filter( 'admin_footer_text', 'change_footer_text2' );
function change_footer_text2( $text ) {
    return 'New footer.';
}

(You can use this in pre-3.2, but you'll need to explode by the pipe character ("|"). [0] => Thanks you [1] => Documentation [2] => Feedback )

posted 12 months ago

WordPress 3.1

http://wordpress.org/news/2011/02/threeone/

After 5 release candidates, WordPress 3.1 is out.

Admin bar, post formats and more.... :)

posted 1 year ago

Fun with stripes

I'm definitely not a designer, but I needed a background for a site I'm working on and I wanted something that I created and wasn't just a solid color.

I started playing around with some of the renders and filters in Photoshop and found (what I think to be) a neat way to create stripes.

It's not too fancy - but I've got to take baby steps!

I'm definitely not a designer, but I needed a background for a site I'm working on and I wanted something that I created and wasn't just a solid color.

I started playing around with some of the renders and filters in Photoshop and found (what I think to be) a neat way to create stripes.

It's not too fancy - but I've got to take baby steps!

posted 2 years ago

PHP File Tree/List

                <?php

function get_tree( $dr = '' )
{
	$dr = $dr . '*';
	$current = glob( $dr );
	
	if ( is_array( $current ) )
	{
		echo '<ul>';

		foreach( $current as $fl )
		{
			$fl = str_replace( dirname( $fl ) , '' , $fl );
			echo '<li>' . $fl . '</li>';
			if ( is_dir( $fl ) ) //if there's a dir, go deeper
			{ 
				get_tree( $fl . '*/' ); 
			}
		}

		echo '</ul>';
	}
}

get_tree(); 

?>                
Raw

Spits out a nice unordered list of every file and directory and indicates depth.

I just needed something simple, and every script I found did more than I needed.

If you've got an improvement, please share.

posted 2 years ago

Remove Update Nag from WordPress

                <?php
add_action( 'admin_init', 'no_update_nag' );
function no_update_nag() {
	remove_action( 'admin_notices', 'update_nag', 3 );
}
?>                
Raw

If for some reason you don't want to update (perhaps your plugins aren't all 3.0-compatible) you can toss this in your functions file to hide the update nag.

For MU users, you can create a file in your mu-plugins directory and paste in this code.