PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / 6.0.5
Floating Button – Easily Create Sticky, Fixed & Floating Buttons v6.0.5
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.5, at classes/Dashboard/DBManager.php

167 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( $_GET['page'] ) : '';
13 $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
14 $id = isset( $_GET['id'] ) ? absint( $_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
46 public static function create( $columns ): void {
47
48 global $wpdb;
49 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
50
51 $charset_collate = $wpdb->get_charset_collate();
52
53 $sql = "CREATE TABLE {$table} ($columns) {$charset_collate};";
54
55 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
56 dbDelta( $sql );
57 }
58
59 public static function get_all_data() {
60 global $wpdb;
61 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
62 $result = $wpdb->get_results( "SELECT * FROM $table ORDER BY id ASC" );
63
64 return ! empty( $result ) ? $result : false;
65 }
66
67 public static function get_data_by_id( $id = '' ) {
68 if ( empty( $id ) ) {
69 return false;
70 }
71 global $wpdb;
72 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
73 $query = $wpdb->prepare( "SELECT * FROM $table WHERE id=%d", absint( $id ) );
74
75 return $wpdb->get_row( $query );
76 }
77
78 public static function get_param_id($id = '') {
79 if ( empty( $id ) ) {
80 return false;
81 }
82 $result = self::get_data_by_id($id);
83 return maybe_unserialize($result->param);
84 }
85
86 public static function get_data_by_title( $title = '' ) {
87 if ( empty( $title ) ) {
88 return false;
89 }
90
91 global $wpdb;
92 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
93 $query = $wpdb->prepare( "SELECT * FROM $table WHERE title=%s", sanitize_text_field( $title ) );
94
95 return $wpdb->get_row( $query );
96 }
97
98 public static function update( $data, $where, $data_formats ): void {
99 global $wpdb;
100 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
101 $result = $wpdb->update( $table, $data, $where, $data_formats );
102 }
103
104 public static function insert( $data, $data_formats ) {
105 global $wpdb;
106 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
107
108 $result = $wpdb->insert( $table, $data, $data_formats );
109
110 if ( $result ) {
111 return $wpdb->insert_id;
112
113 }
114
115 return false;
116 }
117
118 public static function check_row( $id = '' ): bool {
119 global $wpdb;
120 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
121 if ( empty( $id ) ) {
122 return false;
123 }
124
125 $check_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d", $id ) );
126 if ( ! empty( $check_row ) ) {
127 return true;
128 }
129
130 return false;
131 }
132
133 public static function get_columns() {
134 global $wpdb;
135 $table_name = $wpdb->prefix . WOW_Plugin::PREFIX;
136
137 return $wpdb->get_results( "DESCRIBE $table_name" );
138 }
139
140 public static function display_tags(): void {
141 global $wpdb;
142 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
143 $result = $wpdb->get_results( "SELECT * FROM $table order by tag desc", ARRAY_A );
144 $tags = [];
145 if ( ! empty( $result ) ) {
146 foreach ( $result as $column ) {
147 if ( ! empty( $column['tag'] ) ) {
148 $tags[ $column['tag'] ] = $column['tag'];
149 }
150 }
151 }
152 if ( ! empty( $tags ) ) {
153 foreach ( $tags as $tag ) {
154 echo '<option value="' . esc_attr( $tag ) . '">';
155 }
156 }
157 }
158
159 public static function get_tags_from_table() {
160 global $wpdb;
161 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
162 $all_tags = $wpdb->get_results( "SELECT DISTINCT tag FROM $table ORDER BY tag ASC", ARRAY_A );
163
164 return ! empty( $all_tags ) ? $all_tags : false;
165 }
166
167 }