2

I want to open javascript message "Are you sure you want to move the post to trash?"when we clicks on "Move to Trash" link in Publish box. and when we click to OK the post go to trash or cancel to go back to the post.

I found this code on previous question. It's open the javascript message but when I click OK it's just close the popup and don't move the post to trash. What can I add to fix it?

CODE :

if (! empty($GLOBALS['pagenow']) && 'post.php' === $GLOBALS['pagenow'])
    add_action('admin_footer', 'trash_click_message');
function trash_click_message() {
    echo <<<JQUERY
<script>
    jQuery(function($) {
        $('#delete-action a').unbind();
        $('#delete-action a').click(function(event) {
            event.preventDefault();
            alert('Are you sure you want to move the post to trash?');
            setTimeout(
                function() {
                    $('#save-action .spinner').hide();
                    $('#publish').removeClass('button-primary-disabled');
                },
                1
            );
        });
    });
</script>
JQUERY;
}

Picture of my actuel result

enter image description here

UPDATE :

Thanks bergire! It's all most done. I just have one issues. I use Wordpress in english but the serveur is on France. So the confirmation popup is in french like you see in the picture.enter image description here

Is it a way to change labels to (indique) and (annuler) words?

4

You can try to admin enqueue this script, with jquery dependency:

jQuery( function($) {       
    $('.edit-php a.submitdelete, .post-php a.submitdelete').click( function( event ) {
        if( ! confirm( 'Are you sure you want to move the post to trash?' ) ) {
            event.preventDefault();
        }           
    });
});

where we restrict the conformation on the a.submitdelete clicks to the .edit-php and .post-php body classes.

Hope you can adjust it to your needs, e.g. regarding i18n.

  • thanks Birgire. can you check the update of the post please? – sampaii Jul 3 '17 at 13:56
  • You're welcome. Maybe this can help? – birgire Jul 3 '17 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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