PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.9.2.7
Advanced Custom Fields: Extended v0.9.2.7
0.9.2.7 0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / modules / option / module-option-table.php
acf-extended / includes / modules / option Last commit date
module-option-table.php 2 years ago module-option.php 9 months ago
module-option-table.php
303 lines
1 <?php
2
3 if(!defined('ABSPATH')){
4 exit;
5 }
6
7 if(!class_exists('WP_List_Table')){
8
9 require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
10
11 }
12
13 class ACFE_Admin_Options_List extends WP_List_Table{
14
15 /**
16 * Constructor
17 */
18 public function __construct(){
19
20 parent::__construct(array(
21 'singular' => __('Option', 'acfe'),
22 'plural' => __('Options', 'acfe'),
23 'ajax' => false
24 ));
25
26 }
27
28 /**
29 * Retrieve data from the database
30 *
31 * @param int $per_page
32 * @param int $page_number
33 *
34 * @return mixed
35 */
36 public static function get_options($per_page = 100, $page_number = 1, $search = ''){
37
38 global $wpdb;
39
40 $sql = "SELECT * FROM {$wpdb->options}";
41
42 if(!empty($search)){
43
44 $search = '%' . $wpdb->esc_like($search) . '%';
45 $sql .= $wpdb->prepare(" WHERE option_name LIKE %s", $search);
46
47 }
48
49 if(empty($_REQUEST['orderby'])){
50
51 $sql .= ' ORDER BY option_id ASC';
52
53 }else{
54
55 $orderby = esc_sql($_REQUEST['orderby']);
56 $order = !empty($_REQUEST['order']) ? esc_sql($_REQUEST['order']) : 'ASC';
57
58 $orderby_order = sanitize_sql_orderby($orderby . ' ' . $order);
59
60 if($orderby_order){
61 $sql .= ' ORDER BY ' . $orderby_order;
62 }
63
64 }
65
66 if(empty($search)){
67
68 $sql .= " LIMIT $per_page";
69 $sql .= ' OFFSET ' . ($page_number - 1) * $per_page;
70
71 }
72
73
74 $result = $wpdb->get_results($sql, 'ARRAY_A');
75
76 return $result;
77
78 }
79
80 /**
81 * Returns the count of records in the database.
82 *
83 * @return null|string
84 */
85 public static function record_count($search = ''){
86
87 global $wpdb;
88
89 $sql = "SELECT COUNT(*) FROM {$wpdb->options}";
90
91 if(!empty($search)){
92
93 $search = '%' . $wpdb->esc_like($search) . '%';
94 $sql .= $wpdb->prepare(" WHERE option_name LIKE %s", $search);
95
96 }
97
98 return $wpdb->get_var($sql);
99
100 }
101
102
103 /** Text displayed when no data is available */
104 public function no_items(){
105
106 _e('No options avaliable.', 'acfe');
107
108 }
109
110
111 /**
112 * Render a column when no column specific method exist.
113 *
114 * @param array $item
115 * @param string $column_name
116 *
117 * @return mixed
118 */
119 public function column_default($item, $column_name){
120
121 if($column_name === 'option_id'){
122
123 return $item['option_id'];
124
125 }
126
127 elseif($column_name === 'option_value'){
128
129 // raw
130 $raw = map_deep($item['option_value'], '_wp_specialchars');
131
132 // serialized
133 if(is_serialized($item['option_value'])){
134
135 $value = maybe_unserialize($item['option_value']);
136
137 if(is_object($value) && is_a($value, '__PHP_Incomplete_Class')){
138 // do nothing
139 }else{
140 $value = @map_deep($value, '_wp_specialchars');
141 }
142
143 return '<pre style="max-height:200px; overflow:auto; white-space: pre;">' . print_r($value, true) . '</pre><pre style="max-height:200px; overflow:auto; white-space: pre; margin-top:10px;">' . print_r($raw, true) . '</pre>';
144
145 // html
146 }elseif($item['option_value'] != strip_tags($item['option_value'])){
147
148 return '<pre style="max-height:200px; overflow:auto; white-space: pre;">' . print_r($raw, true) . '</pre>';
149
150 // json
151 }elseif(acfe_is_json($item['option_value'])){
152
153 $value = json_decode($item['option_value']);
154 $value = @map_deep($value, '_wp_specialchars');
155
156 return '<pre style="max-height:200px; overflow:auto; white-space: pre;">' . print_r($value, true) . '</pre><pre style="max-height:200px; overflow:auto; white-space: pre; margin-top:10px;">' . print_r($raw, true) . '</pre>';
157
158 // default
159 }else{
160
161 return $raw;
162
163 }
164
165 }
166
167 elseif($column_name === 'autoload'){
168
169 return $item['autoload'];
170
171 }else{
172
173 return print_r($item, true);
174
175 }
176
177 }
178
179 /**
180 * Render the bulk edit checkbox
181 *
182 * @param array $item
183 *
184 * @return string
185 */
186 public function column_cb($item){
187
188 return sprintf(
189 '<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['option_id']
190 );
191
192 }
193
194 /**
195 * Method for name column
196 *
197 * @param array $item an array of DB data
198 *
199 * @return string
200 */
201 public function column_option_name($item){
202
203 $delete_nonce = wp_create_nonce('acfe_options_delete_option');
204
205 $title = '<strong>' . $item['option_name'] . '</strong>';
206
207 $actions = array(
208 'edit' => sprintf('<a href="?page=%s&action=edit&option=%s">' . __('Edit') . '</a>', esc_attr($_REQUEST['page']), absint($item['option_id'])),
209 'delete' => sprintf('<a href="?page=%s&action=delete&option=%s&_wpnonce=%s">' . __('Delete') . '</a>', esc_attr($_REQUEST['page']), absint($item['option_id']), $delete_nonce),
210 );
211
212 return $title . $this->row_actions($actions);
213
214 }
215
216 /**
217 * Associative array of columns
218 *
219 * @return array
220 */
221 public function get_columns(){
222
223 $columns = array(
224 'cb' => '<input type="checkbox" />',
225 'option_id' => __('ID', 'acfe'),
226 'option_name' => __('Name', 'acfe'),
227 'option_value' => __('Value', 'acfe'),
228 'autoload' => __('Autoload', 'acfe'),
229 );
230
231 return $columns;
232
233 }
234
235 /**
236 * Columns to make sortable.
237 *
238 * @return array
239 */
240 public function get_sortable_columns(){
241
242 $sortable_columns = array(
243 'option_id' => array('option_id', true),
244 'option_name' => array('option_name', true),
245 'option_value' => array('option_value', true),
246 'autoload' => array('autoload', true),
247 );
248
249 return $sortable_columns;
250
251 }
252
253 /**
254 * Returns an associative array containing the bulk action
255 *
256 * @return array
257 */
258 public function get_bulk_actions(){
259
260 $actions = array(
261 'bulk-delete' => __('Delete')
262 );
263
264 return $actions;
265
266 }
267
268 /**
269 * Handles data query and filter, sorting, and pagination.
270 */
271 public function prepare_items(){
272
273 // Get columns
274 $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
275
276 // Vars
277 $per_page = $this->get_items_per_page('options_per_page', 100);
278 $current_page = $this->get_pagenum();
279
280 // Search
281 $search = (isset( $_REQUEST['s'])) ? $_REQUEST['s'] : false;
282
283 // Get items
284 $this->items = self::get_options($per_page, $current_page, $search);
285 /*
286 foreach($this->items as &$item){
287 $item = json_encode($item);
288 }*/
289
290 // Get total
291 $total_items = self::record_count($search);
292
293 if(!empty($search))
294 $per_page = $total_items;
295
296 $this->set_pagination_args(array(
297 'total_items' => $total_items,
298 'per_page' => $per_page
299 ));
300
301 }
302
303 }