I used to have an extra option added to the 'Edit Media' screen (using the attachment_fields_to_edit hook, and then saving with attachment_fields_to_save). However, I've updated to 3.5 today, and the Edit Media screen is now based on the Edit Post screen, so those hooks no longer work in this context.

To overcome this, I've added a metabox using add_metabox(). The metabox is displayed, but the issue is with saving the data.

As the function wasn't working as I expeced, I thought I'd output $_POST to see what was going on. However, it appears that the function hooked to save_post isn't being run when I update the media.

Here is my code. Can anybody tell me if I am going about this the wrong way, or perhaps if there is a differnt hook that I am unaware of for this purpose? Thanks.

/** Register hooks for creating a metabox on the Edit Media screen and then saving the values */
if(current_user_can('manage_options')) :

    /** Add the option for including the image in the slideshow on the front page */
    add_action('add_meta_boxes', 'add_front_page_slideshow_option');

    /** Save the '_include_on_front' data */
    add_action('save_post', 'save_front_page_slideshow_option');


 * Saves values from the 'Include in Front Page Sideshow' meta box when the users Updates the media
function save_front_page_slideshow_option($post_id){

    echo '<pre>'; print_r($_POST); echo '</pre>';

    /** Check the security nonce to ensure we have the proper authorisation  */
    if(!wp_verify_nonce($_POST['slideshow_noncename'], 'include-on-front-nonce')) :
        return false;

    /** Ensure that the user has the correct permissions */
    if(!current_user_can('edit_post', $post_id)) :
        return false;

    /** Check if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything */
    if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) :
        return false;

    /** Update the '_include_on_front' post meta field */
    if($_POST['include_on_front']) :
        update_post_meta($post_id, '_include_on_front', $_POST['include_on_front']);
    else : 
        delete_post_meta($post_id, '_include_on_front');


2 Answers 2


attachment_fields_to_save is still called.

Just tried out this on my wordpress 3.5. installation and the following code killed wordpress when saving an image.

add_filter('attachment_fields_to_save', function() {
  • Thanks @jontro, I'm still having some issues here so will revisit shortly...
    – David Gard
    Commented Jan 3, 2013 at 16:29

I am having similar issues. I think I've narrowed down the issue to the nonce check. Seems that its not getting past that. Did you figure this out yet? I find that if I remove the nonce check it works. Not sure why that is though.

  • OK... I guess after battling this for most of last night I was too tired to realize that breaking my functions.php file into different PHP files changes the path of plugin_basename(FILE) which is what I was using for my nonce variable. Duh!
    – dave
    Commented May 23, 2013 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.