PluginProbe
Bubble Menu – Floating Button Menu with Sticky Navigation / 4.0
Bubble Menu – Floating Button Menu with Sticky Navigation v4.0
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, at classes/Admin/DBManager.php

170 lines 4.0 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( $_GET['page'] ) : '';
19 $action = isset( $_GET['action'] ) ? sanitize_text_field( $_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 return maybe_unserialize($result->param);
88 }
89
90 public static function get_data_by_title( $title = '' ) {
91 if ( empty( $title ) ) {
92 return false;
93 }
94
95 global $wpdb;
96 $table = $wpdb->prefix . WOWP_Plugin::PREFIX;
97
98 return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE title=%s", sanitize_text_field( $title ) ) );
99 }
100
101 public static function update( $data, $where, $data_formats ): void {
102 global $wpdb;
103 $table = $wpdb->prefix . WOWP_Plugin::PREFIX;
104 $result = $wpdb->update( $table, $data, $where, $data_formats );
105 }
106
107 public static function insert( $data, $data_formats ) {
108 global $wpdb;
109 $table = $wpdb->prefix . WOWP_Plugin::PREFIX;
110
111 $result = $wpdb->insert( $table, $data, $data_formats );
112
113 if ( $result ) {
114 return $wpdb->insert_id;
115
116 }
117
118 return false;
119 }
120
121 public static function check_row( $id = '' ): bool {
122 global $wpdb;
123 $table = $wpdb->prefix . WOWP_Plugin::PREFIX;
124 if ( empty( $id ) ) {
125 return false;
126 }
127
128 $check_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d", $id ) );
129 if ( ! empty( $check_row ) ) {
130 return true;
131 }
132
133 return false;
134 }
135
136 public static function get_columns() {
137 global $wpdb;
138 $table = $wpdb->prefix . WOWP_Plugin::PREFIX;
139
140 return $wpdb->get_results( "DESCRIBE {$table}" );
141 }
142
143 public static function display_tags(): void {
144 global $wpdb;
145 $table = $wpdb->prefix . WOWP_Plugin::PREFIX;
146 $result = $wpdb->get_results( "SELECT * FROM {$table} order by tag desc", ARRAY_A );
147 $tags = [];
148 if ( ! empty( $result ) ) {
149 foreach ( $result as $column ) {
150 if ( ! empty( $column['tag'] ) ) {
151 $tags[ $column['tag'] ] = $column['tag'];
152 }
153 }
154 }
155 if ( ! empty( $tags ) ) {
156 foreach ( $tags as $tag ) {
157 echo '<option value="' . esc_attr( $tag ) . '">';
158 }
159 }
160 }
161
162 public static function get_tags_from_table() {
163 global $wpdb;
164 $table = $wpdb->prefix . WOWP_Plugin::PREFIX;
165 $all_tags = $wpdb->get_results( "SELECT DISTINCT tag FROM {$table} ORDER BY tag ASC", ARRAY_A );
166
167 return ! empty( $all_tags ) ? $all_tags : false;
168 }
169
170 }