This is a simple way to get a subset of associative array elements using an array of keys; basically you extract out the elements you want from a bigger array by listing the keys you need. Continue reading “Find subset of associative array in PHP”
I wrote this plugin for Sublime Text to help on a project where I am localizing a lot of text.
I found I was copy and pasting the same i18n methods over and over so I decided that there must be a relatively easy way to automate this using a plugin.
Now I select some text, press my key shortcut and the text gets replaced with the appropriate i18n method.
Continue reading “WordPress Localization Plugin for Sublime Text”
This is a fairly common case I think. You have a table that has a datetime field that gets updated when a row is updated – you need to determine if a row has been updated recently.
Continue reading “Determine if a row has recently been updated using MySQL”
This simple method allows you to start at a date and iterate by either days or months until you reach the end date using my favourite PHP function, strtotime().
Continue reading “Loop through dates with strtotime() function”
This may be a pretty rare problem but I’ll post it regardless.
You turn on WordPress debugging only to find the log full of deprecated notices that make the log difficult to parse. Bummer.
You could spend time going through each deprecated notice and updating the offending piece of code. Or you could ask WordPress to ignore these deprecated notices (at least in the short term) by doing the following;
Continue reading “WordPress Debug Log without Deprecated Notices”
Here is a simple way to get the last line of a file without reading the entire file into memory.
Continue reading “Get last line of file in PHP”
If you are developing a plugin on WordPress, you will need to debug your code as you go.
To enable debugging, go to your wp-config.php file.
Find the line…
Replace the line above with the following…
// Turns WordPress debugging on define('WP_DEBUG', true); // Tells WordPress to log everything to the /wp-content/debug.log file define('WP_DEBUG_LOG', true); // Doesn't force the PHP 'display_errors' variable to be on define('WP_DEBUG_DISPLAY', false); // Hides errors from being displayed on-screen @ini_set('display_errors', 0);
Now you all warnings and errors will show up in the /wp-content/debug.log file, including WordPress warnings of deprecated functions.
You can write directly to this log from your plugin using the
//output some debug string error_log( 'this works yo' ); //output some array/object error_log( print_r( $some_obj_or_array, 1 ) );
Kudos to this post. It has some good plugin development tips, including how to enable debugging on WordPress.