Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1405871
Asking to recommend a product (plugin, theme, book, hosting provider), tool, library, or off-site resource is out of scope for this site, as it attracts opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 5 years ago.
Improve this questionIs it possible to add popup when i will delete post in Wordpess for better safe? Any plugin or code ?
Closed. This question is off-topic. It is not currently accepting answers.Asking to recommend a product (plugin, theme, book, hosting provider), tool, library, or off-site resource is out of scope for this site, as it attracts opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 5 years ago.
Improve this questionIs it possible to add popup when i will delete post in Wordpess for better safe? Any plugin or code ?
Share Improve this question asked Dec 7, 2019 at 16:21 golanskygolansky 113 bronze badges 1- 1 Welcome to WordPress Development. While I hope you find the answer(s) you are looking for, the community tends to frown on questions that just ask for code. Our site is different from most - if you have not done so yet, consider checking out the tour and help center to find out how things work. Consider explaining what you have done so far and where you have run dry or gotten stuck. – Matthew Brown aka Lord Matt Commented Dec 8, 2019 at 12:07
1 Answer
Reset to default 2Yes, it's possible.
You have to create a JavaScript File and enqueue this file for admin use.
This hook is to add files for the backend:
add_action( 'admin_enqueue_scripts', 'your_function_name' );
This hook is to add files for the frontend:
add_action( 'wp_enqueue_scripts', 'your_function_name' );
So we need to use the admin_enqueue_scripts hook and create our function:
function your_function_name() {
wp_enqueue_script( 'script', get_template_directory_uri() . '/path/to/admin.js', array( 'jquery' ), 1.1, true );
}
Next create your admin.js file in your template directory. In my case it's dist/css/admin.js (in the example above path/to/admin.js)
jQuery(function ($) {
console.log('load admin.js');
})
You will see the console log as logged in user in your wordpress backend in the developer tools.
Add the following content in the admin.js file:
jQuery(function ($) {
$('.submitdelete').each(function(e) {
$(this).on('click', function(e) {
if( ! confirm("You really want to delete the post?") ) {
e.preventDefault();
return;
}
})
})
})
I looked for the class of the "Trash" link. In my case the trash link has the class="submitdelete".
I create click event which will triggered if the user submit the confirmation form.
本文标签: phpAsking popup for delete post in Wordpress
版权声明:本文标题:php - Asking popup for delete post in Wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744928488a2632750.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论