PluginProbe
WebTotem Security / 2.4.9
WebTotem Security v2.4.9
3.0.2 3.0.1 3.0.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.1 2.2.2 2.2.3 All 110 releases
wt-security / lib / DB.php

DB.php in WebTotem Security 2.4.9, at lib/DB.php

122 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) {
3 if (!headers_sent()) {
4 /* Report invalid access if possible. */
5 header('HTTP/1.1 403 Forbidden');
6 }
7 exit(1);
8 }
9
10 /**
11 * WebTotem Database class for Wordpress.
12 */
13 class WebTotemDB {
14
15 const WTOTEM_DB_VERSION = '1.0';
16 const WTOTEM_TABLE_SETTINGS = 'wtotem_settings';
17
18 /**
19 * Creating a database with plugin settings.
20 */
21 public static function install () {
22 global $wpdb;
23
24 $table_name = self::add_prefix(self::WTOTEM_TABLE_SETTINGS);
25 if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
26
27 $sql = "CREATE TABLE " . $table_name . " (
28 id mediumint(9) NOT NULL AUTO_INCREMENT,
29 name tinytext NOT NULL,
30 value longtext,
31 UNIQUE KEY id (id)
32 );";
33
34 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
35 dbDelta($sql);
36
37 update_option("wtotem_db_version", self::WTOTEM_DB_VERSION);
38 }
39 return true;
40 }
41
42 /**
43 * Add (or update) option to the settings table.
44 */
45 public static function setOption ($name, $value) {
46 global $wpdb;
47
48 $table_name = self::add_prefix(self::WTOTEM_TABLE_SETTINGS);
49
50 $option = array(
51 'name' => $name,
52 'value' => $value,
53 );
54
55 if($current = self::getOption($name, true)){
56 $option['id'] = $current['id'];
57 }
58
59 $wpdb->replace( $table_name, $option );
60 }
61
62 /**
63 * Delete option to the settings table.
64 */
65 public static function deleteOption ($name) {
66 global $wpdb;
67
68 $table_name = self::add_prefix(self::WTOTEM_TABLE_SETTINGS);
69 $wpdb->delete( $table_name, array( 'name' => $name ) );
70 }
71
72 /**
73 * Getting values from the settings table.
74 *
75 * @param string $name
76 * Option name.
77 * @param string $need_id
78 * If you need to return id.
79 *
80 * @return string|array
81 */
82 public static function getOption ($name, $need_id = false) {
83 global $wpdb;
84
85 $table_name = self::add_prefix(self::WTOTEM_TABLE_SETTINGS);
86
87 $option = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $table_name WHERE name = '%s'", $name ) );
88
89 if($option) {
90 if($need_id){
91 return [
92 'id' => $option->id,
93 'value' => $option->value,
94 ];
95 }
96 }
97
98 return $option ? $option->value : '';
99 }
100
101 /**
102 * Deleting all tables.
103 */
104 public static function uninstall() {
105 global $wpdb;
106
107 $wpdb->query("DROP TABLE IF EXISTS `" . self::add_prefix(self::WTOTEM_TABLE_SETTINGS) . "`");
108 }
109
110 /**
111 * Returns the table with the site prefix added.
112 *
113 * @param string $table
114 * Table name.
115 * @return string
116 */
117 public static function add_prefix($table) {
118 global $wpdb;
119 return $wpdb->prefix . $table;
120 }
121
122 }