Completed
Push — fix/product-review-comment-end... ( fcd4b9...b9b2bf )
by Justin
174:21 queued 168:12
created

Jetpack_Affiliate   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A init() 0 6 2
A get_affiliate_code() 0 10 1
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	// Exit if accessed directly
5
	exit;
6
}
7
8
/**
9
 * This class introduces routines to get an affiliate code, that might be obtained from:
10
 * - an `jetpack_affiliate_code` option in the WP database
11
 * - an affiliate code returned by a filter bound to the `jetpack_affiliate_code` filter hook
12
 *
13
 * @since 6.9.0
14
 */
15
class Jetpack_Affiliate {
16
17
	/**
18
	 * @since 6.9.0
19
	 * @var Jetpack_Affiliate This class instance.
20
	 **/
21
	private static $instance = null;
22
23
	private function __construct() {
24
		if ( Jetpack::is_development_mode() ) {
25
			return;
26
		}
27
	}
28
29
	/**
30
	 * Initializes the class or returns the singleton
31
	 *
32
	 * @since 6.9.0
33
	 *
34
	 * @return Jetpack_Affiliate | false
35
	 */
36
	public static function init() {
37
		if ( is_null( self::$instance ) ) {
38
			self::$instance = new Jetpack_Affiliate;
39
		}
40
		return self::$instance;
41
	}
42
43
	/**
44
	 * Returns the affiliate code from database after filtering it.
45
	 *
46
	 * @since 6.9.0
47
	 *
48
	 * @return string The affiliate code.
49
	 */
50
	public function get_affiliate_code() {
51
		/**
52
		 * Allow to filter the affiliate code.
53
		 *
54
		 * @since 6.9.0
55
		 *
56
		 * @param string $aff_code The affiliate code, blank by default.
57
		 */
58
		return apply_filters( 'jetpack_affiliate_code', get_option( 'jetpack_affiliate_code', '' ) );
59
	}
60
}
61
62
add_action( 'init', array( 'Jetpack_Affiliate', 'init' ) );
63