#development

Show WordPress Query Load Times

Here’s a good way to find out how many and what queries are being executed and how long it takes. Your code may be inefficient and here’s a good way to tell.

When troubleshooting

https://gist.github.com/davidsword/24fa2e27b4c62900bc8c66e3c3cec490

I’ve used admin_footer hook so this will show in the admin, you can use wp_footer or other late hooks to show on main site. Note $wpdb->queries will reveal table names to the source code so this shouldn’t be on public sites or proper user conditional tags should be added.

Change the Color of First Few Words PHP

If you have a header or similar and would like the first few words highlighted, here’s a nice little script. In below the class red is defined in my css, and $color would be the number of words I want coloured.

https://gist.github.com/davidsword/9ed30f0cc4daddf9dd99fe885971c094

Usage would be similar to:

https://gist.github.com/davidsword/aa655e47c48c4be14c1432566eeb4842

Domains Added on Plesk Not Receiving Emails

Servers running plesk with domains using an external DNS Zone file and external MX record may experience an email issue as qmail thinks it is sending emails to itself because of the plesk records and will try to bypasses the external DNS Zone.

To fix this, we have to tell qmail that these domains email solutions are not handled on the server.

To do this, remove the line with the problematic domain(s) from both files below:

https://gist.github.com/davidsword/23ab8449299404673321dfd7fe463e1e

date_default_timezone_set() Not Working

This is a silly amateur hour error that I’m positive lots of people miss. date_default_timezone_set() needs to be called within functions, it isn’t a global function.

The script below will demonstrate the how date_default_timezone_set() affects date() (and time()).

https://gist.github.com/davidsword/0c844dc7d92af3ea48bfe03ef815911d

Will output:

// Eastern
// Server’s Time
// Central
// Eastern

Starcraft 2 Rank Badge on Desktop – Geektool

UPDATE: This hasn’t been update to any new standards.

StarCraft is awesome. Growing up I used up so many smoggy summers playing the original release, and after SCII came out I got reattached to it. Further more I actually have a machine with top line graphics and memory, so I can max out the visuals and really enjoy the game for all it’s glory.

(more…)

Plugin: Network Plugin Overview

I wrote this little plugin for WordPress Networks allowing super admins to easily see which plugins are being used on which sites in a wordpress network.

Download

> » WordPress.org Plugins: Network Plugin Overview

Description

Quickly view all your plugins and see which sites are using them, which are network-wide, and which plugins are not active on any sites at all.

Installation

1. Upload the /network-plugin-overview/ folder into the /wp-content/plugins/ directory, or add via the “Add New” option in /wp-admin/plugins

  1. Activate the plugin through the ‘Plugins’ menu in WordPress
  2. Navigate to “Plugin Overview” page in the admin sidebar

Frequently Asked Questions

Why would I need this?

> I personally needed it to delete dated/forgotten plugins that posed a security risk by keeping around. Having a large number of different sites in a network, it’s sometimes hard to determine which plugins are being used where. This plugin clearly highlights which plugins are not being used at all….if you are not using a specific plugin, delete it from the system.

Can I use it on a single installation instead of a network?

> No, just go to “Plugins” in the admin.

Screenshot

Wordpress Network Plugin Overview

Changelog

Version 1.0

> Nov 25, 2012
> Public Launch

Suggestions / Notes

Please post any comments or questions below.

WordPress Simple Cronjobs

WordPress makes it super simple to run cronjobs.. To add one, just place the following code in your functions.php file and change the function/action prefix’s to your relevant plugin name/functions.

https://gist.github.com/davidsword/a92239204229686a5b31cf13100054bc

A little break down for those unfamiliar: the first action runs myplugin_schedule_cron() on each load. If your cronjob (myplugin_cronjob) is not registered, it’s scheduled into WordPress’s cron and becomes a hook. Once it’s registered/schedualed with WordPress, the second action myplugin_cronjob is usable and runs your cronjob function (myplugin_cron_function).

If you want your cronjob to occur less frequent than ‘daily’, you need to add a additional timespan. Since what I’m writting this for has dynamic timespans, I’ve added several intervals for weekly, monthly, quaterly, biyearly, and yearly cronjobs:

https://gist.github.com/davidsword/ef6dda9734eeca6587dd40b906f1b9f4

If you’re uncertain if your cron function is working and want to test it, you can uncomment the third action and refresh the page (to run what WordPress cronjob will run on it’s intervals). If you’re uncertain if your cronjob is actually scheduled you can install Cron View, a plugin that displays the available schedules and the scheduled tasks.