Results 1 to 10 of 10

Thread: Extending the Post Expiration plugins

  1. #1
    iamfriendly is offline Hello World
    Join Date
    Mar 2010
    Location
    Manchester, UK
    Posts
    11

    Default Extending the Post Expiration plugins

    Hey all,

    A need has arisen where I need to allow authors to set an 'expiration date' for the posts that they write on a blog of mine.

    Now, after a wee bit of research, there seems to be a couple of existing plugins which already do something along these lines:

    Atropos and Post Expirator being the plugins which popped up in a couple of different Google searches. Atropos seems to be the 'extension' of Post Expirator.

    Now, Atropos allows you to set an expiration date for the post by specifying a date in a custom meta box that the plugin creates in the write posts page. This, in itself seems like a sensible approach and I've modified the plugin so that it doesn't delete the posts, but instead it marks the post as a draft. I managed this by simply modifying the atropos_delete_expired_posts() function in atropos.php

    PHP Code:
    function atropos_delete_expired_posts () {
      global 
    $wpdb;
      
    $result $wpdb->get_results("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_atropos_expiration_date' AND meta_value < '" date("Y/m/d") . "'");
      foreach (
    $result as $a) {
        
    //wp_delete_post ($a->post_id); //Deleting is bad mmkay
       
    do_action('transition_post_status'draftpublish$a->post_id);
      }

    This is all well and good and does the functionality that I'm after. However, my authors are picky and like things to be easy - bless them. They're not all that happy with having to scroll to the bottom of the write posts screen to add an expiry date and they pointed that it would seem more sensible for the expiry date to be part of the "Publish" meta box on the RHS of this screen - i.e. just below the "Publish immediately" section.

    To be fair, that sounds like a decent suggestion, so, after all this babbling and convolution, here's my question:

    Is it possible to add something to the 'publish' meta box and, if so, which functions and hooks should I be looking toward.

    Thanks very much in advance!

  2. #2
    Jeffro's Avatar
    Jeffro is offline WPTavern Forum Admin
    Join Date
    Jan 2009
    Location
    Ohio
    Posts
    2,358

    Default

    If it's in a custom meta box, would they not be able to just drag that meta box to the top on the right hand side so it's above all the other menus. That would eliminate the scrolling issue.

    Interesting question though. On the surface, it would appear to me that the publish meta box is part of the core so I'm not sure if you can add something to it without losing those additions after a WordPress upgrade. What you may end up having to do is finding a way to over ride the publish meta box with one of your own.

  3. #3
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,993

    Default

    Here's the entire list of actions.
    Here's the entire list of filters.

    Here's the hook for adding a write page meta box: add_meta_box().
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  4. #4
    iamfriendly is offline Hello World
    Join Date
    Mar 2010
    Location
    Manchester, UK
    Posts
    11

    Default

    Jeffro and Chip, thanks for the replies.

    Chip, I'm not directly after adding another meta box, as such, I'm more interested in editing one of the existing ones, but, as Jeffro says it looks like the 'Publish' meta box is directly hard-coded into the core and as we all know, modifying core is bad, mmkay.

    I'm thinking there might be a horribly hacky way of injecting some html into the Publish metabox with some javascript nonsense, but, tbh, I'd rather avoid that as much as possible.

    Anyone know of any plugins which modify any of the existing 'core' meta boxes on the write post screen?

  5. #5
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,993

    Default

    Quote Originally Posted by iamfriendly View Post
    Jeffro and Chip, thanks for the replies.

    Chip, I'm not directly after adding another meta box, as such, I'm more interested in editing one of the existing ones, but, as Jeffro says it looks like the 'Publish' meta box is directly hard-coded into the core and as we all know, modifying core is bad, mmkay.

    I'm thinking there might be a horribly hacky way of injecting some html into the Publish metabox with some javascript nonsense, but, tbh, I'd rather avoid that as much as possible.

    Anyone know of any plugins which modify any of the existing 'core' meta boxes on the write post screen?
    Well, Andreas pulled the following out of the above-linked API reference:

    One of these?
    edit_category_form Runs after the add/edit category form is put on the screen (but before the end of the HTML form tag).
    edit_category_form_pre Runs before the edit category form is put on the screen in the admin menus.
    edit_tag_form Runs after the add/edit tag form is put on the screen (but before the end of the HTML form tag).
    edit_tag_form_pre Runs before the edit tag form is put on the screen in the admin menus.
    edit_form_advanced Runs just before the "advanced" section of the post editing form in the admin menus.
    edit_page_form Runs just before the "advanced" section of the page editing form in the admin menus.
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  6. #6
    iamfriendly is offline Hello World
    Join Date
    Mar 2010
    Location
    Manchester, UK
    Posts
    11

    Default

    Hey Chip, yep I spotted that post but again it looks like those hooks are all for adding another metabox. I'll have to have a deeper look into them, but on first glance it's looking like some serious hackage is happening this weekend ;)

    Thanks again,

    iamfriendly

  7. #7
    sleary's Avatar
    sleary is offline Hello World
    Join Date
    Dec 2009
    Location
    Texas
    Posts
    21

    Default

    There's a submitpost_box filter, but I can't find any documentation on it. I think it'll add things to the Publish box, but you'll have to play with it.

  8. #8
    mfields's Avatar
    mfields is offline Here For The Peanuts
    Join Date
    Nov 2009
    Location
    Portland, OR
    Posts
    168

    Default

    @iamfriendly - The closest I got was to move the box directly above the publish box. To do this, you will need to edit the plugin file.

    Line 312 should be changed from:
    PHP Code:
    add_action ('edit_form_advanced',         'atropos_add_box'); 
    to
    PHP Code:
    add_action ('admin_menu',         'atropos_add_box'); 
    and Line 156 should be changed from:
    PHP Code:
    add_meta_box('atropos'__('Expiration Date'), 'atropos_custom_meta_box''post''advanced''high'); 
    to
    PHP Code:
    add_meta_box('atropos'__('Expiration Date'), 'atropos_custom_meta_box''post''side''high'); 

  9. #9
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    594

    Default

    for the getting Meta Boxes on the side you use add_meta_box and set context to 'side' and try different priority values per instructions here: http://codex.wordpress.org/Function_...e/add_meta_box
    Try setting priority to 'core'.
    If you are experimental you can always inject the metabox using jQuery.
    Checked the meta-boxes.php that generates metaboxes.

    post_submitbox_misc_actions I think this is a good action to hook into. and echo HTML code.
    Last edited by andreasnrb; 03-05-2010 at 11:58 AM.

  10. #10
    iamfriendly is offline Hello World
    Join Date
    Mar 2010
    Location
    Manchester, UK
    Posts
    11

    Default

    Thanks a lot guys, some great resources and suggestions. I shall be having a play over the weekend and let you know how I get on! Again, thanks a million

Posting Permissions

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