Skip to content

Instantly share code, notes, and snippets.

@mahype
Last active August 27, 2019 13:30
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/e4cc734c02fa1bd430b769302e463b37 to your computer and use it in GitHub Desktop.
Save mahype/e4cc734c02fa1bd430b769302e463b37 to your computer and use it in GitHub Desktop.
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