Results 1 to 6 of 6

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

  1. #1
    Jonny is offline Hello World
    Join Date
    Apr 2010
    Posts
    11

    Icon11 load-page.php and load-page-new.php broken in WP3.0

    Prior to WP3.0 I was using this code in a plugin to execute my function when I was creating or editing a page:

    PHP Code:
    add_action('load-page.php', array($instance'function'));
    add_action('load-page-new.php', array($instance'function')); 
    However, I see that page.php and page-new.php are no longer in the core and it's all piped through post.php and post-new.php to handle custom post types, which is understandable.

    The URL in WP3.0 for creating a new page is {adminurl}/post-new.php?post_type=page

    Does anyone know how I can use the 'load-' functionality for pages in WP3.0 - I have had a really good Google around and have even tried some trial and error hacking up of my plugin (like just putting 'load-post-new.php?post_type=page' in - which didn't work of-course!), but sadly no luck so far

    I was wondering if someone could point me in the right direction on this little problem, it seems so simple, but I can't find any documentation on it at-all cheers!

  2. #2
    Jonny is offline Hello World
    Join Date
    Apr 2010
    Posts
    11

    Default

    I was thinking last night if there is a work-around on this - rather than using 'load-' (which I always thought was the neatest way to execute functions on given admin pages), maybe detect post type - seems like a long way round solution, but may work?

    Another thought was if I can grab the argument direct from the URL maybe?

    I'd really prefer to use 'load-', it's just that I can't work out how to supply it the '?post_type=page' argument, despite various attempts at different combinations and formatting!

    Also, my ideas of workarounds may not call early enough to trigger my functions - I'll give it a go over the weekend.

  3. #3
    Utkarsh is offline Hello World
    Join Date
    Nov 2009
    Posts
    73

    Default

    Quote Originally Posted by Jonny View Post
    Another thought was if I can grab the argument direct from the URL maybe?
    For this, you can use if ( $_GET['post_type'] == 'page' ) { .. }

  4. #4
    Jonny is offline Hello World
    Join Date
    Apr 2010
    Posts
    11

    Default

    I've not had a chance to properly look into this yet due to other more pressing projects, but just following on from this I have just noticed that Simon Wheatley has just posted a very timely blog post about this - may be of use if someone else has a similar issue!
    Last edited by Jonny; 06-25-2010 at 04:48 AM. Reason: typo!

  5. #5
    Jonny is offline Hello World
    Join Date
    Apr 2010
    Posts
    11

    Default

    Ah - working on it... nearly there!
    Last edited by Jonny; 06-25-2010 at 12:18 PM.

  6. #6
    Utkarsh is offline Hello World
    Join Date
    Nov 2009
    Posts
    73

    Default

    Quote Originally Posted by Jonny View Post
    Just for the record, $typenow and $_GET['post_type'] 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' - a possible bug?

    This is in WordPress 3.0 - the latest current release.
    Not a bug. The post_type isn't set while editing a page. You could use $_GET['post'] and fetch the post type of it to check.

    like

    PHP Code:
    if ( isset($_GET['post']) )
        
    $post_type get_post_type($_GET['post']); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •