settings.php ➔ wpbo_mp_settings()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 16
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 27
rs 8.8571
1
<?php
2
/**
3
 * BetterOptin Provider MailPoet
4
 *
5
 * @package   BetterOptin/Provider/MailChimp/Settings
6
 * @author    ThemeAvenue <[email protected]>
7
 * @license   GPL-2.0+
8
 * @link      http://themeavenue.net
9
 * @copyright 2015 ThemeAvenue
10
 */
11
12
// If this file is called directly, abort.
13
if ( ! defined( 'WPINC' ) ) {
14
	die;
15
}
16
17
add_filter( 'wpbo_plugin_settings', 'wpbo_mp_settings' );
18
/**
19
 * Addon settings.
20
 *
21
 * Add new settings to the plugin settings page.
22
 *
23
 * @since  1.0.0
24
 *
25
 * @param  array $settings Pre-existing settings
26
 *
27
 * @return array           Updated settings containing MailChimp options
28
 */
29
function wpbo_mp_settings( $settings ) {
30
31
	$lists          = wpbo_mp_get_mailpoet_lists();
32
	$lists_list[''] = esc_html_x( 'Please select...', 'Select a MailPoet mailing list',  'betteroptin' );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$lists_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $lists_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
33
34
	foreach ( $lists as $list ) {
35
		$lists_list[ $list['list_id'] ] = $list['name'];
36
	}
37
38
	$list_id = array(
39
		'name'    => __( 'List', 'betteroptin' ),
40
		'id'      => 'mp_list_id',
41
		'type'    => 'select',
42
		'options' => $lists_list,
43
		'default' => ''
44
	);
45
46
	$settings['mailpoet'] = array(
47
		'name'    => __( 'MailPoet', 'betteroptin' ),
48
		'options' => array(
49
			$list_id
50
		)
51
	);
52
53
	return $settings;
54
55
}