| @@ -1,11 +1,11 @@ | ||
| 1 | -<?php | |
| 1 | +<?php | |
| 2 | 2 | namespace MaxButtons; |
| 3 | 3 | defined('ABSPATH') or die('No direct access permitted'); |
| 4 | 4 | |
| 5 | 5 | class maxInstall |
| 6 | 6 | { |
| 7 | - public static function activation_hook($network_wide) { | |
| 7 | + static function activation_hook($network_wide) { | |
| 8 | 8 | if ($network_wide) { |
| 9 | 9 | static::call_function_for_each_site( array('self','activate_plugin') ); |
| 10 | 10 | } |
| 11 | 11 | else { |
| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | else { |
| 12 | 12 | static::activate_plugin(); |
| 13 | 13 | } |
| 14 | 14 | } |
| 15 | - public static function deactivation_hook($network_wide) { | |
| 15 | + static function deactivation_hook($network_wide) { | |
| 16 | 16 | |
| 17 | 17 | if ($network_wide) { |
| 18 | 18 | static::call_function_for_each_site( array('self','deactivate_plugin') ); |
| 19 | 19 | } |
| @@ -19,37 +19,22 @@ | ||
| 19 | 19 | } |
| 20 | 20 | else { |
| 21 | 21 | static::deactivate_plugin(); |
| 22 | 22 | } |
| 23 | - } | |
| 23 | + } | |
| 24 | 24 | |
| 25 | - public static function hasAddOn($addon) | |
| 26 | - { | |
| 27 | - switch($addon) | |
| 28 | - { | |
| 29 | - case 'socialshare': | |
| 30 | - if (defined('MBSOCIAL_ROOT_FILE')) | |
| 31 | - { | |
| 32 | - return true; | |
| 33 | - } | |
| 34 | - break; | |
| 35 | - } | |
| 36 | - | |
| 37 | - return false; | |
| 38 | - } | |
| 39 | - | |
| 40 | 25 | // This should be done - once! Removed in time as well. |
| 41 | - public static function check_database() | |
| 26 | + static function check_database() | |
| 42 | 27 | { |
| 43 | - $checked = get_option("MB_DBASECHECK", true); | |
| 28 | + $checked = get_option("MB_DBASECHECK", true); | |
| 44 | 29 | if ($checked !== false) // removing this option. |
| 45 | - delete_option('MB_DBASECHECK'); | |
| 46 | - | |
| 30 | + delete_option('MB_DBASECHECK'); | |
| 31 | + | |
| 47 | 32 | $version = MAXBUTTONS_VERSION_NUM; |
| 48 | - $installed_version = MB()->get_installed_version(); | |
| 33 | + $installed_version = MB()->get_installed_version(); | |
| 49 | 34 | if ($version !== $installed_version) |
| 50 | 35 | { |
| 51 | - $table = maxUtils::get_table_name(); | |
| 36 | + $table = maxUtils::get_table_name(); | |
| 52 | 37 | |
| 53 | 38 | self::activate_plugin(); // always run the DBdelta on version mismatch. |
| 54 | 39 | self::clear(); |
| 55 | 40 | } |
| @@ -54,221 +39,149 @@ | ||
| 54 | 39 | self::clear(); |
| 55 | 40 | } |
| 56 | 41 | } |
| 57 | 42 | |
| 58 | - public static function activate_plugin($gocreate = true) | |
| 43 | + static function activate_plugin($gocreate = true) | |
| 59 | 44 | { |
| 45 | + $button = new maxButton(); | |
| 46 | + $button->reset_cache(); //refresh cache | |
| 47 | + | |
| 60 | 48 | static::create_database_table(); |
| 61 | - static::migrate(); | |
| 49 | + static::migrate(); | |
| 62 | 50 | static::upgradeUTF(); |
| 63 | - static::updateFA(); | |
| 64 | - | |
| 65 | - $button = MB()->getClass('button'); | |
| 66 | - $button->reset_cache(); //refresh cache | |
| 67 | - | |
| 68 | 51 | update_option(MAXBUTTONS_VERSION_KEY, MAXBUTTONS_VERSION_NUM); |
| 69 | - $created = get_option("MBFREE_CREATED"); | |
| 70 | - if ($created == '' && $gocreate) | |
| 71 | - { update_option("MBFREE_CREATED", time()); | |
| 72 | - update_option("MBFREE_HOMEURL", home_url()); | |
| 52 | + $created = get_option("MBFREE_CREATED"); | |
| 53 | + if ($created == '' && $gocreate) | |
| 54 | + { update_option("MBFREE_CREATED", time()); | |
| 55 | + update_option("MBFREE_HOMEURL", home_url()); | |
| 73 | 56 | } |
| 74 | 57 | |
| 75 | 58 | } |
| 76 | - | |
| 59 | + | |
| 77 | 60 | /** Function to clear out obsolete and old options, items etc. */ |
| 78 | - public static function clear() | |
| 61 | + static function clear() | |
| 79 | 62 | { |
| 80 | 63 | delete_option('MB_DBASECHECK'); |
| 81 | 64 | } |
| 82 | - | |
| 83 | - /** MOVE Button Database records from FA4 to FA5 */ | |
| 84 | - public static function updateFA() | |
| 85 | - { | |
| 86 | - global $wpdb; | |
| 87 | - | |
| 88 | - $conversion_path = MB()->get_plugin_path() . '/assets/libraries/font-awesome-5/shims.json'; | |
| 89 | - $conversion_array = json_decode(file_get_contents($conversion_path), ARRAY_A); | |
| 90 | - | |
| 91 | - $sql = 'select id, icon from ' . maxUtils::get_table_name(); | |
| 92 | - $result = $wpdb->get_results($sql, ARRAY_A); | |
| 93 | - if (count($result) == 0) | |
| 94 | - return; | |
| 95 | - | |
| 96 | - foreach($result as $item) | |
| 97 | - { | |
| 98 | - $button_id = $item['id']; | |
| 99 | - if (! $button_id > 0) | |
| 100 | - { continue; } | |
| 101 | - // procedure from setupdata by button class | |
| 102 | - $icondata = maybe_unserialize($item['icon']); | |
| 103 | - if (! is_array($icondata) ) | |
| 104 | - { | |
| 105 | - $icondata = json_decode($icondata, true); | |
| 106 | - if (isset($icondata['fa_icon_value']) && strlen($icondata['fa_icon_value']) > 0) | |
| 107 | - { | |
| 108 | - $fa_icon = $icondata['fa_icon_value']; | |
| 109 | - $fa_icon = str_replace('fa-', '', $fa_icon); // remove the prefix | |
| 110 | - | |
| 111 | - // don't convert converted icons. | |
| 112 | - if (strpos($fa_icon, 'fas') === false && strpos($fa_icon, 'fab') === false && strpos($fa_icon,'far') === false) | |
| 113 | - { | |
| 114 | - $new_fa_icon = self::searchNewFA($fa_icon, $conversion_array); | |
| 115 | - $icondata['fa_icon_value'] = $new_fa_icon; | |
| 116 | - $wpdb->update(maxUtils::get_table_name(), array('icon' => json_encode($icondata)), array('id' => $button_id) ); | |
| 117 | - | |
| 118 | - } | |
| 119 | - | |
| 120 | - } | |
| 121 | - } | |
| 122 | - | |
| 123 | - } | |
| 124 | - | |
| 125 | - } | |
| 126 | - | |
| 127 | - /** Convert Font Awesome 4 to Font Awesome 5 via the conversion shims array | |
| 128 | - * @param $old The old value, without the fa- prefix | |
| 129 | - * @param $conversion_array The loaded FA5 shims library | |
| 65 | + | |
| 66 | + /** Move data from old version database to new version | |
| 67 | + | |
| 68 | + Check if new database table is empty ( aka new ) to prevent migrating the same data multiple times then copy all rows from old table to the new one. | |
| 130 | 69 | */ |
| 131 | - public static function searchNewFA($old, $conversion_array) | |
| 132 | - { | |
| 133 | - $new = false; | |
| 134 | - foreach($conversion_array as $key => $items) | |
| 135 | - { | |
| 136 | - if ($items[0] == $old) | |
| 137 | - { | |
| 138 | - $new = (strlen($items[1]) > 0) ? $items[1] : 'fas'; // if not set, fas is the set | |
| 139 | - $new .= ' fa-'; | |
| 140 | - $new .= (strlen($items[2]) > 0) ? $items[2] : $old ; | |
| 141 | - } | |
| 142 | - | |
| 143 | - } | |
| 144 | - | |
| 145 | - if (! $new) | |
| 146 | - { | |
| 147 | - $new = 'fas fa-'. $old; | |
| 148 | - } | |
| 149 | - | |
| 150 | - return $new; | |
| 151 | - } | |
| 152 | - | |
| 153 | - | |
| 154 | - /** Move data from old version database to new version | |
| 155 | - * | |
| 156 | - * Check if new database table is empty ( aka new ) to prevent migrating the same data multiple times then copy all rows from old table to the new one. | |
| 157 | - */ | |
| 158 | 70 | static function migrate() |
| 159 | 71 | { |
| 160 | - global $wpdb; | |
| 161 | - | |
| 162 | - $old_table = maxUtils::get_table_name(true); | |
| 163 | - $table = maxUtils::get_table_name(); | |
| 164 | - | |
| 72 | + global $wpdb; | |
| 73 | + | |
| 74 | + $old_table = maxUtils::get_table_name(true); | |
| 75 | + $table = maxUtils::get_table_name(); | |
| 76 | + | |
| 165 | 77 | if (! self::maxbuttons_database_table_exists($old_table)) |
| 166 | 78 | { |
| 167 | - return; | |
| 79 | + return; | |
| 168 | 80 | } |
| 81 | + | |
| 82 | + $sql = "SELECT id from $table"; | |
| 83 | + $result = $wpdb->get_results($sql, ARRAY_A); | |
| 84 | + if(count($result) > 0) return; // don't do this if table already has data. | |
| 169 | 85 | |
| 170 | - $sql = "SELECT id from $table"; | |
| 171 | - $result = $wpdb->get_results($sql, ARRAY_A); | |
| 172 | - if(count($result) > 0) return; // don't do this if table already has data. | |
| 173 | - | |
| 174 | - $sql = "SELECT * FROM $old_table"; | |
| 175 | - $rows = $wpdb->get_results($sql, ARRAY_A); | |
| 176 | - | |
| 177 | - if (count($rows) == 0 ) // no button in all table; all is good. | |
| 178 | - return true; | |
| 179 | - | |
| 180 | - | |
| 181 | - foreach($rows as $row) | |
| 182 | - { | |
| 86 | + $sql = "SELECT * FROM $old_table"; | |
| 87 | + $rows = $wpdb->get_results($sql, ARRAY_A); | |
| 88 | + | |
| 89 | + if (count($rows) == 0 ) // no button in all table; all is good. | |
| 90 | + return true; | |
| 91 | + | |
| 92 | + | |
| 93 | + foreach($rows as $row) | |
| 94 | + { | |
| 183 | 95 | $data = static::convertOldFields($row); |
| 184 | - $id = $data["id"]; | |
| 185 | - global $wpdb; | |
| 186 | - $wpdb->insert($table, array("id" => $id)); | |
| 187 | - | |
| 188 | - //$data = apply_filters("mb-migration-data",$data, $row); | |
| 189 | - $button = MB()->getClass('button'); | |
| 96 | + $id = $data["id"]; | |
| 97 | + global $wpdb; | |
| 98 | + $wpdb->insert($table, array("id" => $id)); | |
| 99 | + | |
| 100 | + //$data = apply_filters("mb-migration-data",$data, $row); | |
| 101 | + $button = new maxButton(); | |
| 190 | 102 | $button->set($id); |
| 191 | 103 | $button->save($data); |
| 192 | 104 | } |
| 193 | 105 | } |
| 194 | - | |
| 106 | + | |
| 195 | 107 | /** Import fields from the old database format ( pre version 3.0 ) */ |
| 196 | 108 | static function convertOldFields($row) |
| 197 | 109 | { |
| 198 | - $data = array(); | |
| 110 | + $data = array(); | |
| 199 | 111 | |
| 200 | - $data["id"] = (isset($row["id"])) ? $row["id"] : -1; | |
| 112 | + | |
| 113 | + $data["id"] = (isset($row["id"])) ? $row["id"] : -1; | |
| 201 | 114 | $data["name"] = $row["name"]; |
| 202 | 115 | $data["status"] = isset($row["status"]) ? $row["status"] : 'publish'; // happens with downloadable packs. |
| 203 | - $data["description"] = $row["description"]; | |
| 116 | + $data["description"] = $row["description"]; | |
| 204 | 117 | $data["url"] = $row["url"]; |
| 205 | 118 | $data["text"] = $row["text"]; |
| 206 | 119 | $data["new_window"] = (isset($row["new_window"]) && $row["new_window"] != "") ? 1 : 0; |
| 207 | - $data["nofollow"] = (isset($row["nofollow"]) && $row["nofollow"] != "") ? 1 : 0; | |
| 208 | - | |
| 209 | - $data["font"] = $row["text_font_family"]; | |
| 210 | - $data["font_size"] = $row["text_font_size"]; | |
| 211 | - $data["font_style"] = $row["text_font_style"]; | |
| 212 | - $data["font_weight"] = $row["text_font_weight"]; | |
| 213 | - $data["text_shadow_offset_left"] = $row["text_shadow_offset_left"]; | |
| 214 | - $data["text_shadow_offset_top"] = $row["text_shadow_offset_top"]; | |
| 215 | - $data["text_shadow_width"] = $row["text_shadow_width"]; | |
| 216 | - $data["padding_top"] = $row["text_padding_top"]; | |
| 217 | - $data["padding_right"] = $row["text_padding_right"]; | |
| 218 | - $data["padding_bottom"] = $row["text_padding_bottom"]; | |
| 120 | + $data["nofollow"] = (isset($row["nofollow"]) && $row["nofollow"] != "") ? 1 : 0; | |
| 121 | + | |
| 122 | + $data["font"] = $row["text_font_family"]; | |
| 123 | + $data["font_size"] = $row["text_font_size"]; | |
| 124 | + $data["font_style"] = $row["text_font_style"]; | |
| 125 | + $data["font_weight"] = $row["text_font_weight"]; | |
| 126 | + $data["text_shadow_offset_left"] = $row["text_shadow_offset_left"]; | |
| 127 | + $data["text_shadow_offset_top"] = $row["text_shadow_offset_top"]; | |
| 128 | + $data["text_shadow_width"] = $row["text_shadow_width"]; | |
| 129 | + $data["padding_top"] = $row["text_padding_top"]; | |
| 130 | + $data["padding_right"] = $row["text_padding_right"]; | |
| 131 | + $data["padding_bottom"] = $row["text_padding_bottom"]; | |
| 219 | 132 | $data["padding_left"] = $row["text_padding_left"]; |
| 220 | - | |
| 221 | - $data["radius_top_left"] = $row["border_radius_top_left"]; | |
| 222 | - $data["radius_top_right"] = $row["border_radius_top_right"]; | |
| 223 | - $data["radius_bottom_left"] = $row["border_radius_bottom_left"]; | |
| 224 | - $data["radius_bottom_right"] = $row["border_radius_bottom_right"]; | |
| 225 | - $data["border_style"] = $row["border_style"]; | |
| 226 | - $data["border_width"] = $row["border_width"]; | |
| 227 | - $data["box_shadow_offset_left"] = $row["box_shadow_offset_left"]; | |
| 228 | - $data["box_shadow_offset_top"] = $row["box_shadow_offset_top"]; | |
| 229 | - $data["box_shadow_width"] = $row["box_shadow_width"]; | |
| 230 | - | |
| 231 | - $data["text_color"] = $row["text_color"]; | |
| 232 | - $data["text_shadow_color"] = $row["text_shadow_color"]; | |
| 233 | - $data["gradient_start_color"] = $row["gradient_start_color"]; | |
| 234 | - $data["gradient_end_color"] = $row["gradient_end_color"]; | |
| 235 | - $data["border_color"] = $row["border_color"]; | |
| 236 | - $data["box_shadow_color"] = $row["box_shadow_color"]; | |
| 237 | - | |
| 238 | - $data["text_color_hover"] = $row["text_color_hover"]; | |
| 239 | - $data["text_shadow_color_hover"] = $row["text_shadow_color_hover"]; | |
| 240 | - $data["gradient_start_color_hover"] = $row["gradient_start_color_hover"]; | |
| 241 | - $data["gradient_end_color_hover"] = $row["gradient_end_color_hover"]; | |
| 242 | - $data["border_color_hover"] = $row["border_color_hover"]; | |
| 243 | - $data["box_shadow_color_hover"] = $row["box_shadow_color_hover"]; | |
| 244 | - | |
| 245 | - $data["gradient_stop"] = (isset($row["gradient_stop"])) ? $row["gradient_stop"] : 45; | |
| 133 | + | |
| 134 | + $data["radius_top_left"] = $row["border_radius_top_left"]; | |
| 135 | + $data["radius_top_right"] = $row["border_radius_top_right"]; | |
| 136 | + $data["radius_bottom_left"] = $row["border_radius_bottom_left"]; | |
| 137 | + $data["radius_bottom_right"] = $row["border_radius_bottom_right"]; | |
| 138 | + $data["border_style"] = $row["border_style"]; | |
| 139 | + $data["border_width"] = $row["border_width"]; | |
| 140 | + $data["box_shadow_offset_left"] = $row["box_shadow_offset_left"]; | |
| 141 | + $data["box_shadow_offset_top"] = $row["box_shadow_offset_top"]; | |
| 142 | + $data["box_shadow_width"] = $row["box_shadow_width"]; | |
| 143 | + | |
| 144 | + $data["text_color"] = $row["text_color"]; | |
| 145 | + $data["text_shadow_color"] = $row["text_shadow_color"]; | |
| 146 | + $data["gradient_start_color"] = $row["gradient_start_color"]; | |
| 147 | + $data["gradient_end_color"] = $row["gradient_end_color"]; | |
| 148 | + $data["border_color"] = $row["border_color"]; | |
| 149 | + $data["box_shadow_color"] = $row["box_shadow_color"]; | |
| 150 | + | |
| 151 | + $data["text_color_hover"] = $row["text_color_hover"]; | |
| 152 | + $data["text_shadow_color_hover"] = $row["text_shadow_color_hover"]; | |
| 153 | + $data["gradient_start_color_hover"] = $row["gradient_start_color_hover"]; | |
| 154 | + $data["gradient_end_color_hover"] = $row["gradient_end_color_hover"]; | |
| 155 | + $data["border_color_hover"] = $row["border_color_hover"]; | |
| 156 | + $data["box_shadow_color_hover"] = $row["box_shadow_color_hover"]; | |
| 157 | + | |
| 158 | + $data["gradient_stop"] = (isset($row["gradient_stop"])) ? $row["gradient_stop"] : 45; | |
| 246 | 159 | $data["gradient_start_opacity"] = (isset($row["gradient_start_opacity"])) ? $row["gradient_start_opacity"] : 100; |
| 247 | 160 | $data["gradient_end_opacity"] = (isset($row["gradient_end_opacity"])) ? $row["gradient_end_opacity"] : 100; |
| 248 | - $data["gradient_start_opacity_hover"] = (isset($row["gradient_start_opacity_hover"])) ? $row["gradient_start_opacity_hover"] : 100; | |
| 161 | + $data["gradient_start_opacity_hover"] = (isset($row["gradient_start_opacity_hover"])) ? $row["gradient_start_opacity_hover"] : 100; | |
| 249 | 162 | $data["gradient_end_opacity_hover"] = (isset($row["gradient_end_opacity_hover"])) ? $row["gradient_end_opacity_hover"] : 100; |
| 250 | - | |
| 251 | - $data["container_enabled"] = (isset($row["container_enabled"]) && $row["container_enabled"] != "") ? 1 : 0; | |
| 252 | - $data["container_center_div_wrap"] = (isset($row["container_center_div_wrap_enabled"]) && $row["container_center_div_wrap_enabled"] != "") ? 1 : 0; | |
| 253 | - $data["container_width"] = isset($row["container_width"]) ? $row["container_width"] : ''; | |
| 254 | - $data["container_margin_top"] = isset($row["container_margin_top"]) ? $row["container_margin_top"] : ''; | |
| 255 | - $data["container_margin_right"] = isset($row["container_margin_right"]) ? $row["container_margin_right"] : ''; | |
| 256 | - $data["container_margin_bottom"] = isset($row["container_margin_bottom"]) ? $row["container_margin_right"] : ''; | |
| 257 | - $data["container_margin_left"] = isset($row["container_margin_left"]) ? $row["container_margin_left"] : ''; | |
| 163 | + | |
| 164 | + $data["container_enabled"] = (isset($row["container_enabled"]) && $row["container_enabled"] != "") ? 1 : 0; | |
| 165 | + $data["container_center_div_wrap"] = (isset($row["container_center_div_wrap_enabled"]) && $row["container_center_div_wrap_enabled"] != "") ? 1 : 0; | |
| 166 | + $data["container_width"] = isset($row["container_width"]) ? $row["container_width"] : ''; | |
| 167 | + $data["container_margin_top"] = isset($row["container_margin_top"]) ? $row["container_margin_top"] : ''; | |
| 168 | + $data["container_margin_right"] = isset($row["container_margin_right"]) ? $row["container_margin_right"] : ''; | |
| 169 | + $data["container_margin_bottom"] = isset($row["container_margin_bottom"]) ? $row["container_margin_right"] : ''; | |
| 170 | + $data["container_margin_left"] = isset($row["container_margin_left"]) ? $row["container_margin_left"] : ''; | |
| 258 | 171 | $data["container_alignment"] = isset($row["container_alignment"]) ? $row["container_alignment"] : ''; |
| 259 | - | |
| 260 | - $data["status"] = (isset($row["status"])) ? $row["status"] : 'publish'; | |
| 261 | - | |
| 262 | - $data["external_css"] = (isset($row["external_css"]) && $row["external_css"] != "") ? 1: 0; | |
| 172 | + | |
| 173 | + $data["status"] = (isset($row["status"])) ? $row["status"] : 'publish'; | |
| 174 | + | |
| 175 | + $data["external_css"] = (isset($row["external_css"]) && $row["external_css"] != "") ? 1: 0; | |
| 263 | 176 | $data["important_css"] = (isset($row["important_css"]) && $row["important_css"] != "") ? 1 : 0; |
| 264 | - | |
| 177 | + | |
| 265 | 178 | // icon |
| 266 | - $data["use_fa_icon"] = (isset($row["use_font_awesome_icon"]) && $row["use_font_awesome_icon"] != '') ? 1 : 0; | |
| 179 | + $data["use_fa_icon"] = (isset($row["use_font_awesome_icon"]) && $row["use_font_awesome_icon"] != '') ? 1 : 0; | |
| 267 | 180 | $data["fa_icon_value"] = (isset($row["font_awesome_icon"])) ? $row["font_awesome_icon"] : ''; |
| 268 | - $data["fa_icon_size"] = (isset($row["font_awesome_icon_size"])) ? $row["font_awesome_icon_size"] : ''; | |
| 181 | + $data["fa_icon_size"] = (isset($row["font_awesome_icon_size"])) ? $row["font_awesome_icon_size"] : ''; | |
| 269 | 182 | $data["icon_url"] = (isset($row["icon_url"])) ? $row["icon_url"] : ''; |
| 270 | - $data["icon_alt"] = (isset($row["icon_alt"])) ? $row["icon_alt"] : ''; | |
| 183 | + $data["icon_alt"] = (isset($row["icon_alt"])) ? $row["icon_alt"] : ''; | |
| 271 | 184 | $data["icon_position"] = (isset($row["icon_position"])) ? $row["icon_position"] : ''; |
| 272 | 185 | $data["icon_padding_top"] = (isset($row["icon_padding_top"])) ? $row["icon_padding_top"] : ''; |
| 273 | 186 | $data["icon_padding_bottom"] = (isset($row["icon_padding_bottom"])) ? $row["icon_padding_bottom"] : ''; |
| 274 | 187 | $data["icon_padding_left"] = (isset($row["icon_padding_left"])) ? $row["icon_padding_left"] : ''; |
| @@ -274,35 +187,35 @@ | ||
| 274 | 187 | $data["icon_padding_left"] = (isset($row["icon_padding_left"])) ? $row["icon_padding_left"] : ''; |
| 275 | 188 | $data["icon_padding_right"] = (isset($row["icon_padding_right"]))? $row["icon_padding_right"] : ''; |
| 276 | 189 | |
| 277 | 190 | // dimension |
| 278 | - $data["button_width"] = (isset($row["width"])) ? $row["width"] : ''; | |
| 279 | - $data["button_height"] = (isset($row["height"])) ? $row["height"] : ''; | |
| 191 | + $data["button_width"] = (isset($row["width"])) ? $row["width"] : ''; | |
| 192 | + $data["button_height"] = (isset($row["height"])) ? $row["height"] : ''; | |
| 280 | 193 | |
| 281 | - // colorPro | |
| 282 | - $data["icon_color"] = (isset($row["icon_color"])) ? $row["icon_color"] : ''; | |
| 283 | - $data["icon_color_hover"] = (isset($row["icon_color_hover"])) ? $row["icon_color_hover"] : ''; | |
| 284 | - | |
| 285 | - // textPro | |
| 286 | - $data["text2"] = $row["text2"]; | |
| 287 | - $data["font2"] = $row["text2_font_family"]; | |
| 288 | - $data["font_size2"] = $row["text2_font_size"]; | |
| 289 | - $data["font_style2"] = $row["text2_font_style"]; | |
| 290 | - $data["font_weight2"] = $row["text2_font_weight"]; | |
| 291 | - $data["padding_top2"] = $row["text2_padding_top"]; | |
| 292 | - $data["padding_right2"] = $row["text2_padding_right"]; | |
| 293 | - $data["padding_bottom2"] = $row["text2_padding_bottom"]; | |
| 194 | + // colorPro | |
| 195 | + $data["icon_color"] = (isset($row["icon_color"])) ? $row["icon_color"] : ''; | |
| 196 | + $data["icon_color_hover"] = (isset($row["icon_color_hover"])) ? $row["icon_color_hover"] : ''; | |
| 197 | + | |
| 198 | + // textPro | |
| 199 | + $data["text2"] = $row["text2"]; | |
| 200 | + $data["font2"] = $row["text2_font_family"]; | |
| 201 | + $data["font_size2"] = $row["text2_font_size"]; | |
| 202 | + $data["font_style2"] = $row["text2_font_style"]; | |
| 203 | + $data["font_weight2"] = $row["text2_font_weight"]; | |
| 204 | + $data["padding_top2"] = $row["text2_padding_top"]; | |
| 205 | + $data["padding_right2"] = $row["text2_padding_right"]; | |
| 206 | + $data["padding_bottom2"] = $row["text2_padding_bottom"]; | |
| 294 | 207 | $data["padding_left2"] = $row["text2_padding_left"]; |
| 295 | - | |
| 296 | - $data["text_align"] = (isset($row["text_align"])) ? $row["text_align"] : ''; | |
| 297 | - $data["text_align2"] = (isset($row["text2_align"])) ? $row["text2_align"] : ''; | |
| 298 | - // here old / new Pro Database fields. | |
| 299 | - | |
| 208 | + | |
| 209 | + $data["text_align"] = (isset($row["text_align"])) ? $row["text_align"] : ''; | |
| 210 | + $data["text_align2"] = (isset($row["text2_align"])) ? $row["text2_align"] : ''; | |
| 211 | + // here old / new Pro Database fields. | |
| 212 | + | |
| 300 | 213 | return $data; |
| 301 | 214 | } |
| 302 | - | |
| 215 | + | |
| 303 | 216 | static function deactivate_plugin() |
| 304 | - { | |
| 217 | + { | |
| 305 | 218 | delete_option(MAXBUTTONS_VERSION_KEY); |
| 306 | 219 | } |
| 307 | 220 | |
| 308 | 221 | |
| @@ -313,88 +226,88 @@ | ||
| 313 | 226 | |
| 314 | 227 | |
| 315 | 228 | static function create_database_table() { |
| 316 | 229 | //global $maxbuttons_installed_version; |
| 317 | - | |
| 230 | + | |
| 318 | 231 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 319 | - | |
| 232 | + | |
| 320 | 233 | $table_name = maxUtils::get_table_name(); |
| 321 | - $button = MB()->getClass('button'); | |
| 234 | + $button = new maxButton(); | |
| 322 | 235 | $blocks = $button->getBlocks(); |
| 323 | - | |
| 236 | + | |
| 324 | 237 | // IMPORTANT: There MUST be two spaces between the PRIMARY KEY keywords |
| 325 | 238 | // and the column name, and the column name MUST be in parenthesis. |
| 326 | - $sql = "CREATE TABLE " . $table_name . " ( | |
| 327 | - id int NOT NULL AUTO_INCREMENT, | |
| 328 | - name varchar(100) NULL, | |
| 329 | - status varchar(10) default 'publish' NOT NULL, | |
| 330 | - cache text, | |
| 239 | + $sql = "CREATE TABLE " . $table_name . " ( | |
| 240 | + id int NOT NULL AUTO_INCREMENT, | |
| 241 | + name varchar(100) NULL, | |
| 242 | + status varchar(10) default 'publish' NOT NULL, | |
| 243 | + cache text, | |
| 331 | 244 | "; |
| 245 | + | |
| 332 | 246 | |
| 333 | - | |
| 334 | 247 | foreach($blocks as $block) |
| 335 | 248 | { |
| 336 | - $block_name = $block->get_name(); | |
| 337 | - | |
| 338 | - $sql .= "" . $block_name . " TEXT NULL, \n "; | |
| 249 | + $block_name = $block->get_name(); | |
| 250 | + | |
| 251 | + $sql .= "" . $block_name . " TEXT NULL, \n "; | |
| 339 | 252 | } |
| 340 | - | |
| 253 | + | |
| 341 | 254 | $sql .= "updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 342 | - created TIMESTAMP DEFAULT 0 NOT NULL, | |
| 343 | - PRIMARY KEY (id) )"; | |
| 255 | + created TIMESTAMP DEFAULT 0 NOT NULL, | |
| 256 | + PRIMARY KEY (id) )"; | |
| 344 | 257 | |
| 345 | - $result = dbDelta($sql); // always dbdelta | |
| 258 | + $result = dbDelta($sql); // always dbdelta | |
| 346 | 259 | |
| 347 | 260 | // Reset the cache if there were any left from before |
| 348 | - $button->reset_cache(); | |
| 261 | + $button->reset_cache(); | |
| 349 | 262 | |
| 350 | 263 | // Collection table |
| 351 | 264 | $collection_table_name = maxUtils::get_collection_table_name(); |
| 352 | - | |
| 353 | - $sql = "CREATE TABLE " . $collection_table_name . " ( | |
| 354 | - meta_id int(11) NOT NULL AUTO_INCREMENT, | |
| 355 | - collection_id int(11) NOT NULL, | |
| 356 | - collection_key varchar(255), | |
| 357 | - collection_value text, | |
| 358 | - PRIMARY KEY (meta_id) ) | |
| 359 | - | |
| 265 | + | |
| 266 | + $sql = "CREATE TABLE " . $collection_table_name . " ( | |
| 267 | + meta_id int(11) NOT NULL AUTO_INCREMENT, | |
| 268 | + collection_id int(11) NOT NULL, | |
| 269 | + collection_key varchar(255), | |
| 270 | + collection_value text, | |
| 271 | + PRIMARY KEY (meta_id) ) | |
| 272 | + | |
| 360 | 273 | "; |
| 361 | 274 | |
| 362 | 275 | dbDelta($sql); |
| 363 | - | |
| 276 | + | |
| 364 | 277 | $collection_trans_table = maxUtils::get_coltrans_table_name(); |
| 365 | - $sql = "CREATE TABLE $collection_trans_table ( | |
| 366 | - name varchar(1000), | |
| 278 | + $sql = "CREATE TABLE $collection_trans_table ( | |
| 279 | + name varchar(1000), | |
| 367 | 280 | value varchar(255), |
| 368 | 281 | expire int(11) |
| 369 | - ); | |
| 370 | - "; | |
| 371 | - $res = dbDelta($sql); | |
| 282 | + ); | |
| 283 | + "; | |
| 284 | + $res = dbDelta($sql); | |
| 372 | 285 | } |
| 373 | - | |
| 286 | + | |
| 374 | 287 | /** Attempt to upgrade UTF table to UTFmb4 - see this article https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/ |
| 375 | 288 | */ |
| 376 | - public static function upgradeUTF() | |
| 289 | + public static function upgradeUTF() | |
| 377 | 290 | { |
| 378 | 291 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 379 | - | |
| 380 | - if (! function_exists('maybe_convert_table_to_utf8mb4')) | |
| 381 | - return; // Versions before 4.2.0 | |
| 382 | - | |
| 292 | + | |
| 293 | + if (! function_exists('maybe_convert_table_to_utf8mb4')) | |
| 294 | + return; // Versions before 4.2.0 | |
| 295 | + | |
| 383 | 296 | $table_name = maxUtils::get_table_name(); |
| 384 | 297 | $collection_table_name = maxUtils::get_collection_table_name(); |
| 385 | - | |
| 298 | + | |
| 386 | 299 | maybe_convert_table_to_utf8mb4($table_name); |
| 387 | - maybe_convert_table_to_utf8mb4($collection_table_name); | |
| 300 | + maybe_convert_table_to_utf8mb4($collection_table_name); | |
| 388 | 301 | } |
| 389 | - | |
| 302 | + | |
| 390 | 303 | /** Routine for activation for WPMU - All blogs */ |
| 391 | 304 | public static function call_function_for_each_site($function) { |
| 392 | 305 | global $wpdb; |
| 393 | - | |
| 306 | + | |
| 394 | 307 | // Hold this so we can switch back to it |
| 395 | 308 | $root_blog = $wpdb->blogid; |
| 396 | - | |
| 309 | + | |
| 397 | 310 | // Get all the blogs/sites in the network and invoke the function for each one |
| 398 | 311 | $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
| 399 | 312 | foreach ($blog_ids as $blog_id) { |
| 400 | 313 | switch_to_blog($blog_id); |
| @@ -399,9 +312,10 @@ | ||
| 399 | 312 | foreach ($blog_ids as $blog_id) { |
| 400 | 313 | switch_to_blog($blog_id); |
| 401 | 314 | call_user_func($function); |
| 402 | 315 | } |
| 403 | - | |
| 316 | + | |
| 404 | 317 | // Now switch back to the root blog |
| 405 | 318 | switch_to_blog($root_blog); |
| 406 | 319 | } |
| 407 | 320 | } // class |
| 321 | + | |