Skip to content

Instantly share code, notes, and snippets.

@mahype
Last active February 13, 2019 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahype/f2abc06ecefbcf8daa31dfca32e77365 to your computer and use it in GitHub Desktop.
Save mahype/f2abc06ecefbcf8daa31dfca32e77365 to your computer and use it in GitHub Desktop.
Torro Forms example Action (without options in backend)
<?php
/**
* This class shows how to create an action which is processed directly after sending a form.
**/
class Send_To_API extends awsmug\Torro_Forms\Modules\Actions\Action {
protected function bootstrap() {
$this->slug = 'send-to-api';
$this->title = 'Send to API';
}
/**
* Handles the action for a specific form submission.
*
* @param Submission $submission Submission to handle by the action.
* @param Form $form Form the submission applies to.
* @return bool|WP_Error True on success, error object on failure.
*/
public function handle( $submission, $form ) {
// My API actions here.
}
/**
* Checks whether the action is enabled for a specific form.
*
* @param Form $form Form object to check.
* @return bool True if the action is enabled, false otherwise.
*/
public function enabled( $form ) {
return true; // We enable this example in general
}
}
/**
* We need to register our Action
**/
add_action( 'init', function() {
torro()->modules()->actions()->register( 'send-to-api', 'Send_To_API' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment