ALNP_Settings_Page   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 193
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 193
rs 10
c 0
b 0
f 0
wmc 19
lcom 1
cbo 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A get_id() 0 3 1
A get_label() 0 3 1
A add_settings_page() 0 5 1
A add_menu_page() 0 5 1
A get_settings() 0 3 1
A get_sections() 0 3 1
B output_sections() 0 25 6
A output() 0 5 1
A save() 0 11 2
A need_help() 0 10 3
1
<?php
2
/**
3
 * Auto Load Next Post Settings Page
4
 *
5
 * @since    1.0.0
6
 * @version  1.6.0
7
 * @author   Sébastien Dumont
8
 * @category Admin
9
 * @package  Auto Load Next Post/Admin/Settings
10
 * @license  GPL-2.0+
11
 */
12
13
if ( ! defined('ABSPATH') ) {
14
	exit; // Exit if accessed directly.
15
}
16
17
if ( ! class_exists( 'ALNP_Settings_Page' ) ) {
18
19
	abstract class ALNP_Settings_Page {
20
21
		/**
22
		 * Setting page id.
23
		 *
24
		 * @access protected
25
		 * @var    string $id
26
		 */
27
		protected $id = '';
28
29
		/**
30
		 * Setting page label.
31
		 *
32
		 * @access protected
33
		 * @var    string $label
34
		 */
35
		protected $label = '';
36
37
		/**
38
		 * Constructor.
39
		 *
40
		 * @access  public
41
		 * @since   1.4.10
42
		 * @version 1.6.0
43
		 */
44
		public function __construct() {
45
			add_filter( 'alnp_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
46
			add_action( 'auto_load_next_post_sections_' . $this->id, array( $this, 'output_sections' ) );
47
			add_action( 'auto_load_next_post_settings_' . $this->id, array( $this, 'need_help' ), 5 );
48
			add_action( 'auto_load_next_post_settings_' . $this->id, array( $this, 'output' ), 10 );
49
			add_action( 'auto_load_next_post_settings_save_' . $this->id, array( $this, 'save' ) );
50
		}
51
52
		/**
53
		 * Get settings page ID.
54
		 *
55
		 * @access public
56
		 * @since  1.4.10
57
		 * @return string
58
		 */
59
		public function get_id() {
60
			return $this->id;
61
		} // END get_id()
62
63
		/**
64
		 * Get settings page label.
65
		 *
66
		 * @access public
67
		 * @since  1.4.10
68
		 * @return string
69
		 */
70
		public function get_label() {
71
			return $this->label;
72
		} // END get_label()
73
74
		/**
75
		 * Add this page to settings.
76
		 *
77
		 * @access public
78
		 * @since  1.0.0
79
		 * @param  array $pages
80
		 * @return array $pages
81
		 */
82
		public function add_settings_page( $pages ) {
83
			$pages[$this->id] = $this->label;
84
85
			return $pages;
86
		} // END add_settings_page()
87
88
		/**
89
		 * Add this settings page to plugin menu.
90
		 *
91
		 * @access public
92
		 * @since  1.0.0
93
		 * @param  array $pages
94
		 * @return array $pages
95
		 */
96
		public function add_menu_page( $pages ) {
97
			$pages[$this->id] = $this->label;
98
99
			return $pages;
100
		} // END add_menu_page()
101
102
		/**
103
		 * Get settings array
104
		 *
105
		 * @access public
106
		 * @since  1.0.0
107
		 * @return array
108
		 */
109
		public function get_settings() {
110
			return array();
111
		} // END get_settings()
112
113
		/**
114
		 * Get sections.
115
		 *
116
		 * @access public
117
		 * @since  1.6.0
118
		 * @return array
119
		 */
120
		public function get_sections() {
121
			return array();
122
		} // END get_sections()
123
124
		/**
125
		 * Output sections.
126
		 *
127
		 * @access public
128
		 * @since  1.6.0
129
		 * @global $current_section
130
		 */
131
		public function output_sections() {
132
			global $current_section;
133
134
			$sections = $this->get_sections();
135
136
			if ( empty( $sections ) || 1 === sizeof( $sections ) ) {
137
				return;
138
			}
139
140
			echo '<ul class="subsubsub">';
141
142
			$array_keys = array_keys( $sections );
143
144
			foreach ( $sections as $id => $label ) {
145
				$url = add_query_arg( array(
146
					'page'    => 'auto-load-next-post',
147
					'view'    => $this->id,
148
					'section' => sanitize_title( $id ),
149
				), admin_url( 'options-general.php' ) );
150
151
				echo '<li><a href="' . $url . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
152
			}
153
154
			echo '</ul><br class="clear" />';
155
		} // END output_sections()
156
157
		/**
158
		 * Output the settings.
159
		 *
160
		 * @access public
161
		 * @since  1.0.0
162
		 */
163
		public function output() {
164
			$settings = $this->get_settings();
165
166
			ALNP_Admin_Settings::output_fields( $settings );
167
		} // END output()
168
169
		/**
170
		 * Save settings.
171
		 *
172
		 * @access  public
173
		 * @since   1.0.0
174
		 * @version 1.6.0
175
		 * @global  $current_section
176
		 */
177
		public function save() {
178
			global $current_section;
179
180
			$settings = $this->get_settings();
181
182
			ALNP_Admin_Settings::save_fields( $settings );
183
184
			if ( $current_section ) {
185
				do_action( 'auto_load_next_post_update_options_' . $this->id . '_' . $current_section );
186
			}
187
		} // END save()
188
189
		/**
190
		 * Displays a button above the settings header to toggle the help panel.
191
		 * 
192
		 * The help button does not show for theme selectors if the theme is already supported.
193
		 * 
194
		 * @access  public
195
		 * @static
196
		 * @since   1.5.5
197
		 * @version 1.6.0
198
		 * @global  $current_view
199
		 */
200
		public function need_help() {
201
			global $current_view;
202
203
			// If theme is already supported then don't show help button for theme selectors.
204
			if ( is_alnp_supported() && $current_view == 'theme-selectors' ) {
205
				return;
206
			}
207
208
			echo '<a href="#" class="need-help trigger-help" data-tab="' . $current_view . '"><span class="sonar-dot"></span> ' . esc_html__( 'Need Help?', 'auto-load-next-post' ) . '</a>';
209
		} // END need_help()
210
211
	} // END class
212
213
} // END if class exists.
214