Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');

endif;

/**
 * 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>';
    die();

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

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

    /** 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;
    endif;

    /** 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');
    endif;

}
share|improve this question
add comment

2 Answers

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() {
    die('attachment_fields_to_save');
});
share|improve this answer
    
Thanks @jontro, I'm still having some issues here so will revisit shortly... –  David Gard Jan 3 '13 at 16:29
add comment

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.

share|improve this answer
    
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 May 23 '13 at 13:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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