PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.47
Code Manager v1.0.47
1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / Code_Manager / Code_Manager_List_View.php
code-manager / Code_Manager Last commit date
Code_Manager.php 6 days ago Code_Manager_Dashboard.php 6 days ago Code_Manager_Export.php 6 days ago Code_Manager_Form.php 6 days ago Code_Manager_Import.php 6 days ago Code_Manager_Import_File.php 6 days ago Code_Manager_List.php 6 days ago Code_Manager_List_View.php 6 days ago Code_Manager_Model.php 6 days ago Code_Manager_Preview.php 6 days ago Code_Manager_Settings.php 6 days ago Code_Manager_Tabs.php 6 days ago Message_Box.php 6 days ago WP_List_Table.php 6 days ago
Code_Manager_List_View.php
163 lines
1 <?php
2 /**
3 * Code Manager list view
4 *
5 * @package Code_Manager
6 */
7
8 namespace Code_Manager {
9
10 /**
11 * Class Code_Manager_List_View
12 *
13 * Implements a layer between the menu and the list table/data entry form.
14 *
15 * @author Peter Schulz
16 * @since 1.0.0
17 */
18 class Code_Manager_List_View {
19
20 /**
21 * Page hook suffix
22 *
23 * @var object|boolean Reference to (sub) menu or false
24 */
25 protected $page_hook_suffix;
26
27 /**
28 * Action (taken from $_REQUEST)
29 *
30 * @var string
31 */
32 protected $action;
33
34 /**
35 * Code_Manager_List_View constructor
36 *
37 * @param array $args [
38 * 'page_hook_suffix' => (string|boolean) Page hook suffix or false (default = false)
39 * ]
40 */
41 public function __construct( $args = array() ) {
42 $this->action =
43 isset( $_REQUEST['action'] ) ?
44 sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) :
45 ''; // input var okay.
46
47 if ( 'new' !== $this->action && 'edit' !== $this->action ) {
48 $this->page_hook_suffix = isset( $args['page_hook_suffix'] ) ? $args['page_hook_suffix'] : false;
49 if ( false !== $this->page_hook_suffix ) {
50 add_action( 'load-' . $this->page_hook_suffix, array( $this, 'page_screen_options' ) );
51 }
52 }
53 }
54
55 /**
56 * Show the list table or data entry form
57 *
58 * Depending on the value of argument action:
59 * (1) The list table is shown when no actions is defined
60 * (2) The data entry form is shown for actions new and edit
61 *
62 * @since 1.0.0
63 */
64 public function show() {
65 switch ( $this->action ) {
66 case 'new':
67 case 'edit':
68 $this->display_edit_form();
69 break;
70 default:
71 $this->display_list_table();
72 }
73 }
74
75 /**
76 * Show data entry form
77 *
78 * @since 1.0.0
79 */
80 public function display_edit_form() {
81 $form = new Code_Manager_Form();
82 $form->show();
83 }
84
85 /**
86 * Show list table
87 *
88 * @since 1.0.0
89 */
90 public function display_list_table() {
91 $list = new Code_Manager_List();
92 $list->show();
93 }
94
95 /**
96 * Prepare screen options
97 *
98 * @since 1.0.0
99 */
100 public function page_screen_options() {
101 if ( is_admin() ) {
102 add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
103
104 set_screen_options();
105 $screen = get_current_screen();
106
107 if ( is_object( $screen ) && $screen->id === $this->page_hook_suffix ) {
108 // Add column selection.
109 $hidden = get_user_meta(
110 get_current_user_id(),
111 'manage' . get_current_screen()->id . 'columnshidden'
112 );
113
114 if ( 0 === count( $hidden ) ) {
115 add_user_meta(
116 get_current_user_id(),
117 'manage' . get_current_screen()->id . 'columnshidden',
118 array(
119 0 => 'code_author',
120 1 => 'code_description',
121 )
122 );
123 }
124
125 add_filter(
126 'manage_' . get_current_screen()->id . '_columns',
127 array( Code_Manager_List::class, 'get_column_labels_default' ),
128 0
129 );
130
131 // Add pagination.
132 $pagination = 10;
133 $args = array(
134 'label' => __( 'Number of items per page', 'code-manager' ),
135 'default' => $pagination,
136 'option' => 'code_manager_rows_per_page',
137 );
138 add_screen_option( 'per_page', $args );
139 }
140 }
141 }
142
143 /**
144 * Set screen options for list table
145 *
146 * @param mixed $status Current screen option.
147 * @param string $option Option name.
148 * @param int $value Option value.
149 *
150 * @return mixed
151 */
152 public function set_screen_option( $status, $option, $value ) {
153 if ( 'code_manager_rows_per_page' === $option ) {
154 return $value;
155 }
156
157 return $status;
158 }
159
160 }
161
162 }
163