WordPress plugin how to run function when button is clicked

Create 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

Leave a Comment

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş