Completed
Push — staging ( 78e662...0f9e2f )
by
unknown
05:16
created

__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
*	Custom class to allow Easy Forms for Mailchimp to extend visual composer
5
*	@since 6.0.3
6
*/
7
8
class YIKES_Mailchimp_Visual_Composer_Extension {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
	/**
11
	 * Constructor
12
	 *
13
	 * @since 6.0.3
14
	 */
15
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
16
		
17
		add_action( 'admin_init', array( $this, 'extend_visual_composer' ) );
18
19
		if ( function_exists( 'vc_add_shortcode_param' ) ) {
20
			vc_add_shortcode_param( 'yikes_mailchimp_logo', array( $this, 'yikes_mailchimp_logo_vc_section' ) );
21
		}
22
	}
23
24
	/**
25
	 *    Extend Visual Composer with custom button
26
	 *
27
	 * @since 6.0.3
28
	 */
29
	public function extend_visual_composer() {
30
31
		if ( ! function_exists( 'vc_map' ) ) {
32
			return;
33
		}
34
35
		vc_map( array(
36
			'name'        => __( 'Easy Forms for Mailchimp', 'yikes-inc-easy-mailchimp-extender' ),
37
			'base'        => 'yikes-mailchimp',
38
			'icon'        => YIKES_MC_URL . 'includes/images/Mailchimp_Assets/yikes-mailchimp-welcome-logo.png',
39
			'category'    => 'Content',
40
			'description' => __( 'Display a Mailchimp Opt-In form', 'yikes-inc-easy-mailchimp-extender' ),
41
			'params'      => array(
42
				array(
43
					'type'        => 'yikes_mailchimp_logo',
44
					'holder'      => 'div',
45
					'class'       => '',
46
					'heading'     => '',
47
					'param_name'  => 'yikes_vc_logo',
48
					'value'       => '',
49
					'description' => '',
50
				),
51
				array(
52
					'type'        => 'dropdown',
53
					'holder'      => 'div',
54
					'class'       => '',
55
					'heading'     => __( 'Mailchimp Opt-In Form', 'yikes-inc-easy-mailchimp-extender' ),
56
					'param_name'  => 'form',
57
					'value'       => self::yikes_mailchimp_retreive_user_created_forms(),
58
					'description' => __( 'Select which form to display.', 'yikes-inc-easy-mailchimp-extender' ),
59
					'save_always' => true,
60
				),
61
				array(
62
					'type'        => 'checkbox',
63
					'holder'      => 'div',
64
					'class'       => '',
65
					'heading'     => __( 'Display Form Title', 'yikes-inc-easy-mailchimp-extender' ),
66
					'param_name'  => 'title',
67
					'value'       => array(
68
						__( 'Yes', 'yikes-inc-easy-mailchimp-extender' ) => '1',
69
					),
70
					'description' => __( 'Should this form display the title.', 'yikes-inc-easy-mailchimp-extender' ),
71
				),
72
				array(
73
					'type'        => 'checkbox',
74
					'holder'      => 'div',
75
					'class'       => '',
76
					'heading'     => __( 'Display Form Description', 'yikes-inc-easy-mailchimp-extender' ),
77
					'param_name'  => 'description',
78
					'value'       => array(
79
						__( 'Yes', 'yikes-inc-easy-mailchimp-extender' ) => '1',
80
					),
81
					'description' => __( 'Should this form display the description.', 'yikes-inc-easy-mailchimp-extender' ),
82
				),
83
				array(
84
					'type'        => 'textfield',
85
					'holder'      => 'div',
86
					'class'       => '',
87
					'heading'     => __( 'Submit Button Text', 'yikes-inc-easy-mailchimp-extender' ),
88
					'param_name'  => 'submit',
89
					'value'       => __( 'Submit', 'yikes-inc-easy-mailchimp-extender' ),
90
					'description' => __( 'Enter a title to display', 'yikes-inc-easy-mailchimp-extender' ),
91
				),
92
			),
93
		) );
94
	}
95
96
	/**
97
	 * Custom Callback Section
98
	 *
99
	 * @since 6.0.3
100
	 */
101
	public function yikes_mailchimp_logo_vc_section() {
102
		return '<img style="width:250px;display:block;margin:0 auto;" src="' . YIKES_MC_URL . 'includes/images/Mailchimp_Assets/mailchimp-logo.png" title="' . __( 'Easy Forms for Mailchimp', 'yikes-inc-easy-mailchimp-extender' ) . '" />';
103
	}
104
105
	/**
106
	 *    Retreive a list of forms created by the user that they can select from in the dropdown
107
	 *
108
	 * @since 6.0.3
109
	 */
110
	public function yikes_mailchimp_retreive_user_created_forms() {
111
		$interface = yikes_easy_mailchimp_extender_get_form_interface();
112
		$all_forms = $interface->get_all_forms();
113
114
		$lists = array();
115
		if ( ! empty( $all_forms ) ) {
116
			// build an array to pass to our javascript
117
			foreach ( $all_forms as $id => $form ) {
118
				$lists[ $form['form_name'] ] = $id;
119
			}
120
		} else {
121
			$lists[ __( 'Please Import Some Mailchimp Lists', 'yikes-inc-easy-mailchimp-extender' ) ] = '-';
122
		}
123
124
		return $lists;
125
	}
126
}
127