PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.5
WP Coder – Insert & Manage Code Snippets v4.5
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
← All changes | classes/Dashboard/ListTable.php +106 -75 3.0.24.5 View file →
@@ -4,9 +4,9 @@
4 4
5 5 defined( 'ABSPATH' ) || exit;
6 6
7 7 use WP_List_Table;
8 -use WPCoder\WOW_Plugin;
8 +use WPCoder\WPCoder;
9 9
10 10 class ListTable extends WP_List_Table {
11 11
12 12 public $per_page = 30;
@@ -32,25 +32,34 @@
32 32 echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
33 33 }
34 34 ?>
35 35 <p class="search-box">
36 - <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ) ?>"><?php echo esc_attr( $text ); ?>
36 + <label class="screen-reader-text" for="<?php
37 + echo esc_attr( $input_id ) ?>"><?php
38 + echo esc_attr( $text ); ?>
37 39 :</label>
38 - <input type="search" id="<?php echo esc_attr( $input_id ) ?>" name="s"
39 - value="<?php _admin_search_query(); ?>"/>
40 - <?php submit_button( $text, 'button', false, false, array( 'ID' => 'search-submit' ) ); ?>
40 + <input type="search" id="<?php
41 + echo esc_attr( $input_id ) ?>" name="s" value="<?php
42 + _admin_search_query(); ?>"/>
43 + <?php
44 + submit_button( $text, 'button', false, false, array( 'ID' => 'search-submit' ) ); ?>
41 45 </p>
42 46 <?php
43 47 }
44 48
45 49 public function column_title( $item ): string {
46 - $title = ! empty( $item['title'] ) ? $item['title'] : __( 'Untitled', 'side-menu' );
50 + $title = ! empty( $item['title'] ) ? $item['title'] : __( 'Untitled', 'wp-coder' );
51 +
47 52 $actions = [
48 53 'id' => 'ID: ' . $item['ID'],
49 - 'edit' => '<a href="' . esc_url( Link::edit( $item['ID'] ) ) . '">' . esc_attr__( 'Edit', 'wpcoder' ) . '</a>',
50 - 'duplicate' => '<a href="' . esc_url( Link::duplicate( $item['ID'] ) ) . '">' . esc_attr__( 'Duplicate', 'wpcoder' ) . '</a>',
51 - 'delete' => '<a href="' . esc_url( Link::remove( $item['ID'] ) ) . '" >' . esc_attr__( 'Delete', 'wpcoder' ) . '</a>',
52 - 'export' => '<a href="' . esc_url( Link::export( $item['ID'] ) ) . '" >' . esc_attr__( 'Export', 'wpcoder' ) . '</a>',
54 + 'edit' => '<a href="' . esc_url( Link::edit( $item['ID'] ) ) . '">' . esc_attr__( 'Edit',
55 + 'wp-coder' ) . '</a>',
56 + 'duplicate' => '<a href="' . esc_url( Link::duplicate( $item['ID'] ) ) . '">' . esc_attr__( 'Duplicate',
57 + 'wp-coder' ) . '</a>',
58 + 'delete' => '<a href="' . esc_url( Link::remove( $item['ID'] ) ) . '" >' . esc_attr__( 'Delete',
59 + 'wp-coder' ) . '</a>',
60 + 'export' => '<a href="' . esc_url( Link::export( $item['ID'] ) ) . '" >' . esc_attr__( 'Export',
61 + 'wp-coder' ) . '</a>',
53 62 ];
54 63
55 64
56 65 return $title . $this->row_actions( $actions );
@@ -78,17 +87,20 @@
78 87 }
79 88
80 89 public function get_columns(): array {
81 90 return [
82 - 'cb' => '<input type="checkbox" />',
83 - 'title' => __( 'Title', 'wpcoder' ),
84 - 'code' => __( 'Shortcode', 'wpcoder' ),
85 - 'code-alt' => __('Alternative Shortcode','wpcoder' ),
86 - 'tag' => __( 'Tag', 'wpcoder' ),
87 - 'mode' => __( 'Test mode', 'wpcoder' ) . '<sup class="has-tooltip" data-tooltip="' . __( 'The item will only be displayed for administrators.', 'wpcoder' ) . '">ℹ</sup>',
88 - 'status' => __( 'Status', 'wpcoder' ) . '<sup class="has-tooltip" data-tooltip="' . __( 'The item will only be displayed for administrators.', 'wpcoder' ) . '">ℹ</sup>',
91 + 'cb' => '<input type="checkbox" />',
92 + 'title' => __( 'Title', 'wp-coder' ),
93 + 'code' => __( 'Shortcode', 'wp-coder' ),
94 + 'code-alt' => __( 'Alternative Shortcode', 'wp-coder' ),
95 + 'tag' => __( 'Tag', 'wp-coder' ),
96 + 'mode' => __( 'Test mode',
97 + 'wp-coder' ) . '<sup class="wowp-tooltip" data-tooltip="' . __( 'The item will only be displayed for administrators.',
98 + 'wp-coder' ) . '">ℹ</sup>',
99 + 'status' => __( 'Status',
100 + 'wp-coder' ) . '<sup class="wowp-tooltip" data-tooltip="' . __( 'The item will only be displayed for administrators.',
101 + 'wp-coder' ) . '">ℹ</sup>',
89 102 ];
90 -
91 103 }
92 104
93 105 public function get_hidden_columns(): array {
94 106 return [];
@@ -106,34 +118,45 @@
106 118 $offset = $this->per_page * ( $paged - 1 );
107 119
108 120 $result = $this->get_results();
109 121
110 - $slug = WOW_Plugin::SLUG;
111 - $shortcode = WOW_Plugin::SHORTCODE;
122 + $slug = WPCoder::SLUG;
123 + $shortcode = WPCoder::SHORTCODE;
112 124
113 125 if ( empty( $result ) ) {
114 126 return $data;
115 127 }
128 + $paged = $_GET['paged'] ?? '';
116 129
117 - $main_link = add_query_arg( [
118 - 'page' => $slug,
119 - 'tab' => 'settings',
130 + $main_link_arg = [
131 + 'page' => $slug . '-settings',
120 132 'action' => 'update'
121 - ], admin_url( 'admin.php' ) );
133 + ];
134 +
135 + if ( ! empty( $paged ) ) {
136 + $main_link_arg['wpcoder-page'] = absint( $paged );
137 + }
138 +
139 + $main_link = add_query_arg( $main_link_arg, admin_url( 'admin.php' ) );
140 +
141 +
122 142 foreach ( $result as $key => $value ) {
123 -
124 - $title = ! empty( $value->title ) ? $value->title : __( 'UnTitle', 'wpcoder' );
125 - $tooltip_off = esc_attr__( 'Click for Deactivate.', 'wpcoder' );
126 - $tooltip_on = esc_attr__( 'Click for Activate.', 'wpcoder' );
127 - $status_off = '<a href="' . esc_url( Link::activate_url( $value->id ) ) . '" class="wowp-toogle is-off" data-tooltip="' . esc_attr( $tooltip_on ) . '"><span>' . esc_attr__( 'OFF', 'wpcoder' ) . '</span></a>';
128 - $status_on = '<a href="' . esc_url( Link::deactivate_url( $value->id ) ) . '" class="wowp-toogle is-on" data-tooltip="' . esc_attr( $tooltip_off ) . '"><span>' . esc_attr__( 'ON', 'wpcoder' ) . '</span></a>';
143 + $title = ! empty( $value->title ) ? $value->title : __( 'Untitled', 'wp-coder' );
144 + $tooltip_off = esc_attr__( 'Click for Deactivate.', 'wp-coder' );
145 + $tooltip_on = esc_attr__( 'Click for Activate.', 'wp-coder' );
146 + $status_off = '<a href="' . esc_url( Link::activate_url( $value->id ) ) . '" class="wowp-toogle is-off" data-tooltip="' . esc_attr( $tooltip_on ) . '"><span>' . esc_attr__( 'OFF',
147 + 'wp-coder' ) . '</span></a>';
148 + $status_on = '<a href="' . esc_url( Link::deactivate_url( $value->id ) ) . '" class="wowp-toogle is-on" data-tooltip="' . esc_attr( $tooltip_off ) . '"><span>' . esc_attr__( 'ON',
149 + 'wp-coder' ) . '</span></a>';
129 150 $status = ! empty( $value->status ) ? $status_off : $status_on;
130 151
131 - $mode_tooltip_off = esc_attr__( 'Click for OFF.', 'wpcoder' );
132 - $mode_tooltip_on = esc_attr__( 'Click for ON.', 'wpcoder' );
152 + $mode_tooltip_off = esc_attr__( 'Click for OFF.', 'wp-coder' );
153 + $mode_tooltip_on = esc_attr__( 'Click for ON.', 'wp-coder' );
133 154
134 - $mode_off = '<a href="' . esc_url( Link::activate_mode( $value->id ) ) . '" class="wowp-toogle is-off" data-tooltip="' . esc_attr( $mode_tooltip_on ) . '"><span>' . esc_attr__( 'OFF', 'wpcoder' ) . '</span></a>';
135 - $mode_on = '<a href="' . esc_url( Link::deactivate_mode( $value->id ) ) . '" class="wowp-toogle is-on" data-tooltip="' . esc_attr( $mode_tooltip_off ) . '"><span>' . esc_attr__( 'ON', 'wpcoder' ) . '</span></a>';
155 + $mode_off = '<a href="' . esc_url( Link::activate_mode( $value->id ) ) . '" class="wowp-toogle is-off" data-tooltip="' . esc_attr( $mode_tooltip_on ) . '"><span>' . esc_attr__( 'OFF',
156 + 'wp-coder' ) . '</span></a>';
157 + $mode_on = '<a href="' . esc_url( Link::deactivate_mode( $value->id ) ) . '" class="wowp-toogle is-on" data-tooltip="' . esc_attr( $mode_tooltip_off ) . '"><span>' . esc_attr__( 'ON',
158 + 'wp-coder' ) . '</span></a>';
136 159
137 160 $mode = empty( $value->mode ) ? $mode_off : $mode_on;
138 161
139 162 $tag = '';
@@ -138,9 +161,9 @@
138 161
139 162 $tag = '';
140 163 if ( isset( $value->tag ) ) {
141 164 $tag_url = add_query_arg( [
142 - 'page' => WOW_Plugin::SLUG,
165 + 'page' => WPCoder::SLUG,
143 166 'tag' => $value->tag
144 167 ], admin_url( 'admin.php' ) );
145 168 $tag = '<a href="' . esc_url( $tag_url ) . '">' . esc_attr( $value->tag ) . '</a>';
146 169 }
@@ -146,21 +169,19 @@
146 169 }
147 170
148 171 $link = add_query_arg( [ 'id' => $value->id ], $main_link );
149 172 $data[] = array(
150 - 'ID' => $value->id,
151 - 'title' => '<a href="' . esc_url( $link ) . '">' . esc_attr( $title ) . '</a>',
152 - 'code' => '[' . esc_attr( $shortcode ) . ' id="' . absint( $value->id ) . '"]',
153 - 'code-alt' => '[' . esc_attr($shortcode) . ' title="' . esc_attr($title) . '"]',
154 - 'tag' => $tag,
155 - 'mode' => $mode,
156 - 'status' => $status,
173 + 'ID' => $value->id,
174 + 'title' => '<a href="' . esc_url( $link ) . '">' . esc_attr( $title ) . '</a>',
175 + 'code' => '<div class="wowp-field has-addon"><label for="shortcode" class="label is-addon"><span class="wowp-tooltip on-right is-pointer can-copy" data-tooltip="Copy"><span class="wowp-copy icon icon-copy"></span></span></label><input type="text" value="[' . esc_attr( $shortcode ) . ' id=&quot;' . absint( $value->id ) . '&quot;]" readonly="readonly"></div>',
176 + 'code-alt' => '<div class="wowp-field has-addon"><label for="shortcode" class="label is-addon"><span class="wowp-tooltip on-right is-pointer can-copy" data-tooltip="Copy"><span class="wowp-copy icon icon-copy"></span></span></label><input type="text" value="[' . esc_attr( $shortcode ) . ' title=&quot;' . esc_attr( $title ) . '&quot;]" readonly="readonly"></div>',
177 + 'tag' => $tag,
178 + 'mode' => $mode,
179 + 'status' => $status,
157 180 );
158 181 }
159 182
160 183 return $data;
161 -
162 -
163 184 }
164 185
165 186 public function column_cb( $item ) {
166 187 return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', 'ID', $item['ID'] );
@@ -196,39 +217,37 @@
196 217
197 218
198 219 $result = '';
199 220
200 - $table = $wpdb->prefix . WOW_Plugin::PREFIX;
201 -
221 + $table = $wpdb->prefix . WPCoder::PREFIX;
222 +// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
202 223 if ( empty( $search ) ) {
203 224 $result = $wpdb->get_results( "SELECT * FROM $table order by id desc" );
204 225 if ( ! empty( $tag_search ) ) {
205 - $result = $wpdb->get_results( "SELECT * FROM $table WHERE tag='$tag_search' order by id desc" );
226 + $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $table WHERE tag=%s order by id desc", $tag_search ));
206 227 }
207 - } elseif ( trim( $search ) === 'UnTitle' ) {
228 + } elseif ( trim( $search ) === 'Untitled' ) {
208 229 $result = $wpdb->get_results( "SELECT * FROM $table WHERE title='' order by id desc" );
209 230 if ( ! empty( $tag_search ) ) {
210 - $result = $wpdb->get_results( "SELECT * FROM $table WHERE title='' AND tag='$tag_search' order by id desc" );
231 + $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $table WHERE title='' AND tag=%s order by id desc", $tag_search));
211 232 }
212 233 } elseif ( is_numeric( $search ) ) {
213 - $query = $wpdb->prepare( "SELECT * FROM $table WHERE id=%d", absint( $search ) );
234 + $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $table WHERE id=%d", absint( $search ) ) );
214 235 if ( ! empty( $tag_search ) ) {
215 - $query = $wpdb->prepare( "SELECT * FROM $table WHERE id=%d AND tag='%s'", absint( $search ),
216 - $tag_search );
236 + $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $table WHERE id=%d AND tag=%s", absint( $search ),
237 + $tag_search ) );
217 238 }
218 - $result = $wpdb->get_results( $query );
219 239 } else {
220 - $wild = '%';
221 - $find = sanitize_text_field( $search );
222 - $like = $wild . $wpdb->esc_like( $find ) . $wild;
223 - $query = $wpdb->prepare( "SELECT * FROM $table WHERE title LIKE %s order by id desc", $like );
240 + $wild = '%';
241 + $find = sanitize_text_field( $search );
242 + $like = $wild . $wpdb->esc_like( $find ) . $wild;
243 + $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $table WHERE title LIKE %s order by id desc", $like ) );
224 244 if ( ! empty( $tag_search ) ) {
225 - $query = $wpdb->prepare( "SELECT * FROM $table WHERE title LIKE %s AND tag='%s' order by id desc",
226 - $like, $tag_search );
245 + $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $table WHERE title LIKE %s AND tag=%s order by id desc", $like, $tag_search ) );
227 246 }
228 - $result = $wpdb->get_results( $query );
229 247 }
230 248
249 +// phpcs:enable
231 250 return $result;
232 251 }
233 252
234 253
@@ -233,13 +252,14 @@
233 252
234 253
235 254 public function get_bulk_actions() {
236 255 $actions = [
237 - 'delete' => __( 'Delate', 'wpcoder' ),
238 - 'activate' => __( 'Activate', 'wpcoder' ),
239 - 'deactivate' => __( 'Deactivate', 'wpcoder' ),
240 - 'test_on' => __( 'Test mode ON', 'wpcoder' ),
241 - 'test_off' => __( 'Test mode OFF', 'wpcoder' ),
256 + 'delete' => __( 'Delate', 'wp-coder' ),
257 + 'activate' => __( 'Activate', 'wp-coder' ),
258 + 'deactivate' => __( 'Deactivate', 'wp-coder' ),
259 + 'test_on' => __( 'Test mode ON', 'wp-coder' ),
260 + 'test_off' => __( 'Test mode OFF', 'wp-coder' ),
261 + 'export' => __( 'Export', 'wp-coder' ),
242 262 ];
243 263
244 264 return $actions;
245 265 }
@@ -250,11 +270,17 @@
250 270 if ( ! is_array( $ids ) ) {
251 271 $ids = [ $ids ];
252 272 }
253 273 if ( empty( $action ) ) {
254 - return;
274 + return false;
255 275 }
256 276
277 + $verify = $this->verify();
278 +
279 + if ( ! $verify ) {
280 + return false;
281 + }
282 +
257 283 foreach ( $ids as $id ) {
258 284 if ( 'delete' === $this->current_action() ) {
259 285 DBManager::delete( $id );
260 286 }
@@ -270,24 +296,22 @@
270 296 if ( 'test_off' === $this->current_action() ) {
271 297 Settings::deactivate_mode( $id );
272 298 }
273 299 }
274 -
275 300 }
276 301
277 302 protected function extra_tablenav( $which ) {
278 303 if ( 'top' === $which ) {
279 -
280 304 $tags = DBManager::get_tags_from_table();
281 305
282 306 $tag_search = ( ! empty( $_REQUEST['tag'] ) ) ? sanitize_text_field( $_REQUEST ['tag'] ) : '';
283 307 $tag_search = ( $tag_search === 'all' ) ? '' : $tag_search;
284 308
285 - echo '<div class="alignleft actions"><label for="filter-by-tag" class="screen-reader-text">' . __( 'Filter by tag',
286 - 'wpcoder' ) . '</label>';
309 + echo '<div class="alignleft actions"><label for="filter-by-tag" class="screen-reader-text">' . esc_attr__( 'Filter by tag',
310 + 'wp-coder' ) . '</label>';
287 311 echo '<select name="tag" id="filter-by-tag">';
288 - echo '<option value="all"' . selected( 'all', $tag_search, false ) . '>' . __( 'All',
289 - 'wpcoder' ) . '</option>';
312 + echo '<option value="all"' . selected( 'all', $tag_search, false ) . '>' . esc_attr__( 'All',
313 + 'wp-coder' ) . '</option>';
290 314
291 315 if ( ! empty( $tags ) ) {
292 316 foreach ( $tags as $tag ) {
293 317 if ( empty( $tag['tag'] ) ) {
@@ -292,14 +316,14 @@
292 316 foreach ( $tags as $tag ) {
293 317 if ( empty( $tag['tag'] ) ) {
294 318 continue;
295 319 }
296 - echo '<option value="' . trim( esc_attr( $tag['tag'] ) ) . '"' . selected( $tag['tag'], $tag_search,
297 - false ) . '>' . esc_attr( $tag['tag'] ) . '</option>';
320 + echo '<option value="' . esc_attr( trim( $tag['tag'] ) ) . '"' . selected( $tag['tag'], $tag_search,
321 + false ) . '>' . esc_html( $tag['tag'] ) . '</option>';
298 322 }
299 323 }
300 324 echo '</select>';
301 - submit_button( __( 'Filter', 'wpcoder' ), 'secondary', 'action', false );
325 + submit_button( __( 'Filter', 'wp-coder' ), 'secondary', 'action', false );
302 326 echo '</div>';
303 327 }
304 328 }
305 329
@@ -312,8 +336,15 @@
312 336 $result = strnatcmp( $a[ $orderby ], $b[ $orderby ] );
313 337
314 338 // Send final sort direction to usort
315 339 return ( $order === 'asc' ) ? $result : - $result;
340 + }
316 341
342 + private function verify() {
343 + $name = WPCoder::PREFIX . '_list_action';
344 + $nonce_action = WPCoder::PREFIX . '_nonce';
345 +
346 + return ! ( ! isset( $_POST[ $name ] ) || ! wp_verify_nonce( $_POST[ $name ],
347 + $nonce_action ) || ! current_user_can( 'unfiltered_html' ) );
317 348 }
318 349
319 350 }