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

Yikes_Easy_MC_bbPress_Checkbox_Class   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A output_checkbox() 0 6 2
A subscribe_from_bbpress() 0 12 2
A subscribe_from_bbpress_new_topic() 0 7 2
A subscribe_from_bbpress_new_reply() 0 7 2
1
<?php
2
/**
3
 * Handle bbPress Integration: add a checkbox for subscribers when signing up via bbPress.
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 bbPress Integration.
13
 */
14
class Yikes_Easy_MC_bbPress_Checkbox_Class extends Yikes_Easy_MC_Checkbox_Integration_Class {
15
16
	/**
17
	 * The integration type.
18
	 *
19
	 * @var string $type
20
	 */
21
	protected $type = 'bbpress_forms';
22
23
	/**
24
	 * Constructor.
25
	 */
26
	public function __construct() {
27
		add_action( 'bbp_theme_after_topic_form_subscriptions', array( $this, 'output_checkbox' ), 10 );
28
		add_action( 'bbp_theme_after_reply_form_subscription', array( $this, 'output_checkbox' ), 10 );
29
		add_action( 'bbp_theme_anonymous_form_extras_bottom', array( $this, 'output_checkbox' ), 10 );
30
		add_action( 'bbp_new_topic', array( $this, 'subscribe_from_bbpress_new_topic' ), 10, 4 );
31
		add_action( 'bbp_new_reply', array( $this, 'subscribe_from_bbpress_new_reply' ), 10, 5 );
32
	}
33
34
	/**
35
	 * Outputs a checkbox if user is not already subscribed.
36
	 */
37
	public function output_checkbox() {
38
		if ( $this->is_user_already_subscribed( $this->type ) ) {
39
			return;
40
		}
41
		echo $this->yikes_get_checkbox();
42
	}
43
44
	/**
45
	 * Subscribe the user. At this point, they chose.
46
	 *
47
	 * @param int $user_id The WP User ID.
48
	 */
49
	public function subscribe_from_bbpress( $user_id ) {
50
		$user = get_userdata( $user_id );
51
52
		if ( false === $user ) {
53
			return false;
54
		}
55
56
		$email      = $user->user_email;
57
		$merge_vars = $this->user_merge_vars( $user );
58
		$addl_vars  = apply_filters( 'yikes_mailchimp_checkbox_integration_additional_vars', array( 'user' => $user ), $this->type );
59
		$this->subscribe_user_integration( $email, $this->type, $merge_vars, $addl_vars );
60
	}
61
62
	/**
63
	 * Subscribe the user if they so chose.
64
	 *
65
	 * @param int   $topic_id        The topic's ID.
66
	 * @param int   $forum_id        The forum's ID.
67
	 * @param mixed $anonymous_data  Honestly I don't know.
68
	 * @param int   $topic_author_id The topic author's ID (WP User ID).
69
	 */
70
	public function subscribe_from_bbpress_new_topic( $topic_id, $forum_id, $anonymous_data, $topic_author_id ) {
71
		if ( false == $this->was_checkbox_checked( $this->type ) ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
72
			return;
73
		}
74
75
		$this->subscribe_from_bbpress( $topic_author_id );
76
	}
77
78
	/**
79
	 * Subscribe the user if they so chose.
80
	 *
81
	 * @param int   $reply_id        The reply's ID.
82
	 * @param int   $topic_id        The topic's ID.
83
	 * @param int   $forum_id        The forum's ID.
84
	 * @param mixed $anonymous_data  Honestly I don't know.
85
	 * @param int   $reply_author_id The topic author's ID (WP User ID).
86
	 */
87
	public function subscribe_from_bbpress_new_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author_id ) {
88
		if ( false == $this->was_checkbox_checked( $this->type ) ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
89
			return;
90
		}
91
92
		$this->subscribe_from_bbpress( $reply_author_id );
93
	}
94
}
95
$yikes_easy_mc_bbpress_checkbox_class = new Yikes_Easy_MC_bbPress_Checkbox_Class();
96