Completed
Push — staging ( 99a729...9693fc )
by
unknown
19:21
created

Yikes_Inc_Easy_Mailchimp_Forms_Admin   F

Complexity

Total Complexity 391

Size/Duplication

Total Lines 2949
Duplicated Lines 5.12 %

Coupling/Cohesion

Components 3
Dependencies 10

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 151
loc 2949
ccs 0
cts 1136
cp 0
rs 0.8
c 0
b 0
f 0
wmc 391
lcom 3
cbo 10

64 Methods

Rating   Name   Duplication   Size   Complexity  
F hooks() 0 189 28
B get_premium_license() 0 17 7
A __construct() 0 9 1
A easy_forms_plugin_action_links() 0 5 1
A yikes_easy_forms_admin_disclaimer() 0 10 3
B parse_mailchimp_default_tag() 0 32 9
A yikes_easy_mailchimp_clear_error_log() 0 21 3
A yikes_easy_mailchimp_export_forms() 3 17 3
A yikes_easy_mailchimp_export_plugin_settings() 3 15 2
A yikes_easy_mailchimp_import_forms() 3 19 3
F yikes_easy_mailchimp_premium_support_request() 0 45 12
A load_error_logging_class() 8 8 2
A yikes_easy_mailchimp_check_installation_date() 0 20 5
F yikes_easy_mailchimp_display_review_us_notice() 0 39 13
A yikes_easy_mailchimp_stop_bugging_me() 0 5 3
A display_php_warning() 0 4 1
A add_tinyMCE_buttons() 0 9 2
A yks_mc_add_tinymce_button() 0 5 1
A yks_mc_add_tinymce_plugin() 0 6 1
A tinymce_yikes_easy_mc() 0 36 4
A fix_menu_icon_spacing() 0 9 1
A enqueue_styles() 0 13 2
B enqueue_scripts() 0 59 3
D yikes_jQuery_datepicker_date_format_php_to_js() 47 53 25
A yikes_jQuery_datepicker_date_format() 0 16 5
B register_admin_pages() 0 107 1
A generateAddOnsPage() 0 3 1
A generateManageFormsPage() 0 3 1
A generateManageListsPage() 0 3 1
A generateSupportPage() 0 5 1
A generateEditFormPage() 0 3 1
A generateViewListPage() 0 3 1
A generateViewUserPage() 0 3 1
B yikes_easy_mc_settings_init() 0 141 1
A yikes_mc_validate_api_key() 0 29 4
A generatePageOptions() 0 3 1
A is_user_mc_api_valid_form() 0 13 4
A findMCListID() 0 8 3
F generate_options_pages_sidebar_menu() 0 48 19
D generate_manage_forms_sidebar() 0 99 13
B generate_page_redirect_dropdown() 0 66 9
B generate_show_some_love_container() 0 78 4
F generate_form_editor() 42 714 92
B build_available_merge_vars() 5 41 9
B build_available_interest_groups() 5 41 9
A build_available_tags() 0 27 5
A yikes_easy_mailchimp_create_form() 0 25 3
A yikes_easy_mailchimp_delete_form() 3 15 2
A yikes_easy_mailchimp_duplicate_form() 10 39 3
A yikes_easy_mailchimp_reset_impression_stats() 10 27 3
F yikes_easy_mailchimp_update_form() 3 118 18
A generate_default_email_body() 0 21 1
A yikes_easy_mailchimp_unsubscribe_user() 3 23 3
A yikes_easy_mailchimp_create_missing_error_log() 3 19 3
B yikes_easy_mailchimp_clear_transient_data() 3 26 8
A get_mailchimp_list_ids_on_account() 0 18 4
A yikes_mailchimp_load_helper_class() 0 7 2
B alter_yikes_easy_mc_color_scheme() 0 48 9
A display_support_page_content() 0 15 2
A check_yikes_mc_table_version() 0 9 2
A process_subscriber_count_shortcode_in_form_descriptions() 0 4 1
A generate_edit_forms_upsell_ad() 0 12 3
A delete_yikes_mailchimp_transients() 0 20 2
A register_optin_widget() 0 3 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Yikes_Inc_Easy_Mailchimp_Forms_Admin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Yikes_Inc_Easy_Mailchimp_Forms_Admin, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * The admin-specific functionality of the plugin.
4
 *
5
 * Defines the plugin name, version, and two examples hooks for how to
6
 * enqueue the admin-specific stylesheet and JavaScript.
7
 *
8
 * @package    Yikes_Inc_Easy_Mailchimp_Forms
9
 * @subpackage Yikes_Inc_Easy_Mailchimp_Forms/admin
10
 * @author     YIKES, Inc. <[email protected]>
11
 */
12
class Yikes_Inc_Easy_Mailchimp_Forms_Admin {
13
14
	/**
15
	 * The ID of this plugin.
16
	 *
17
	 * @since    1.0.0
18
	 * @access   private
19
	 * @var      string    $yikes_inc_easy_mailchimp_extender    The ID of this plugin.
20
	 */
21
	private $yikes_inc_easy_mailchimp_extender;
22
23
	/**
24
	 * The version of this plugin.
25
	 *
26
	 * @since    1.0.0
27
	 * @access   private
28
	 * @var      string    $version    The current version of this plugin.
29
	 */
30
	private $version;
31
32
	/**
33
	 * Our form interface instance.
34
	 *
35
	 * @var Yikes_Inc_Easy_Mailchimp_Extender_Form_Interface
36
	 */
37
	private $form_interface;
38
39
	/**
40
	 * Initialize the class and set its properties.
41
	 *
42
	 * @since    1.0.0
43
	 *
44
	 * @param string                                           $yikes_inc_easy_mailchimp_extender The name of this plugin.
45
	 * @param string                                           $version                           The version of this plugin.
46
	 * @param Yikes_Inc_Easy_Mailchimp_Extender_Form_Interface $form_interface
47
	 */
48
	public function __construct(
49
		$yikes_inc_easy_mailchimp_extender,
50
		$version,
51
		Yikes_Inc_Easy_Mailchimp_Extender_Form_Interface $form_interface
52
	) {
53
		$this->yikes_inc_easy_mailchimp_extender = $yikes_inc_easy_mailchimp_extender;
54
		$this->version                           = $version;
55
		$this->form_interface                    = $form_interface;
56
	}
57
58
	/**
59
	 * Our admin hooks.
60
	 *
61
	 * @author Jeremy Pry
62
	 */
63
	public function hooks() {
64
65
		// Register admin pages.
66
		add_action( 'admin_menu', array( $this, 'register_admin_pages' ), 11 );
67
68
		// fix menu icon spacing.
69
		add_action( 'admin_head', array( $this, 'fix_menu_icon_spacing' ) );
70
71
		// register our plugin settings.
72
		add_action( 'admin_init', array( $this, 'yikes_easy_mc_settings_init' ) );
73
74
		// Include Third Party Extensions.
75
		new YIKES_Mailchimp_ThirdParty_Integrations();
76
77
		// Include our dashboard widget class.
78
		new YIKES_Inc_Easy_Mailchimp_Dashboard_Widgets();
79
80
		// Include our front end widget class.
81
		add_action( 'widgets_init', array( $this, 'register_optin_widget' ) );
82
83
		// Include our ajax processing class.
84
		new YIKES_Inc_Easy_Mailchimp_Process_Ajax();
85
86
		// load up our helper class.
87
		add_action( 'admin_init', array( $this, 'yikes_mailchimp_load_helper_class' ) );
88
89
		// process the subscriber count shortcode in form descriptions.
90
		add_action( 'yikes-mailchimp-form-description', array( $this, 'process_subscriber_count_shortcode_in_form_descriptions' ), 10, 2 );
91
92
		/***********************/
93
		/** Create A Form **/
94
		/**********************/
95
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-create-form' ) {
96
97
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_create_form' ) );
98
99
		}
100
101
		/***********************/
102
		/** Delete A Form **/
103
		/**********************/
104
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-delete-form' ) {
105
106
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_delete_form' ) );
107
108
		}
109
110
		/**********************************/
111
		/** Duplicate/Clone A Form    **/
112
		/********************************/
113
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-duplicate-form' ) {
114
115
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_duplicate_form' ) );
116
117
		}
118
119
		/*************************************/
120
		/**  Reset Form Impression Stats **/
121
		/***********************************/
122
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-reset-stats' ) {
123
124
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_reset_impression_stats' ) );
125
126
		}
127
128
		/**********************************/
129
		/**         Update A Form        **/
130
		/********************************/
131
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-update-form' ) {
132
133
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_update_form' ) );
134
135
		}
136
137
		/**************************************************/
138
		/**     Clear Store Mailchimp Transient Data   **/
139
		/*************************************************/
140
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-clear-transient-data' ) {
141
142
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_clear_transient_data' ) );
143
144
		}
145
146
		/*******************************************/
147
		/** Remove a user from a mailing list     **/
148
		/*****************************************/
149
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-unsubscribe-user' ) {
150
151
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_unsubscribe_user' ) );
152
153
		}
154
155
		/*******************************************/
156
		/**    Create misisng error log file  **/
157
		/*****************************************/
158
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-create-error-log' ) {
159
160
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_create_missing_error_log' ) );
161
162
		}
163
164
		/*******************************************/
165
		/**   TinyMCE Initialization Functions     **/
166
		/*****************************************/
167
		add_action( 'admin_head', array( $this, 'add_tinyMCE_buttons' ) );
168
169
		// pass our lists data to tinyMCE button for use.
170
		foreach ( array( 'post.php', 'post-new.php' ) as $hook ) {
171
172
			add_action( 'admin_enqueue_scripts', array( $this, 'tinymce_yikes_easy_mc' ) );
173
174
		}
175
176
		// display an admin notice for users on PHP < 5.3.
177
		if ( phpversion() < '5.3' ) {
178
			add_action( "admin_notices", array( $this, 'display_php_warning' ), 999 );
179
		}
180
181
		// two week , dismissable notification - check the users plugin installation date.
182
		add_action( 'admin_init', array( $this, 'yikes_easy_mailchimp_check_installation_date' ) );
183
184
		// dismissable notice admin side.
185
		add_action( 'admin_init', array( $this, 'yikes_easy_mailchimp_stop_bugging_me' ), 5 );
186
187
		/**************************************************/
188
		/**        Clear Mailchimp Error Log Data        **/
189
		/*************************************************/
190
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-clear-error-log' ) {
191
192
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_clear_error_log' ) );
193
194
		}
195
196
		/*********************************************/
197
		/**        Export Mailchimp Opt-in Forms   **/
198
		/*******************************************/
199
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-export-forms' ) {
200
201
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_export_forms' ) );
202
203
		}
204
205
		/*********************************************/
206
		/**                Export Plugin Settings           **/
207
		/*******************************************/
208
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-export-settings' ) {
209
210
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_export_plugin_settings' ) );
211
212
		}
213
214
		/*******************************************/
215
		/**        Import Class Inclusion       **/
216
		/*****************************************/
217
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yikes-easy-mc-import-forms' ) {
218
219
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_import_forms' ) );
220
221
		}
222
223
		/*******************************************/
224
		/**    Premium Support Request     **/
225
		/*****************************************/
226
		if ( isset( $_POST['submit-premium-support-request'] ) ) {
227
228
			add_action( 'init', array( $this, 'yikes_easy_mailchimp_premium_support_request' ) );
229
230
		}
231
232
		/** Parse default value into usable dynamic data **/
233
		add_filter( 'yikes-mailchimp-process-default-tag', array( $this, 'parse_mailchimp_default_tag' ) );
234
235
		/** Add a disclaimer to ensure that we let people know we are not endorsed/backed by Mailchimp at all **/
236
		add_filter( 'admin_footer_text', array( $this, 'yikes_easy_forms_admin_disclaimer' ) );
237
238
		/** Add custom plugin action links **/
239
		add_filter( 'plugin_action_links_yikes-inc-easy-mailchimp-extender/yikes-inc-easy-mailchimp-extender.php', array( $this, 'easy_forms_plugin_action_links' ) );
240
241
		/* Alter the color scheme based on the users selection */
242
		add_action( 'admin_print_scripts', array( $this, 'alter_yikes_easy_mc_color_scheme' ) );
243
244
		// Display our premium support page if we have add-ons.
245
		add_action( 'yikes-mailchimp-support-page', array( $this, 'display_support_page_content' ), 40 );
246
247
		// ensure that the upgrade went smoothly, else we have to let the user know we need to upgrade the database.
248
		// after upgrading f rom 6.0.3.7 users need to upgrade the database as well
249
		add_action( 'plugins_loaded', array( $this, 'check_yikes_mc_table_version' ) );
250
251
	}
252
253
		/**
254
		 * Add custom action links on plugins.php
255
		 * @ param  array  $links  Pre-existing plugin action links
256
		 * @ return array  $links  New array of plugin actions
257
		 */
258
		public function easy_forms_plugin_action_links( $links ) {
259
			$links[] = '<a href="'. esc_url( get_admin_url(null, 'admin.php?page=yikes-inc-easy-mailchimp-settings') ) .'">' . __( 'Settings', 'yikes-inc-easy-mailchimp-extender' ) . '</a>';
260
			$links[] = '<a href="' . esc_url( 'http://www.yikesplugins.com?utm_source=plugins-page&utm_medium=plugin-row&utm_campaign=admin' ) . '" target="_blank">' . __( 'More plugins by YIKES, Inc.', 'yikes-inc-easy-mailchimp-extender' ) . '</a>';
261
			return $links;
262
		}
263
264
		/**
265
		 * Add a disclaimer to the admin footer for all YIKES pages to ensure that users understand there is no correlation between this plugin and Mailchimp.
266
		 * This plugin simply provides the service of linking Mailchimp with your site.
267
		 *
268
		 * @since  6.0
269
		 *
270
		 * @param  string $footer_text The existing footer text.
271
		 *
272
		 * @return string
273
		 */
274
		public function yikes_easy_forms_admin_disclaimer( $footer_text ) {
275
			$page = get_current_screen();
276
			$base = $page->base;
277
			if ( strpos( $base, 'yikes-inc-easy-mailchimp' ) !== false || strpos( $base, 'yikes-mailchimp' ) !== false ) {
278
				$disclaimer_text = sprintf( '<em>' . __( 'Disclaimer: <strong>Easy Forms for Mailchimp</strong> is in no way endorsed, affiliated or backed by Mailchimp, or its parent company Rocket Science Group.', 'yikes-inc-easy-mailchimp-extender' ), '<a href="https://wordpress.org/support/view/plugin-reviews/give?filter=5#postform" target="_blank" class="give-rating-link" data-rated="' . __( 'Thanks :)', 'yikes-inc-easy-mailchimp-extender' ) . '">', '</a></em>' );
279
				return $disclaimer_text;
280
			} else {
281
				return $footer_text;
282
			}
283
		}
284
285
		/*
286
		*	Parse our default tag into dynamic data
287
		*	to be passed to Mailchimp
288
		*
289
		*	@since 6.0.0
290
		*	@return	parsed tag content
291
		*/
292
		public function parse_mailchimp_default_tag( $default_tag ) {
293
			if ( ! $default_tag || $default_tag == '' ) {
294
				return $default_tag;
295
			}
296
			global $post;
297
			// page title.
298
			if ( $default_tag == '{page_title}' ) {
299
				$default_tag = get_the_title( $post->ID );
300
			}
301
			// page id.
302
			if ( $default_tag == '{page_id}' ) {
303
				$default_tag = $post->ID;
304
			}
305
			// page url.
306
			if ( $default_tag == '{page_url}' ) {
307
				$default_tag = get_permalink( $post->ID );
308
			}
309
			// blog name.
310
			if ( $default_tag == '{blog_name}' ) {
311
				$default_tag = get_bloginfo( 'name' );
312
			}
313
			// is user logged in.
314
			if ( $default_tag == '{user_logged_in}' ) {
315
				if ( is_user_logged_in() ) {
316
					$default_tag = 'Registered User';
317
				} else {
318
					$default_tag = 'Guest User';
319
				}
320
			}
321
			/* Return our filtered tag */
322
			return apply_filters( 'yikes-mailchimp-parse-custom-default-value', $default_tag );
323
		}
324
325
		/*
326
		*	Delete the contents of our error log
327
		*
328
		*	When a user clicks 'Clear Log' on the debug settings page, this funciton
329
		*	is used to clear the data out of our php file.
330
		*/
331
		public function yikes_easy_mailchimp_clear_error_log() {
332
333
			// Get our error log class.
334
			$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
335
336
			// file put contents $returned error + other data.
337
			if ( file_exists( $error_logging->error_log_file_path ) ) {
338
339
				$clear_log = file_put_contents( $error_logging->error_log_file_path, '' );
340
341
				if ( $clear_log === false ) {
342
343
					// redirect the user to the manage forms page, display error message.
344
					wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=debug-settings&error-log-cleared=false' ) ) );
345
				} else {
346
347
					// redirect the user to the manage forms page, display confirmation.
348
					wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=debug-settings&error-log-cleared=true' ) ) );
349
				}
350
			}
351
		}
352
353
		/*
354
		*	Custom export function to export all or specific forms
355
		*	to allow for easy transpot to other sites
356
		*	@since 		6.0.0
357
		*	@return 	CSV export file
358
		*/
359
		public function yikes_easy_mailchimp_export_forms() {
360
			// grab our nonce.
361
			$nonce = $_REQUEST['nonce'];
362
			// grab the forms.
363
			$forms = isset( $_REQUEST['yikes_export_forms'] ) ? $_REQUEST['yikes_export_forms'] : array();
364
			// validate nonce.
365 View Code Duplication
			if ( ! wp_verify_nonce( $nonce, 'export-forms' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
366
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) );
367
			}
368
369
			// run the export function.
370
			// parameters: ( $table_name, $form_ids, $file_name ).
371
			Yikes_Inc_Easy_Mailchimp_Export_Class::yikes_mailchimp_form_export('Yikes-Inc-Easy-Mailchimp-Forms-Export', $forms );
372
			// re-direct the user back to the page.
373
			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=import-export-forms' ) ) );
374
			die();
375
		}
376
377
		/*
378
		*	Custom export function to export YIKES Easy Forms for Mailchimp Plugin Settings
379
		*	to allow for easy transpot to other sites
380
		*	@since 		6.0.0
381
		*	@return 	CSV export file
382
		*/
383
		public function yikes_easy_mailchimp_export_plugin_settings() {
384
			// grab our nonce
385
			$nonce = $_REQUEST['nonce'];
386
			// validate nonce.
387 View Code Duplication
			if ( ! wp_verify_nonce( $nonce, 'export-settings' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
388
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) );
389
			}
390
391
			// run the export function.
392
			// parameters: ( $table_name, $form_ids, $file_name ).
393
			Yikes_Inc_Easy_Mailchimp_Export_Class::yikes_mailchimp_settings_export( 'Yikes-Inc-Easy-Mailchimp-Settings-Export' );
394
			// re-direct the user back to the page.
395
			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=import-export-forms' ) ) );
396
			die();
397
		}
398
399
		/*
400
		*	Custom import function to import all or specific forms
401
		*	@since 6.0.0
402
		*/
403
		public function yikes_easy_mailchimp_import_forms() {
404
			// grab our nonce.
405
			$nonce = $_REQUEST['nonce'];
406
			// validate nonce.
407 View Code Duplication
			if ( ! wp_verify_nonce( $nonce, 'import-forms' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
408
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) );
409
			}
410
			// include the export class.
411
			if ( ! class_exists( 'Yikes_Inc_Easy_Mailchimp_Import_Class' ) ) {
412
				include_once( YIKES_MC_PATH . 'includes/import-export/yikes-easy-mailchimp-import.class.php' );
413
			}
414
			// run the import function.
415
			// parameters: ( $_FILES ).
416
			Yikes_Inc_Easy_Mailchimp_Import_Class::yikes_mailchimp_import_forms( $_FILES );
417
			$import_query_arg = Yikes_Inc_Easy_Mailchimp_Import_Class::yikes_mailchimp_import_type( $_FILES );
418
			// re-direct the user back to the page.
419
			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=import-export-forms&' . $import_query_arg . '=true' ) ) );
420
			die();
421
		}
422
423
		/*
424
		*	Premium Support Request
425
		*	@since 6.0.0
426
		*/
427
		public function yikes_easy_mailchimp_premium_support_request() {
428
429
			if ( isset( $_POST['action'] ) && $_POST['action'] != 'yikes-support-request' ) {
430
				return __( 'We encountered an error. Please contact the YIKES Inc. support team.', 'yikes-inc-easy-mailchimp-extender' );
431
			}
432
433
			$email       = isset( $_POST['user-email'] ) ? $_POST['user-email'] : '';
434
			$topic       = isset( $_POST['support-topic'] ) ? $_POST['support-topic'] : '';
435
			$issue       = isset( $_POST['support-content'] ) ? $_POST['support-content'] : '';
436
			$priority    = isset( $_POST['support-priority'] ) ? $_POST['support-priority'] : 1;
437
			$license     = isset( $_POST['license_key'] ) ? $_POST['license_key'] : '';
438
			$plugin_name = isset( $_POST['plugin-name'] ) ? $_POST['plugin-name'] : '';
439
			$plugin_slug = isset( $_POST['plugin-slug'] ) ? $_POST['plugin-slug'] : '';
440
			$name        = isset( $_POST['user-name'] ) ? $_POST['user-name'] : 'Mailchimp Support';
441
442
			$edd_item_id = $this->get_premium_license( $plugin_slug );
443
444
			$ticket_array = array(
445
				'action'           => 'yikes-support-request',
446
				'license_key'      => base64_encode( $license ),
447
				'plugin_name'      => $plugin_name,
448
				'edd_item_id'      => $edd_item_id,
449
				'user_email'       => $email,
450
				'site_url'         => esc_url( home_url() ),
451
				'support_name'     => $name,
452
				'support_topic'    => $topic,
453
				'support_priority' => $priority,
454
				'support_content'  => $issue,
455
				'api_version'      => '2'
456
			);
457
458
			$response = wp_remote_post( 'https://yikesplugins.com', array(
459
				'timeout'   => 30,
460
				'sslverify' => false,
461
				'body'      => $ticket_array
462
			) );
463
464
			// Catch the error.
465
			if ( is_wp_error( $response ) ) {
466
				wp_send_json_error( $response->getMessage() );
467
			}
468
469
			// Retrieve our body.
470
			$response_body = json_decode( wp_remote_retrieve_body( $response ) );
0 ignored issues
show
Unused Code introduced by
$response_body is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
471
		}
472
473
		public function get_premium_license( $plugin_slug ) {
474
475
			switch( $plugin_slug ) {
476
477
				case 'form-customizer':
478
					return defined( 'YIKES_CUSTOMIZER_EDD_ITEM_ID' ) ? YIKES_CUSTOMIZER_EDD_ITEM_ID : '';
479
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
480
481
				case 'incentive-attachments':
482
					return defined( 'YIKES_INCENTIVES_EDD_ITEM_ID' ) ? YIKES_INCENTIVES_EDD_ITEM_ID : '';
483
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
484
485
				case 'popups':
486
					return defined( 'YIKES_MC_POPUP_EDD_ITEM_ID' ) ? YIKES_MC_POPUP_EDD_ITEM_ID : '';
487
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
488
			}
489
		}
490
491
		/**
492
		 * Error logging class
493
		 *
494
		 * This is our main error logging class file, used to log errors to the error log.
495
		 *
496
		 * @since 6.0.0
497
		 */
498 View Code Duplication
		public function load_error_logging_class() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
499
			if ( get_option( 'yikes-mailchimp-debug-status', '' ) == '1' ) {
500
				// if error logging is enabled we should include our error logging class
501
				/* Generate oure error logging table */
502
				require_once YIKES_MC_PATH . '/includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php';
503
				$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
0 ignored issues
show
Unused Code introduced by
$error_logging is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
504
			}
505
		}
506
507
		/**
508
		 * yikes_easy_mailchimp_check_installation_date()
509
		 * checks the user installation date, and adds our action
510
		 * - if it's past 2 weeks we ask the user for a review :)
511
		 *
512
		 * @since v6.0.0
513
		 */
514
		public function yikes_easy_mailchimp_check_installation_date() {
515
516
			// add a new option to store the plugin activation date/time.
517
			// @since v6.0.0.
518
			// this is used to notify the user that they should review after 2 weeks.
519
			if ( !get_option( 'yikes_easy_mailchimp_activation_date' ) ) {
520
				add_option( 'yikes_easy_mailchimp_activation_date', strtotime( "now" ) );
521
			}
522
523
			$stop_bugging_me = get_option( 'yikes_easy_mailchimp_review_stop_bugging_me' );
524
525
			if ( ! $stop_bugging_me ) {
526
				$install_date = get_option( 'yikes_easy_mailchimp_activation_date' );
527
				$past_date = strtotime( '-14 days' );
528
				if ( $past_date >= $install_date && current_user_can( 'install_plugins' ) ) {
529
					add_action( 'admin_notices', array( $this , 'yikes_easy_mailchimp_display_review_us_notice' ) );
530
				}
531
			}
532
533
		}
534
535
		/*
536
			Display our admin notification
537
			asking for a review, and for user feedback
538
			@since v6.0.0
539
		*/
540
		public function yikes_easy_mailchimp_display_review_us_notice() {
541
			/* Lets only display our admin notice on YT4WP pages to not annoy the hell out of people :) */
542
			if ( in_array( get_current_screen()->base , array( 'dashboard', 'post', 'edit' ) ) || strpos( get_current_screen()->base ,'yikes-inc-easy-mailchimp') !== false ) {
543
544
				// The URL of the page the user is currently on 
545
				$current_uri  	  = isset( $_SERVER['REQUEST_URI'] ) && ! empty( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : false;
546
				$current_host	  = isset( $_SERVER['HTTP_HOST'] ) && ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : false;
547
				$current_protocol = is_ssl() === true ? 'https://' : 'http://';
548
				$current_url	  = ( $current_uri !== false && $current_host !== false ) ? $current_protocol . $current_host . $current_uri : admin_url();
549
550
				$plugin_name = '<strong>Easy Forms for Mailchimp</strong>';
551
				// Review URL - Change to the URL of your plugin on WordPress.org.
552
				$reviewurl = 'https://wordpress.org/support/view/plugin-reviews/yikes-inc-easy-mailchimp-extender';
553
				$addons_url = esc_url( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-addons' ) );
554
				$nobugurl = esc_url_raw( add_query_arg( 'yikes_easy_mc_icons_nobug', '1', $current_url ) );
555
556
				// Make sure all of our variables have values.
557
				$reviewurl  = ( ! empty( $reviewurl ) ) ? $reviewurl : '';
558
				$addons_url = ( ! empty( $addons_url ) ) ? $addons_url : '';
559
				$nobugurl	= ( ! empty( $nobugurl ) ) ? $nobugurl : '';
560
561
				$review_message = '<div id="yikes-mailchimp-logo"></div>';
562
				$review_message .= sprintf( 
563
					__( 'It looks like you\'ve been using %1$s for 2 weeks now. We hope you\'re enjoying the features included with the free version. If so, please consider leaving us a review. Reviews only help to catch other users attention as well as provide us with feedback to grow and improve upon. If you\'re really enjoying the plugin, consider buying an add-on or developer license for some really awesome features and premium support.', 'yikes-inc-easy-mailchimp-extender' ) 
564
					. '<span class="button-container"> <a href="%2$s" target="_blank" class="button-secondary"><span class="dashicons dashicons-star-filled"></span>'
565
						. __( "Leave A Review" , 'yikes-inc-easy-mailchimp-extender' ) 
566
					. '</a> <a href="%3$s" class="button-secondary"><span class="dashicons dashicons-upload"></span>'
567
						. __( "View Addons" , 'yikes-inc-easy-mailchimp-extender' ) 
568
					. '</a> <a href="%4$s" class="button-secondary"><span class="dashicons dashicons-no-alt"></span>'
569
						. __( "Dismiss" , 'yikes-inc-easy-mailchimp-extender' ) 
570
					. "</a> </span>", 
571
				$plugin_name, $reviewurl, $addons_url, $nobugurl );
572
				?>
573
					<div id="review-yikes-easy-mailchimp-notice">
574
						<?php echo $review_message; ?>
575
					</div>
576
				<?php
577
			}
578
		}
579
580
		/**
581
			yikes_easy_mailchimp_stop_bugging_me()
582
			Remove the Review us notification when user clicks 'Dismiss'
583
			@since v3.1.1
584
		*/
585
		public function yikes_easy_mailchimp_stop_bugging_me() {
586
			if ( isset( $_GET['yikes_easy_mc_icons_nobug'] ) && (int) filter_var( $_GET['yikes_easy_mc_icons_nobug'], FILTER_SANITIZE_NUMBER_INT ) === 1 ) {
587
				add_option( 'yikes_easy_mailchimp_review_stop_bugging_me', true );
588
			}
589
		}
590
591
	/* End Two Week Notification */
592
593
		/* Display a warning users who are using PHP < 5.3 */
594
		public function display_php_warning() {
595
			$message = __( 'Easy Forms for Mailchimp requires a minimum of PHP 5.3. The plugin will not function properly until you update. Please reach out to your host provider for assistance.', 'yikes-inc-easy-mailchimp-extender' );
596
			echo "<div class='error'> <p><span class='dashicons dashicons-no-alt' style='color:rgb(231, 98, 98)'></span> $message</p></div>";
597
		}
598
599
	/**
600
	 *
601
	 * TinyMCE Functions
602
	 */
603
	// load our button and pass in the JS form data variable.
604
	public function add_tinyMCE_buttons() {
605
		global $typenow;
606
		// only on Post Type: post and page.
607
		if ( ! in_array( $typenow, array( 'post', 'page' ) ) ) {
608
			return;
609
		}
610
		add_filter( 'mce_buttons', array( $this, 'yks_mc_add_tinymce_button' ) );
611
		add_filter( 'mce_external_plugins', array( $this, 'yks_mc_add_tinymce_plugin' ) );
612
	}
613
614
	// Add the button key for address via JS.
615
	public function yks_mc_add_tinymce_button( $buttons ) {
616
		array_push( $buttons, 'yks_mc_tinymce_button_key' );
617
		// Print all buttons.
618
		return $buttons;
619
	}
620
621
	// inlcude the js for tinymce.
622
	public function yks_mc_add_tinymce_plugin( $plugin_array ) {
623
624
		$plugin_array['yks_mc_tinymce_button'] = plugins_url( '/js/min/yikes-inc-easy-mailchimp-tinymce-button.min.js', __FILE__ );
625
626
		return $plugin_array;
627
	}
628
629
		/**
630
		 * Localize Script
631
		 * Pass our imported list data, to the JS file
632
		 * to build the drop down list in the modal
633
		 */
634
	public function tinymce_yikes_easy_mc() {
635
		// check capabilities.
636
		if ( ! current_user_can( apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ) ) ) {
637
			return;
638
		}
639
640
		$list_data = $this->form_interface->get_all_forms();
641
		$lists     = array();
642
		if ( ! empty( $list_data ) ) {
643
			// build an array to pass to our javascript.
644
			foreach ( $list_data as $id => $form ) {
645
				$lists[] = array(
646
					'text'  => urlencode( $form['form_name'] ),
647
					'value' => $id,
648
				);
649
			}
650
		} else {
651
			$lists[0] = array(
652
				'text'  => __( 'Please Import Some Mailchimp Lists', 'yikes-inc-easy-mailchimp-extender' ),
653
				'value' => '-',
654
			);
655
		}
656
657
			/* Pass our form data to our JS file for use */
658
			wp_localize_script( 'editor', 'localized_data', array(
659
				'forms'                    => wp_json_encode( $lists ),
660
				'button_title'             => __( 'Easy Forms for Mailchimp', 'yikes-inc-easy-mailchimp-extender' ),
661
				'popup_title'              => __( 'Easy Forms for Mailchimp', 'yikes-inc-easy-mailchimp-extender' ),
662
				'list_id_label'            => __( 'Mailchimp Opt-In Form', 'yikes-inc-easy-mailchimp-extender' ),
663
				'show_title_label'         => __( 'Display Form Title', 'yikes-inc-easy-mailchimp-extender' ),
664
				'show_description_label'   => __( 'Display Form Description', 'yikes-inc-easy-mailchimp-extender' ),
665
				'submit_button_text_label' => __( 'Custom Submit Button Text', 'yikes-inc-easy-mailchimp-extender' ),
666
				'submit_button_message'    => '<em>' . __( 'If left empty, the button will use the default submit button text .', 'yikes-inc-easy-mailchimp-extender' ) . '</em>',
667
				'alert_translated'         => sprintf( __( 'You need to <a href=%s title="%s">create a form</a> before you can add one to a page or post.', 'yikes-inc-easy-mailchimp-extender' ), esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp' ) ), __( 'Create a form', 'yikes-inc-easy-mailchimp-extender' ) ),
668
			) );
669
	}
670
	/* End TinyMCE Functions */
671
672
	/**
673
	 *  Fix the Mailchimp icon spacing in the admin menu.
674
	 */
675
	public function fix_menu_icon_spacing() {
676
		?>
677
			<style>
678
			a[href="admin.php?page=yikes-inc-easy-mailchimp"] .wp-menu-image img {
679
				padding-top: 5px !important;
680
			}
681
			</style>
682
		<?php
683
	}
684
685
	/**
686
	 * Register the stylesheets for the admin area.
687
	 *
688
	 * @since    6.0.0
689
	 */
690
	public function enqueue_styles() {
691
		/**
692
		 *	Enqueue our global dashboard styles.
693
		 */
694
		wp_enqueue_style( 'yikes-inc-easy-mailchimp-extender-admin', plugin_dir_url( __FILE__ ) . 'css/yikes-inc-easy-mailchimp-extender-admin.min.css', array(), $this->version, 'all' );
695
696
		/*
697
		*	Enqueue Add-ons styles.
698
		*/
699
		if ( get_current_screen()->base == 'easy-forms_page_yikes-inc-easy-mailchimp-addons' ) {
700
			wp_enqueue_style( 'yikes-inc-easy-mailchimp-extender-addons-styles', plugin_dir_url( __FILE__ ) . 'css/yikes-inc-easy-mailchimp-extender-addons.min.css', array(), $this->version, 'all' );
701
		}
702
	}
703
	/**
704
	 * Register the JavaScript for the admin area.
705
	 *
706
	 * @since    6.0.0
707
	 */
708
	public function enqueue_scripts() {
709
		wp_enqueue_script( 'yikes-inc-easy-mailchimp-extender-admin-js', plugin_dir_url( __FILE__ ) . 'js/min/yikes-inc-easy-mailchimp-extender-admin.min.js', array( 'jquery', 'jquery-ui-sortable' ), $this->version, false );
710
711
		$localized_data = array(
712
			'admin_url'                => esc_url_raw( admin_url() ),
713
			'ajax_url'                 => esc_url_raw( admin_url( 'admin-ajax.php' ) ),
714
			'locating_interest_groups' => __( 'Locating Interest Groups', 'yikes-inc-easy-mailchimp-extender' ),
715
			'search_preloader_url'     => YIKES_MC_URL . 'includes/images/search-interest-group-preloader.gif',
716
			'preloader_url'            => esc_url_raw( admin_url( '/images/wpspin_light.gif' ) ),
717
		);
718
719
		wp_localize_script( 'yikes-inc-easy-mailchimp-extender-admin-js', 'object_data', $localized_data );
720
721
		// Enqueue required scripts for the form editor
722
		$screen = get_current_screen();
723
		if ( ! isset( $screen->base ) || 'admin_page_yikes-mailchimp-edit-form' !== $screen->base ) {
724
			return;
725
		}
726
727
		/** @var WP_Locale */
728
		global $wp_locale;
729
730
		wp_enqueue_style( 'wp-color-picker' );
731
		wp_enqueue_script( 'wp-color-picker' );
732
		wp_enqueue_script( 'jquery.timepicker.js',YIKES_MC_URL . 'admin/js/jquery.timepicker.min.js', array( 'jquery' ) , $this->version, false );
733
		wp_enqueue_script( 'edit-form-js', YIKES_MC_URL . 'admin/js/min/yikes-inc-easy-mailchimp-extender-edit-form.min.js', array( 'jquery.timepicker.js', 'jquery-ui-datepicker' ) , $this->version, false );
734
735
		$localized_data = array(
736
			'add_tag_nonce'                     => wp_create_nonce( 'add-tag' ),
737
			'remove_tag_nonce'                  => wp_create_nonce( 'remove-tag' ),
738
			'ajax_url'                          => esc_url_raw( admin_url( 'admin-ajax.php' ) ),
739
			'no_fields_assigned'                => __( 'No fields assigned to this form. Select some fields to add to this form from the right hand column.', 'yikes-inc-easy-mailchimp-extender' ),
740
			'bulk_delete_alert'                 => __( 'Are you sure you want to delete all of the fields assigned to this form?', 'yikes-inc-easy-mailchimp-extender' ),
741
			'closeText'                         => __( 'Done', 'yikes-inc-easy-mailchimp-extender' ),
742
			'currentText'                       => __( 'Today', 'yikes-inc-easy-mailchimp-extender' ),
743
			'monthNames'                        => array_values( $wp_locale->month ),
744
			'monthNamesShort'                   => array_values( $wp_locale->month_abbrev ),
745
			'monthStatus'                       => __( 'Show a different month', 'yikes-inc-easy-mailchimp-extender' ),
746
			'dayNames'                          => array_values( $wp_locale->weekday ),
747
			'dayNamesShort'                     => array_values( $wp_locale->weekday_abbrev ),
748
			'dayNamesMin'                       => array_values( $wp_locale->weekday_initial ),
749
750
			// set the date format to match the WP general date settings
751
			'dateFormat'                        => $this->yikes_jQuery_datepicker_date_format_php_to_js( get_option( 'date_format' ), 'date' ),
752
753
			// get the start of week from WP general setting
754
			'firstDay'                          => get_option( 'start_of_week' ),
755
756
			// is Right to left language? default is false
757
			'isRTL'                             => $wp_locale->is_rtl(),
758
			'start_date_exceeds_end_date_error' => __( 'Error: The start date and time cannot occur after the end date and time. Chosen date reverted to previous selection.', 'yikes-inc-easy-mailchimp-extender' ),
759
760
			// Editing field label fields
761
			'edit_field_label_pencil_title' => __( 'Click to edit the label', 'yikes-inc-easy-mailchimp-extender' ),
762
			'edit_field_label_cancel_title' => __( 'Click to cancel editing. Your changes will not be saved.', 'yikes-inc-easy-mailchimp-extender' ),
763
			'save_field_label_nonce' => wp_create_nonce( 'save_field_label_nonce' ),
764
		);
765
		wp_localize_script( 'edit-form-js', 'yikes_mailchimp_edit_form', $localized_data );
766
	}
767
768
	/**
769
	 * Convert the php date format string to a js date format
770
	 */
771
	public function yikes_jQuery_datepicker_date_format_php_to_js( $sFormat, $type ) {
772
		switch ( $type ) {
773
			default:
774 View Code Duplication
			case 'date':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
775
				// Standard Date Fields
776
				switch ( $sFormat ) {
777
					//Predefined WP date formats
778
					case 'F j, Y':
779
					case 'j F Y':
780
					case 'm/d/Y':
781
					case 'mm/dd/yyyy':
782
					case 'MM/DD/YYYY':
783
					default:
784
						return( 'mm/dd/yy' );
785
						break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
786
					case 'Y/m/d':
0 ignored issues
show
Unused Code introduced by
case 'Y/m/d': does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
787
					case 'Y-m-d':
788
						return( 'yy/mm/dd' );
789
						break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
790
					case 'd/m/Y':
791
					case 'dd/mm/yyyy':
792
					case 'DD/MM/YYYY':
793
						return( 'dd/mm/yyyy' );
794
						break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
795
				 }
796
				break;
797
			// Birthday Fields
798 View Code Duplication
			case 'birthday':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
799
				switch ( $sFormat ) {
800
					//Predefined WP date formats
801
					case 'F j, Y':
802
					case 'j F Y':
803
					case 'm/d/Y':
804
					case 'mm/dd/yyyy':
805
					case 'MM/DD/YYYY':
806
					default:
807
						return( 'mm/dd' );
808
						break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
809
					case 'Y/m/d':
0 ignored issues
show
Unused Code introduced by
case 'Y/m/d': does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
810
					case 'Y-m-d':
811
						return( 'mm/dd' );
812
						break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
813
					case 'd/m/Y':
814
					case 'dd/mm/yyyy':
815
					case 'DD/MM/YYYY':
816
					case 'dd/mm':
817
					case 'DD/MM':
818
						return( 'dd/mm' );
819
						break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
820
				 }
821
				break;
822
		}
823
	}
824
825
	/**
826
	 * Convert the php date format string to a js date format
827
	 */
828
	public function yikes_jQuery_datepicker_date_format( $site_option ) {
829
		switch( $site_option ) {
830
			//Predefined WP date formats
831
			default:
832
			case 'F j, Y':
833
			case 'm/d/Y':
834
				return( 'm/d/Y' );
835
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
836
			case 'Y-m-d':
837
				return( 'Y/m/d' );
838
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
839
			case 'd/m/Y':
840
				return( 'd/m/Y' );
841
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
842
		 }
843
	}
844
845
	/**
846
	*	Register our admin pages
847
	*	used to display data back to the user
848
	**/
849
	public function register_admin_pages() {
850
851
		/* Top Level Menu 'Easy Mailchimp' */
852
		add_menu_page(
853
			__( 'Easy Forms', 'yikes-inc-easy-mailchimp-extender' ),
854
			'Easy Forms',
855
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
856
			'yikes-inc-easy-mailchimp',
857
			'', // no callback,
858
			YIKES_MC_URL . 'includes/images/Mailchimp_Assets/Freddie_wink_icon.png'
859
		);
860
861
		// Sub Pages
862
		/*************/
863
864
		/* Easy Mailchimp Settings */
865
866
		/* Easy Mailchimp Manage Forms */
867
		add_submenu_page(
868
			'yikes-inc-easy-mailchimp',
869
			__( 'Opt-in Forms', 'yikes-inc-easy-mailchimp-extender' ),
870
			__( 'Opt-in Forms', 'yikes-inc-easy-mailchimp-extender' ),
871
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
872
			'yikes-inc-easy-mailchimp',
873
			array( $this, 'generateManageFormsPage' )
874
		);
875
876
		/* Easy Mailchimp Manage Lists */
877
		add_submenu_page(
878
			'yikes-inc-easy-mailchimp',
879
			__( 'Mailing Lists', 'yikes-inc-easy-mailchimp-extender' ),
880
			__( 'Mailing Lists', 'yikes-inc-easy-mailchimp-extender' ),
881
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
882
			'yikes-inc-easy-mailchimp-lists',
883
			array( $this, 'generateManageListsPage' )
884
		);
885
886
887
		/*
888
		*	Custom action hook to hook into to add additional
889
		*	menu items from extensions
890
		*/
891
		do_action( 'yikes-mailchimp-menu' );
892
893
		/* Easy Mailchimp Settings */
894
		add_submenu_page(
895
			'yikes-inc-easy-mailchimp',
896
			__( 'Settings.', 'yikes-inc-easy-mailchimp-extender' ),
897
			__( 'Settings', 'yikes-inc-easy-mailchimp-extender' ),
898
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
899
			'yikes-inc-easy-mailchimp-settings',
900
			array( $this, 'generatePageOptions' )
901
		);
902
903
		/* Support Page */
904
		add_submenu_page(
905
			'yikes-inc-easy-mailchimp',
906
			__( 'Support', 'yikes-inc-easy-mailchimp-extender' ),
907
			__( 'Support', 'yikes-inc-easy-mailchimp-extender' ),
908
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
909
			'yikes-inc-easy-mailchimp-support',
910
			array( $this, 'generateSupportPage' )
911
		);
912
913
		/* Add-Ons Page */
914
		add_submenu_page(
915
			'yikes-inc-easy-mailchimp',
916
			__( 'Add-Ons', 'yikes-inc-easy-mailchimp-extender' ),
917
			__( 'Add-Ons', 'yikes-inc-easy-mailchimp-extender' ),
918
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
919
			'yikes-inc-easy-mailchimp-addons',
920
			array( $this, 'generateAddOnsPage' )
921
		);
922
923
		/** Hidden Pages **/
924
925
		/* Add Hidden Edit Form Page */
926
		add_submenu_page(
927
			'options.php',
928
			__( 'Edit Form', 'yikes-inc-easy-mailchimp-extender' ),
929
			__( 'Edit Form', 'yikes-inc-easy-mailchimp-extender' ),
930
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
931
			'yikes-mailchimp-edit-form',
932
			array( $this, 'generateEditFormPage' )
933
		);
934
935
		/* Add Hidden 'View List' Page */
936
		add_submenu_page(
937
			'options.php',
938
			__( 'View List', 'yikes-inc-easy-mailchimp-extender' ),
939
			__( 'View List', 'yikes-inc-easy-mailchimp-extender' ),
940
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
941
			'yikes-mailchimp-view-list',
942
			array( $this, 'generateViewListPage' )
943
		);
944
945
		/* Add Hidden View User Page */
946
		add_submenu_page(
947
			'options.php',
948
			__( 'View User', 'yikes-inc-easy-mailchimp-extender' ),
949
			__( 'View User', 'yikes-inc-easy-mailchimp-extender' ),
950
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
951
			'yikes-mailchimp-view-user',
952
			array( $this, 'generateViewUserPage' )
953
		);
954
955
	}
956
957
	/*
958
	*	Redirect a user to an external page
959
	*	when they click 'Go Pro' in the admin menu
960
	*	to do: populate with sales URL
961
	*/
962
	public function generateAddOnsPage() {
963
		require_once YIKES_MC_PATH . 'admin/partials/menu/add-ons.php'; // include our add-ons page
964
	}
965
966
	/**
967
	* Generate Us Easy Mailchimp Manage Forms Page
968
	*
969
	* @since    1.0.0
970
	*/
971
	function generateManageFormsPage() {
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...
972
		require_once YIKES_MC_PATH . 'admin/partials/menu/manage-forms.php'; // include our manage forms page
973
	}
974
975
	/**
976
	* Generate Us Easy Mailchimp Manage Lists Page
977
	*
978
	* @since    1.0.0
979
	*/
980
	function generateManageListsPage() {
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...
981
		require_once YIKES_MC_PATH . 'admin/partials/menu/manage-lists.php'; // include our lists page
982
	}
983
984
	/**
985
	* Generate Us Easy Mailchimp Support Page
986
	*
987
	* @since    1.0.0
988
	*/
989
	function generateSupportPage() {
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...
990
991
		wp_enqueue_script( 'yikes-inc-easy-mailchimp-extender-support-scripts', plugin_dir_url( __FILE__ ) . 'js/support.js', array( 'jquery' ), $this->version, false );	
992
		require_once YIKES_MC_PATH . 'admin/partials/menu/support.php';
993
	}
994
995
	/**
996
	* Generate Us Easy Mailchimp Edit Form Page
997
	*
998
	* @since    1.0.0
999
	*/
1000
	function generateEditFormPage() {
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...
1001
		require_once YIKES_MC_PATH . 'admin/partials/edit-form.php'; // include our options page
1002
	}
1003
1004
	/**
1005
	* Generate Us Easy Mailchimp View List Page
1006
	*
1007
	* @since    1.0.0
1008
	*/
1009
	function generateViewListPage() {
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...
1010
		require_once YIKES_MC_PATH . 'admin/partials/view-list.php'; // include our options page
1011
	}
1012
1013
	/**
1014
	* Generate Us Easy Mailchimp View User Page
1015
	*
1016
	* @since    1.0.0
1017
	*/
1018
	function generateViewUserPage() {
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...
1019
		require_once YIKES_MC_PATH . 'admin/partials/view-user.php'; // include our options page
1020
	}
1021
1022
	/**
1023
	*	Register our plugin settings, and display them on our settings page
1024
	*
1025
	* @since v.5.4
1026
	**/
1027
	function yikes_easy_mc_settings_init() {
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...
1028
1029
		/* Register General Settings Section */
1030
1031
		register_setting( 'yikes_inc_easy_mc_general_settings_page', 'yikes-mc-api-key', array( $this , 'yikes_mc_validate_api_key' ) );
1032
1033
		register_setting( 'yikes_inc_easy_mc_general_settings_page', 'yikes-mailchimp-use-nonce' );
1034
1035
		add_settings_section(
1036
			'yikes_easy_mc_settings_general_section_callback',
1037
			'',
1038
			'',
1039
			'yikes_inc_easy_mc_general_settings_page'
1040
		);
1041
1042
		/* Register Visual Representation of Connection */
1043
		add_settings_field(
1044
			'connection',
1045
			__( 'API Connection', 'yikes-inc-easy-mailchimp-extender' ),
1046
			'yikes_inc_easy_mc_visual_representation_of_connection_callback', // callback + validation inside of admin/partials/menu/options.php
1047
			'yikes_inc_easy_mc_general_settings_page',
1048
			'yikes_easy_mc_settings_general_section_callback'
1049
		);
1050
1051
		/* Register Check Box Setting */
1052
		add_settings_field(
1053
			'yikes-mc-api-key',
1054
			__( 'Mailchimp API Key', 'yikes-inc-easy-mailchimp-extender' ),
1055
			'yikes_inc_easy_mc_api_key_field_callback', // callback + validation inside of admin/partials/menu/options.php
1056
			'yikes_inc_easy_mc_general_settings_page',
1057
			'yikes_easy_mc_settings_general_section_callback'
1058
		);
1059
1060
		/* End General Settings */
1061
1062
		/* Checkbox Settings */
1063
		register_setting( 'yikes_inc_easy_mc_checkbox_settings_page', 'optin-checkbox-init' );
1064
1065
		/* Register General Settings Section */
1066
		add_settings_section(
1067
			'yikes_inc_easy_mc_checkbox_settings',
1068
			'',
1069
			'',
1070
			'yikes_inc_easy_mc_checkbox_settings_page'
1071
		);
1072
1073
		add_settings_field(
1074
			'optin-checkbox-init',
1075
			__( 'Select Checkboxes to Generate', 'yikes-inc-easy-mailchimp-extender' ),
1076
			'',  // callback + validation inside of admin/partials/menu/options.php
1077
			'yikes_inc_easy_mc_checkbox_settings'
1078
		);
1079
		/* End Checkbox Settings */
1080
1081
		/* reCAPTCHA Settings */
1082
1083
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-status' );
1084
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-site-key' );
1085
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-secret-key' );
1086
1087
			/* Version 3 Settings */
1088
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-site-key-three' );
1089
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-secret-key-three' );
1090
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-version-three' );
1091
1092
			/* Register reCAPTCHA Settings Section */
1093
			add_settings_section(
1094
				'yikes_easy_mc_settings_recpatcha_section',
1095
				'',
1096
				'',
1097
				'yikes_inc_easy_mc_recaptcha_settings_page'
1098
			);
1099
1100
			add_settings_field(
1101
				'yikes-mc-recaptcha-site-key',
1102
				__( 'Enter reCAPTCHA V2 Site Key', 'yikes-inc-easy-mailchimp-extender' ),
1103
				'',  // callback + validation inside of admin/partials/menu/options.php
1104
				'yikes_easy_mc_settings_recpatcha_section'
1105
			);
1106
1107
			add_settings_field(
1108
				'yikes-mc-recaptcha-secret-key',
1109
				__( 'Enter reCAPTCHA V2 Secret Key', 'yikes-inc-easy-mailchimp-extender' ),
1110
				'',  // callback + validation inside of admin/partials/menu/options.php
1111
				'yikes_easy_mc_settings_recpatcha_section'
1112
			);
1113
1114
			add_settings_field(
1115
				'yikes-mc-recaptcha-status',
1116
				__( 'Enable ReCaptcha', 'yikes-inc-easy-mailchimp-extender' ),
1117
				'',  // callback + validation inside of admin/partials/menu/options.php
1118
				'yikes_easy_mc_settings_recpatcha_section'
1119
			);
1120
1121
			add_settings_field(
1122
				'yikes-mc-recaptcha-version-three',
1123
				__( 'Enable Version 3', 'yikes-inc-easy-mailchimp-extender' ),
1124
				'',  // callback + validation inside of admin/partials/menu/options.php
1125
				'yikes_easy_mc_settings_recpatcha_section'
1126
			);
1127
1128
			add_settings_field(
1129
				'yikes-mc-recaptcha-site-key-three',
1130
				__( 'Enter reCAPTCHA V3 Site Key', 'yikes-inc-easy-mailchimp-extender' ),
1131
				'',  // callback + validation inside of admin/partials/menu/options.php
1132
				'yikes_easy_mc_settings_recpatcha_section'
1133
			);
1134
1135
			add_settings_field(
1136
				'yikes-mc-recaptcha-secret-key-three',
1137
				__( 'Enter reCAPTCHA V3 Secret Key', 'yikes-inc-easy-mailchimp-extender' ),
1138
				'',  // callback + validation inside of admin/partials/menu/options.php
1139
				'yikes_easy_mc_settings_recpatcha_section'
1140
			);
1141
1142
		/* End reCAPTCHA Settings */
1143
1144
		/* Debug Settings */
1145
			register_setting( 'yikes_inc_easy_mc_debug_settings_page', 'yikes-mailchimp-debug-status' );
1146
1147
			/* Register Debug Settings Section */
1148
			add_settings_section(
1149
				'yikes_easy_mc_settings_debug_section',
1150
				'',
1151
				'',
1152
				'yikes_inc_easy_mc_debug_settings_page'
1153
			);
1154
1155
			add_settings_field(
1156
				'yikes-mailchimp-debug-status',
1157
				__( 'Enable Debugging', 'yikes-inc-easy-mailchimp-extender' ),
1158
				'',  // callback + validation inside of admin/partials/menu/options.php
1159
				'yikes_easy_mc_settings_debug_section'
1160
			);
1161
1162
		/* Custom Action Hook For Addon Settings */
1163
			// custom action hook to allow our add-ons to take
1164
			// advantage of our base settings
1165
			do_action( 'yikes-mailchimp-settings-field' );
1166
1167
	}
1168
1169
	/**
1170
	*	Options Sanitization & Validation
1171
	*	@since complete re-write
1172
	**/
1173
	function yikes_mc_validate_api_key( $input ) {
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...
1174
		if ( $input === '' ) {
1175
			update_option( 'yikes-mc-api-validation', 'invalid_api_key' );
1176
			return '';
1177
		}
1178
		$api_key = strip_tags ( trim( $input ) );
1179
		$dash_position = strpos( trim( $input ), '-' );
1180
		if ( $dash_position !== false ) {
1181
			$manager = new Yikes_Inc_Easy_Mailchimp_API_Manager( $api_key );
1182
		} else {
1183
			update_option( 'yikes-mc-api-invalid-key-response', __( 'Your API key appears to be invalid.', 'yikes-inc-easy-mailchimp-extender' ) );
1184
			update_option( 'yikes-mc-api-validation', 'invalid_api_key' );
1185
			return $api_key;
1186
		}
1187
1188
		$response = $manager->get_account_handler()->get_account( false );
1189
		if ( ! is_wp_error( $response ) ) {
1190
			update_option( 'yikes-mc-api-validation', 'valid_api_key' );
1191
				// Clear the API key transient data
1192
			$this->delete_yikes_mailchimp_transients();
1193
		}  else {
1194
			$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
1195
			$error_logging->yikes_easy_mailchimp_write_to_error_log( $response->get_error_message() , __( "Connecting to Mailchimp" , 'yikes-inc-easy-mailchimp-extender' ) , __( "Settings Page/General Settings" , 'yikes-inc-easy-mailchimp-extender' ) );
1196
			update_option( 'yikes-mc-api-invalid-key-response', $response->get_error_message() );
1197
			update_option( 'yikes-mc-api-validation', 'invalid_api_key' );
1198
		}
1199
		// returned the api key
1200
		return $api_key;
1201
	}
1202
1203
	/**
1204
	* Generate Us Easy Forms for Mailchimp Options Page
1205
	*
1206
	* @since    1.0.0
1207
	*/
1208
	function generatePageOptions() {
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...
1209
		require_once YIKES_MC_PATH . 'admin/partials/menu/options.php'; // include our options page
1210
	}
1211
1212
	/**
1213
	*	Check if users API key is valid, if not
1214
	*	this function will apply a disabled attribute
1215
	*	to form fields. (input, dropdowns, buttons etc.)
1216
	* 	@since v5.5 re-write
1217
	**/
1218
	public function is_user_mc_api_valid_form( $echo = true ) {
1219
		if ( $echo == true ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
1220
			if ( get_option( 'yikes-mc-api-validation', 'invalid_api_key' ) == 'invalid_api_key' ) {
1221
				echo 'disabled="disabled"';
1222
			}
1223
		} else {
1224
			if ( get_option( 'yikes-mc-api-validation', 'invalid_api_key' ) == 'invalid_api_key' ) {
1225
				return false;
1226
			} else {
1227
				return true;
1228
			}
1229
		}
1230
	}
1231
1232
	/**
1233
	 * Admin Notices
1234
	 *	- Notifications displayed at the top of admin pages, back to the user
1235
	 */
1236
1237
		/*
1238
		*	Search through multi dimensional array
1239
		*	and return the index ( used to find the list name assigned to a form )
1240
		*	- http://stackoverflow.com/questions/6661530/php-multi-dimensional-array-search
1241
		*/
1242
		function findMCListID($id, $array) {
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...
1243
		   foreach ($array as $key => $val) {
1244
			   if ($val['id'] === $id) {
1245
				   return $key;
1246
			   }
1247
		   }
1248
		   return null;
1249
		} // end
1250
1251
		/*
1252
		*	generate_options_pages_sidebar_menu();
1253
		*	Render our sidebar menu on all of the setings pages (general, form, checkbox, recaptcha, popup, debug etc. )
1254
		*	@since v5.6 - complete re-write
1255
		*/
1256
		public function generate_options_pages_sidebar_menu() {
1257
			if ( isset( $_REQUEST['section'] ) ) {
1258
				$selected = $_REQUEST['section'];
0 ignored issues
show
Unused Code introduced by
$selected is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1259
			}
1260
			$installed_addons = get_option( 'yikes-easy-mc-active-addons', array() );
1261
1262
			// Make sure we don't have any duplicates by mistake
1263
			$installed_addons = array_unique( $installed_addons );
1264
1265
			// v1.2.6 of popups plugin had a bug that expanded the array indefinitely, so let's trim it in one place here.
1266
			// This can be removed within a few weeks
1267
			update_option( 'yikes-easy-mc-active-addons', $installed_addons );
1268
1269
			// sort our addons array alphabetically so they appear in similar orders across all sites
1270
			asort( $installed_addons );
1271
			?>
1272
				<h3><span><?php _e( 'Additional Settings', 'yikes-inc-easy-mailchimp-extender' ); ?></span></h3>
1273
				<div class="inside">
1274
					<ul id="settings-nav">
1275
						<li><?php if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] == 'general-settings' || !isset( $_REQUEST['section'] ) ) { ?><div class="option-menu-selected-arrow"></div><?php } ?><a href="<?php echo esc_url_raw( add_query_arg( array( 'section' => 'general-settings' ) , admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=general-settings' ) ) ); ?>"><?php _e( 'General Settings', 'yikes-inc-easy-mailchimp-extender' ); ?></a></li>
1276
						<li><?php if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] == 'integration-settings' ) { ?><div class="option-menu-selected-arrow"></div><?php } ?><a href="<?php echo esc_url_raw( add_query_arg( array( 'section' => 'integration-settings' ) , admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=integration-settings' ) ) ); ?>"><?php _e( 'Integration Settings', 'yikes-inc-easy-mailchimp-extender' ); ?></a></li>
1277
						<li><?php if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] == 'recaptcha-settings' ) { ?><div class="option-menu-selected-arrow"></div><?php } ?><a href="<?php echo esc_url_raw( add_query_arg( array( 'section' => 'recaptcha-settings' ) , admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=recaptcha-settings' ) ) ); ?>"><?php _e( 'ReCaptcha Settings', 'yikes-inc-easy-mailchimp-extender' ); ?></a></li>
1278
						<li><?php if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] == 'api-cache-settings' ) { ?><div class="option-menu-selected-arrow"></div><?php } ?><a href="<?php echo esc_url_raw( add_query_arg( array( 'section' => 'api-cache-settings' ) , admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=api-cache-settings' ) ) ); ?>"><?php _e( 'API Cache Settings', 'yikes-inc-easy-mailchimp-extender' ); ?></a></li>
1279
						<li><?php if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] ==  'debug-settings' ) { ?><div class="option-menu-selected-arrow"></div><?php } ?><a href="<?php echo esc_url_raw( add_query_arg( array( 'section' => 'debug-settings' ) , admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=debug-settings' ) ) ); ?>"><?php _e( 'Debug Settings', 'yikes-inc-easy-mailchimp-extender' ); ?></a></li>
1280
						<li><?php if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] ==  'import-export-forms' ) { ?><div class="option-menu-selected-arrow"></div><?php } ?><a href="<?php echo esc_url_raw( add_query_arg( array( 'section' => 'import-export-forms' ) , admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=import-export-forms' ) ) ); ?>"><?php _e( 'Import/Export', 'yikes-inc-easy-mailchimp-extender' ); ?></a></li>
1281
					</ul>
1282
					<?php
1283
						// create our add-on settings pages
1284
						if ( !empty( $installed_addons ) ) {
1285
							?>
1286
							<hr class="add-on-settings-divider" />
1287
							<strong><?php _e( 'Addon Settings', 'yikes-inc-easy-mailchimp-extender' ); ?></strong>
1288
							<ul id="addon-settings-nav">
1289
							<?php
1290
							foreach( $installed_addons as $addon_name ) {
1291
								?>
1292
									<li>
1293
										<?php if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] ==  $addon_name ) { ?><div class="option-menu-selected-arrow"></div><?php } ?><a href="<?php echo esc_url_raw( add_query_arg( array( 'section' => $addon_name, 'addon' => 'true' ) , admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section='.$addon_name ) ) ); ?>"><?php echo ucwords( str_replace( '-', ' ', $addon_name ) ); ?></a></li>
1294
								<?php
1295
							}
1296
							?>
1297
							</ul>
1298
							<?php
1299
						}
1300
						?>
1301
				</div> <!-- .inside -->
1302
			<?php
1303
		}
1304
1305
		/*
1306
		*	generate_manage_forms_sidebar();
1307
		*	Render our sidebar menu on all of the setings pages (general, form, checkbox, recaptcha, popup, debug etc. )
1308
		*	@since v5.6 - complete re-write
1309
		*/
1310
		public function generate_manage_forms_sidebar( $lists ) {
1311
			// create a custom URL to allow for creating fields
1312
			$url = esc_url_raw(
1313
				add_query_arg(
1314
					array(
1315
						'action' => 'yikes-easy-mc-create-form',
1316
						'nonce' => wp_create_nonce( 'create_mailchimp_form' )
1317
					)
1318
				)
1319
			);
1320
			?>
1321
			<h3><?php _e( 'Create a New Signup Form', 'yikes-inc-easy-mailchimp-extender' ); ?></h3>
1322
1323
			<div class="inside">
1324
1325
				<p class="description"><?php _e( "Give your form a name, select a Mailchimp list to assign users to, then click 'Create'.", 'yikes-inc-easy-mailchimp-extender' ); ?></p>
1326
1327
				<form id="import-list-to-site" method="POST" action="<?php echo $url; ?>">
1328
					<input type="hidden" name="import-list-to-site" value="1" />
1329
					<!-- Name your new form -->
1330
					<label for="form-name"><strong><?php _e( 'Form Name', 'yikes-inc-easy-mailchimp-extender' ); ?></strong>
1331
						<input type="text" class="widefat input-field" placeholder="<?php _e( 'Form Name', 'yikes-inc-easy-mailchimp-extender' ); ?>" name="form-name" id="form-name" <?php $this->is_user_mc_api_valid_form( true ); ?> required>
1332
					</label>
1333
					<!-- Name your new form -->
1334
					<label for="form-description"><strong><?php _e( 'Form Description', 'yikes-inc-easy-mailchimp-extender' ); ?></strong>
1335
						<textarea class="widefat input-field form-description" placeholder="<?php _e( 'Form Description', 'yikes-inc-easy-mailchimp-extender' ); ?>" name="form-description" id="form-description" <?php $this->is_user_mc_api_valid_form( true ); ?>></textarea>
1336
					</label>
1337
					<!-- Associate this form with a list! -->
1338
					<label for="associated-list"><strong><?php _e( 'Associated List', 'yikes-inc-easy-mailchimp-extender' ); ?></strong>
1339
						<select name="associated-list" id="associated-list" class=" input-field" <?php $this->is_user_mc_api_valid_form( true ); disabled( true, empty( $lists ) ); ?>>
1340
							<?php
1341
							if ( ! empty( $lists ) ) {
1342
								foreach( $lists as $mailing_list ) {
1343
									?>
1344
									<option value="<?php echo $mailing_list['id']; ?>"><?php echo stripslashes( $mailing_list['name'] ) . ' (' . $mailing_list['stats']['member_count'] . ') '; ?></option>
1345
									<?php
1346
								}
1347
							} else {
1348
								if ( get_option( 'yikes-mc-api-validation', 'invalid_api_key' ) == 'invalid_api_key' ) {
1349
									?>
1350
									<option><?php echo __( "Please enter a valid API key." , 'yikes-inc-easy-mailchimp-extender' ); ?></option>
1351
									<?php
1352
								} else {
1353
									?>
1354
									<option><?php echo __( "No lists were found on the account." , 'yikes-inc-easy-mailchimp-extender' ); ?></option>
1355
									<?php
1356
1357
								}
1358
							}
1359
							?>
1360
						</select>
1361
1362
						<?php
1363
						if ( isset( $_GET['transient-cleared'] ) ) {
1364
							if ( 'true' === $_GET['transient-cleared'] ) {
1365
								?>
1366
								<div class="yikes-list-refreshed-notice">
1367
									<p><?php esc_attr_e( 'Mailchimp list data has been succesfully refreshed.', 'yikes-inc-easy-mailchimp-extender' ); ?></p>
1368
								</div>
1369
								<?php
1370
							}
1371
						}
1372
1373
						if ( isset( $lists ) && empty( $lists ) ) {
1374
							if ( get_option( 'yikes-mc-api-validation', 'invalid_api_key' ) != 'invalid_api_key' ) {
1375
								?>
1376
									<p class="description">
1377
										<?php printf( __( 'Head over to <a href="http://www.Mailchimp.com" title="%s">Mailchimp</a> to create a new list.', 'yikes-inc-easy-mailchimp-extender' ) , __( 'Create a list', 'yikes-inc-easy-mailchimp-extender' ) ); ?>
1378
									</p>
1379
								<?php
1380
							}
1381
						}
1382
						?>
1383
					</label>
1384
					<?php
1385
						if ( $this->is_user_mc_api_valid_form( false ) ) {
1386
							echo submit_button( __( 'Create', 'yikes-inc-easy-mailchimp-extender' ) , 'primary', '', false , array( 'style' => 'margin:.75em 0 .5em 0;' ) );
1387
						} else {
1388
							echo '<p class="description">' . __( "Please enter a valid Mailchimp API key to get started." , 'yikes-inc-easy-mailchimp-extender' ) . '</p>';
1389
							?>
1390
								<a href="<?php echo esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&settings-updated=true' ) ); ?>"><?php _e( 'general settings', 'yikes-inc-easy-mailchimp-extender' ); ?></a>
1391
							<?php
1392
						}
1393
					?>
1394
				</form>
1395
1396
				<!-- Clear API CACHE -->
1397
				<?php
1398
				if ( isset( $lists ) && ! empty( $lists ) ) {
1399
					if ( false !== get_transient( 'yikes-easy-mailchimp-list-data' ) ) { ?>
1400
						<form action="<?php echo esc_url_raw( add_query_arg( array( 'action' => 'yikes-easy-mc-clear-transient-data', 'nonce' => wp_create_nonce( 'clear-mc-transient-data' ) ) ) ); ?>" method="post">
1401
							<input type="submit" class="button-secondary clear-mailchimp-api-cache" value="<?php _e( 'Refresh Lists', 'yikes-inc-easy-mailchimp-extender' ); ?>" />
1402
						</form>
1403
					<?php }
1404
				}
1405
				?>
1406
			</div> <!-- .inside -->
1407
			<?php
1408
		}
1409
1410
		/*
1411
		*	Generate a dropdown of post and pages
1412
		*	so the user can send the user to on form submission
1413
		*/
1414
		public function generate_page_redirect_dropdown( $redirect, $redirect_page, $custom_redirect_url ) {
1415
				$post_types = get_post_types();
1416
				?>
1417
				<label id="redirect-user-to-selection-label" for="redirect-user-to-selection" class="<?php if ( $redirect == '0' ) { echo 'yikes-easy-mc-hidden'; } ?>">
1418
					<?php _e( "Select A Page or Post" , 'yikes-inc-easy-mailchimp-extender' ); ?>
1419
					<select id="redirect-user-to-selection" name="redirect-user-to-selection" onchange="shouldWeDisplayCustomURL( this );return;">
1420
				<?php
1421
1422
					/**
1423
					*	yikes-mailchimp-excluded-redirect-post-types
1424
					*
1425
					*	Filter the post types that will not show on the redirect list dropdown.
1426
					*
1427
					* 	@param array | $excluded_post_types | The array of default excluded post types
1428
					*	@return array| $excluded_post_types | The array of user-defined excluded post types
1429
					*/
1430
					$excluded_post_types = array( 'attachment', 'revision', 'nav_menu_item', 'shop_order', 'shop_order_refund', 'custom_css', 'customize_changeset', 'forum', 'topic', 'reply' );
1431
					$excluded_post_types = apply_filters( 'yikes-mailchimp-excluded-redirect-post-types', $excluded_post_types );
1432
1433
						// loop over registered post types, and query!
1434
						foreach( $post_types as $registered_post_type ) {
1435
1436
							// exclude a few built in custom post types and any defined by the filter
1437
							if ( ! in_array( $registered_post_type, $excluded_post_types ) ) {
1438
1439
								// Grab only the post IDs - in the past we've created timeout issues on some servers with lots of posts
1440
								$wp_query_args = array(
1441
									'post_status' => 'publish',
1442
									'post_type' => $registered_post_type,
1443
									'posts_per_page' => -1,
1444
									'fields' => 'ids',
1445
									'order' => 'ASC',
1446
									'orderby' => 'post_title',
1447
								);
1448
								$wp_query_result = new WP_Query( $wp_query_args );
1449
1450
								$post_ids = ! empty( $wp_query_result->posts ) ? $wp_query_result->posts : array();
1451
1452
								if ( ! empty ( $post_ids ) ) {
1453
									?>
1454
										<optgroup label="<?php echo ucwords( str_replace( '_', ' ', $registered_post_type ) ); ?>">
1455
									<?php
1456
											foreach( $post_ids as $post_id ) {
1457
												?><option <?php selected( $redirect_page , $post_id ); ?> value="<?php echo $post_id; ?>"><?php echo get_the_title( $post_id ) ?></option><?php
1458
											}
1459
									?>
1460
										</optgroup>
1461
									<?php
1462
								}
1463
							}
1464
						}
1465
					?>
1466
						<!-- Add the Custom URL option -->
1467
						<optgroup label="Custom URL">
1468
							<option <?php selected( $redirect_page, 'custom_url' ); ?> value="custom_url"><?php echo __( 'Custom URL', 'yikes-inc-easy-mailchimp-extender' ); ?></option>
1469
						</optgroup>
1470
					</select>
1471
1472
					<label name="custom-redirect-url" class="custom_redirect_url_label" <?php if ( ! isset( $redirect_page ) || $redirect_page != 'custom_url' ) { echo 'style="display:none;"'; } ?>>
1473
						<?php _e( "Enter Custom URL" , 'yikes-inc-easy-mailchimp-extender' ); ?>
1474
						<input type="text" class="widefat custom-redirect-url" name="custom-redirect-url" value="<?php echo $custom_redirect_url; ?>" />
1475
					</label>
1476
1477
				</label>
1478
			<?php
1479
		}
1480
1481
		/*
1482
		*	generate_show_some_love_container()
1483
		*	Generate a container, with some author info
1484
		*
1485
		* 	Displayed in sidebars
1486
		*/
1487
		public function generate_show_some_love_container() {
1488
			// if no active add-ons are installed,
1489
			// lets display our branding and add-on sidebar
1490
			$options = get_option( 'yikes-easy-mc-active-addons', array() );
1491
			if ( empty( $options ) ) {
1492
1493
				/* On Edit Forms Page Display Upsell to Customizer */
1494
				$screen = get_current_screen();
1495
				if ( isset( $screen ) && $screen->base == 'admin_page_yikes-mailchimp-edit-form' ) {
1496
				?>
1497
1498
					<div class="postbox yikes-easy-mc-postbox show-some-love-container">
1499
1500
						<?php $this->generate_edit_forms_upsell_ad(); ?>
1501
1502
					</div>
1503
1504
				<?php } else { ?>
1505
1506
					<div class="postbox yikes-easy-mc-postbox show-some-love-container">
1507
1508
						<!-- review us container -->
1509
						<h3 data-alt-text="<?php _e( 'About YIKES, Inc.', 'yikes-inc-easy-mailchimp-extender' ); ?>"><?php _e( 'Show Us Some Love', 'yikes-inc-easy-mailchimp-extender' ); ?></h3>
1510
						<div id="review-yikes-easy-mc" class="inside">
1511
1512
							<p>
1513
								<?php _e( 'Leave a review', 'yikes-inc-easy-mailchimp-extender' ); ?>
1514
								<p class="star-container">
1515
									<a href="https://wordpress.org/support/view/plugin-reviews/yikes-inc-easy-mailchimp-extender" target="_blank">
1516
										<b class="dashicons dashicons-star-filled"></b>
1517
										<b class="dashicons dashicons-star-filled"></b>
1518
										<b class="dashicons dashicons-star-filled"></b>
1519
										<b class="dashicons dashicons-star-filled"></b>
1520
										<b class="dashicons dashicons-star-filled"></b>
1521
									</a>
1522
								</p>
1523
							</p>
1524
1525
							<?php _e( 'Tweet about it', 'yikes-inc-easy-mailchimp-extender' ); ?>
1526
							<p class="sidebar-container">
1527
								<a href="https://twitter.com/share" class="twitter-share-button" data-url="https://wordpress.org/plugins/yikes-inc-easy-mailchimp-extender/" data-text="I'm using the Easy Forms for Mailchimp plugin by @YikesInc to grow my mailing list - it's awesome! -" data-hashtags="Mailchimp">Tweet</a>
1528
								<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if (!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
1529
							</p>
1530
						</div>
1531
1532
						<p class="description sidebar-footer-text"><?php printf( __( "This plugin made with %s by %s" , 'yikes-inc-easy-mailchimp-extender' ), '<span class="dashicons dashicons-heart yikes-love"></span>', '<a href="http://www.yikesinc.com" target="_blank" title="YIKES Inc.">YIKES Inc.</a>' ); ?> </p>
1533
1534
						<section id="about-yikes-inc" class="inside">
1535
							<a href="https://www.yikesinc.com" target="_blank" title="YIKES Inc.">
1536
								<img src="<?php echo YIKES_MC_URL . 'includes/images/About_Page/yikes-logo.png'; ?>" class="about-sidebar-yikes-logo" />
1537
							</a>
1538
							<p><strong>YIKES Inc.</strong> &mdash; <?php _e( 'is a web design and development company located in Philadelphia, Pennsylvania, US. YIKES specializes in custom WordPress theme and plugin development, site maintenance, eCommerce, custom-built web-based applications and more.', 'yikes-inc-easy-mailchimp-extender' ); ?></p>
1539
						</section>
1540
1541
						<p class="description sidebar-footer-text"><a href="#" class="about-yikes-inc-toggle" data-alt-text="<?php _e( 'Show YIKES Some Love', 'yikes-inc-easy-mailchimp-extender' ); ?>"><?php _e( 'About YIKES', 'yikes-inc-easy-mailchimp-extender' ); ?></a></p>
1542
1543
					</div>
1544
1545
					<div class="postbox yikes-easy-mc-postbox">
1546
1547
						<!-- review us container -->
1548
						<h3><?php _e( 'Easy Forms for Mailchimp Add-Ons', 'yikes-inc-easy-mailchimp-extender' ); ?></h3>
1549
						<div id="review-yikes-easy-mc" class="inside">
1550
							<p><?php _e( "Check out available add-ons for some seriously enhanced features." , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
1551
							<p><a class="button-secondary" href="<?php echo esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-addons' ) ); ?>" title="<?php _e( 'View Add-Ons', 'yikes-inc-easy-mailchimp-extender' ); ?>"><?php _e( 'View Add-Ons', 'yikes-inc-easy-mailchimp-extender' ); ?></a></p>
1552
						</div>
1553
1554
					</div>
1555
				<?php }
1556
			}
1557
1558
			/**
1559
			*	Custom action hook for our extensions to hook into
1560
			*	@parameter	get_current_screen()	current screen information
1561
			*/
1562
			do_action( 'yikes-mailchimp-admin-sidebar', get_current_screen() );
1563
1564
		}
1565
1566
		/*
1567
		*	generate_form_editor( $list_id )
1568
		*	Submit an API request to get our merge variables, and build up a small form editor
1569
		*	for users to 'customize' their form
1570
		*	-
1571
		* @parameters - $list_id - pass in the list ID to retreive merge variables from
1572
		*/
1573
		public function generate_form_editor( $form_fields, $list_id, $merge_variables, $interest_groups ) {
1574
1575
			// if no list id, die!
1576
			if ( ! $list_id ) {
1577
				wp_die( __( "We've encountered an error. No list ID was sent." , 'yikes-inc-easy-mailchimp-extender' ) );
1578
			}
1579
1580
			if ( ! $merge_variables ) {
1581
				wp_die( __( "We've encountered an error. Reload the page and try again. If the error persists, please reach out to support." , 'yikes-inc-easy-mailchimp-extender' ) );
1582
			}
1583
1584
			if ( ! empty( $form_fields ) ) {
1585
1586
				// find any fields that are assigned to this form, that don't exist in Mailchimp
1587
				// or else were going to run into issues when we submit the form
1588
				$available_merge_variables	= array();
1589
				$available_interest_groups	= array();
1590
1591
				// Default variables as arrays - these are used for holding the Mailchimp merge field ID
1592
				$merge_field_ids			= array();
1593
				$mailchimp_merge_field_ids	= array();
0 ignored issues
show
Unused Code introduced by
$mailchimp_merge_field_ids is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1594
1595
				// loop over merge variables
1596
				if ( ! empty( $merge_variables['merge_fields'] ) ) {
1597
					$available_merge_variables = wp_list_pluck( $merge_variables['merge_fields'], 'tag' );
1598
					$mailchimp_merge_field_ids = wp_list_pluck( $merge_variables['merge_fields'], 'merge_id' );
1599
					
1600
					// Array will look like $merge_tag => $merge_id
1601
					foreach( $available_merge_variables as $index => $merge_tag ) { 
1602
						$merge_field_ids[$merge_tag] = $mailchimp_merge_field_ids[$index];
1603
					}
1604
				}
1605
1606
				// loop over interest groups
1607
				if ( ! empty( $interest_groups ) ) {
1608
					$available_interest_groups = array_keys( $interest_groups );
1609
				}
1610
1611
				// build our assigned fields
1612
				$assigned_fields = array_keys( $form_fields );
1613
				$merged_fields   = array_merge( $available_merge_variables, $available_interest_groups );
1614
				$excluded_fields = array_diff( $assigned_fields, $merged_fields );
1615
1616
				$i = 1;
1617
				foreach( $form_fields as $field ) {
1618
1619
					if ( isset( $field['merge'] ) ) {
1620
						// @todo: don't use in_array()
1621
						$excluded_field = in_array( $field['merge'], $excluded_fields, true );
1622
						?>
1623
						<section class="draggable" id="<?php echo $field['merge']; ?>">
1624
							<!-- top -->
1625
							<a class="expansion-section-title settings-sidebar">
1626
								<span class="dashicons dashicons-plus yikes-mc-expansion-toggle"></span>
1627
								<span class="yikes-mc-expansion-section-field-label"> <?php echo stripslashes( $field['label'] ); ?> </span>
1628
								<?php if ( $excluded_field ) { ?>
1629
									<img src="<?php echo YIKES_MC_URL . 'includes/images/warning.svg'; ?>" class="field-doesnt-exist-notice" title="<?php _e( 'Field no longer exists.', 'yikes-inc-easy-mailchimp-extender' ); ?>" alt="<?php _e( 'Field no longer exists.', 'yikes-inc-easy-mailchimp-extender' ); ?>">
1630
								<?php } ?>
1631
								<input maxlength="50" type="text" class="yikes-mc-edit-field-label-input" value="<?php echo stripslashes( $field['label'] ); ?>" />
1632
								<span class="dashicons dashicons-yes yikes-mc-save-field-label-edits-icon" title="<?php _e( 'Click to save changes.', 'yikes-inc-easy-mailchimp-extender' ); ?>"></span>
1633
								<span class="dashicons dashicons-edit yikes-mc-edit-field-label-icon" title="<?php _e( 'Click to edit the label', 'yikes-inc-easy-mailchimp-extender' ); ?>"></span>
1634
								<span class="yikes-mc-edit-field-label-message"></span>
1635
								<span class="field-type-text"><small><?php echo __( 'type', 'yikes-inc-easy-mailchimp-extender' ) . ' : ' . $field['type']; ?></small></span>
1636
							</a>
1637
							<!-- expansion section -->
1638
							<div class="yikes-mc-settings-expansion-section">
1639
1640
								<?php if ( $excluded_field ) { ?>
1641
									<p class="yikes-mc-warning-message"><?php _e( "This field no longer exists in this list. Delete this field from the form to prevent issues on your website." , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
1642
								<?php } ?>
1643
1644
								<!-- store field data -->
1645
								<input type="hidden" class="yikes-mc-merge-field-label" name="field[<?php echo $field['merge']; ?>][label]" value="<?php echo htmlspecialchars( $field['label'] ); ?>" />
1646
								<input type="hidden" class="yikes-mc-merge-field-type" name="field[<?php echo $field['merge']; ?>][type]" value="<?php echo $field['type']; ?>" />
1647
								<input type="hidden" class="yikes-mc-merge-field-tag" name="field[<?php echo $field['merge']; ?>][merge]" value="<?php echo $field['merge']; ?>" />
1648
								<input type="hidden" class="field-<?php echo $field['merge']; ?>-position position-input" name="field[<?php echo $field['merge']; ?>][position]" value="<?php echo $i++; ?>" />
1649
								<?php if ( isset( $merge_field_ids[ $field['merge'] ] ) && is_int( $merge_field_ids[ $field['merge'] ] ) ) { ?> 
1650
									<input type="hidden" class="yikes-mc-merge-field-id" name="field[<?php echo $field['merge']; ?>][id]" value="<?php echo $merge_field_ids[ $field['merge'] ] ?>" />  
1651
								<?php } ?>
1652
1653
								<?php if ( $field['type'] == 'radio' || $field['type'] == 'dropdown' || $field['type'] == 'select' ) {
1654
									$choices = json_decode( $field['choices'], true );
1655
								?>
1656
									<input type="hidden" name="field[<?php echo $field['merge']; ?>][choices]" value='<?php echo esc_attr( json_encode( $choices ) ); ?>' />
1657
								<?php } ?>
1658
1659
								<!-- Single or Double Opt-in -->
1660
								<p class="type-container"><!-- necessary to prevent skipping on slideToggle(); -->
1661
1662
									<table class="form-table form-field-container">
1663
1664
										<!-- Merge Tag -->
1665
										<tr valign="top">
1666
											<td scope="row">
1667
												<label for="merge-tag">
1668
													<?php _e( 'Merge Tag', 'yikes-inc-easy-mailchimp-extender' ); ?>
1669
												</label>
1670
											</td>
1671
											<td>
1672
												<input class="widefat merge-tag-text" type="text" readonly value="<?php echo $field['merge']; ?>">
1673
											</td>
1674
										</tr>
1675
1676
										<!-- Placeholder Value -->
1677
										<?php switch( $field['type'] ) {
1678
1679
											case 'text':
1680
											case 'email':
1681
											case 'url':
1682
											case 'number';
1683
											case 'birthday':
1684
											case 'date':
1685
											case 'zip':
1686 View Code Duplication
											case 'phone':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1687
										?>
1688
										<!-- Placeholder -->
1689
										<tr valign="top">
1690
											<td scope="row">
1691
												<label for="placeholder_<?php echo esc_attr( $field['merge'] ); ?>">
1692
													<?php _e( 'Placeholder', 'yikes-inc-easy-mailchimp-extender' ); ?>
1693
												</label>
1694
											</td>
1695
											<td>
1696
												<input type="text" id="placeholder_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat" name="field[<?php echo $field['merge']; ?>][placeholder]" value="<?php echo isset( $field['placeholder'] ) ? $field['placeholder'] : '' ; ?>" />
1697
												<p class="description"><small><?php _e( "Assign a placeholder value to this field.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1698
											</td>
1699
										</tr>
1700
										<?php
1701
											break;
1702
1703
											// Custom address placeholder field
1704 View Code Duplication
											case 'address':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1705
											?>
1706
												<tr valign="top">
1707
													<td scope="row">
1708
														<label for="placeholder_<?php echo esc_attr( $field['merge'] ); ?>">
1709
															<?php _e( 'Placeholder', 'yikes-inc-easy-mailchimp-extender' ); ?>
1710
														</label>
1711
													</td>
1712
													<td>
1713
														<input type="checkbox" id="placeholder_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat" name="field[<?php echo $field['merge']; ?>][placeholder]" value="1" <?php echo isset( $field['placeholder'] ) && ! empty( $field['placeholder'] ) ? 'checked="checked"' : '' ; ?> />
1714
														<span class="description"><small><?php _e( "Use placeholders for this field (these will be automatically filled in with field names).", 'yikes-inc-easy-mailchimp-extender' );?></small></span>
1715
													</td>
1716
												</tr>
1717
											<?php
1718
											break;
1719
1720
										}
1721
										?>
1722
1723
										<!-- Default Value -->
1724
										<?php switch( $field['type'] ) {
1725
											default:
1726
											case 'text':
1727
											case 'number':
1728
											case 'url':
1729
										?>
1730
											<tr valign="top">
1731
												<td scope="row">
1732
													<label for="default_value_<?php echo esc_attr( $field['merge'] ); ?>">
1733
														<?php _e( 'Default Value', 'yikes-inc-easy-mailchimp-extender' ); ?>
1734
													</label>
1735
												</td>
1736
												<td>
1737 View Code Duplication
													<input id="default_value_<?php echo esc_attr( $field['merge'] ); ?>" <?php if ( $field['type'] != 'number' ) { ?> type="text" <?php } else { ?> type="number" <?php } ?> class="widefat" name="field[<?php echo $field['merge']; ?>][default]" <?php if ( $field['type'] != 'url' ) { ?> value="<?php echo isset( $field['default'] ) ? stripslashes( wp_strip_all_tags( $field['default'] ) ) : ''; ?>" <?php } else { ?> value="<?php echo isset( $field['default'] ) ? stripslashes( wp_strip_all_tags( esc_url_raw( $field['default'] ) ) ) : ''; ?>" <?php } ?> />
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1738
													<p class="description"><small><?php _e( "Assign a default value to populate this field with on initial page load.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1739
													<?php
1740
													switch( $field['type'] ) {
1741
														case 'text':
1742
															?>
1743
																<p><small class="pre-defined-tag-link"><a href="#TB_inline?width=600&height=550&inlineId=pre-defined-tag-container" onclick="storeGlobalClicked( jQuery( this ) );" class="thickbox"><?php _e( 'View Pre-Defined Tags', 'yikes-inc-easy-mailchimp-extender' ); ?></a></small></p>
1744
															<?php
1745
														break;
1746
													} ?>
1747
												</td>
1748
											</tr>
1749
										<?php
1750
												break;
1751
1752
											case 'radio':
1753
											?>
1754
												<tr valign="top">
1755
													<td scope="row">
1756
														<label for="placeholder">
1757
															<?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?>
1758
														</label>
1759
													</td>
1760
													<td>
1761
														<?php
1762
															$field['default_choice'] = ! isset( $field['default_choice'] ) ? 'no-default' : $field['default_choice'];
1763
															$x = 0;
1764
														?>
1765
														<label for="<?php echo $field['merge'] . '-no-default'; ?>">
1766
															<input id="<?php echo $field['merge'] . '-no-default'; ?>"
1767
															       type="radio"
1768
															       name="field[<?php echo $field['merge']; ?>][default_choice]"
1769
															       value="no-default" <?php checked( $field['default_choice'], 'no-default' ); ?>
1770
															>
1771
															No Default&nbsp;
1772
														</label>
1773
														<?php
1774
														foreach ( $choices as $choice => $value ) { ?>
0 ignored issues
show
Bug introduced by
The variable $choices does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1775
															<label for="<?php echo $field['merge'].'-'.$x; ?>">
1776
																<input id="<?php echo $field['merge'].'-'.$x; ?>"
1777
																       type="radio"
1778
																       name="field[<?php echo $field['merge']; ?>][default_choice]"
1779
																       value="<?php echo $x; ?>" <?php checked( $field['default_choice'], $x ); ?>>
1780
																<?php echo $value; ?>&nbsp;
1781
															</label>
1782
														<?php $x++; } ?>
1783
														<p class="description"><small><?php _e( "Select the option that should be selected by default.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1784
													</td>
1785
												</tr>
1786
1787
											<?php
1788
												break;
1789
1790
											case 'dropdown':
1791
											?>
1792
												<tr valign="top">
1793
													<td scope="row">
1794
														<label for="placeholder">
1795
															<?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?>
1796
														</label>
1797
													</td>
1798
													<td>
1799
														<select type="default" name="field[<?php echo $field['merge']; ?>][default_choice]">
1800
															<option value="no-default" <?php selected( $field['default_choice'] , 'no-default' ); ?>>No Default</option>
1801
															<?php foreach( json_decode( $field['choices'], true ) as $choice => $value ) { ?>
1802
																<option value="<?php echo $choice; ?>" <?php selected( $field['default_choice'] , $choice ); ?>><?php echo $value; ?></option>
1803
															<?php } ?>
1804
														</select>
1805
														<p class="description"><small><?php _e( "Which option should be selected by default?", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1806
													</td>
1807
												</tr>
1808
1809
										<?php
1810
												break;
1811
1812
											case "birthday":
1813
											case "address":
1814
												break;
1815
1816
										} // end Default Value ?>
1817
1818
1819
										<!-- Field Description -->
1820
										<tr valign="top">
1821
											<td scope="row">
1822
												<label for="description_<?php echo esc_attr( $field['merge'] ); ?>">
1823
													<?php _e( 'Description', 'yikes-inc-easy-mailchimp-extender' ); ?>
1824
												</label>
1825
											</td>
1826
											<td>
1827
												<textarea class="widefat field-description-input" id="description_<?php echo esc_attr( $field['merge'] ); ?>" name="field[<?php echo $field['merge']; ?>][description]"><?php echo isset( $field['description'] ) ? stripslashes( esc_html( $field['description'] ) ) : '' ; ?></textarea>
1828
												<p class="description"><small><?php _e( "Enter the description for the form field. This will be displayed to the user and will provide some direction on how the field should be filled out or selected.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1829
											</td>
1830
										</tr>
1831
										<!-- Description Above Field -->
1832
										<tr valign="top" class="yikes-checkbox-container">
1833
											<td scope="row">
1834
												<label for="description_above_<?php echo esc_attr( $field['merge'] ); ?>">
1835
													<?php _e( 'Description Above Field', 'yikes-inc-easy-mailchimp-extender' ); ?>
1836
												</label>
1837
											</td>
1838
											<td>
1839
												<input type="checkbox" id="description_above_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat field-description-input" name="field[<?php echo $field['merge']; ?>][description_above]" value="1" <?php echo isset( $field['description_above'] ) && $field['description_above'] === '1' ? 'checked="checked"' : ''; ?> />
1840
												<p class="description"><small><?php _e( "By default the description will appear undearneath the field. Check this box if you'd like the description to appear above the field.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1841
											</td>
1842
										</tr>
1843
										<!-- Additional Classes -->
1844
										<tr valign="top">
1845
											<td scope="row">
1846
												<label for="classes_<?php echo esc_attr( $field['merge'] ); ?>">
1847
													<?php _e( 'Additional Classes', 'yikes-inc-easy-mailchimp-extender' ); ?>
1848
												</label>
1849
											</td>
1850
											<td>
1851
												<input type="text" id="classes_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat" name="field[<?php echo $field['merge']; ?>][additional-classes]" value="<?php echo isset( $field['additional-classes'] ) ? stripslashes( wp_strip_all_tags( $field['additional-classes'] ) ) : '' ; ?>" />
1852
												<p class="description"><small><?php printf( __( "Assign additional classes to this field. %s.", 'yikes-inc-easy-mailchimp-extender' ), '<a target="_blank" href="' . esc_url( 'https://yikesplugins.com/support/knowledge-base/bundled-css-classes/' ) . '">' . __( 'View bundled classes', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' );?></small></p>
1853
											</td>
1854
										</tr>
1855
										<!-- Required Toggle -->
1856
										<tr valign="top" class="yikes-checkbox-container yikes-checkbox-container-first">
1857
											<td scope="row">
1858
												<label for="field-required-<?php echo esc_attr( $field['merge'] ); ?>">
1859
													<?php _e( 'Field Required?', 'yikes-inc-easy-mailchimp-extender' ); ?>
1860
												</label>
1861
											</td>
1862
											<td>
1863
												<?php $checked = isset( $field['require'] ) ? $field['require'] : '0'; ?>
1864
												<input id="field-required-<?php echo esc_attr( $field['merge'] ); ?>" type="checkbox" class="widefat" value="1" name="field[<?php echo $field['merge']; ?>][require]" <?php checked( $checked , 1 ); ?> <?php if ( $field['merge'] == 'EMAIL' ) {  ?> disabled="disabled" checked="checked" title="<?php echo __( 'Email is a required field.', 'yikes-inc-easy-mailchimp-extender' ); } ?>">
1865
												<p class="description"><small><?php _e( "Require this field to be filled in before the form can be submitted.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1866
											</td>
1867
										</tr>
1868
										<!-- Visible Toggle -->
1869
										<tr valign="top" class="yikes-checkbox-container">
1870
											<td scope="row">
1871
												<label for="hide-field-<?php echo esc_attr( $field['merge'] ); ?>">
1872
													<?php _e( 'Hide Field', 'yikes-inc-easy-mailchimp-extender' ); ?>
1873
												</label>
1874
											</td>
1875
											<td>
1876
												<?php $hide = isset( $field['hide'] ) ? $field['hide'] : '0'; ?>
1877
												<input id="hide-field-<?php echo esc_attr( $field['merge'] ); ?>" type="checkbox" class="widefat" value="1" name="field[<?php echo $field['merge']; ?>][hide]" <?php checked( $hide , 1 ); ?> <?php if ( $field['merge'] == 'EMAIL' ) {  ?> disabled="disabled" title="<?php echo __( 'Cannot toggle email field visibility.', 'yikes-inc-easy-mailchimp-extender' ); } ?>">
1878
												<p class="description"><small><?php _e( "Hide this field from being displayed on the front end.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1879
											</td>
1880
										</tr>
1881
										<!-- Toggle Field Label Visibility -->
1882
										<tr valign="top" class="yikes-checkbox-container">
1883
											<td scope="row">
1884
												<label for="hide-label-<?php echo esc_attr( $field['merge'] ); ?>">
1885
													<?php _e( 'Hide Label', 'yikes-inc-easy-mailchimp-extender' ); ?>
1886
												</label>
1887
											</td>
1888
											<td>
1889
												<?php $hide_label = isset( $field['hide-label'] ) ? $field['hide-label'] : '0'; ?>
1890
												<input id="hide-label-<?php echo esc_attr( $field['merge'] ); ?>" type="checkbox" name="field[<?php echo $field['merge']; ?>][hide-label]" value="1" <?php checked( $hide_label , 1 ); ?>/>
1891
												<p class="description"><small><?php _e( "Toggle field label visibility.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1892
											</td>
1893
										</tr>
1894
										<!-- Display Phone/Date Formats back to the user -->
1895
										<!-- Phone Format Initial Load -->
1896
										<?php
1897
											switch( $field['type'] ) {
1898
												/* Store the phone format, for properly regex pattern */
1899
												case 'phone':
1900
												case 'birthday':
1901
												case 'date':
1902
													?>
1903
														<tr valign="top">
1904
															<td scope="row">
1905
																<label for="placeholder">
1906
																	<?php
1907
																		switch( $field['type'] ) {
1908
																			default:
1909 View Code Duplication
																			case 'birthday':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1910
																				$type = __( 'Date Format', 'yikes-inc-easy-mailchimp-extender' );
1911
																				$format = ( isset( $field['date_format'] ) ) ? $field['date_format'] : 'MM/DD';
1912
																				$format_name = 'date_format';
1913
																				break;
1914
1915 View Code Duplication
																			case 'date':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1916
																				$type = __( 'Date Format', 'yikes-inc-easy-mailchimp-extender' );
1917
																				$format = ( isset( $field['date_format'] ) ) ? $field['date_format'] : 'MM/DD/YYYY';
1918
																				$format_name = 'date_format';
1919
																				break;
1920
1921
																			case 'phone':
1922
																				$type = __( 'Phone Format', 'yikes-inc-easy-mailchimp-extender' );
1923
																				$format = isset( $field['phone_format'] ) && ! empty( $field['phone_format'] ) ? $field['phone_format'] : __( 'International', 'yikes-inc-easy-mailchimp-extender' );
1924
																				$format_name = 'phone_format';
1925
																				break;
1926
																		}
1927
																		echo $type;
1928
																	?>
1929
																</label>
1930
															</td>
1931
															<td>
1932
																<strong><?php echo $format; ?></strong>
1933
																<input type="hidden" name="field[<?php echo $field['merge']; ?>][<?php echo $format_name; ?>]" value="<?php echo $format; ?>" />
1934
																<p class="description"><small>
1935
																	<?php printf( __( 'To change the %s please head over to <a href="%s" title="Mailchimp" target="_blank">Mailchimp</a>. If you alter the format, you should re-import this field.', 'yikes-inc-easy-mailchimp-extender' ), strtolower( $type ), esc_url( 'http://www.mailchimp.com' ) ); ?>
1936
																</small></p>
1937
															</td>
1938
														</tr>
1939
													<?php
1940
												break;
1941
												// others..
1942
												default:
1943
													break;
1944
											}
1945
										?>
1946
										<!-- End Date/Phone Formats -->
1947
										<!-- Toggle Buttons -->
1948
										<tr valign="top">
1949
											<td scope="row">
1950
												&nbsp;
1951
											</td>
1952
											<td>
1953
												<span class="toggle-container">
1954
													<a href="#" class="close-form-expansion"><?php _e( "Close" , 'yikes-inc-easy-mailchimp-extender' ); ?></a> |
1955
													<a href="#" class="remove-field" alt="<?php echo $field['merge']; ?>"><?php _e( "Remove Field" , 'yikes-inc-easy-mailchimp-extender' ); ?></a>
1956
												</span>
1957
											</td>
1958
										</tr>
1959
									</table>
1960
								</p>
1961
1962
							</div>
1963
						</section>
1964
						<?php
1965
1966
1967
1968
					} else {
1969
1970
						/**** Interest Group ****/
1971
1972
						?>
1973
						<section class="draggable" id="<?php echo $field['group_id']; ?>">
1974
							<!-- top -->
1975
							<a href="#" class="expansion-section-title settings-sidebar">
1976
								<span class="dashicons dashicons-plus yikes-mc-expansion-toggle"></span><?php echo stripslashes( $field['label'] ); ?>
1977
								<?php if ( in_array( $field['group_id'] , $excluded_fields ) ) { ?>
1978
									<img src="<?php echo YIKES_MC_URL . 'includes/images/warning.svg'; ?>" class="field-no-longer-exists-warning" title="<?php _e( 'Field no longer exists.', 'yikes-inc-easy-mailchimp-extender' ); ?>" alt="<?php _e( 'Field no longer exists.', 'yikes-inc-easy-mailchimp-extender' ); ?>">
1979
								<?php } ?>
1980
								<span class="field-type-text"><small><?php echo __( 'type', 'yikes-inc-easy-mailchimp-extender' ) . ' : ' . $field['type']; ?></small></span>
1981
							</a>
1982
							<!-- expansion section -->
1983
							<div class="yikes-mc-settings-expansion-section">
1984
1985
								<!-- check if this field exists in the available interest group array -->
1986
								<?php if ( in_array( $field['group_id'] , $excluded_fields ) ) { ?>
1987
									<p class="yikes-mc-warning-message"><?php _e( "This field no longer exists in this list. Delete this field from the form to prevent issues on the front end." , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
1988
								<?php } ?>
1989
1990
								<!-- store the label -->
1991
								<input type="hidden" name="field[<?php echo $field['group_id']; ?>][label]" value="<?php echo htmlspecialchars( $field['label'] ); ?>" />
1992
								<input type="hidden" name="field[<?php echo $field['group_id']; ?>][type]" value="<?php echo $field['type']; ?>" />
1993
								<input type="hidden" name="field[<?php echo $field['group_id']; ?>][group_id]" value="<?php echo $field['group_id']; ?>" />
1994
								<input type="hidden" name="field[<?php echo $field['group_id']; ?>][groups]" value='<?php echo esc_attr( json_encode( json_decode( $field['groups'], true ) ) ); ?>' />
1995
1996
								<!-- Single or Double Opt-in -->
1997
								<p class="type-container"><!-- necessary to prevent skipping on slideToggle(); -->
1998
1999
									<table class="form-table form-field-container">
2000
										<!-- Default Value -->
2001
										<?php switch( $field['type'] ) {
2002
											default:
2003
											case 'radio':
2004
											case 'checkboxes':
2005
											?>
2006
												<tr valign="top">
2007
													<td scope="row">
2008
														<label for="placeholder">
2009
															<?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?>
2010
														</label>
2011
													</td>
2012
													<td>
2013
														<?php
2014
														$field['default_choice'] = isset( $field['default_choice'] ) ? $field['default_choice'] : '';
2015
2016
														$default_shown = false;
2017
2018
														foreach ( json_decode( $field['groups'], true ) as $id => $group ) {
2019
															$field_id   = "{$field['group_id']}-{$id}";
2020
															$field_type = 'hidden' == $field['type'] ? 'checkbox' : $field['type'];
2021
															$field_type = 'checkboxes' == $field_type ? 'checkbox' : $field_type;
2022
															$field_name = "field[{$field['group_id']}][default_choice]";
2023
															$field_name = 'checkbox' == $field_type ? $field_name . '[]' : $field_name;
2024
2025
															// Determine if the current group is checked.
2026
															$checked = '';
0 ignored issues
show
Unused Code introduced by
$checked is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2027
															switch ( $field_type ) {
2028
																case 'radio':
2029
																default:
2030
																	$default = is_array( $field['default_choice'] ) ? current( $field['default_choice'] ) : $field['default_choice'];
0 ignored issues
show
Unused Code introduced by
$default is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2031
																	$checked = is_array( $field['default_choice'] ) ? checked( current( $field['default_choice'] ), $id, false ) : checked( $field['default_choice'], $id, false );
2032
																break;
2033
2034
																case 'checkbox':
0 ignored issues
show
Unused Code introduced by
case 'checkbox': does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
2035
																case 'hidden':
2036
																	if ( is_array( $field['default_choice'] ) && in_array( $id, $field['default_choice'] ) ) {
2037
																		$checked = checked( true, true, false );
2038
																	}
2039
																break;
2040
															}
2041
2042
															// Allow users to not set a default choice for radio buttons.
2043
															if ( $field_type === 'radio' && $default_shown === false ) {
2044
																$default_shown = true;
2045
																?>
2046
																<label for="<?php echo $field_id . 'no-default'; ?>">
2047
																	<input id="<?php echo $field_id . 'no-default'; ?>"
2048
																	    type="<?php echo $field_type; ?>"
2049
																	    name="<?php echo $field_name; ?>"
2050
																	    value="no-default" 
2051
																	    <?php is_array( $field['default_choice'] ) ? checked( current( $field['default_choice'] ), 'no-default' ) : checked( $field['default_choice'], 'no-default' ); ?>>
2052
																	No Default&nbsp;
2053
																</label>
2054
																<?php
2055
															}
2056
2057
															?>
2058
															<label for="<?php echo $field_id; ?>">
2059
																<input id="<?php echo $field_id; ?>"
2060
																    type="<?php echo $field_type; ?>"
2061
																    name="<?php echo $field_name; ?>"
2062
																    value="<?php echo $id; ?>" <?php echo $checked; ?>>
2063
																<?php echo stripslashes( str_replace( '\'', '', $group ) ); ?>&nbsp;
2064
															</label>
2065
															<?php
2066
														} ?>
2067
														<p class="description"><small><?php _e( "Select the option that should be selected by default.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2068
													</td>
2069
												</tr>
2070
2071
											<?php
2072
												break;
2073
2074
											case 'dropdown':
2075
											?>
2076
												<!-- Placeholder -->
2077
												<tr valign="top">
2078
													<td scope="row">
2079
														<label for="placeholder_<?php echo esc_attr( $field['merge'] ); ?>">
2080
															<?php _e( 'Placeholder', 'yikes-inc-easy-mailchimp-extender' ); ?>
2081
														</label>
2082
													</td>
2083
													<td>
2084
														<input type="text" id="placeholder_<?php echo esc_attr( $field['merge'] ); ?>" class="widefat" name="field[<?php echo $field['merge']; ?>][placeholder]" value="<?php echo isset( $field['placeholder'] ) ? $field['placeholder'] : '' ; ?>" />
2085
														<p class="description"><small><?php _e( "Assign a placeholder value to this field.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2086
													</td>
2087
												</tr>
2088
												<tr valign="top">
2089
													<td scope="row">
2090
														<label for="placeholder">
2091
															<?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?>
2092
														</label>
2093
													</td>
2094
													<td>
2095
														<select type="default" name="field[<?php echo $field['group_id']; ?>][default_choice]">
2096
															<option value="no-default">No Default</option>
2097
															<?php foreach( json_decode( stripslashes_deep( $field['groups'] ) , true ) as $id => $group ) { ?>
2098
																<option value="<?php echo $id; ?>" <?php selected( $field['default_choice'] , $id ); ?>><?php echo stripslashes( $group ); ?></option>
2099
															<?php } ?>
2100
														</select>
2101
														<p class="description"><small><?php _e( "Which option should be selected by default?", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2102
													</td>
2103
												</tr>
2104
2105
											<?php
2106
												break;
2107
										?>
2108
0 ignored issues
show
Unused Code introduced by
?> <?php does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
2109
										<?php } // end Default Value ?>
2110
2111
										<!-- Field Description -->
2112
										<tr valign="top">
2113
											<td scope="row">
2114
												<label for="description_<?php echo esc_attr( $field['group_id'] ); ?>">
2115
													<?php _e( 'Description', 'yikes-inc-easy-mailchimp-extender' ); ?>
2116
												</label>
2117
											</td>
2118
											<td>
2119
												<textarea id="description_<?php echo esc_attr( $field['group_id'] ); ?>" class="widefat field-description-input" name="field[<?php echo $field['group_id']; ?>][description]"><?php echo isset( $field['description'] ) ? stripslashes( esc_html( $field['description'] ) ) : '' ; ?></textarea>
2120
												<p class="description"><small><?php _e( "Enter the description for the form field. This will be displayed to the user and provide some direction on how the field should be filled out or selected.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2121
											</td>
2122
										</tr>
2123
2124
										<!-- Description Above Field -->
2125
										<tr valign="top" class="yikes-checkbox-container">
2126
											<td scope="row">
2127
												<label for="description_above_<?php echo $field['group_id']; ?>">
2128
													<?php _e( 'Description Above Field', 'yikes-inc-easy-mailchimp-extender' ); ?>
2129
												</label>
2130
											</td>
2131
											<td>
2132
												<input type="checkbox" id="description_above_<?php echo $field['group_id']; ?>" class="widefat field-description-input" name="field[<?php echo $field['group_id']; ?>][description_above]" value="1" <?php echo isset( $field['description_above'] ) && $field['description_above'] === '1' ? 'checked="checked"' : ''; ?> />
2133
												<p class="description"><small><?php _e( "By default the description will appear undearneath the field. Check this box if you'd like the description to appear above the field.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2134
											</td>
2135
										</tr>
2136
2137
										<!-- Additional Classes -->
2138
										<tr valign="top">
2139
											<td scope="row">
2140
												<label for="classes_<?php echo esc_attr( $field['group_id'] ); ?>">
2141
													<?php _e( 'Additional Classes', 'yikes-inc-easy-mailchimp-extender' ); ?>
2142
												</label>
2143
											</td>
2144
											<td>
2145
												<input type="text" id="classes_<?php echo esc_attr( $field['group_id'] ); ?>" class="widefat" name="field[<?php echo $field['group_id']; ?>][additional-classes]" value="<?php echo isset( $field['additional-classes'] ) ? stripslashes( wp_strip_all_tags( $field['additional-classes'] ) ) : '' ; ?>" />
2146
												<p class="description"><small><?php printf( __( "Assign additional classes to this field. %s.", 'yikes-inc-easy-mailchimp-extender' ), '<a target="_blank" href="' . esc_url( 'https://yikesplugins.com/support/knowledge-base/bundled-css-classes/' ) . '">' . __( 'View bundled classes', 'yikes-inc-easy-mailchimp-extender' ) . '</a>' );?></small></p>
2147
											</td>
2148
										</tr>
2149
										<!-- Required Toggle -->
2150
										<tr valign="top" class="yikes-checkbox-container">
2151
											<td scope="row">
2152
												<label for="field-required-<?php echo esc_attr( $field['group_id'] ); ?>">
2153
													<?php _e( 'Field Required?', 'yikes-inc-easy-mailchimp-extender' ); ?>
2154
												</label>
2155
											</td>
2156
											<td>
2157
												<?php $checked = isset( $field['require'] ) ? $field['require'] : '0'; ?>
2158
												<input type="checkbox" id="field-required-<?php echo esc_attr( $field['group_id'] ); ?>" class="widefat" value="1" name="field[<?php echo $field['group_id']; ?>][require]" <?php checked( $checked , 1 ); ?>>
2159
												<p class="description"><small><?php _e( "Require this field to be filled in before the form can be submitted.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2160
											</td>
2161
										</tr>
2162
										<!-- Visible Toggle -->
2163
										<tr valign="top" class="yikes-checkbox-container">
2164
											<td scope="row">
2165
												<label for="hide-field-<?php echo esc_attr( $field['group_id'] ); ?>">
2166
													<?php _e( 'Hide Field', 'yikes-inc-easy-mailchimp-extender' ); ?>
2167
												</label>
2168
											</td>
2169
											<td>
2170
												<?php $hide = isset( $field['hide'] ) ? $field['hide'] : '0'; ?>
2171
												<input type="checkbox" id="hide-field-<?php echo esc_attr( $field['group_id'] ); ?>" class="widefat" value="1" name="field[<?php echo $field['group_id']; ?>][hide]" <?php checked( $hide , 1 ); ?>>
2172
												<p class="description"><small><?php _e( "Hide this field from being displayed on the front end.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2173
											</td>
2174
										</tr>
2175
										<!-- Toggle Field Label Visibility -->
2176
										<tr valign="top" class="yikes-checkbox-container">
2177
											<td scope="row">
2178
												<label for="hide-label-<?php echo esc_attr( $field['group_id'] ); ?>">
2179
													<?php _e( 'Hide Label', 'yikes-inc-easy-mailchimp-extender' ); ?>
2180
												</label>
2181
											</td>
2182
											<td>
2183
												<?php $hide = isset( $field['hide-label'] ) ? $field['hide-label'] : '0'; ?>
2184
												<input type="checkbox" id="hide-label-<?php echo esc_attr( $field['group_id'] ); ?>" name="field[<?php echo $field['group_id']; ?>][hide-label]" value="1" <?php checked( $hide , 1 ); ?>/>
2185
												<p class="description"><small><?php _e( "Toggle field label visibility.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2186
											</td>
2187
										</tr>
2188
										<!-- Toggle Buttons -->
2189
										<tr valign="top">
2190
											<td scope="row">
2191
												&nbsp;
2192
											</td>
2193
											<td>
2194
												<span class="toggle-container">
2195
													<a href="#" class="close-form-expansion"><?php _e( "Close" , 'yikes-inc-easy-mailchimp-extender' ); ?></a> |
2196
													<a href="#" class="remove-field" alt="<?php echo $field['group_id']; ?>"><?php _e( "Remove Field" , 'yikes-inc-easy-mailchimp-extender' ); ?></a>
2197
												</span>
2198
											</td>
2199
										</tr>
2200
									</table>
2201
								</p>
2202
2203
							</div>
2204
						</section>
2205
						<?php
2206
					}
2207
				}
2208
			} else {
2209
				?>
2210
					<h4 class="no-fields-assigned-notice non-draggable-yikes"><em><?php _e( 'No fields are assigned to this form. Select fields from the right hand column to add to this form.', 'yikes-inc-easy-mailchimp-extender' ); ?></em></h4>
2211
				<?php
2212
			}
2213
				/* Pre Defined Merge Tag Container - Always rendered so the modal appears and links are clickable on initial page load */
2214
				add_thickbox();
2215
				// enqueue jquery qtip for our tooltip
2216
				wp_enqueue_script( 'jquery-qtip-tooltip', YIKES_MC_URL . 'admin/js/min/jquery.qtip.min.js', array( 'jquery' ) );
2217
				wp_enqueue_style( 'jquery-qtip-style',  YIKES_MC_URL . 'admin/css/jquery.qtip.min.css' );
2218
					$available_tags = array(
2219
						array(
2220
							'tag' => '{page_title}',
2221
							'description' => '<h4 class="tooltip-title">' . __( 'Page Title', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{page_title}</small></h4><hr />' . __( 'Pre-populate the field with the current page or post title that the user is on when opting in to your mailing list.', 'yikes-inc-easy-mailchimp-extender' ),
2222
							'title' => __( 'Page Title', 'yikes-inc-easy-mailchimp-extender' )
2223
						),
2224
						array(
2225
							'tag' => '{page_id}',
2226
							'description' => '<h4 class="tooltip-title">' . __( 'Page ID', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{page_id}</small></h4><hr />' . __( 'Pre-populate the field with the current page or post ID that the user is on when opting in to your mailing list.', 'yikes-inc-easy-mailchimp-extender' ),
2227
							'title' => __( 'Page ID', 'yikes-inc-easy-mailchimp-extender' )
2228
						),
2229
						array(
2230
							'tag' => '{page_url}',
2231
							'description' => '<h4 class="tooltip-title">' . __( 'Page URL', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{page_url}</small></h4><hr />' . __( 'Pre-populate the field with the current page URL that the user is on when opting in to your mailing list.', 'yikes-inc-easy-mailchimp-extender' ),
2232
							'title' => __( 'Page URL', 'yikes-inc-easy-mailchimp-extender' )
2233
						),
2234
						array(
2235
							'tag' => '{blog_name}',
2236
							'description' => '<h4 class="tooltip-title">' . __( 'Blog Name', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{blog_name}</small></h4><hr />' . __( 'Pre-populate the field with the current blog name that the user is on when opting in to your mailing list. This is especially helpful for multi-site networks.', 'yikes-inc-easy-mailchimp-extender' ),
2237
							'title' => __( 'Blog Name', 'yikes-inc-easy-mailchimp-extender' )
2238
						),
2239
						array(
2240
							'tag' => '{user_logged_in}',
2241
							'description' => '<h4 class="tooltip-title">' . __( 'User Logged In', 'yikes-inc-easy-mailchimp-extender' ) . ' | <small>{user_logged_in}</small></h4><hr />' . __( 'Detects if a user is logged in and pre-populates the field with an appropriate value.', 'yikes-inc-easy-mailchimp-extender' ),
2242
							'title' => __( 'User Logged In', 'yikes-inc-easy-mailchimp-extender' )
2243
						),
2244
					);
2245
				?>
2246
				<!-- tooltips -->
2247
				<script type="text/javascript">
2248
					/* Initialize Qtip tooltips for pre-defined tags */
2249
					jQuery( document ).ready( function() {
2250
						jQuery( '.dashicons-editor-help' ).each( function() {
2251
							 jQuery( this ).qtip({
2252
								 content: {
2253
									 text: jQuery( this ).next( '.tooltiptext' ),
2254
									 style: {
2255
										def: false
2256
									 }
2257
								 }
2258
							 });
2259
						 });
2260
						 jQuery( '.qtip' ).each( function() {
2261
							jQuery( this ).removeClass( 'qtip-default' );
2262
						 });
2263
					});
2264
				</script>
2265
2266
				<div id="pre-defined-tag-container">
2267
					<input type="hidden" value="" class="clicked-input">
2268
					<div id="pre-defined-tag-interior-container">
2269
						<h3><?php _e( 'Pre Defined Tags', 'yikes-inc-easy-mailchimp-extender' ); ?></h3>
2270
						<p class="description"><?php _e( 'You can use any of the following tags to populate a Mailchimp text field with dynamic content. This can be used to determine which page the user signed up on, if the user was logged in and more.', 'yikes-inc-easy-mailchimp-extender' ); ?></p>
2271
						<ul>
2272
							<?php foreach( apply_filters( 'yikes-mailchimp-custom-default-value-tags', $available_tags ) as $tag ) { ?>
2273
								<li class="tooltop-tag">
2274
									<!-- link/tag -->
2275
									<a href="#" onclick="populateDefaultValue( '<?php echo $tag['tag']; ?>' );return false;" data-attr-tag="<?php echo $tag['tag']; ?>" title="<?php echo $tag['title']; ?>"><?php echo $tag['title']; ?></a>
2276
									<!-- help icon -->
2277
									<span class="dashicons dashicons-editor-help"></span>
2278
									<!-- tooltip -->
2279
									<div class="tooltiptext qtip-bootstrap yikes-easy-mc-hidden"><?php echo $tag['description']; ?></div>
2280
								</li>
2281
							<?php } ?>
2282
						</ul>
2283
					</div>
2284
				</div>
2285
				<?php
2286
		}
2287
2288
		/**
2289
		 *	build_available_merge_vars( $list_id )
2290
		 *	Submit an API request to get our merge variables, and build up a small form editor
2291
		 *	for users to 'customize' their form
2292
		 *	-
2293
		 * @parameters - $list_id - pass in the list ID to retreive merge variables from
2294
		 */
2295
		public function build_available_merge_vars( $form_fields, $available_merge_variables ) {
2296
			$fields_assigned_to_form = array();
2297 View Code Duplication
			foreach ( $form_fields as $field ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2298
				if ( isset( $field['merge'] ) ) {
2299
					$fields_assigned_to_form[ $field['merge'] ] = true;
2300
				}
2301
			}
2302
2303
			if ( ! empty( $available_merge_variables['merge_fields'] ) ) {
2304
				?>
2305
				<ul id="available-fields"><?php
2306
				foreach ( $available_merge_variables['merge_fields'] as $merge_var ) {
2307
					$not_available = isset( $fields_assigned_to_form[ $merge_var['tag'] ] );
2308
					?>
2309
					<li class="available-field <?php echo $not_available ? 'not-available' : ''; ?>"
2310
						alt="<?php echo esc_attr( $merge_var['tag'] ); ?>"
2311
						data-attr-field-type="<?php echo esc_attr( $merge_var['type'] ); ?>"
2312
						data-attr-field-name="<?php echo esc_attr( $merge_var['name'] ); ?>"
2313
						data-attr-form-id="<?php echo esc_attr( $available_merge_variables['list_id'] ); ?>"
2314
						title="<?php echo $not_available ? esc_attr__( 'Already assigned to your form', 'yikes-inc-easy-mailchimp-extender' ) : ''; ?>"
2315
						<?php echo $not_available ? 'disabled="disabled"' : ''; ?>
2316
					>
2317
						<?php
2318
							echo esc_html( stripslashes( $merge_var['name'] ) );
2319
							if ( $merge_var['required'] ) {
2320
								echo ' <span class="field-required" title="' . __( 'required field', 'yikes-inc-easy-mailchimp-extender' ) . '">*</span>';
2321
							}
2322
						?>
2323
						<small class="field-type-text"><?php echo esc_html( $merge_var['type'] ); ?></small>
2324
					</li>
2325
					<?php
2326
				}
2327
				?></ul>
2328
				<a href="#" class="add-field-to-editor add-to-editor button-secondary yikes-easy-mc-hidden" style="display:none;">
2329
					<small>
2330
						<span class="dashicons dashicons-arrow-left-alt add-to-form-builder-arrow"></span> <?php _e( 'Add to Form Builder', 'yikes-inc-easy-mailchimp-extender' ); ?>
2331
					</small>
2332
				</a>
2333
				<?php
2334
			}
2335
		}
2336
2337
		/**
2338
		 *	build_available_interest_groups( $form_fields , $available_interest_groups )
2339
		 *	Submit an API request to get our merge variables, and build up a small form editor
2340
		 *	for users to 'customize' their form
2341
		 *	-
2342
		 * @parameters - $list_id - pass in the list ID to retreive merge variables from
2343
		 */
2344
		public function build_available_interest_groups( $form_fields, $available_interest_groups, $list_id ) {
2345
			$fields_assigned_to_form = array();
2346
			if ( ! empty( $form_fields ) ) {
2347 View Code Duplication
				foreach ( $form_fields as $field ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2348
					if ( isset( $field['group_id'] ) ) {
2349
						$fields_assigned_to_form[ $field['group_id'] ] = true;
2350
					}
2351
				}
2352
			}
2353
2354
			if ( ! empty( $available_interest_groups ) ) {
2355
			?>
2356
				<ul id="available-interest-groups">
2357
				<?php
2358
					foreach ( $available_interest_groups as $interest_group ) {
2359
						$not_available = isset( $fields_assigned_to_form[ $interest_group['id'] ] );
2360
						?>
2361
						<li class="available-field <?php echo $not_available ? 'not-available' : ''; ?>" 
2362
							alt="<?php echo esc_attr( $interest_group['id'] ); ?>" 
2363
							data-group-id="<?php echo esc_attr( $interest_group['id'] ); ?>" 
2364
							data-attr-field-name="<?php echo esc_attr( htmlspecialchars( $interest_group['title'] ) ); ?>" 
2365
							data-attr-field-type="<?php echo esc_attr( $interest_group['type'] ); ?>" 
2366
							data-attr-form-id="<?php echo esc_attr( $list_id ); ?>"
2367
							title="<?php echo $not_available ? __( 'Already assigned to your form', 'yikes-inc-easy-mailchimp-extender' ) : ''; ?>"
2368
							<?php echo $not_available ? 'disabled="disabled"' : ''; ?>
2369
						>
2370
							<?php echo esc_html( stripslashes( $interest_group['title'] ) ); ?>
2371
							<small class="field-type-text"><?php echo esc_html( $interest_group['type'] ); ?></small>
2372
						</li>
2373
						<?php
2374
					}
2375
				?>
2376
				</ul>
2377
				<a href="#" class="add-interest-group-to-editor add-to-editor button-secondary yikes-easy-mc-hidden" style="display:none;">
2378
					<small>
2379
						<span class="dashicons dashicons-arrow-left-alt add-to-form-builder-arrow"></span> <?php esc_html_e( 'Add to Form Builder', 'yikes-inc-easy-mailchimp-extender' ); ?>
2380
					</small>
2381
				</a>
2382
			<?php
2383
			}
2384
		}
2385
2386
		/**
2387
		 * Smt.
2388
		 */
2389
		public function build_available_tags( $form_tags, $tags, $list_id ) {
0 ignored issues
show
Unused Code introduced by
The parameter $list_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2390
			?>
2391
			<ul id="available-tags">
2392
			<?php
2393
			foreach ( $tags as $tag_id => $tag ) {
2394
				$not_available = isset( $form_tags[ $tag_id ] );
2395
				?>
2396
				<li class="available-field <?php echo $not_available ? 'not-available' : ''; ?>"
2397
					id="tag-<?php echo esc_attr( $tag['id'] ); ?>"
2398
					data-tag-id="<?php echo esc_attr( $tag['id'] ); ?>"
2399
					data-tag-name="<?php echo esc_attr( $tag['name'] ); ?>"
2400
					title="<?php echo $not_available ? __( 'Already assigned to your form', 'yikes-inc-easy-mailchimp-extender' ) : esc_attr( $tag['name'] ); ?>"
2401
					<?php echo $not_available ? 'disabled="disabled"' : ''; ?>
2402
				>
2403
					<?php echo esc_html( $tag['name'] ); ?>
2404
				</li>
2405
				<?php
2406
			}
2407
			?>
2408
			</ul>
2409
			<a href="#" class="add-tag-to-editor add-to-editor button-secondary yikes-easy-mc-hidden" style="display:none;">
2410
				<small>
2411
					<span class="dashicons dashicons-arrow-left-alt add-to-form-builder-arrow"></span> <?php _e( 'Add to Form Builder', 'yikes-inc-easy-mailchimp-extender' ); ?>
2412
				</small>
2413
			</a>
2414
			<?php
2415
		}
2416
2417
		/*
2418
		*	Create A New Form!
2419
		*	Probably Move these to its own file,
2420
		*	and include it here for easy maintenance
2421
		*	- must clean up db tables , ensure what data is going in and what is needed...
2422
		*/
2423
		public function yikes_easy_mailchimp_create_form() {
2424
			$nonce = $_REQUEST['nonce'];
2425
			if ( ! wp_verify_nonce( $nonce, 'create_mailchimp_form' ) ) {
2426
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) );
2427
			}
2428
2429
			$result = $this->form_interface->create_form( array(
2430
				'list_id'          => sanitize_key( $_POST['associated-list'] ),
2431
				'form_name'        => stripslashes( $_POST['form-name'] ),
2432
				'form_description' => stripslashes( $_POST['form-description'] ),
2433
			) );
2434
2435
			// if an error occurs during the form creation process
2436
			if ( false == $result ) {
2437
				// write it to the error log
2438
				// if the form was not created successfully
2439
				$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
2440
				$error_logging->maybe_write_to_log( __( 'Error creating a new form', 'yikes-inc-easy-mailchimp-extender') , __( "Creating a new form" , 'yikes-inc-easy-mailchimp-extender' ) , __( "Forms" , 'yikes-inc-easy-mailchimp-extender' ) );
2441
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-edit-form&sql_error=' . urlencode( __( 'Error creating a new form', 'yikes-inc-easy-mailchimp-extender' ) ) ) ) );
2442
			} else {
2443
				// redirect the user to the new form edit page
2444
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-edit-form&id=' . $result) ) );
2445
			}
2446
			exit();
2447
		}
2448
2449
		/*
2450
		*	Delete A Form !
2451
		*	Probably Move these to its own file,
2452
		*	and include it here for easy maintenance
2453
		*	- must clean up db tables , ensure what data is going in and what is needed...
2454
		*/
2455
		public function yikes_easy_mailchimp_delete_form() {
2456
			// grab & store our variables ( associated list & form name )
2457
			$nonce = $_REQUEST['nonce'];
2458
			$post_id_to_delete = $_REQUEST['mailchimp-form'];
2459
			// verify our nonce
2460 View Code Duplication
			if ( ! wp_verify_nonce( $nonce, 'delete-mailchimp-form-'.$post_id_to_delete ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2461
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) );
2462
			}
2463
2464
			$this->form_interface->delete_form( $post_id_to_delete );
2465
2466
			// redirect the user to the manage forms page, display confirmation
2467
			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&deleted-form=true' ) ) );
2468
			exit();
2469
		}
2470
2471
		/*
2472
		*	Duplicate an entire form !
2473
		*	Probably Move these to its own file,
2474
		*/
2475
		public function yikes_easy_mailchimp_duplicate_form() {
2476
			// grab & store our variables ( associated list & form name )
2477
			$nonce = $_REQUEST['nonce'];
2478
			$post_id_to_clone = $_REQUEST['mailchimp-form'];
2479
			// verify our nonce
2480 View Code Duplication
			if ( ! wp_verify_nonce( $nonce, 'duplicate-mailchimp-form-'.$post_id_to_clone ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2481
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) );
2482
			}
2483
2484
			// Get the current form data.
2485
			$form_data = $this->form_interface->get_form( $post_id_to_clone );
2486
2487
			// Update some of the data before duplication
2488
			$form_data['form_name'] .= ' - Copy';
2489
			$form_data['impressions'] = $form_data['submissions'] = 0;
2490
2491
			// Create the new form, and handle the result.
2492
			$result = $this->form_interface->create_form( $form_data );
2493
2494
			/**
2495
			* `yikes-mailchimp-after-duplicating-form`
2496
			*
2497
			* @param $post_id_to_clone | int   | ID of the original form
2498
			* @param $result           | mixed | ID of the new form OR false if the operation failed
2499
			* @param $form_data        | array | Array of the form data 
2500
			*
2501
			*/
2502
			do_action( 'yikes-mailchimp-after-duplicating-form', $post_id_to_clone, $result, $form_data );
2503
2504 View Code Duplication
			if ( false === $result ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2505
				// redirect the user to the manage forms page, display error
2506
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&duplicated-form=false' ) ) );
2507
			} else {
2508
				// redirect the user to the manage forms page, display confirmation
2509
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&duplicated-form=true' ) ) );
2510
			}
2511
2512
			exit();
2513
		}
2514
2515
		/*
2516
		*	Reset a forms impression stats
2517
		*/
2518
		public function yikes_easy_mailchimp_reset_impression_stats() {
2519
			// grab & store our variables ( associated list & form name )
2520
			$nonce = $_REQUEST['nonce'];
2521
			$form_id_to_reset = $_REQUEST['mailchimp-form'];
2522
			// verify our nonce
2523 View Code Duplication
			if ( ! wp_verify_nonce( $nonce, 'reset-stats-mailchimp-form-'.$form_id_to_reset ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2524
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) );
2525
			}
2526
2527
			$result = $this->form_interface->update_form(
2528
				$form_id_to_reset,
2529
				array(
2530
					'impressions' => 0,
2531
					'submissions' => 0
2532
				)
2533
			);
2534
2535 View Code Duplication
			if ( false === $result ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2536
				// redirect the user to the manage forms page, display error
2537
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&reset-stats=false' ) ) );
2538
			} else {
2539
				// redirect the user to the manage forms page, display confirmation
2540
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&reset-stats=true' ) ) );
2541
			}
2542
2543
			exit();
2544
		}
2545
2546
		/*
2547
		*	Update an entire form !
2548
		*	Probably Move these to its own file,
2549
		*/
2550
		public function yikes_easy_mailchimp_update_form() {
2551
2552
			$nonce   = $_REQUEST['nonce'];
2553
			$form_id = $_REQUEST['id'];
2554
2555
			// verify our nonce
2556 View Code Duplication
			if ( ! wp_verify_nonce( $nonce, 'update-mailchimp-form-' . $form_id ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2557
				wp_die(
2558
					__( "We've run into an error. The security check didn't pass. Please try again.", 'yikes-inc-easy-mailchimp-extender' ),
2559
					__( "Failed nonce validation", 'yikes-inc-easy-mailchimp-extender' ),
2560
					array(
2561
						'response'  => 500,
2562
						'back_link' => true,
2563
				) );
2564
			}
2565
2566
			// Store our values!
2567
			$list_id                 = $_POST['associated-list'];
2568
			$form_name               = stripslashes( $_POST['form-name'] );
2569
			$form_description        = sanitize_text_field( stripslashes( $_POST['form-description'] ) );
2570
			$redirect_user_on_submit = $_POST['redirect-user-on-submission'];
2571
			$redirect_page           = $_POST['redirect-user-to-selection'];
2572
2573
			// stripslashes_deep on save, to prevent foreign languages from added excessive backslashes
2574
			$assigned_fields = isset( $_POST['field'] ) ? stripslashes_deep( $_POST['field'] ): array();
2575
2576
			// setup our submission settings serialized array
2577
			$submission_settings = array(
2578
				'ajax'                   => $_POST['form-ajax-submission'],
2579
				'redirect_on_submission' => $_POST['redirect-user-on-submission'],
2580
				'redirect_page'          => $_POST['redirect-user-to-selection'],
2581
				'custom_redirect_url'    => esc_url( $_POST['custom-redirect-url'] ),
2582
				'redirect_new_window'	 => $_POST['redirect_new_window'],
2583
				'hide_form_post_signup'  => $_POST['hide-form-post-signup'],
2584
				'replace_interests'      => $_POST['replace-interest-groups'],
2585
			);
2586
2587
			// setup our opt-in settings serialized array
2588
			$optin_settings = array(
2589
				'optin'                => $_POST['single-double-optin'],
2590
				'update_existing_user' => $_POST['update-existing-user'],
2591
				'send_update_email'    => $_POST['update-existing-email'],
2592
			);
2593
2594
			// Setup our error settings serialized array
2595
			$error_settings = array(
2596
				'success'				=> trim( $_POST['yikes-easy-mc-success-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-success-message'] ) ) : '',
2597
				'success-single-optin'	=> trim( $_POST['yikes-easy-mc-success-single-optin-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-success-single-optin-message'] ) ) : '',
2598
				'success-resubscribed'	=> trim( $_POST['yikes-easy-mc-user-resubscribed-success-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-resubscribed-success-message'] ) ) : '',
2599
				'general-error'			=> trim( $_POST['yikes-easy-mc-general-error-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-general-error-message'] ) ) : '',
2600
				'already-subscribed'	=> trim( $_POST['yikes-easy-mc-user-subscribed-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-subscribed-message'] ) ) : '',
2601
				'update-link'			=> trim( $_POST['yikes-easy-mc-user-update-link'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-update-link'] ) ) : '',
2602
				'email-subject'			=> trim( $_POST['yikes-easy-mc-user-email-subject'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-email-subject'] ) ) : '',
2603
				'email-body'			=> trim( $_POST['yikes-easy-mc-user-email-body'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-email-body'] ) ) : '',
2604
				'update-email-success'  => trim( $_POST['yikes-easy-mc-update-email-successful'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-update-email-successful'] ) ) : '',
2605
				'update-email-failure'  => trim( $_POST['yikes-easy-mc-update-email-failure'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-update-email-failure'] ) ) : '',
2606
			);
2607
2608
			// Setup the new form settings array
2609
			// @since 6.0.3.8
2610
			// To Do: Combine date & time so it's a single unix timestamp
2611
			$form_settings = array(
2612
				'yikes-easy-mc-form-class-names'                 => trim( $_POST['yikes-easy-mc-form-class-names'] ),
2613
				'yikes-easy-mc-inline-form'                      => $_POST['yikes-easy-mc-inline-form'][0],
2614
				'yikes-easy-mc-submit-button-type'               => $_POST['yikes-easy-mc-submit-button-type'][0],
2615
				'yikes-easy-mc-submit-button-text'               => trim( $_POST['yikes-easy-mc-submit-button-text'] ),
2616
				'yikes-easy-mc-submit-button-image'              => esc_url( trim( $_POST['yikes-easy-mc-submit-button-image'] ) ),
2617
				'yikes-easy-mc-submit-button-classes'            => trim( $_POST['yikes-easy-mc-submit-button-classes'] ),
2618
				'yikes-easy-mc-form-schedule'                    => ( isset( $_POST['yikes-easy-mc-form-schedule'] ) ) ? '1' : '0',
2619
				'yikes-easy-mc-form-restriction-start'           => strtotime( $_POST['yikes-easy-mc-form-restriction-start-date'] . ' ' . $_POST['yikes-easy-mc-form-restriction-start-time'] ),
2620
				'yikes-easy-mc-form-restriction-end'             => strtotime( $_POST['yikes-easy-mc-form-restriction-end-date'] . ' ' . $_POST['yikes-easy-mc-form-restriction-end-time'] ),
2621
				'yikes-easy-mc-form-restriction-pending-message' => trim( $_POST['yikes-easy-mc-form-restriction-pending-message'] ),
2622
				'yikes-easy-mc-form-restriction-expired-message' => trim( $_POST['yikes-easy-mc-form-restriction-expired-message'] ),
2623
				'yikes-easy-mc-form-login-required'              => ( isset( $_POST['yikes-easy-mc-form-login-required'] ) ) ? '1' : '0',
2624
				'yikes-easy-mc-form-restriction-login-message'   => trim( $_POST['yikes-easy-mc-form-restriction-login-message'] ),
2625
			);
2626
2627
			// additional custom fields (extensions / user defined fields)
2628
			$custom_fields = array();
2629
			if ( isset( $_POST['custom-field'] ) ) {
2630
				foreach ( $_POST['custom-field'] as $custom_field => $custom_value ) {
2631
					if ( is_array( $custom_value ) ) {
2632
						$custom_fields[ $custom_field ] = array_filter( stripslashes_deep( $custom_value ) ); // array_filters to remove empty items (don't save them!)
2633
					} else {
2634
						$custom_fields[ $custom_field ] = stripslashes( $custom_value );
2635
					}
2636
				}
2637
			}
2638
2639
			$form_updates = yikes_deep_parse_args(
2640
				array(
2641
					'list_id'                 => $list_id,
2642
					'form_name'               => $form_name,
2643
					'form_description'        => $form_description,
2644
					'fields'                  => $assigned_fields,
2645
					'custom_template'         => 0,
2646
					'redirect_user_on_submit' => $redirect_user_on_submit,
2647
					'redirect_page'           => $redirect_page,
2648
					'submission_settings'     => $submission_settings,
2649
					'optin_settings'          => $optin_settings,
2650
					'error_messages'          => $error_settings,
2651
					'form_settings'           => $form_settings,
2652
					'custom_fields'           => $custom_fields,
2653
				),
2654
				$this->form_interface->get_form_defaults()
2655
			);
2656
2657
			$form_updates = apply_filters( 'yikes-mailchimp-save-form-filter', $form_updates, $form_id );
2658
2659
			$this->form_interface->update_form( $form_id, $form_updates );
2660
2661
			/* Custom action hook which allows users to update specific options when a form is updated - used in add ons */
2662
			do_action( 'yikes-mailchimp-save-form', $form_id,  $custom_fields );
2663
2664
			// redirect the user to the manage forms page, display confirmation
2665
			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-edit-form&id=' . $form_id . '&updated-form=true' ) ) );
2666
			exit();
2667
		}
2668
2669
		public static function generate_default_email_body() {
2670
			$email_body  = '<p>' . __( 'Greetings,', 'yikes-inc-easy-mailchimp-extender' ) . '</p>'; 
2671
2672
			$email_body .= '<p>';
2673
			$email_body .= 	__( 'A request has been made to update your Mailchimp account profile information.', 'yikes-inc-easy-mailchimp-extender' );
2674
			$email_body .=	__( ' To do so please use the following link: ', 'yikes-inc-easy-mailchimp-extender' );
2675
			$email_body .=	'[link]';
2676
			$email_body .=		__( 'Update Mailchimp Profile Info', 'yikes-inc-easy-mailchimp-extender' );
2677
			$email_body .= 	'[/link]';
2678
			$email_body .= '</p>';
2679
2680
			$email_body .= '<p>' . __( 'If you did not request this update, please disregard this email.', 'yikes-inc-easy-mailchimp-extender' ) . '</p>';
2681
2682
			$email_body .= '<p>&nbsp;</p>';
2683
			$email_body .= '<p>' . sprintf( __( 'This email was sent from: %s', 'yikes-inc-easy-mailchimp-extender' ), '[url]' ) . '</p>';
2684
			$email_body .= '<p>&nbsp;</p>';
2685
			$email_body .= '<p>&nbsp;</p>';
2686
			$email_body .= '<p style="font-size:13px;margin-top:5em;"><em>This email was generated by the <a href="http://www.wordpress.org/plugins/yikes-inc-easy-mailchimp-extender/" target="_blank">Easy Forms for Mailchimp</a> plugin, created by <a href="http://www.yikesinc.com" target="_blank">YIKES Inc.</a></em></p>';
2687
2688
			return $email_body;
2689
		}
2690
2691
		/* Unsubscribe a given user from our list */
2692
		public function yikes_easy_mailchimp_unsubscribe_user() {
2693
			$nonce    = $_REQUEST['nonce'];
2694
			$list_id  = $_REQUEST['mailchimp-list'];
2695
			$email_id = $_REQUEST['email_id'];
2696
2697
			// verify our nonce
2698 View Code Duplication
			if ( ! wp_verify_nonce( $nonce, 'unsubscribe-user-' . $email_id ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2699
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) );
2700
			}
2701
2702
			$response = yikes_get_mc_api_manager()->get_list_handler()->member_unsubscribe( $list_id, $email_id );
2703
			if ( is_wp_error( $response ) ) {
2704
				$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
2705
				$error_logging->maybe_write_to_log(
2706
					$response->get_error_code(),
2707
					__( "Unsubscribe User", 'yikes-inc-easy-mailchimp-extender' ),
2708
					__( "Manage List Page", 'yikes-inc-easy-mailchimp-extender' )
2709
				);
2710
			}
2711
2712
			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-view-list&list-id=' . $list_id . '&user-unsubscribed=true' ) ) );
2713
			exit;
2714
		}
2715
2716
		public function yikes_easy_mailchimp_create_missing_error_log() {
2717
			// grab our nonnce
2718
			$nonce = $_REQUEST['nonce'];
2719
			// validate nonce
2720 View Code Duplication
			if ( !wp_verify_nonce( $nonce, 'create_error_log' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2721
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) );
2722
			}
2723
			// setup the path to the error log
2724
			$error_log = fopen( plugin_dir_path( __FILE__ ) . '../includes/error_log/yikes-easy-mailchimp-error-log.php', 'w' );
2725
			try {
2726
				// create the file
2727
				fwrite( $error_log , '' );
2728
				// close out
2729
				fclose( $error_log );
2730
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=debug-settings&error_log_created=true' ) ) );
2731
			} catch ( Exception $e ) {
2732
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=debug-settings&error_log_created=false&error_message='.urlencode( $e->getMessage() ) ) ) );
2733
			}
2734
		}
2735
2736
		/*
2737
		*	Clear Transient Data !
2738
		*	Probably Move these to its own file,
2739
		*/
2740
		public function yikes_easy_mailchimp_clear_transient_data() {
2741
2742
			// verify our nonce
2743
			$nonce = $_REQUEST['nonce'];
2744 View Code Duplication
			if ( ! wp_verify_nonce( $nonce, 'clear-mc-transient-data' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2745
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) , __( "Failed nonce validation" , 'yikes-inc-easy-mailchimp-extender' ) , array( 'response' => 500 , 'back_link' => true ) );
2746
			}
2747
2748
			$this->delete_yikes_mailchimp_transients();
2749
2750
			// if the request came from the settings page, redirect to the settings page.
2751
			$referer = wp_get_referer();
2752
			if ( $referer && ( strpos( $referer, 'yikes-inc-easy-mailchimp-settings' ) > 0 ) ) {
2753
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=api-cache-settings&transient-cleared=true' ) ) );
2754
			} elseif ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] === 'yikes-mailchimp-edit-form' && isset( $_REQUEST['id'] ) && ! empty( $_REQUEST['id'] ) ) {
2755
2756
				// else check if we were editing a form.
2757
				$id = filter_var( $_REQUEST['id'], FILTER_SANITIZE_NUMBER_INT );
2758
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-edit-form&id=' . $id ) ) );
2759
			} else {
2760
				// else redirect to the manage forms page.
2761
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&transient-cleared=true' ) ) );
2762
			}
2763
2764
			exit;
2765
		}
2766
2767
		/**
2768
		 * Return an array of Mailchimp lists associated with this account
2769
		 *
2770
		 * Used when deleting the sites Mailchimp cache stored
2771
		 *
2772
		 * @since 6.0.2
2773
		 * @return $list_id_array - array of list id's to loop over
0 ignored issues
show
Documentation introduced by
The doc-type $list_id_array could not be parsed: Unknown type name "$list_id_array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
2774
		 */
2775
		public function get_mailchimp_list_ids_on_account() {
2776
			$api_key = yikes_get_mc_api_key();
2777
			if ( ! $api_key ) {
2778
				// if no api key is set/site is not connected, return an empty array.
2779
				return array();
2780
			}
2781
2782
			$lists = get_transient( 'yikesinc_eme_list_ids' );
2783
			if ( false === $lists ) {
2784
				$lists = yikes_get_mc_api_manager()->get_list_handler()->get_list_ids();
2785
				if ( is_wp_error( $lists ) ) {
2786
					return array();
2787
				}
2788
				set_transient( 'yikesinc_eme_list_ids', $lists, HOUR_IN_SECONDS );
2789
			}
2790
2791
			return $lists;
2792
		}
2793
2794
		/**
2795
		 *	Include our main Helper class file
2796
		 *
2797
		 *	@since 6.0
2798
		 */
2799
		public function yikes_mailchimp_load_helper_class() {
2800
			// check to see if it's already loaded up.
2801
			if ( !class_exists( 'Yikes_Inc_Easy_Mailchimp_Forms_Helper' ) ) {
2802
				// Include our main helper class file
2803
				include_once( YIKES_MC_PATH . 'admin/partials/helpers/init.php' );
2804
			}
2805
		}
2806
2807
		/**
2808
		 * Alter the color scheme based on the current user selection (this is done to help integrate the plugin into the dashboard more seamlessly)
2809
		 *
2810
		 * @since 0.1
2811
		 * @order requires that yikes-inc-easy-mailchimp-extender-admin.min.css be enqueued, so we can override the defaults (handle: yikes-inc-easy-mailchimp-extender-admin)
2812
		 * @return print out custom styles to the admin header to alter the default blue color
2813
		 */
2814
		public function alter_yikes_easy_mc_color_scheme() {
2815
			// get the current set color scheme for the logged in user
2816
			$current_color_scheme = get_user_option( 'admin_color' );
2817
			// switch over each color scheme, and set our variable
2818
			switch ( $current_color_scheme ) {
2819
				default:
2820
				case 'fresh': // default blue (defined by this plugin)
2821
					$main_color = '#00a0d2';
2822
					break;
2823
				case 'light': // light grey
2824
					$main_color = '#E5E5E5';
2825
					break;
2826
				case 'blue': // light blue
2827
					$main_color = '#52ACCC';
2828
					break;
2829
				case 'coffee': // light brown-ish
2830
					$main_color = '#59524C';
2831
					break;
2832
				case 'ectoplasm': // purple
2833
					$main_color = '#523F6D';
2834
					break;
2835
				case 'midnight': // black
2836
					$main_color = '#363B3F';
2837
					break;
2838
				case 'ocean': // green/teal-ish
2839
					$main_color = '#738E96';
2840
					break;
2841
				case 'sunrish': // red/orange
2842
					$main_color = '#CF4944';
2843
					break;
2844
			}
2845
			ob_start();
2846
			?>
2847
				<style>
2848
					.yikes-easy-mc-postbox h3,
2849
					.column-columnname .form-id-container,
2850
					.mv_ig_list .nav-tab-active {
2851
						background: <?php echo $main_color; ?>;
2852
					}
2853
					.mv_ig_list .arrow-down {
2854
						border-top: 9pt solid <?php echo $main_color; ?>;
2855
					}
2856
				</style>
2857
			<?php
2858
			$override_admin_styles = ob_get_clean();
2859
			// add our inline styles.
2860
			echo $override_admin_styles;
2861
		}
2862
2863
		/**
2864
		 *	Display premium support page if any add-ons are installed, otherwise display free support page
2865
		 */
2866
		public function display_support_page_content() {
2867
2868
			$addons = get_option( 'yikes-easy-mc-active-addons', array() );
2869
2870
			// If we have premium add-ons...
2871
			if ( ! empty( $addons ) ) { 
2872
2873
				// Add our premium support partial.
2874
				include_once( YIKES_MC_PATH . 'admin/partials/helpers/premium-support.php' );
2875
			} else {
2876
2877
				// Otherwise add our free support partial.
2878
				include_once( YIKES_MC_PATH . 'admin/partials/helpers/free-support.php' );
2879
			}
2880
		}
2881
2882
		/**
2883
		 * Check the users version number, and display a notice to upgrade the database if needed
2884
		 *
2885
		 * @since 6.0.4
2886
		 */
2887
		public function check_yikes_mc_table_version() {
2888
			if ( get_option( 'yikes_mc_database_version', '0.00' ) < '1.0' ) {
2889
				require_once YIKES_MC_PATH . 'includes/class-yikes-inc-easy-mailchimp-extender-activator.php';
2890
				global $wpdb;
2891
				Yikes_Inc_Easy_Mailchimp_Extender_Activator::_activate_yikes_easy_mailchimp( $wpdb );
2892
				// update the database option
2893
				update_option( 'yikes_mc_database_version', '1.0' );
2894
			}
2895
		}
2896
2897
		/**
2898
		 * Process [yikes-mailchimp-form-description] into the shortcode
2899
		 *
2900
		 * @since 6.0.4.4
2901
		 */
2902
		public function process_subscriber_count_shortcode_in_form_descriptions( $form_description, $form_id ) {
2903
			$form_description = str_replace( '[yikes-mailchimp-subscriber-count]', do_shortcode( '[yikes-mailchimp-subscriber-count form="' . $form_id . '"]' ), $form_description );
2904
			return $form_description;
2905
		}
2906
2907
		/**
2908
		 * Generate the sidebar advertisement on the 'Edit Form' page
2909
		 *
2910
		 * @since 6.0.3
2911
		 */
2912
		public function generate_edit_forms_upsell_ad() {
2913
		$upsell_ads = glob( YIKES_MC_PATH . 'includes/upsells/*.php' );
2914
		if ( $upsell_ads && ! empty( $upsell_ads ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $upsell_ads of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2915
			$ad_count = absint( count( $upsell_ads ) - 1 );
2916
			$ad       = $upsell_ads[ mt_rand( 0, $ad_count ) ];
2917
			ob_start();
2918
			include_once( $ad );
2919
			$ad_content = ob_get_contents();
2920
			ob_get_clean();
2921
		}
2922
		echo wp_kses_post( $ad_content );
0 ignored issues
show
Bug introduced by
The variable $ad_content does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2923
		}
2924
2925
		/***
2926
		 * Helper function to clear out transients stored by this plugin
2927
		 *
2928
		 * Mainly used when the API key is altered, changed or removed.
2929
		 * @since 6.1.3
2930
		 */
2931
		public function delete_yikes_mailchimp_transients() {
2932
2933
		// delete all of the list_id transients.
2934
		$list_ids = $this->get_mailchimp_list_ids_on_account();
2935
		foreach ( $list_ids as $id ) {
2936
			delete_transient( "yikes_eme_list_{$id}" );
2937
			delete_transient( "yikes_eme_merge_variables_{$id}" );
2938
			delete_transient( "yikes_eme_interest_categories_{$id}" );
2939
			delete_transient( "yikes_eme_segments_{$id}_saved" );
2940
			delete_transient( "yikes_eme_segments_{$id}_static" );
2941
			delete_transient( "yikes_eme_segments_{$id}_fuzzy" );
2942
			delete_transient( "yikes_eme_members_{$id}" );
2943
		}
2944
2945
		delete_transient( 'yikes-easy-mailchimp-list-data' );
2946
		delete_transient( 'yikes-easy-mailchimp-account-data' );
2947
		delete_transient( 'yikes-easy-mailchimp-profile-data' );
2948
		delete_transient( 'yikesinc_eme_list_ids' );
2949
		delete_transient( 'yikes_eme_lists' );
2950
	}
2951
2952
	/**
2953
	 * Register the Opt-in widget.
2954
	 *
2955
	 * @author Jeremy Pry
2956
	 */
2957
	public function register_optin_widget() {
2958
		register_widget( 'Yikes_Inc_Easy_Mailchimp_Extender_Widget' );
2959
	}
2960
}
2961