Completed
Push — staging ( 99a729...9693fc )
by
unknown
19:21
created

Yikes_Easy_MC_BuddyPress_Checkbox_Class   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A output_checkbox() 0 6 2
A subscribe_from_buddypress_form() 0 16 3
1
<?php
2
/**
3
 * Handle BuddyPress Integration: add a checkbox for subscribers when signing up via BuddyPress.
4
 *
5
 * @since 6.0.0
6
 */
7
8
// Prevent direct access to the file.
9
defined( 'ABSPATH' ) || die( esc_html_e( "Whoops, you shouldn't be accessing this file directly. Abort!", 'yikes-inc-easy-mailchimp-extender' ) );
10
11
/**
12
 * Handle BuddyPress Integration.
13
 */
14
class Yikes_Easy_MC_BuddyPress_Checkbox_Class extends Yikes_Easy_MC_Checkbox_Integration_Class {
15
16
	/**
17
	 * The integration type.
18
	 *
19
	 * @var string $type
20
	 */
21
	protected $type = 'buddypress_form';
22
23
	/**
24
	 * Constructor.
25
	 */
26
	public function __construct() {
27
		add_action( 'bp_before_registration_submit_buttons', array( $this, 'output_checkbox' ), 20 );
28
		add_action( 'bp_core_signup_user', array( $this, 'subscribe_from_buddypress_form' ), 10, 4 );
29
	}
30
31
	/**
32
	 * Outputs a checkbox if user is not already subscribed.
33
	 */
34
	public function output_checkbox() {
35
		if ( $this->is_user_already_subscribed( $this->type ) ) {
36
			return;
37
		}
38
		echo $this->yikes_get_checkbox();
39
	}
40
41
	/**
42
	 * Subscribe the user if they so chose.
43
	 *
44
	 * @param int    $user_id       The user's ID.
45
	 * @param string $user_login    The user's login.
46
	 * @param string $user_password The user's password.
47
	 * @param string $user_email    The user's email.
48
	 */
49
	public function subscribe_from_buddypress_form( $user_id, $user_login, $user_password, $user_email ) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_login 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 $user_password 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 $user_email 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...
50
		if ( false === $this->was_checkbox_checked( $this->type ) ) {
51
			return;
52
		}
53
54
		$user = get_userdata( $user_id );
55
56
		if ( false === $user ) {
57
			return false;
58
		}
59
60
		$email      = $user->user_email;
61
		$merge_vars = $this->user_merge_vars( $user );
62
		$addl_vars  = apply_filters( 'yikes_mailchimp_checkbox_integration_additional_vars', array( 'user' => $user ), $this->type );
63
		$this->subscribe_user_integration( $email, $this->type, $merge_vars, $addl_vars );
64
	}
65
}
66
$yikes_easy_mc_buddypress_checkbox_class = new Yikes_Easy_MC_BuddyPress_Checkbox_Class();
67