Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * USAGE: include this file,
- * in the form template, add an hidden input with name "action" and value "X"
- * call register_form_action('X', *callback);
- */
- if ( ! function_exists( 'add_action' ) ) {
- die( 'Nothing to see here, move along' );
- }
- $form_actions_list = [];
- $form_action_prefix = 'action_';
- if ( ! function_exists( 'register_form_action' ) ) {
- function register_form_action( $name, $callback ) {
- global $form_actions_list, $form_action_prefix;
- $form_actions_list[] = $name;
- add_action( $form_action_prefix . $name, $callback );
- }
- }
- add_action( 'init', function () {
- if ( isset( $_POST['action'] ) ) {
- global $form_actions_list, $form_action_prefix;
- $actionName = $form_action_prefix . $_POST['action'];
- if ( in_array( $_POST['action'], $form_actions_list ) && has_action( $actionName ) ) {
- do_action( $actionName );
- }
- }
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement