PluginProbe
Posts Table with Search & Sort / 1.3.1
Posts Table with Search & Sort v1.3.1
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.1, at src/Admin/Settings_Page.php

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