PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / 6.0.11
Floating Button – Easily Create Sticky, Fixed & Floating Buttons v6.0.11
trunk 2.0.2 3.0 4.0 4.1.2 4.3 5.0 5.0.1 5.1 5.1.1 5.2 5.3 5.3.1 6.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 All 31 releases
floating-button / classes / Dashboard / DBManager.php

DBManager.php in Floating Button – Easily Create Sticky, Fixed & Floating Buttons 6.0.11, at classes/Dashboard/DBManager.php

163 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FloatingButton\Dashboard;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use FloatingButton\WOW_Plugin;
8
9 class DBManager {
10
11 public static function remove_item() {
12 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
13 $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
14 $id = isset( $_GET['id'] ) ? absint( wp_unslash( $_GET['id'] ) ) : '';
15
16 if ( ( $page !== WOW_Plugin::SLUG ) || ( $action !== 'delete' ) || empty( $id ) ) {
17 return false;
18 }
19
20 global $wpdb;
21 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
22
23 $result = $wpdb->delete( $table, [ 'id' => $id ], [ '%d' ] );
24
25 if ( $result ) {
26 wp_safe_redirect( Link::remove_item() );
27 exit;
28 }
29
30 return false;
31 }
32
33
34 public static function delete( $id ) {
35 if ( ! isset( $id ) ) {
36 return false;
37 }
38
39 global $wpdb;
40 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
41
42 return $wpdb->delete( $table, [ 'id' => $id ], [ '%d' ] );
43 }
44
45 public static function create( $columns ): void {
46 global $wpdb;
47 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
48
49 $charset_collate = $wpdb->get_charset_collate();
50
51 $sql = "CREATE TABLE {$table} ($columns) {$charset_collate};";
52
53 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
54 dbDelta( $sql );
55 }
56
57 public static function get_all_data() {
58 global $wpdb;
59 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
60 $result = $wpdb->get_results( "SELECT * FROM $table ORDER BY id ASC" );
61
62 return ! empty( $result ) ? $result : false;
63 }
64
65 public static function get_data_by_id( $id = '' ) {
66 if ( empty( $id ) ) {
67 return false;
68 }
69 global $wpdb;
70 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
71
72 return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id=%d", absint( $id ) ) );
73 }
74
75 public static function get_param_id( $id = '' ) {
76 if ( empty( $id ) ) {
77 return false;
78 }
79 $result = self::get_data_by_id( $id );
80
81 return maybe_unserialize( $result->param );
82 }
83
84 public static function get_data_by_title( $title = '' ) {
85 if ( empty( $title ) ) {
86 return false;
87 }
88
89 global $wpdb;
90 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
91
92 return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE title=%s", sanitize_text_field( $title ) ) );
93 }
94
95 public static function update( $data, $where, $data_formats ): void {
96 global $wpdb;
97 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
98 $result = $wpdb->update( $table, $data, $where, $data_formats );
99 }
100
101 public static function insert( $data, $data_formats ) {
102 global $wpdb;
103 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
104
105 $result = $wpdb->insert( $table, $data, $data_formats );
106
107 if ( $result ) {
108 return $wpdb->insert_id;
109 }
110
111 return false;
112 }
113
114 public static function check_row( $id = '' ): bool {
115 global $wpdb;
116 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
117 if ( empty( $id ) ) {
118 return false;
119 }
120
121 $check_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d", $id ) );
122 if ( ! empty( $check_row ) ) {
123 return true;
124 }
125
126 return false;
127 }
128
129 public static function get_columns() {
130 global $wpdb;
131 $table_name = $wpdb->prefix . WOW_Plugin::PREFIX;
132
133 return $wpdb->get_results( "DESCRIBE $table_name" );
134 }
135
136 public static function display_tags(): void {
137 global $wpdb;
138 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
139 $result = $wpdb->get_results( "SELECT * FROM $table order by tag desc", ARRAY_A );
140 $tags = [];
141 if ( ! empty( $result ) ) {
142 foreach ( $result as $column ) {
143 if ( ! empty( $column['tag'] ) ) {
144 $tags[ $column['tag'] ] = $column['tag'];
145 }
146 }
147 }
148 if ( ! empty( $tags ) ) {
149 foreach ( $tags as $tag ) {
150 echo '<option value="' . esc_attr( $tag ) . '">';
151 }
152 }
153 }
154
155 public static function get_tags_from_table() {
156 global $wpdb;
157 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
158 $all_tags = $wpdb->get_results( "SELECT DISTINCT tag FROM $table ORDER BY tag ASC", ARRAY_A );
159
160 return ! empty( $all_tags ) ? $all_tags : false;
161 }
162
163 }