|
/** |
|
* Get submission value. |
|
* |
|
* @param WPCF7_Submission $submission Submission. |
|
* @param string $type Type to search for. |
|
* @return mixed |
|
*/ |
|
public static function get_submission_value( WPCF7_Submission $submission, $type ) { |
|
// phpcs:disable WordPress.Security.NonceVerification.Missing |
|
$result = null; |
|
|
|
$prefixed_type = 'pronamic_pay_' . $type; |
|
|
|
// Hidden fields. |
|
$hidden_fields = \filter_input( \INPUT_POST, '_wpcf7cf_hidden_group_fields' ); |
|
|
|
if ( ! empty( $hidden_fields ) ) { |
|
$hidden_fields = \json_decode( stripslashes( $hidden_fields ) ); |
|
} |
|
|
|
if ( ! \is_array( $hidden_fields ) ) { |
|
$hidden_fields = []; |
|
} |
|
|
|
// @link https://contactform7.com/tag-syntax/ |
|
$tags = WPCF7_FormTagsManager::get_instance()->get_scanned_tags(); |
|
|
|
foreach ( $tags as $tag ) { |
|
// Check if tag base type or name is requested type or tag has requested type as option. |
|
if ( ! \in_array( $tag->basetype, [ $type, $prefixed_type ], true ) && ! $tag->has_option( $prefixed_type ) && $prefixed_type !== $tag->name ) { |
|
continue; |
|
} |
|
|
|
// Check if field is not hidden. |
|
if ( \in_array( $tag->name, $hidden_fields, true ) ) { |
|
continue; |
|
} |
|
|
|
// Submission value. |
|
$value = $submission->get_posted_string( $tag->name ); |
|
|
|
if ( empty( $value ) ) { |
|
continue; |
|
} |
|
|
|
switch ( $type ) { |
|
case 'amount': |
|
/** |
|
* Contact Form 7 concatenates the field option value with user input for free text fields. We |
|
* are only interested in the input value as amount. |
|
* |
|
* @link https://github.com/rocklobster-in/contact-form-7/blob/2cfaa472fa485c6d3366fcdd80701fdaf7f9e425/includes/submission.php#L434-L437 |
|
*/ |
|
if ( \wpcf7_form_tag_supports( $tag->type, 'selectable-values' ) && $tag->has_option( 'free_text' ) ) { |
|
$values = \WPCF7_USE_PIPE ? $tag->pipes->collect_afters() : $tag->values; |
|
|
|
$last_value = end( $values ); |
|
|
|
if ( \str_starts_with( $value, $last_value . ' ' ) ) { |
|
$value = substr( $value, strlen( $last_value . ' ' ) ); |
|
} |
|
} |
|
|
|
$value = Tags\AmountTag::parse_value( $value ); |
|
|
|
// Set parsed value as result or add to existing money result. |
|
if ( null !== $value ) { |
|
$result = ( $result instanceof Money ? $result->add( $value ) : $value ); |
|
} |
|
|
|
break; |
|
default: |
|
$result = $value; |
|
} |
|
|
|
// Prefer tag with option (`pronamic_pay_email`) over tag name match (e.g. `email`). |
|
if ( $tag->has_option( $prefixed_type ) ) { |
|
return $result; |
|
} |
|
} |
|
|
|
// phpcs:enable WordPress.Security.NonceVerification.Missing |
|
|
|
return $result; |
|
} |