Complex classes like Plugin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Plugin, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | final class Plugin { |
||
| 18 | /** |
||
| 19 | * @var string The plugin version. |
||
| 20 | * |
||
| 21 | * @api |
||
| 22 | * @since 2.0 |
||
| 23 | */ |
||
| 24 | public static $version = GV_PLUGIN_VERSION; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string Minimum WordPress version. |
||
| 28 | * |
||
| 29 | * GravityView requires at least this version of WordPress to function properly. |
||
| 30 | */ |
||
| 31 | private static $min_wp_version = GV_MIN_WP_VERSION; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string Minimum Gravity Forms version. |
||
| 35 | * |
||
| 36 | * GravityView requires at least this version of Gravity Forms to function properly. |
||
| 37 | */ |
||
| 38 | public static $min_gf_version = GV_MIN_GF_VERSION; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string Minimum PHP version. |
||
| 42 | * |
||
| 43 | * GravityView requires at least this version of PHP to function properly. |
||
| 44 | */ |
||
| 45 | private static $min_php_version = GV_MIN_PHP_VERSION; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string|bool Minimum future PHP version. |
||
| 49 | * |
||
| 50 | * GravityView will require this version of PHP soon. False if no future PHP version changes are planned. |
||
| 51 | */ |
||
| 52 | private static $future_min_php_version = GV_FUTURE_MIN_PHP_VERSION; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string|bool Minimum future Gravity Forms version. |
||
| 56 | * |
||
| 57 | * GravityView will require this version of Gravity Forms soon. False if no future Gravity Forms version changes are planned. |
||
| 58 | */ |
||
| 59 | private static $future_min_gf_version = GV_FUTURE_MIN_GF_VERSION; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var \GV\Plugin The \GV\Plugin static instance. |
||
| 63 | */ |
||
| 64 | private static $__instance = null; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var \GV\Addon_Settings The plugin "addon" settings. |
||
| 68 | * |
||
| 69 | * @api |
||
| 70 | * @since 2.0 |
||
| 71 | */ |
||
| 72 | public $settings; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string The GFQuery functionality identifier. |
||
| 76 | */ |
||
| 77 | const FEATURE_GFQUERY = 'gfquery'; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string The joins functionality identifier. |
||
| 81 | */ |
||
| 82 | const FEATURE_JOINS = 'joins'; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string The unions functionality identifier. |
||
| 86 | */ |
||
| 87 | const FEATURE_UNIONS = 'unions'; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string The REST API functionality identifier. |
||
| 91 | */ |
||
| 92 | const FEATURE_REST = 'rest_api'; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get the global instance of \GV\Plugin. |
||
| 96 | * |
||
| 97 | * @return \GV\Plugin The global instance of GravityView Plugin. |
||
| 98 | */ |
||
| 99 | public static function get() { |
||
| 105 | |||
| 106 | |||
| 107 | private function __construct() { |
||
| 123 | |||
| 124 | public function load_license_settings() { |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Check whether GravityView is network activated. |
||
| 137 | * |
||
| 138 | * @return bool Whether it's network activated or not. |
||
| 139 | */ |
||
| 140 | 1 | public static function is_network_activated() { |
|
| 141 | |||
| 142 | 1 | $plugin_basename = plugin_basename( GRAVITYVIEW_FILE ); |
|
| 143 | |||
| 144 | 1 | return is_multisite() && ( function_exists( 'is_plugin_active_for_network' ) && is_plugin_active_for_network( $plugin_basename ) ); |
|
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Include more legacy stuff. |
||
| 149 | * |
||
| 150 | * @param boolean $force Whether to force the includes. |
||
| 151 | * |
||
| 152 | * @return void |
||
| 153 | */ |
||
| 154 | public function include_legacy_frontend( $force = false ) { |
||
| 155 | |||
| 156 | if ( gravityview()->request->is_admin() && ! $force ) { |
||
| 157 | return; |
||
| 158 | } |
||
| 159 | |||
| 160 | include_once $this->dir( 'includes/class-gravityview-image.php' ); |
||
| 161 | include_once $this->dir( 'includes/class-template.php' ); |
||
| 162 | include_once $this->dir( 'includes/class-api.php' ); |
||
| 163 | include_once $this->dir( 'includes/class-frontend-views.php' ); |
||
| 164 | include_once $this->dir( 'includes/class-gravityview-change-entry-creator.php' ); |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded |
||
| 168 | * |
||
| 169 | * @deprecated Use `gravityview/loaded` along with \GV\Request::is_admin(), etc. |
||
| 170 | * |
||
| 171 | * Nice place to insert extensions' frontend stuff |
||
| 172 | */ |
||
| 173 | do_action( 'gravityview_include_frontend_actions' ); |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Load more legacy core files. |
||
| 178 | * |
||
| 179 | * @return void |
||
| 180 | */ |
||
| 181 | public function include_legacy_core() { |
||
| 182 | |||
| 183 | if ( ! class_exists( '\GravityView_Extension' ) ) { |
||
| 184 | include_once $this->dir( 'includes/class-gravityview-extension.php' ); |
||
| 185 | } |
||
| 186 | |||
| 187 | // Load fields |
||
| 188 | include_once $this->dir( 'includes/fields/class-gravityview-fields.php' ); |
||
| 189 | include_once $this->dir( 'includes/fields/class-gravityview-field.php' ); |
||
| 190 | |||
| 191 | // Load all field files automatically |
||
| 192 | foreach ( glob( $this->dir( 'includes/fields/class-gravityview-field*.php' ) ) as $gv_field_filename ) { |
||
| 193 | include_once $gv_field_filename; |
||
| 194 | } |
||
| 195 | |||
| 196 | include_once $this->dir( 'includes/class-gravityview-entry-approval-status.php' ); |
||
| 197 | include_once $this->dir( 'includes/class-gravityview-entry-approval.php' ); |
||
| 198 | |||
| 199 | include_once $this->dir( 'includes/class-gravityview-entry-notes.php' ); |
||
| 200 | include_once $this->dir( 'includes/load-plugin-and-theme-hooks.php' ); |
||
| 201 | |||
| 202 | // Load Extensions |
||
| 203 | // @todo: Convert to a scan of the directory or a method where this all lives |
||
| 204 | include_once $this->dir( 'includes/extensions/edit-entry/class-edit-entry.php' ); |
||
| 205 | include_once $this->dir( 'includes/extensions/delete-entry/class-delete-entry.php' ); |
||
| 206 | include_once $this->dir( 'includes/extensions/entry-notes/class-gravityview-field-notes.php' ); |
||
| 207 | |||
| 208 | // Load WordPress Widgets |
||
| 209 | include_once $this->dir( 'includes/wordpress-widgets/register-wordpress-widgets.php' ); |
||
| 210 | |||
| 211 | // Load GravityView Widgets |
||
| 212 | include_once $this->dir( 'includes/widgets/register-gravityview-widgets.php' ); |
||
| 213 | |||
| 214 | // Add oEmbed |
||
| 215 | include_once $this->dir( 'includes/class-api.php' ); |
||
| 216 | include_once $this->dir( 'includes/class-oembed.php' ); |
||
| 217 | |||
| 218 | // Add logging |
||
| 219 | include_once $this->dir( 'includes/class-gravityview-logging.php' ); |
||
| 220 | |||
| 221 | include_once $this->dir( 'includes/class-ajax.php' ); |
||
| 222 | include_once $this->dir( 'includes/class-gravityview-html-elements.php' ); |
||
| 223 | include_once $this->dir( 'includes/class-frontend-views.php' ); |
||
| 224 | include_once $this->dir( 'includes/class-gravityview-admin-bar.php' ); |
||
| 225 | include_once $this->dir( 'includes/class-gravityview-entry-list.php' ); |
||
| 226 | include_once $this->dir( 'includes/class-gravityview-merge-tags.php'); /** @since 1.8.4 */ |
||
| 227 | include_once $this->dir( 'includes/class-data.php' ); |
||
| 228 | include_once $this->dir( 'includes/class-gravityview-shortcode.php' ); |
||
| 229 | include_once $this->dir( 'includes/class-gravityview-entry-link-shortcode.php' ); |
||
| 230 | include_once $this->dir( 'includes/class-gvlogic-shortcode.php' ); |
||
| 231 | include_once $this->dir( 'includes/presets/register-default-templates.php' ); |
||
| 232 | |||
| 233 | if ( class_exists( '\GFFormsModel' ) ) { |
||
| 234 | include_once $this->dir( 'includes/class-gravityview-gfformsmodel.php' ); |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Load the translations. |
||
| 240 | * |
||
| 241 | * Order of look-ups: |
||
| 242 | * |
||
| 243 | * 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core) |
||
| 244 | * 2. /wp-content/mu-plugins/gravityview-{locale}.mo |
||
| 245 | * 3. /wp-content/mu-plugins/languages/gravityview-{locale}.mo |
||
| 246 | * 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo |
||
| 247 | * |
||
| 248 | * @return void |
||
| 249 | */ |
||
| 250 | public function load_textdomain() { |
||
| 251 | |||
| 252 | $domain = 'gravityview'; |
||
| 253 | |||
| 254 | // 1. /wp-content/languages/plugins/gravityview-{locale}.mo (loaded by WordPress Core) |
||
| 255 | if ( is_textdomain_loaded( $domain ) ) { |
||
| 256 | return; |
||
| 257 | } |
||
| 258 | |||
| 259 | // 2. /wp-content/languages/plugins/gravityview-{locale}.mo |
||
| 260 | // 3. /wp-content/mu-plugins/plugins/languages/gravityview-{locale}.mo |
||
| 261 | $loaded = load_muplugin_textdomain( $domain, '/languages/' ); |
||
| 262 | |||
| 263 | if ( $loaded ) { |
||
| 264 | return; |
||
| 265 | } |
||
| 266 | |||
| 267 | // 4. /wp-content/plugins/gravityview/languages/gravityview-{locale}.mo |
||
| 268 | $loaded = load_plugin_textdomain( $domain, false, $this->relpath( '/languages/' ) ); |
||
| 269 | |||
| 270 | if ( $loaded ) { |
||
| 271 | return; |
||
| 272 | } |
||
| 273 | |||
| 274 | // Pre-4.6 loading |
||
| 275 | // TODO: Remove when GV minimum version is WordPress 4.6.0 |
||
| 276 | $locale = apply_filters( 'plugin_locale', ( ( function_exists('get_user_locale') && is_admin() ) ? get_user_locale() : get_locale() ), 'gravityview' ); |
||
| 277 | |||
| 278 | $loaded = load_textdomain( 'gravityview', sprintf( '%s/%s-%s.mo', $this->dir('languages'), $domain, $locale ) ); |
||
| 279 | |||
| 280 | if( $loaded ) { |
||
| 281 | return; |
||
| 282 | } |
||
| 283 | |||
| 284 | gravityview()->log->error( sprintf( 'Unable to load textdomain for %s locale.', $locale ) ); |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Register hooks that are fired when the plugin is activated and deactivated. |
||
| 289 | * |
||
| 290 | * @return void |
||
| 291 | */ |
||
| 292 | public function register_activation_hooks() { |
||
| 293 | register_activation_hook( $this->dir( 'gravityview.php' ), array( $this, 'activate' ) ); |
||
| 294 | register_deactivation_hook( $this->dir( 'gravityview.php' ), array( $this, 'deactivate' ) ); |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Plugin activation function. |
||
| 299 | * |
||
| 300 | * @internal |
||
| 301 | * @return void |
||
| 302 | */ |
||
| 303 | 1 | public function activate() { |
|
| 304 | 1 | gravityview(); |
|
| 305 | |||
| 306 | 1 | if ( ! $this->is_compatible() ) { |
|
| 307 | return; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** Register the gravityview post type upon WordPress core init. */ |
||
| 311 | 1 | require_once $this->dir( 'future/includes/class-gv-view.php' ); |
|
| 312 | 1 | View::register_post_type(); |
|
| 313 | |||
| 314 | /** Add the entry rewrite endpoint. */ |
||
| 315 | 1 | require_once $this->dir( 'future/includes/class-gv-entry.php' ); |
|
| 316 | 1 | Entry::add_rewrite_endpoint(); |
|
| 317 | |||
| 318 | /** Flush all URL rewrites. */ |
||
| 319 | 1 | flush_rewrite_rules(); |
|
| 320 | |||
| 321 | 1 | update_option( 'gv_version', self::$version ); |
|
| 322 | |||
| 323 | /** Add the transient to redirect to configuration page. */ |
||
| 324 | 1 | set_transient( '_gv_activation_redirect', true, 60 ); |
|
| 325 | |||
| 326 | /** Clear settings transient. */ |
||
| 327 | 1 | delete_transient( 'gravityview_edd-activate_valid' ); |
|
| 328 | |||
| 329 | 1 | \GravityView_Roles_Capabilities::get_instance()->add_caps(); |
|
| 330 | 1 | } |
|
| 331 | |||
| 332 | /** |
||
| 333 | * Plugin deactivation function. |
||
| 334 | * |
||
| 335 | * @internal |
||
| 336 | * @return void |
||
| 337 | */ |
||
| 338 | public function deactivate() { |
||
| 339 | flush_rewrite_rules(); |
||
| 340 | } |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Retrieve an absolute path within the GravityView plugin directory. |
||
| 344 | * |
||
| 345 | * @api |
||
| 346 | * @since 2.0 |
||
| 347 | * |
||
| 348 | * @param string $path Optional. Append this extra path component. |
||
| 349 | * @return string The absolute path to the plugin directory. |
||
| 350 | */ |
||
| 351 | 113 | public function dir( $path = '' ) { |
|
| 352 | 113 | return wp_normalize_path( GRAVITYVIEW_DIR . ltrim( $path, '/' ) ); |
|
| 353 | } |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Retrieve a relative path to the GravityView plugin directory from the WordPress plugin directory |
||
| 357 | * |
||
| 358 | * @api |
||
| 359 | * @since 2.2.3 |
||
| 360 | * |
||
| 361 | * @param string $path Optional. Append this extra path component. |
||
| 362 | * @return string The relative path to the plugin directory from the plugin directory. |
||
| 363 | */ |
||
| 364 | 1 | public function relpath( $path = '' ) { |
|
| 365 | |||
| 366 | 1 | $dirname = trailingslashit( dirname( plugin_basename( GRAVITYVIEW_FILE ) ) ); |
|
| 367 | |||
| 368 | 1 | return wp_normalize_path( $dirname . ltrim( $path, '/' ) ); |
|
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Retrieve a URL within the GravityView plugin directory. |
||
| 373 | * |
||
| 374 | * @api |
||
| 375 | * @since 2.0 |
||
| 376 | * |
||
| 377 | * @param string $path Optional. Extra path appended to the URL. |
||
| 378 | * @return string The URL to this plugin, with trailing slash. |
||
| 379 | */ |
||
| 380 | 1 | public function url( $path = '/' ) { |
|
| 381 | 1 | return plugins_url( $path, $this->dir( 'gravityview.php' ) ); |
|
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Is everything compatible with this version of GravityView? |
||
| 386 | * |
||
| 387 | * @api |
||
| 388 | * @since 2.0 |
||
| 389 | * |
||
| 390 | * @return bool |
||
| 391 | */ |
||
| 392 | 4 | public function is_compatible() { |
|
| 393 | return |
||
| 394 | 4 | $this->is_compatible_php() |
|
| 395 | 4 | && $this->is_compatible_wordpress() |
|
| 396 | 4 | && $this->is_compatible_gravityforms(); |
|
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Is this version of GravityView compatible with the current version of PHP? |
||
| 401 | * |
||
| 402 | * @api |
||
| 403 | * @since 2.0 |
||
| 404 | * |
||
| 405 | * @return bool true if compatible, false otherwise. |
||
| 406 | */ |
||
| 407 | 4 | public function is_compatible_php() { |
|
| 408 | 4 | return version_compare( $this->get_php_version(), self::$min_php_version, '>=' ); |
|
| 409 | } |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Is this version of GravityView compatible with the future required version of PHP? |
||
| 413 | * |
||
| 414 | * @api |
||
| 415 | * @since 2.0 |
||
| 416 | * |
||
| 417 | * @return bool true if compatible, false otherwise. |
||
| 418 | */ |
||
| 419 | public function is_compatible_future_php() { |
||
| 420 | return version_compare( $this->get_php_version(), self::$future_min_php_version, '>=' ); |
||
| 421 | } |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Is this version of GravityView compatible with the current version of WordPress? |
||
| 425 | * |
||
| 426 | * @api |
||
| 427 | * @since 2.0 |
||
| 428 | * |
||
| 429 | * @param string $version Version to check against; otherwise uses GV_MIN_WP_VERSION |
||
| 430 | * |
||
| 431 | * @return bool true if compatible, false otherwise. |
||
| 432 | */ |
||
| 433 | 4 | public function is_compatible_wordpress( $version = null ) { |
|
| 434 | |||
| 435 | 4 | if( ! $version ) { |
|
|
|
|||
| 436 | 4 | $version = self::$min_wp_version; |
|
| 437 | } |
||
| 438 | |||
| 439 | 4 | return version_compare( $this->get_wordpress_version(), $version, '>=' ); |
|
| 440 | } |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Is this version of GravityView compatible with the current version of Gravity Forms? |
||
| 444 | * |
||
| 445 | * @api |
||
| 446 | * @since 2.0 |
||
| 447 | * |
||
| 448 | * @return bool true if compatible, false otherwise (or not active/installed). |
||
| 449 | */ |
||
| 450 | 4 | public function is_compatible_gravityforms() { |
|
| 451 | 4 | $version = $this->get_gravityforms_version(); |
|
| 452 | 4 | return $version ? version_compare( $version, self::$min_gf_version, '>=' ) : false; |
|
| 453 | } |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Is this version of GravityView compatible with the future version of Gravity Forms? |
||
| 457 | * |
||
| 458 | * @api |
||
| 459 | * @since 2.0 |
||
| 460 | * |
||
| 461 | * @return bool true if compatible, false otherwise (or not active/installed). |
||
| 462 | */ |
||
| 463 | public function is_compatible_future_gravityforms() { |
||
| 464 | $version = $this->get_gravityforms_version(); |
||
| 465 | return $version ? version_compare( $version, self::$future_min_gf_version, '>=' ) : false; |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Retrieve the current PHP version. |
||
| 470 | * |
||
| 471 | * Overridable with GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE during testing. |
||
| 472 | * |
||
| 473 | * @return string The version of PHP. |
||
| 474 | */ |
||
| 475 | 3 | private function get_php_version() { |
|
| 476 | 3 | return ! empty( $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] ) ? |
|
| 477 | 3 | $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion(); |
|
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Retrieve the current WordPress version. |
||
| 482 | * |
||
| 483 | * Overridable with GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE during testing. |
||
| 484 | * |
||
| 485 | * @return string The version of WordPress. |
||
| 486 | */ |
||
| 487 | 3 | private function get_wordpress_version() { |
|
| 488 | 3 | return ! empty( $GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] ) ? |
|
| 489 | 3 | $GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] : $GLOBALS['wp_version']; |
|
| 490 | } |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Retrieve the current Gravity Forms version. |
||
| 494 | * |
||
| 495 | * Overridable with GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE during testing. |
||
| 496 | * |
||
| 497 | * @return string|null The version of Gravity Forms or null if inactive. |
||
| 498 | */ |
||
| 499 | 3 | private function get_gravityforms_version() { |
|
| 500 | 3 | if ( ! class_exists( '\GFCommon' ) || ! empty( $GLOBALS['GRAVITYVIEW_TESTS_GF_INACTIVE_OVERRIDE'] ) ) { |
|
| 501 | gravityview()->log->error( 'Gravity Forms is inactive or not installed.' ); |
||
| 502 | return null; |
||
| 503 | } |
||
| 504 | |||
| 505 | 3 | return ! empty( $GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE'] ) ? |
|
| 506 | 3 | $GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE'] : \GFCommon::$version; |
|
| 507 | } |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Feature support detection. |
||
| 511 | * |
||
| 512 | * @param string $feature Feature name. Check FEATURE_* class constants. |
||
| 513 | * |
||
| 514 | * @return boolean |
||
| 515 | */ |
||
| 516 | 187 | public function supports( $feature ) { |
|
| 517 | 187 | if ( ! is_null( $supports = apply_filters( "gravityview/plugin/feature/$feature", null ) ) ) { |
|
| 518 | return $supports; |
||
| 519 | } |
||
| 520 | |||
| 521 | switch ( $feature ): |
||
| 522 | 187 | case self::FEATURE_GFQUERY: |
|
| 523 | 66 | return class_exists( '\GF_Query' ); |
|
| 524 | 187 | case self::FEATURE_JOINS: |
|
| 525 | 187 | case self::FEATURE_UNIONS: |
|
| 526 | 171 | return apply_filters( 'gravityview/query/class', false ) === '\GF_Patched_Query'; |
|
| 527 | 187 | case self::FEATURE_REST: |
|
| 528 | 187 | return class_exists( '\WP_REST_Controller' ); |
|
| 529 | default: |
||
| 530 | return false; |
||
| 531 | endswitch; |
||
| 532 | } |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Delete GravityView Views, settings, roles, caps, etc. |
||
| 536 | * |
||
| 537 | * @return void |
||
| 538 | */ |
||
| 539 | public function uninstall() { |
||
| 540 | global $wpdb; |
||
| 541 | |||
| 542 | $suppress = $wpdb->suppress_errors(); |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Posts. |
||
| 546 | */ |
||
| 547 | $items = get_posts( array( |
||
| 548 | 'post_type' => 'gravityview', |
||
| 549 | 'post_status' => 'any', |
||
| 550 | 'numberposts' => -1, |
||
| 551 | 'fields' => 'ids' |
||
| 552 | ) ); |
||
| 553 | |||
| 554 | foreach ( $items as $item ) { |
||
| 555 | wp_delete_post( $item, true ); |
||
| 556 | } |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Meta. |
||
| 560 | */ |
||
| 561 | $tables = array(); |
||
| 562 | |||
| 563 | if ( version_compare( \GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) ) { |
||
| 564 | $tables []= \GFFormsModel::get_entry_meta_table_name(); |
||
| 565 | } |
||
| 566 | $tables []= \GFFormsModel::get_lead_meta_table_name(); |
||
| 567 | |||
| 568 | foreach ( $tables as $meta_table ) { |
||
| 569 | $sql = " |
||
| 570 | DELETE FROM $meta_table |
||
| 571 | WHERE ( |
||
| 572 | `meta_key` = 'is_approved' |
||
| 573 | ); |
||
| 574 | "; |
||
| 575 | $wpdb->query( $sql ); |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Notes. |
||
| 580 | */ |
||
| 581 | $tables = array(); |
||
| 582 | |||
| 583 | if ( version_compare( \GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) && method_exists( 'GFFormsModel', 'get_entry_notes_table_name' ) ) { |
||
| 584 | $tables[] = \GFFormsModel::get_entry_notes_table_name(); |
||
| 585 | } |
||
| 586 | |||
| 587 | $tables[] = \GFFormsModel::get_lead_notes_table_name(); |
||
| 588 | |||
| 589 | $disapproved = __('Disapproved the Entry for GravityView', 'gravityview'); |
||
| 590 | $approved = __('Approved the Entry for GravityView', 'gravityview'); |
||
| 591 | |||
| 592 | $suppress = $wpdb->suppress_errors(); |
||
| 593 | foreach ( $tables as $notes_table ) { |
||
| 594 | $sql = $wpdb->prepare( " |
||
| 595 | DELETE FROM $notes_table |
||
| 596 | WHERE ( |
||
| 597 | `note_type` = 'gravityview' OR |
||
| 598 | `value` = %s OR |
||
| 599 | `value` = %s |
||
| 600 | ); |
||
| 601 | ", $approved, $disapproved ); |
||
| 602 | $wpdb->query( $sql ); |
||
| 603 | } |
||
| 604 | |||
| 605 | $wpdb->suppress_errors( $suppress ); |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Capabilities. |
||
| 609 | */ |
||
| 610 | \GravityView_Roles_Capabilities::get_instance()->remove_caps(); |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Options. |
||
| 614 | */ |
||
| 615 | delete_option( 'gravityview_cache_blacklist' ); |
||
| 616 | delete_option( 'gv_version_upgraded_from' ); |
||
| 617 | delete_transient( 'gravityview_edd-activate_valid' ); |
||
| 618 | delete_transient( 'gravityview_edd-deactivate_valid' ); |
||
| 619 | delete_transient( 'gravityview_dismissed_notices' ); |
||
| 620 | delete_site_transient( 'gravityview_related_plugins' ); |
||
| 621 | } |
||
| 622 | |||
| 623 | private function __clone() { } |
||
| 624 | |||
| 625 | private function __wakeup() { } |
||
| 626 | } |
||
| 627 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: