PluginProbe
WP Coder – Insert & Manage Code Snippets / 3.1.1
WP Coder – Insert & Manage Code Snippets v3.1.1
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
← All changes | classes/Update/UpdateDB.php +62 -24 4.5.13.1.1 View file →
@@ -1,15 +1,33 @@
1 1 <?php
2 2
3 3 namespace WPCoder\Update;
4 4
5 +defined( 'ABSPATH' ) || exit;
6 +
7 +use WPCoder\Dashboard\DBManager;
5 8 use WPCoder\WPCoder;
6 9
7 10 class UpdateDB {
8 11
9 - const NEW_DB_VERSION = '3.6';
12 + public static function init(): void {
13 + $current_db_version = get_option( WPCoder::PREFIX . '_db_version' );
10 14
11 - const TABLE_COLUMNS = "
15 + if ( $current_db_version && version_compare( $current_db_version, '3.1', '>=' ) ) {
16 + return;
17 + }
18 +
19 + self::updateDB();
20 + self::updateDBFields();
21 +
22 + update_option( WPCoder::PREFIX . '_db_version', '3.1' );
23 + }
24 +
25 + private static function updateDB(): void {
26 + global $wpdb;
27 + $table = $wpdb->prefix . WPCoder::PREFIX;
28 +
29 + $columns = "
12 30 id mediumint(9) NOT NULL AUTO_INCREMENT,
13 31 title VARCHAR(200) NOT NULL,
14 32 html_code LONGTEXT,
15 33 css_code LONGTEXT,
@@ -18,37 +36,57 @@
18 36 param LONGTEXT,
19 37 status BOOLEAN,
20 38 mode BOOLEAN,
21 39 tag TEXT,
22 - php_include int(11) NOT NULL DEFAULT '0',
23 - UNIQUE KEY id (id),
24 - INDEX id_index (id)
25 - ";
40 + UNIQUE KEY id (id)
41 + ";
42 + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
26 43
27 - public static function init(): void {
28 - $current_db_version = get_option( WPCoder::PREFIX . '_db_version' );
44 + $sql = "CREATE TABLE $table ($columns) DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->collate};";
45 + dbDelta( $sql );
46 + }
29 47
30 - if ( $current_db_version && version_compare( $current_db_version, self::NEW_DB_VERSION, '>=' ) ) {
31 - return;
32 - }
48 + private static function updateDBFields(): void {
49 + $results = DBManager::get_all_data();
33 50
34 - self::start_update();
35 - update_option( WPCoder::PREFIX . '_db_version', self::NEW_DB_VERSION );
36 - }
51 + if ( ! empty( $results ) ) {
52 + foreach ( $results as $key => $val ) {
53 + $id = $val->id;
54 + $title = $val->title;
55 + $param = maybe_unserialize( $val->param );
37 56
38 - private static function start_update(): void {
39 - self::update_database();
40 - }
57 + $html_code = ! empty( $param['content_html'] ) ? $param['content_html'] : '';
58 + if ( ! empty ( $val->html_code ) ) {
59 + $html_code = $val->html_code;
60 + }
61 + $css_code = ! empty( $param['content_css'] ) ? $param['content_css'] : '';
62 + if ( ! empty ( $val->css_code ) ) {
63 + $css_code = $val->css_code;
64 + }
41 65
42 - private static function update_database(): void {
43 - global $wpdb;
66 + $js_code = ! empty( $param['content_js'] ) ? $param['content_js'] : '';
67 + if ( ! empty ( $val->js_code ) ) {
68 + $js_code = $val->js_code;
69 + }
44 70
45 - $table = $wpdb->prefix . WPCoder::PREFIX;
46 - $charset_collate = $wpdb->get_charset_collate();
71 + $data = [
72 + 'title' => $title,
73 + 'html_code' => $html_code,
74 + 'css_code' => $css_code,
75 + 'js_code' => $js_code,
76 + 'status' => 0,
77 + 'mode' => 0,
78 + 'tag' => '',
79 + 'param' => $val->param,
80 + ];
47 81
48 - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
82 + $where = [ 'id' => $id ];
49 83
50 - $sql = "CREATE TABLE $table (" . self::TABLE_COLUMNS . ") $charset_collate;";
51 - dbDelta( $sql );
84 + $data_formats = [ '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%s' ];
85 +
86 + DBManager::update( $data, $where, $data_formats );
87 + }
88 + }
52 89 }
90 +
53 91
54 92 }