Completed
Pull Request — staging (#840)
by
unknown
16:56
created

Yikes_Inc_Easy_Mailchimp_Forms_Admin   F

Complexity

Total Complexity 392

Size/Duplication

Total Lines 2959
Duplicated Lines 4.66 %

Coupling/Cohesion

Components 3
Dependencies 10

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 138
loc 2959
ccs 0
cts 1146
cp 0
rs 0.8
c 0
b 0
f 0
wmc 392
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() 29 724 93
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
											case 'phone':
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
											case 'address':
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
												$field_merge = $field['merge'];
1811
												$selectedValue = "field[" . $field_merge . "][default_choice]";
1812 View Code Duplication
												switch ( $_POST[ $selectedValue ] ) {
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...
1813
													case 'no-default':
1814
													?>
1815
													<!-- Placeholder -->
1816
													<tr valign="top">
1817
														<td scope="row">
1818
															<label for="placeholder_<?php echo esc_attr( $field['merge'] ); ?>">
1819
																<?php _e( 'Placeholder', 'yikes-inc-easy-mailchimp-extender' ); ?>
1820
															</label>
1821
														</td>
1822
														<td>
1823
															<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'] : '' ; ?>" />
1824
															<p class="description"><small><?php _e( "Assign a placeholder value to this field.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1825
														</td>
1826
													</tr>
1827
													<?php
1828
													break;
1829
												}
1830
												?>
1831
										<?php
1832
												break;
1833
1834
											case "birthday":
1835
											case "address":
1836
												break;
1837
1838
										} // end Default Value ?>
1839
1840
1841
										<!-- Field Description -->
1842
										<tr valign="top">
1843
											<td scope="row">
1844
												<label for="description_<?php echo esc_attr( $field['merge'] ); ?>">
1845
													<?php _e( 'Description', 'yikes-inc-easy-mailchimp-extender' ); ?>
1846
												</label>
1847
											</td>
1848
											<td>
1849
												<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>
1850
												<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>
1851
											</td>
1852
										</tr>
1853
										<!-- Description Above Field -->
1854
										<tr valign="top" class="yikes-checkbox-container">
1855
											<td scope="row">
1856
												<label for="description_above_<?php echo esc_attr( $field['merge'] ); ?>">
1857
													<?php _e( 'Description Above Field', 'yikes-inc-easy-mailchimp-extender' ); ?>
1858
												</label>
1859
											</td>
1860
											<td>
1861
												<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"' : ''; ?> />
1862
												<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>
1863
											</td>
1864
										</tr>
1865
										<!-- Additional Classes -->
1866
										<tr valign="top">
1867
											<td scope="row">
1868
												<label for="classes_<?php echo esc_attr( $field['merge'] ); ?>">
1869
													<?php _e( 'Additional Classes', 'yikes-inc-easy-mailchimp-extender' ); ?>
1870
												</label>
1871
											</td>
1872
											<td>
1873
												<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'] ) ) : '' ; ?>" />
1874
												<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>
1875
											</td>
1876
										</tr>
1877
										<!-- Required Toggle -->
1878
										<tr valign="top" class="yikes-checkbox-container yikes-checkbox-container-first">
1879
											<td scope="row">
1880
												<label for="field-required-<?php echo esc_attr( $field['merge'] ); ?>">
1881
													<?php _e( 'Field Required?', 'yikes-inc-easy-mailchimp-extender' ); ?>
1882
												</label>
1883
											</td>
1884
											<td>
1885
												<?php $checked = isset( $field['require'] ) ? $field['require'] : '0'; ?>
1886
												<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' ); } ?>">
1887
												<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>
1888
											</td>
1889
										</tr>
1890
										<!-- Visible Toggle -->
1891
										<tr valign="top" class="yikes-checkbox-container">
1892
											<td scope="row">
1893
												<label for="hide-field-<?php echo esc_attr( $field['merge'] ); ?>">
1894
													<?php _e( 'Hide Field', 'yikes-inc-easy-mailchimp-extender' ); ?>
1895
												</label>
1896
											</td>
1897
											<td>
1898
												<?php $hide = isset( $field['hide'] ) ? $field['hide'] : '0'; ?>
1899
												<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' ); } ?>">
1900
												<p class="description"><small><?php _e( "Hide this field from being displayed on the front end.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1901
											</td>
1902
										</tr>
1903
										<!-- Toggle Field Label Visibility -->
1904
										<tr valign="top" class="yikes-checkbox-container">
1905
											<td scope="row">
1906
												<label for="hide-label-<?php echo esc_attr( $field['merge'] ); ?>">
1907
													<?php _e( 'Hide Label', 'yikes-inc-easy-mailchimp-extender' ); ?>
1908
												</label>
1909
											</td>
1910
											<td>
1911
												<?php $hide_label = isset( $field['hide-label'] ) ? $field['hide-label'] : '0'; ?>
1912
												<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 ); ?>/>
1913
												<p class="description"><small><?php _e( "Toggle field label visibility.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
1914
											</td>
1915
										</tr>
1916
										<!-- Display Phone/Date Formats back to the user -->
1917
										<!-- Phone Format Initial Load -->
1918
										<?php
1919
											switch( $field['type'] ) {
1920
												/* Store the phone format, for properly regex pattern */
1921
												case 'phone':
1922
												case 'birthday':
1923
												case 'date':
1924
													?>
1925
														<tr valign="top">
1926
															<td scope="row">
1927
																<label for="placeholder">
1928
																	<?php
1929
																		switch( $field['type'] ) {
1930
																			default:
1931 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...
1932
																				$type = __( 'Date Format', 'yikes-inc-easy-mailchimp-extender' );
1933
																				$format = ( isset( $field['date_format'] ) ) ? $field['date_format'] : 'MM/DD';
1934
																				$format_name = 'date_format';
1935
																				break;
1936
1937 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...
1938
																				$type = __( 'Date Format', 'yikes-inc-easy-mailchimp-extender' );
1939
																				$format = ( isset( $field['date_format'] ) ) ? $field['date_format'] : 'MM/DD/YYYY';
1940
																				$format_name = 'date_format';
1941
																				break;
1942
1943
																			case 'phone':
1944
																				$type = __( 'Phone Format', 'yikes-inc-easy-mailchimp-extender' );
1945
																				$format = isset( $field['phone_format'] ) && ! empty( $field['phone_format'] ) ? $field['phone_format'] : __( 'International', 'yikes-inc-easy-mailchimp-extender' );
1946
																				$format_name = 'phone_format';
1947
																				break;
1948
																		}
1949
																		echo $type;
1950
																	?>
1951
																</label>
1952
															</td>
1953
															<td>
1954
																<strong><?php echo $format; ?></strong>
1955
																<input type="hidden" name="field[<?php echo $field['merge']; ?>][<?php echo $format_name; ?>]" value="<?php echo $format; ?>" />
1956
																<p class="description"><small>
1957
																	<?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' ) ); ?>
1958
																</small></p>
1959
															</td>
1960
														</tr>
1961
													<?php
1962
												break;
1963
												// others..
1964
												default:
1965
													break;
1966
											}
1967
										?>
1968
										<!-- End Date/Phone Formats -->
1969
										<!-- Toggle Buttons -->
1970
										<tr valign="top">
1971
											<td scope="row">
1972
												&nbsp;
1973
											</td>
1974
											<td>
1975
												<span class="toggle-container">
1976
													<a href="#" class="close-form-expansion"><?php _e( "Close" , 'yikes-inc-easy-mailchimp-extender' ); ?></a> |
1977
													<a href="#" class="remove-field" alt="<?php echo $field['merge']; ?>"><?php _e( "Remove Field" , 'yikes-inc-easy-mailchimp-extender' ); ?></a>
1978
												</span>
1979
											</td>
1980
										</tr>
1981
									</table>
1982
								</p>
1983
1984
							</div>
1985
						</section>
1986
						<?php
1987
1988
1989
1990
					} else {
1991
1992
						/**** Interest Group ****/
1993
1994
						?>
1995
						<section class="draggable" id="<?php echo $field['group_id']; ?>">
1996
							<!-- top -->
1997
							<a href="#" class="expansion-section-title settings-sidebar">
1998
								<span class="dashicons dashicons-plus yikes-mc-expansion-toggle"></span><?php echo stripslashes( $field['label'] ); ?>
1999
								<?php if ( in_array( $field['group_id'] , $excluded_fields ) ) { ?>
2000
									<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' ); ?>">
2001
								<?php } ?>
2002
								<span class="field-type-text"><small><?php echo __( 'type', 'yikes-inc-easy-mailchimp-extender' ) . ' : ' . $field['type']; ?></small></span>
2003
							</a>
2004
							<!-- expansion section -->
2005
							<div class="yikes-mc-settings-expansion-section">
2006
2007
								<!-- check if this field exists in the available interest group array -->
2008
								<?php if ( in_array( $field['group_id'] , $excluded_fields ) ) { ?>
2009
									<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>
2010
								<?php } ?>
2011
2012
								<!-- store the label -->
2013
								<input type="hidden" name="field[<?php echo $field['group_id']; ?>][label]" value="<?php echo htmlspecialchars( $field['label'] ); ?>" />
2014
								<input type="hidden" name="field[<?php echo $field['group_id']; ?>][type]" value="<?php echo $field['type']; ?>" />
2015
								<input type="hidden" name="field[<?php echo $field['group_id']; ?>][group_id]" value="<?php echo $field['group_id']; ?>" />
2016
								<input type="hidden" name="field[<?php echo $field['group_id']; ?>][groups]" value='<?php echo esc_attr( json_encode( json_decode( $field['groups'], true ) ) ); ?>' />
2017
2018
								<!-- Single or Double Opt-in -->
2019
								<p class="type-container"><!-- necessary to prevent skipping on slideToggle(); -->
2020
2021
									<table class="form-table form-field-container">
2022
										<!-- Default Value -->
2023
										<?php switch( $field['type'] ) {
2024
											default:
2025
											case 'radio':
2026
											case 'checkboxes':
2027
											?>
2028
												<tr valign="top">
2029
													<td scope="row">
2030
														<label for="placeholder">
2031
															<?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?>
2032
														</label>
2033
													</td>
2034
													<td>
2035
														<?php
2036
														$field['default_choice'] = isset( $field['default_choice'] ) ? $field['default_choice'] : '';
2037
2038
														$default_shown = false;
2039
2040
														foreach ( json_decode( $field['groups'], true ) as $id => $group ) {
2041
															$field_id   = "{$field['group_id']}-{$id}";
2042
															$field_type = 'hidden' == $field['type'] ? 'checkbox' : $field['type'];
2043
															$field_type = 'checkboxes' == $field_type ? 'checkbox' : $field_type;
2044
															$field_name = "field[{$field['group_id']}][default_choice]";
2045
															$field_name = 'checkbox' == $field_type ? $field_name . '[]' : $field_name;
2046
2047
															// Determine if the current group is checked.
2048
															$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...
2049
															switch ( $field_type ) {
2050
																case 'radio':
2051
																default:
2052
																	$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...
2053
																	$checked = is_array( $field['default_choice'] ) ? checked( current( $field['default_choice'] ), $id, false ) : checked( $field['default_choice'], $id, false );
2054
																break;
2055
2056
																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...
2057
																case 'hidden':
2058
																	if ( is_array( $field['default_choice'] ) && in_array( $id, $field['default_choice'] ) ) {
2059
																		$checked = checked( true, true, false );
2060
																	}
2061
																break;
2062
															}
2063
2064
															// Allow users to not set a default choice for radio buttons.
2065
															if ( $field_type === 'radio' && $default_shown === false ) {
2066
																$default_shown = true;
2067
																?>
2068
																<label for="<?php echo $field_id . 'no-default'; ?>">
2069
																	<input id="<?php echo $field_id . 'no-default'; ?>"
2070
																	    type="<?php echo $field_type; ?>"
2071
																	    name="<?php echo $field_name; ?>"
2072
																	    value="no-default" 
2073
																	    <?php is_array( $field['default_choice'] ) ? checked( current( $field['default_choice'] ), 'no-default' ) : checked( $field['default_choice'], 'no-default' ); ?>>
2074
																	No Default&nbsp;
2075
																</label>
2076
																<?php
2077
															}
2078
2079
															?>
2080
															<label for="<?php echo $field_id; ?>">
2081
																<input id="<?php echo $field_id; ?>"
2082
																    type="<?php echo $field_type; ?>"
2083
																    name="<?php echo $field_name; ?>"
2084
																    value="<?php echo $id; ?>" <?php echo $checked; ?>>
2085
																<?php echo stripslashes( str_replace( '\'', '', $group ) ); ?>&nbsp;
2086
															</label>
2087
															<?php
2088
														} ?>
2089
														<p class="description"><small><?php _e( "Select the option that should be selected by default.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2090
													</td>
2091
												</tr>
2092
2093
											<?php
2094
												break;
2095
2096
											case 'dropdown':
2097
											?>
2098
												<tr valign="top">
2099
													<td scope="row">
2100
														<label for="placeholder">
2101
															<?php _e( 'Default Selection', 'yikes-inc-easy-mailchimp-extender' ); ?>
2102
														</label>
2103
													</td>
2104
													<td>
2105
														<select type="default" name="field[<?php echo $field['group_id']; ?>][default_choice]">
2106
															<option value="no-default">No Default</option>
2107
															<?php foreach( json_decode( stripslashes_deep( $field['groups'] ) , true ) as $id => $group ) { ?>
2108
																<option value="<?php echo $id; ?>" <?php selected( $field['default_choice'] , $id ); ?>><?php echo stripslashes( $group ); ?></option>
2109
															<?php } ?>
2110
														</select>
2111
														<p class="description"><small><?php _e( "Which option should be selected by default?", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2112
													</td>
2113
												</tr>
2114
2115
											<?php
2116
												break;
2117
										?>
2118
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...
2119
										<?php } // end Default Value ?>
2120
2121
										<!-- Field Description -->
2122
										<tr valign="top">
2123
											<td scope="row">
2124
												<label for="description_<?php echo esc_attr( $field['group_id'] ); ?>">
2125
													<?php _e( 'Description', 'yikes-inc-easy-mailchimp-extender' ); ?>
2126
												</label>
2127
											</td>
2128
											<td>
2129
												<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>
2130
												<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>
2131
											</td>
2132
										</tr>
2133
2134
										<!-- Description Above Field -->
2135
										<tr valign="top" class="yikes-checkbox-container">
2136
											<td scope="row">
2137
												<label for="description_above_<?php echo $field['group_id']; ?>">
2138
													<?php _e( 'Description Above Field', 'yikes-inc-easy-mailchimp-extender' ); ?>
2139
												</label>
2140
											</td>
2141
											<td>
2142
												<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"' : ''; ?> />
2143
												<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>
2144
											</td>
2145
										</tr>
2146
2147
										<!-- Additional Classes -->
2148
										<tr valign="top">
2149
											<td scope="row">
2150
												<label for="classes_<?php echo esc_attr( $field['group_id'] ); ?>">
2151
													<?php _e( 'Additional Classes', 'yikes-inc-easy-mailchimp-extender' ); ?>
2152
												</label>
2153
											</td>
2154
											<td>
2155
												<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'] ) ) : '' ; ?>" />
2156
												<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>
2157
											</td>
2158
										</tr>
2159
										<!-- Required Toggle -->
2160
										<tr valign="top" class="yikes-checkbox-container">
2161
											<td scope="row">
2162
												<label for="field-required-<?php echo esc_attr( $field['group_id'] ); ?>">
2163
													<?php _e( 'Field Required?', 'yikes-inc-easy-mailchimp-extender' ); ?>
2164
												</label>
2165
											</td>
2166
											<td>
2167
												<?php $checked = isset( $field['require'] ) ? $field['require'] : '0'; ?>
2168
												<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 ); ?>>
2169
												<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>
2170
											</td>
2171
										</tr>
2172
										<!-- Visible Toggle -->
2173
										<tr valign="top" class="yikes-checkbox-container">
2174
											<td scope="row">
2175
												<label for="hide-field-<?php echo esc_attr( $field['group_id'] ); ?>">
2176
													<?php _e( 'Hide Field', 'yikes-inc-easy-mailchimp-extender' ); ?>
2177
												</label>
2178
											</td>
2179
											<td>
2180
												<?php $hide = isset( $field['hide'] ) ? $field['hide'] : '0'; ?>
2181
												<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 ); ?>>
2182
												<p class="description"><small><?php _e( "Hide this field from being displayed on the front end.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2183
											</td>
2184
										</tr>
2185
										<!-- Toggle Field Label Visibility -->
2186
										<tr valign="top" class="yikes-checkbox-container">
2187
											<td scope="row">
2188
												<label for="hide-label-<?php echo esc_attr( $field['group_id'] ); ?>">
2189
													<?php _e( 'Hide Label', 'yikes-inc-easy-mailchimp-extender' ); ?>
2190
												</label>
2191
											</td>
2192
											<td>
2193
												<?php $hide = isset( $field['hide-label'] ) ? $field['hide-label'] : '0'; ?>
2194
												<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 ); ?>/>
2195
												<p class="description"><small><?php _e( "Toggle field label visibility.", 'yikes-inc-easy-mailchimp-extender' );?></small></p>
2196
											</td>
2197
										</tr>
2198
										<!-- Toggle Buttons -->
2199
										<tr valign="top">
2200
											<td scope="row">
2201
												&nbsp;
2202
											</td>
2203
											<td>
2204
												<span class="toggle-container">
2205
													<a href="#" class="close-form-expansion"><?php _e( "Close" , 'yikes-inc-easy-mailchimp-extender' ); ?></a> |
2206
													<a href="#" class="remove-field" alt="<?php echo $field['group_id']; ?>"><?php _e( "Remove Field" , 'yikes-inc-easy-mailchimp-extender' ); ?></a>
2207
												</span>
2208
											</td>
2209
										</tr>
2210
									</table>
2211
								</p>
2212
2213
							</div>
2214
						</section>
2215
						<?php
2216
					}
2217
				}
2218
			} else {
2219
				?>
2220
					<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>
2221
				<?php
2222
			}
2223
				/* Pre Defined Merge Tag Container - Always rendered so the modal appears and links are clickable on initial page load */
2224
				add_thickbox();
2225
				// enqueue jquery qtip for our tooltip
2226
				wp_enqueue_script( 'jquery-qtip-tooltip', YIKES_MC_URL . 'admin/js/min/jquery.qtip.min.js', array( 'jquery' ) );
2227
				wp_enqueue_style( 'jquery-qtip-style',  YIKES_MC_URL . 'admin/css/jquery.qtip.min.css' );
2228
					$available_tags = array(
2229
						array(
2230
							'tag' => '{page_title}',
2231
							'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' ),
2232
							'title' => __( 'Page Title', 'yikes-inc-easy-mailchimp-extender' )
2233
						),
2234
						array(
2235
							'tag' => '{page_id}',
2236
							'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' ),
2237
							'title' => __( 'Page ID', 'yikes-inc-easy-mailchimp-extender' )
2238
						),
2239
						array(
2240
							'tag' => '{page_url}',
2241
							'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' ),
2242
							'title' => __( 'Page URL', 'yikes-inc-easy-mailchimp-extender' )
2243
						),
2244
						array(
2245
							'tag' => '{blog_name}',
2246
							'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' ),
2247
							'title' => __( 'Blog Name', 'yikes-inc-easy-mailchimp-extender' )
2248
						),
2249
						array(
2250
							'tag' => '{user_logged_in}',
2251
							'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' ),
2252
							'title' => __( 'User Logged In', 'yikes-inc-easy-mailchimp-extender' )
2253
						),
2254
					);
2255
				?>
2256
				<!-- tooltips -->
2257
				<script type="text/javascript">
2258
					/* Initialize Qtip tooltips for pre-defined tags */
2259
					jQuery( document ).ready( function() {
2260
						jQuery( '.dashicons-editor-help' ).each( function() {
2261
							 jQuery( this ).qtip({
2262
								 content: {
2263
									 text: jQuery( this ).next( '.tooltiptext' ),
2264
									 style: {
2265
										def: false
2266
									 }
2267
								 }
2268
							 });
2269
						 });
2270
						 jQuery( '.qtip' ).each( function() {
2271
							jQuery( this ).removeClass( 'qtip-default' );
2272
						 });
2273
					});
2274
				</script>
2275
2276
				<div id="pre-defined-tag-container">
2277
					<input type="hidden" value="" class="clicked-input">
2278
					<div id="pre-defined-tag-interior-container">
2279
						<h3><?php _e( 'Pre Defined Tags', 'yikes-inc-easy-mailchimp-extender' ); ?></h3>
2280
						<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>
2281
						<ul>
2282
							<?php foreach( apply_filters( 'yikes-mailchimp-custom-default-value-tags', $available_tags ) as $tag ) { ?>
2283
								<li class="tooltop-tag">
2284
									<!-- link/tag -->
2285
									<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>
2286
									<!-- help icon -->
2287
									<span class="dashicons dashicons-editor-help"></span>
2288
									<!-- tooltip -->
2289
									<div class="tooltiptext qtip-bootstrap yikes-easy-mc-hidden"><?php echo $tag['description']; ?></div>
2290
								</li>
2291
							<?php } ?>
2292
						</ul>
2293
					</div>
2294
				</div>
2295
				<?php
2296
		}
2297
2298
		/**
2299
		 *	build_available_merge_vars( $list_id )
2300
		 *	Submit an API request to get our merge variables, and build up a small form editor
2301
		 *	for users to 'customize' their form
2302
		 *	-
2303
		 * @parameters - $list_id - pass in the list ID to retreive merge variables from
2304
		 */
2305
		public function build_available_merge_vars( $form_fields, $available_merge_variables ) {
2306
			$fields_assigned_to_form = array();
2307 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...
2308
				if ( isset( $field['merge'] ) ) {
2309
					$fields_assigned_to_form[ $field['merge'] ] = true;
2310
				}
2311
			}
2312
2313
			if ( ! empty( $available_merge_variables['merge_fields'] ) ) {
2314
				?>
2315
				<ul id="available-fields"><?php
2316
				foreach ( $available_merge_variables['merge_fields'] as $merge_var ) {
2317
					$not_available = isset( $fields_assigned_to_form[ $merge_var['tag'] ] );
2318
					?>
2319
					<li class="available-field <?php echo $not_available ? 'not-available' : ''; ?>"
2320
						alt="<?php echo esc_attr( $merge_var['tag'] ); ?>"
2321
						data-attr-field-type="<?php echo esc_attr( $merge_var['type'] ); ?>"
2322
						data-attr-field-name="<?php echo esc_attr( $merge_var['name'] ); ?>"
2323
						data-attr-form-id="<?php echo esc_attr( $available_merge_variables['list_id'] ); ?>"
2324
						title="<?php echo $not_available ? esc_attr__( 'Already assigned to your form', 'yikes-inc-easy-mailchimp-extender' ) : ''; ?>"
2325
						<?php echo $not_available ? 'disabled="disabled"' : ''; ?>
2326
					>
2327
						<?php
2328
							echo esc_html( stripslashes( $merge_var['name'] ) );
2329
							if ( $merge_var['required'] ) {
2330
								echo ' <span class="field-required" title="' . __( 'required field', 'yikes-inc-easy-mailchimp-extender' ) . '">*</span>';
2331
							}
2332
						?>
2333
						<small class="field-type-text"><?php echo esc_html( $merge_var['type'] ); ?></small>
2334
					</li>
2335
					<?php
2336
				}
2337
				?></ul>
2338
				<a href="#" class="add-field-to-editor add-to-editor button-secondary yikes-easy-mc-hidden" style="display:none;">
2339
					<small>
2340
						<span class="dashicons dashicons-arrow-left-alt add-to-form-builder-arrow"></span> <?php _e( 'Add to Form Builder', 'yikes-inc-easy-mailchimp-extender' ); ?>
2341
					</small>
2342
				</a>
2343
				<?php
2344
			}
2345
		}
2346
2347
		/**
2348
		 *	build_available_interest_groups( $form_fields , $available_interest_groups )
2349
		 *	Submit an API request to get our merge variables, and build up a small form editor
2350
		 *	for users to 'customize' their form
2351
		 *	-
2352
		 * @parameters - $list_id - pass in the list ID to retreive merge variables from
2353
		 */
2354
		public function build_available_interest_groups( $form_fields, $available_interest_groups, $list_id ) {
2355
			$fields_assigned_to_form = array();
2356
			if ( ! empty( $form_fields ) ) {
2357 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...
2358
					if ( isset( $field['group_id'] ) ) {
2359
						$fields_assigned_to_form[ $field['group_id'] ] = true;
2360
					}
2361
				}
2362
			}
2363
2364
			if ( ! empty( $available_interest_groups ) ) {
2365
			?>
2366
				<ul id="available-interest-groups">
2367
				<?php
2368
					foreach ( $available_interest_groups as $interest_group ) {
2369
						$not_available = isset( $fields_assigned_to_form[ $interest_group['id'] ] );
2370
						?>
2371
						<li class="available-field <?php echo $not_available ? 'not-available' : ''; ?>" 
2372
							alt="<?php echo esc_attr( $interest_group['id'] ); ?>" 
2373
							data-group-id="<?php echo esc_attr( $interest_group['id'] ); ?>" 
2374
							data-attr-field-name="<?php echo esc_attr( htmlspecialchars( $interest_group['title'] ) ); ?>" 
2375
							data-attr-field-type="<?php echo esc_attr( $interest_group['type'] ); ?>" 
2376
							data-attr-form-id="<?php echo esc_attr( $list_id ); ?>"
2377
							title="<?php echo $not_available ? __( 'Already assigned to your form', 'yikes-inc-easy-mailchimp-extender' ) : ''; ?>"
2378
							<?php echo $not_available ? 'disabled="disabled"' : ''; ?>
2379
						>
2380
							<?php echo esc_html( stripslashes( $interest_group['title'] ) ); ?>
2381
							<small class="field-type-text"><?php echo esc_html( $interest_group['type'] ); ?></small>
2382
						</li>
2383
						<?php
2384
					}
2385
				?>
2386
				</ul>
2387
				<a href="#" class="add-interest-group-to-editor add-to-editor button-secondary yikes-easy-mc-hidden" style="display:none;">
2388
					<small>
2389
						<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' ); ?>
2390
					</small>
2391
				</a>
2392
			<?php
2393
			}
2394
		}
2395
2396
		/**
2397
		 * Smt.
2398
		 */
2399
		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...
2400
			?>
2401
			<ul id="available-tags">
2402
			<?php
2403
			foreach ( $tags as $tag_id => $tag ) {
2404
				$not_available = isset( $form_tags[ $tag_id ] );
2405
				?>
2406
				<li class="available-field <?php echo $not_available ? 'not-available' : ''; ?>"
2407
					id="tag-<?php echo esc_attr( $tag['id'] ); ?>"
2408
					data-tag-id="<?php echo esc_attr( $tag['id'] ); ?>"
2409
					data-tag-name="<?php echo esc_attr( $tag['name'] ); ?>"
2410
					title="<?php echo $not_available ? __( 'Already assigned to your form', 'yikes-inc-easy-mailchimp-extender' ) : esc_attr( $tag['name'] ); ?>"
2411
					<?php echo $not_available ? 'disabled="disabled"' : ''; ?>
2412
				>
2413
					<?php echo esc_html( $tag['name'] ); ?>
2414
				</li>
2415
				<?php
2416
			}
2417
			?>
2418
			</ul>
2419
			<a href="#" class="add-tag-to-editor add-to-editor button-secondary yikes-easy-mc-hidden" style="display:none;">
2420
				<small>
2421
					<span class="dashicons dashicons-arrow-left-alt add-to-form-builder-arrow"></span> <?php _e( 'Add to Form Builder', 'yikes-inc-easy-mailchimp-extender' ); ?>
2422
				</small>
2423
			</a>
2424
			<?php
2425
		}
2426
2427
		/*
2428
		*	Create A New Form!
2429
		*	Probably Move these to its own file,
2430
		*	and include it here for easy maintenance
2431
		*	- must clean up db tables , ensure what data is going in and what is needed...
2432
		*/
2433
		public function yikes_easy_mailchimp_create_form() {
2434
			$nonce = $_REQUEST['nonce'];
2435
			if ( ! wp_verify_nonce( $nonce, 'create_mailchimp_form' ) ) {
2436
				wp_die( __( "We've run into an error. The security check didn't pass. Please try again." , 'yikes-inc-easy-mailchimp-extender' ) );
2437
			}
2438
2439
			$result = $this->form_interface->create_form( array(
2440
				'list_id'          => sanitize_key( $_POST['associated-list'] ),
2441
				'form_name'        => stripslashes( $_POST['form-name'] ),
2442
				'form_description' => stripslashes( $_POST['form-description'] ),
2443
			) );
2444
2445
			// if an error occurs during the form creation process
2446
			if ( false == $result ) {
2447
				// write it to the error log
2448
				// if the form was not created successfully
2449
				$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
2450
				$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' ) );
2451
				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' ) ) ) ) );
2452
			} else {
2453
				// redirect the user to the new form edit page
2454
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-edit-form&id=' . $result) ) );
2455
			}
2456
			exit();
2457
		}
2458
2459
		/*
2460
		*	Delete A Form !
2461
		*	Probably Move these to its own file,
2462
		*	and include it here for easy maintenance
2463
		*	- must clean up db tables , ensure what data is going in and what is needed...
2464
		*/
2465
		public function yikes_easy_mailchimp_delete_form() {
2466
			// grab & store our variables ( associated list & form name )
2467
			$nonce = $_REQUEST['nonce'];
2468
			$post_id_to_delete = $_REQUEST['mailchimp-form'];
2469
			// verify our nonce
2470 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...
2471
				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 ) );
2472
			}
2473
2474
			$this->form_interface->delete_form( $post_id_to_delete );
2475
2476
			// redirect the user to the manage forms page, display confirmation
2477
			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&deleted-form=true' ) ) );
2478
			exit();
2479
		}
2480
2481
		/*
2482
		*	Duplicate an entire form !
2483
		*	Probably Move these to its own file,
2484
		*/
2485
		public function yikes_easy_mailchimp_duplicate_form() {
2486
			// grab & store our variables ( associated list & form name )
2487
			$nonce = $_REQUEST['nonce'];
2488
			$post_id_to_clone = $_REQUEST['mailchimp-form'];
2489
			// verify our nonce
2490 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...
2491
				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 ) );
2492
			}
2493
2494
			// Get the current form data.
2495
			$form_data = $this->form_interface->get_form( $post_id_to_clone );
2496
2497
			// Update some of the data before duplication
2498
			$form_data['form_name'] .= ' - Copy';
2499
			$form_data['impressions'] = $form_data['submissions'] = 0;
2500
2501
			// Create the new form, and handle the result.
2502
			$result = $this->form_interface->create_form( $form_data );
2503
2504
			/**
2505
			* `yikes-mailchimp-after-duplicating-form`
2506
			*
2507
			* @param $post_id_to_clone | int   | ID of the original form
2508
			* @param $result           | mixed | ID of the new form OR false if the operation failed
2509
			* @param $form_data        | array | Array of the form data 
2510
			*
2511
			*/
2512
			do_action( 'yikes-mailchimp-after-duplicating-form', $post_id_to_clone, $result, $form_data );
2513
2514 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...
2515
				// redirect the user to the manage forms page, display error
2516
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&duplicated-form=false' ) ) );
2517
			} else {
2518
				// redirect the user to the manage forms page, display confirmation
2519
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&duplicated-form=true' ) ) );
2520
			}
2521
2522
			exit();
2523
		}
2524
2525
		/*
2526
		*	Reset a forms impression stats
2527
		*/
2528
		public function yikes_easy_mailchimp_reset_impression_stats() {
2529
			// grab & store our variables ( associated list & form name )
2530
			$nonce = $_REQUEST['nonce'];
2531
			$form_id_to_reset = $_REQUEST['mailchimp-form'];
2532
			// verify our nonce
2533 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...
2534
				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 ) );
2535
			}
2536
2537
			$result = $this->form_interface->update_form(
2538
				$form_id_to_reset,
2539
				array(
2540
					'impressions' => 0,
2541
					'submissions' => 0
2542
				)
2543
			);
2544
2545 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...
2546
				// redirect the user to the manage forms page, display error
2547
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&reset-stats=false' ) ) );
2548
			} else {
2549
				// redirect the user to the manage forms page, display confirmation
2550
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&reset-stats=true' ) ) );
2551
			}
2552
2553
			exit();
2554
		}
2555
2556
		/*
2557
		*	Update an entire form !
2558
		*	Probably Move these to its own file,
2559
		*/
2560
		public function yikes_easy_mailchimp_update_form() {
2561
2562
			$nonce   = $_REQUEST['nonce'];
2563
			$form_id = $_REQUEST['id'];
2564
2565
			// verify our nonce
2566 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...
2567
				wp_die(
2568
					__( "We've run into an error. The security check didn't pass. Please try again.", 'yikes-inc-easy-mailchimp-extender' ),
2569
					__( "Failed nonce validation", 'yikes-inc-easy-mailchimp-extender' ),
2570
					array(
2571
						'response'  => 500,
2572
						'back_link' => true,
2573
				) );
2574
			}
2575
2576
			// Store our values!
2577
			$list_id                 = $_POST['associated-list'];
2578
			$form_name               = stripslashes( $_POST['form-name'] );
2579
			$form_description        = sanitize_text_field( stripslashes( $_POST['form-description'] ) );
2580
			$redirect_user_on_submit = $_POST['redirect-user-on-submission'];
2581
			$redirect_page           = $_POST['redirect-user-to-selection'];
2582
2583
			// stripslashes_deep on save, to prevent foreign languages from added excessive backslashes
2584
			$assigned_fields = isset( $_POST['field'] ) ? stripslashes_deep( $_POST['field'] ): array();
2585
2586
			// setup our submission settings serialized array
2587
			$submission_settings = array(
2588
				'ajax'                   => $_POST['form-ajax-submission'],
2589
				'redirect_on_submission' => $_POST['redirect-user-on-submission'],
2590
				'redirect_page'          => $_POST['redirect-user-to-selection'],
2591
				'custom_redirect_url'    => esc_url( $_POST['custom-redirect-url'] ),
2592
				'redirect_new_window'	 => $_POST['redirect_new_window'],
2593
				'hide_form_post_signup'  => $_POST['hide-form-post-signup'],
2594
				'replace_interests'      => $_POST['replace-interest-groups'],
2595
			);
2596
2597
			// setup our opt-in settings serialized array
2598
			$optin_settings = array(
2599
				'optin'                => $_POST['single-double-optin'],
2600
				'update_existing_user' => $_POST['update-existing-user'],
2601
				'send_update_email'    => $_POST['update-existing-email'],
2602
			);
2603
2604
			// Setup our error settings serialized array
2605
			$error_settings = array(
2606
				'success'				=> trim( $_POST['yikes-easy-mc-success-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-success-message'] ) ) : '',
2607
				'success-single-optin'	=> trim( $_POST['yikes-easy-mc-success-single-optin-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-success-single-optin-message'] ) ) : '',
2608
				'success-resubscribed'	=> trim( $_POST['yikes-easy-mc-user-resubscribed-success-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-resubscribed-success-message'] ) ) : '',
2609
				'general-error'			=> trim( $_POST['yikes-easy-mc-general-error-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-general-error-message'] ) ) : '',
2610
				'already-subscribed'	=> trim( $_POST['yikes-easy-mc-user-subscribed-message'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-subscribed-message'] ) ) : '',
2611
				'update-link'			=> trim( $_POST['yikes-easy-mc-user-update-link'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-update-link'] ) ) : '',
2612
				'email-subject'			=> trim( $_POST['yikes-easy-mc-user-email-subject'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-email-subject'] ) ) : '',
2613
				'email-body'			=> trim( $_POST['yikes-easy-mc-user-email-body'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-user-email-body'] ) ) : '',
2614
				'update-email-success'  => trim( $_POST['yikes-easy-mc-update-email-successful'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-update-email-successful'] ) ) : '',
2615
				'update-email-failure'  => trim( $_POST['yikes-easy-mc-update-email-failure'] ) ? trim( stripslashes( $_POST['yikes-easy-mc-update-email-failure'] ) ) : '',
2616
			);
2617
2618
			// Setup the new form settings array
2619
			// @since 6.0.3.8
2620
			// To Do: Combine date & time so it's a single unix timestamp
2621
			$form_settings = array(
2622
				'yikes-easy-mc-form-class-names'                 => trim( $_POST['yikes-easy-mc-form-class-names'] ),
2623
				'yikes-easy-mc-inline-form'                      => $_POST['yikes-easy-mc-inline-form'][0],
2624
				'yikes-easy-mc-submit-button-type'               => $_POST['yikes-easy-mc-submit-button-type'][0],
2625
				'yikes-easy-mc-submit-button-text'               => trim( $_POST['yikes-easy-mc-submit-button-text'] ),
2626
				'yikes-easy-mc-submit-button-image'              => esc_url( trim( $_POST['yikes-easy-mc-submit-button-image'] ) ),
2627
				'yikes-easy-mc-submit-button-classes'            => trim( $_POST['yikes-easy-mc-submit-button-classes'] ),
2628
				'yikes-easy-mc-form-schedule'                    => ( isset( $_POST['yikes-easy-mc-form-schedule'] ) ) ? '1' : '0',
2629
				'yikes-easy-mc-form-restriction-start'           => strtotime( $_POST['yikes-easy-mc-form-restriction-start-date'] . ' ' . $_POST['yikes-easy-mc-form-restriction-start-time'] ),
2630
				'yikes-easy-mc-form-restriction-end'             => strtotime( $_POST['yikes-easy-mc-form-restriction-end-date'] . ' ' . $_POST['yikes-easy-mc-form-restriction-end-time'] ),
2631
				'yikes-easy-mc-form-restriction-pending-message' => trim( $_POST['yikes-easy-mc-form-restriction-pending-message'] ),
2632
				'yikes-easy-mc-form-restriction-expired-message' => trim( $_POST['yikes-easy-mc-form-restriction-expired-message'] ),
2633
				'yikes-easy-mc-form-login-required'              => ( isset( $_POST['yikes-easy-mc-form-login-required'] ) ) ? '1' : '0',
2634
				'yikes-easy-mc-form-restriction-login-message'   => trim( $_POST['yikes-easy-mc-form-restriction-login-message'] ),
2635
			);
2636
2637
			// additional custom fields (extensions / user defined fields)
2638
			$custom_fields = array();
2639
			if ( isset( $_POST['custom-field'] ) ) {
2640
				foreach ( $_POST['custom-field'] as $custom_field => $custom_value ) {
2641
					if ( is_array( $custom_value ) ) {
2642
						$custom_fields[ $custom_field ] = array_filter( stripslashes_deep( $custom_value ) ); // array_filters to remove empty items (don't save them!)
2643
					} else {
2644
						$custom_fields[ $custom_field ] = stripslashes( $custom_value );
2645
					}
2646
				}
2647
			}
2648
2649
			$form_updates = yikes_deep_parse_args(
2650
				array(
2651
					'list_id'                 => $list_id,
2652
					'form_name'               => $form_name,
2653
					'form_description'        => $form_description,
2654
					'fields'                  => $assigned_fields,
2655
					'custom_template'         => 0,
2656
					'redirect_user_on_submit' => $redirect_user_on_submit,
2657
					'redirect_page'           => $redirect_page,
2658
					'submission_settings'     => $submission_settings,
2659
					'optin_settings'          => $optin_settings,
2660
					'error_messages'          => $error_settings,
2661
					'form_settings'           => $form_settings,
2662
					'custom_fields'           => $custom_fields,
2663
				),
2664
				$this->form_interface->get_form_defaults()
2665
			);
2666
2667
			$form_updates = apply_filters( 'yikes-mailchimp-save-form-filter', $form_updates, $form_id );
2668
2669
			$this->form_interface->update_form( $form_id, $form_updates );
2670
2671
			/* Custom action hook which allows users to update specific options when a form is updated - used in add ons */
2672
			do_action( 'yikes-mailchimp-save-form', $form_id,  $custom_fields );
2673
2674
			// redirect the user to the manage forms page, display confirmation
2675
			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-edit-form&id=' . $form_id . '&updated-form=true' ) ) );
2676
			exit();
2677
		}
2678
2679
		public static function generate_default_email_body() {
2680
			$email_body  = '<p>' . __( 'Greetings,', 'yikes-inc-easy-mailchimp-extender' ) . '</p>'; 
2681
2682
			$email_body .= '<p>';
2683
			$email_body .= 	__( 'A request has been made to update your Mailchimp account profile information.', 'yikes-inc-easy-mailchimp-extender' );
2684
			$email_body .=	__( ' To do so please use the following link: ', 'yikes-inc-easy-mailchimp-extender' );
2685
			$email_body .=	'[link]';
2686
			$email_body .=		__( 'Update Mailchimp Profile Info', 'yikes-inc-easy-mailchimp-extender' );
2687
			$email_body .= 	'[/link]';
2688
			$email_body .= '</p>';
2689
2690
			$email_body .= '<p>' . __( 'If you did not request this update, please disregard this email.', 'yikes-inc-easy-mailchimp-extender' ) . '</p>';
2691
2692
			$email_body .= '<p>&nbsp;</p>';
2693
			$email_body .= '<p>' . sprintf( __( 'This email was sent from: %s', 'yikes-inc-easy-mailchimp-extender' ), '[url]' ) . '</p>';
2694
			$email_body .= '<p>&nbsp;</p>';
2695
			$email_body .= '<p>&nbsp;</p>';
2696
			$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>';
2697
2698
			return $email_body;
2699
		}
2700
2701
		/* Unsubscribe a given user from our list */
2702
		public function yikes_easy_mailchimp_unsubscribe_user() {
2703
			$nonce    = $_REQUEST['nonce'];
2704
			$list_id  = $_REQUEST['mailchimp-list'];
2705
			$email_id = $_REQUEST['email_id'];
2706
2707
			// verify our nonce
2708 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...
2709
				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 ) );
2710
			}
2711
2712
			$response = yikes_get_mc_api_manager()->get_list_handler()->member_unsubscribe( $list_id, $email_id );
2713
			if ( is_wp_error( $response ) ) {
2714
				$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
2715
				$error_logging->maybe_write_to_log(
2716
					$response->get_error_code(),
2717
					__( "Unsubscribe User", 'yikes-inc-easy-mailchimp-extender' ),
2718
					__( "Manage List Page", 'yikes-inc-easy-mailchimp-extender' )
2719
				);
2720
			}
2721
2722
			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-view-list&list-id=' . $list_id . '&user-unsubscribed=true' ) ) );
2723
			exit;
2724
		}
2725
2726
		public function yikes_easy_mailchimp_create_missing_error_log() {
2727
			// grab our nonnce
2728
			$nonce = $_REQUEST['nonce'];
2729
			// validate nonce
2730 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...
2731
				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 ) );
2732
			}
2733
			// setup the path to the error log
2734
			$error_log = fopen( plugin_dir_path( __FILE__ ) . '../includes/error_log/yikes-easy-mailchimp-error-log.php', 'w' );
2735
			try {
2736
				// create the file
2737
				fwrite( $error_log , '' );
2738
				// close out
2739
				fclose( $error_log );
2740
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=debug-settings&error_log_created=true' ) ) );
2741
			} catch ( Exception $e ) {
2742
				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() ) ) ) );
2743
			}
2744
		}
2745
2746
		/*
2747
		*	Clear Transient Data !
2748
		*	Probably Move these to its own file,
2749
		*/
2750
		public function yikes_easy_mailchimp_clear_transient_data() {
2751
2752
			// verify our nonce
2753
			$nonce = $_REQUEST['nonce'];
2754 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...
2755
				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 ) );
2756
			}
2757
2758
			$this->delete_yikes_mailchimp_transients();
2759
2760
			// if the request came from the settings page, redirect to the settings page.
2761
			$referer = wp_get_referer();
2762
			if ( $referer && ( strpos( $referer, 'yikes-inc-easy-mailchimp-settings' ) > 0 ) ) {
2763
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=api-cache-settings&transient-cleared=true' ) ) );
2764
			} elseif ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] === 'yikes-mailchimp-edit-form' && isset( $_REQUEST['id'] ) && ! empty( $_REQUEST['id'] ) ) {
2765
2766
				// else check if we were editing a form.
2767
				$id = filter_var( $_REQUEST['id'], FILTER_SANITIZE_NUMBER_INT );
2768
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-edit-form&id=' . $id ) ) );
2769
			} else {
2770
				// else redirect to the manage forms page.
2771
				wp_redirect( esc_url_raw( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp&transient-cleared=true' ) ) );
2772
			}
2773
2774
			exit;
2775
		}
2776
2777
		/**
2778
		 * Return an array of Mailchimp lists associated with this account
2779
		 *
2780
		 * Used when deleting the sites Mailchimp cache stored
2781
		 *
2782
		 * @since 6.0.2
2783
		 * @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...
2784
		 */
2785
		public function get_mailchimp_list_ids_on_account() {
2786
			$api_key = yikes_get_mc_api_key();
2787
			if ( ! $api_key ) {
2788
				// if no api key is set/site is not connected, return an empty array.
2789
				return array();
2790
			}
2791
2792
			$lists = get_transient( 'yikesinc_eme_list_ids' );
2793
			if ( false === $lists ) {
2794
				$lists = yikes_get_mc_api_manager()->get_list_handler()->get_list_ids();
2795
				if ( is_wp_error( $lists ) ) {
2796
					return array();
2797
				}
2798
				set_transient( 'yikesinc_eme_list_ids', $lists, HOUR_IN_SECONDS );
2799
			}
2800
2801
			return $lists;
2802
		}
2803
2804
		/**
2805
		 *	Include our main Helper class file
2806
		 *
2807
		 *	@since 6.0
2808
		 */
2809
		public function yikes_mailchimp_load_helper_class() {
2810
			// check to see if it's already loaded up.
2811
			if ( !class_exists( 'Yikes_Inc_Easy_Mailchimp_Forms_Helper' ) ) {
2812
				// Include our main helper class file
2813
				include_once( YIKES_MC_PATH . 'admin/partials/helpers/init.php' );
2814
			}
2815
		}
2816
2817
		/**
2818
		 * Alter the color scheme based on the current user selection (this is done to help integrate the plugin into the dashboard more seamlessly)
2819
		 *
2820
		 * @since 0.1
2821
		 * @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)
2822
		 * @return print out custom styles to the admin header to alter the default blue color
2823
		 */
2824
		public function alter_yikes_easy_mc_color_scheme() {
2825
			// get the current set color scheme for the logged in user
2826
			$current_color_scheme = get_user_option( 'admin_color' );
2827
			// switch over each color scheme, and set our variable
2828
			switch ( $current_color_scheme ) {
2829
				default:
2830
				case 'fresh': // default blue (defined by this plugin)
2831
					$main_color = '#00a0d2';
2832
					break;
2833
				case 'light': // light grey
2834
					$main_color = '#E5E5E5';
2835
					break;
2836
				case 'blue': // light blue
2837
					$main_color = '#52ACCC';
2838
					break;
2839
				case 'coffee': // light brown-ish
2840
					$main_color = '#59524C';
2841
					break;
2842
				case 'ectoplasm': // purple
2843
					$main_color = '#523F6D';
2844
					break;
2845
				case 'midnight': // black
2846
					$main_color = '#363B3F';
2847
					break;
2848
				case 'ocean': // green/teal-ish
2849
					$main_color = '#738E96';
2850
					break;
2851
				case 'sunrish': // red/orange
2852
					$main_color = '#CF4944';
2853
					break;
2854
			}
2855
			ob_start();
2856
			?>
2857
				<style>
2858
					.yikes-easy-mc-postbox h3,
2859
					.column-columnname .form-id-container,
2860
					.mv_ig_list .nav-tab-active {
2861
						background: <?php echo $main_color; ?>;
2862
					}
2863
					.mv_ig_list .arrow-down {
2864
						border-top: 9pt solid <?php echo $main_color; ?>;
2865
					}
2866
				</style>
2867
			<?php
2868
			$override_admin_styles = ob_get_clean();
2869
			// add our inline styles.
2870
			echo $override_admin_styles;
2871
		}
2872
2873
		/**
2874
		 *	Display premium support page if any add-ons are installed, otherwise display free support page
2875
		 */
2876
		public function display_support_page_content() {
2877
2878
			$addons = get_option( 'yikes-easy-mc-active-addons', array() );
2879
2880
			// If we have premium add-ons...
2881
			if ( ! empty( $addons ) ) { 
2882
2883
				// Add our premium support partial.
2884
				include_once( YIKES_MC_PATH . 'admin/partials/helpers/premium-support.php' );
2885
			} else {
2886
2887
				// Otherwise add our free support partial.
2888
				include_once( YIKES_MC_PATH . 'admin/partials/helpers/free-support.php' );
2889
			}
2890
		}
2891
2892
		/**
2893
		 * Check the users version number, and display a notice to upgrade the database if needed
2894
		 *
2895
		 * @since 6.0.4
2896
		 */
2897
		public function check_yikes_mc_table_version() {
2898
			if ( get_option( 'yikes_mc_database_version', '0.00' ) < '1.0' ) {
2899
				require_once YIKES_MC_PATH . 'includes/class-yikes-inc-easy-mailchimp-extender-activator.php';
2900
				global $wpdb;
2901
				Yikes_Inc_Easy_Mailchimp_Extender_Activator::_activate_yikes_easy_mailchimp( $wpdb );
2902
				// update the database option
2903
				update_option( 'yikes_mc_database_version', '1.0' );
2904
			}
2905
		}
2906
2907
		/**
2908
		 * Process [yikes-mailchimp-form-description] into the shortcode
2909
		 *
2910
		 * @since 6.0.4.4
2911
		 */
2912
		public function process_subscriber_count_shortcode_in_form_descriptions( $form_description, $form_id ) {
2913
			$form_description = str_replace( '[yikes-mailchimp-subscriber-count]', do_shortcode( '[yikes-mailchimp-subscriber-count form="' . $form_id . '"]' ), $form_description );
2914
			return $form_description;
2915
		}
2916
2917
		/**
2918
		 * Generate the sidebar advertisement on the 'Edit Form' page
2919
		 *
2920
		 * @since 6.0.3
2921
		 */
2922
		public function generate_edit_forms_upsell_ad() {
2923
		$upsell_ads = glob( YIKES_MC_PATH . 'includes/upsells/*.php' );
2924
		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...
2925
			$ad_count = absint( count( $upsell_ads ) - 1 );
2926
			$ad       = $upsell_ads[ mt_rand( 0, $ad_count ) ];
2927
			ob_start();
2928
			include_once( $ad );
2929
			$ad_content = ob_get_contents();
2930
			ob_get_clean();
2931
		}
2932
		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...
2933
		}
2934
2935
		/***
2936
		 * Helper function to clear out transients stored by this plugin
2937
		 *
2938
		 * Mainly used when the API key is altered, changed or removed.
2939
		 * @since 6.1.3
2940
		 */
2941
		public function delete_yikes_mailchimp_transients() {
2942
2943
		// delete all of the list_id transients.
2944
		$list_ids = $this->get_mailchimp_list_ids_on_account();
2945
		foreach ( $list_ids as $id ) {
2946
			delete_transient( "yikes_eme_list_{$id}" );
2947
			delete_transient( "yikes_eme_merge_variables_{$id}" );
2948
			delete_transient( "yikes_eme_interest_categories_{$id}" );
2949
			delete_transient( "yikes_eme_segments_{$id}_saved" );
2950
			delete_transient( "yikes_eme_segments_{$id}_static" );
2951
			delete_transient( "yikes_eme_segments_{$id}_fuzzy" );
2952
			delete_transient( "yikes_eme_members_{$id}" );
2953
		}
2954
2955
		delete_transient( 'yikes-easy-mailchimp-list-data' );
2956
		delete_transient( 'yikes-easy-mailchimp-account-data' );
2957
		delete_transient( 'yikes-easy-mailchimp-profile-data' );
2958
		delete_transient( 'yikesinc_eme_list_ids' );
2959
		delete_transient( 'yikes_eme_lists' );
2960
	}
2961
2962
	/**
2963
	 * Register the Opt-in widget.
2964
	 *
2965
	 * @author Jeremy Pry
2966
	 */
2967
	public function register_optin_widget() {
2968
		register_widget( 'Yikes_Inc_Easy_Mailchimp_Extender_Widget' );
2969
	}
2970
}
2971