The quest continues

Why haven’t you been posting new filters? Don’t tell me you flaked out after only 25 …

y_u_no_post_filtersHave no fear, I don’t plan to give up anytime soon. For personal reasons, I had to take a few days off, but posting will resume its usual fervor this weekend. I’m discovering more and more that you do the things you need to do before you can do the things you want to do.

Which brings me to my next point: I’ve decided to take a bit of a different tack on this project going forward.

I’m still planning to try documenting (at least) three filters a day, but I’m going to adopt a much more structured format:

  • The randomized master list is going away and I’ll instead be going file by file through core
  • Posts will be more succinct, less focused on where filters are located and their history, and more focused on their purpose and what arguments they accept
  • Whenever possible, there will still be examples with every post

Partly the reasoning for these changes is so that it takes me less time to document each filter, and partly it’s due to some exciting code documentation plans shaping up for the 3.7 cycle. Keep an eye peeled for more on that second part soon.

Next up: wp-admin/includes/ajax-actions.php

#25: the_modified_date

The the_modified_date filter allows you to modify the modified date output when used for a post inside the Loop.

It is evaluated in the the_modified_date() template tag in the wp-includes/general-template.php file. Template tags must be used inside the Loop.

the_modified_date accepts 4 arguments:

  1. string $the_modified_date The date the post was modified
  2. string $d The date format, if empty it defaults to the value of date_format option
  3. string $before What to output before the date
  4. string $after What to output after the date

Example:

The following wraps the modified date in emphasis tags on output.

View the code example on Gist.

#24: login_messages

The login_messages filter allows you to modify various messages shown on the login screen.

It is evaluated in login_header() in the wp-login.php file.

Messages include:

  • ‘Session expired. Please log in again. You will not move away from this page.’
  • ‘You are now logged out.’
  • ‘User registration is currently not allowed.’
  • ‘Check your e-mail for the confirmation link.’
  • ‘Check your e-mail for your new password.’
  • ‘Registration complete. Please check your e-email.’
  • You have successfully updated WordPress! Please log back in to experience the awesomeness.

login_messages accepts a single argument taking the form of a string containing the message for the context.

It’s important to remember that login_messages is evaluated as a string, not an array of messages like elsewhere in Core. The string delivered is determined based on the provided context in the query string. If you want to modify the message as stored in the WP_Error object, take a look at the wp_login_errors filter.

For more information on messages and their respective contexts, see the login switch case in wp-login.php

Example:

Let’s say you want to remove the hyphens in ‘e-mail’ for any of the checkemail context, because maybe you’re kind of a nut for AP Style. The following checks for the existence of ‘e-mail’ in the message string and replaces it with ’email’.

View the code example on Gist.