1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Auto Load Next Post Settings - Theme Selectors |
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
|
|
|
// Exit if accessed directly. |
14
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
15
|
|
|
exit; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
if ( ! class_exists( 'ALNP_Settings_Theme_Selectors' ) ) { |
19
|
|
|
|
20
|
|
|
class ALNP_Settings_Theme_Selectors extends ALNP_Settings_Page { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor. |
24
|
|
|
* |
25
|
|
|
* @access public |
26
|
|
|
* @since 1.0.0 |
27
|
|
|
* @version 1.6.0 |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public function __construct() { |
30
|
|
|
$this->id = 'theme-selectors'; |
31
|
|
|
$this->label = esc_html__( 'Theme Selectors', 'auto-load-next-post' ); |
32
|
|
|
|
33
|
|
|
parent::__construct(); |
34
|
|
|
|
35
|
|
|
add_action( 'auto_load_next_post_settings_theme-selectors', array( __CLASS__, 'is_theme_supported' ), 0 ); |
36
|
|
|
add_action( 'auto_load_next_post_settings_theme-selectors', array( __CLASS__, 'no_theme_selectors_set' ), 0 ); |
37
|
|
|
} // END __construct() |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* This notifies the user if the active theme supports Auto Load Next Post. |
41
|
|
|
* |
42
|
|
|
* @access public |
43
|
|
|
* @static |
44
|
|
|
* @since 1.5.10 |
45
|
|
|
*/ |
46
|
|
|
public static function is_theme_supported() { |
47
|
|
|
if ( is_alnp_supported() ) { |
48
|
|
|
$plugin_supported = alnp_get_theme_support( 'plugin_support' ); |
49
|
|
|
|
50
|
|
|
// Is the theme supported by theme or plugin? |
51
|
|
|
if ( ! empty( $plugin_supported ) && $plugin_supported == 'yes' ) { |
52
|
|
|
include( dirname( AUTO_LOAD_NEXT_POST_FILE ) . '/includes/admin/views/html-notice-plugin-supported.php' ); |
53
|
|
|
} else { |
54
|
|
|
include( dirname( AUTO_LOAD_NEXT_POST_FILE ) . '/includes/admin/views/html-notice-is-supported.php' ); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} // END is_theme_supported() |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* This notifies the user if none of the required theme selectors are set. |
61
|
|
|
* |
62
|
|
|
* @access public |
63
|
|
|
* @static |
64
|
|
|
* @since 1.5.0 |
65
|
|
|
*/ |
66
|
|
|
public static function no_theme_selectors_set() { |
67
|
|
|
$set_selectors = array(); |
68
|
|
|
|
69
|
|
|
$content_container = get_option( 'auto_load_next_post_content_container' ); |
70
|
|
|
$title_selector = get_option( 'auto_load_next_post_title_selector' ); |
71
|
|
|
$navigation_container = get_option( 'auto_load_next_post_navigation_container' ); |
72
|
|
|
|
73
|
|
|
if ( ! empty( $content_container ) ) { |
74
|
|
|
$set_selectors[] = $content_container; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if ( ! empty( $title_selector ) ) { |
78
|
|
|
$set_selectors[] = $title_selector; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
if ( ! empty( $navigation_container ) ) { |
82
|
|
|
$set_selectors[] = $navigation_container; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if ( empty( $set_selectors ) || is_array( $set_selectors ) && count( $set_selectors ) < 3 ) { |
86
|
|
|
include( dirname( AUTO_LOAD_NEXT_POST_FILE ) . '/includes/admin/views/html-notice-no-theme-selectors.php' ); |
87
|
|
|
} |
88
|
|
|
} // END no_theme_selectors_set() |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get settings array. |
92
|
|
|
* |
93
|
|
|
* @access public |
94
|
|
|
* @since 1.0.0 |
95
|
|
|
* @version 1.6.0 |
96
|
|
|
* @global int $blog_id |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function get_settings() { |
100
|
|
|
global $blog_id; |
101
|
|
|
|
102
|
|
|
$settings = array(); |
103
|
|
|
|
104
|
|
|
$settings[] = array( |
105
|
|
|
'title' => esc_html__( 'Theme Selectors', 'auto-load-next-post' ), |
106
|
|
|
'type' => 'title', |
107
|
|
|
'desc' => sprintf( esc_html__( 'Here you set the theme selectors below according to your active theme. All are required for %s to work.', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ), |
108
|
|
|
'id' => 'theme_selectors_options' |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
// Provide the theme customizer option if theme is not already supported. |
112
|
|
|
if ( ! is_alnp_supported() ) { |
113
|
|
|
$query = array( |
114
|
|
|
'autofocus[panel]' => 'alnp', |
115
|
|
|
'autofocus[section]' => 'auto_load_next_post_theme_selectors', |
116
|
|
|
'url' => alnp_get_random_page_permalink(), |
117
|
|
|
'return' => add_query_arg( array( 'page' => 'auto-load-next-post', 'view' => 'theme-selectors' ), admin_url( 'options-general.php' ) ), |
118
|
|
|
); |
119
|
|
|
$customizer_link = add_query_arg( $query, admin_url( 'customize.php' ) ); |
120
|
|
|
|
121
|
|
|
$settings[] = array( |
122
|
|
|
'title' => esc_html__( 'Theme Customizer', 'auto-load-next-post' ), |
123
|
|
|
'desc' => esc_html__( 'Use the theme customizer to enter the theme selectors while you inspect the theme.', 'auto-load-next-post' ), |
124
|
|
|
'id' => 'auto_load_next_post_customizer', |
125
|
|
|
'value' => esc_html__( 'Open Theme Customizer', 'auto-load-next-post' ), |
126
|
|
|
'url' => $customizer_link, |
127
|
|
|
'type' => 'button' |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
// Defines input field status |
132
|
|
|
$container_readonly = 'no'; |
133
|
|
|
$post_title_readonly = 'no'; |
134
|
|
|
$post_navigation_readonly = 'no'; |
135
|
|
|
$comments_container_readonly = 'no'; |
136
|
|
|
|
137
|
|
|
// Defines if we should show default selector. |
138
|
|
|
$container_default = ''; |
139
|
|
|
$post_title_default = ''; |
140
|
|
|
$post_navigation_default = ''; |
141
|
|
|
$comments_container_default = ''; |
142
|
|
|
|
143
|
|
|
// Checks if the Content Container selector has been set by theme support. |
144
|
|
View Code Duplication |
if ( ! empty( alnp_get_theme_support( 'content_container' ) ) ) { |
145
|
|
|
$container_readonly = 'yes'; |
146
|
|
|
} else { |
147
|
|
|
$container_default = sprintf( __( 'Default: %s', 'auto-load-next-post' ), '<code>main.site-main</code>' ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$settings[] = array( |
151
|
|
|
'title' => esc_html__( 'Content Container', 'auto-load-next-post' ), |
152
|
|
|
'desc' => sprintf( __( 'The primary container where the post content is loaded in. %s', 'auto-load-next-post' ), $container_default ), |
153
|
|
|
'id' => 'auto_load_next_post_content_container', |
154
|
|
|
'default' => 'main.site-main', |
155
|
|
|
'placeholder' => sprintf( esc_html__( 'e.g. %s', 'auto-load-next-post' ), 'main.site-main' ), |
156
|
|
|
'readonly' => $container_readonly, |
157
|
|
|
'type' => 'text', |
158
|
|
|
'css' => 'min-width:300px;', |
159
|
|
|
'class' => 'required', |
160
|
|
|
'autoload' => false |
161
|
|
|
); |
162
|
|
|
|
163
|
|
|
// Checks if the Post Title selector has been set by theme support. |
164
|
|
View Code Duplication |
if ( ! empty( alnp_get_theme_support( 'title_selector' ) ) ) { |
165
|
|
|
$post_title_readonly = 'yes'; |
166
|
|
|
} else { |
167
|
|
|
$post_title_default = sprintf( __( 'Default: %s', 'auto-load-next-post' ), '<code>h1.entry-title</code>' ); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
$settings[] = array( |
171
|
|
|
'title' => esc_html__( 'Post Title', 'auto-load-next-post' ), |
172
|
|
|
'desc' => sprintf( __( 'Used to identify which article the user is reading and track should Google Analytics or other analytics be enabled. %s', 'auto-load-next-post' ), $post_title_default ), |
173
|
|
|
'id' => 'auto_load_next_post_title_selector', |
174
|
|
|
'default' => 'h1.entry-title', |
175
|
|
|
'placeholder' => sprintf( esc_html__( 'e.g. %s', 'auto-load-next-post' ), 'h1.entry-title' ), |
176
|
|
|
'readonly' => $post_title_readonly, |
177
|
|
|
'type' => 'text', |
178
|
|
|
'css' => 'min-width:300px;', |
179
|
|
|
'class' => 'required', |
180
|
|
|
'autoload' => false |
181
|
|
|
); |
182
|
|
|
|
183
|
|
|
// Checks if the Post Navigation selector has been set by theme support. |
184
|
|
View Code Duplication |
if ( ! empty( alnp_get_theme_support( 'navigation_container' ) ) ) { |
185
|
|
|
$post_navigation_readonly = 'yes'; |
186
|
|
|
} else { |
187
|
|
|
$post_navigation_default = sprintf( __( 'Default: %s', 'auto-load-next-post' ), '<code>nav.post-navigation</code>' ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
$settings[] = array( |
191
|
|
|
'title' => esc_html__( 'Post Navigation', 'auto-load-next-post' ), |
192
|
|
|
'desc' => sprintf( __( 'Used to identify which post to load next if any. %s', 'auto-load-next-post' ), $post_navigation_default ), |
193
|
|
|
'id' => 'auto_load_next_post_navigation_container', |
194
|
|
|
'default' => 'nav.post-navigation', |
195
|
|
|
'placeholder' => sprintf( esc_html__( 'e.g. %s', 'auto-load-next-post' ), 'nav.post-navigation' ), |
196
|
|
|
'readonly' => $post_navigation_readonly, |
197
|
|
|
'type' => 'text', |
198
|
|
|
'css' => 'min-width:300px;', |
199
|
|
|
'class' => 'required', |
200
|
|
|
'autoload' => false |
201
|
|
|
); |
202
|
|
|
|
203
|
|
|
// Checks if the Comments Container selector has been set by theme support. |
204
|
|
View Code Duplication |
if ( ! empty( alnp_get_theme_support( 'comments_container' ) ) ) { |
205
|
|
|
$comments_container_readonly = 'yes'; |
206
|
|
|
} else { |
207
|
|
|
$comments_container_default = sprintf( __( 'Default: %s', 'auto-load-next-post' ), '<code>div#comments</code>' ); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
$settings[] = array( |
211
|
|
|
'title' => esc_html__( 'Comments Container', 'auto-load-next-post' ), |
212
|
|
|
'desc' => sprintf( __( 'Used to remove comments if enabled under %1$sMisc%2$s settings. %3$s', 'auto-load-next-post' ), '<strong><a href="' . add_query_arg( array( 'page' => 'auto-load-next-post', 'view' => 'misc' ), get_admin_url( $blog_id, 'options-general.php' ) ) . '">', '</a></strong>', $comments_container_default ), |
213
|
|
|
'id' => 'auto_load_next_post_comments_container', |
214
|
|
|
'default' => 'div#comments', |
215
|
|
|
'placeholder' => sprintf( esc_html__( 'e.g. %s', 'auto-load-next-post' ), 'div#comments' ), |
216
|
|
|
'readonly' => $comments_container_readonly, |
217
|
|
|
'type' => 'text', |
218
|
|
|
'css' => 'min-width:300px;', |
219
|
|
|
'autoload' => false |
220
|
|
|
); |
221
|
|
|
|
222
|
|
|
$settings[] = array( |
223
|
|
|
'type' => 'sectionend', |
224
|
|
|
'id' => 'theme_selectors_options' |
225
|
|
|
); |
226
|
|
|
|
227
|
|
|
return apply_filters( 'alnp_selectors_settings', $settings ); |
228
|
|
|
} // END get_settings() |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Output the settings. |
232
|
|
|
* |
233
|
|
|
* @access public |
234
|
|
|
* @since 1.4.10 |
235
|
|
|
*/ |
236
|
|
|
public function output() { |
237
|
|
|
$settings = $this->get_settings(); |
238
|
|
|
|
239
|
|
|
ALNP_Admin_Settings::output_fields( $settings ); |
240
|
|
|
} // END output() |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Save settings. |
244
|
|
|
* |
245
|
|
|
* @access public |
246
|
|
|
* @since 1.0.0 |
247
|
|
|
* @version 1.5.0 |
248
|
|
|
*/ |
249
|
|
|
public function save() { |
250
|
|
|
$settings = $this->get_settings(); |
251
|
|
|
|
252
|
|
|
ALNP_Admin_Settings::save_fields( $settings ); |
253
|
|
|
} // END save() |
254
|
|
|
|
255
|
|
|
} // END class |
256
|
|
|
|
257
|
|
|
} // END if class exists |
258
|
|
|
|
259
|
|
|
return new ALNP_Settings_Theme_Selectors(); |
260
|
|
|
|