PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.8
Advanced Custom Fields: Extended v0.8
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 / admin / options.class.php
acf-extended / includes / admin Last commit date
tools 6 years ago views 6 years ago options.class.php 6 years ago options.php 6 years ago plugins.php 6 years ago settings.php 6 years ago
options.class.php
277 lines
1 <?php
2
3 if(!defined('ABSPATH'))
4 exit;
5
6 if(!class_exists('WP_List_Table'))
7 require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
8
9 class ACFE_Admin_Options_List extends WP_List_Table{
10
11 /**
12 * Constructor
13 *
14 */
15 public function __construct(){
16
17 parent::__construct(array(
18 'singular' => __('Option', 'acfe'),
19 'plural' => __('Options', 'acfe'),
20 'ajax' => false
21 ));
22
23 }
24
25
26 /**
27 * Retrieve data from the database
28 *
29 * @param int $per_page
30 * @param int $page_number
31 *
32 * @return mixed
33 */
34 public static function get_options($per_page = 100, $page_number = 1, $search = ''){
35
36 global $wpdb;
37
38 $sql = "SELECT * FROM {$wpdb->options}";
39
40 if(!empty($search)){
41
42 $sql .= ' WHERE option_name LIKE \'%' . $search . '%\'';
43
44 }
45
46 if(empty($_REQUEST['orderby'])){
47
48 $sql .= ' ORDER BY option_id ASC';
49
50 }
51
52 else{
53
54 $sql .= ' ORDER BY ' . esc_sql($_REQUEST['orderby']);
55 $sql .= !empty($_REQUEST['order']) ? ' ' . esc_sql($_REQUEST['order']) : ' ASC';
56
57 }
58
59 if(empty($search)){
60
61 $sql .= " LIMIT $per_page";
62 $sql .= ' OFFSET ' . ($page_number - 1) * $per_page;
63
64 }
65
66
67 $result = $wpdb->get_results($sql, 'ARRAY_A');
68
69 return $result;
70
71 }
72
73
74 /**
75 * Returns the count of records in the database.
76 *
77 * @return null|string
78 */
79 public static function record_count($search = ''){
80
81 global $wpdb;
82
83 $sql = "SELECT COUNT(*) FROM {$wpdb->options}";
84
85 if(!empty($search)){
86
87 $sql .= ' WHERE option_name LIKE \'%' . $search . '%\'';
88
89 }
90
91 return $wpdb->get_var($sql);
92
93 }
94
95
96 /** Text displayed when no data is available */
97 public function no_items(){
98
99 _e('No options avaliable.', 'acfe');
100
101 }
102
103
104 /**
105 * Render a column when no column specific method exist.
106 *
107 * @param array $item
108 * @param string $column_name
109 *
110 * @return mixed
111 */
112 public function column_default($item, $column_name){
113
114 if($column_name === 'option_id'){
115
116 return $item['option_id'];
117
118 }
119
120 elseif($column_name === 'option_value'){
121
122 if(is_serialized($item['option_value']) || $item['option_value'] != strip_tags($item['option_value'])){
123
124 return '<pre style="max-height:200px; overflow:auto; white-space: pre;">' . print_r(maybe_unserialize($item['option_value']), true) . '</pre>';
125
126 }elseif(acfe_is_json($item['option_value'])){
127
128 return '<pre style="max-height:200px; overflow:auto; white-space: pre;">' . print_r(json_decode($item['option_value']), true) . '</pre>';
129
130 }
131
132
133 return $item['option_value'];
134
135 }
136
137 elseif($column_name === 'autoload'){
138
139 return $item['autoload'];
140
141 }else{
142
143 return print_r($item, true);
144
145 }
146
147 }
148
149 /**
150 * Render the bulk edit checkbox
151 *
152 * @param array $item
153 *
154 * @return string
155 */
156 public function column_cb($item){
157
158 return sprintf(
159 '<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['option_id']
160 );
161
162 }
163
164
165 /**
166 * Method for name column
167 *
168 * @param array $item an array of DB data
169 *
170 * @return string
171 */
172 public function column_option_name($item){
173
174 $delete_nonce = wp_create_nonce('acfe_options_delete_option');
175
176 $title = '<strong>' . $item['option_name'] . '</strong>';
177
178 $actions = array(
179 'edit' => sprintf('<a href="?page=%s&action=edit&option=%s">' . __('Edit') . '</a>', esc_attr($_REQUEST['page']), absint($item['option_id'])),
180 'delete' => sprintf('<a href="?page=%s&action=delete&option=%s&_wpnonce=%s">' . __('Delete') . '</a>', esc_attr($_REQUEST['page']), absint($item['option_id']), $delete_nonce),
181 );
182
183 return $title . $this->row_actions($actions);
184
185 }
186
187
188 /**
189 * Associative array of columns
190 *
191 * @return array
192 */
193 public function get_columns(){
194
195 $columns = array(
196 'cb' => '<input type="checkbox" />',
197 'option_id' => __('ID', 'acfe'),
198 'option_name' => __('Name', 'acfe'),
199 'option_value' => __('Value', 'acfe'),
200 'autoload' => __('Autoload', 'acfe'),
201 );
202
203 return $columns;
204
205 }
206
207
208 /**
209 * Columns to make sortable.
210 *
211 * @return array
212 */
213 public function get_sortable_columns(){
214
215 $sortable_columns = array(
216 'option_id' => array('option_id', true),
217 'option_name' => array('option_name', true),
218 'option_value' => array('option_value', true),
219 'autoload' => array('autoload', true),
220 );
221
222 return $sortable_columns;
223
224 }
225
226 /**
227 * Returns an associative array containing the bulk action
228 *
229 * @return array
230 */
231 public function get_bulk_actions(){
232
233 $actions = array(
234 'bulk-delete' => __('Delete')
235 );
236
237 return $actions;
238
239 }
240
241
242 /**
243 * Handles data query and filter, sorting, and pagination.
244 */
245 public function prepare_items(){
246
247 // Get columns
248 $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
249
250 // Vars
251 $per_page = $this->get_items_per_page('options_per_page', 100);
252 $current_page = $this->get_pagenum();
253
254 // Search
255 $search = (isset( $_REQUEST['s'])) ? $_REQUEST['s'] : false;
256
257 // Get items
258 $this->items = self::get_options($per_page, $current_page, $search);
259 /*
260 foreach($this->items as &$item){
261 $item = json_encode($item);
262 }*/
263
264 // Get total
265 $total_items = self::record_count($search);
266
267 if(!empty($search))
268 $per_page = $total_items;
269
270 $this->set_pagination_args(array(
271 'total_items' => $total_items,
272 'per_page' => $per_page
273 ));
274
275 }
276
277 }