| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
/** |
| 10 |
* Class ConditionalFields Support |
| 11 |
* Add support for conditional fields if available. |
| 12 |
* |
| 13 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 14 |
*/ |
| 15 |
class ConditionalFields |
| 16 |
{ |
| 17 |
private $conditionalFieldsParameter = array( |
| 18 |
'_wpcf7cf_hidden_group_fields' => '', |
| 19 |
'_wpcf7cf_hidden_groups' => '', |
| 20 |
'_wpcf7cf_visible_groups' => '', |
| 21 |
'_wpcf7cf_repeaters' => '', |
| 22 |
'_wpcf7cf_steps' => '', |
| 23 |
'_wpcf7cf_options' => '' |
| 24 |
); |
| 25 |
|
| 26 |
/** |
| 27 |
* Admin constructor. |
| 28 |
*/ |
| 29 |
public function __construct() |
| 30 |
{ |
| 31 |
add_filter('f12_cf7_doubleoptin_add_request_parameter', array($this,'_initConditionalFieldParameter'), 10, 1); |
| 32 |
add_filter('f12_cf7_doubleoptin_body', array($this, '_getOptinBody'), 10, 1); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Add the option to add conditional fields also to the optin mail. |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
public function _getOptinBody($body) |
| 40 |
{ |
| 41 |
if(!defined('WPCF7CF_PLUGIN') || !class_exists('\Wpcf7cfMailParser')){ |
| 42 |
return $body; |
| 43 |
} |
| 44 |
|
| 45 |
$CFMP = new \Wpcf7cfMailParser($body, $this->conditionalFieldsParameter['_wpcf7cf_visible_groups'], $this->conditionalFieldsParameter['_wpcf7cf_hidden_groups'], $this->conditionalFieldsParameter['_wpcf7cf_repeaters'], array()); |
| 46 |
return $CFMP->getParsedMail(); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Check if conditional field plugin is available and if yes, check for the parameter |
| 51 |
* which has to be stored within the content. |
| 52 |
* @param $parameter |
| 53 |
*/ |
| 54 |
public function _initConditionalFieldParameter($parameter) |
| 55 |
{ |
| 56 |
if (!defined('WPCF7CF_PLUGIN')) { |
| 57 |
return $parameter; |
| 58 |
} |
| 59 |
|
| 60 |
foreach ($this->conditionalFieldsParameter as $key => $value) { |
| 61 |
if (isset($_POST[$key])) { |
| 62 |
$parameter[$key] = sanitize_text_field($_POST[$key]); |
| 63 |
$this->conditionalFieldsParameter[$key] = sanitize_text_field(json_decode(stripslashes($_POST[$key]))); |
| 64 |
} |
| 65 |
} |
| 66 |
return $parameter; |
| 67 |
} |
| 68 |
} |
| 69 |
} |