rebase on oct-10-2023
This commit is contained in:
@@ -62,6 +62,7 @@ function wpcf7_enqueue_block_editor_assets() {
|
||||
static function ( $contact_form ) {
|
||||
return array(
|
||||
'id' => $contact_form->id(),
|
||||
'hash' => $contact_form->hash(),
|
||||
'slug' => $contact_form->name(),
|
||||
'title' => $contact_form->title(),
|
||||
'locale' => $contact_form->locale(),
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"hash": {
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,989 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Configuration validator.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/
|
||||
*/
|
||||
class WPCF7_ConfigValidator {
|
||||
|
||||
/**
|
||||
* The plugin version in which important updates happened last time.
|
||||
*/
|
||||
const last_important_update = '5.6.1';
|
||||
|
||||
const error = 100;
|
||||
const error_maybe_empty = 101;
|
||||
const error_invalid_mailbox_syntax = 102;
|
||||
const error_email_not_in_site_domain = 103;
|
||||
const error_html_in_message = 104;
|
||||
const error_multiple_controls_in_label = 105;
|
||||
const error_file_not_found = 106;
|
||||
const error_unavailable_names = 107;
|
||||
const error_invalid_mail_header = 108;
|
||||
const error_deprecated_settings = 109;
|
||||
const error_file_not_in_content_dir = 110;
|
||||
const error_unavailable_html_elements = 111;
|
||||
const error_attachments_overweight = 112;
|
||||
const error_dots_in_names = 113;
|
||||
const error_colons_in_names = 114;
|
||||
const error_upload_filesize_overlimit = 115;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a URL linking to the documentation page for the error type.
|
||||
*/
|
||||
public static function get_doc_link( $error_code = '' ) {
|
||||
$url = __( 'https://contactform7.com/configuration-errors/',
|
||||
'contact-form-7'
|
||||
);
|
||||
|
||||
if ( '' !== $error_code ) {
|
||||
$error_code = strtr( $error_code, '_', '-' );
|
||||
|
||||
$url = sprintf( '%s/%s', untrailingslashit( $url ), $error_code );
|
||||
}
|
||||
|
||||
return esc_url( $url );
|
||||
}
|
||||
|
||||
|
||||
private $contact_form;
|
||||
private $errors = array();
|
||||
|
||||
public function __construct( WPCF7_ContactForm $contact_form ) {
|
||||
$this->contact_form = $contact_form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the contact form object that is tied to this validator.
|
||||
*/
|
||||
public function contact_form() {
|
||||
return $this->contact_form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if no error has been detected.
|
||||
*/
|
||||
public function is_valid() {
|
||||
return ! $this->count_errors();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Counts detected errors.
|
||||
*/
|
||||
public function count_errors( $args = '' ) {
|
||||
$args = wp_parse_args( $args, array(
|
||||
'section' => '',
|
||||
'code' => '',
|
||||
) );
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ( $this->errors as $key => $errors ) {
|
||||
if ( preg_match( '/^mail_[0-9]+\.(.*)$/', $key, $matches ) ) {
|
||||
$key = sprintf( 'mail.%s', $matches[1] );
|
||||
}
|
||||
|
||||
if ( $args['section']
|
||||
and $key != $args['section']
|
||||
and preg_replace( '/\..*$/', '', $key, 1 ) != $args['section'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $errors as $error ) {
|
||||
if ( empty( $error ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $args['code'] and $error['code'] != $args['code'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Collects messages for detected errors.
|
||||
*/
|
||||
public function collect_error_messages() {
|
||||
$error_messages = array();
|
||||
|
||||
foreach ( $this->errors as $section => $errors ) {
|
||||
$error_messages[$section] = array();
|
||||
|
||||
foreach ( $errors as $error ) {
|
||||
if ( empty( $error['args']['message'] ) ) {
|
||||
$message = $this->get_default_message( $error['code'] );
|
||||
} elseif ( empty( $error['args']['params'] ) ) {
|
||||
$message = $error['args']['message'];
|
||||
} else {
|
||||
$message = $this->build_message(
|
||||
$error['args']['message'],
|
||||
$error['args']['params'] );
|
||||
}
|
||||
|
||||
$link = '';
|
||||
|
||||
if ( ! empty( $error['args']['link'] ) ) {
|
||||
$link = $error['args']['link'];
|
||||
}
|
||||
|
||||
$error_messages[$section][] = array(
|
||||
'message' => $message,
|
||||
'link' => esc_url( $link ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $error_messages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds an error message by replacing placeholders.
|
||||
*/
|
||||
public function build_message( $message, $params = '' ) {
|
||||
$params = wp_parse_args( $params, array() );
|
||||
|
||||
foreach ( $params as $key => $val ) {
|
||||
if ( ! preg_match( '/^[0-9A-Za-z_]+$/', $key ) ) { // invalid key
|
||||
continue;
|
||||
}
|
||||
|
||||
$placeholder = '%' . $key . '%';
|
||||
|
||||
if ( false !== stripos( $message, $placeholder ) ) {
|
||||
$message = str_ireplace( $placeholder, $val, $message );
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a default message that is used when the message for the error
|
||||
* is not specified.
|
||||
*/
|
||||
public function get_default_message( $code ) {
|
||||
switch ( $code ) {
|
||||
case self::error_maybe_empty:
|
||||
return __( "There is a possible empty field.", 'contact-form-7' );
|
||||
case self::error_invalid_mailbox_syntax:
|
||||
return __( "Invalid mailbox syntax is used.", 'contact-form-7' );
|
||||
case self::error_email_not_in_site_domain:
|
||||
return __( "Sender email address does not belong to the site domain.", 'contact-form-7' );
|
||||
case self::error_html_in_message:
|
||||
return __( "HTML tags are used in a message.", 'contact-form-7' );
|
||||
case self::error_multiple_controls_in_label:
|
||||
return __( "Multiple form controls are in a single label element.", 'contact-form-7' );
|
||||
case self::error_invalid_mail_header:
|
||||
return __( "There are invalid mail header fields.", 'contact-form-7' );
|
||||
case self::error_deprecated_settings:
|
||||
return __( "Deprecated settings are used.", 'contact-form-7' );
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a validation error.
|
||||
*
|
||||
* @param string $section The section where the error detected.
|
||||
* @param int $code The unique code of the error.
|
||||
* This must be one of the class constants.
|
||||
* @param string|array $args Optional options for the error.
|
||||
*/
|
||||
public function add_error( $section, $code, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array(
|
||||
'message' => '',
|
||||
'params' => array(),
|
||||
) );
|
||||
|
||||
if ( ! isset( $this->errors[$section] ) ) {
|
||||
$this->errors[$section] = array();
|
||||
}
|
||||
|
||||
$this->errors[$section][] = array( 'code' => $code, 'args' => $args );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes an error.
|
||||
*/
|
||||
public function remove_error( $section, $code ) {
|
||||
if ( empty( $this->errors[$section] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( (array) $this->errors[$section] as $key => $error ) {
|
||||
if ( isset( $error['code'] )
|
||||
and $error['code'] == $code ) {
|
||||
unset( $this->errors[$section][$key] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $this->errors[$section] ) ) {
|
||||
unset( $this->errors[$section] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The main validation runner.
|
||||
*
|
||||
* @return bool True if there is no error detected.
|
||||
*/
|
||||
public function validate() {
|
||||
$this->errors = array();
|
||||
|
||||
$this->validate_form();
|
||||
$this->validate_mail( 'mail' );
|
||||
$this->validate_mail( 'mail_2' );
|
||||
$this->validate_messages();
|
||||
$this->validate_additional_settings();
|
||||
|
||||
do_action( 'wpcf7_config_validator_validate', $this );
|
||||
|
||||
return $this->is_valid();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves detected errors as a post meta data.
|
||||
*/
|
||||
public function save() {
|
||||
if ( $this->contact_form->initial() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete_post_meta( $this->contact_form->id(), '_config_errors' );
|
||||
|
||||
if ( $this->errors ) {
|
||||
update_post_meta(
|
||||
$this->contact_form->id(), '_config_errors', $this->errors
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restore errors from the database.
|
||||
*/
|
||||
public function restore() {
|
||||
$config_errors = get_post_meta(
|
||||
$this->contact_form->id(), '_config_errors', true
|
||||
);
|
||||
|
||||
foreach ( (array) $config_errors as $section => $errors ) {
|
||||
if ( empty( $errors ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! is_array( $errors ) ) { // for back-compat
|
||||
$code = $errors;
|
||||
$this->add_error( $section, $code );
|
||||
} else {
|
||||
foreach ( (array) $errors as $error ) {
|
||||
if ( ! empty( $error['code'] ) ) {
|
||||
$code = $error['code'];
|
||||
$args = isset( $error['args'] ) ? $error['args'] : '';
|
||||
$this->add_error( $section, $code, $args );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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] == ']' ) {
|
||||
return substr( $matches[0], 1, -1 );
|
||||
}
|
||||
|
||||
$tag = $matches[0];
|
||||
$tagname = $matches[2];
|
||||
$values = $matches[3];
|
||||
|
||||
$mail_tag = new WPCF7_MailTag( $tag, $tagname, $values );
|
||||
$field_name = $mail_tag->field_name();
|
||||
|
||||
$example_email = 'example@example.com';
|
||||
$example_text = 'example';
|
||||
$example_blank = '';
|
||||
|
||||
$form_tags = $this->contact_form->scan_form_tags(
|
||||
array( 'name' => $field_name )
|
||||
);
|
||||
|
||||
if ( $form_tags ) {
|
||||
$form_tag = new WPCF7_FormTag( $form_tags[0] );
|
||||
|
||||
$is_required = ( $form_tag->is_required() || 'radio' == $form_tag->type );
|
||||
|
||||
if ( ! $is_required ) {
|
||||
return $example_blank;
|
||||
}
|
||||
|
||||
if ( wpcf7_form_tag_supports( $form_tag->type, 'selectable-values' ) ) {
|
||||
if ( $form_tag->pipes instanceof WPCF7_Pipes ) {
|
||||
if ( $mail_tag->get_option( 'do_not_heat' ) ) {
|
||||
$before_pipes = $form_tag->pipes->collect_befores();
|
||||
$last_item = array_pop( $before_pipes );
|
||||
} else {
|
||||
$after_pipes = $form_tag->pipes->collect_afters();
|
||||
$last_item = array_pop( $after_pipes );
|
||||
}
|
||||
} else {
|
||||
$last_item = array_pop( $form_tag->values );
|
||||
}
|
||||
|
||||
if ( $last_item and wpcf7_is_mailbox_list( $last_item ) ) {
|
||||
return $example_email;
|
||||
} else {
|
||||
return $example_text;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'email' == $form_tag->basetype ) {
|
||||
return $example_email;
|
||||
} else {
|
||||
return $example_text;
|
||||
}
|
||||
|
||||
} else { // maybe special mail tag
|
||||
// for back-compat
|
||||
$field_name = preg_replace( '/^wpcf7\./', '_', $field_name );
|
||||
|
||||
if ( '_site_admin_email' == $field_name ) {
|
||||
return get_bloginfo( 'admin_email', 'raw' );
|
||||
|
||||
} elseif ( '_user_agent' == $field_name ) {
|
||||
return $example_text;
|
||||
|
||||
} elseif ( '_user_email' == $field_name ) {
|
||||
return $this->contact_form->is_true( 'subscribers_only' )
|
||||
? $example_email
|
||||
: $example_blank;
|
||||
|
||||
} elseif ( '_user_' == substr( $field_name, 0, 6 ) ) {
|
||||
return $this->contact_form->is_true( 'subscribers_only' )
|
||||
? $example_text
|
||||
: $example_blank;
|
||||
|
||||
} elseif ( '_' == substr( $field_name, 0, 1 ) ) {
|
||||
return '_email' == substr( $field_name, -6 )
|
||||
? $example_email
|
||||
: $example_text;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the form section.
|
||||
*/
|
||||
public function validate_form() {
|
||||
$section = 'form.body';
|
||||
$form = $this->contact_form->prop( 'form' );
|
||||
$this->detect_multiple_controls_in_label( $section, $form );
|
||||
$this->detect_unavailable_names( $section, $form );
|
||||
$this->detect_unavailable_html_elements( $section, $form );
|
||||
$this->detect_dots_in_names( $section, $form );
|
||||
$this->detect_colons_in_names( $section, $form );
|
||||
$this->detect_upload_filesize_overlimit( $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';
|
||||
|
||||
if ( preg_match_all( $pattern, $content, $matches ) ) {
|
||||
$form_tags_manager = WPCF7_FormTagsManager::get_instance();
|
||||
|
||||
foreach ( $matches[1] as $insidelabel ) {
|
||||
$tags = $form_tags_manager->scan( $insidelabel );
|
||||
$fields_count = 0;
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$is_multiple_controls_container = wpcf7_form_tag_supports(
|
||||
$tag->type, 'multiple-controls-container'
|
||||
);
|
||||
|
||||
$is_zero_controls_container = wpcf7_form_tag_supports(
|
||||
$tag->type, 'zero-controls-container'
|
||||
);
|
||||
|
||||
if ( $is_multiple_controls_container ) {
|
||||
$fields_count += count( $tag->values );
|
||||
|
||||
if ( $tag->has_option( 'free_text' ) ) {
|
||||
$fields_count += 1;
|
||||
}
|
||||
} elseif ( $is_zero_controls_container ) {
|
||||
$fields_count += 0;
|
||||
} elseif ( ! empty( $tag->name ) ) {
|
||||
$fields_count += 1;
|
||||
}
|
||||
|
||||
if ( 1 < $fields_count ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_multiple_controls_in_label, array(
|
||||
'link' => self::get_doc_link( 'multiple_controls_in_label' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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',
|
||||
'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order',
|
||||
'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second',
|
||||
'name', 'category_name', 'tag', 'feed', 'author_name', 'static',
|
||||
'pagename', 'page_id', 'error', 'attachment', 'attachment_id',
|
||||
'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term',
|
||||
'cpage', 'post_type', 'embed',
|
||||
);
|
||||
|
||||
$form_tags_manager = WPCF7_FormTagsManager::get_instance();
|
||||
|
||||
$ng_named_tags = $form_tags_manager->filter( $content, array(
|
||||
'name' => $public_query_vars,
|
||||
) );
|
||||
|
||||
$ng_names = array();
|
||||
|
||||
foreach ( $ng_named_tags as $tag ) {
|
||||
$ng_names[] = sprintf( '"%s"', $tag->name );
|
||||
}
|
||||
|
||||
if ( $ng_names ) {
|
||||
$ng_names = array_unique( $ng_names );
|
||||
|
||||
return $this->add_error( $section,
|
||||
self::error_unavailable_names,
|
||||
array(
|
||||
'message' =>
|
||||
/* translators: %names%: a list of form control names */
|
||||
__( "Unavailable names (%names%) are used for form controls.", 'contact-form-7' ),
|
||||
'params' => array( 'names' => implode( ', ', $ng_names ) ),
|
||||
'link' => self::get_doc_link( 'unavailable_names' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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';
|
||||
|
||||
if ( preg_match( $pattern, $content ) ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_unavailable_html_elements,
|
||||
array(
|
||||
'message' => __( "Unavailable HTML elements are used in the form template.", 'contact-form-7' ),
|
||||
'link' => self::get_doc_link( 'unavailable_html_elements' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
$tags = $form_tags_manager->filter( $content, array(
|
||||
'feature' => 'name-attr',
|
||||
) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
if ( false !== strpos( $tag->raw_name, '.' ) ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_dots_in_names,
|
||||
array(
|
||||
'message' => __( "Dots are used in form-tag names.", 'contact-form-7' ),
|
||||
'link' => self::get_doc_link( 'dots_in_names' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
$tags = $form_tags_manager->filter( $content, array(
|
||||
'feature' => 'name-attr',
|
||||
) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
if ( false !== strpos( $tag->raw_name, ':' ) ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_colons_in_names,
|
||||
array(
|
||||
'message' => __( "Colons are used in form-tag names.", 'contact-form-7' ),
|
||||
'link' => self::get_doc_link( 'colons_in_names' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of uploadable file size overlimit.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/upload-filesize-overlimit
|
||||
*/
|
||||
public function detect_upload_filesize_overlimit( $section, $content ) {
|
||||
$upload_max_filesize = ini_get( 'upload_max_filesize' );
|
||||
|
||||
if ( ! $upload_max_filesize ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$upload_max_filesize = strtolower( $upload_max_filesize );
|
||||
$upload_max_filesize = trim( $upload_max_filesize );
|
||||
|
||||
if ( ! preg_match( '/^(\d+)([kmg]?)$/', $upload_max_filesize, $matches ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'k' === $matches[2] ) {
|
||||
$upload_max_filesize = (int) $matches[1] * KB_IN_BYTES;
|
||||
} elseif ( 'm' === $matches[2] ) {
|
||||
$upload_max_filesize = (int) $matches[1] * MB_IN_BYTES;
|
||||
} elseif ( 'g' === $matches[2] ) {
|
||||
$upload_max_filesize = (int) $matches[1] * GB_IN_BYTES;
|
||||
} else {
|
||||
$upload_max_filesize = (int) $matches[1];
|
||||
}
|
||||
|
||||
$form_tags_manager = WPCF7_FormTagsManager::get_instance();
|
||||
|
||||
$tags = $form_tags_manager->filter( $content, array(
|
||||
'basetype' => 'file',
|
||||
) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
if ( $upload_max_filesize < $tag->get_limit_option() ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_upload_filesize_overlimit,
|
||||
array(
|
||||
'message' => __( "Uploadable file size exceeds PHP’s maximum acceptable size.", 'contact-form-7' ),
|
||||
'link' => self::get_doc_link( 'upload_filesize_overlimit' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the mail sections.
|
||||
*/
|
||||
public function validate_mail( $template = 'mail' ) {
|
||||
if (
|
||||
$this->contact_form->is_true( 'demo_mode' ) or
|
||||
$this->contact_form->is_true( 'skip_mail' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$components = (array) $this->contact_form->prop( $template );
|
||||
|
||||
if ( ! $components ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'mail' !== $template and empty( $components['active'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$components = wp_parse_args( $components, array(
|
||||
'subject' => '',
|
||||
'sender' => '',
|
||||
'recipient' => '',
|
||||
'additional_headers' => '',
|
||||
'body' => '',
|
||||
'attachments' => '',
|
||||
) );
|
||||
|
||||
$callback = array( $this, 'replace_mail_tags_with_minimum_input' );
|
||||
|
||||
$subject = new WPCF7_MailTaggedText(
|
||||
$components['subject'],
|
||||
array( 'callback' => $callback )
|
||||
);
|
||||
|
||||
$subject = $subject->replace_tags();
|
||||
$subject = wpcf7_strip_newline( $subject );
|
||||
|
||||
$this->detect_maybe_empty( sprintf( '%s.subject', $template ), $subject );
|
||||
|
||||
$sender = new WPCF7_MailTaggedText(
|
||||
$components['sender'],
|
||||
array( 'callback' => $callback )
|
||||
);
|
||||
|
||||
$sender = $sender->replace_tags();
|
||||
$sender = wpcf7_strip_newline( $sender );
|
||||
|
||||
$invalid_mailbox = $this->detect_invalid_mailbox_syntax(
|
||||
sprintf( '%s.sender', $template ),
|
||||
$sender
|
||||
);
|
||||
|
||||
if ( ! $invalid_mailbox and ! wpcf7_is_email_in_site_domain( $sender ) ) {
|
||||
$this->add_error( sprintf( '%s.sender', $template ),
|
||||
self::error_email_not_in_site_domain, array(
|
||||
'link' => self::get_doc_link( 'email_not_in_site_domain' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$recipient = new WPCF7_MailTaggedText(
|
||||
$components['recipient'],
|
||||
array( 'callback' => $callback )
|
||||
);
|
||||
|
||||
$recipient = $recipient->replace_tags();
|
||||
$recipient = wpcf7_strip_newline( $recipient );
|
||||
|
||||
$this->detect_invalid_mailbox_syntax(
|
||||
sprintf( '%s.recipient', $template ),
|
||||
$recipient
|
||||
);
|
||||
|
||||
$additional_headers = new WPCF7_MailTaggedText(
|
||||
$components['additional_headers'],
|
||||
array( 'callback' => $callback )
|
||||
);
|
||||
|
||||
$additional_headers = $additional_headers->replace_tags();
|
||||
$additional_headers = explode( "\n", $additional_headers );
|
||||
$mailbox_header_types = array( 'reply-to', 'cc', 'bcc' );
|
||||
$invalid_mail_header_exists = false;
|
||||
|
||||
foreach ( $additional_headers as $header ) {
|
||||
$header = trim( $header );
|
||||
|
||||
if ( '' === $header ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! preg_match( '/^([0-9A-Za-z-]+):(.*)$/', $header, $matches ) ) {
|
||||
$invalid_mail_header_exists = true;
|
||||
} else {
|
||||
$header_name = $matches[1];
|
||||
$header_value = trim( $matches[2] );
|
||||
|
||||
if ( in_array( strtolower( $header_name ), $mailbox_header_types )
|
||||
and '' !== $header_value ) {
|
||||
$this->detect_invalid_mailbox_syntax(
|
||||
sprintf( '%s.additional_headers', $template ),
|
||||
$header_value,
|
||||
array(
|
||||
'message' =>
|
||||
__( "Invalid mailbox syntax is used in the %name% field.", 'contact-form-7' ),
|
||||
'params' => array( 'name' => $header_name )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $invalid_mail_header_exists ) {
|
||||
$this->add_error( sprintf( '%s.additional_headers', $template ),
|
||||
self::error_invalid_mail_header, array(
|
||||
'link' => self::get_doc_link( 'invalid_mail_header' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$body = new WPCF7_MailTaggedText(
|
||||
$components['body'],
|
||||
array( 'callback' => $callback )
|
||||
);
|
||||
|
||||
$body = $body->replace_tags();
|
||||
|
||||
$this->detect_maybe_empty( sprintf( '%s.body', $template ), $body );
|
||||
|
||||
if ( '' !== $components['attachments'] ) {
|
||||
$attachables = array();
|
||||
|
||||
$tags = $this->contact_form->scan_form_tags(
|
||||
array( 'type' => array( 'file', 'file*' ) )
|
||||
);
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$name = $tag->name;
|
||||
|
||||
if ( false === strpos( $components['attachments'], "[{$name}]" ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$limit = (int) $tag->get_limit_option();
|
||||
|
||||
if ( empty( $attachables[$name] )
|
||||
or $attachables[$name] < $limit ) {
|
||||
$attachables[$name] = $limit;
|
||||
}
|
||||
}
|
||||
|
||||
$total_size = array_sum( $attachables );
|
||||
|
||||
$has_file_not_found = false;
|
||||
$has_file_not_in_content_dir = false;
|
||||
|
||||
foreach ( explode( "\n", $components['attachments'] ) as $line ) {
|
||||
$line = trim( $line );
|
||||
|
||||
if ( '' === $line or '[' == substr( $line, 0, 1 ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$has_file_not_found = $this->detect_file_not_found(
|
||||
sprintf( '%s.attachments', $template ), $line
|
||||
);
|
||||
|
||||
if ( ! $has_file_not_found and ! $has_file_not_in_content_dir ) {
|
||||
$has_file_not_in_content_dir = $this->detect_file_not_in_content_dir(
|
||||
sprintf( '%s.attachments', $template ), $line
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! $has_file_not_found ) {
|
||||
$path = path_join( WP_CONTENT_DIR, $line );
|
||||
$total_size += (int) @filesize( $path );
|
||||
}
|
||||
}
|
||||
|
||||
$max = 25 * MB_IN_BYTES; // 25 MB
|
||||
|
||||
if ( $max < $total_size ) {
|
||||
$this->add_error( sprintf( '%s.attachments', $template ),
|
||||
self::error_attachments_overweight,
|
||||
array(
|
||||
'message' => __( "The total size of attachment files is too large.", 'contact-form-7' ),
|
||||
'link' => self::get_doc_link( 'attachments_overweight' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of invalid mailbox syntax.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/invalid-mailbox-syntax/
|
||||
*/
|
||||
public function detect_invalid_mailbox_syntax( $section, $content, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array(
|
||||
'link' => self::get_doc_link( 'invalid_mailbox_syntax' ),
|
||||
'message' => '',
|
||||
'params' => array(),
|
||||
) );
|
||||
|
||||
if ( ! wpcf7_is_mailbox_list( $content ) ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_invalid_mailbox_syntax, $args
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of empty message fields.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/maybe-empty/
|
||||
*/
|
||||
public function detect_maybe_empty( $section, $content ) {
|
||||
if ( '' === $content ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_maybe_empty, array(
|
||||
'link' => self::get_doc_link( 'maybe_empty' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of nonexistent attachment files.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/file-not-found/
|
||||
*/
|
||||
public function detect_file_not_found( $section, $content ) {
|
||||
$path = path_join( WP_CONTENT_DIR, $content );
|
||||
|
||||
if ( ! is_readable( $path ) or ! is_file( $path ) ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_file_not_found,
|
||||
array(
|
||||
'message' =>
|
||||
__( "Attachment file does not exist at %path%.", 'contact-form-7' ),
|
||||
'params' => array( 'path' => $content ),
|
||||
'link' => self::get_doc_link( 'file_not_found' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of attachment files out of the content directory.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/file-not-in-content-dir/
|
||||
*/
|
||||
public function detect_file_not_in_content_dir( $section, $content ) {
|
||||
$path = path_join( WP_CONTENT_DIR, $content );
|
||||
|
||||
if ( ! wpcf7_is_file_path_in_content_dir( $path ) ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_file_not_in_content_dir,
|
||||
array(
|
||||
'message' =>
|
||||
__( "It is not allowed to use files outside the wp-content directory.", 'contact-form-7' ),
|
||||
'link' => self::get_doc_link( 'file_not_in_content_dir' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the messages section.
|
||||
*/
|
||||
public function validate_messages() {
|
||||
$messages = (array) $this->contact_form->prop( 'messages' );
|
||||
|
||||
if ( ! $messages ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $messages['captcha_not_match'] )
|
||||
and ! wpcf7_use_really_simple_captcha() ) {
|
||||
unset( $messages['captcha_not_match'] );
|
||||
}
|
||||
|
||||
foreach ( $messages as $key => $message ) {
|
||||
$section = sprintf( 'messages.%s', $key );
|
||||
$this->detect_html_in_message( $section, $message );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of HTML uses in a message.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/html-in-message/
|
||||
*/
|
||||
public function detect_html_in_message( $section, $content ) {
|
||||
$stripped = wp_strip_all_tags( $content );
|
||||
|
||||
if ( $stripped != $content ) {
|
||||
return $this->add_error( $section,
|
||||
self::error_html_in_message,
|
||||
array(
|
||||
'link' => self::get_doc_link( 'html_in_message' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the additional settings section.
|
||||
*/
|
||||
public function validate_additional_settings() {
|
||||
$deprecated_settings_used =
|
||||
$this->contact_form->additional_setting( 'on_sent_ok' ) ||
|
||||
$this->contact_form->additional_setting( 'on_submit' );
|
||||
|
||||
if ( $deprecated_settings_used ) {
|
||||
return $this->add_error( 'additional_settings.body',
|
||||
self::error_deprecated_settings,
|
||||
array(
|
||||
'link' => self::get_doc_link( 'deprecated_settings' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
add_action(
|
||||
'wpcf7_update_option',
|
||||
'wpcf7_config_validator_update_option',
|
||||
10, 3
|
||||
);
|
||||
|
||||
/**
|
||||
* Runs bulk validation after the reCAPTCHA integration option is updated.
|
||||
*/
|
||||
function wpcf7_config_validator_update_option( $name, $value, $old_option ) {
|
||||
if ( 'recaptcha' === $name ) {
|
||||
$contact_forms = WPCF7_ContactForm::find();
|
||||
|
||||
$options = array(
|
||||
'include' => 'unsafe_email_without_protection',
|
||||
);
|
||||
|
||||
foreach ( $contact_forms as $contact_form ) {
|
||||
$config_validator = new WPCF7_ConfigValidator( $contact_form, $options );
|
||||
$config_validator->restore();
|
||||
$config_validator->validate();
|
||||
$config_validator->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
trait WPCF7_ConfigValidator_AdditionalSettings {
|
||||
|
||||
/**
|
||||
* Runs error detection for the additional settings section.
|
||||
*/
|
||||
public function validate_additional_settings() {
|
||||
$section = 'additional_settings.body';
|
||||
|
||||
if ( $this->supports( 'deprecated_settings' ) ) {
|
||||
$deprecated_settings_used =
|
||||
$this->contact_form->additional_setting( 'on_sent_ok' ) ||
|
||||
$this->contact_form->additional_setting( 'on_submit' );
|
||||
|
||||
if ( $deprecated_settings_used ) {
|
||||
$this->add_error( $section, 'deprecated_settings',
|
||||
array(
|
||||
'message' => __( "Deprecated settings are used.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'deprecated_settings' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
trait WPCF7_ConfigValidator_Form {
|
||||
|
||||
/**
|
||||
* Runs error detection for the form section.
|
||||
*/
|
||||
public function validate_form() {
|
||||
$section = 'form.body';
|
||||
$form = $this->contact_form->prop( 'form' );
|
||||
|
||||
if ( $this->supports( 'multiple_controls_in_label' ) ) {
|
||||
if ( $this->detect_multiple_controls_in_label( $section, $form ) ) {
|
||||
$this->add_error( $section, 'multiple_controls_in_label',
|
||||
array(
|
||||
'message' => __( "Multiple form controls are in a single label element.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'multiple_controls_in_label' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'unavailable_names' ) ) {
|
||||
$ng_names = $this->detect_unavailable_names( $section, $form );
|
||||
|
||||
if ( $ng_names ) {
|
||||
$this->add_error( $section, 'unavailable_names',
|
||||
array(
|
||||
'message' =>
|
||||
/* translators: %names%: a list of form control names */
|
||||
__( "Unavailable names (%names%) are used for form controls.", 'contact-form-7' ),
|
||||
'params' => array( 'names' => implode( ', ', $ng_names ) ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'unavailable_names' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'unavailable_html_elements' ) ) {
|
||||
if ( $this->detect_unavailable_html_elements( $section, $form ) ) {
|
||||
$this->add_error( $section, 'unavailable_html_elements',
|
||||
array(
|
||||
'message' => __( "Unavailable HTML elements are used in the form template.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'unavailable_html_elements' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'dots_in_names' ) ) {
|
||||
if ( $this->detect_dots_in_names( $section, $form ) ) {
|
||||
$this->add_error( $section, 'dots_in_names',
|
||||
array(
|
||||
'message' => __( "Dots are used in form-tag names.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'dots_in_names' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'colons_in_names' ) ) {
|
||||
if ( $this->detect_colons_in_names( $section, $form ) ) {
|
||||
$this->add_error( $section, 'colons_in_names',
|
||||
array(
|
||||
'message' => __( "Colons are used in form-tag names.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'colons_in_names' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'upload_filesize_overlimit' ) ) {
|
||||
if ( $this->detect_upload_filesize_overlimit( $section, $form ) ) {
|
||||
$this->add_error( $section, 'upload_filesize_overlimit',
|
||||
array(
|
||||
'message' => __( "Uploadable file size exceeds PHP’s maximum acceptable size.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'upload_filesize_overlimit' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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';
|
||||
|
||||
if ( preg_match_all( $pattern, $content, $matches ) ) {
|
||||
$form_tags_manager = WPCF7_FormTagsManager::get_instance();
|
||||
|
||||
foreach ( $matches[1] as $insidelabel ) {
|
||||
$tags = $form_tags_manager->scan( $insidelabel );
|
||||
$fields_count = 0;
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$is_multiple_controls_container = wpcf7_form_tag_supports(
|
||||
$tag->type, 'multiple-controls-container'
|
||||
);
|
||||
|
||||
$is_zero_controls_container = wpcf7_form_tag_supports(
|
||||
$tag->type, 'zero-controls-container'
|
||||
);
|
||||
|
||||
if ( $is_multiple_controls_container ) {
|
||||
$fields_count += count( $tag->values );
|
||||
|
||||
if ( $tag->has_option( 'free_text' ) ) {
|
||||
$fields_count += 1;
|
||||
}
|
||||
} elseif ( $is_zero_controls_container ) {
|
||||
$fields_count += 0;
|
||||
} elseif ( ! empty( $tag->name ) ) {
|
||||
$fields_count += 1;
|
||||
}
|
||||
|
||||
if ( 1 < $fields_count ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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',
|
||||
'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order',
|
||||
'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second',
|
||||
'name', 'category_name', 'tag', 'feed', 'author_name', 'static',
|
||||
'pagename', 'page_id', 'error', 'attachment', 'attachment_id',
|
||||
'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term',
|
||||
'cpage', 'post_type', 'embed',
|
||||
);
|
||||
|
||||
$form_tags_manager = WPCF7_FormTagsManager::get_instance();
|
||||
|
||||
$ng_named_tags = $form_tags_manager->filter( $content, array(
|
||||
'name' => $public_query_vars,
|
||||
) );
|
||||
|
||||
$ng_names = array();
|
||||
|
||||
foreach ( $ng_named_tags as $tag ) {
|
||||
$ng_names[] = sprintf( '"%s"', $tag->name );
|
||||
}
|
||||
|
||||
if ( $ng_names ) {
|
||||
return array_unique( $ng_names );
|
||||
}
|
||||
|
||||
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';
|
||||
|
||||
if ( preg_match( $pattern, $content ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
$tags = $form_tags_manager->filter( $content, array(
|
||||
'feature' => 'name-attr',
|
||||
) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
if ( str_contains( $tag->raw_name, '.' ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
$tags = $form_tags_manager->filter( $content, array(
|
||||
'feature' => 'name-attr',
|
||||
) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
if ( str_contains( $tag->raw_name, ':' ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of uploadable file size overlimit.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/upload-filesize-overlimit
|
||||
*/
|
||||
public function detect_upload_filesize_overlimit( $section, $content ) {
|
||||
$upload_max_filesize = ini_get( 'upload_max_filesize' );
|
||||
|
||||
if ( ! $upload_max_filesize ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$upload_max_filesize = strtolower( $upload_max_filesize );
|
||||
$upload_max_filesize = trim( $upload_max_filesize );
|
||||
|
||||
if ( ! preg_match( '/^(\d+)([kmg]?)$/', $upload_max_filesize, $matches ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'k' === $matches[2] ) {
|
||||
$upload_max_filesize = (int) $matches[1] * KB_IN_BYTES;
|
||||
} elseif ( 'm' === $matches[2] ) {
|
||||
$upload_max_filesize = (int) $matches[1] * MB_IN_BYTES;
|
||||
} elseif ( 'g' === $matches[2] ) {
|
||||
$upload_max_filesize = (int) $matches[1] * GB_IN_BYTES;
|
||||
} else {
|
||||
$upload_max_filesize = (int) $matches[1];
|
||||
}
|
||||
|
||||
$form_tags_manager = WPCF7_FormTagsManager::get_instance();
|
||||
|
||||
$tags = $form_tags_manager->filter( $content, array(
|
||||
'basetype' => 'file',
|
||||
) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
if ( $upload_max_filesize < $tag->get_limit_option() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,603 @@
|
||||
<?php
|
||||
|
||||
trait WPCF7_ConfigValidator_Mail {
|
||||
|
||||
/**
|
||||
* Replaces all mail-tags in the given content.
|
||||
*/
|
||||
public function replace_mail_tags( $content, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array(
|
||||
'html' => false,
|
||||
'callback' =>
|
||||
array( $this, 'replace_mail_tags_with_minimum_input_callback' ),
|
||||
) );
|
||||
|
||||
$content = new WPCF7_MailTaggedText( $content, $args );
|
||||
|
||||
return $content->replace_tags();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback function for WPCF7_MailTaggedText. Replaces mail-tags with
|
||||
* the most conservative inputs.
|
||||
*/
|
||||
public function replace_mail_tags_with_minimum_input_callback( $matches ) {
|
||||
// allow [[foo]] syntax for escaping a tag
|
||||
if ( $matches[1] === '[' and $matches[4] === ']' ) {
|
||||
return substr( $matches[0], 1, -1 );
|
||||
}
|
||||
|
||||
$tag = $matches[0];
|
||||
$tagname = $matches[2];
|
||||
$values = $matches[3];
|
||||
|
||||
$mail_tag = new WPCF7_MailTag( $tag, $tagname, $values );
|
||||
$field_name = $mail_tag->field_name();
|
||||
|
||||
$example_email = 'example@example.com';
|
||||
$example_text = 'example';
|
||||
$example_blank = '';
|
||||
|
||||
$form_tags = $this->contact_form->scan_form_tags(
|
||||
array( 'name' => $field_name )
|
||||
);
|
||||
|
||||
if ( $form_tags ) {
|
||||
$form_tag = new WPCF7_FormTag( $form_tags[0] );
|
||||
|
||||
$is_required = $form_tag->is_required() || 'radio' === $form_tag->type;
|
||||
|
||||
if ( ! $is_required ) {
|
||||
return $example_blank;
|
||||
}
|
||||
|
||||
if ( wpcf7_form_tag_supports( $form_tag->type, 'selectable-values' ) ) {
|
||||
if ( $form_tag->pipes instanceof WPCF7_Pipes ) {
|
||||
if ( $mail_tag->get_option( 'do_not_heat' ) ) {
|
||||
$before_pipes = $form_tag->pipes->collect_befores();
|
||||
$last_item = array_pop( $before_pipes );
|
||||
} else {
|
||||
$after_pipes = $form_tag->pipes->collect_afters();
|
||||
$last_item = array_pop( $after_pipes );
|
||||
}
|
||||
} else {
|
||||
$last_item = array_pop( $form_tag->values );
|
||||
}
|
||||
|
||||
if ( $last_item and wpcf7_is_mailbox_list( $last_item ) ) {
|
||||
return $example_email;
|
||||
} else {
|
||||
return $example_text;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'email' === $form_tag->basetype ) {
|
||||
return $example_email;
|
||||
} else {
|
||||
return $example_text;
|
||||
}
|
||||
|
||||
} else { // maybe special mail tag
|
||||
// for back-compat
|
||||
$field_name = preg_replace( '/^wpcf7\./', '_', $field_name );
|
||||
|
||||
if ( '_site_admin_email' === $field_name ) {
|
||||
return get_bloginfo( 'admin_email', 'raw' );
|
||||
|
||||
} elseif ( '_user_agent' === $field_name ) {
|
||||
return $example_text;
|
||||
|
||||
} elseif ( '_user_email' === $field_name ) {
|
||||
return $this->contact_form->is_true( 'subscribers_only' )
|
||||
? $example_email
|
||||
: $example_blank;
|
||||
|
||||
} elseif ( str_starts_with( $field_name, '_user_' ) ) {
|
||||
return $this->contact_form->is_true( 'subscribers_only' )
|
||||
? $example_text
|
||||
: $example_blank;
|
||||
|
||||
} elseif ( str_starts_with( $field_name, '_' ) ) {
|
||||
return str_ends_with( $field_name, '_email' )
|
||||
? $example_email
|
||||
: $example_text;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the mail sections.
|
||||
*/
|
||||
public function validate_mail( $template = 'mail' ) {
|
||||
if (
|
||||
$this->contact_form->is_true( 'demo_mode' ) or
|
||||
$this->contact_form->is_true( 'skip_mail' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$components = (array) $this->contact_form->prop( $template );
|
||||
|
||||
if ( ! $components ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'mail' !== $template and empty( $components['active'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$components = wp_parse_args( $components, array(
|
||||
'subject' => '',
|
||||
'sender' => '',
|
||||
'recipient' => '',
|
||||
'additional_headers' => '',
|
||||
'body' => '',
|
||||
'attachments' => '',
|
||||
) );
|
||||
|
||||
$this->validate_mail_subject(
|
||||
$template,
|
||||
$components['subject']
|
||||
);
|
||||
|
||||
$this->validate_mail_sender(
|
||||
$template,
|
||||
$components['sender']
|
||||
);
|
||||
|
||||
$this->validate_mail_recipient(
|
||||
$template,
|
||||
$components['recipient']
|
||||
);
|
||||
|
||||
$this->validate_mail_additional_headers(
|
||||
$template,
|
||||
$components['additional_headers']
|
||||
);
|
||||
|
||||
$this->validate_mail_body(
|
||||
$template,
|
||||
$components['body']
|
||||
);
|
||||
|
||||
$this->validate_mail_attachments(
|
||||
$template,
|
||||
$components['attachments']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the mail subject section.
|
||||
*/
|
||||
public function validate_mail_subject( $template, $content ) {
|
||||
$section = sprintf( '%s.subject', $template );
|
||||
|
||||
if ( $this->supports( 'maybe_empty' ) ) {
|
||||
if ( $this->detect_maybe_empty( $section, $content ) ) {
|
||||
$this->add_error( $section, 'maybe_empty',
|
||||
array(
|
||||
'message' => __( "There is a possible empty field.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'maybe_empty' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the mail sender section.
|
||||
*/
|
||||
public function validate_mail_sender( $template, $content ) {
|
||||
$section = sprintf( '%s.sender', $template );
|
||||
|
||||
if ( $this->supports( 'invalid_mailbox_syntax' ) ) {
|
||||
if ( $this->detect_invalid_mailbox_syntax( $section, $content ) ) {
|
||||
$this->add_error( $section, 'invalid_mailbox_syntax',
|
||||
array(
|
||||
'message' => __( "Invalid mailbox syntax is used.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'invalid_mailbox_syntax' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'email_not_in_site_domain' ) ) {
|
||||
$this->remove_error( $section, 'email_not_in_site_domain' );
|
||||
|
||||
if ( ! $this->has_error( $section, 'invalid_mailbox_syntax' ) ) {
|
||||
$sender = $this->replace_mail_tags( $content );
|
||||
$sender = wpcf7_strip_newline( $sender );
|
||||
|
||||
if ( ! wpcf7_is_email_in_site_domain( $sender ) ) {
|
||||
$this->add_error( $section, 'email_not_in_site_domain',
|
||||
array(
|
||||
'message' => __( "Sender email address does not belong to the site domain.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the mail recipient section.
|
||||
*/
|
||||
public function validate_mail_recipient( $template, $content ) {
|
||||
$section = sprintf( '%s.recipient', $template );
|
||||
|
||||
if ( $this->supports( 'invalid_mailbox_syntax' ) ) {
|
||||
if ( $this->detect_invalid_mailbox_syntax( $section, $content ) ) {
|
||||
$this->add_error( $section, 'invalid_mailbox_syntax',
|
||||
array(
|
||||
'message' => __( "Invalid mailbox syntax is used.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'invalid_mailbox_syntax' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'unsafe_email_without_protection' ) ) {
|
||||
$this->remove_error( $section, 'unsafe_email_without_protection' );
|
||||
|
||||
if ( ! $this->has_error( $section, 'invalid_mailbox_syntax' ) ) {
|
||||
if (
|
||||
$this->detect_unsafe_email_without_protection( $section, $content )
|
||||
) {
|
||||
$this->add_error( $section, 'unsafe_email_without_protection',
|
||||
array(
|
||||
'message' => __( "Unsafe email config is used without sufficient protection.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the mail additional headers section.
|
||||
*/
|
||||
public function validate_mail_additional_headers( $template, $content ) {
|
||||
$section = sprintf( '%s.additional_headers', $template );
|
||||
|
||||
$invalid_mail_headers = array();
|
||||
$invalid_mailbox_fields = array();
|
||||
$unsafe_email_fields = array();
|
||||
|
||||
foreach ( explode( "\n", $content ) as $header ) {
|
||||
$header = trim( $header );
|
||||
|
||||
if ( '' === $header ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_valid_header = preg_match(
|
||||
'/^([0-9A-Za-z-]+):(.*)$/',
|
||||
$header,
|
||||
$matches
|
||||
);
|
||||
|
||||
if ( ! $is_valid_header ) {
|
||||
$invalid_mail_headers[] = $header;
|
||||
continue;
|
||||
}
|
||||
|
||||
$header_name = $matches[1];
|
||||
$header_value = trim( $matches[2] );
|
||||
|
||||
if (
|
||||
in_array(
|
||||
strtolower( $header_name ), array( 'reply-to', 'cc', 'bcc' )
|
||||
) and
|
||||
'' !== $header_value and
|
||||
$this->detect_invalid_mailbox_syntax( $section, $header_value )
|
||||
) {
|
||||
$invalid_mailbox_fields[] = $header_name;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
in_array( strtolower( $header_name ), array( 'cc', 'bcc' ) ) and
|
||||
$this->detect_unsafe_email_without_protection( $section, $header_value )
|
||||
) {
|
||||
$unsafe_email_fields[] = $header_name;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'invalid_mail_header' ) ) {
|
||||
if ( ! empty( $invalid_mail_headers ) ) {
|
||||
$this->add_error( $section, 'invalid_mail_header',
|
||||
array(
|
||||
'message' => __( "There are invalid mail header fields.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'invalid_mail_header' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'invalid_mailbox_syntax' ) ) {
|
||||
if ( ! empty( $invalid_mailbox_fields ) ) {
|
||||
foreach ( $invalid_mailbox_fields as $header_name ) {
|
||||
$this->add_error( $section, 'invalid_mailbox_syntax',
|
||||
array(
|
||||
'message' => __( "Invalid mailbox syntax is used in the %name% field.", 'contact-form-7' ),
|
||||
'params' => array( 'name' => $header_name ),
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->remove_error( $section, 'invalid_mailbox_syntax' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'unsafe_email_without_protection' ) ) {
|
||||
if ( ! empty( $unsafe_email_fields ) ) {
|
||||
$this->add_error( $section, 'unsafe_email_without_protection',
|
||||
array(
|
||||
'message' => __( "Unsafe email config is used without sufficient protection.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'unsafe_email_without_protection' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the mail body section.
|
||||
*/
|
||||
public function validate_mail_body( $template, $content ) {
|
||||
$section = sprintf( '%s.body', $template );
|
||||
|
||||
if ( $this->supports( 'maybe_empty' ) ) {
|
||||
if ( $this->detect_maybe_empty( $section, $content ) ) {
|
||||
$this->add_error( $section, 'maybe_empty',
|
||||
array(
|
||||
'message' => __( "There is a possible empty field.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'maybe_empty' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs error detection for the mail attachments section.
|
||||
*/
|
||||
public function validate_mail_attachments( $template, $content ) {
|
||||
$section = sprintf( '%s.attachments', $template );
|
||||
|
||||
$total_size = 0;
|
||||
$files_not_found = array();
|
||||
$files_out_of_content = array();
|
||||
|
||||
if ( '' !== $content ) {
|
||||
$attachables = array();
|
||||
|
||||
$tags = $this->contact_form->scan_form_tags(
|
||||
array( 'type' => array( 'file', 'file*' ) )
|
||||
);
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$name = $tag->name;
|
||||
|
||||
if ( ! str_contains( $content, "[{$name}]" ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$limit = (int) $tag->get_limit_option();
|
||||
|
||||
if ( empty( $attachables[$name] ) or $attachables[$name] < $limit ) {
|
||||
$attachables[$name] = $limit;
|
||||
}
|
||||
}
|
||||
|
||||
$total_size = array_sum( $attachables );
|
||||
|
||||
foreach ( explode( "\n", $content ) as $line ) {
|
||||
$line = trim( $line );
|
||||
|
||||
if ( '' === $line or str_starts_with( $line, '[' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $this->detect_file_not_found( $section, $line ) ) {
|
||||
$files_not_found[] = $line;
|
||||
} elseif ( $this->detect_file_not_in_content_dir( $section, $line ) ) {
|
||||
$files_out_of_content[] = $line;
|
||||
} else {
|
||||
$total_size += (int) @filesize( $path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'file_not_found' ) ) {
|
||||
if ( ! empty( $files_not_found ) ) {
|
||||
foreach ( $files_not_found as $line ) {
|
||||
$this->add_error( $section, 'file_not_found',
|
||||
array(
|
||||
'message' => __( "Attachment file does not exist at %path%.", 'contact-form-7' ),
|
||||
'params' => array( 'path' => $line ),
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->remove_error( $section, 'file_not_found' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'file_not_in_content_dir' ) ) {
|
||||
if ( ! empty( $files_out_of_content ) ) {
|
||||
$this->add_error( $section, 'file_not_in_content_dir',
|
||||
array(
|
||||
'message' => __( "It is not allowed to use files outside the wp-content directory.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'file_not_in_content_dir' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->supports( 'attachments_overweight' ) ) {
|
||||
$max = 25 * MB_IN_BYTES; // 25 MB
|
||||
|
||||
if ( $max < $total_size ) {
|
||||
$this->add_error( $section, 'attachments_overweight',
|
||||
array(
|
||||
'message' => __( "The total size of attachment files is too large.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'attachments_overweight' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of invalid mailbox syntax.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/invalid-mailbox-syntax/
|
||||
*/
|
||||
public function detect_invalid_mailbox_syntax( $section, $content ) {
|
||||
$content = $this->replace_mail_tags( $content );
|
||||
$content = wpcf7_strip_newline( $content );
|
||||
|
||||
if ( ! wpcf7_is_mailbox_list( $content ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of empty message fields.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/maybe-empty/
|
||||
*/
|
||||
public function detect_maybe_empty( $section, $content ) {
|
||||
$content = $this->replace_mail_tags( $content );
|
||||
$content = wpcf7_strip_newline( $content );
|
||||
|
||||
if ( '' === $content ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of nonexistent attachment files.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/file-not-found/
|
||||
*/
|
||||
public function detect_file_not_found( $section, $content ) {
|
||||
$path = path_join( WP_CONTENT_DIR, $content );
|
||||
|
||||
if ( ! is_readable( $path ) or ! is_file( $path ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of attachment files out of the content directory.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/file-not-in-content-dir/
|
||||
*/
|
||||
public function detect_file_not_in_content_dir( $section, $content ) {
|
||||
$path = path_join( WP_CONTENT_DIR, $content );
|
||||
|
||||
if ( ! wpcf7_is_file_path_in_content_dir( $path ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of that unsafe email config is used without
|
||||
* sufficient protection.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/unsafe-email-without-protection/
|
||||
*/
|
||||
public function detect_unsafe_email_without_protection( $section, $content ) {
|
||||
static $is_recaptcha_active = null;
|
||||
|
||||
if ( null === $is_recaptcha_active ) {
|
||||
$is_recaptcha_active = call_user_func( function () {
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
return $service->is_active();
|
||||
} );
|
||||
}
|
||||
|
||||
if ( $is_recaptcha_active ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$example_email = 'example@example.com';
|
||||
|
||||
// Replace mail-tags connected to an email type form-tag first.
|
||||
$content = $this->replace_mail_tags( $content, array(
|
||||
'callback' => function ( $matches ) use ( $example_email ) {
|
||||
// allow [[foo]] syntax for escaping a tag
|
||||
if ( $matches[1] === '[' and $matches[4] === ']' ) {
|
||||
return substr( $matches[0], 1, -1 );
|
||||
}
|
||||
|
||||
$tag = $matches[0];
|
||||
$tagname = $matches[2];
|
||||
$values = $matches[3];
|
||||
|
||||
$mail_tag = new WPCF7_MailTag( $tag, $tagname, $values );
|
||||
$field_name = $mail_tag->field_name();
|
||||
|
||||
$form_tags = $this->contact_form->scan_form_tags(
|
||||
array( 'name' => $field_name )
|
||||
);
|
||||
|
||||
if ( $form_tags ) {
|
||||
$form_tag = new WPCF7_FormTag( $form_tags[0] );
|
||||
|
||||
if ( 'email' === $form_tag->basetype ) {
|
||||
return $example_email;
|
||||
}
|
||||
}
|
||||
|
||||
return $tag;
|
||||
},
|
||||
) );
|
||||
|
||||
// Replace remaining mail-tags.
|
||||
$content = $this->replace_mail_tags( $content );
|
||||
|
||||
$content = wpcf7_strip_newline( $content );
|
||||
|
||||
if ( str_contains( $content, $example_email ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
trait WPCF7_ConfigValidator_Messages {
|
||||
|
||||
/**
|
||||
* Runs error detection for the messages section.
|
||||
*/
|
||||
public function validate_messages() {
|
||||
$messages = (array) $this->contact_form->prop( 'messages' );
|
||||
|
||||
if ( ! $messages ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
isset( $messages['captcha_not_match'] ) and
|
||||
! wpcf7_use_really_simple_captcha()
|
||||
) {
|
||||
unset( $messages['captcha_not_match'] );
|
||||
}
|
||||
|
||||
foreach ( $messages as $key => $message ) {
|
||||
$section = sprintf( 'messages.%s', $key );
|
||||
|
||||
if ( $this->supports( 'html_in_message' ) ) {
|
||||
if ( $this->detect_html_in_message( $section, $message ) ) {
|
||||
$this->add_error( $section, 'html_in_message',
|
||||
array(
|
||||
'message' => __( "HTML tags are used in a message.", 'contact-form-7' ),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->remove_error( $section, 'html_in_message' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects errors of HTML uses in a message.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/html-in-message/
|
||||
*/
|
||||
public function detect_html_in_message( $section, $content ) {
|
||||
$stripped = wp_strip_all_tags( $content );
|
||||
|
||||
if ( $stripped !== $content ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
|
||||
require_once path_join( __DIR__, 'form.php' );
|
||||
require_once path_join( __DIR__, 'mail.php' );
|
||||
require_once path_join( __DIR__, 'messages.php' );
|
||||
require_once path_join( __DIR__, 'additional-settings.php' );
|
||||
require_once path_join( __DIR__, 'actions.php' );
|
||||
|
||||
|
||||
/**
|
||||
* Configuration validator.
|
||||
*
|
||||
* @link https://contactform7.com/configuration-errors/
|
||||
*/
|
||||
class WPCF7_ConfigValidator {
|
||||
|
||||
/**
|
||||
* The plugin version in which important updates happened last time.
|
||||
*/
|
||||
const last_important_update = '5.8.1';
|
||||
|
||||
const error_codes = array(
|
||||
'maybe_empty',
|
||||
'invalid_mailbox_syntax',
|
||||
'email_not_in_site_domain',
|
||||
'html_in_message',
|
||||
'multiple_controls_in_label',
|
||||
'file_not_found',
|
||||
'unavailable_names',
|
||||
'invalid_mail_header',
|
||||
'deprecated_settings',
|
||||
'file_not_in_content_dir',
|
||||
'unavailable_html_elements',
|
||||
'attachments_overweight',
|
||||
'dots_in_names',
|
||||
'colons_in_names',
|
||||
'upload_filesize_overlimit',
|
||||
'unsafe_email_without_protection',
|
||||
);
|
||||
|
||||
use WPCF7_ConfigValidator_Form;
|
||||
use WPCF7_ConfigValidator_Mail;
|
||||
use WPCF7_ConfigValidator_Messages;
|
||||
use WPCF7_ConfigValidator_AdditionalSettings;
|
||||
|
||||
private $contact_form;
|
||||
private $errors = array();
|
||||
private $include;
|
||||
private $exclude;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a URL linking to the documentation page for the error type.
|
||||
*/
|
||||
public static function get_doc_link( $child_page = '' ) {
|
||||
$url = __( 'https://contactform7.com/configuration-errors/',
|
||||
'contact-form-7'
|
||||
);
|
||||
|
||||
if ( '' !== $child_page ) {
|
||||
$child_page = strtr( $child_page, '_', '-' );
|
||||
|
||||
$url = sprintf( '%s/%s', untrailingslashit( $url ), $child_page );
|
||||
}
|
||||
|
||||
return esc_url( $url );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct( WPCF7_ContactForm $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array(
|
||||
'include' => null,
|
||||
'exclude' => null,
|
||||
) );
|
||||
|
||||
$this->contact_form = $contact_form;
|
||||
|
||||
if ( isset( $args['include'] ) ) {
|
||||
$this->include = (array) $args['include'];
|
||||
}
|
||||
|
||||
if ( isset( $args['exclude'] ) ) {
|
||||
$this->exclude = (array) $args['exclude'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the contact form object that is tied to this validator.
|
||||
*/
|
||||
public function contact_form() {
|
||||
return $this->contact_form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if no error has been detected.
|
||||
*/
|
||||
public function is_valid() {
|
||||
return ! $this->count_errors();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the given error code is supported by this instance.
|
||||
*/
|
||||
public function supports( $error_code ) {
|
||||
if ( isset( $this->include ) ) {
|
||||
$supported_codes = array_intersect( self::error_codes, $this->include );
|
||||
} else {
|
||||
$supported_codes = self::error_codes;
|
||||
}
|
||||
|
||||
if ( isset( $this->exclude ) ) {
|
||||
$supported_codes = array_diff( $supported_codes, $this->exclude );
|
||||
}
|
||||
|
||||
return in_array( $error_code, $supported_codes, true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Counts detected errors.
|
||||
*/
|
||||
public function count_errors( $args = '' ) {
|
||||
$args = wp_parse_args( $args, array(
|
||||
'section' => '',
|
||||
'code' => '',
|
||||
) );
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ( $this->errors as $key => $errors ) {
|
||||
if ( preg_match( '/^mail_[0-9]+\.(.*)$/', $key, $matches ) ) {
|
||||
$key = sprintf( 'mail.%s', $matches[1] );
|
||||
}
|
||||
|
||||
if ( $args['section']
|
||||
and $key !== $args['section']
|
||||
and preg_replace( '/\..*$/', '', $key, 1 ) !== $args['section'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $errors as $error ) {
|
||||
if ( empty( $error ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $args['code'] and $error['code'] !== $args['code'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Collects messages for detected errors.
|
||||
*/
|
||||
public function collect_error_messages() {
|
||||
$error_messages = array();
|
||||
|
||||
foreach ( $this->errors as $section => $errors ) {
|
||||
$error_messages[$section] = array();
|
||||
|
||||
foreach ( $errors as $error ) {
|
||||
if ( empty( $error['args']['message'] ) ) {
|
||||
$message = $this->get_default_message( $error['code'] );
|
||||
} elseif ( empty( $error['args']['params'] ) ) {
|
||||
$message = $error['args']['message'];
|
||||
} else {
|
||||
$message = $this->build_message(
|
||||
$error['args']['message'],
|
||||
$error['args']['params']
|
||||
);
|
||||
}
|
||||
|
||||
$link = '';
|
||||
|
||||
if ( ! empty( $error['args']['link'] ) ) {
|
||||
$link = $error['args']['link'];
|
||||
}
|
||||
|
||||
$error_messages[$section][] = array(
|
||||
'message' => $message,
|
||||
'link' => esc_url( $link ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $error_messages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds an error message by replacing placeholders.
|
||||
*/
|
||||
public function build_message( $message, $params = '' ) {
|
||||
$params = wp_parse_args( $params, array() );
|
||||
|
||||
foreach ( $params as $key => $val ) {
|
||||
if ( ! preg_match( '/^[0-9A-Za-z_]+$/', $key ) ) { // invalid key
|
||||
continue;
|
||||
}
|
||||
|
||||
$placeholder = '%' . $key . '%';
|
||||
|
||||
if ( false !== stripos( $message, $placeholder ) ) {
|
||||
$message = str_ireplace( $placeholder, $val, $message );
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a default message that is used when the message for the error
|
||||
* is not specified.
|
||||
*/
|
||||
public function get_default_message( $code = '' ) {
|
||||
return __( "Configuration error is detected.", 'contact-form-7' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the specified section has the specified error.
|
||||
*
|
||||
* @param string $section The section where the error detected.
|
||||
* @param string $code The unique code of the error.
|
||||
*/
|
||||
public function has_error( $section, $code ) {
|
||||
if ( empty( $this->errors[$section] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( (array) $this->errors[$section] as $error ) {
|
||||
if ( isset( $error['code'] ) and $error['code'] === $code ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a validation error.
|
||||
*
|
||||
* @param string $section The section where the error detected.
|
||||
* @param string $code The unique code of the error.
|
||||
* @param string|array $args Optional options for the error.
|
||||
*/
|
||||
public function add_error( $section, $code, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array(
|
||||
'message' => '',
|
||||
'params' => array(),
|
||||
) );
|
||||
|
||||
$available_error_codes = (array) apply_filters(
|
||||
'wpcf7_config_validator_available_error_codes',
|
||||
self::error_codes,
|
||||
$this->contact_form
|
||||
);
|
||||
|
||||
if ( ! in_array( $code, $available_error_codes, true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! isset( $args['link'] ) ) {
|
||||
$args['link'] = self::get_doc_link( $code );
|
||||
}
|
||||
|
||||
if ( ! isset( $this->errors[$section] ) ) {
|
||||
$this->errors[$section] = array();
|
||||
}
|
||||
|
||||
$this->errors[$section][] = array(
|
||||
'code' => $code,
|
||||
'args' => $args,
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes an error.
|
||||
*
|
||||
* @param string $section The section where the error detected.
|
||||
* @param string $code The unique code of the error.
|
||||
*/
|
||||
public function remove_error( $section, $code ) {
|
||||
if ( empty( $this->errors[$section] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( (array) $this->errors[$section] as $key => $error ) {
|
||||
if ( isset( $error['code'] ) and $error['code'] === $code ) {
|
||||
unset( $this->errors[$section][$key] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $this->errors[$section] ) ) {
|
||||
unset( $this->errors[$section] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The main validation runner.
|
||||
*
|
||||
* @return bool True if there is no error detected.
|
||||
*/
|
||||
public function validate() {
|
||||
$this->validate_form();
|
||||
$this->validate_mail( 'mail' );
|
||||
$this->validate_mail( 'mail_2' );
|
||||
$this->validate_messages();
|
||||
$this->validate_additional_settings();
|
||||
|
||||
do_action( 'wpcf7_config_validator_validate', $this );
|
||||
|
||||
return $this->is_valid();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves detected errors as a post meta data.
|
||||
*/
|
||||
public function save() {
|
||||
if ( $this->contact_form->initial() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete_post_meta( $this->contact_form->id(), '_config_validation' );
|
||||
|
||||
if ( $this->errors ) {
|
||||
update_post_meta(
|
||||
$this->contact_form->id(), '_config_validation', $this->errors
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restore errors from the database.
|
||||
*/
|
||||
public function restore() {
|
||||
$config_errors = get_post_meta(
|
||||
$this->contact_form->id(), '_config_validation', true
|
||||
);
|
||||
|
||||
foreach ( (array) $config_errors as $section => $errors ) {
|
||||
if ( empty( $errors ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( (array) $errors as $error ) {
|
||||
if ( ! empty( $error['code'] ) ) {
|
||||
$code = $error['code'];
|
||||
$args = isset( $error['args'] ) ? $error['args'] : '';
|
||||
$this->add_error( $section, $code, $args );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,6 +33,32 @@ function wpcf7_get_contact_form_by_old_id( $old_id ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches for a contact form by a hash string.
|
||||
*
|
||||
* @param string $hash Part of a hash string.
|
||||
* @return WPCF7_ContactForm Contact form object.
|
||||
*/
|
||||
function wpcf7_get_contact_form_by_hash( $hash ) {
|
||||
global $wpdb;
|
||||
|
||||
$hash = trim( $hash );
|
||||
|
||||
if ( strlen( $hash ) < 7 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$like = $wpdb->esc_like( $hash ) . '%';
|
||||
|
||||
$q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_hash'"
|
||||
. $wpdb->prepare( " AND meta_value LIKE %s", $like );
|
||||
|
||||
if ( $post_id = $wpdb->get_var( $q ) ) {
|
||||
return wpcf7_contact_form( $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches for a contact form by title.
|
||||
*
|
||||
@@ -166,20 +192,22 @@ function wpcf7_get_message( $status ) {
|
||||
*/
|
||||
function wpcf7_form_controls_class( $type, $default_classes = '' ) {
|
||||
$type = trim( $type );
|
||||
$default_classes = array_filter( explode( ' ', $default_classes ) );
|
||||
|
||||
$classes = array_merge( array( 'wpcf7-form-control' ), $default_classes );
|
||||
if ( is_string( $default_classes ) ) {
|
||||
$default_classes = explode( ' ', $default_classes );
|
||||
}
|
||||
|
||||
$typebase = rtrim( $type, '*' );
|
||||
$required = ( '*' == substr( $type, -1 ) );
|
||||
$classes = array(
|
||||
'wpcf7-form-control',
|
||||
sprintf( 'wpcf7-%s', rtrim( $type, '*' ) ),
|
||||
);
|
||||
|
||||
$classes[] = 'wpcf7-' . $typebase;
|
||||
|
||||
if ( $required ) {
|
||||
if ( str_ends_with( $type, '*' ) ) {
|
||||
$classes[] = 'wpcf7-validates-as-required';
|
||||
}
|
||||
|
||||
$classes = array_unique( $classes );
|
||||
$classes = array_merge( $classes, $default_classes );
|
||||
$classes = array_filter( array_unique( $classes ) );
|
||||
|
||||
return implode( ' ', $classes );
|
||||
}
|
||||
@@ -193,10 +221,10 @@ function wpcf7_contact_form_tag_func( $atts, $content = null, $code = '' ) {
|
||||
return '[contact-form-7]';
|
||||
}
|
||||
|
||||
if ( 'contact-form-7' == $code ) {
|
||||
if ( 'contact-form-7' === $code ) {
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'id' => 0,
|
||||
'id' => '',
|
||||
'title' => '',
|
||||
'html_id' => '',
|
||||
'html_name' => '',
|
||||
@@ -207,10 +235,16 @@ function wpcf7_contact_form_tag_func( $atts, $content = null, $code = '' ) {
|
||||
$atts, 'wpcf7'
|
||||
);
|
||||
|
||||
$id = (int) $atts['id'];
|
||||
$id = trim( $atts['id'] );
|
||||
$title = trim( $atts['title'] );
|
||||
|
||||
if ( ! $contact_form = wpcf7_contact_form( $id ) ) {
|
||||
$contact_form = wpcf7_get_contact_form_by_hash( $id );
|
||||
|
||||
if ( ! $contact_form ) {
|
||||
$contact_form = wpcf7_contact_form( $id );
|
||||
}
|
||||
|
||||
if ( ! $contact_form ) {
|
||||
$contact_form = wpcf7_get_contact_form_by_title( $title );
|
||||
}
|
||||
|
||||
@@ -235,11 +269,15 @@ function wpcf7_contact_form_tag_func( $atts, $content = null, $code = '' ) {
|
||||
return $contact_form->form_html( $atts );
|
||||
};
|
||||
|
||||
return wpcf7_switch_locale(
|
||||
$output = wpcf7_switch_locale(
|
||||
$contact_form->locale(),
|
||||
$callback,
|
||||
$contact_form, $atts
|
||||
);
|
||||
|
||||
do_action( 'wpcf7_shortcode_callback', $contact_form, $atts );
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
@@ -415,3 +453,19 @@ function wpcf7_sanitize_additional_settings( $input, $default_template = '' ) {
|
||||
$output = trim( $input );
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a random hash string for a contact form.
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
* @return string SHA-1 hash.
|
||||
*/
|
||||
function wpcf7_generate_contact_form_hash( $post_id ) {
|
||||
return sha1( implode( '|', array(
|
||||
get_current_user_id(),
|
||||
$post_id,
|
||||
time(),
|
||||
home_url(),
|
||||
) ) );
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class WPCF7_ContactFormTemplate {
|
||||
. '-- ' . "\n"
|
||||
. sprintf(
|
||||
/* translators: 1: blog name, 2: blog URL */
|
||||
__( 'This e-mail was sent from a contact form on %1$s (%2$s)', 'contact-form-7' ),
|
||||
__( 'This is a notification that a contact form was submitted on your website (%1$s %2$s).', 'contact-form-7' ),
|
||||
'[_site_title]',
|
||||
'[_site_url]'
|
||||
),
|
||||
@@ -108,7 +108,7 @@ class WPCF7_ContactFormTemplate {
|
||||
. '-- ' . "\n"
|
||||
. sprintf(
|
||||
/* translators: 1: blog name, 2: blog URL */
|
||||
__( 'This e-mail was sent from a contact form on %1$s (%2$s)', 'contact-form-7' ),
|
||||
__( 'This email is a receipt for your contact form submission on our website (%1$s %2$s) in which your email address was used. If that was not you, please ignore this message.', 'contact-form-7' ),
|
||||
'[_site_title]',
|
||||
'[_site_url]'
|
||||
),
|
||||
|
||||
@@ -18,6 +18,7 @@ class WPCF7_ContactForm {
|
||||
private $responses_count = 0;
|
||||
private $scanned_form_tags;
|
||||
private $shortcode_atts = array();
|
||||
private $hash = '';
|
||||
|
||||
|
||||
/**
|
||||
@@ -207,11 +208,12 @@ class WPCF7_ContactForm {
|
||||
$post = get_post( $post );
|
||||
|
||||
if ( $post
|
||||
and self::post_type == get_post_type( $post ) ) {
|
||||
and self::post_type === get_post_type( $post ) ) {
|
||||
$this->id = $post->ID;
|
||||
$this->name = $post->post_name;
|
||||
$this->title = $post->post_title;
|
||||
$this->locale = get_post_meta( $post->ID, '_locale', true );
|
||||
$this->hash = get_post_meta( $post->ID, '_hash', true );
|
||||
|
||||
$this->construct_properties( $post );
|
||||
$this->upgrade();
|
||||
@@ -471,6 +473,17 @@ class WPCF7_ContactForm {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the random hash string tied to this contact form.
|
||||
*
|
||||
* @param int $length Length of hash string.
|
||||
* @return string Hash string unique to this contact form.
|
||||
*/
|
||||
public function hash( $length = 7 ) {
|
||||
return substr( $this->hash, 0, absint( $length ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the specified shortcode attribute value.
|
||||
*
|
||||
@@ -626,9 +639,9 @@ class WPCF7_ContactForm {
|
||||
'data-status' => $data_status_attr,
|
||||
);
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
$atts += (array) apply_filters( 'wpcf7_form_additional_atts', array() );
|
||||
|
||||
$html .= sprintf( '<form %s>', $atts ) . "\n";
|
||||
$html .= sprintf( '<form %s>', wpcf7_format_atts( $atts ) ) . "\n";
|
||||
$html .= $this->form_hidden_fields();
|
||||
$html .= $this->form_elements();
|
||||
|
||||
@@ -1263,6 +1276,11 @@ class WPCF7_ContactForm {
|
||||
update_post_meta( $post_id, '_locale', $this->locale );
|
||||
}
|
||||
|
||||
add_post_meta( $post_id, '_hash',
|
||||
wpcf7_generate_contact_form_hash( $post_id ),
|
||||
true // Unique
|
||||
);
|
||||
|
||||
if ( $this->initial() ) {
|
||||
$this->id = $post_id;
|
||||
do_action( 'wpcf7_after_create', $this );
|
||||
@@ -1333,8 +1351,8 @@ class WPCF7_ContactForm {
|
||||
}
|
||||
} else {
|
||||
$shortcode = sprintf(
|
||||
'[contact-form-7 id="%1$d" title="%2$s"]',
|
||||
$this->id,
|
||||
'[contact-form-7 id="%1$s" title="%2$s"]',
|
||||
$this->hash(),
|
||||
$title
|
||||
);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class WPCF7_FormTag implements ArrayAccess {
|
||||
* Returns true if the type has a trailing asterisk.
|
||||
*/
|
||||
public function is_required() {
|
||||
return ( '*' === substr( $this->type, -1 ) );
|
||||
return str_ends_with( $this->type, '*' );
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,21 @@ class WPCF7_FormTag implements ArrayAccess {
|
||||
* Retrieves the id option value from the form-tag.
|
||||
*/
|
||||
public function get_id_option() {
|
||||
return $this->get_option( 'id', 'id', true );
|
||||
static $used = array();
|
||||
|
||||
$option = $this->get_option( 'id', 'id', true );
|
||||
|
||||
if (
|
||||
! $option or
|
||||
str_starts_with( $option, 'wpcf7' ) or
|
||||
in_array( $option, $used, true )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$used[] = $option;
|
||||
|
||||
return $option;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,9 +148,10 @@ class WPCF7_FormTag implements ArrayAccess {
|
||||
|
||||
$options = array_merge(
|
||||
(array) $default_classes,
|
||||
(array) $this->get_option( 'class', 'class' )
|
||||
(array) $this->get_option( 'class' )
|
||||
);
|
||||
|
||||
$options = array_map( 'sanitize_html_class', $options );
|
||||
$options = array_filter( array_unique( $options ) );
|
||||
|
||||
if ( empty( $options ) ) {
|
||||
@@ -395,7 +410,7 @@ class WPCF7_FormTag implements ArrayAccess {
|
||||
if ( $contact_form = WPCF7_ContactForm::get_current() ) {
|
||||
$val = $contact_form->shortcode_attr( $this->name );
|
||||
|
||||
if ( strlen( $val ) ) {
|
||||
if ( isset( $val ) and strlen( $val ) ) {
|
||||
if ( $args['multiple'] ) {
|
||||
$values[] = $val;
|
||||
} else {
|
||||
|
||||
@@ -522,7 +522,13 @@ function wpcf7_format_atts( $atts ) {
|
||||
}
|
||||
|
||||
static $boolean_attributes = array(
|
||||
'checked', 'disabled', 'multiple', 'readonly', 'required', 'selected',
|
||||
'checked',
|
||||
'disabled',
|
||||
'inert',
|
||||
'multiple',
|
||||
'readonly',
|
||||
'required',
|
||||
'selected',
|
||||
);
|
||||
|
||||
if ( in_array( $name, $boolean_attributes ) and '' === $value ) {
|
||||
|
||||
@@ -210,7 +210,7 @@ function wpcf7_validate_configuration() {
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if wpcf7_autop() is applied to form content.
|
||||
* Returns true if wpcf7_autop() is applied.
|
||||
*/
|
||||
function wpcf7_autop_or_not() {
|
||||
return (bool) apply_filters( 'wpcf7_autop_or_not', WPCF7_AUTOP );
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
<?php
|
||||
|
||||
add_filter( 'wpcf7_mail_html_body', 'wpcf7_mail_html_body_autop', 10, 1 );
|
||||
|
||||
/**
|
||||
* Filter callback that applies auto-p to HTML email message body.
|
||||
*/
|
||||
function wpcf7_mail_html_body_autop( $body ) {
|
||||
if ( wpcf7_autop_or_not() ) {
|
||||
$body = wpcf7_autop( $body );
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class that represents an attempt to compose and send email.
|
||||
*/
|
||||
@@ -142,14 +156,19 @@ class WPCF7_Mail {
|
||||
<title>' . esc_html( $this->get( 'subject', true ) ) . '</title>
|
||||
</head>
|
||||
<body>
|
||||
', $this );
|
||||
',
|
||||
$this
|
||||
);
|
||||
|
||||
$body = apply_filters( 'wpcf7_mail_html_body', $body, $this );
|
||||
|
||||
$footer = apply_filters( 'wpcf7_mail_html_footer',
|
||||
'</body>
|
||||
</html>', $this );
|
||||
</html>',
|
||||
$this
|
||||
);
|
||||
|
||||
$html = $header . wpcf7_autop( $body ) . $footer;
|
||||
return $html;
|
||||
return $header . $body . $footer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -179,6 +179,7 @@ class WPCF7_REST_Controller {
|
||||
foreach ( $items as $item ) {
|
||||
$response[] = array(
|
||||
'id' => $item->id(),
|
||||
'hash' => $item->hash(),
|
||||
'slug' => $item->name(),
|
||||
'title' => $item->title(),
|
||||
'locale' => $item->locale(),
|
||||
|
||||
@@ -32,7 +32,7 @@ function wpcf7_special_mail_tag( $output, $name, $html, $mail_tag = null ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
if ( '_remote_ip' == $name ) {
|
||||
if ( '_remote_ip' === $name ) {
|
||||
if ( $remote_ip = $submission->get_meta( 'remote_ip' ) ) {
|
||||
return $remote_ip;
|
||||
} else {
|
||||
@@ -40,7 +40,7 @@ function wpcf7_special_mail_tag( $output, $name, $html, $mail_tag = null ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( '_user_agent' == $name ) {
|
||||
if ( '_user_agent' === $name ) {
|
||||
if ( $user_agent = $submission->get_meta( 'user_agent' ) ) {
|
||||
return $html ? esc_html( $user_agent ) : $user_agent;
|
||||
} else {
|
||||
@@ -48,7 +48,7 @@ function wpcf7_special_mail_tag( $output, $name, $html, $mail_tag = null ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( '_url' == $name ) {
|
||||
if ( '_url' === $name ) {
|
||||
if ( $url = $submission->get_meta( 'url' ) ) {
|
||||
return $url;
|
||||
} else {
|
||||
@@ -56,14 +56,13 @@ function wpcf7_special_mail_tag( $output, $name, $html, $mail_tag = null ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( '_date' == $name
|
||||
or '_time' == $name ) {
|
||||
if ( '_date' === $name or '_time' === $name ) {
|
||||
if ( $timestamp = $submission->get_meta( 'timestamp' ) ) {
|
||||
if ( '_date' == $name ) {
|
||||
if ( '_date' === $name ) {
|
||||
return wp_date( get_option( 'date_format' ), $timestamp );
|
||||
}
|
||||
|
||||
if ( '_time' == $name ) {
|
||||
if ( '_time' === $name ) {
|
||||
return wp_date( get_option( 'time_format' ), $timestamp );
|
||||
}
|
||||
}
|
||||
@@ -71,7 +70,7 @@ function wpcf7_special_mail_tag( $output, $name, $html, $mail_tag = null ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( '_invalid_fields' == $name ) {
|
||||
if ( '_invalid_fields' === $name ) {
|
||||
return count( $submission->get_invalid_fields() );
|
||||
}
|
||||
|
||||
@@ -99,7 +98,7 @@ function wpcf7_post_related_smt( $output, $name, $html, $mail_tag = null ) {
|
||||
);
|
||||
}
|
||||
|
||||
if ( '_post_' != substr( $name, 0, 6 ) ) {
|
||||
if ( ! str_starts_with( $name, '_post_' ) ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
@@ -111,34 +110,33 @@ function wpcf7_post_related_smt( $output, $name, $html, $mail_tag = null ) {
|
||||
|
||||
$post_id = (int) $submission->get_meta( 'container_post_id' );
|
||||
|
||||
if ( ! $post_id
|
||||
or ! $post = get_post( $post_id ) ) {
|
||||
if ( ! $post_id or ! $post = get_post( $post_id ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( '_post_id' == $name ) {
|
||||
if ( '_post_id' === $name ) {
|
||||
return (string) $post->ID;
|
||||
}
|
||||
|
||||
if ( '_post_name' == $name ) {
|
||||
if ( '_post_name' === $name ) {
|
||||
return $post->post_name;
|
||||
}
|
||||
|
||||
if ( '_post_title' == $name ) {
|
||||
if ( '_post_title' === $name ) {
|
||||
return $html ? esc_html( $post->post_title ) : $post->post_title;
|
||||
}
|
||||
|
||||
if ( '_post_url' == $name ) {
|
||||
if ( '_post_url' === $name ) {
|
||||
return get_permalink( $post->ID );
|
||||
}
|
||||
|
||||
$user = new WP_User( $post->post_author );
|
||||
|
||||
if ( '_post_author' == $name ) {
|
||||
if ( '_post_author' === $name ) {
|
||||
return $user->display_name;
|
||||
}
|
||||
|
||||
if ( '_post_author_email' == $name ) {
|
||||
if ( '_post_author_email' === $name ) {
|
||||
return $user->user_email;
|
||||
}
|
||||
|
||||
@@ -168,7 +166,7 @@ function wpcf7_site_related_smt( $output, $name, $html, $mail_tag = null ) {
|
||||
|
||||
$filter = $html ? 'display' : 'raw';
|
||||
|
||||
if ( '_site_title' == $name ) {
|
||||
if ( '_site_title' === $name ) {
|
||||
$output = get_bloginfo( 'name', $filter );
|
||||
|
||||
if ( ! $html ) {
|
||||
@@ -178,7 +176,7 @@ function wpcf7_site_related_smt( $output, $name, $html, $mail_tag = null ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
if ( '_site_description' == $name ) {
|
||||
if ( '_site_description' === $name ) {
|
||||
$output = get_bloginfo( 'description', $filter );
|
||||
|
||||
if ( ! $html ) {
|
||||
@@ -188,11 +186,11 @@ function wpcf7_site_related_smt( $output, $name, $html, $mail_tag = null ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
if ( '_site_url' == $name ) {
|
||||
if ( '_site_url' === $name ) {
|
||||
return get_bloginfo( 'url', $filter );
|
||||
}
|
||||
|
||||
if ( '_site_admin_email' == $name ) {
|
||||
if ( '_site_admin_email' === $name ) {
|
||||
return get_bloginfo( 'admin_email', $filter );
|
||||
}
|
||||
|
||||
@@ -220,8 +218,7 @@ function wpcf7_user_related_smt( $output, $name, $html, $mail_tag = null ) {
|
||||
);
|
||||
}
|
||||
|
||||
if ( '_user_' != substr( $name, 0, 6 )
|
||||
or '_user_agent' == $name ) {
|
||||
if ( ! str_starts_with( $name, '_user_' ) or '_user_agent' === $name ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -33,7 +33,4 @@ class WPCF7_SWV_DateRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
class WPCF7_SWV_DayofweekRule extends WPCF7_SWV_Rule {
|
||||
|
||||
const rule_name = 'dayofweek';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$field = $this->get_property( 'field' );
|
||||
|
||||
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
|
||||
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
$acceptable_values = (array) $this->get_property( 'accept' );
|
||||
$acceptable_values = array_map( 'intval', $acceptable_values );
|
||||
$acceptable_values = array_filter( $acceptable_values );
|
||||
$acceptable_values = array_unique( $acceptable_values );
|
||||
|
||||
foreach ( $input as $i ) {
|
||||
if ( wpcf7_is_date( $i ) ) {
|
||||
$datetime = date_create_immutable( $i, wp_timezone() );
|
||||
$dow = (int) $datetime->format( 'N' );
|
||||
|
||||
if ( ! in_array( $dow, $acceptable_values, true ) ) {
|
||||
return new WP_Error( 'wpcf7_invalid_dayofweek',
|
||||
$this->get_property( 'error' )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,7 +33,4 @@ class WPCF7_SWV_EmailRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,4 @@ class WPCF7_SWV_EnumRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,4 @@ class WPCF7_SWV_FileRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,4 @@ class WPCF7_SWV_MaxDateRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,4 @@ class WPCF7_SWV_MaxFileSizeRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,4 @@ class WPCF7_SWV_MaxItemsRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,4 @@ class WPCF7_SWV_MaxLengthRule extends WPCF7_SWV_Rule {
|
||||
}
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,4 @@ class WPCF7_SWV_MaxNumberRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,4 @@ class WPCF7_SWV_MinDateRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,4 @@ class WPCF7_SWV_MinFileSizeRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,4 @@ class WPCF7_SWV_MinItemsRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,4 @@ class WPCF7_SWV_MinLengthRule extends WPCF7_SWV_Rule {
|
||||
}
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,4 @@ class WPCF7_SWV_MinNumberRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,4 @@ class WPCF7_SWV_NumberRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,4 @@ class WPCF7_SWV_RequiredRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,4 @@ class WPCF7_SWV_RequiredFileRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,4 @@ class WPCF7_SWV_TelRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class WPCF7_SWV_TimeRule extends WPCF7_SWV_Rule {
|
||||
|
||||
const rule_name = 'time';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$field = $this->get_property( 'field' );
|
||||
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
foreach ( $input as $i ) {
|
||||
if ( ! wpcf7_is_time( $i ) ) {
|
||||
return new WP_Error( 'wpcf7_invalid_time',
|
||||
$this->get_property( 'error' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,7 +33,4 @@ class WPCF7_SWV_URLRule extends WPCF7_SWV_Rule {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array( 'rule' => self::rule_name ) + (array) $this->properties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ function wpcf7_swv_available_rules() {
|
||||
'tel' => 'WPCF7_SWV_TelRule',
|
||||
'number' => 'WPCF7_SWV_NumberRule',
|
||||
'date' => 'WPCF7_SWV_DateRule',
|
||||
'time' => 'WPCF7_SWV_TimeRule',
|
||||
'file' => 'WPCF7_SWV_FileRule',
|
||||
'enum' => 'WPCF7_SWV_EnumRule',
|
||||
'dayofweek' => 'WPCF7_SWV_DayofweekRule',
|
||||
'minitems' => 'WPCF7_SWV_MinItemsRule',
|
||||
'maxitems' => 'WPCF7_SWV_MaxItemsRule',
|
||||
'minlength' => 'WPCF7_SWV_MinLengthRule',
|
||||
@@ -168,7 +170,13 @@ abstract class WPCF7_SWV_Rule {
|
||||
* @return array Array of properties.
|
||||
*/
|
||||
public function to_array() {
|
||||
return (array) $this->properties;
|
||||
$properties = (array) $this->properties;
|
||||
|
||||
if ( defined( 'static::rule_name' ) and static::rule_name ) {
|
||||
$properties = array( 'rule' => static::rule_name ) + $properties;
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +284,7 @@ abstract class WPCF7_SWV_CompositeRule extends WPCF7_SWV_Rule {
|
||||
*/
|
||||
class WPCF7_SWV_Schema extends WPCF7_SWV_CompositeRule {
|
||||
|
||||
const version = 'Contact Form 7 SWV Schema 2022-10';
|
||||
const version = 'Contact Form 7 SWV Schema 2023-07';
|
||||
|
||||
public function __construct( $properties = '' ) {
|
||||
$this->properties = wp_parse_args( $properties, array(
|
||||
|
||||
@@ -1,7 +1,44 @@
|
||||
<?php
|
||||
|
||||
add_action( 'wpcf7_upgrade', 'wpcf7_upgrade_58', 10, 2 );
|
||||
|
||||
/**
|
||||
* Runs functions necessary when upgrading from old plugin versions before 5.8.
|
||||
*
|
||||
* @since 5.8.0 New `_config_validation` post meta is introduced.
|
||||
*/
|
||||
function wpcf7_upgrade_58( $new_ver, $old_ver ) {
|
||||
if ( ! version_compare( $old_ver, '5.8-dev', '<' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$posts = WPCF7_ContactForm::find( array(
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => -1,
|
||||
) );
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
$post_id = $post->id();
|
||||
|
||||
// Delete the old post meta for config-validation results.
|
||||
delete_post_meta( $post_id, '_config_errors' );
|
||||
|
||||
// Add the contact form hash.
|
||||
add_post_meta( $post_id, '_hash',
|
||||
wpcf7_generate_contact_form_hash( $post_id ),
|
||||
true // Unique
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
add_action( 'wpcf7_upgrade', 'wpcf7_convert_to_cpt', 10, 2 );
|
||||
|
||||
/**
|
||||
* Converts old data in the dedicated database table to custom posts.
|
||||
*
|
||||
* @since 3.0.0 `wpcf7_contact_form` CPT is introduced.
|
||||
*/
|
||||
function wpcf7_convert_to_cpt( $new_ver, $old_ver ) {
|
||||
global $wpdb;
|
||||
|
||||
@@ -44,18 +81,29 @@ function wpcf7_convert_to_cpt( $new_ver, $old_ver ) {
|
||||
if ( $post_id ) {
|
||||
update_post_meta( $post_id, '_old_cf7_unit_id', $row->cf7_unit_id );
|
||||
|
||||
$metas = array( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' );
|
||||
$metas = array(
|
||||
'form',
|
||||
'mail',
|
||||
'mail_2',
|
||||
'messages',
|
||||
'additional_settings',
|
||||
);
|
||||
|
||||
foreach ( $metas as $meta ) {
|
||||
update_post_meta( $post_id, '_' . $meta,
|
||||
wpcf7_normalize_newline_deep( maybe_unserialize( $row->{$meta} ) ) );
|
||||
wpcf7_normalize_newline_deep( maybe_unserialize( $row->{$meta} ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
add_action( 'wpcf7_upgrade', 'wpcf7_prepend_underscore', 10, 2 );
|
||||
|
||||
/**
|
||||
* Prepends an underscore to post meta keys.
|
||||
*/
|
||||
function wpcf7_prepend_underscore( $new_ver, $old_ver ) {
|
||||
if ( version_compare( $old_ver, '3.0-dev', '<' ) ) {
|
||||
return;
|
||||
|
||||
@@ -75,7 +75,11 @@ function wpcf7_is_number( $text ) {
|
||||
* @link https://html.spec.whatwg.org/multipage/input.html#date-state-(type=date)
|
||||
*/
|
||||
function wpcf7_is_date( $text ) {
|
||||
$result = preg_match( '/^([0-9]{4,})-([0-9]{2})-([0-9]{2})$/', $text, $matches );
|
||||
$result = preg_match(
|
||||
'/^([0-9]{4,})-([0-9]{2})-([0-9]{2})$/',
|
||||
$text,
|
||||
$matches
|
||||
);
|
||||
|
||||
if ( $result ) {
|
||||
$result = checkdate( $matches[2], $matches[3], $matches[1] );
|
||||
@@ -85,6 +89,32 @@ function wpcf7_is_date( $text ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the given text is a valid time.
|
||||
*
|
||||
* @link https://html.spec.whatwg.org/multipage/input.html#time-state-(type=time)
|
||||
*/
|
||||
function wpcf7_is_time( $text ) {
|
||||
$result = preg_match(
|
||||
'/^([0-9]{2})\:([0-9]{2})(?:\:([0-9]{2}))?$/',
|
||||
$text,
|
||||
$matches
|
||||
);
|
||||
|
||||
if ( $result ) {
|
||||
$hour = (int) $matches[1];
|
||||
$minute = (int) $matches[2];
|
||||
$second = empty( $matches[3] ) ? 0 : (int) $matches[3];
|
||||
|
||||
$result = 0 <= $hour && $hour <= 23 &&
|
||||
0 <= $minute && $minute <= 59 &&
|
||||
0 <= $second && $second <= 59;
|
||||
}
|
||||
|
||||
return apply_filters( 'wpcf7_is_time', $result, $text );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the given text is a well-formed mailbox list.
|
||||
*
|
||||
@@ -229,12 +259,23 @@ function wpcf7_is_file_path_in_content_dir( $path ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 0 === strpos( $path, realpath( WP_CONTENT_DIR ) ) ) {
|
||||
if (
|
||||
str_starts_with( $path, trailingslashit( realpath( WP_CONTENT_DIR ) ) )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( defined( 'UPLOADS' )
|
||||
and 0 === strpos( $path, realpath( ABSPATH . UPLOADS ) ) ) {
|
||||
if (
|
||||
defined( 'UPLOADS' ) and
|
||||
str_starts_with( $path, trailingslashit( realpath( ABSPATH . UPLOADS ) ) )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
defined( 'WP_TEMP_DIR' ) and
|
||||
str_starts_with( $path, trailingslashit( realpath( WP_TEMP_DIR ) ) )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user