Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Self written protector
<?php
/**
* Self written protector.
*
* To see a full working example, just take a look at the Torro Forms Timetrap Protector:
* https://github.com/awsmug/torro-forms/blob/master/src/src/modules/protectors/timetrap.php
*/
class Self_Written_Protector extends awsmug\Torro_Forms\Modules\Protectors\Protector {
/**
* Basic information of the protector.
*
* @since 1.0.0
*/
protected function bootstrap() {
$this->slug = 'selfwrittenprotector';
$this->title = __( 'Self Written Protector', 'textdomain' );
$this->description = __( 'I will try to ban spam!', 'textdomain' );
}
/**
* Do your checks after submission here
*
* @param array $data Submission POST data.
* @param Form $form Form object.
* @param Submission|null $submission Submission object, or null if a new submission.
*
* @return bool|WP_Error True if request is not spammy, false or error object otherwise.
*/
public function verify_request( $data, $form, $submission = null ) {
$check = true;
if ( $check === false ) {
WP_Error( 'check_is_false', __( 'The check has gone wrong', 'textdomain' ) );
}
return true;
}
/**
* Put the code for the frontend in this function.
*
* @param Form $form Form object.
*/
public function render_output( $form ) {
?>
<!-- Put the HTML you need for the form here //-->
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment