Completed
Push — master ( 42ba23...5fbbab )
by Julien
03:55
created

functions-metabox.php ➔ wpbo_mc_save_list()   C

Complexity

Conditions 13
Paths 12

Size

Total Lines 35
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 13
eloc 18
c 1
b 0
f 1
nc 12
nop 1
dl 0
loc 35
rs 5.1234

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * BetterOptin Provider MailChimp
4
 *
5
 * @package   BetterOptin/Provider/MailChimp
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_action( 'save_post', 'wpbo_mc_save_list' );
18
/**
19
 * Save the popup custom list.
20
 *
21
 * @since  1.0.0
22
 * @param  integer $post_id Post ID
23
 */
24
function wpbo_mc_save_list( $post_id ) {
25
26
	if ( ! isset( $_POST['wpbo_display'] ) || isset( $_POST['wpbo_display'] ) && ! wp_verify_nonce( $_POST['wpbo_display'], 'add_display' ) ) {
27
		return;
28
	}
29
30
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
31
		return;
32
	}
33
34
	if ( ! isset( $_POST['post_type'] ) || isset( $_POST['post_type'] ) && 'wpbo-popup' != $_POST['post_type'] ) {
35
		return;
36
	}
37
38
	if ( ! current_user_can( 'edit_post', $post_id ) ) {
39
		return;
40
	}
41
42
	$list = isset( $_POST['wpbo_mc_list'] ) ? $_POST['wpbo_mc_list'] : false;
43
44
	/* Save custom list ID */
45
	if ( false === $list ) {
46
		delete_post_meta( $post_id, 'wpbo_mc_list' );
47
	} else {
48
		update_post_meta( $post_id, 'wpbo_mc_list', $list );
49
	}
50
51
	/* Save the list groups */
52
	if ( isset( $_POST['wpbo_mc_list_groups'] ) ) {
53
		update_post_meta( $post_id, 'wpbo_mc_list_groups', $_POST['wpbo_mc_list_groups'] );
54
	} else {
55
		delete_post_meta( $post_id, 'wpbo_mc_list_groups' );
56
	}
57
58
}
59
60
add_action( 'add_meta_boxes', 'wpbo_mc_mailing_list_selector' );
61
/**
62
 * Add list selector metabox to popup edit screen.
63
 *
64
 * @since  1.0.0
65
 * @return null
66
 */
67
function wpbo_mc_mailing_list_selector () {
68
	add_meta_box( 'wpbo_mc_list', __( 'Mailing List <small>(Optional)</small>', 'wpbo_mc' ), 'wpbo_mc_display_mc_list', 'wpbo-popup', 'side', 'high' );
69
}
70
71
/**
72
 * Display content of list metabox.
73
 *
74
 * @since  1.0.0
75
 * @return null
76
 */
77
function wpbo_mc_display_mc_list() {
78
	require( WPBO_PATH . 'includes/providers/mailchimp/views/metabox-list.php' );
79
}