Bradycardia & Cardiac Arrest for WordPress 3.6

Bradycardia is the resting heart rate of under 60 beats per minute….
Wikipedia

WordPress HeartbeatA new feature in WordPress 3.6 is an upgrade to the autosave functionality that’s been around for years. It’s called “Heartbeat” and it makes sure you have valid authentication credentials, aren’t working on the same post as other people, and more. The problem is that (as it is) it slows web pages down to a grinding halt.

Read the active discussion on WordPress.org about this feature – a lot of people are upset about the CPU load it adds.

Note: I don’t recommend doing these changes on every Admin page. Use sparingly.

Slow Down WordPress 3.6’s Racing Heartbeat

Here’s how to slow down the heartbeat from once every 15 seconds (the default) to once every minute (the max allowed by WordPress): Continue reading “Bradycardia & Cardiac Arrest for WordPress 3.6”

Add "Preview" Link to Manage Themes

Get That Preview Link Back!

Ever since WordPress added a Live Preview option to the Manage Themes screen, it’s been frustrating to test a plugin using multiple themes.

Why Live Preview sucks for developers

When using Live Preview, you can’t modify the URL of the page you’re visiting or open the preview in a new window or tab. Live Preview prevents you from viewing multiple themes at once in different tabs.

If you wanted to get the old Preview link back, you had to disable Javascript, then refresh the page, then open the links.  Continue reading “Add "Preview" Link to Manage Themes”

How to Email Pictures from iPhoto Using Mail.app

Update: If you are using iPhoto 11, you can simply go to "Preferences > Email photos using"
Update: If you are using iPhoto 11, you can simply go to Preferences > “Email photos using”

iPhoto Email Fail

iPhoto Mail App
The Best Kitties; The Worst Email App

iPhoto 11 added an awful new built-in email service that replaces the previous functionality: when sending an email, it used to open the Mail application and attach the photos to a new email. Now, it uses a terribly designed built-in email functionality that ruins everything.

Here’s how to get Mail.app back in iPhoto

Open the Terminal application.

Enter the following in Terminal: `defaults write com.apple.iPhoto EmailApp Mail`

Restart iPhoto and you’re all set.

If you change your mind, and you want to revert to using iPhoto’s email client, enter this in the Terminal: `defaults write com.apple.iPhoto EmailApp iPhoto`

How to Hide or Replace the WordPress Welcome Panel

Updated: now with more in-depth code!

So you want to modify the WordPress Dashboard Welcome Screen

There was a thread on the WPMU website that discusses how to disable the WordPress welcome screen, but the code provided didn’t work, so I figured I’d show how to do it!

The `wp_welcome_panel()` function uses the `show_welcome_panel` user meta setting to determine whether or not to show the welcome panel.  In order to modify this setting, we’re going to add a filter to the `get_user_metadata` filter, which uses the `get_metadata` function.

The following code snippets should be added to your theme’s `functions.php` file.

Disable the dashboard welcome screen…

This will only hide the panel, not replace it with any other content.

add_filter("get_user_metadata", "my_own_welcome_panel", 1, 4);

function my_own_welcome_panel($null, $object_id, $meta_key, $single) {
	if($meta_key === 'my_own_welcome_panel') { return 0; }
}

or Show Your Own Panel

You can replace the WP welcome panel with your own content using this snippet.

add_filter("get_user_metadata", "my_own_welcome_panel", 1, 4);
function my_own_welcome_panel($null, $object_id, $meta_key, $single) {

	// Only work with the show_welcome_panel
	if($meta_key !== 'show_welcome_panel') { return null; }

	// If the user has already said they don't want to see the panel, don't show it!
	$show_panel = get_user_meta( get_current_user_id(), 'my_own_welcome_panel', true );
	if(empty($show_panel)) { return 0; }

	// Echo your HTML or content here, but make sure to have a link like the following:
	?>
	<a class="welcome-panel-close" href="<?php echo esc_url( admin_url( '?my_own_welcome=0' ) ); ?>"><?php _e('Dismiss this Message'); ?></a>
	<?php

	// Return 0 or else the original welcome panel will show as well.
	return 0;
}

// Add the functionality to update the user's settings with whether or not they have closed the panel
add_action('admin_init', 'my_own_welcome_set_welcome_panel');
function my_own_welcome_set_welcome_panel() {
	if ( isset( $_GET['my_own_welcome'] ) ) {
		update_user_meta( get_current_user_id(), 'my_own_welcome_panel', intval($_GET['my_own_welcome']));
	}
}

Major Changes in the WordPress.org Plugin Directory

The new plugin Reviews feature suggests a shifting approach to the WordPress ecosystem.

Reviews: a new tab in town

WordPress.org Reviews TabOn every plugin page, there is now a Reviews tab. This is in addition to the Support tab that WordPress added around August.

Rating a plugin now requires a review

Until now, WordPress reviews were basic: 1-5 stars, with no additional details. You would only need to be signed in and click a star rating. With this change, WordPress.org requires users to be logged in and to write a review with their star rating. This will force users to be more thoughtful on why they rate a plugin a certain way.

You can now reply to reviews. Nice.Each review is now a forum thread: when a review is posted, the plugin author has a chance to reply. This is great for me as a plugin author: I can attempt to  resolve issues and get better plugin ratings. Users are able to modify their reviews and update their star ratings, which adds incentive for plugin authors to address issues with each reviewer. This is smart.

The beginning of higher accountability.

This is one way to add security and stability to the WordPress ecosystem.

I believe WordPress wants to have more tight controls over the plugins listed on the directory.  With over 22,000 plugins, Automattic simply does not have the resources to make sure all plugins are up to snuff.

The WordPress team has taken steps to help users know whether a plugin is good or not:

  • The May update made visible the number of resolved plugin support requests over a time span.
  • Earlier in the year, the website started displayed a banner alerting users when a plugin hadn’t been updated in over two years.
  • In 2011, the website started showing a graph of the plugin star ratings, not just the aggregated star rating. This helped visualize the plugin’s ratings.

WordPress as a platform.

Matt Mullenweg spoke at a WordCamp recently about his vision for auto-updating WordPress where users wouldn’t have to manually upgrade the software. His vision is of WordPress as a hassle-free platform, and I bet that reducing the variables added by troublesome plugins or themes is a high priority.

WordPress 3.5, currently in beta, introduces a new feature (emphasis mine):

You can browse and install plugins you’ve marked as favorites on WordPress.org, directly from your dashboard.

This feature, in concert with more in-depth reviews, marks a shift from a directory of plugin downloads to more of a WordPress “App Store” mentality: when you are logged in to your account, you can easily find and download your favorite plugins. The directory, armed with better ratings and review, will show higher-rated plugins first. All from inside WordPress instead of on the WordPress.org website.

This reviews implementation is a big next for the plugin directory, and is likely the first  step of many. I look forward to seeing what is planned for the directory, as well as the WordPress platform as a whole.


Notes as a Plugin Developer

  • On each plugin page, you can grab an RSS feed of the reviews, which will be helpful for responding to review comments. This is functionally similar to the plugin Support forum.
  • I really, really like this change. It will help good plugins get discovered.
  • Plugin authors can now respond to their critics! Re: Marco Arment.

Feature Request: Per-Version Ratings

Each review prominently displays the date of the review. I’m hoping that WordPress segment reviews on a per-version basis, like what Apple does in their App Store. There would be two charts: ratings for all versions, and ratings for the current version.

Prevent Refresh from Adding Another Product in WooCommerce

Update: this issue has been resolved. WooCommerce now replaces the `add-to-cart` query arg with `added-to-cart` on success.

Prevent items from being mistakenly added to the cart multiple times.

Mountain America Jerky uses the WooCommerce eCommerce plugin for WordPress, and they were having an issue: when users added a product to their cart then refreshed, the item was being added again. Also, when customers added items to their cart, then hit back, they got the dreaded “Confirm Form Resubmission” notice.

To solve this issue, I added a redirection when users added products to their cart. The code hooks into WooCommerce’s `woocommerce_add_to_cart_action` function, located in `/woocommerce/woocommerce-functions.php`.

Here’s the code that you should add to your theme’s `functions.php` file, or to your own custom plugin:

add_action('add_to_cart_redirect', 'resolve_dupes_add_to_cart_redirect');
 
function resolve_dupes_add_to_cart_redirect($url = false) {
 
     // If another plugin beats us to the punch, let them have their way with the URL
     if(!empty($url)) { return $url; }
 
     // Redirect back to the original page, without the 'add-to-cart' parameter.
     // We add the `get_bloginfo` part so it saves a redirect on https:// sites.
     return get_bloginfo('wpurl').add_query_arg(array(), remove_query_arg('add-to-cart'));
 
}

I hope this helps someone else with the same issue!

A Gravity Forms Add-on: Change Who Created An Entry

Download the “Change Entry Creator” Gravity Forms Add-on

Change User for an Entry In Gravity Forms

This simple plugin allows you to edit who created an entry in Gravity Forms.

When you have an entry from Gravity Forms that you want to edit, you can edit almost anything, except for the entry assignment; who created the entry.

Activate the plugin and you will see a drop-down input with each user on your site.

  • Only users with entry entry editing capability will be able to see the drop-down and edit the entry (the `gravityforms_edit_entries` capability)
  • Select a new user from the drop-down, update the entry, and the entry creator will be updated.
  • A note will be added to the entry with the following information:
    • Who changed the entry creator
    • When the change took place
    • Who the previous entry creator was

Simply upload the plugin, activate it, and you’ll see the drop-down in the Edit Lead “Info” box.

How to Change the Width of the Reading List Sidebar in Safari

For the record, I know this is a silly hack.

Add a new item to the `~/Library/Preferences/com.apple.Safari.plist` file:

Key: `SidebarSplitViewDividerPosition`
Type: "Number"
Value: `400`

For the value, use whatever width you want in the number of pixels. I think I like 400.

Get URL for Searches in Safari 6

There have been many articles and conversations about the question of how to get the URL of a Google search in Safari 6. Some solutions include using the Terminal to get the URL, using AppleScript,  using bookmarklets, and using Automator. I created a Safari Extension to make this process easier.

Get URL: Easily get the URL of your current tab.

With my Get URL Safari Extension, simply click the toolbar button for a popup that contains the URL of the current page. The URL is already selected, making it simple to copy.

Download the Get URL Safari Extension
(.safariextz, 46 kb)

Update: I’ve received notice from Apple that the extension will be available in the Safari Extensions Gallery. Look for it there soon!

Add Googlebot User Agent to Safari Develop Menu

Googlebot Safari

If you’re like me, you’ve wanted to have the Googlebot user agent availalbe in the Develop menu of Safari.

  1. Go to /Applications/
  2. Right-click on Safari.app and select Show Package Contents
  3. Navigate to Contents/Resources/
  4. Find `UserAgents.plist`
  5. Open `UserAgents.plist` in your favorite text editor
  6. Either
    • Replace with the contents of this file and continue to step 9: [download id=”12″]
    • … or continue on:
  7. At the end of the file, find:
    </array>
    </plist>
  8. Replace with:
    	<dict>
    		<key>separator</key>
    		<true/>
    	</dict>
    	<dict>
    		<key>name</key>
    		<string>Googlebot</string>
    		<key>version</key>
    		<string>2.1</string>
    		<key>platform</key>
    		<string>Googlebot</string>
    		<key>user-agent</key>
    		<string>Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)</string>
    	</dict>
    	<dict>
    		<key>name</key>
    		<string>Bing</string>
    		<key>version</key>
    		<string>2.0</string>
    		<key>platform</key>
    		<string>Bingbot</string>
    		<key>user-agent</key>
    		<string>Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)</string>
    	</dict>
    </array>
    </plist>
    
  9. Save the file (you’ll need to type in your user password)

Voila! Now in your Safari Develop > User Agent menu, you should see `Googlebot 2.1 – Googlebot` and `Bing 2.0 – Bingbot`.

Time Out Free: An App to Enforce Your Stretch Breaks

It’s hard to get up and stretch on a regular basis, especially when your computer allows you to keep working!

I will spend all day on my ass. That can’t be good. I have been dreaming about the perfect app that would force me to get up by blocking all access to what I was doing.

I found the app I’ve been looking for: it’s called Time Out Free.

Time Out Screenshot Time Out Free is a timer that kicks in every so often (you set the rules) and blocks your entire screen. You can set short breaks and long breaks, and you can override the breaks if you want to. Time Out Free makes it easy for me to remember to stand up, stretch my legs and move. It encourages me to stay hydrated and to fill up my empty water glasses.

It’s a developer’s best friend (and worst nagging enemy!).

It can be frustrating, but I know that it’s good for me, so I removed the option to skip breaks. The three options are:

  1. Take a break
  2. Delay the break by 1 minute
  3. Delay the break by 2 minutes

After three delays, I get annoyed and stretch. The app works!

Suggestion for improvement: move to the menu bar.

Given that it’s a free app, it’s already amazing. I believe an improvement would be to have the app in the menu bar and remove it from the dock. That way, it’s not taking up space in the app switcher. To get around this for now, I’m using Dock Dodger, which works well…except that the preferences are not easily accessible.

Create a Custom Error Page for "Error establishing a database connection"

Error establishing a database connection

Here’s how to make a custom database error page for WordPress.

If your site’s all set up and you see “Error establishing a database connection,” that’s an immediate “oh crap” situation.

Hostgator.com, the company that hosts this website, has had some issues recently, and I’ve seen that screen a little too often.

If you want to define a custom “Error establishing a database connection” screen, add a file to your /wp-content/ folder named db-error.php. That will be loaded instead of that stupid message. Check out SEODenver.com’s db-error.php.

A Good Idea for SEO

If you want to prevent search engines from indexing your site while it’s down, add <meta name="robots" content="noindex, nofollow" /> to your page’s `<head>`. You sure don’t want Google caching your error! Continue reading “Create a Custom Error Page for "Error establishing a database connection"”

Generate a Link to Activate a Plugin in WordPress

Here’s another specialized plugin development tip!

If you want to create a link to activate a plugin, you need to know the path of the plugin file. Let’s use Akismet for this example.

$path = 'akismet/akismet.php';
$link = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$path), 'activate-plugin_'.$path);

The `$link` URL will be something like http://yoursite.com/wp-admin/plugins.php?action=activate&plugin=akismet%2Fakismet.php&_wpnonce=f97dabdf9

How to Hard-Code a UA String for the Google Analytics for WordPress Plugin

If you want to define a Google Analytics “UA String” while using Yoast Google Analytics plugin for WordPress.

Add the following to your theme’s `functions.php` file:

add_filter( 'option_Yoast_Google_Analytics', 'custom_ua_string_filter');

function custom_ua_string_filter($options = array()) {
	$options['uastring'] = 'UA-########-#';
	$options['manual_uastring'] = true;
	return $options;
}

For users of WordPress Multisite, this will allow you to pre-configure new blogs with the same UA string.

Enable Shortcodes for Gravity Forms Field Descriptions

To enable shortcodes inside your Gravity Forms form description, field labels and descriptions, you need to add the following code to your theme’s `functions.php` file:


add_filter(‘gform_pre_render’, ‘walker_do_shortcode_gform_description’, 10, 2);

function do_shortcode_gform_description(&$item, $key) {
$item = do_shortcode($item);
}

function walker_do_shortcode_gform_description($form, $ajax) {

$form[‘description’] = do_shortcode($form[‘description’]);
array_walk_recursive($form[‘fields’], ‘do_shortcode_gform_description’);

return $form;
}

Merge Settings Into an Array in WordPress

Arrays Merging

I found people are coming to this site (to an unrelated article) looking for a way to merge settings into an array.

You’re looking for `wp_parse_args()`

The main function for WordPress to do this is `wp_parse_args()`. You likely want this function.

Learn more about `wp_parse_args()`

Also consider `shortcode_atts()`

This is used for parsing shortcode options. It only supports defined arguments.

Learn more about `shortcode_atts()`

Mitt Romney's Compressed Images

Mitt, don’t skimp on image optimization

I just visited Mitt Romney’s website for the first time and noticed right away that his site looked cheap because his button images had been so compressed for load time.

 

For comparison, here are some similar boxes on BarackObama.com

 

Look for yourself

I don’t think the affect of the bad quality comes across in these pictures. I encourage you to compare and contrast.

Simple Way to Get Plugin Status in WordPress

Active plugin volcano.

I have previously written on how to determine if a widget is active. This is helpful for widgets, but not for plugins.

WordPress has a couple of different functions that help you determine plugin status. They are both located in wp-includes/plugin.php

  • `validate_plugin()` spits out an error if the plugin file does not  exist or has an invalid header. This lets you know that the file is there.
  • `is_plugin_inactive()` lets you know if the plugin is not active (using the `is_plugin_active()` function)

A function to get plugin status

Using these two functions, I put together a one-size-fits-all function `get_plugin_status()`. Continue reading “Simple Way to Get Plugin Status in WordPress”

A WordPress Developer's Tips for Using Panic Coda

Panic CodaI use Panic Coda for coding. I like its Mac-style interface and it “fits” me well. There are some items that are frustrating, including a lack of auto-complete for functions you’ve already used in your code. Here are three tips to improve your coding experience. Continue reading “A WordPress Developer's Tips for Using Panic Coda”