PluginProbe
Float menu – awesome floating side menu / 7.0.2
Float menu – awesome floating side menu v7.0.2
7.2.5 trunk 2.1 2.2 3.0.1 3.1 3.2.2 3.3.1 3.5 3.5.1 3.5.2 3.5.3. 3.5.4 4.0 4.1 4.1.1 4.2 4.3 4.3.1 4.3.2 5.0 5.0.1 5.0.2 5.0.3 5.1 All 57 releases
float-menu / classes / Admin / DBManager.php

DBManager.php in Float menu – awesome floating side menu 7.0.2, at classes/Admin/DBManager.php

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