Eeek! The load-page-new.php and load-page.php actions have vanished!

So WordPress 3.0 is out, and some of the useful admin area load-* hooks that I use have vanished or changed. To refresh your memory, there are individual and specific hooks which run whenever WordPress loads an admin page. These hooks are named after the PHP file in the URL to the admin page, for example the URL to create a new post is post-new.php so the action you can hook when this page is loaded is “load-post-new.php“. All good. Very handy.

In WordPress 3.0 the URLs to create a post and edit a post are now all post-new.php and post.php, with the post type being passed in a GET parameter like so: post-new.php?post_type=page… i.e. load-page-new.php and load-page.php action hooks have both vanished! Never fear, there are two ways around this problem, read on…

The obvious way to cope with this is to hook the load-post-new.php and load-post.php actions and include some conditional code which looks to the GET parameter in the URL, something like this perhaps:

$get_post_type = @ $_GET[ 'post_type' ];
if ( ! $get_post_type ) {
$get_post_type = 'post';

Alternatively you could access a global variable called $typenow, as in this little demo plugin I’ve whipped up.

Happy coding!

9 thoughts on “Eeek! The load-page-new.php and load-page.php actions have vanished!

  1. Jonny

    Simon – great work fella, this is just what I needed! Thanks so much for putting this info up, it couldn’t have been timed better!

  2. John Blackbourn

    I was editing some plugins of mine just yesterday to cope with this. I went with the $_GET[‘post_type’] route, but the $typenow variable is a bit more elegant (just).

    Also worth noting that a similar change has happened with the Categories and Tags screens. For example, load-categories.php is now load-edit-tags.php with a ‘taxonomy’ query string.

    To round it off, the names of custom columns for tables in the admin screens are related, so for posts and taxonomies have changed too. If you’re adding a custom column on the Categories screen it’s now “manage_edit-category_columns”, on the Tags screen it’s the good-luck-guessing-the-name-correctly “manage_edit-post_tag_columns”, and on the posts screen it’s now “manage_posts_custom_column” (yay for naming consistencies).

    And there I was thinking that WordPress 3.0 wasn’t going to cause me a lot of work.

  3. Pingback: load-page.php and load-page-new.php broken in WP3.0

    1. Simon Wheatley Post author

      Agreed, that is neatly on one line… but I find ternary operators are pretty confusing, so I avoid them (particularly when explaining things). ;)

      [edit: corrected tertiary to ternary]

  4. Simon Wheatley Post author

    I’ve put a suggested patch (#14083) in to add backwards compatibility, and to propose some new dynamically constructed hooks based on the content type and taxonomy type (e.g. “load-edit-tags.php-type-post-tax-category”, “load-post.php-type-event”, etc).

    If you guys had time to review it, that would be handy!

  5. Jonny

    Booo – so close, yet so far!

    This works fine when:
    – creating a new post
    – editing a post
    – creating a new page

    HOWEVER, when you edit an existing page, both $typenow and $_GET[‘post_type’] both return ‘post’

    Looks like a bug – boo!

  6. Jonny

    Nope, my mistake – both $typenow and $_GET[‘post_type’] return nothing when editing an existing page (fine when creating a new one though)

  7. Greg WOods

    I’m new to wordpress, but need to create an admin page plugin, and have learnt a lot from your blog posts. In the example plugin linked to in this page, I get the general idea of what the code is doing, but I’m confused by how ttpla_init() is ever called. Any additional insights would be appreciated.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>