PluginProbe
Bubble Menu – Floating Button Menu with Sticky Navigation / 4.0.3
Bubble Menu – Floating Button Menu with Sticky Navigation v4.0.3
trunk 1.3 2.0 2.2 2.2.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.1 4.1.1
bubble-menu / classes / Admin / DBManager.php

DBManager.php in Bubble Menu – Floating Button Menu with Sticky Navigation 4.0.3, at classes/Admin/DBManager.php

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