| @@ -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', 'wpcoder' ); | |
| 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 | + 'wpcoder' ) . '</a>', | |
| 56 | + 'duplicate' => '<a href="' . esc_url( Link::duplicate( $item['ID'] ) ) . '">' . esc_attr__( 'Duplicate', | |
| 57 | + 'wpcoder' ) . '</a>', | |
| 58 | + 'delete' => '<a href="' . esc_url( Link::remove( $item['ID'] ) ) . '" >' . esc_attr__( 'Delete', | |
| 59 | + 'wpcoder' ) . '</a>', | |
| 60 | + 'export' => '<a href="' . esc_url( Link::export( $item['ID'] ) ) . '" >' . esc_attr__( 'Export', | |
| 61 | + 'wpcoder' ) . '</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', 'wpcoder' ), | |
| 93 | + 'code' => __( 'Shortcode', 'wpcoder' ), | |
| 94 | + 'code-alt' => __( 'Alternative Shortcode', 'wpcoder' ), | |
| 95 | + 'tag' => __( 'Tag', 'wpcoder' ), | |
| 96 | + 'mode' => __( 'Test mode', | |
| 97 | + 'wpcoder' ) . '<sup class="has-tooltip" data-tooltip="' . __( 'The item will only be displayed for administrators.', | |
| 98 | + 'wpcoder' ) . '">ℹ</sup>', | |
| 99 | + 'status' => __( 'Status', | |
| 100 | + 'wpcoder' ) . '<sup class="has-tooltip" data-tooltip="' . __( 'The item will only be displayed for administrators.', | |
| 101 | + 'wpcoder' ) . '">ℹ</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 | 143 | $title = ! empty( $value->title ) ? $value->title : __( 'UnTitle', 'wpcoder' ); |
| 125 | 144 | $tooltip_off = esc_attr__( 'Click for Deactivate.', 'wpcoder' ); |
| 126 | 145 | $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>'; | |
| 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 | + 'wpcoder' ) . '</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 | + 'wpcoder' ) . '</span></a>'; | |
| 129 | 150 | $status = ! empty( $value->status ) ? $status_off : $status_on; |
| 130 | 151 | |
| 131 | 152 | $mode_tooltip_off = esc_attr__( 'Click for OFF.', 'wpcoder' ); |
| 132 | 153 | $mode_tooltip_on = esc_attr__( 'Click for ON.', 'wpcoder' ); |
| 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 | + 'wpcoder' ) . '</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 | + 'wpcoder' ) . '</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-input-group"><input type="text" value="[' . esc_attr( $shortcode ) . ' id="' . absint( $value->id ) . '"]" readonly="readonly"><span class="wowp-copy codericon codericon-copy"></span></div>', | |
| 176 | + 'code-alt' => '<div class="wowp-input-group"><input type="text" value="[' . esc_attr( $shortcode ) . ' title="' . esc_attr( $title ) . '"]" readonly="readonly"><span class="wowp-copy codericon codericon-copy"></span></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,9 +217,9 @@ | ||
| 196 | 217 | |
| 197 | 218 | |
| 198 | 219 | $result = ''; |
| 199 | 220 | |
| 200 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 221 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 201 | 222 | |
| 202 | 223 | if ( empty( $search ) ) { |
| 203 | 224 | $result = $wpdb->get_results( "SELECT * FROM $table order by id desc" ); |
| 204 | 225 | if ( ! empty( $tag_search ) ) { |
| @@ -250,11 +271,17 @@ | ||
| 250 | 271 | if ( ! is_array( $ids ) ) { |
| 251 | 272 | $ids = [ $ids ]; |
| 252 | 273 | } |
| 253 | 274 | if ( empty( $action ) ) { |
| 254 | - return; | |
| 275 | + return false; | |
| 255 | 276 | } |
| 256 | 277 | |
| 278 | + $verify = $this->verify(); | |
| 279 | + | |
| 280 | + if ( ! $verify ) { | |
| 281 | + return false; | |
| 282 | + } | |
| 283 | + | |
| 257 | 284 | foreach ( $ids as $id ) { |
| 258 | 285 | if ( 'delete' === $this->current_action() ) { |
| 259 | 286 | DBManager::delete( $id ); |
| 260 | 287 | } |
| @@ -270,14 +297,12 @@ | ||
| 270 | 297 | if ( 'test_off' === $this->current_action() ) { |
| 271 | 298 | Settings::deactivate_mode( $id ); |
| 272 | 299 | } |
| 273 | 300 | } |
| 274 | - | |
| 275 | 301 | } |
| 276 | 302 | |
| 277 | 303 | protected function extra_tablenav( $which ) { |
| 278 | 304 | if ( 'top' === $which ) { |
| 279 | - | |
| 280 | 305 | $tags = DBManager::get_tags_from_table(); |
| 281 | 306 | |
| 282 | 307 | $tag_search = ( ! empty( $_REQUEST['tag'] ) ) ? sanitize_text_field( $_REQUEST ['tag'] ) : ''; |
| 283 | 308 | $tag_search = ( $tag_search === 'all' ) ? '' : $tag_search; |
| @@ -312,8 +337,15 @@ | ||
| 312 | 337 | $result = strnatcmp( $a[ $orderby ], $b[ $orderby ] ); |
| 313 | 338 | |
| 314 | 339 | // Send final sort direction to usort |
| 315 | 340 | return ( $order === 'asc' ) ? $result : - $result; |
| 341 | + } | |
| 316 | 342 | |
| 343 | + private function verify() { | |
| 344 | + $name = WPCoder::PREFIX . '_list_action'; | |
| 345 | + $nonce_action = WPCoder::PREFIX . '_nonce'; | |
| 346 | + | |
| 347 | + return ! ( ! isset( $_POST[ $name ] ) || ! wp_verify_nonce( $_POST[ $name ], | |
| 348 | + $nonce_action ) || ! current_user_can( 'unfiltered_html' ) ); | |
| 317 | 349 | } |
| 318 | 350 | |
| 319 | 351 | } |