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

165 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 $sql = "CREATE TABLE IF NOT EXISTS $table ($columns) DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->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 $query = $wpdb->prepare( "SELECT * FROM $table WHERE id=%d", absint( $id ) );
72
73 return $wpdb->get_row( $query );
74 }
75
76 public static function get_param_id($id = '') {
77 if ( empty( $id ) ) {
78 return false;
79 }
80 $result = self::get_data_by_id($id);
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 $query = $wpdb->prepare( "SELECT * FROM $table WHERE title=%s", sanitize_text_field( $title ) );
92
93 return $wpdb->get_row( $query );
94 }
95
96 public static function update( $data, $where, $data_formats ): void {
97 global $wpdb;
98 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
99 $result = $wpdb->update( $table, $data, $where, $data_formats );
100 }
101
102 public static function insert( $data, $data_formats ) {
103 global $wpdb;
104 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
105
106 $result = $wpdb->insert( $table, $data, $data_formats );
107
108 if ( $result ) {
109 return $wpdb->insert_id;
110
111 }
112
113 return false;
114 }
115
116 public static function check_row( $id = '' ): bool {
117 global $wpdb;
118 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
119 if ( empty( $id ) ) {
120 return false;
121 }
122
123 $check_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d", $id ) );
124 if ( ! empty( $check_row ) ) {
125 return true;
126 }
127
128 return false;
129 }
130
131 public static function get_columns() {
132 global $wpdb;
133 $table_name = $wpdb->prefix . WOW_Plugin::PREFIX;
134
135 return $wpdb->get_results( "DESCRIBE $table_name" );
136 }
137
138 public static function display_tags(): void {
139 global $wpdb;
140 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
141 $result = $wpdb->get_results( "SELECT * FROM $table order by tag desc", ARRAY_A );
142 $tags = [];
143 if ( ! empty( $result ) ) {
144 foreach ( $result as $column ) {
145 if ( ! empty( $column['tag'] ) ) {
146 $tags[ $column['tag'] ] = $column['tag'];
147 }
148 }
149 }
150 if ( ! empty( $tags ) ) {
151 foreach ( $tags as $tag ) {
152 echo '<option value="' . esc_attr( $tag ) . '">';
153 }
154 }
155 }
156
157 public static function get_tags_from_table() {
158 global $wpdb;
159 $table = $wpdb->prefix . WOW_Plugin::PREFIX;
160 $all_tags = $wpdb->get_results( "SELECT DISTINCT tag FROM $table ORDER BY tag ASC", ARRAY_A );
161
162 return ! empty( $all_tags ) ? $all_tags : false;
163 }
164
165 }