Plugin Updates
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class DateRule extends Rule {
|
||||
|
||||
const rule_name = 'date';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$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 $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class DayofweekRule extends 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 ) {
|
||||
$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( '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 $this->create_error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class EmailRule extends Rule {
|
||||
|
||||
const rule_name = 'email';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$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 $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class EnumRule extends Rule {
|
||||
|
||||
const rule_name = 'enum';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$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_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 $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class FileRule extends Rule {
|
||||
|
||||
const rule_name = 'file';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['file'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$field = $this->get_property( 'field' );
|
||||
$input = $_FILES[$field]['name'] ?? '';
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
$acceptable_filetypes = array();
|
||||
|
||||
foreach ( (array) $this->get_property( 'accept' ) as $accept ) {
|
||||
if ( preg_match( '/^\.[a-z0-9]+$/i', $accept ) ) {
|
||||
$acceptable_filetypes[] = strtolower( $accept );
|
||||
} else {
|
||||
foreach ( wpcf7_convert_mime_to_ext( $accept ) as $ext ) {
|
||||
$acceptable_filetypes[] = sprintf(
|
||||
'.%s',
|
||||
strtolower( trim( $ext, ' .' ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$acceptable_filetypes = array_unique( $acceptable_filetypes );
|
||||
|
||||
foreach ( $input as $i ) {
|
||||
$last_period_pos = strrpos( $i, '.' );
|
||||
|
||||
if ( false === $last_period_pos ) { // no period
|
||||
return $this->create_error();
|
||||
}
|
||||
|
||||
$suffix = strtolower( substr( $i, $last_period_pos ) );
|
||||
|
||||
if ( ! in_array( $suffix, $acceptable_filetypes, true ) ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MaxDateRule extends Rule {
|
||||
|
||||
const rule_name = 'maxdate';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$input = $this->get_default_input();
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
$threshold = $this->get_property( 'threshold' );
|
||||
|
||||
if ( ! wpcf7_is_date( $threshold ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ( $input as $i ) {
|
||||
if ( wpcf7_is_date( $i ) and $threshold < $i ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MaxFileSizeRule extends Rule {
|
||||
|
||||
const rule_name = 'maxfilesize';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['file'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$field = $this->get_property( 'field' );
|
||||
$input = $_FILES[$field]['size'] ?? '';
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
if ( empty( $input ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$threshold = $this->get_property( 'threshold' );
|
||||
|
||||
if ( $threshold < array_sum( $input ) ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MaxItemsRule extends Rule {
|
||||
|
||||
const rule_name = 'maxitems';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$input = $this->get_default_input();
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
$threshold = $this->get_property( 'threshold' );
|
||||
|
||||
if ( ! wpcf7_is_number( $threshold ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( (int) $threshold < count( $input ) ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MaxLengthRule extends Rule {
|
||||
|
||||
const rule_name = 'maxlength';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$input = $this->get_default_input();
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
if ( empty( $input ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
|
||||
foreach ( $input as $i ) {
|
||||
$total += wpcf7_count_code_units( $i );
|
||||
}
|
||||
|
||||
$threshold = (int) $this->get_property( 'threshold' );
|
||||
|
||||
if ( $total <= $threshold ) {
|
||||
return true;
|
||||
} else {
|
||||
return $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MaxNumberRule extends Rule {
|
||||
|
||||
const rule_name = 'maxnumber';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$input = $this->get_default_input();
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
$threshold = $this->get_property( 'threshold' );
|
||||
|
||||
if ( ! wpcf7_is_number( $threshold ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ( $input as $i ) {
|
||||
if ( wpcf7_is_number( $i ) and (float) $threshold < (float) $i ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MinDateRule extends Rule {
|
||||
|
||||
const rule_name = 'mindate';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$input = $this->get_default_input();
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
$threshold = $this->get_property( 'threshold' );
|
||||
|
||||
if ( ! wpcf7_is_date( $threshold ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ( $input as $i ) {
|
||||
if ( wpcf7_is_date( $i ) and $i < $threshold ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MinFileSizeRule extends Rule {
|
||||
|
||||
const rule_name = 'minfilesize';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['file'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$field = $this->get_property( 'field' );
|
||||
$input = $_FILES[$field]['size'] ?? '';
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
if ( empty( $input ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$threshold = $this->get_property( 'threshold' );
|
||||
|
||||
if ( array_sum( $input ) < $threshold ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MinItemsRule extends Rule {
|
||||
|
||||
const rule_name = 'minitems';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$input = $this->get_default_input();
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
$threshold = $this->get_property( 'threshold' );
|
||||
|
||||
if ( ! wpcf7_is_number( $threshold ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( count( $input ) < (int) $threshold ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MinLengthRule extends Rule {
|
||||
|
||||
const rule_name = 'minlength';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$input = $this->get_default_input();
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
if ( empty( $input ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
|
||||
foreach ( $input as $i ) {
|
||||
$total += wpcf7_count_code_units( $i );
|
||||
}
|
||||
|
||||
$threshold = (int) $this->get_property( 'threshold' );
|
||||
|
||||
if ( $threshold <= $total ) {
|
||||
return true;
|
||||
} else {
|
||||
return $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class MinNumberRule extends Rule {
|
||||
|
||||
const rule_name = 'minnumber';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$input = $this->get_default_input();
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
$threshold = $this->get_property( 'threshold' );
|
||||
|
||||
if ( ! wpcf7_is_number( $threshold ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ( $input as $i ) {
|
||||
if ( wpcf7_is_number( $i ) and (float) $i < (float) $threshold ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class NumberRule extends Rule {
|
||||
|
||||
const rule_name = 'number';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$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 $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class RequiredRule extends Rule {
|
||||
|
||||
const rule_name = 'required';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$input = $this->get_default_input();
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
if ( empty( $input ) ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class RequiredFileRule extends Rule {
|
||||
|
||||
const rule_name = 'requiredfile';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['file'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$field = $this->get_property( 'field' );
|
||||
$input = $_FILES[$field]['tmp_name'] ?? '';
|
||||
$input = wpcf7_array_flatten( $input );
|
||||
$input = wpcf7_exclude_blank( $input );
|
||||
|
||||
if ( empty( $input ) ) {
|
||||
return $this->create_error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class TelRule extends Rule {
|
||||
|
||||
const rule_name = 'tel';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$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 $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class TimeRule extends 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 ) {
|
||||
$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 $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Contactable\SWV;
|
||||
|
||||
class URLRule extends Rule {
|
||||
|
||||
const rule_name = 'url';
|
||||
|
||||
public function matches( $context ) {
|
||||
if ( false === parent::matches( $context ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( empty( $context['text'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate( $context ) {
|
||||
$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 $this->create_error();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user