| 1 |
<?php |
| 2 |
|
| 3 |
namespace Barn2\Plugin\Posts_Table_Search_Sort\Admin\Wizard\Steps; |
| 4 |
|
| 5 |
use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Setup_Wizard\Api; |
| 6 |
use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Setup_Wizard\Step; |
| 7 |
use Barn2\Plugin\Posts_Table_Search_Sort\Settings; |
| 8 |
use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Util; |
| 9 |
|
| 10 |
/** |
| 11 |
* Loading step. |
| 12 |
* |
| 13 |
* @package Barn2\posts-data-table |
| 14 |
* @author Barn2 Plugins <info@barn2.com> |
| 15 |
* @license GPL-3.0 |
| 16 |
* @copyright Barn2 Media Ltd |
| 17 |
*/ |
| 18 |
class Loading extends Step { |
| 19 |
|
| 20 |
/** |
| 21 |
* {@inheritdoc} |
| 22 |
*/ |
| 23 |
public function init() { |
| 24 |
$this->set_id( 'loading' ); |
| 25 |
$this->set_name( esc_html__( 'Loading', 'posts-data-table' ) ); |
| 26 |
$this->set_description( esc_html__( 'Control how the posts in the table load.', 'posts-data-table' ) ); |
| 27 |
$this->set_title( esc_html__( 'Table loading', 'posts-data-table' ) ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* {@inheritdoc} |
| 32 |
*/ |
| 33 |
public function setup_fields() { |
| 34 |
$fields = [ |
| 35 |
'posts_per_page' => [ |
| 36 |
'label' => __( 'Posts per page', 'posts-data-table' ), |
| 37 |
'description' => __( 'The number of posts per page of results. Enter -1 to display all posts on one page.', 'posts-data-table' ), |
| 38 |
'type' => 'number', |
| 39 |
'value' => Settings::get_table_args()['rows_per_page'] ?? 20, |
| 40 |
], |
| 41 |
'lazy_load' => [ |
| 42 |
'title' => __( 'Lazy load', 'posts-data-table' ), |
| 43 |
'label' => __( 'Load the posts one page at a time', 'posts-data-table' ), |
| 44 |
'description' => __( 'Enable this if you have many posts or experience slow page load times.', 'posts-data-table' ) . ' ' . Util::barn2_link( 'kb/posts-table-lazy-load/', esc_html__( 'Read more', 'posts-data-table' ), true ), |
| 45 |
'type' => 'checkbox', |
| 46 |
'value' => false, |
| 47 |
'premium' => true, |
| 48 |
], |
| 49 |
]; |
| 50 |
|
| 51 |
return $fields; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* {@inheritdoc} |
| 56 |
*/ |
| 57 |
public function submit( array $values ) { |
| 58 |
|
| 59 |
$options = Settings::get_table_args(); |
| 60 |
$options['rows_per_page'] = isset( $values['posts_per_page'] ) ? $values['posts_per_page'] : 20; |
| 61 |
$options = Settings::sanitize_table_args( $options ); |
| 62 |
|
| 63 |
update_option( Settings::TABLE_ARGS_SETTING, $options ); |
| 64 |
|
| 65 |
return Api::send_success_response(); |
| 66 |
} |
| 67 |
} |
| 68 |
|