Last active
February 13, 2019 15:11
-
-
Save mahype/f2abc06ecefbcf8daa31dfca32e77365 to your computer and use it in GitHub Desktop.
Torro Forms example Action (without options in backend)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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