ALNP_Extensions   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A add_extensions_page() 0 5 1
A output() 0 21 4
1
<?php
2
/**
3
 * Auto Load Next Post Extensions class
4
 *
5
 * Displays Extensions available for Auto Load Next Post hosted via WordPress.org
6
 *
7
 * @since    1.6.0
8
 * @author   Sébastien Dumont
9
 * @category Classes
10
 * @package  Auto Load Next Post/Classes/Extensions
11
 * @license  GPL-2.0+
12
 */
13
14
// Exit if accessed directly.
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit;
17
}
18
19
if ( ! class_exists( 'ALNP_Extensions' ) ) {
20
21
	class ALNP_Extensions {
22
23
		/**
24
		 * Extensions Var
25
		 * 
26
		 * @access public
27
		 * @static
28
		 */
29
		public static $extensions;
30
31
		/**
32
		 * Initialize Extensions.
33
		 *
34
		 * @access public
35
		 */
36
		public function __construct() {
37
			$this->id    = 'extensions';
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38
			$this->label = esc_html__( 'Extensions', 'auto-load-next-post' );
0 ignored issues
show
Bug introduced by
The property label does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
40
			// Below are extensions hosted on WordPress.org
41
			self::$extensions = array(
42
				array(
43
					'slug' => 'alnp-facebook-pixel-tracking', // Facebook Pixel Tracking
44
				),
45
			);
46
47
			include_once( AUTO_LOAD_NEXT_POST_FILE_PATH . '/vendor/connekt-plugin-installer/class-connekt-plugin-installer.php'); // Plugin Installer
48
49
			add_filter( 'alnp_settings_tabs_array', array( $this, 'add_extensions_page' ), 99 );
50
			add_action( 'auto_load_next_post_settings_end', array( $this, 'output' ), 10, 2 );
51
		} // END __construct()
52
53
		/**
54
		 * Add the extensions page to the settings.
55
		 *
56
		 * @access public
57
		 * @param  array $pages
58
		 * @return array $pages
59
		 */
60
		public function add_extensions_page( $pages ) {
61
			$pages[$this->id] = $this->label;
62
63
			return $pages;
64
		} // END add_extensions_page()
65
66
		/**
67
		 * Output the extensions.
68
		 * 
69
		 * @access public
70
		 * @param  string $current_view
71
		 * @param  array  $tabs
72
		 */
73
		public function output( $current_view, $tabs ) {
74
			if ( $current_view !== 'extensions' ) {
75
				return;
76
			}
77
			?>
78
			<div class="wrap auto-load-next-post">
79
				<?php
80
				// Include settings tabs.
81
				include_once( dirname( __FILE__ ) . '/views/html-admin-tabs.php' );
82
				?>
83
				<h1 class="screen-reader-text"><?php echo esc_html( $this->label ); ?></h1>
84
85
				<?php
86
				// Load the class if it exists and Airplane Mode is disabled.
87
				if ( class_exists( 'Connekt_Plugin_Installer' ) && ! alnp_airplane_mode_enabled() ) {
88
					Connekt_Plugin_Installer::init( self::$extensions );
89
				}
90
				?>
91
			</div>
92
			<?php
93
		} // END output()
94
95
	} // END class
96
97
} // END if class
98
99
return new ALNP_Extensions();