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

yikes-inc-easy-mailchimp-extender.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Plugin Name: Easy Forms for Mailchimp
4
 * Plugin URI:  https://yikesplugins.com/plugin/easy-forms-for-mailchimp/
5
 * Description: The ultimate Mailchimp WordPress plugin. Easily build <strong>unlimited forms for your Mailchimp lists</strong>, add them to your site and track subscriber activity. To get started, go to the settings page and enter your <a href="https://yikesplugins.com/support/knowledge-base/finding-your-mailchimp-api-key/" target="_blank">Mailchimp API key</a>.
6
 * Version:     6.5.1
7
 * Author:      YIKES, Inc.
8
 * Author URI:  https://www.yikesplugins.com/
9
 * License:     GPL-3.0+
10
 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
11
 * Text Domain: yikes-inc-easy-mailchimp-extender
12
 *
13
 * Easy Forms for Mailchimp is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation, either version 2 of the License, or
16
 * any later version.
17
 *
18
 * Easy Forms for Mailchimp is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with Easy Forms for Mailchimp. If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 * We at YIKES, Inc. embrace the open source philosophy on a daily basis. We donate company time back to the WordPress project,
27
 * and constantly strive to improve the WordPress project and community as a whole.
28
 *
29
 * "'Free software' is a matter of liberty, not price. To understand the concept, you should think of 'free' as in 'free speech,' not as in 'free beer'."
30
 * - Richard Stallman
31
 *
32
 */
33
34
35
// If accessed directly, abort
36
if ( ! defined( 'WPINC' ) ) {
37
	die;
38
}
39
40
/**
41
 * 	Define version constant
42
 *
43
 * 	@since 6.1.3
44
 */
45
if ( ! defined( 'YIKES_MC_VERSION' ) ) {
46
	define( 'YIKES_MC_VERSION', '6.5.1' );
47
}
48
49
/**
50
 * 	Define path constant to our plugin directory.
51
 *
52
 * 	@since 6.0.0
53
 */
54
if ( ! defined( 'YIKES_MC_PATH' ) ) {
55
	define( 'YIKES_MC_PATH', plugin_dir_path( __FILE__ ) );
56
}
57
58
/**
59
 * 	Define URL constant to our plugin directory.
60
 *
61
 * 	@since 6.0.0
62
 */
63
if ( ! defined( 'YIKES_MC_URL' ) ) {
64
	define( 'YIKES_MC_URL', plugin_dir_url( __FILE__ ) );
65
}
66
67
// Include our autoloader
68
require_once dirname( __FILE__ ) . '/class-loader.php';
69
70
/**
71
 *	activate_yikes_inc_easy_mailchimp_extender();
72
 * 	Fires during activation.
73
 *
74
 * 	This action is documented in includes/class-yikes-inc-easy-mailchimp-extender-activator.php
75
 * 	and carries out some important tasks such as creating our custom database table if it doesn't
76
 * 	already exist, and defining default options.
77
 *
78
 * 	@since 6.0.0
79
 *	@return void
80
 */
81
register_activation_hook( __FILE__, 'activate_yikes_inc_easy_mailchimp_extender' );
82
function activate_yikes_inc_easy_mailchimp_extender( $network_wide ) {
83
	Yikes_Inc_Easy_Mailchimp_Extender_Activator::activate( $network_wide );
84
}
85
86
/**
87
 *	uninstall_yikes_inc_easy_mailchimp_extender();
88
 * 	The code that runs during uninstall.
89
 *
90
 * 	This action is documented in includes/class-yikes-inc-easy-mailchimp-extender-uninstall.php
91
 *	and carries out the deletion of Mailchimp transients, plugin options and Mailchimp form tables.
92
 *
93
 * @since 6.0.0
94
 *	@return void
95
 */
96
register_deactivation_hook( __FILE__, 'deactivate_yikes_inc_easy_mailchimp_extender' );
97
function deactivate_yikes_inc_easy_mailchimp_extender() {
98
	// delete the activation re-driect option
99
	update_option( 'yikes_mailchimp_activation_redirect', 'true' );
100
}
101
102
/**
103
 *	uninstall_yikes_inc_easy_mailchimp_extender();
104
 * 	The code that runs during uninstall.
105
 *
106
 * 	This action is documented in includes/class-yikes-inc-easy-mailchimp-extender-uninstall.php
107
 *	and carries out the deletion of Mailchimp transients, plugin options and Mailchimp form tables.
108
 *
109
 * @since 6.0.0
110
 * @return void
111
 */
112
register_uninstall_hook( __FILE__, 'uninstall_yikes_inc_easy_mailchimp_extender' );
113
function uninstall_yikes_inc_easy_mailchimp_extender() {
114
	Yikes_Inc_Easy_Mailchimp_Extender_Uninstaller::uninstall();
115
}
116
117
/**
118
 * 	Multi-site blog creation
119
 *
120
 *	If a new blog is created on a mutli-site network
121
 *	we should run our activation hook to create the necessary form table
122
 *
123
 * 	@since 6.0.0
124
 *	@return void
125
 */
126
add_action( 'wpmu_new_blog', 'yikes_easy_mailchimp_new_network_site', 10, 6 );
127
function yikes_easy_mailchimp_new_network_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
128
	if ( is_plugin_active_for_network( 'yikes-inc-easy-mailchimp-extender/yikes-inc-easy-mailchimp-extender.php' ) ) {
129
		switch_to_blog( $blog_id );
130
		Yikes_Inc_Easy_Mailchimp_Extender_Activator::activate( false );
131
		restore_current_blog();
132
	}
133
}
134
135
/**
136
 * Retrieve the forms interface that we should be using.
137
 *
138
 * By default this will use the new Options interface, but this can be
139
 * overridden by a constant, YIKES_MC_CUSTOM_DB.
140
 *
141
 * @author Jeremy Pry
142
 * @return Yikes_Inc_Easy_MailChimp_Extender_Form_Interface
143
 */
144
function yikes_easy_mailchimp_extender_get_form_interface() {
145
	static $interface = null;
146
147
	if ( null === $interface ) {
148
		if ( yikes_inc_easy_mailchimp_extender_use_custom_db() ) {
149
			global $wpdb;
150
			$interface = new Yikes_Inc_Easy_MailChimp_Extender_Forms( $wpdb );
151
		} else {
152
			$interface = new Yikes_Inc_Easy_MailChimp_Extender_Option_Forms();
153
		}
154
	}
155
156
	return $interface;
157
}
158
159
/**
160
 * Determine whether we should use the custom database table.
161
 *
162
 * @author Jeremy Pry
163
 * @return bool Whether to use the custom database table.
164
 */
165
function yikes_inc_easy_mailchimp_extender_use_custom_db() {
166
	/**
167
	 * Filter whether we should use the custom database table instead of the Options API
168
	 *
169
	 * @param bool $use_custom_db True to use the custom database table, false to use the Options API.
170
	 */
171
	return (bool) apply_filters( 'yikes_easy_mailchimp_extender_use_custom_db', defined( 'YIKES_EMCE_CUSTOM_DB' ) && YIKES_EMCE_CUSTOM_DB );
172
}
173
174
/**
175
 * 	Begins execution of the plugin.
176
 *
177
 * 	@since 6.0.0
178
 *	@return Yikes_Inc_Easy_Mailchimp_Extender
179
 */
180
function yikes_inc_easy_mailchimp_extender() {
181
	static $plugin = null;
182
183
	if ( null === $plugin ) {
184
		$plugin = new Yikes_Inc_Easy_Mailchimp_Extender( yikes_easy_mailchimp_extender_get_form_interface() );
0 ignored issues
show
It seems like yikes_easy_mailchimp_extender_get_form_interface() can also be of type null; however, Yikes_Inc_Easy_Mailchimp_Extender::__construct() does only seem to accept object<Yikes_Inc_Easy_Ma...xtender_Form_Interface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
185
		$plugin->run();
186
	}
187
188
	return $plugin;
189
}
190
yikes_inc_easy_mailchimp_extender()->run();
191
192
/**
193
 * Helper function to return our API key
194
 * Support the use of a PHP constant
195
 * @return string Mailchimp API key from the PHP constant, or the options
196
 * @security strip away tags and patch security
197
 * @since 6.2.2
198
 */
199
function yikes_get_mc_api_key() {
200
	if ( defined( 'YIKES_MC_API_KEY' ) ) {
201
		return trim( strip_tags( YIKES_MC_API_KEY ) );
202
	}
203
204
	return trim( strip_tags( get_option( 'yikes-mc-api-key', '' ) ) );
205
}
206
207
/**
208
 * Get the API Manager instance.
209
 *
210
 * @author Jeremy Pry
211
 * @return Yikes_Inc_Easy_MailChimp_API_Manager
212
 */
213
function yikes_get_mc_api_manager() {
214
	static $manager = null;
215
216
	if ( null === $manager ) {
217
		$manager = new Yikes_Inc_Easy_MailChimp_API_Manager( yikes_get_mc_api_key() );
218
	}
219
220
	return $manager;
221
}
222
223
add_action( 'plugins_loaded', 'yikes_mailchimp_plugin_textdomain' );
224
function yikes_mailchimp_plugin_textdomain() {
225
	load_plugin_textdomain( 'yikes-inc-easy-mailchimp-extender', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
226
}
227
228
/*
229
*	Enjoy this wonderfully powerful (and free) plugin.
230
*	~<|:D
231
*/
232