Completed
Branch master (8d1f99)
by
unknown
01:57
created

Auto_Load_Next_Post_Extensions::output()   B

Complexity

Conditions 9
Paths 33

Size

Total Lines 26

Duplication

Lines 3
Ratio 11.54 %

Importance

Changes 0
Metric Value
cc 9
nc 33
nop 2
dl 3
loc 26
rs 8.0555
c 0
b 0
f 0
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( 'Auto_Load_Next_Post_Extensions' ) ) {
20
21
	class Auto_Load_Next_Post_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( 'auto_load_next_post_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_tab
71
		 * @param array  $tabs
72
		 */
73
		public function output( $current_tab, $tabs ) {
74
			if ( $current_tab !== 'extensions' ) {
75
				return;
76
			}
77
78
			$tab_exists        = isset( $tabs[ $current_tab ] ) || has_action( 'auto_load_next_post_sections_' . $current_tab ) || has_action( 'auto_load_next_post_settings_' . $current_tab ) || has_action( 'auto_load_next_post_settings_tabs_' . $current_tab );
0 ignored issues
show
Unused Code introduced by
$tab_exists is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
79
			$current_tab_label = isset( $tabs[ $current_tab ] ) ? $tabs[ $current_tab ] : '';
80
			?>
81
			<div class="wrap auto-load-next-post">
82
				<nav class="nav-tab-wrapper">
83
					<?php
84 View Code Duplication
					foreach ( $tabs as $slug => $label ) {
85
						echo '<a href="' . esc_html( admin_url( 'options-general.php?page=auto-load-next-post-settings&tab=' . esc_attr( $slug ) ) ) . '" class="nav-tab ' . ( $current_tab === $slug ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>';
86
					}
87
88
					do_action( 'auto_load_next_post_settings_tabs' );
89
					?>
90
				</nav>
91
				<h1 class="screen-reader-text"><?php echo esc_html( $current_tab_label ); ?></h1>
92
			</div>
93
94
			<?php
95
			if ( class_exists( 'Connekt_Plugin_Installer' ) ) {
96
				Connekt_Plugin_Installer::init( self::$extensions );
97
			}
98
		} // END output()
99
100
	} // END class
101
102
} // END if class
103
104
return new Auto_Load_Next_Post_Extensions();