|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Handle Contact Form 7 Integration: create a [yikes_mailchimp_checkbox] shortcode for use in CF7 form building. |
|
4
|
|
|
* |
|
5
|
|
|
* @since 6.0.0 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
// Prevent direct access to the file. |
|
9
|
|
|
defined( 'ABSPATH' ) || die( esc_html_e( "Whoops, you shouldn't be accessing this file directly. Abort!", 'yikes-inc-easy-mailchimp-extender' ) ); |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Handle Contact Form 7 Integration. |
|
13
|
|
|
*/ |
|
14
|
|
|
class Yikes_Easy_MC_CF7_Checkbox_Class extends Yikes_Easy_MC_Checkbox_Integration_Class { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The integration type. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string $type |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $type = 'contact_form_7'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Constructor. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct() { |
|
27
|
|
|
$this->init(); |
|
28
|
|
|
add_action( 'wpcf7_mail_sent', array( $this, 'new_cf7_subscription' ) ); |
|
29
|
|
|
add_action( 'wpcf7_posted_data', array( $this, 'alter_cf7_data' ) ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Registers the CF7 shortcode. |
|
34
|
|
|
* |
|
35
|
|
|
* @return boolean True if we were able to register the shortcode. |
|
36
|
|
|
*/ |
|
37
|
|
|
public function init() { |
|
38
|
|
|
if ( ! function_exists( 'wpcf7_add_form_tag' ) ) { |
|
39
|
|
|
return false; |
|
40
|
|
|
} |
|
41
|
|
|
return wpcf7_add_form_tag( 'yikes_mailchimp_checkbox', array( $this, 'yikes_get_checkbox' ) ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Add yikes_mailchimp_checkbox to post data as "Yes" or "No." |
|
46
|
|
|
* |
|
47
|
|
|
* @param array $data CF7 posted data. |
|
48
|
|
|
* @return array $data CF7 posted data. |
|
49
|
|
|
*/ |
|
50
|
|
|
public function alter_cf7_data( $data = array() ) { |
|
51
|
|
|
$data['yikes_mailchimp_checkbox'] = $this->was_checkbox_checked( $this->type ) ? __( 'Yes', 'yikes-inc-easy-mailchimp-extender' ) : __( 'No', 'yikes-inc-easy-mailchimp-extender' ); |
|
52
|
|
|
return $data; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Subscribe the user if they so chose. |
|
57
|
|
|
* |
|
58
|
|
|
* @param Object $contact_form The CF7 object. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function new_cf7_subscription( $contact_form ) { |
|
61
|
|
|
if ( false === $this->was_checkbox_checked( $this->type ) ) { |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
$integration_options = get_option( 'optin-checkbox-init', '' ); |
|
|
|
|
|
|
65
|
|
|
$submission = WPCF7_Submission::get_instance(); |
|
66
|
|
|
if ( $submission ) { |
|
67
|
|
|
$data = $submission->get_posted_data(); |
|
68
|
|
|
$email = isset( $data['your-email'] ) ? $data['your-email'] : ''; |
|
69
|
|
|
$fields = array( 'email' => $email ); |
|
70
|
|
|
$addl_vars = apply_filters( 'yikes_mailchimp_checkbox_integration_additional_vars', array( 'cf7_data' => $data, 'contact_form' => $contact_form ), $this->type ); |
|
71
|
|
|
$this->subscribe_user_integration( $email, $this->type, apply_filters( 'yikes-mailchimp-contact-form-7', $fields, $data ), $addl_vars ); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
$yikes_easy_mc_cf7_checkbox_class = new Yikes_Easy_MC_CF7_Checkbox_Class(); |
|
76
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.