Create your own bulk actions

2016-10-21_13-46-04
Including version 4.6 it was quite difficult to add custom bulk actions to the WordPress admin pages. In version 4.7 a hook is added that simplifies the task a lot:

add_action('bulk_actions-{screen_id}', 'my_bulk_action');

Defining the hook

As an example we'll use the post page, the variables are named accordingly.

add_filter( 'bulk_actions-edit-post', 'register_my_bulk_actions' );

Continue reading …

Inform user about automatic comment closing time

To prevent spammers from flooding old articles with useless comments you can set WordPress to close comments after a certain number of days:
close-comments
It might be surprising for some users if the comments are closed automatically so it might be a good idea to inform them about the remaining time.

add_action( 'comment_form_top', 'topic_closes_in' );

function topic_closes_in() {
    global $post;
    if ($post->comment_status == 'open') {
        $close_comments_days_old = get_option( 'close_comments_days_old' );
        $expires = strtotime( "{$post->post_date_gmt} GMT" ) +  $close_comments_days_old * DAY_IN_SECONDS;
        printf( __( '(This topic will automatically close in %s. )', 'domain' ),  human_time_diff( $expires ));
    }
}

While the code should be almost self explanatory there is an interesting function not every WordPress developer might know: human_time_diff(). This function is hidden in the .../wp-includes/formatting.php file. It is originally planned to be used in themes to provide a more "human" touch to the date/time a post was written. Since the function does not care if the date is in the past or in the future we can use it for our needs.

close comment example

Escaping the maintenance mode trap

WordPress makes upgrading very easy . You simply click "Update now", wait for a minute or two and your system is up to date. If, well if everything works fine.
The most common problem during an upgrade is the Internet connection to drop unexpectedly or the user to shut down the browser unintentionally. In both situations the upgrade will stop instantly.
If you try to log in to your backend again you will receive the message

"Briefly unavailable for scheduled maintenance. Check back in a minute."

This message is useful to keep users away from your blog during the upgrade but right now it's keeping you from restarting the upgrade. To solve this problem we have to take a look at how WordPress determines that it's in maintenance mode.

WordPress is looking for a possible maintenance mode very early to prevent the system dying from any fatal error. So it using a very simple method by writing a file called .maintenance to the WordPress root directory. If the blog or backend is accessed it will check for the file and stop if it's present.

Knowing this the solution to our problem is quite simple: access your WordPress system via FTP and delete the file .maintenance.

If you're not able to log in to your server via FTP for some reason there is a second method for escaping from maintenance mode: simply wait 10 minutes!
The file .maintenance contains a timestamp of the time the file was created. If this time is less than 10 minutes ago WordPress will go into maintenance mode otherwise it will continue to work as usual and enable you to restart the upgrade unless something worse keeps it from starting.

New hooks in WordPress 3.8

WordPress 3.8 introduced one new action and five new filters:

  • automatic_updates_complete
    Action triggered after all automatic updates have run.
    (wp-admin/includes/class-wp-upgrader.php)

  • automatic_updates_debug_email
    Filter the debug email that can be sent following an automatic background core update.
    (wp-admin/includes/class-wp-upgrader.php)
  • comment_notification_notify_author
    Filter whether to notify comment authors of their comments on their own posts.
    (wp-includes/pluggable.php)
  • dashboard_glance_items
    Include additional elements in the 'At a Glance' dashboard widget. This widget was previously 'Right Now'.
    (wp-admin/includes/dashboard.php)
  • user_{$name}_label
    Filter a user contactmethod label.
    (wp-admin/user-edit.php)
  • wp_prepare_themes_for_js
    Filter the themes prepared for JavaScript, for themes.php. Could be useful for changing the order, which is by name by default.
    (wp-admin/includes/theme.php)
  • A list of all new hooks can you also find in the hot list of WP Seek.

Lifespan of a WordPress version

The new version 3.6 has been released much later than anticipated; the release has been estimated for the end of April and has finally been released in early August. Therefore v3.5.x stayed the freshest available version for 234 days. How does this compare to the previous versions?

wp-versions-3

On average a WordPress version was replaced by a new one after 198 days. Outstanding is the version 2.0 which stayed the newest version for over one year (Dec 2005 - Jan 2007). Starting with version 2.1 WordPress development took a faster pace and the release of new versions took about four to six months. (Source: Wikipedia)