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