Plugin Updates

This commit is contained in:
Tony Volpe
2024-03-19 15:33:31 +00:00
parent ff5b56dc44
commit 3a70a6e4bf
317 changed files with 8178 additions and 2933 deletions

View File

@@ -130,7 +130,8 @@ function wpcf7_admin_enqueue_scripts( $hook_suffix ) {
wp_enqueue_script( 'wpcf7-admin',
wpcf7_plugin_url( 'admin/js/scripts.js' ),
array( 'jquery', 'jquery-ui-tabs' ),
WPCF7_VERSION, true
WPCF7_VERSION,
array( 'in_footer' => true )
);
$args = array(
@@ -144,8 +145,7 @@ function wpcf7_admin_enqueue_scripts( $hook_suffix ) {
'saveAlert' => __(
"The changes you made will be lost if you navigate away from this page.",
'contact-form-7' ),
'activeTab' => isset( $_GET['active-tab'] )
? (int) $_GET['active-tab'] : 0,
'activeTab' => (int) ( $_GET['active-tab'] ?? 0 ),
'configValidator' => array(
'errors' => array(),
'howToCorrect' => __( "How to resolve?", 'contact-form-7' ),
@@ -176,7 +176,7 @@ function wpcf7_admin_enqueue_scripts( $hook_suffix ) {
wpcf7_plugin_url( 'admin/js/tag-generator.js' ),
array( 'jquery', 'thickbox', 'wpcf7-admin' ),
WPCF7_VERSION,
true
array( 'in_footer' => true )
);
}
@@ -204,12 +204,13 @@ function wpcf7_load_contact_form_admin() {
$action = wpcf7_current_action();
do_action( 'wpcf7_admin_load',
isset( $_GET['page'] ) ? trim( $_GET['page'] ) : '',
trim( $_GET['page'] ?? '' ),
$action
);
if ( 'save' == $action ) {
$id = isset( $_POST['post_ID'] ) ? $_POST['post_ID'] : '-1';
if ( 'save' === $action ) {
$id = $_POST['post_ID'] ?? '-1';
check_admin_referer( 'wpcf7-save-contact-form_' . $id );
if ( ! current_user_can( 'wpcf7_edit_contact_form', $id ) ) {
@@ -218,31 +219,21 @@ function wpcf7_load_contact_form_admin() {
);
}
$args = $_REQUEST;
$args['id'] = $id;
$args['title'] = isset( $_POST['post_title'] )
? $_POST['post_title'] : null;
$args['locale'] = isset( $_POST['wpcf7-locale'] )
? $_POST['wpcf7-locale'] : null;
$args['form'] = isset( $_POST['wpcf7-form'] )
? $_POST['wpcf7-form'] : '';
$args['mail'] = isset( $_POST['wpcf7-mail'] )
? $_POST['wpcf7-mail'] : array();
$args['mail_2'] = isset( $_POST['wpcf7-mail-2'] )
? $_POST['wpcf7-mail-2'] : array();
$args['messages'] = isset( $_POST['wpcf7-messages'] )
? $_POST['wpcf7-messages'] : array();
$args['additional_settings'] = isset( $_POST['wpcf7-additional-settings'] )
? $_POST['wpcf7-additional-settings'] : '';
$contact_form = wpcf7_save_contact_form( $args );
$contact_form = wpcf7_save_contact_form(
array_merge(
$_REQUEST,
array(
'id' => $id,
'title' => $_POST['post_title'] ?? null,
'locale' => $_POST['wpcf7-locale'] ?? null,
'form' => $_POST['wpcf7-form'] ?? '',
'mail' => $_POST['wpcf7-mail'] ?? array(),
'mail_2' => $_POST['wpcf7-mail-2'] ?? array(),
'messages' => $_POST['wpcf7-messages'] ?? array(),
'additional_settings' => $_POST['wpcf7-additional-settings'] ?? '',
)
)
);
if ( $contact_form and wpcf7_validate_configuration() ) {
$config_validator = new WPCF7_ConfigValidator( $contact_form );
@@ -252,8 +243,7 @@ function wpcf7_load_contact_form_admin() {
$query = array(
'post' => $contact_form ? $contact_form->id() : 0,
'active-tab' => isset( $_POST['active-tab'] )
? (int) $_POST['active-tab'] : 0,
'active-tab' => (int) ( $_POST['active-tab'] ?? 0 ),
);
if ( ! $contact_form ) {
@@ -269,10 +259,8 @@ function wpcf7_load_contact_form_admin() {
exit();
}
if ( 'copy' == $action ) {
$id = empty( $_POST['post_ID'] )
? absint( $_REQUEST['post'] )
: absint( $_POST['post_ID'] );
if ( 'copy' === $action ) {
$id = absint( $_POST['post_ID'] ?? $_REQUEST['post'] ?? '' );
check_admin_referer( 'wpcf7-copy-contact-form_' . $id );
@@ -298,7 +286,7 @@ function wpcf7_load_contact_form_admin() {
exit();
}
if ( 'delete' == $action ) {
if ( 'delete' === $action ) {
if ( ! empty( $_POST['post_ID'] ) ) {
check_admin_referer( 'wpcf7-delete-contact-form_' . $_POST['post_ID'] );
} elseif ( ! is_array( $_REQUEST['post'] ) ) {
@@ -307,9 +295,7 @@ function wpcf7_load_contact_form_admin() {
check_admin_referer( 'bulk-posts' );
}
$posts = empty( $_POST['post_ID'] )
? (array) $_REQUEST['post']
: (array) $_POST['post_ID'];
$posts = (array) ( $_POST['post_ID'] ?? $_REQUEST['post'] ?? array() );
$deleted = 0;
@@ -347,9 +333,9 @@ function wpcf7_load_contact_form_admin() {
$post = null;
if ( 'wpcf7-new' == $plugin_page ) {
if ( 'wpcf7-new' === $plugin_page ) {
$post = WPCF7_ContactForm::get_template( array(
'locale' => isset( $_GET['locale'] ) ? $_GET['locale'] : null,
'locale' => $_GET['locale'] ?? null,
) );
} elseif ( ! empty( $_GET['post'] ) ) {
$post = WPCF7_ContactForm::get_instance( $_GET['post'] );
@@ -470,7 +456,7 @@ function wpcf7_admin_add_new_page() {
function wpcf7_load_integration_page() {
do_action( 'wpcf7_admin_load',
isset( $_GET['page'] ) ? trim( $_GET['page'] ) : '',
trim( $_GET['page'] ?? '' ),
wpcf7_current_action()
);
@@ -520,7 +506,7 @@ function wpcf7_admin_integration_page() {
);
if ( $service ) {
$message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : '';
$message = $_REQUEST['message'] ?? '';
$service->admin_notice( $message );
$integration->list_services( array(
@@ -547,11 +533,11 @@ function wpcf7_admin_updated_message( $page, $action, $object ) {
return;
}
if ( 'created' == $_REQUEST['message'] ) {
if ( 'created' === $_REQUEST['message'] ) {
$updated_message = __( "Contact form created.", 'contact-form-7' );
} elseif ( 'saved' == $_REQUEST['message'] ) {
} elseif ( 'saved' === $_REQUEST['message'] ) {
$updated_message = __( "Contact form saved.", 'contact-form-7' );
} elseif ( 'deleted' == $_REQUEST['message'] ) {
} elseif ( 'deleted' === $_REQUEST['message'] ) {
$updated_message = __( "Contact form deleted.", 'contact-form-7' );
}
@@ -564,7 +550,7 @@ function wpcf7_admin_updated_message( $page, $action, $object ) {
return;
}
if ( 'failed' == $_REQUEST['message'] ) {
if ( 'failed' === $_REQUEST['message'] ) {
$updated_message =
__( "There was an error saving the contact form.", 'contact-form-7' );
@@ -576,7 +562,7 @@ function wpcf7_admin_updated_message( $page, $action, $object ) {
return;
}
if ( 'validated' == $_REQUEST['message'] ) {
if ( 'validated' === $_REQUEST['message'] ) {
$bulk_validate = WPCF7::get_option( 'bulk_validate', array() );
$count_invalid = isset( $bulk_validate['count_invalid'] )
? absint( $bulk_validate['count_invalid'] ) : 0;
@@ -693,3 +679,21 @@ function wpcf7_outdated_php_warning( $page, $action, $object ) {
esc_html( $message )
);
}
add_action( 'wpcf7_admin_warnings', 'wpcf7_ctct_deprecated_warning', 10, 3 );
function wpcf7_ctct_deprecated_warning( $page, $action, $object ) {
$service = WPCF7_ConstantContact::get_instance();
if ( ! $service->is_active() ) {
return;
}
$message = __( "The Constant Contact integration is deprecated. It is not recommended to continue using the feature.", 'contact-form-7' );
echo sprintf(
'<div class="notice notice-warning"><p>%s</p></div>',
esc_html( $message )
);
}

View File

@@ -85,7 +85,7 @@ if ( $post ) :
<input type="hidden" id="post_ID" name="post_ID" value="<?php echo (int) $post_id; ?>" />
<input type="hidden" id="wpcf7-locale" name="wpcf7-locale" value="<?php echo esc_attr( $post->locale() ); ?>" />
<input type="hidden" id="hiddenaction" name="action" value="save" />
<input type="hidden" id="active-tab" name="active-tab" value="<?php echo isset( $_GET['active-tab'] ) ? (int) $_GET['active-tab'] : '0'; ?>" />
<input type="hidden" id="active-tab" name="active-tab" value="<?php echo (int) ( $_GET['active-tab'] ?? '0' ); ?>" />
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">

View File

@@ -146,15 +146,11 @@ class WPCF7_WelcomePanelColumn_Integration extends WPCF7_WelcomePanelColumn {
protected function content() {
return array(
sprintf(
/* translators: 1: link labeled 'Brevo', 2: link labeled 'Constant Contact' */
esc_html( __( 'Your contact forms will become more powerful and versatile by integrating them with external APIs. With CRM and email marketing services, you can build your own contact lists (%1$s and %2$s).', 'contact-form-7' ) ),
/* translators: 1: link labeled 'Brevo' */
esc_html( __( 'Your contact forms will become more powerful and versatile by integrating them with external APIs. With CRM and email marketing services, you can build your own contact lists (%1$s).', 'contact-form-7' ) ),
wpcf7_link(
__( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ),
__( 'Brevo', 'contact-form-7' )
),
wpcf7_link(
__( 'https://contactform7.com/constant-contact-integration/', 'contact-form-7' ),
__( 'Constant Contact', 'contact-form-7' )
)
),
sprintf(

View File

@@ -1,6 +1,6 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"apiVersion": 3,
"name": "contact-form-7/contact-form-selector",
"title": "Contact Form 7",
"category": "widgets",

File diff suppressed because one or more lines are too long

View File

@@ -39,74 +39,49 @@ trait WPCF7_ConfigValidator_Mail {
$example_text = 'example';
$example_blank = '';
$form_tags = $this->contact_form->scan_form_tags(
array( 'name' => $field_name )
);
// for back-compat
$field_name = preg_replace( '/^wpcf7\./', '_', $field_name );
if ( $form_tags ) {
$form_tag = new WPCF7_FormTag( $form_tags[0] );
if ( '_site_admin_email' === $field_name ) {
return get_bloginfo( 'admin_email', 'raw' );
$is_required = $form_tag->is_required() || 'radio' === $form_tag->type;
} elseif ( '_user_agent' === $field_name ) {
return $example_text;
if ( ! $is_required ) {
return $example_blank;
}
} elseif ( '_user_email' === $field_name ) {
return $this->contact_form->is_true( 'subscribers_only' )
? $example_email
: $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 );
}
} elseif ( str_starts_with( $field_name, '_user_' ) ) {
return $this->contact_form->is_true( 'subscribers_only' )
? $example_text
: $example_blank;
if ( $last_item and wpcf7_is_mailbox_list( $last_item ) ) {
return $example_email;
} else {
return $example_text;
}
}
} elseif ( str_starts_with( $field_name, '_' ) ) {
return str_ends_with( $field_name, '_email' )
? $example_email
: $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;
static $opcalcset = array();
if ( ! isset( $opcalcset[$this->contact_form->id()] ) ) {
$opcalcset[$this->contact_form->id()] =
new WPCF7_MailTag_OutputCalculator( $this->contact_form );
}
$opcalc = $opcalcset[$this->contact_form->id()];
$op = $opcalc->calc_output( $mail_tag );
if ( WPCF7_MailTag_OutputCalculator::email === $op ) {
return $example_email;
} elseif ( ! ( WPCF7_MailTag_OutputCalculator::blank & $op ) ) {
return $example_text;
} else {
return $example_blank;
}
}

View File

@@ -3,6 +3,7 @@
class WPCF7_ContactForm {
use WPCF7_SWV_SchemaHolder;
use WPCF7_PipesHolder;
const post_type = 'wpcf7_contact_form';

View File

@@ -54,7 +54,7 @@ add_action(
array( 'swv' )
),
$assets['version'],
true
array( 'in_footer' => true )
);
wp_register_script(
@@ -62,7 +62,7 @@ add_action(
wpcf7_plugin_url( 'includes/js/html5-fallback.js' ),
array( 'jquery-ui-datepicker' ),
WPCF7_VERSION,
true
array( 'in_footer' => true )
);
if ( wpcf7_load_js() ) {

View File

@@ -34,13 +34,15 @@ function wpcf7_unship_uploaded_file( $file, $args = '' ) {
}
if ( isset( $args['schema'] ) and isset( $args['name'] ) ) {
$result = $args['schema']->validate( array(
$context = array(
'file' => true,
'field' => $args['name'],
) );
);
if ( is_wp_error( $result ) ) {
return $result;
foreach ( $args['schema']->validate( $context ) as $result ) {
if ( is_wp_error( $result ) ) {
return $result;
}
}
}

View File

@@ -141,6 +141,8 @@ class WPCF7_Integration {
<h2 class="title"><?php echo esc_html( $service->get_title() ); ?></h2>
<div class="infobox">
<?php echo esc_html( implode( ', ', $cats ) ); ?>
<br />
<?php $service->link(); ?>
</div>
<br class="clear" />
@@ -247,8 +249,8 @@ class WPCF7_Service_OAuth2 extends WPCF7_Service {
public function load( $action = '' ) {
if ( 'auth_redirect' == $action ) {
$code = isset( $_GET['code'] ) ? $_GET['code'] : '';
if ( 'auth_redirect' === $action ) {
$code = $_GET['code'] ?? '';
if ( $code ) {
$this->request_token( $code );

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,197 @@
<?php
/**
* Class that represents a mail-tag.
*/
class WPCF7_MailTag {
private $tag;
private $tagname = '';
private $name = '';
private $options = array();
private $values = array();
private $form_tag = null;
/**
* The constructor method.
*/
public function __construct( $tag, $tagname, $values ) {
$this->tag = $tag;
$this->name = $this->tagname = $tagname;
$this->options = array(
'do_not_heat' => false,
'format' => '',
);
if ( ! empty( $values ) ) {
preg_match_all( '/"[^"]*"|\'[^\']*\'/', $values, $matches );
$this->values = wpcf7_strip_quote_deep( $matches[0] );
}
if ( preg_match( '/^_raw_(.+)$/', $tagname, $matches ) ) {
$this->name = trim( $matches[1] );
$this->options['do_not_heat'] = true;
}
if ( preg_match( '/^_format_(.+)$/', $tagname, $matches ) ) {
$this->name = trim( $matches[1] );
$this->options['format'] = $this->values[0];
}
}
/**
* Returns the name part of this mail-tag.
*/
public function tag_name() {
return $this->tagname;
}
/**
* Returns the form field name corresponding to this mail-tag.
*/
public function field_name() {
return strtr( $this->name, '.', '_' );
}
/**
* Returns the value of the specified option.
*/
public function get_option( $option ) {
return $this->options[$option];
}
/**
* Returns the values part of this mail-tag.
*/
public function values() {
return $this->values;
}
/**
* Retrieves the WPCF7_FormTag object that corresponds to this mail-tag.
*/
public function corresponding_form_tag() {
if ( $this->form_tag instanceof WPCF7_FormTag ) {
return $this->form_tag;
}
if ( $submission = WPCF7_Submission::get_instance() ) {
$contact_form = $submission->get_contact_form();
$tags = $contact_form->scan_form_tags( array(
'name' => $this->field_name(),
'feature' => '! zero-controls-container',
) );
if ( $tags ) {
$this->form_tag = $tags[0];
}
}
return $this->form_tag;
}
}
use Contactable\SWV;
/**
* Mail-tag output calculator.
*/
class WPCF7_MailTag_OutputCalculator {
const email = 0b100;
const text = 0b010;
const blank = 0b001;
private $contact_form;
public function __construct( WPCF7_ContactForm $contact_form ) {
$this->contact_form = $contact_form;
}
public function calc_output( WPCF7_MailTag $mail_tag ) {
return $this->calc_swv_result(
$mail_tag,
$this->contact_form->get_schema()
);
}
private function calc_swv_result( WPCF7_MailTag $mail_tag, SWV\Rule $rule ) {
if ( $rule instanceof SWV\AnyRule ) {
$result = 0b000;
foreach ( $rule->rules() as $child_rule ) {
$result |= $this->calc_swv_result( $mail_tag, $child_rule );
}
return $result;
}
if ( $rule instanceof SWV\CompositeRule ) {
$result = 0b111;
foreach ( $rule->rules() as $child_rule ) {
$result &= $this->calc_swv_result( $mail_tag, $child_rule );
}
return $result;
}
$field_prop = $rule->get_property( 'field' );
if ( empty( $field_prop ) or $field_prop !== $mail_tag->field_name() ) {
return self::email | self::text | self::blank;
}
if ( $rule instanceof SWV\RequiredRule ) {
return ~ self::blank;
}
if ( $rule instanceof SWV\EmailRule ) {
return self::email | self::blank;
}
if ( $rule instanceof SWV\EnumRule ) {
$acceptable_values = (array) $rule->get_property( 'accept' );
$acceptable_values = array_map( 'strval', $acceptable_values );
$acceptable_values = array_filter( $acceptable_values );
$acceptable_values = array_unique( $acceptable_values );
if ( ! $mail_tag->get_option( 'do_not_heat' ) ) {
$pipes = $this->contact_form->get_pipes(
$mail_tag->field_name()
);
$acceptable_values = array_map(
static function ( $val ) use ( $pipes ) {
return $pipes->do_pipe( $val );
},
$acceptable_values
);
}
$email_values = array_filter(
$acceptable_values,
'wpcf7_is_mailbox_list'
);
if ( count( $email_values ) === count( $acceptable_values ) ) {
return self::email | self::blank;
} else {
return self::email | self::text | self::blank;
}
}
return self::email | self::text | self::blank;
}
}

View File

@@ -24,6 +24,7 @@ class WPCF7_Mail {
private $name = '';
private $locale = '';
private $template = array();
private $component = '';
private $use_html = false;
private $exclude_blank = false;
@@ -36,6 +37,35 @@ class WPCF7_Mail {
}
/**
* Returns the name of the email template currently processed.
*
* Expected output: 'mail' or 'mail_2'
*/
public static function get_current_template_name() {
$current = self::get_current();
if ( $current instanceof self ) {
return $current->get_template_name();
}
}
/**
* Returns the name of the email template component currently processed.
*
* Expected output: 'recipient', 'sender', 'subject',
* 'additional_headers', 'body', or 'attachments'
*/
public static function get_current_component_name() {
$current = self::get_current();
if ( $current instanceof self ) {
return $current->get_component_name();
}
}
/**
* Composes and sends email based on the specified template.
*
@@ -86,6 +116,22 @@ class WPCF7_Mail {
}
/**
* Returns the name of the email template. A wrapper method of name().
*/
public function get_template_name() {
return $this->name();
}
/**
* Returns the name of the email template component currently processed.
*/
public function get_component_name() {
return $this->component;
}
/**
* Retrieves a component from the email template.
*
@@ -95,8 +141,10 @@ class WPCF7_Mail {
* @return string The text representation of the email component.
*/
public function get( $component, $replace_tags = false ) {
$use_html = ( $this->use_html && 'body' == $component );
$exclude_blank = ( $this->exclude_blank && 'body' == $component );
$this->component = $component;
$use_html = ( $this->use_html && 'body' === $component );
$exclude_blank = ( $this->exclude_blank && 'body' === $component );
$template = $this->template;
$component = isset( $template[$component] ) ? $template[$component] : '';
@@ -127,6 +175,8 @@ class WPCF7_Mail {
}
}
$this->component = '';
return $component;
}
@@ -502,9 +552,7 @@ class WPCF7_MailTaggedText {
: null;
if ( $mail_tag->get_option( 'do_not_heat' ) ) {
$submitted = isset( $_POST[$field_name] )
? wp_unslash( $_POST[$field_name] )
: '';
$submitted = wp_unslash( $_POST[$field_name] ?? '' );
}
$replaced = $submitted;
@@ -514,8 +562,12 @@ class WPCF7_MailTaggedText {
$replaced = $this->format( $replaced, $format );
}
$separator = ( 'body' === WPCF7_Mail::get_current_component_name() )
? wp_get_list_item_separator()
: ', ';
$replaced = wpcf7_flat_join( $replaced, array(
'separator' => wp_get_list_item_separator(),
'separator' => $separator,
) );
if ( $html ) {
@@ -578,103 +630,3 @@ class WPCF7_MailTaggedText {
}
}
/**
* Class that represents a mail-tag.
*/
class WPCF7_MailTag {
private $tag;
private $tagname = '';
private $name = '';
private $options = array();
private $values = array();
private $form_tag = null;
/**
* The constructor method.
*/
public function __construct( $tag, $tagname, $values ) {
$this->tag = $tag;
$this->name = $this->tagname = $tagname;
$this->options = array(
'do_not_heat' => false,
'format' => '',
);
if ( ! empty( $values ) ) {
preg_match_all( '/"[^"]*"|\'[^\']*\'/', $values, $matches );
$this->values = wpcf7_strip_quote_deep( $matches[0] );
}
if ( preg_match( '/^_raw_(.+)$/', $tagname, $matches ) ) {
$this->name = trim( $matches[1] );
$this->options['do_not_heat'] = true;
}
if ( preg_match( '/^_format_(.+)$/', $tagname, $matches ) ) {
$this->name = trim( $matches[1] );
$this->options['format'] = $this->values[0];
}
}
/**
* Returns the name part of this mail-tag.
*/
public function tag_name() {
return $this->tagname;
}
/**
* Returns the form field name corresponding to this mail-tag.
*/
public function field_name() {
return strtr( $this->name, '.', '_' );
}
/**
* Returns the value of the specified option.
*/
public function get_option( $option ) {
return $this->options[$option];
}
/**
* Returns the values part of this mail-tag.
*/
public function values() {
return $this->values;
}
/**
* Retrieves the WPCF7_FormTag object that corresponds to this mail-tag.
*/
public function corresponding_form_tag() {
if ( $this->form_tag instanceof WPCF7_FormTag ) {
return $this->form_tag;
}
if ( $submission = WPCF7_Submission::get_instance() ) {
$contact_form = $submission->get_contact_form();
$tags = $contact_form->scan_form_tags( array(
'name' => $this->field_name(),
'feature' => '! zero-controls-container',
) );
if ( $tags ) {
$this->form_tag = $tags[0];
}
}
return $this->form_tag;
}
}

View File

@@ -36,8 +36,8 @@ class WPCF7_Pipes {
private $pipes = array();
public function __construct( array $texts ) {
foreach ( $texts as $text ) {
public function __construct( array $texts = null ) {
foreach ( (array) $texts as $text ) {
$this->add_pipe( $text );
}
}
@@ -47,6 +47,10 @@ class WPCF7_Pipes {
$this->pipes[] = $pipe;
}
public function merge( self $another ) {
$this->pipes = array_merge( $this->pipes, $another->pipes );
}
public function do_pipe( $input ) {
$input_canonical = wpcf7_canonicalize( $input, array(
'strto' => 'as-is',
@@ -109,3 +113,37 @@ class WPCF7_Pipes {
);
}
}
/**
* Trait for classes that hold cross-tag WPCF7_Pipes object.
*/
trait WPCF7_PipesHolder {
protected $pipes;
public function get_pipes( $field_name ) {
if ( isset( $this->pipes[$field_name] ) ) {
return $this->pipes[$field_name];
}
$result = new WPCF7_Pipes;
$tags = $this->scan_form_tags( array(
'name' => $field_name,
) );
foreach ( $tags as $tag ) {
if ( $tag->pipes instanceof WPCF7_Pipes ) {
$result->merge( $tag->pipes );
}
}
return $this->pipes[$field_name] = $result;
}
public function scan_form_tags() {
return array();
}
}

View File

@@ -259,11 +259,7 @@ class WPCF7_Submission {
* or false when no invalid field.
*/
public function get_invalid_field( $name ) {
if ( isset( $this->invalid_fields[$name] ) ) {
return $this->invalid_fields[$name];
} else {
return false;
}
return $this->invalid_fields[$name] ?? false;
}
@@ -285,9 +281,7 @@ class WPCF7_Submission {
* null otherwise.
*/
public function get_meta( $name ) {
if ( isset( $this->meta[$name] ) ) {
return $this->meta[$name];
}
return $this->meta[$name] ?? null;
}
@@ -295,38 +289,16 @@ class WPCF7_Submission {
* Collects meta information about this submission.
*/
private function setup_meta_data() {
$timestamp = time();
$remote_ip = $this->get_remote_ip_addr();
$remote_port = isset( $_SERVER['REMOTE_PORT'] )
? (int) $_SERVER['REMOTE_PORT'] : '';
$user_agent = isset( $_SERVER['HTTP_USER_AGENT'] )
? substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 ) : '';
$url = $this->get_request_url();
$unit_tag = isset( $_POST['_wpcf7_unit_tag'] )
? wpcf7_sanitize_unit_tag( $_POST['_wpcf7_unit_tag'] ) : '';
$container_post_id = isset( $_POST['_wpcf7_container_post'] )
? (int) $_POST['_wpcf7_container_post'] : 0;
$current_user_id = get_current_user_id();
$do_not_store = $this->contact_form->is_true( 'do_not_store' );
$this->meta = array(
'timestamp' => $timestamp,
'remote_ip' => $remote_ip,
'remote_port' => $remote_port,
'user_agent' => $user_agent,
'url' => $url,
'unit_tag' => $unit_tag,
'container_post_id' => $container_post_id,
'current_user_id' => $current_user_id,
'do_not_store' => $do_not_store,
'timestamp' => time(),
'remote_ip' => $this->get_remote_ip_addr(),
'remote_port' => $_SERVER['REMOTE_PORT'] ?? '',
'user_agent' => substr( $_SERVER['HTTP_USER_AGENT'] ?? '', 0, 254 ),
'url' => $this->get_request_url(),
'unit_tag' => wpcf7_sanitize_unit_tag( $_POST['_wpcf7_unit_tag'] ?? '' ),
'container_post_id' => absint( $_POST['_wpcf7_container_post'] ?? 0 ),
'current_user_id' => get_current_user_id(),
'do_not_store' => $this->contact_form->is_true( 'do_not_store' ),
);
return $this->meta;
@@ -342,11 +314,7 @@ class WPCF7_Submission {
*/
public function get_posted_data( $name = '' ) {
if ( ! empty( $name ) ) {
if ( isset( $this->posted_data[$name] ) ) {
return $this->posted_data[$name];
} else {
return null;
}
return $this->posted_data[$name] ?? null;
}
return $this->posted_data;
@@ -377,86 +345,56 @@ class WPCF7_Submission {
* Constructs posted data property based on user input values.
*/
private function setup_posted_data() {
$posted_data = array_filter( (array) $_POST, static function ( $key ) {
return '_' !== substr( $key, 0, 1 );
}, ARRAY_FILTER_USE_KEY );
$posted_data = array_filter(
(array) $_POST,
static function ( $key ) {
return ! str_starts_with( $key, '_' );
},
ARRAY_FILTER_USE_KEY
);
$posted_data = wp_unslash( $posted_data );
$posted_data = $this->sanitize_posted_data( $posted_data );
$tags = $this->contact_form->scan_form_tags();
$tags = $this->contact_form->scan_form_tags( array(
'feature' => array(
'name-attr',
'! not-for-mail',
),
) );
foreach ( (array) $tags as $tag ) {
if ( empty( $tag->name ) ) {
continue;
$tags = array_reduce( $tags, static function ( $carry, $tag ) {
if ( $tag->name and ! isset( $carry[$tag->name] ) ) {
$carry[$tag->name] = $tag;
}
$type = $tag->type;
$name = $tag->name;
$pipes = $tag->pipes;
return $carry;
}, array() );
$value_orig = $value = '';
foreach ( $tags as $tag ) {
$value_orig = $value = $posted_data[$tag->name] ?? '';
if ( isset( $posted_data[$name] ) ) {
$value_orig = $value = $posted_data[$name];
}
if ( WPCF7_USE_PIPE
and $pipes instanceof WPCF7_Pipes
and ! $pipes->zero() ) {
if ( is_array( $value_orig ) ) {
$value = array();
foreach ( $value_orig as $v ) {
$value[] = $pipes->do_pipe( $v );
}
} else {
$value = $pipes->do_pipe( $value_orig );
}
}
if ( wpcf7_form_tag_supports( $type, 'selectable-values' ) ) {
if ( wpcf7_form_tag_supports( $tag->type, 'selectable-values' ) ) {
$value = (array) $value;
if ( $tag->has_option( 'free_text' )
and isset( $posted_data[$name . '_free_text'] ) ) {
$last_val = array_pop( $value );
if ( WPCF7_USE_PIPE ) {
$pipes = $this->contact_form->get_pipes( $tag->name );
list( $tied_item ) = array_slice(
WPCF7_USE_PIPE ? $tag->pipes->collect_afters() : $tag->values,
-1, 1
);
list( $last_val, $tied_item ) = array_map(
static function ( $item ) {
return wpcf7_canonicalize( $item, array(
'strto' => 'as-is',
) );
},
array( $last_val, $tied_item )
);
if ( $last_val === $tied_item ) {
$value[] = sprintf( '%s %s',
$last_val,
$posted_data[$name . '_free_text']
);
} else {
$value[] = $last_val;
}
unset( $posted_data[$name . '_free_text'] );
$value = array_map( static function ( $value ) use ( $pipes ) {
return $pipes->do_pipe( $value );
}, $value );
}
}
$value = apply_filters( "wpcf7_posted_data_{$type}", $value,
$value_orig, $tag
$value = apply_filters( "wpcf7_posted_data_{$tag->type}",
$value,
$value_orig,
$tag
);
$posted_data[$name] = $value;
$posted_data[$tag->name] = $value;
if ( $tag->has_option( 'consent_for:storage' )
and empty( $posted_data[$name] ) ) {
if ( $tag->has_option( 'consent_for:storage' ) and empty( $value ) ) {
$this->meta['do_not_store'] = true;
}
}
@@ -595,8 +533,7 @@ class WPCF7_Submission {
$home_url = untrailingslashit( home_url() );
if ( self::is_restful() ) {
$referer = isset( $_SERVER['HTTP_REFERER'] )
? trim( $_SERVER['HTTP_REFERER'] ) : '';
$referer = trim( $_SERVER['HTTP_REFERER'] ?? '' );
if ( $referer
and 0 === strpos( $referer, $home_url ) ) {
@@ -758,7 +695,7 @@ class WPCF7_Submission {
return true;
}
$nonce = isset( $_POST['_wpnonce'] ) ? $_POST['_wpnonce'] : '';
$nonce = $_POST['_wpnonce'] ?? '';
return wpcf7_verify_nonce( $nonce );
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,191 @@
<?php
namespace Contactable\SWV;
use WP_Error;
/**
* The base class of SWV rules.
*/
abstract class Rule {
protected $properties = array();
public function __construct( $properties = '' ) {
$this->properties = wp_parse_args( $properties, array() );
}
/**
* Returns true if this rule matches the given context.
*
* @param array $context Context.
*/
public function matches( $context ) {
$field = $this->get_property( 'field' );
if ( ! empty( $context['field'] ) ) {
if ( $field and ! in_array( $field, (array) $context['field'], true ) ) {
return false;
}
}
return true;
}
/**
* Validates with this rule's logic.
*
* @param array $context Context.
*/
public function validate( $context ) {
return true;
}
/**
* Converts the properties to an array.
*
* @return array Array of properties.
*/
public function to_array() {
$properties = (array) $this->properties;
if ( defined( 'static::rule_name' ) and static::rule_name ) {
$properties = array( 'rule' => static::rule_name ) + $properties;
}
return $properties;
}
/**
* Returns the property value specified by the given property name.
*
* @param string $name Property name.
* @return mixed Property value.
*/
public function get_property( $name ) {
if ( isset( $this->properties[$name] ) ) {
return $this->properties[$name];
}
}
/**
* Returns the default user input value from $_POST.
*
* @return mixed Default user input value.
*/
public function get_default_input() {
$field = $this->get_property( 'field' );
if ( isset( $_POST[$field] ) ) {
return wp_unslash( $_POST[$field] );
}
return '';
}
/**
* Creates an error object. Returns false if the error property is omitted.
*/
protected function create_error() {
$error_code = defined( 'static::rule_name' )
? sprintf( 'swv_%s', static::rule_name )
: 'swv';
return new WP_Error(
$error_code,
(string) $this->get_property( 'error' ),
$this
);
}
}
/**
* The base class of SWV composite rules.
*/
abstract class CompositeRule extends Rule {
protected $rules = array();
/**
* Adds a sub-rule to this composite rule.
*
* @param Rule $rule Sub-rule to be added.
*/
public function add_rule( $rule ) {
if ( $rule instanceof Rule ) {
$this->rules[] = $rule;
}
}
/**
* Returns an iterator of sub-rules.
*/
public function rules() {
foreach ( $this->rules as $rule ) {
yield $rule;
}
}
/**
* Returns true if this rule matches the given context.
*
* @param array $context Context.
*/
public function matches( $context ) {
return true;
}
/**
* Validates with this rule's logic.
*
* @param array $context Context.
*/
public function validate( $context ) {
foreach ( $this->rules() as $rule ) {
if ( $rule->matches( $context ) ) {
$result = $rule->validate( $context );
if ( is_wp_error( $result ) ) {
return $result;
}
}
}
return true;
}
/**
* Converts the properties to an array.
*
* @return array Array of properties.
*/
public function to_array() {
$rules_arrays = array_map(
static function ( $rule ) {
return $rule->to_array();
},
$this->rules
);
return array_merge(
parent::to_array(),
array(
'rules' => $rules_arrays,
)
);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Contactable\SWV;
class AllRule extends CompositeRule {
const rule_name = 'all';
public function matches( $context ) {
if ( false === parent::matches( $context ) ) {
return false;
}
return true;
}
public function validate( $context ) {
foreach ( $this->rules() as $rule ) {
if ( $rule->matches( $context ) ) {
$result = $rule->validate( $context );
if ( is_wp_error( $result ) ) {
if ( $result->get_error_message() ) {
return $result;
} else {
return $this->create_error();
}
}
}
}
return true;
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Contactable\SWV;
class AnyRule extends CompositeRule {
const rule_name = 'any';
public function matches( $context ) {
if ( false === parent::matches( $context ) ) {
return false;
}
return true;
}
public function validate( $context ) {
foreach ( $this->rules() as $rule ) {
if ( $rule->matches( $context ) ) {
$result = $rule->validate( $context );
if ( ! is_wp_error( $result ) ) {
return true;
}
}
}
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_DateRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class DateRule extends Rule {
const rule_name = 'date';
@@ -17,16 +19,13 @@ class WPCF7_SWV_DateRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
foreach ( $input as $i ) {
if ( ! wpcf7_is_date( $i ) ) {
return new WP_Error( 'wpcf7_invalid_date',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_DayofweekRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class DayofweekRule extends Rule {
const rule_name = 'dayofweek';
@@ -17,10 +19,7 @@ class WPCF7_SWV_DayofweekRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -35,9 +34,7 @@ class WPCF7_SWV_DayofweekRule extends WPCF7_SWV_Rule {
$dow = (int) $datetime->format( 'N' );
if ( ! in_array( $dow, $acceptable_values, true ) ) {
return new WP_Error( 'wpcf7_invalid_dayofweek',
$this->get_property( 'error' )
);
return $this->create_error();
}
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_EmailRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class EmailRule extends Rule {
const rule_name = 'email';
@@ -17,16 +19,13 @@ class WPCF7_SWV_EmailRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
foreach ( $input as $i ) {
if ( ! wpcf7_is_email( $i ) ) {
return new WP_Error( 'wpcf7_invalid_email',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_EnumRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class EnumRule extends Rule {
const rule_name = 'enum';
@@ -17,23 +19,23 @@ class WPCF7_SWV_EnumRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
$acceptable_values = (array) $this->get_property( 'accept' );
$acceptable_values = array_map( 'strval', $acceptable_values );
$acceptable_values = array_filter( $acceptable_values );
$acceptable_values = array_unique( $acceptable_values );
$acceptable_values = array_filter( $acceptable_values,
static function ( $val ) {
return '' !== $val;
}
);
foreach ( $input as $i ) {
if ( ! in_array( $i, $acceptable_values, true ) ) {
return new WP_Error( 'wpcf7_invalid_enum',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_FileRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class FileRule extends Rule {
const rule_name = 'file';
@@ -18,7 +20,7 @@ class WPCF7_SWV_FileRule extends WPCF7_SWV_Rule {
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_FILES[$field]['name'] ) ? $_FILES[$field]['name'] : '';
$input = $_FILES[$field]['name'] ?? '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -43,17 +45,13 @@ class WPCF7_SWV_FileRule extends WPCF7_SWV_Rule {
$last_period_pos = strrpos( $i, '.' );
if ( false === $last_period_pos ) { // no period
return new WP_Error( 'wpcf7_invalid_file',
$this->get_property( 'error' )
);
return $this->create_error();
}
$suffix = strtolower( substr( $i, $last_period_pos ) );
if ( ! in_array( $suffix, $acceptable_filetypes, true ) ) {
return new WP_Error( 'wpcf7_invalid_file',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MaxDateRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MaxDateRule extends Rule {
const rule_name = 'maxdate';
@@ -17,8 +19,7 @@ class WPCF7_SWV_MaxDateRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -30,9 +31,7 @@ class WPCF7_SWV_MaxDateRule extends WPCF7_SWV_Rule {
foreach ( $input as $i ) {
if ( wpcf7_is_date( $i ) and $threshold < $i ) {
return new WP_Error( 'wpcf7_invalid_maxdate',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MaxFileSizeRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MaxFileSizeRule extends Rule {
const rule_name = 'maxfilesize';
@@ -18,7 +20,7 @@ class WPCF7_SWV_MaxFileSizeRule extends WPCF7_SWV_Rule {
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_FILES[$field]['size'] ) ? $_FILES[$field]['size'] : '';
$input = $_FILES[$field]['size'] ?? '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -29,9 +31,7 @@ class WPCF7_SWV_MaxFileSizeRule extends WPCF7_SWV_Rule {
$threshold = $this->get_property( 'threshold' );
if ( $threshold < array_sum( $input ) ) {
return new WP_Error( 'wpcf7_invalid_maxfilesize',
$this->get_property( 'error' )
);
return $this->create_error();
}
return true;

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MaxItemsRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MaxItemsRule extends Rule {
const rule_name = 'maxitems';
@@ -17,8 +19,7 @@ class WPCF7_SWV_MaxItemsRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -29,9 +30,7 @@ class WPCF7_SWV_MaxItemsRule extends WPCF7_SWV_Rule {
}
if ( (int) $threshold < count( $input ) ) {
return new WP_Error( 'wpcf7_invalid_maxitems',
$this->get_property( 'error' )
);
return $this->create_error();
}
return true;

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MaxLengthRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MaxLengthRule extends Rule {
const rule_name = 'maxlength';
@@ -17,8 +19,7 @@ class WPCF7_SWV_MaxLengthRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -37,9 +38,7 @@ class WPCF7_SWV_MaxLengthRule extends WPCF7_SWV_Rule {
if ( $total <= $threshold ) {
return true;
} else {
return new WP_Error( 'wpcf7_invalid_maxlength',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MaxNumberRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MaxNumberRule extends Rule {
const rule_name = 'maxnumber';
@@ -17,8 +19,7 @@ class WPCF7_SWV_MaxNumberRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -30,9 +31,7 @@ class WPCF7_SWV_MaxNumberRule extends WPCF7_SWV_Rule {
foreach ( $input as $i ) {
if ( wpcf7_is_number( $i ) and (float) $threshold < (float) $i ) {
return new WP_Error( 'wpcf7_invalid_maxnumber',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MinDateRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MinDateRule extends Rule {
const rule_name = 'mindate';
@@ -17,8 +19,7 @@ class WPCF7_SWV_MinDateRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -30,9 +31,7 @@ class WPCF7_SWV_MinDateRule extends WPCF7_SWV_Rule {
foreach ( $input as $i ) {
if ( wpcf7_is_date( $i ) and $i < $threshold ) {
return new WP_Error( 'wpcf7_invalid_mindate',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MinFileSizeRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MinFileSizeRule extends Rule {
const rule_name = 'minfilesize';
@@ -18,7 +20,7 @@ class WPCF7_SWV_MinFileSizeRule extends WPCF7_SWV_Rule {
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_FILES[$field]['size'] ) ? $_FILES[$field]['size'] : '';
$input = $_FILES[$field]['size'] ?? '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -29,9 +31,7 @@ class WPCF7_SWV_MinFileSizeRule extends WPCF7_SWV_Rule {
$threshold = $this->get_property( 'threshold' );
if ( array_sum( $input ) < $threshold ) {
return new WP_Error( 'wpcf7_invalid_minfilesize',
$this->get_property( 'error' )
);
return $this->create_error();
}
return true;

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MinItemsRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MinItemsRule extends Rule {
const rule_name = 'minitems';
@@ -17,8 +19,7 @@ class WPCF7_SWV_MinItemsRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -29,9 +30,7 @@ class WPCF7_SWV_MinItemsRule extends WPCF7_SWV_Rule {
}
if ( count( $input ) < (int) $threshold ) {
return new WP_Error( 'wpcf7_invalid_minitems',
$this->get_property( 'error' )
);
return $this->create_error();
}
return true;

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MinLengthRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MinLengthRule extends Rule {
const rule_name = 'minlength';
@@ -17,8 +19,7 @@ class WPCF7_SWV_MinLengthRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -37,9 +38,7 @@ class WPCF7_SWV_MinLengthRule extends WPCF7_SWV_Rule {
if ( $threshold <= $total ) {
return true;
} else {
return new WP_Error( 'wpcf7_invalid_minlength',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_MinNumberRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class MinNumberRule extends Rule {
const rule_name = 'minnumber';
@@ -17,8 +19,7 @@ class WPCF7_SWV_MinNumberRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
@@ -30,9 +31,7 @@ class WPCF7_SWV_MinNumberRule extends WPCF7_SWV_Rule {
foreach ( $input as $i ) {
if ( wpcf7_is_number( $i ) and (float) $i < (float) $threshold ) {
return new WP_Error( 'wpcf7_invalid_minnumber',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_NumberRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class NumberRule extends Rule {
const rule_name = 'number';
@@ -17,16 +19,13 @@ class WPCF7_SWV_NumberRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
foreach ( $input as $i ) {
if ( ! wpcf7_is_number( $i ) ) {
return new WP_Error( 'wpcf7_invalid_number',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_RequiredRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class RequiredRule extends Rule {
const rule_name = 'required';
@@ -17,17 +19,12 @@ class WPCF7_SWV_RequiredRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
if ( empty( $input ) ) {
return new WP_Error( 'wpcf7_invalid_required',
$this->get_property( 'error' )
);
return $this->create_error();
}
return true;

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_RequiredFileRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class RequiredFileRule extends Rule {
const rule_name = 'requiredfile';
@@ -18,17 +20,12 @@ class WPCF7_SWV_RequiredFileRule extends WPCF7_SWV_Rule {
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_FILES[$field]['tmp_name'] )
? $_FILES[$field]['tmp_name'] : '';
$input = $_FILES[$field]['tmp_name'] ?? '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
if ( empty( $input ) ) {
return new WP_Error( 'wpcf7_invalid_requiredfile',
$this->get_property( 'error' )
);
return $this->create_error();
}
return true;

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_TelRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class TelRule extends Rule {
const rule_name = 'tel';
@@ -17,16 +19,13 @@ class WPCF7_SWV_TelRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
foreach ( $input as $i ) {
if ( ! wpcf7_is_tel( $i ) ) {
return new WP_Error( 'wpcf7_invalid_tel',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_TimeRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class TimeRule extends Rule {
const rule_name = 'time';
@@ -17,16 +19,13 @@ class WPCF7_SWV_TimeRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$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 $this->create_error();
}
}

View File

@@ -1,6 +1,8 @@
<?php
class WPCF7_SWV_URLRule extends WPCF7_SWV_Rule {
namespace Contactable\SWV;
class URLRule extends Rule {
const rule_name = 'url';
@@ -17,16 +19,13 @@ class WPCF7_SWV_URLRule extends WPCF7_SWV_Rule {
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = $this->get_default_input();
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
foreach ( $input as $i ) {
if ( ! wpcf7_is_url( $i ) ) {
return new WP_Error( 'wpcf7_invalid_url',
$this->get_property( 'error' )
);
return $this->create_error();
}
}

View File

@@ -29,29 +29,18 @@ trait WPCF7_SWV_SchemaHolder {
* Validates form inputs based on the schema and given context.
*/
public function validate_schema( $context, WPCF7_Validation $validity ) {
$callback = static function ( $rule ) use ( &$callback, $context, $validity ) {
if ( ! $rule->matches( $context ) ) {
return;
}
$schema = $this->get_schema();
if ( $rule instanceof WPCF7_SWV_CompositeRule ) {
foreach ( $rule->rules() as $child_rule ) {
call_user_func( $callback, $child_rule );
}
} else {
foreach ( $schema->validate( $context ) as $result ) {
if ( is_wp_error( $result ) ) {
$rule = $result->get_error_data();
$field = $rule->get_property( 'field' );
if ( $validity->is_valid( $field ) ) {
$result = $rule->validate( $context );
if ( is_wp_error( $result ) ) {
$validity->invalidate( $field, $result );
}
if ( isset( $field ) and $validity->is_valid( $field ) ) {
$validity->invalidate( $field, $result );
}
}
};
call_user_func( $callback, $this->get_schema() );
}
}
}

View File

@@ -19,7 +19,7 @@ add_action(
wpcf7_plugin_url( 'includes/swv/js/index.js' ),
$assets['dependencies'],
$assets['version'],
true
array( 'in_footer' => true )
);
},
10, 0

View File

@@ -5,6 +5,7 @@
require_once WPCF7_PLUGIN_DIR . '/includes/swv/schema-holder.php';
require_once WPCF7_PLUGIN_DIR . '/includes/swv/script-loader.php';
require_once WPCF7_PLUGIN_DIR . '/includes/swv/php/abstract-rules.php';
/**
@@ -12,27 +13,29 @@ require_once WPCF7_PLUGIN_DIR . '/includes/swv/script-loader.php';
*/
function wpcf7_swv_available_rules() {
$rules = array(
'required' => 'WPCF7_SWV_RequiredRule',
'requiredfile' => 'WPCF7_SWV_RequiredFileRule',
'email' => 'WPCF7_SWV_EmailRule',
'url' => 'WPCF7_SWV_URLRule',
'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',
'maxlength' => 'WPCF7_SWV_MaxLengthRule',
'minnumber' => 'WPCF7_SWV_MinNumberRule',
'maxnumber' => 'WPCF7_SWV_MaxNumberRule',
'mindate' => 'WPCF7_SWV_MinDateRule',
'maxdate' => 'WPCF7_SWV_MaxDateRule',
'minfilesize' => 'WPCF7_SWV_MinFileSizeRule',
'maxfilesize' => 'WPCF7_SWV_MaxFileSizeRule',
'required' => 'Contactable\SWV\RequiredRule',
'requiredfile' => 'Contactable\SWV\RequiredFileRule',
'email' => 'Contactable\SWV\EmailRule',
'url' => 'Contactable\SWV\URLRule',
'tel' => 'Contactable\SWV\TelRule',
'number' => 'Contactable\SWV\NumberRule',
'date' => 'Contactable\SWV\DateRule',
'time' => 'Contactable\SWV\TimeRule',
'file' => 'Contactable\SWV\FileRule',
'enum' => 'Contactable\SWV\EnumRule',
'dayofweek' => 'Contactable\SWV\DayofweekRule',
'minitems' => 'Contactable\SWV\MinItemsRule',
'maxitems' => 'Contactable\SWV\MaxItemsRule',
'minlength' => 'Contactable\SWV\MinLengthRule',
'maxlength' => 'Contactable\SWV\MaxLengthRule',
'minnumber' => 'Contactable\SWV\MinNumberRule',
'maxnumber' => 'Contactable\SWV\MaxNumberRule',
'mindate' => 'Contactable\SWV\MinDateRule',
'maxdate' => 'Contactable\SWV\MaxDateRule',
'minfilesize' => 'Contactable\SWV\MinFileSizeRule',
'maxfilesize' => 'Contactable\SWV\MaxFileSizeRule',
'all' => 'Contactable\SWV\AllRule',
'any' => 'Contactable\SWV\AnyRule',
);
return apply_filters( 'wpcf7_swv_available_rules', $rules );
@@ -49,7 +52,7 @@ function wpcf7_swv_load_rules() {
foreach ( array_keys( $rules ) as $rule ) {
$file = sprintf( '%s.php', $rule );
$path = path_join( WPCF7_PLUGIN_DIR . '/includes/swv/rules', $file );
$path = path_join( WPCF7_PLUGIN_DIR . '/includes/swv/php/rules', $file );
if ( file_exists( $path ) ) {
include_once $path;
@@ -63,7 +66,7 @@ function wpcf7_swv_load_rules() {
*
* @param string $rule_name Rule name.
* @param string|array $properties Optional. Rule properties.
* @return WPCF7_SWV_Rule|null The rule object, or null if it failed.
* @return Rule|null The rule object, or null if it failed.
*/
function wpcf7_swv_create_rule( $rule_name, $properties = '' ) {
$rules = wpcf7_swv_available_rules();
@@ -124,172 +127,38 @@ function wpcf7_swv_get_meta_schema() {
}
/**
* The base class of SWV rules.
*/
abstract class WPCF7_SWV_Rule {
protected $properties = array();
public function __construct( $properties = '' ) {
$this->properties = wp_parse_args( $properties, array() );
}
/**
* Returns true if this rule matches the given context.
*
* @param array $context Context.
*/
public function matches( $context ) {
$field = $this->get_property( 'field' );
if ( ! empty( $context['field'] ) ) {
if ( $field and ! in_array( $field, (array) $context['field'], true ) ) {
return false;
}
}
return true;
}
/**
* Validates with this rule's logic.
*
* @param array $context Context.
*/
public function validate( $context ) {
return true;
}
/**
* Converts the properties to an array.
*
* @return array Array of properties.
*/
public function to_array() {
$properties = (array) $this->properties;
if ( defined( 'static::rule_name' ) and static::rule_name ) {
$properties = array( 'rule' => static::rule_name ) + $properties;
}
return $properties;
}
/**
* Returns the property value specified by the given property name.
*
* @param string $name Property name.
* @return mixed Property value.
*/
public function get_property( $name ) {
if ( isset( $this->properties[$name] ) ) {
return $this->properties[$name];
}
}
}
/**
* The base class of SWV composite rules.
*/
abstract class WPCF7_SWV_CompositeRule extends WPCF7_SWV_Rule {
protected $rules = array();
/**
* Adds a sub-rule to this composite rule.
*
* @param WPCF7_SWV_Rule $rule Sub-rule to be added.
*/
public function add_rule( $rule ) {
if ( $rule instanceof WPCF7_SWV_Rule ) {
$this->rules[] = $rule;
}
}
/**
* Returns an iterator of sub-rules.
*/
public function rules() {
foreach ( $this->rules as $rule ) {
yield $rule;
}
}
/**
* Returns true if this rule matches the given context.
*
* @param array $context Context.
*/
public function matches( $context ) {
return true;
}
/**
* Validates with this rule's logic.
*
* @param array $context Context.
*/
public function validate( $context ) {
foreach ( $this->rules() as $rule ) {
if ( $rule->matches( $context ) ) {
$result = $rule->validate( $context );
if ( is_wp_error( $result ) ) {
return $result;
}
}
}
return true;
}
/**
* Converts the properties to an array.
*
* @return array Array of properties.
*/
public function to_array() {
$rules_arrays = array_map(
static function ( $rule ) {
return $rule->to_array();
},
$this->rules
);
return array_merge(
parent::to_array(),
array(
'rules' => $rules_arrays,
)
);
}
}
/**
* The schema class as a composite rule.
*/
class WPCF7_SWV_Schema extends WPCF7_SWV_CompositeRule {
class WPCF7_SWV_Schema extends \Contactable\SWV\CompositeRule {
const version = 'Contact Form 7 SWV Schema 2023-07';
/**
* The human-readable version of the schema.
*/
const version = 'Contact Form 7 SWV Schema 2024-02';
/**
* Constructor.
*/
public function __construct( $properties = '' ) {
$this->properties = wp_parse_args( $properties, array(
'version' => self::version,
) );
}
/**
* Validates with this schema.
*
* @param array $context Context.
*/
public function validate( $context ) {
foreach ( $this->rules() as $rule ) {
if ( $rule->matches( $context ) ) {
yield $rule->validate( $context );
}
}
}
}

View File

@@ -14,6 +14,7 @@ require_once WPCF7_PLUGIN_DIR . '/includes/contact-form-functions.php';
require_once WPCF7_PLUGIN_DIR . '/includes/contact-form-template.php';
require_once WPCF7_PLUGIN_DIR . '/includes/contact-form.php';
require_once WPCF7_PLUGIN_DIR . '/includes/mail.php';
require_once WPCF7_PLUGIN_DIR . '/includes/mail-tag.php';
require_once WPCF7_PLUGIN_DIR . '/includes/special-mail-tags.php';
require_once WPCF7_PLUGIN_DIR . '/includes/file.php';
require_once WPCF7_PLUGIN_DIR . '/includes/validation-functions.php';

View File

@@ -12,6 +12,7 @@ function wpcf7_add_form_tag_acceptance() {
'wpcf7_acceptance_form_tag_handler',
array(
'name-attr' => true,
'selectable-values' => true,
)
);
}

View File

@@ -52,8 +52,7 @@ function wpcf7_akismet( $spam, $submission ) {
'blog_charset' => get_option( 'blog_charset' ),
'user_ip' => $submission->get_meta( 'remote_ip' ),
'user_agent' => $submission->get_meta( 'user_agent' ),
'referrer' => isset( $_SERVER['HTTP_REFERER'] )
? $_SERVER['HTTP_REFERER'] : '',
'referrer' => $_SERVER['HTTP_REFERER'] ?? '',
);
$datetime = date_create_immutable(

View File

@@ -72,11 +72,14 @@ function wpcf7_checkbox_form_tag_handler( $tag ) {
$tag->values = array_merge(
array_slice( $tag->values, 0, -1 ),
array_values( $data ),
array_slice( $tag->values, -1 ) );
array_slice( $tag->values, -1 )
);
$tag->labels = array_merge(
array_slice( $tag->labels, 0, -1 ),
array_values( $data ),
array_slice( $tag->labels, -1 ) );
array_slice( $tag->labels, -1 )
);
} else {
$tag->values = array_merge( $tag->values, array_values( $data ) );
$tag->labels = array_merge( $tag->labels, array_values( $data ) );
@@ -148,7 +151,7 @@ function wpcf7_checkbox_form_tag_handler( $tag ) {
$class .= ' last';
if ( $free_text ) {
$free_text_name = $tag->name . '_free_text';
$free_text_name = sprintf( '_wpcf7_free_text_%s', $tag->name );
$free_text_atts = array(
'name' => $free_text_name,
@@ -207,6 +210,120 @@ function wpcf7_swv_add_checkbox_rules( $schema, $contact_form ) {
}
add_action(
'wpcf7_swv_create_schema',
'wpcf7_swv_add_checkbox_enum_rules',
20, 2
);
function wpcf7_swv_add_checkbox_enum_rules( $schema, $contact_form ) {
$tags = $contact_form->scan_form_tags( array(
'basetype' => array( 'checkbox', 'radio' ),
) );
$values = array_reduce(
$tags,
function ( $values, $tag ) {
if ( $tag->has_option( 'free_text' ) ) {
$values[$tag->name] = 'free_text';
}
if (
isset( $values[$tag->name] ) and
! is_array( $values[$tag->name] ) // Maybe 'free_text'
) {
return $values;
}
if ( ! isset( $values[$tag->name] ) ) {
$values[$tag->name] = array();
}
$tag_values = array_merge(
(array) $tag->values,
(array) $tag->get_data_option()
);
$values[$tag->name] = array_merge(
$values[$tag->name],
$tag_values
);
return $values;
},
array()
);
foreach ( $values as $field => $field_values ) {
if ( ! is_array( $field_values ) ) { // Maybe 'free_text'
continue;
}
$field_values = array_map(
static function ( $value ) {
return html_entity_decode(
(string) $value,
ENT_QUOTES | ENT_HTML5,
'UTF-8'
);
},
$field_values
);
$field_values = array_filter(
array_unique( $field_values ),
static function ( $value ) {
return '' !== $value;
}
);
$schema->add_rule(
wpcf7_swv_create_rule( 'enum', array(
'field' => $field,
'accept' => array_values( $field_values ),
'error' => $contact_form->filter_message(
__( "Undefined value was submitted through this field.", 'contact-form-7' )
),
) )
);
}
}
add_filter( 'wpcf7_posted_data_checkbox',
'wpcf7_posted_data_checkbox',
10, 3
);
add_filter( 'wpcf7_posted_data_checkbox*',
'wpcf7_posted_data_checkbox',
10, 3
);
add_filter( 'wpcf7_posted_data_radio',
'wpcf7_posted_data_checkbox',
10, 3
);
function wpcf7_posted_data_checkbox( $value, $value_orig, $form_tag ) {
if ( $form_tag->has_option( 'free_text' ) ) {
$value = (array) $value;
$free_text_name = sprintf( '_wpcf7_free_text_%s', $form_tag->name );
$free_text = wp_unslash( $_POST[$free_text_name] ?? '' );
$last_val = array_pop( $value );
if ( isset( $last_val ) ) {
$last_val = sprintf( '%s %s', $last_val, $free_text );
$value[] = trim( $last_val );
}
}
return $value;
}
/* Tag generator */
add_action( 'wpcf7_admin_init',

View File

@@ -14,7 +14,7 @@ wpcf7_include_module_file( 'constant-contact/doi.php' );
add_action(
'wpcf7_init',
'wpcf7_constant_contact_register_service',
20, 0
120, 0
);
/**

View File

@@ -113,10 +113,7 @@ class WPCF7_ConstantContact extends WPCF7_Service_OAuth2 {
}
public function link() {
echo sprintf( '<a href="%1$s">%2$s</a>',
'https://constant-contact.evyy.net/c/1293104/205991/3411',
'constantcontact.com'
);
echo 'constantcontact.com';
}
protected function get_redirect_uri() {
@@ -366,6 +363,15 @@ class WPCF7_ConstantContact extends WPCF7_Service_OAuth2 {
}
public function display( $action = '' ) {
echo sprintf(
'<p><strong>%1$s</strong> %2$s</p>',
esc_html( __( 'Warning:', 'contact-form-7' ) ),
wpcf7_link(
__( 'https://contactform7.com/2024/02/02/we-end-the-constant-contact-integration/', 'contact-form-7' ),
__( "This feature is deprecated. You are not recommended to use it.", 'contact-form-7' )
)
);
echo sprintf(
'<p>%s</p>',
esc_html( __( "The Constant Contact integration module allows you to send contact data collected through your contact forms to the Constant Contact API. You can create reliable email subscription services in a few easy steps.", 'contact-form-7' ) )

View File

@@ -98,7 +98,7 @@ add_filter( 'wpcf7_validate_quiz', 'wpcf7_quiz_validation_filter', 10, 2 );
function wpcf7_quiz_validation_filter( $result, $tag ) {
$name = $tag->name;
$answer = isset( $_POST[$name] ) ? wp_unslash( $_POST[$name] ) : '';
$answer = wp_unslash( $_POST[$name] ?? '' );
$answer = wpcf7_canonicalize( $answer, array(
'strip_separators' => true,
@@ -106,9 +106,7 @@ function wpcf7_quiz_validation_filter( $result, $tag ) {
$answer_hash = wp_hash( $answer, 'wpcf7_quiz' );
$expected_hash = isset( $_POST['_wpcf7_quiz_answer_' . $name] )
? (string) $_POST['_wpcf7_quiz_answer_' . $name]
: '';
$expected_hash = (string) ( $_POST['_wpcf7_quiz_answer_' . $name] ?? '' );
if ( ! hash_equals( $expected_hash, $answer_hash ) ) {
$result->invalidate( $tag, wpcf7_get_message( 'quiz_answer_not_correct' ) );
@@ -176,7 +174,7 @@ add_filter( 'wpcf7_mail_tag_replaced_quiz', 'wpcf7_quiz_mail_tag', 10, 4 );
function wpcf7_quiz_mail_tag( $replaced, $submitted, $html, $mail_tag ) {
$field_name = $mail_tag->field_name();
$submitted = isset( $_POST[$field_name] ) ? $_POST[$field_name] : '';
$submitted = $_POST[$field_name] ?? '';
$replaced = $submitted;
if ( $html ) {

View File

@@ -167,8 +167,8 @@ function wpcf7_captcha_validation_filter( $result, $tag ) {
$captchac = '_wpcf7_captcha_challenge_' . $name;
$prefix = isset( $_POST[$captchac] ) ? (string) $_POST[$captchac] : '';
$response = isset( $_POST[$name] ) ? (string) $_POST[$name] : '';
$prefix = (string) ( $_POST[$captchac] ?? '' );
$response = (string) ( $_POST[$name] ?? '' );
$response = wpcf7_canonicalize( $response );
if ( 0 === strlen( $prefix )

View File

@@ -53,7 +53,7 @@ function wpcf7_recaptcha_enqueue_scripts() {
),
array(),
'3.0',
true
array( 'in_footer' => true )
);
$assets = array();
@@ -79,7 +79,7 @@ function wpcf7_recaptcha_enqueue_scripts() {
)
),
$assets['version'],
true
array( 'in_footer' => true )
);
wp_enqueue_script( 'wpcf7-recaptcha' );
@@ -135,8 +135,7 @@ function wpcf7_recaptcha_verify_response( $spam, $submission ) {
return $spam;
}
$token = isset( $_POST['_wpcf7_recaptcha_response'] )
? trim( $_POST['_wpcf7_recaptcha_response'] ) : '';
$token = trim( $_POST['_wpcf7_recaptcha_response'] ?? '' );
if ( $service->verify( $token ) ) { // Human
$spam = false;

View File

@@ -221,8 +221,8 @@ class WPCF7_RECAPTCHA extends WPCF7_Service {
$this->reset_data();
$redirect_to = $this->menu_page_url( 'action=setup' );
} else {
$sitekey = isset( $_POST['sitekey'] ) ? trim( $_POST['sitekey'] ) : '';
$secret = isset( $_POST['secret'] ) ? trim( $_POST['secret'] ) : '';
$sitekey = trim( $_POST['sitekey'] ?? '' );
$secret = trim( $_POST['secret'] ?? '' );
if ( $sitekey and $secret ) {
$this->sitekeys = array( $sitekey => $secret );

View File

@@ -153,6 +153,75 @@ function wpcf7_swv_add_select_rules( $schema, $contact_form ) {
}
add_action(
'wpcf7_swv_create_schema',
'wpcf7_swv_add_select_enum_rules',
20, 2
);
function wpcf7_swv_add_select_enum_rules( $schema, $contact_form ) {
$tags = $contact_form->scan_form_tags( array(
'basetype' => array( 'select' ),
) );
$values = array_reduce(
$tags,
function ( $values, $tag ) {
if ( ! isset( $values[$tag->name] ) ) {
$values[$tag->name] = array();
}
$tag_values = array_merge(
(array) $tag->values,
(array) $tag->get_data_option()
);
if ( $tag->has_option( 'first_as_label' ) ) {
$tag_values = array_slice( $tag_values, 1 );
}
$values[$tag->name] = array_merge(
$values[$tag->name],
$tag_values
);
return $values;
},
array()
);
foreach ( $values as $field => $field_values ) {
$field_values = array_map(
static function ( $value ) {
return html_entity_decode(
(string) $value,
ENT_QUOTES | ENT_HTML5,
'UTF-8'
);
},
$field_values
);
$field_values = array_filter(
array_unique( $field_values ),
static function ( $value ) {
return '' !== $value;
}
);
$schema->add_rule(
wpcf7_swv_create_rule( 'enum', array(
'field' => $field,
'accept' => array_values( $field_values ),
'error' => $contact_form->filter_message(
__( "Undefined value was submitted through this field.", 'contact-form-7' )
),
) )
);
}
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_menu', 25, 0 );

View File

@@ -38,9 +38,7 @@ function wpcf7_sendinblue_save_contact_form( $contact_form, $args, $context ) {
return;
}
$prop = isset( $_POST['wpcf7-sendinblue'] )
? (array) $_POST['wpcf7-sendinblue']
: array();
$prop = (array) ( $_POST['wpcf7-sendinblue'] ?? array() );
$prop = wp_parse_args(
$prop,

View File

@@ -47,7 +47,7 @@ class WPCF7_Sendinblue extends WPCF7_Service {
public function link() {
echo wpcf7_link(
'https://www.brevo.com/',
'https://get.brevo.com/wpcf7-integration',
'brevo.com'
);
}
@@ -88,9 +88,7 @@ class WPCF7_Sendinblue extends WPCF7_Service {
$this->reset_data();
$redirect_to = $this->menu_page_url( 'action=setup' );
} else {
$this->api_key = isset( $_POST['api_key'] )
? trim( $_POST['api_key'] )
: '';
$this->api_key = trim( $_POST['api_key'] ?? '' );
$confirmed = $this->confirm_key();

View File

@@ -107,9 +107,8 @@ class WPCF7_Stripe extends WPCF7_Service {
$this->reset_data();
$redirect_to = $this->menu_page_url( 'action=setup' );
} else {
$publishable = isset( $_POST['publishable'] ) ?
trim( $_POST['publishable'] ) : '';
$secret = isset( $_POST['secret'] ) ? trim( $_POST['secret'] ) : '';
$publishable = trim( $_POST['publishable'] ?? '' );
$secret = trim( $_POST['secret'] ?? '' );
if ( $publishable and $secret ) {
$this->api_keys = array(

View File

@@ -80,7 +80,7 @@ function wpcf7_stripe_enqueue_scripts() {
)
),
$assets['version'],
true
array( 'in_footer' => true )
);
$api_keys = $service->get_api_keys();

View File

@@ -1,11 +1,11 @@
=== Contact Form 7 ===
Contributors: takayukister
Donate link: https://contactform7.com/donate/
Tags: contact, form, contact form, feedback, email, ajax, captcha, akismet, multilingual
Requires at least: 6.2
Tags: contact form, schema-woven validation
Requires at least: 6.3
Requires PHP: 7.4
Tested up to: 6.4
Stable tag: 5.8.7
Tested up to: 6.5
Stable tag: 5.9.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -78,6 +78,14 @@ Do you have questions or issues with Contact Form 7? Use these support channels
For more information, see [Releases](https://contactform7.com/category/releases/).
= 5.9.2 =
[https://contactform7.com/contact-form-7-592/](https://contactform7.com/contact-form-7-592/)
= 5.9 =
[https://contactform7.com/contact-form-7-59/](https://contactform7.com/contact-form-7-59/)
= 5.8.7 =
[https://contactform7.com/contact-form-7-587/](https://contactform7.com/contact-form-7-587/)
@@ -110,40 +118,4 @@ For more information, see [Releases](https://contactform7.com/category/releases/
[https://contactform7.com/contact-form-7-58/](https://contactform7.com/contact-form-7-58/)
= 5.7.7 =
[https://contactform7.com/contact-form-7-577/](https://contactform7.com/contact-form-7-577/)
= 5.7.6 =
[https://contactform7.com/contact-form-7-576/](https://contactform7.com/contact-form-7-576/)
= 5.7.5.1 =
* Fixes an old PHP compatibility issue.
= 5.7.5 =
[https://contactform7.com/contact-form-7-575/](https://contactform7.com/contact-form-7-575/)
= 5.7.4 =
[https://contactform7.com/contact-form-7-574/](https://contactform7.com/contact-form-7-574/)
= 5.7.3 =
[https://contactform7.com/contact-form-7-573/](https://contactform7.com/contact-form-7-573/)
= 5.7.2 =
[https://contactform7.com/contact-form-7-572/](https://contactform7.com/contact-form-7-572/)
= 5.7.1 =
[https://contactform7.com/contact-form-7-571/](https://contactform7.com/contact-form-7-571/)
= 5.7 =
[https://contactform7.com/contact-form-7-57/](https://contactform7.com/contact-form-7-57/)
== Upgrade Notice ==

View File

@@ -7,14 +7,14 @@
* Author URI: https://ideasilo.wordpress.com/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Version: 5.8.7
* Requires at least: 6.2
* Version: 5.9.2
* Requires at least: 6.3
* Requires PHP: 7.4
*/
define( 'WPCF7_VERSION', '5.8.7' );
define( 'WPCF7_VERSION', '5.9.2' );
define( 'WPCF7_REQUIRED_WP_VERSION', '6.2' );
define( 'WPCF7_REQUIRED_WP_VERSION', '6.3' );
define( 'WPCF7_TEXT_DOMAIN', 'contact-form-7' );