Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update config-validator.php #892

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions includes/config-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ public function validate() {
return $this->is_valid();
}


/**
* Saves detected errors as a post meta data.
*/
public function save() {
if ( $this->contact_form->initial() ) {
return;
Expand All @@ -273,6 +277,10 @@ public function save() {
}
}


/**
* Restore errors from the database.
*/
public function restore() {
$config_errors = get_post_meta(
$this->contact_form->id(), '_config_errors', true
Expand All @@ -298,6 +306,11 @@ public function restore() {
}
}


/**
* Callback function for WPCF7_MailTaggedText. Replaces mail-tags with
* the most conservative inputs.
*/
public function replace_mail_tags_with_minimum_input( $matches ) {
// allow [[foo]] syntax for escaping a tag
if ( $matches[1] == '[' && $matches[4] == ']' ) {
Expand Down Expand Up @@ -385,6 +398,10 @@ public function replace_mail_tags_with_minimum_input( $matches ) {
return $tag;
}


/**
* Runs error detection for the form section.
*/
public function validate_form() {
$section = 'form.body';
$form = $this->contact_form->prop( 'form' );
Expand All @@ -395,6 +412,12 @@ public function validate_form() {
$this->detect_colons_in_names( $section, $form );
}


/**
* Detects errors of multiple form controls in a single label.
*
* @link https://contactform7.com/configuration-errors/multiple-controls-in-label/
*/
public function detect_multiple_controls_in_label( $section, $content ) {
$pattern = '%<label(?:[ \t\n]+.*?)?>(.+?)</label>%s';

Expand Down Expand Up @@ -440,6 +463,12 @@ public function detect_multiple_controls_in_label( $section, $content ) {
return false;
}


/**
* Detects errors of unavailable form-tag names.
*
* @link https://contactform7.com/configuration-errors/unavailable-names/
*/
public function detect_unavailable_names( $section, $content ) {
$public_query_vars = array( 'm', 'p', 'posts', 'w', 'cat',
'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence',
Expand Down Expand Up @@ -481,6 +510,12 @@ public function detect_unavailable_names( $section, $content ) {
return false;
}


/**
* Detects errors of unavailable HTML elements.
*
* @link https://contactform7.com/configuration-errors/unavailable-html-elements/
*/
public function detect_unavailable_html_elements( $section, $content ) {
$pattern = '%(?:<form[\s\t>]|</form>)%i';

Expand All @@ -497,6 +532,12 @@ public function detect_unavailable_html_elements( $section, $content ) {
return false;
}


/**
* Detects errors of dots in form-tag names.
*
* @link https://contactform7.com/configuration-errors/dots-in-names/
*/
public function detect_dots_in_names( $section, $content ) {
$form_tags_manager = WPCF7_FormTagsManager::get_instance();

Expand All @@ -520,6 +561,11 @@ public function detect_dots_in_names( $section, $content ) {
}


/**
* Detects errors of colons in form-tag names.
*
* @link https://contactform7.com/configuration-errors/colons-in-names/
*/
public function detect_colons_in_names( $section, $content ) {
$form_tags_manager = WPCF7_FormTagsManager::get_instance();

Expand All @@ -543,6 +589,9 @@ public function detect_colons_in_names( $section, $content ) {
}


/**
* Runs error detection for the mail sections.
*/
public function validate_mail( $template = 'mail' ) {
$components = (array) $this->contact_form->prop( $template );

Expand Down