Completed
Push — staging ( 68fed3...485a71 )
by Evan
04:30
created

yikes-inc-easy-mailchimp-extender.php ➔ yikes_get_mc_api_manager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 0
cts 5
cp 0
crap 6
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 45 and the first side effect is on line 36.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Plugin Name: Easy Forms for MailChimp by YIKES
4
 * Plugin URI:  http://www.yikesinc.com/services/yikes-inc-easy-mailchimp-extender/
5
 * Description: YIKES Easy Forms for MailChimp links your site to MailChimp and allows you to generate and display mailing list opt-in forms anywhere on your site with ease.
6
 * Version:     6.3.0
7
 * Author:      YIKES
8
 * Author URI:  http://www.yikesinc.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
 * YIKES 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
 * YIKES 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. We eat, sleep and breathe WordPress.
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
// If accessed directly, abort
35
if ( ! defined( 'WPINC' ) ) {
36
	die;
37
}
38
39
/**
40
 * 	Define version constant
41
 *
42
 * 	@since 6.1.3
43
 */
44
if ( ! defined( 'YIKES_MC_VERSION' ) ) {
45
	define( 'YIKES_MC_VERSION' , '6.2.4' );
46
}
47
48
/**
49
 * 	Define path constant to our plugin directory.
50
 *
51
 * 	@since 6.0.0
52
 */
53
if ( ! defined( 'YIKES_MC_PATH' ) ) {
54
	define( 'YIKES_MC_PATH' , plugin_dir_path( __FILE__ ) );
55
}
56
57
/**
58
 * 	Define URL constant to our plugin directory.
59
 *
60
 * 	@since 6.0.0
61
 */
62
if ( ! defined( 'YIKES_MC_URL' ) ) {
63
	define( 'YIKES_MC_URL' , plugin_dir_url( __FILE__ ) );
64
}
65
66
// Include our autoloader
67
require_once( dirname( __FILE__ ) . '/class-loader.php' );
68
69
/**
70
 *	activate_yikes_inc_easy_mailchimp_extender();
71
 * 	Fires during activation.
72
 *
73
 * 	This action is documented in includes/class-yikes-inc-easy-mailchimp-extender-activator.php
74
 * 	and carries out some important tasks such as creating our custom database table if it doesn't
75
 * 	already exist, and defining default options.
76
 *
77
 * 	@since 6.0.0
78
 *	@return void
79
 */
80
register_activation_hook( __FILE__, 'activate_yikes_inc_easy_mailchimp_extender' );
81
function activate_yikes_inc_easy_mailchimp_extender( $network_wide ) {
82
	add_option( 'yikes_mailchimp_activation_redirect', 'true' );
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 ) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_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...
Unused Code introduced by
The parameter $domain 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...
Unused Code introduced by
The parameter $path 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...
Unused Code introduced by
The parameter $site_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...
Unused Code introduced by
The parameter $meta 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...
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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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
Bug introduced by
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