Completed
Pull Request — staging (#840)
by
unknown
19:08
created

Yikes_Inc_Easy_Mailchimp_Forms_Admin   F

Complexity

Total Complexity 391

Size/Duplication

Total Lines 2938
Duplicated Lines 6.67 %

Coupling/Cohesion

Components 3
Dependencies 10

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 196
loc 2938
ccs 0
cts 1127
cp 0
rs 0.8
c 0
b 0
f 0
wmc 391
lcom 3
cbo 10

64 Methods

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

How to fix   Duplicated Code    Complexity   

Duplicated Code

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

Common duplication problems, and corresponding solutions are:

Complex Class

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return false;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return false;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
842
		 }
843
	}
844
845
	/**
846
	*	Register our admin pages
847
	*	used to display data back to the user
848
	**/
849
	public function register_admin_pages() {
850
851
		/* Top Level Menu 'Easy Mailchimp' */
852
		add_menu_page(
853
			__( 'Easy Forms', 'yikes-inc-easy-mailchimp-extender' ),
854
			'Easy Forms',
855
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
856
			'yikes-inc-easy-mailchimp',
857
			'', // no callback,
858
			YIKES_MC_URL . 'includes/images/Mailchimp_Assets/Freddie_wink_icon.png'
859
		);
860
861
		// Sub Pages
862
		/*************/
863
864
		/* Easy Mailchimp Settings */
865
866
		/* Easy Mailchimp Manage Forms */
867
		add_submenu_page(
868
			'yikes-inc-easy-mailchimp',
869
			__( 'Opt-in Forms', 'yikes-inc-easy-mailchimp-extender' ),
870
			__( 'Opt-in Forms', 'yikes-inc-easy-mailchimp-extender' ),
871
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
872
			'yikes-inc-easy-mailchimp',
873
			array( $this, 'generateManageFormsPage' )
874
		);
875
876
		/* Easy Mailchimp Manage Lists */
877
		add_submenu_page(
878
			'yikes-inc-easy-mailchimp',
879
			__( 'Mailing Lists', 'yikes-inc-easy-mailchimp-extender' ),
880
			__( 'Mailing Lists', 'yikes-inc-easy-mailchimp-extender' ),
881
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
882
			'yikes-inc-easy-mailchimp-lists',
883
			array( $this, 'generateManageListsPage' )
884
		);
885
886
887
		/*
888
		*	Custom action hook to hook into to add additional
889
		*	menu items from extensions
890
		*/
891
		do_action( 'yikes-mailchimp-menu' );
892
893
		/* Easy Mailchimp Settings */
894
		add_submenu_page(
895
			'yikes-inc-easy-mailchimp',
896
			__( 'Settings.', 'yikes-inc-easy-mailchimp-extender' ),
897
			__( 'Settings', 'yikes-inc-easy-mailchimp-extender' ),
898
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
899
			'yikes-inc-easy-mailchimp-settings',
900
			array( $this, 'generatePageOptions' )
901
		);
902
903
		/* Support Page */
904
		add_submenu_page(
905
			'yikes-inc-easy-mailchimp',
906
			__( 'Support', 'yikes-inc-easy-mailchimp-extender' ),
907
			__( 'Support', 'yikes-inc-easy-mailchimp-extender' ),
908
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
909
			'yikes-inc-easy-mailchimp-support',
910
			array( $this, 'generateSupportPage' )
911
		);
912
913
		/* Add-Ons Page */
914
		add_submenu_page(
915
			'yikes-inc-easy-mailchimp',
916
			__( 'Add-Ons', 'yikes-inc-easy-mailchimp-extender' ),
917
			__( 'Add-Ons', 'yikes-inc-easy-mailchimp-extender' ),
918
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
919
			'yikes-inc-easy-mailchimp-addons',
920
			array( $this, 'generateAddOnsPage' )
921
		);
922
923
		/** Hidden Pages **/
924
925
		/* Add Hidden Edit Form Page */
926
		add_submenu_page(
927
			'options.php',
928
			__( 'Edit Form', 'yikes-inc-easy-mailchimp-extender' ),
929
			__( 'Edit Form', 'yikes-inc-easy-mailchimp-extender' ),
930
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
931
			'yikes-mailchimp-edit-form',
932
			array( $this, 'generateEditFormPage' )
933
		);
934
935
		/* Add Hidden 'View List' Page */
936
		add_submenu_page(
937
			'options.php',
938
			__( 'View List', 'yikes-inc-easy-mailchimp-extender' ),
939
			__( 'View List', 'yikes-inc-easy-mailchimp-extender' ),
940
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
941
			'yikes-mailchimp-view-list',
942
			array( $this, 'generateViewListPage' )
943
		);
944
945
		/* Add Hidden View User Page */
946
		add_submenu_page(
947
			'options.php',
948
			__( 'View User', 'yikes-inc-easy-mailchimp-extender' ),
949
			__( 'View User', 'yikes-inc-easy-mailchimp-extender' ),
950
			apply_filters( 'yikes-mailchimp-user-role-access', 'manage_options' ),
951
			'yikes-mailchimp-view-user',
952
			array( $this, 'generateViewUserPage' )
953
		);
954
955
	}
956
957
	/*
958
	*	Redirect a user to an external page
959
	*	when they click 'Go Pro' in the admin menu
960
	*	to do: populate with sales URL
961
	*/
962
	public function generateAddOnsPage() {
963
		require_once YIKES_MC_PATH . 'admin/partials/menu/add-ons.php'; // include our add-ons page
964
	}
965
966
	/**
967
	* Generate Us Easy Mailchimp Manage Forms Page
968
	*
969
	* @since    1.0.0
970
	*/
971
	function generateManageFormsPage() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
972
		require_once YIKES_MC_PATH . 'admin/partials/menu/manage-forms.php'; // include our manage forms page
973
	}
974
975
	/**
976
	* Generate Us Easy Mailchimp Manage Lists Page
977
	*
978
	* @since    1.0.0
979
	*/
980
	function generateManageListsPage() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
981
		require_once YIKES_MC_PATH . 'admin/partials/menu/manage-lists.php'; // include our lists page
982
	}
983
984
	/**
985
	* Generate Us Easy Mailchimp Support Page
986
	*
987
	* @since    1.0.0
988
	*/
989
	function generateSupportPage() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
990
991
		wp_enqueue_script( 'yikes-inc-easy-mailchimp-extender-support-scripts', plugin_dir_url( __FILE__ ) . 'js/support.js', array( 'jquery' ), $this->version, false );	
992
		require_once YIKES_MC_PATH . 'admin/partials/menu/support.php';
993
	}
994
995
	/**
996
	* Generate Us Easy Mailchimp Edit Form Page
997
	*
998
	* @since    1.0.0
999
	*/
1000
	function generateEditFormPage() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
1001
		require_once YIKES_MC_PATH . 'admin/partials/edit-form.php'; // include our options page
1002
	}
1003
1004
	/**
1005
	* Generate Us Easy Mailchimp View List Page
1006
	*
1007
	* @since    1.0.0
1008
	*/
1009
	function generateViewListPage() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
1010
		require_once YIKES_MC_PATH . 'admin/partials/view-list.php'; // include our options page
1011
	}
1012
1013
	/**
1014
	* Generate Us Easy Mailchimp View User Page
1015
	*
1016
	* @since    1.0.0
1017
	*/
1018
	function generateViewUserPage() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
1019
		require_once YIKES_MC_PATH . 'admin/partials/view-user.php'; // include our options page
1020
	}
1021
1022
	/**
1023
	*	Register our plugin settings, and display them on our settings page
1024
	*
1025
	* @since v.5.4
1026
	**/
1027
	function yikes_easy_mc_settings_init() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
1028
1029
		/* Register General Settings Section */
1030
1031
		register_setting( 'yikes_inc_easy_mc_general_settings_page', 'yikes-mc-api-key', array( $this , 'yikes_mc_validate_api_key' ) );
1032
1033
		register_setting( 'yikes_inc_easy_mc_general_settings_page', 'yikes-mailchimp-use-nonce' );
1034
1035
		add_settings_section(
1036
			'yikes_easy_mc_settings_general_section_callback',
1037
			'',
1038
			'',
1039
			'yikes_inc_easy_mc_general_settings_page'
1040
		);
1041
1042
		/* Register Visual Representation of Connection */
1043
		add_settings_field(
1044
			'connection',
1045
			__( 'API Connection', 'yikes-inc-easy-mailchimp-extender' ),
1046
			'yikes_inc_easy_mc_visual_representation_of_connection_callback', // callback + validation inside of admin/partials/menu/options.php
1047
			'yikes_inc_easy_mc_general_settings_page',
1048
			'yikes_easy_mc_settings_general_section_callback'
1049
		);
1050
1051
		/* Register Check Box Setting */
1052
		add_settings_field(
1053
			'yikes-mc-api-key',
1054
			__( 'Mailchimp API Key', 'yikes-inc-easy-mailchimp-extender' ),
1055
			'yikes_inc_easy_mc_api_key_field_callback', // callback + validation inside of admin/partials/menu/options.php
1056
			'yikes_inc_easy_mc_general_settings_page',
1057
			'yikes_easy_mc_settings_general_section_callback'
1058
		);
1059
1060
		/* End General Settings */
1061
1062
		/* Checkbox Settings */
1063
		register_setting( 'yikes_inc_easy_mc_checkbox_settings_page', 'optin-checkbox-init' );
1064
1065
		/* Register General Settings Section */
1066
		add_settings_section(
1067
			'yikes_inc_easy_mc_checkbox_settings',
1068
			'',
1069
			'',
1070
			'yikes_inc_easy_mc_checkbox_settings_page'
1071
		);
1072
1073
		add_settings_field(
1074
			'optin-checkbox-init',
1075
			__( 'Select Checkboxes to Generate', 'yikes-inc-easy-mailchimp-extender' ),
1076
			'',  // callback + validation inside of admin/partials/menu/options.php
1077
			'yikes_inc_easy_mc_checkbox_settings'
1078
		);
1079
		/* End Checkbox Settings */
1080
1081
		/* reCAPTCHA Settings */
1082
1083
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-status' );
1084
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-site-key' );
1085
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-secret-key' );
1086
1087
			/* Version 3 Settings */
1088
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-site-key-three' );
1089
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-secret-key-three' );
1090
			register_setting( 'yikes_inc_easy_mc_recaptcha_settings_page', 'yikes-mc-recaptcha-version-three' );
1091
1092
			/* Register reCAPTCHA Settings Section */
1093
			add_settings_section(
1094
				'yikes_easy_mc_settings_recpatcha_section',
1095
				'',
1096
				'',
1097
				'yikes_inc_easy_mc_recaptcha_settings_page'
1098
			);
1099
1100
			add_settings_field(
1101
				'yikes-mc-recaptcha-site-key',
1102
				__( 'Enter reCAPTCHA V2 Site Key', 'yikes-inc-easy-mailchimp-extender' ),
1103
				'',  // callback + validation inside of admin/partials/menu/options.php
1104
				'yikes_easy_mc_settings_recpatcha_section'
1105
			);
1106
1107
			add_settings_field(
1108
				'yikes-mc-recaptcha-secret-key',
1109
				__( 'Enter reCAPTCHA V2 Secret Key', 'yikes-inc-easy-mailchimp-extender' ),
1110
				'',  // callback + validation inside of admin/partials/menu/options.php
1111
				'yikes_easy_mc_settings_recpatcha_section'
1112
			);
1113
1114
			add_settings_field(
1115
				'yikes-mc-recaptcha-status',
1116
				__( 'Enable ReCaptcha', 'yikes-inc-easy-mailchimp-extender' ),
1117
				'',  // callback + validation inside of admin/partials/menu/options.php
1118
				'yikes_easy_mc_settings_recpatcha_section'
1119
			);
1120
1121
			add_settings_field(
1122
				'yikes-mc-recaptcha-version-three',
1123
				__( 'Enable Version 3', 'yikes-inc-easy-mailchimp-extender' ),
1124
				'',  // callback + validation inside of admin/partials/menu/options.php
1125
				'yikes_easy_mc_settings_recpatcha_section'
1126
			);
1127
1128
			add_settings_field(
1129
				'yikes-mc-recaptcha-site-key-three',
1130
				__( 'Enter reCAPTCHA V3 Site Key', 'yikes-inc-easy-mailchimp-extender' ),
1131
				'',  // callback + validation inside of admin/partials/menu/options.php
1132
				'yikes_easy_mc_settings_recpatcha_section'
1133
			);
1134
1135
			add_settings_field(
1136
				'yikes-mc-recaptcha-secret-key-three',
1137
				__( 'Enter reCAPTCHA V3 Secret Key', 'yikes-inc-easy-mailchimp-extender' ),
1138
				'',  // callback + validation inside of admin/partials/menu/options.php
1139
				'yikes_easy_mc_settings_recpatcha_section'
1140
			);
1141
1142
		/* End reCAPTCHA Settings */
1143
1144
		/* Debug Settings */
1145
			register_setting( 'yikes_inc_easy_mc_debug_settings_page', 'yikes-mailchimp-debug-status' );
1146
1147
			/* Register Debug Settings Section */
1148
			add_settings_section(
1149
				'yikes_easy_mc_settings_debug_section',
1150
				'',
1151
				'',
1152
				'yikes_inc_easy_mc_debug_settings_page'
1153
			);
1154
1155
			add_settings_field(
1156
				'yikes-mailchimp-debug-status',
1157
				__( 'Enable Debugging', 'yikes-inc-easy-mailchimp-extender' ),
1158
				'',  // callback + validation inside of admin/partials/menu/options.php
1159
				'yikes_easy_mc_settings_debug_section'
1160
			);
1161
1162
		/* Custom Action Hook For Addon Settings */
1163
			// custom action hook to allow our add-ons to take
1164
			// advantage of our base settings
1165
			do_action( 'yikes-mailchimp-settings-field' );
1166
1167
	}
1168
1169
	/**
1170
	*	Options Sanitization & Validation
1171
	*	@since complete re-write
1172
	**/
1173
	function yikes_mc_validate_api_key( $input ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
1174
		if ( $input === '' ) {
1175
			update_option( 'yikes-mc-api-validation', 'invalid_api_key' );
1176
			return '';
1177
		}
1178
		$api_key = strip_tags ( trim( $input ) );
1179
		$dash_position = strpos( trim( $input ), '-' );
1180
		if ( $dash_position !== false ) {
1181
			$manager = new Yikes_Inc_Easy_Mailchimp_API_Manager( $api_key );
1182
		} else {
1183
			update_option( 'yikes-mc-api-invalid-key-response', __( 'Your API key appears to be invalid.', 'yikes-inc-easy-mailchimp-extender' ) );
1184
			update_option( 'yikes-mc-api-validation', 'invalid_api_key' );
1185
			return $api_key;
1186
		}
1187
1188
		$response = $manager->get_account_handler()->get_account( false );
1189
		if ( ! is_wp_error( $response ) ) {
1190
			update_option( 'yikes-mc-api-validation', 'valid_api_key' );
1191
				// Clear the API key transient data
1192
			$this->delete_yikes_mailchimp_transients();
1193
		}  else {
1194
			$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
1195
			$error_logging->yikes_easy_mailchimp_write_to_error_log( $response->get_error_message() , __( "Connecting to Mailchimp" , 'yikes-inc-easy-mailchimp-extender' ) , __( "Settings Page/General Settings" , 'yikes-inc-easy-mailchimp-extender' ) );
1196
			update_option( 'yikes-mc-api-invalid-key-response', $response->get_error_message() );
1197
			update_option( 'yikes-mc-api-validation', 'invalid_api_key' );
1198
		}
1199
		// returned the api key
1200
		return $api_key;
1201
	}
1202
1203
	/**
1204
	* Generate Us Easy Forms for Mailchimp Options Page
1205
	*
1206
	* @since    1.0.0
1207
	*/
1208
	function generatePageOptions() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
1209
		require_once YIKES_MC_PATH . 'admin/partials/menu/options.php'; // include our options page
1210
	}
1211
1212
	/**
1213
	*	Check if users API key is valid, if not
1214
	*	this function will apply a disabled attribute
1215
	*	to form fields. (input, dropdowns, buttons etc.)
1216
	* 	@since v5.5 re-write
1217
	**/
1218
	public function is_user_mc_api_valid_form( $echo = true ) {
1219
		if ( $echo == true ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

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

Loading history...
1220
			if ( get_option( 'yikes-mc-api-validation', 'invalid_api_key' ) == 'invalid_api_key' ) {
1221
				echo 'disabled="disabled"';
1222
			}
1223
		} else {
1224
			if ( get_option( 'yikes-mc-api-validation', 'invalid_api_key' ) == 'invalid_api_key' ) {
1225
				return false;
1226
			} else {
1227
				return true;
1228
			}
1229
		}
1230
	}
1231
1232
	/**
1233
	 * Admin Notices
1234
	 *	- Notifications displayed at the top of admin pages, back to the user
1235
	 */
1236
1237
		/*
1238
		*	Search through multi dimensional array
1239
		*	and return the index ( used to find the list name assigned to a form )
1240
		*	- http://stackoverflow.com/questions/6661530/php-multi-dimensional-array-search
1241
		*/
1242
		function findMCListID($id, $array) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
1243
		   foreach ($array as $key => $val) {
1244
			   if ($val['id'] === $id) {
1245
				   return $key;
1246
			   }
1247
		   }
1248
		   return null;
1249
		} // end
1250
1251
		/*
1252
		*	generate_options_pages_sidebar_menu();
1253
		*	Render our sidebar menu on all of the setings pages (general, form, checkbox, recaptcha, popup, debug etc. )
1254
		*	@since v5.6 - complete re-write
1255
		*/
1256
		public function generate_options_pages_sidebar_menu() {
1257
			if ( isset( $_REQUEST['section'] ) ) {
1258
				$selected = $_REQUEST['section'];
0 ignored issues
show
Unused Code introduced by
$selected is not used, you could remove the assignment.

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

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

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

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

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

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

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

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

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

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

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

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

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