| 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 |
* Layout Settings 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 Layout extends Step { |
| 19 |
|
| 20 |
/** |
| 21 |
* {@inheritdoc} |
| 22 |
*/ |
| 23 |
public function init() { |
| 24 |
$this->set_id( 'layout' ); |
| 25 |
$this->set_name( esc_html__( 'Layout and Content', 'posts-data-table' ) ); |
| 26 |
$this->set_description( esc_html__( 'First, choose what to include in your post tables.', 'posts-data-table' ) ); |
| 27 |
$this->set_title( esc_html__( 'Layout and content', 'posts-data-table' ) ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* {@inheritdoc} |
| 32 |
*/ |
| 33 |
public function setup_fields() { |
| 34 |
$fields = [ |
| 35 |
'layout' => [ |
| 36 |
'label' => __( 'Post type', 'posts-data-table' ), |
| 37 |
'description' => __( 'The default post type for your tables.', 'posts-data-table' ), |
| 38 |
'type' => 'select', |
| 39 |
'options' => [ |
| 40 |
[ |
| 41 |
'value' => 'post', |
| 42 |
'label' => __( 'Post', 'posts-data-table' ), |
| 43 |
], |
| 44 |
], |
| 45 |
'value' => 'post', |
| 46 |
'premium' => true, |
| 47 |
], |
| 48 |
'columns' => [ |
| 49 |
'label' => __( 'Columns', 'posts-data-table' ), |
| 50 |
'description' => __( 'List the columns to include in your posts tables.', 'posts-data-table' ) . ' ' . Util::barn2_link( 'kb/list-your-wordpress-blog-posts/#table-columns', esc_html__( 'Read more', 'posts-data-table' ), true ), |
| 51 |
'type' => 'text', |
| 52 |
'value' => Settings::get_table_args()['columns'] ?? 'title,content,date,author,categories', |
| 53 |
], |
| 54 |
'length' => [ |
| 55 |
'label' => __( 'Content length', 'posts-data-table' ), |
| 56 |
'description' => __( 'If you have included a ‘content’ column, then enter the number of characters to appear in the table. Enter -1 to show the full content.', 'posts-data-table' ), |
| 57 |
'type' => 'number', |
| 58 |
'value' => Settings::get_table_args()['content_length'] ?? 15, |
| 59 |
], |
| 60 |
]; |
| 61 |
|
| 62 |
return $fields; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* {@inheritdoc} |
| 67 |
*/ |
| 68 |
public function submit( array $values ) { |
| 69 |
|
| 70 |
$columns = isset( $values['columns'] ) ? $values['columns'] : 'title,content,date,author,categories'; |
| 71 |
$length = isset( $values['length'] ) ? $values['length'] : 15; |
| 72 |
|
| 73 |
$options = Settings::get_table_args(); |
| 74 |
$options['columns'] = $columns; |
| 75 |
$options['content_length'] = $length; |
| 76 |
$options = Settings::sanitize_table_args( $options ); |
| 77 |
|
| 78 |
update_option( Settings::TABLE_ARGS_SETTING, $options ); |
| 79 |
|
| 80 |
return Api::send_success_response(); |
| 81 |
} |
| 82 |
} |
| 83 |
|