PluginProbe
Posts Table with Search & Sort / 1.3.2
Posts Table with Search & Sort v1.3.2
1.4.13 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2 1.3 1.3.1 1.3.1-v2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 40 releases
posts-data-table / src / Admin / Settings_Page.php

Settings_Page.php in Posts Table with Search & Sort 1.3.2, at src/Admin/Settings_Page.php

378 lines 18.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Barn2\Plugin\Posts_Table_Search_Sort\Admin;
3
4 use Barn2\PTS_Lib\Util,
5 Barn2\PTS_Lib\Registerable,
6 Barn2\PTS_Lib\Admin\Settings_API_Helper,
7 Barn2\Plugin\Posts_Table_Search_Sort\Simple_Posts_Table,
8 Barn2\Plugin\Posts_Table_Search_Sort\Settings;
9
10 /**
11 * This class handles our plugin settings page in the admin.
12 *
13 * @package Barn2\posts-table-search-sort
14 * @author Barn2 Plugins <support@barn2.co.uk>
15 * @license GPL-3.0
16 * @copyright Barn2 Media Ltd
17 */
18 class Settings_Page implements Registerable {
19
20 const MENU_SLUG = 'posts_table_search_sort';
21 const OPTION_GROUP = 'posts_table_search_sort_main';
22
23 private static $readonly_settings = array(
24 'post_type',
25 'image_size',
26 'lightbox',
27 'shortcodes',
28 'excerpt_length',
29 'links',
30 'lazy_load',
31 'post_limit',
32 'cache',
33 'filters',
34 'page_length',
35 'search_box',
36 'totals',
37 'pagination',
38 'paging_type',
39 'reset_button',
40 );
41
42 public function register() {
43 add_action( 'admin_menu', array( $this, 'add_settings_page' ) );
44 add_action( 'admin_init', array( $this, 'register_settings' ) );
45 }
46
47 public function add_settings_page() {
48 add_options_page(
49 __( 'Posts Table With Search &amp; Sort', 'posts-data-table' ),
50 __( 'Posts Table With Search &amp; Sort', 'posts-data-table' ),
51 'manage_options',
52 self::MENU_SLUG,
53 array( $this, 'render_settings_page' )
54 );
55 }
56
57 public function render_settings_page() {
58 ?>
59 <div class="wrap">
60 <h1><?php _e( 'Posts Table with Search and Sort', 'posts-data-table' ); ?></h1>
61 <form action="options.php" method="post">
62 <?php
63 // Output the hidden form fields (_wpnonce, etc)
64 settings_fields( self::OPTION_GROUP );
65
66 // Output the sections and their settings
67 do_settings_sections( self::MENU_SLUG );
68 ?>
69 <p class="submit">
70 <input name="Submit" type="submit" name="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Changes', 'posts-data-table' ); ?>" />
71 </p>
72 </form>
73 </div>
74 <?php
75 }
76
77 public function register_settings() {
78 // Register the settings
79 register_setting( self::OPTION_GROUP, Settings::TABLE_ARGS_SETTING, array(
80 'type' => 'string', // array type not supported, so just use string
81 'description' => 'Posts Table with Search and Sort - table defaults',
82 'sanitize_callback' => '\Barn2\Plugin\Posts_Table_Search_Sort\Settings::sanitize_table_args'
83 ) );
84
85 $default_args = Simple_Posts_Table::get_defaults();
86 $args_setting = Settings::TABLE_ARGS_SETTING;
87
88 // Selecting posts
89 Settings_API_Helper::add_settings_section(
90 'ptss_post_selection', self::MENU_SLUG, __( 'Posts selection', 'posts-data-table' ), array( $this, 'section_description_selecting_posts' ),
91 $this->mark_readonly_settings( array(
92 array(
93 'id' => $args_setting . '[post_type]',
94 'title' => __( 'Post type', 'posts-data-table' ),
95 'type' => 'select',
96 'desc' => __( 'The default post type for your tables.', 'posts-data-table' ),
97 'options' => array( 'post' ),
98 'default' => 'post'
99 ),
100 ) )
101 );
102
103 // Table content
104 Settings_API_Helper::add_settings_section(
105 'ptss_content', self::MENU_SLUG, __( 'Table content', 'posts-data-table' ), array( $this, 'section_description_table_content' ),
106 $this->mark_readonly_settings( array(
107 array(
108 'id' => $args_setting . '[columns]',
109 'title' => __( 'Columns', 'posts-data-table' ),
110 'type' => 'text',
111 'desc' => __( 'The columns displayed in your table (comma-separated). ', 'posts-data-table' ),
112 'default' => $default_args['columns'],
113 ),
114 array(
115 'id' => $args_setting . '[image_size]',
116 'title' => __( 'Image size', 'posts-data-table' ),
117 'type' => 'text',
118 'desc' => __( "W x H in pixels. Sets the image size when using the 'image' column. ", 'posts-data-table' ) . Util::barn2_link( 'kb/ptp-column-widths/#image-size' ),
119 'default' => 'thumbnail',
120 ),
121 array(
122 'id' => $args_setting . '[lightbox]',
123 'title' => __( 'Image lightbox', 'posts-data-table' ),
124 'type' => 'checkbox',
125 'label' => __( 'Display featured images in a lightbox when opened', 'posts-data-table' ),
126 'default' => true,
127 ),
128 array(
129 'title' => __( 'Shortcodes', 'posts-data-table' ),
130 'type' => 'checkbox',
131 'id' => $args_setting . '[shortcodes]',
132 'label' => __( 'Display shortcodes, HTML and other formatting inside the table content', 'posts-data-table' ),
133 'default' => true
134 ),
135 array(
136 'id' => $args_setting . '[content_length]',
137 'title' => __( 'Content length', 'posts-data-table' ),
138 'type' => 'number',
139 'class' => 'small-text',
140 'suffix' => __( 'words', 'posts-data-table' ),
141 'desc' => __( 'Enter -1 to show the full post content.', 'posts-data-table' ),
142 'default' => $default_args['content_length'],
143 'custom_attributes' => array(
144 'min' => -1
145 )
146 ),
147 array(
148 'id' => $args_setting . '[excerpt_length]',
149 'title' => __( 'Excerpt length', 'posts-data-table' ),
150 'type' => 'number',
151 'class' => 'small-text',
152 'suffix' => __( 'words', 'posts-data-table' ),
153 'desc' => __( 'Enter -1 to show the full excerpt.', 'posts-data-table' ),
154 'default' => 15,
155 'custom_attributes' => array(
156 'min' => -1
157 )
158 ),
159 array(
160 'id' => $args_setting . '[links]',
161 'title' => __( 'Links', 'posts-data-table' ),
162 'type' => 'text',
163 'desc' => __( 'Display links to the single post page, category, tag, or term archive. ', 'posts-data-table' ) . Util::barn2_link( 'kb/links-posts-table/' ),
164 'default' => 'all',
165 )
166 ) )
167 );
168
169 // Loading posts
170 Settings_API_Helper::add_settings_section(
171 'ptss_loading', self::MENU_SLUG, __( 'Table loading', 'posts-data-table' ), '__return_false',
172 $this->mark_readonly_settings( array(
173 array(
174 'title' => __( 'Lazy load', 'posts-data-table' ),
175 'type' => 'checkbox',
176 'id' => $args_setting . '[lazy_load]',
177 'label' => __( 'Load the posts one page at a time', 'posts-data-table' ),
178 'desc' => sprintf( __( 'Enable this if you have many posts or experience slow page load times. ', 'posts-data-table' ) ) . Util::barn2_link( 'kb/posts-table-lazy-load/' ),
179 'default' => false,
180 ),
181 array(
182 'title' => __( 'Post limit', 'posts-data-table' ),
183 'type' => 'number',
184 'id' => $args_setting . '[post_limit]',
185 'desc' => __( 'The maximum (total) number of posts to display in one table.', 'posts-data-table' ),
186 'default' => 500,
187 'class' => 'small-text',
188 'custom_attributes' => array(
189 'min' => -1
190 )
191 ),
192 array(
193 'title' => __( 'Posts per page', 'posts-data-table' ),
194 'type' => 'number',
195 'id' => $args_setting . '[rows_per_page]',
196 'desc' => __( 'The number of posts per page of results. Enter -1 to display all posts on one page.', 'posts-data-table' ),
197 'default' => $default_args['rows_per_page'],
198 'custom_attributes' => array(
199 'min' => -1
200 )
201 ),
202 array(
203 'title' => __( 'Caching', 'posts-data-table' ),
204 'type' => 'checkbox',
205 'id' => $args_setting . '[cache]',
206 'label' => __( 'Cache table contents to improve load time', 'posts-data-table' ),
207 'default' => false
208 )
209 ) )
210 );
211
212 // Sorting
213 $sort_columns = wp_list_pluck( Simple_Posts_Table::get_column_defaults(), 'heading' );
214
215 Settings_API_Helper::add_settings_section(
216 'ptss_sorting', self::MENU_SLUG, __( 'Sorting', 'posts-data-table' ), '__return_false',
217 $this->mark_readonly_settings( array(
218 array(
219 'title' => __( 'Sort by', 'posts-data-table' ),
220 'type' => 'select',
221 'id' => $args_setting . '[sort_by]',
222 'options' => $sort_columns,
223 'desc' => __( 'The initial sort order applied to the table. ', 'posts-data-table' ),
224 'default' => $default_args['sort_by']
225 ),
226 array(
227 'title' => __( 'Sort direction', 'posts-data-table' ),
228 'type' => 'select',
229 'id' => $args_setting . '[sort_order]',
230 'options' => array(
231 '' => __( 'Automatic', 'posts-data-table' ),
232 'asc' => __( 'Ascending (A to Z, 1 to 99)', 'posts-data-table' ),
233 'desc' => __( 'Descending (Z to A, 99 to 1)', 'posts-data-table' )
234 ),
235 'default' => $default_args['sort_order']
236 )
237 ) )
238 );
239
240 // Table controls
241 Settings_API_Helper::add_settings_section(
242 'ptss_controls', self::MENU_SLUG, __( 'Table controls', 'posts-data-table' ), '__return_false',
243 $this->mark_readonly_settings( array(
244 array(
245 'title' => __( 'Search filters', 'posts-data-table' ),
246 'type' => 'select',
247 'id' => $args_setting . '[filters]',
248 'options' => array(
249 'false' => __( 'Disabled', 'posts-data-table' ),
250 'true' => __( 'Show based on columns in table', 'posts-data-table' ),
251 'custom' => __( 'Custom', 'posts-data-table' )
252 ),
253 'desc' => __( 'Dropdown lists to filter the table by category, tag, attribute, or custom taxonomy. ', 'posts-data-table' ) . Util::barn2_link( 'kb/posts-table-filters/' ),
254 'default' => true,
255 ),
256 array(
257 'title' => __( 'Page length', 'posts-data-table' ),
258 'type' => 'select',
259 'id' => $args_setting . '[page_length]',
260 'options' => array(
261 'top' => __( 'Above table', 'posts-data-table' ),
262 'bottom' => __( 'Below table', 'posts-data-table' ),
263 'both' => __( 'Above and below table', 'posts-data-table' ),
264 'false' => __( 'Hidden', 'posts-data-table' )
265 ),
266 'desc' => __( "The position of the 'Show [x] entries' dropdown list.", 'posts-data-table' ),
267 'default' => 'top'
268 ),
269 array(
270 'title' => __( 'Search box', 'posts-data-table' ),
271 'type' => 'select',
272 'id' => $args_setting . '[search_box]',
273 'options' => array(
274 'top' => __( 'Above table', 'posts-data-table' ),
275 'bottom' => __( 'Below table', 'posts-data-table' ),
276 'both' => __( 'Above and below table', 'posts-data-table' ),
277 'false' => __( 'Hidden', 'posts-data-table' )
278 ),
279 'default' => 'top'
280 ),
281 array(
282 'title' => __( 'Totals', 'posts-data-table' ),
283 'type' => 'select',
284 'id' => $args_setting . '[totals]',
285 'options' => array(
286 'top' => __( 'Above table', 'posts-data-table' ),
287 'bottom' => __( 'Below table', 'posts-data-table' ),
288 'both' => __( 'Above and below table', 'posts-data-table' ),
289 'false' => __( 'Hidden', 'posts-data-table' )
290 ),
291 'desc' => __( "The position of the post totals, e.g. 'Showing 1 to 5 of 10 entries'.", 'posts-data-table' ),
292 'default' => 'bottom'
293 ),
294 array(
295 'title' => __( 'Pagination buttons', 'posts-data-table' ),
296 'type' => 'select',
297 'id' => $args_setting . '[pagination]',
298 'options' => array(
299 'top' => __( 'Above table', 'posts-data-table' ),
300 'bottom' => __( 'Below table', 'posts-data-table' ),
301 'both' => __( 'Above and below table', 'posts-data-table' ),
302 'false' => __( 'Hidden', 'posts-data-table' )
303 ),
304 'desc' => __( 'The position of the paging buttons which scroll between results.', 'posts-data-table' ),
305 'default' => 'bottom'
306 ),
307 array(
308 'title' => __( 'Pagination type', 'posts-data-table' ),
309 'type' => 'select',
310 'id' => $args_setting . '[paging_type]',
311 'options' => array(
312 'numbers' => __( 'Numbers only', 'posts-data-table' ),
313 'simple' => __( 'Prev|Next', 'posts-data-table' ),
314 'simple_numbers' => __( 'Prev|Next + Numbers', 'posts-data-table' ),
315 'full' => __( 'Prev|Next|First|Last', 'posts-data-table' ),
316 'full_numbers' => __( 'Prev|Next|First|Last + Numbers', 'posts-data-table' )
317 ),
318 'default' => 'simple_numbers'
319 ),
320 array(
321 'title' => __( 'Reset button', 'posts-data-table' ),
322 'type' => 'checkbox',
323 'id' => $args_setting . '[reset_button]',
324 'label' => __( 'Show a reset button above the table', 'posts-data-table' ),
325 'default' => false
326 )
327 ) )
328 );
329 }
330
331 public function mark_readonly_settings( $settings ) {
332 foreach ( $settings as &$setting ) {
333 $subkey = preg_filter( '/^[\w\[\]]+\[(\w+)\]$/', '$1', $setting['id'] );
334
335 if ( $subkey && false !== array_search( $subkey, self::$readonly_settings ) ) {
336 $setting['field_class'] = 'readonly';
337 $setting['custom_attributes'] = array(
338 'disabled' => 'disabled'
339 );
340
341 $setting['title'] = $setting['title'] .
342 sprintf( '<span class="pro-version">%s</span>', Util::barn2_link( 'wordpress-plugins/posts-table-pro/', __( 'Pro version only', 'posts-data-table' ), true ) );
343 }
344 }
345
346 return $settings;
347 }
348
349 public function section_description_selecting_posts() {
350 ?>
351 <p>
352 <?php
353 printf(
354 __( 'Posts tables display all published posts for the selected post type. To restrict the posts by category, tag, author, etc, set the relevant option in the [posts_table] shortcode. See the %splugin description%s for details.', 'posts-data-table' ),
355 '<a href="' . esc_url( 'https://wordpress.org/plugins/posts-data-table/#description-header' ) . '" target="_blank">',
356 '</a>'
357 );
358 ?>
359 </p>
360 <?php
361 }
362
363 public function section_description_table_content() {
364 ?>
365 <p>
366 <?php
367 printf(
368 __( 'You can override these options by setting the relevant option in the [posts_table] shortcode. See the %splugin description%s for details.', 'posts-data-table' ),
369 '<a href="' . esc_url( 'https://wordpress.org/plugins/posts-data-table/#description-header' ) . '" target="_blank">',
370 '</a>'
371 );
372 ?>
373 </p>
374 <?php
375 }
376
377 }
378