|
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( 'Auto_Load_Next_Post_Settings_Page' ) ) { |
|
18
|
|
|
|
|
19
|
|
|
abstract class Auto_Load_Next_Post_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( 'auto_load_next_post_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
|
46
|
|
|
add_action( 'auto_load_next_post_settings_' . $this->id, array( $this, 'need_help' ), 0 ); |
|
47
|
|
|
add_action( 'auto_load_next_post_sections_' . $this->id, array( $this, 'output_sections' ) ); |
|
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
|
|
|
echo '<li><a href="' . admin_url( 'options-general.php?page=auto-load-next-post-settings&tab=' . $this->id . '§ion=' . sanitize_title( $id ) ) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>'; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
echo '</ul><br class="clear" />'; |
|
149
|
|
|
} // END output_sections() |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Output the settings. |
|
153
|
|
|
* |
|
154
|
|
|
* @access public |
|
155
|
|
|
* @since 1.0.0 |
|
156
|
|
|
*/ |
|
157
|
|
|
public function output() { |
|
158
|
|
|
$settings = $this->get_settings(); |
|
159
|
|
|
|
|
160
|
|
|
Auto_Load_Next_Post_Admin_Settings::output_fields( $settings ); |
|
161
|
|
|
} // END output() |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Save settings. |
|
165
|
|
|
* |
|
166
|
|
|
* @access public |
|
167
|
|
|
* @since 1.0.0 |
|
168
|
|
|
* @version 1.6.0 |
|
169
|
|
|
* @global $current_section |
|
170
|
|
|
*/ |
|
171
|
|
|
public function save() { |
|
172
|
|
|
global $current_section; |
|
173
|
|
|
|
|
174
|
|
|
$settings = $this->get_settings(); |
|
175
|
|
|
|
|
176
|
|
|
Auto_Load_Next_Post_Admin_Settings::save_fields( $settings ); |
|
177
|
|
|
|
|
178
|
|
|
if ( $current_section ) { |
|
179
|
|
|
do_action( 'auto_load_next_post_update_options_' . $this->id . '_' . $current_section ); |
|
180
|
|
|
} |
|
181
|
|
|
} // END save() |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Displays a button above the settings header to toggle the help panel. |
|
185
|
|
|
* |
|
186
|
|
|
* The help tab does not show for theme selectors if the theme is already supported. |
|
187
|
|
|
* |
|
188
|
|
|
* @access public |
|
189
|
|
|
* @static |
|
190
|
|
|
* @since 1.5.5 |
|
191
|
|
|
* @global $current_tab |
|
192
|
|
|
*/ |
|
193
|
|
|
public function need_help() { |
|
194
|
|
|
global $current_tab; |
|
195
|
|
|
|
|
196
|
|
|
// If theme is already supported then don't show help button for theme selectors. |
|
197
|
|
|
if ( is_alnp_supported() && $current_tab == 'theme-selectors' ) { |
|
198
|
|
|
return; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
echo '<a href="#" class="need-help trigger-help" data-tab="' . $current_tab . '"><span class="sonar-dot"></span> ' . esc_html( 'Need Help?', 'auto-load-next-post' ) . '</a>'; |
|
202
|
|
|
} // END need_help() |
|
203
|
|
|
|
|
204
|
|
|
} // END class |
|
205
|
|
|
|
|
206
|
|
|
} // END if class exists. |
|
207
|
|
|
|