I want to open javascript error message when some one clicks on "Move to Trash" link in Publish box in wp-admin
1 Answer
Put the following in your functions.php
:
if (! empty($GLOBALS['pagenow']) && 'post.php' === $GLOBALS['pagenow'])
add_action('admin_footer', 'trash_click_error');
function trash_click_error() {
echo <<<JQUERY
<script>
jQuery(function($) {
$('#delete-action a').unbind();
$('#delete-action a').click(function(event) {
event.preventDefault();
alert('Error!');
setTimeout(
function() {
$('#save-action .spinner').hide();
$('#publish').removeClass('button-primary-disabled');
},
1
);
});
});
</script>
JQUERY;
}
-
Thanks for your help. I think we are very close to do it. I used 'wp_trash_post' instead of 'admin_footer'. It goes in this function but I am not able to get the alert box. Can you please help me to sort out it.– Xing LeeApr 22, 2013 at 11:41
-
Well, that is beacuse the hook is the wrong one. If you don't want to use
admin_footer
(whatever the reason may be), useadmin_head
with a priority of 999 or something like this. Why is that so? We are injecting some jQuery code (to the website's source code) that then is affecting the link. There's no sense in doing this after the link has already been clicked (which is when you hook action is fired).– tfrommenApr 22, 2013 at 11:57 -
Hi,I need to apply same thing on Trash link on posts listing page. Any help much appriciated– Xing LeeMay 3, 2013 at 7:34
.click()
method.