admin管理员组文章数量:1023738
I am writing a WP plugin. I have created a button for the user to click in thw WP dashboard. I need to run a function when a user clicks the button, shown with a red arrow. The code snippet for the button is:<p><button class="button button-primary">Update Media Titles and ALT Text</button></p>
. I have already created the function in my class like so:
public function kh_update_media_seo() {
//update media files title and alt tags here
}
I can handle the code that goes in the function alone, I only need help making the button in the WP dashboard fire off this specific function when clicked.
Pardon me if this sounds dump or straight forward. It's my first time doing this.
My plugin is a one file plugin if that helps.
I am writing a WP plugin. I have created a button for the user to click in thw WP dashboard. I need to run a function when a user clicks the button, shown with a red arrow. The code snippet for the button is:<p><button class="button button-primary">Update Media Titles and ALT Text</button></p>
. I have already created the function in my class like so:
public function kh_update_media_seo() {
//update media files title and alt tags here
}
I can handle the code that goes in the function alone, I only need help making the button in the WP dashboard fire off this specific function when clicked.
Pardon me if this sounds dump or straight forward. It's my first time doing this.
My plugin is a one file plugin if that helps.
Share Improve this question asked Jul 24, 2018 at 19:55 Kha KaliKha Kali 411 gold badge1 silver badge2 bronze badges1 Answer
Reset to default 5Create form or link with action="my_media_update"
<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
<input type="hidden" name="action" value="my_media_update">
<input type="submit" value="Update Media Titles and ALT Text">
</form>
Add this function and hook in your plugin file:
public function kh_update_media_seo() {
//update media files title and alt tags here
//
// at the end redirect to target page
}
add_action( 'admin_post_my_media_update', 'kh_update_media_seo' );
When form will be sent and field "action" will have value "my_media_update", then your function will be executed. Wordpress Codex
I am writing a WP plugin. I have created a button for the user to click in thw WP dashboard. I need to run a function when a user clicks the button, shown with a red arrow. The code snippet for the button is:<p><button class="button button-primary">Update Media Titles and ALT Text</button></p>
. I have already created the function in my class like so:
public function kh_update_media_seo() {
//update media files title and alt tags here
}
I can handle the code that goes in the function alone, I only need help making the button in the WP dashboard fire off this specific function when clicked.
Pardon me if this sounds dump or straight forward. It's my first time doing this.
My plugin is a one file plugin if that helps.
I am writing a WP plugin. I have created a button for the user to click in thw WP dashboard. I need to run a function when a user clicks the button, shown with a red arrow. The code snippet for the button is:<p><button class="button button-primary">Update Media Titles and ALT Text</button></p>
. I have already created the function in my class like so:
public function kh_update_media_seo() {
//update media files title and alt tags here
}
I can handle the code that goes in the function alone, I only need help making the button in the WP dashboard fire off this specific function when clicked.
Pardon me if this sounds dump or straight forward. It's my first time doing this.
My plugin is a one file plugin if that helps.
Share Improve this question asked Jul 24, 2018 at 19:55 Kha KaliKha Kali 411 gold badge1 silver badge2 bronze badges1 Answer
Reset to default 5Create form or link with action="my_media_update"
<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
<input type="hidden" name="action" value="my_media_update">
<input type="submit" value="Update Media Titles and ALT Text">
</form>
Add this function and hook in your plugin file:
public function kh_update_media_seo() {
//update media files title and alt tags here
//
// at the end redirect to target page
}
add_action( 'admin_post_my_media_update', 'kh_update_media_seo' );
When form will be sent and field "action" will have value "my_media_update", then your function will be executed. Wordpress Codex
本文标签: WordPress plugin how to run function when button is clicked
版权声明:本文标题:WordPress plugin how to run function when button is clicked 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745545035a2155355.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论