PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.18
Code Manager v1.0.18
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 3 years ago Code_Manager_Dashboard.php 3 years ago Code_Manager_Export.php 3 years ago Code_Manager_Form.php 3 years ago Code_Manager_Import.php 3 years ago Code_Manager_Import_File.php 3 years ago Code_Manager_List.php 3 years ago Code_Manager_List_View.php 3 years ago Code_Manager_Model.php 3 years ago Code_Manager_Preview.php 3 years ago Code_Manager_Settings.php 3 years ago Code_Manager_Tabs.php 3 years ago Message_Box.php 3 years ago WP_List_Table.php 3 years ago
Code_Manager_List_View.php
165 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 $formclass = CODE_MANAGER_FORM_CLASS;
82 $form = new $formclass();
83 $form->show();
84 }
85
86 /**
87 * Show list table
88 *
89 * @since 1.0.0
90 */
91 public function display_list_table() {
92 $listclass = CODE_MANAGER_LIST_CLASS;
93 $list = new $listclass();
94 $list->show();
95 }
96
97 /**
98 * Prepare screen options
99 *
100 * @since 1.0.0
101 */
102 public function page_screen_options() {
103 if ( is_admin() ) {
104 add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
105
106 set_screen_options();
107 $screen = get_current_screen();
108
109 if ( is_object( $screen ) && $screen->id === $this->page_hook_suffix ) {
110 // Add column selection.
111 $hidden = get_user_meta(
112 get_current_user_id(),
113 'manage' . get_current_screen()->id . 'columnshidden'
114 );
115
116 if ( 0 === count( $hidden ) ) {
117 add_user_meta(
118 get_current_user_id(),
119 'manage' . get_current_screen()->id . 'columnshidden',
120 array(
121 0 => 'code_author',
122 1 => 'code_description',
123 )
124 );
125 }
126
127 add_filter(
128 'manage_' . get_current_screen()->id . '_columns',
129 array( Code_Manager_List::class, 'get_column_labels_default' ),
130 0
131 );
132
133 // Add pagination.
134 $pagination = 10;
135 $args = array(
136 'label' => __( 'Number of items per page', 'code-manager' ),
137 'default' => $pagination,
138 'option' => 'code_manager_rows_per_page',
139 );
140 add_screen_option( 'per_page', $args );
141 }
142 }
143 }
144
145 /**
146 * Set screen options for list table
147 *
148 * @param mixed $status Current screen option.
149 * @param string $option Option name.
150 * @param int $value Option value.
151 *
152 * @return mixed
153 */
154 public function set_screen_option( $status, $option, $value ) {
155 if ( 'code_manager_rows_per_page' === $option ) {
156 return $value;
157 }
158
159 return $status;
160 }
161
162 }
163
164 }
165