Plugin Updates
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user