• Resolved matoma16

    (@matoma16)


    Hi,

    I modified the wordpress admin with a plugin I wrote, and my last problem is that there’s no action while the post is being updated or published in the admin. I looked around for a function or something that’ld let me do something while the post is being updated but so far I didn’t have any luck. Anyone know how to do it ? I’ld like to add HTML (a div) if I can but really anything would be nice !

    Thanks for your help 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    I think the hook you are looking for is the filter ‘wp_insert_post_data’. Once you decipher the arrays you are passed, just update the correct value and return the array to the filter.

    Note it is a filter, not an action.

    The action save_post is what you are looking for if you are trying to save data from the post form.

    As far as editing the post form you should look at add_meta_box function.

    Thread Starter matoma16

    (@matoma16)

    What I’m trying to do is show to the user that the post is being published, so, when I hit publish, I want something to tell my users “that post is being uploaded, please wait”. I’ll look again at save_post, or publish_post, but both didn’t work when i tryed. If I find the answer, i’ll post.

    Thanks for your help !

    Unfortunately neither of those hooks will work for what you are after. I don’t believe that there is a hook/filter or set of these that will do what you are after.

    However I have to say that I would not be that worried about it if I was you. The difference in time between when the post starts being updated and when the update is completed is going to be milliseconds (unless your server is REALLY underpowered, in which case you wouldn’t see the actual posts in any resonable amount of time anyway). The chances of someone clicking on the post at the time between starting the update and completing the update is very very very very small.

    Can I ask what your concerns are about this? If it’s just that people might see a post that’s not quite ready, then I wouldn’t be concerned about it.

    @michael.mariart makes a fair point, but if you have to have it…

    place this in your plugin…

    add_action('admin_enqueue_scripts','MY_MESSAGE_JS_FUNCTION');
    function MY_MESSAGE_JS_FUNCTION(){
        wp_register_script('MY_MESSAGE_JS',plugins_url('message.js',__FILE__),array('jquery'));
        wp_enqueue_script('MY_MESSAGE_JS');
    }

    NOTE: you will need to create message.js and put this in it…

    jQuery(document).ready(function($){
        $('#publish').live('click',function(){
            //message to display
            var msg = '<div class="MY_MESSAGE updated"><p>Post is being saved!</p></div>';
            //if there is an 'post updated' message remove it
            if($('#message').length > 0){ $('#message').remove(); }
            //if our message  isn't on screen already, inject it after the page title 'Edit Page/Post'
            if($('.MY_MESSAGE').length === 0){ $('.wrap h2').after(msg); }
        });
    });

    Enjoy! remember replace all uppercase stuff with your own lowercase names etc.

    Thread Starter matoma16

    (@matoma16)

    Thanks ! I actually figured it out a few hours ago while I was posting my question on another forum… and it was like a big duh…. I was trying too had to find a wp way to do it I guess…

    I need it because I have a metabox, and it uploads a picture, but not with wordpress’s media uploader. So, since depending on the size it may take a while, I need to tell the users to wait and not click the publish button over and over again (did a user test on sunday and my user did that). If I didn’t have my photo uploading I wouldn’t need it but it just takes too much time sometimes.

    Thanks for your help !

    Np! Another trick I use when validating metabox inputs with js, is I disable the publish button till all conditions are met…
    $('#publish').attr('disabled','disabled');
    And
    $('#publish').removeAttr('disabled');
    when all is good!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Action while post is being published’ is closed to new replies.