| @@ -29,8 +29,9 @@ | ||
| 29 | 29 | * |
| 30 | 30 | * @see WP_Data_Access_Switch::activate() |
| 31 | 31 | * @see WP_Data_Access_Switch::deactivate() |
| 32 | 32 | */ |
| 33 | +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound | |
| 33 | 34 | class WP_Data_Access_Switch { |
| 34 | 35 | /** |
| 35 | 36 | * Activate plugin WP Data Access |
| 36 | 37 | * |
| @@ -54,10 +55,11 @@ | ||
| 54 | 55 | // Activate plugin. |
| 55 | 56 | if ( is_multisite() ) { |
| 56 | 57 | global $wpdb; |
| 57 | 58 | // Multisite installation. |
| 59 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 58 | 60 | $blogids = $wpdb->get_col( "select blog_id from {$wpdb->blogs}" ); |
| 59 | - // db call ok; no-cache ok. | |
| 61 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 60 | 62 | foreach ( $blogids as $blog_id ) { |
| 61 | 63 | // Activate blog. |
| 62 | 64 | switch_to_blog( $blog_id ); |
| 63 | 65 | self::activate_blog(); |
| @@ -140,10 +142,11 @@ | ||
| 140 | 142 | // Deactivate plugin. |
| 141 | 143 | if ( is_multisite() ) { |
| 142 | 144 | global $wpdb; |
| 143 | 145 | // Multisite installation. |
| 146 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 144 | 147 | $blogids = $wpdb->get_col( "select blog_id from {$wpdb->blogs}" ); |
| 145 | - // db call ok; no-cache ok. | |
| 148 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 146 | 149 | foreach ( $blogids as $blog_id ) { |
| 147 | 150 | // Deactivate blog. |
| 148 | 151 | switch_to_blog( $blog_id ); |
| 149 | 152 | self::flush_rewrite_rules(); |
| @@ -161,53 +164,43 @@ | ||
| 161 | 164 | |
| 162 | 165 | private static function set_legacy_tools() { |
| 163 | 166 | // Get current legacy tool settings |
| 164 | 167 | $stored_legacy_tools = get_option( 'wpda_plugin_legacy_tools' ); |
| 165 | - $option_legacy_tools = \WPDataAccess\Utilities\WPDA_Legacy_Tool_Visibility::get(); | |
| 166 | - // Update legacy tool settings | |
| 167 | - if ( 0 === $option_legacy_tools['tables'] ) { | |
| 168 | - $option_legacy_tools['tables'][0] = false; | |
| 169 | - } else { | |
| 170 | - if ( false === $stored_legacy_tools ) { | |
| 171 | - $option_legacy_tools['tables'][0] = true; | |
| 168 | + if ( false === $stored_legacy_tools ) { | |
| 169 | + // Use default for fresh installation | |
| 170 | + // Update if legacy tool is actively used | |
| 171 | + $option_legacy_tools = \WPDataAccess\Utilities\WPDA_Legacy_Tool_Visibility::get(); | |
| 172 | + $option_updated = false; | |
| 173 | + if ( 0 < $option_legacy_tools['tables'][1] ) { | |
| 174 | + $option_legacy_tools['tables'] = array(true, $option_legacy_tools['tables'][1]); | |
| 175 | + $option_updated = true; | |
| 172 | 176 | } |
| 173 | - } | |
| 174 | - if ( 0 === $option_legacy_tools['forms'] ) { | |
| 175 | - $option_legacy_tools['forms'][0] = false; | |
| 176 | - } else { | |
| 177 | - if ( false === $stored_legacy_tools ) { | |
| 178 | - $option_legacy_tools['forms'][0] = true; | |
| 177 | + if ( 0 < $option_legacy_tools['forms'][1] ) { | |
| 178 | + $option_legacy_tools['forms'] = array(true, $option_legacy_tools['forms'][1]); | |
| 179 | + $option_updated = true; | |
| 179 | 180 | } |
| 180 | - } | |
| 181 | - if ( 0 === $option_legacy_tools['templates'] ) { | |
| 182 | - $option_legacy_tools['templates'][0] = false; | |
| 183 | - } else { | |
| 184 | - if ( false === $stored_legacy_tools ) { | |
| 185 | - $option_legacy_tools['templates'][0] = true; | |
| 181 | + if ( 0 < $option_legacy_tools['templates'][1] ) { | |
| 182 | + $option_legacy_tools['templates'] = array(true, $option_legacy_tools['templates'][1]); | |
| 183 | + $option_updated = true; | |
| 186 | 184 | } |
| 187 | - } | |
| 188 | - if ( 0 === $option_legacy_tools['designer'] ) { | |
| 189 | - $option_legacy_tools['designer'][0] = false; | |
| 190 | - } else { | |
| 191 | - if ( false === $stored_legacy_tools ) { | |
| 192 | - $option_legacy_tools['designer'][0] = true; | |
| 185 | + if ( 0 < $option_legacy_tools['designer'][1] ) { | |
| 186 | + $option_legacy_tools['designer'] = array(true, $option_legacy_tools['designer'][1]); | |
| 187 | + $option_updated = true; | |
| 193 | 188 | } |
| 194 | - } | |
| 195 | - if ( 0 === $option_legacy_tools['dashboards'] ) { | |
| 196 | - $option_legacy_tools['dashboards'][0] = false; | |
| 197 | - } else { | |
| 198 | - if ( false === $stored_legacy_tools ) { | |
| 199 | - $option_legacy_tools['dashboards'][0] = true; | |
| 189 | + if ( 0 < $option_legacy_tools['dashboards'][1] ) { | |
| 190 | + $option_legacy_tools['dashboards'] = array(true, $option_legacy_tools['dashboards'][1]); | |
| 191 | + $option_updated = true; | |
| 200 | 192 | } |
| 201 | - } | |
| 202 | - if ( 0 === $option_legacy_tools['charts'] ) { | |
| 203 | - $option_legacy_tools['charts'][0] = false; | |
| 204 | - } else { | |
| 205 | - if ( false === $stored_legacy_tools ) { | |
| 206 | - $option_legacy_tools['charts'][0] = true; | |
| 193 | + if ( 0 < $option_legacy_tools['charts'][1] ) { | |
| 194 | + $option_legacy_tools['charts'] = array(true, $option_legacy_tools['charts'][1]); | |
| 195 | + $option_updated = true; | |
| 207 | 196 | } |
| 197 | + if ( $option_updated ) { | |
| 198 | + // Save legacy tool settings. | |
| 199 | + WPDA::set_option( WPDA::OPTION_PLUGIN_LEGACY_TOOLS, $option_legacy_tools ); | |
| 200 | + } | |
| 208 | 201 | } |
| 209 | - // Save legacy tool settings. | |
| 210 | - WPDA::set_option( WPDA::OPTION_PLUGIN_LEGACY_TOOLS, $option_legacy_tools ); | |
| 211 | 202 | } |
| 212 | 203 | |
| 213 | 204 | } |
| 205 | + | |
| 206 | +// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound | |