| Conditions | 36 |
| Paths | > 20000 |
| Total Lines | 262 |
| Code Lines | 161 |
| Lines | 15 |
| Ratio | 5.73 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 336 | function network_step2( $errors = false ) { |
||
| 337 | global $wpdb; |
||
| 338 | |||
| 339 | $hostname = get_clean_basedomain(); |
||
| 340 | $slashed_home = trailingslashit( get_option( 'home' ) ); |
||
| 341 | $base = parse_url( $slashed_home, PHP_URL_PATH ); |
||
| 342 | $document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) ); |
||
| 343 | $abspath_fix = str_replace( '\\', '/', ABSPATH ); |
||
| 344 | $home_path = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path(); |
||
| 345 | $wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix ); |
||
| 346 | $rewrite_base = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : ''; |
||
| 347 | |||
| 348 | |||
| 349 | $location_of_wp_config = $abspath_fix; |
||
| 350 | if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) { |
||
| 351 | $location_of_wp_config = dirname( $abspath_fix ); |
||
| 352 | } |
||
| 353 | $location_of_wp_config = trailingslashit( $location_of_wp_config ); |
||
| 354 | |||
| 355 | // Wildcard DNS message. |
||
| 356 | if ( is_wp_error( $errors ) ) |
||
| 357 | echo '<div class="error">' . $errors->get_error_message() . '</div>'; |
||
| 358 | |||
| 359 | if ( $_POST ) { |
||
| 360 | if ( allow_subdomain_install() ) |
||
| 361 | $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true; |
||
| 362 | else |
||
| 363 | $subdomain_install = false; |
||
| 364 | } else { |
||
| 365 | if ( is_multisite() ) { |
||
| 366 | $subdomain_install = is_subdomain_install(); |
||
| 367 | ?> |
||
| 368 | <p><?php _e( 'The original configuration steps are shown here for reference.' ); ?></p> |
||
| 369 | <?php |
||
| 370 | } else { |
||
| 371 | $subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" ); |
||
| 372 | ?> |
||
| 373 | <div class="error"><p><strong><?php _e('Warning:'); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div> |
||
| 374 | <p><?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p> |
||
| 375 | <?php |
||
| 376 | } |
||
| 377 | } |
||
| 378 | |||
| 379 | $subdir_match = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?'; |
||
| 380 | $subdir_replacement_01 = $subdomain_install ? '' : '$1'; |
||
| 381 | $subdir_replacement_12 = $subdomain_install ? '$1' : '$2'; |
||
| 382 | |||
| 383 | if ( $_POST || ! is_multisite() ) { |
||
| 384 | ?> |
||
| 385 | <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3> |
||
| 386 | <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p> |
||
| 387 | <div class="updated inline"><p><?php |
||
| 388 | if ( file_exists( $home_path . '.htaccess' ) ) { |
||
| 389 | echo '<strong>' . __( 'Caution:' ) . '</strong> '; |
||
| 390 | printf( |
||
| 391 | /* translators: 1: wp-config.php 2: .htaccess */ |
||
| 392 | __( 'We recommend you back up your existing %1$s and %2$s files.' ), |
||
| 393 | '<code>wp-config.php</code>', |
||
| 394 | '<code>.htaccess</code>' |
||
| 395 | ); |
||
| 396 | } elseif ( file_exists( $home_path . 'web.config' ) ) { |
||
| 397 | echo '<strong>' . __( 'Caution:' ) . '</strong> '; |
||
| 398 | printf( |
||
| 399 | /* translators: 1: wp-config.php 2: web.config */ |
||
| 400 | __( 'We recommend you back up your existing %1$s and %2$s files.' ), |
||
| 401 | '<code>wp-config.php</code>', |
||
| 402 | '<code>web.config</code>' |
||
| 403 | ); |
||
| 404 | } else { |
||
| 405 | echo '<strong>' . __( 'Caution:' ) . '</strong> '; |
||
| 406 | printf( |
||
| 407 | /* translators: 1: wp-config.php */ |
||
| 408 | __( 'We recommend you back up your existing %s file.' ), |
||
| 409 | '<code>wp-config.php</code>' |
||
| 410 | ); |
||
| 411 | } |
||
| 412 | ?></p></div> |
||
| 413 | <?php |
||
| 414 | } |
||
| 415 | ?> |
||
| 416 | <ol> |
||
| 417 | <li><p><?php printf( |
||
| 418 | /* translators: 1: wp-config.php 2: location of wp-config file, 3: translated version of "That's all, stop editing! Happy blogging." */ |
||
| 419 | __( 'Add the following to your %1$s file in %2$s <strong>above</strong> the line reading %3$s:' ), |
||
| 420 | '<code>wp-config.php</code>', |
||
| 421 | '<code>' . $location_of_wp_config . '</code>', |
||
| 422 | /* |
||
| 423 | * translators: This string should only be translated if wp-config-sample.php is localized. |
||
| 424 | * You can check the localized release package or |
||
| 425 | * https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php |
||
| 426 | */ |
||
| 427 | '<code>/* ' . __( 'That’s all, stop editing! Happy blogging.' ) . ' */</code>' |
||
| 428 | ); ?></p> |
||
| 429 | <textarea class="code" readonly="readonly" cols="100" rows="7"> |
||
| 430 | define('MULTISITE', true); |
||
| 431 | define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>); |
||
| 432 | define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>'); |
||
| 433 | define('PATH_CURRENT_SITE', '<?php echo $base; ?>'); |
||
| 434 | define('SITE_ID_CURRENT_SITE', 1); |
||
| 435 | define('BLOG_ID_CURRENT_SITE', 1); |
||
| 436 | </textarea> |
||
| 437 | <?php |
||
| 438 | $keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' ); |
||
| 439 | foreach ( $keys_salts as $c => $v ) { |
||
| 440 | if ( defined( $c ) ) |
||
| 441 | unset( $keys_salts[ $c ] ); |
||
| 442 | } |
||
| 443 | |||
| 444 | if ( ! empty( $keys_salts ) ) { |
||
| 445 | $keys_salts_str = ''; |
||
| 446 | $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); |
||
| 447 | if ( is_wp_error( $from_api ) ) { |
||
| 448 | foreach ( $keys_salts as $c => $v ) { |
||
| 449 | $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );"; |
||
| 450 | } |
||
| 451 | } else { |
||
| 452 | $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) ); |
||
| 453 | foreach ( $keys_salts as $c => $v ) { |
||
| 454 | $keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );"; |
||
| 455 | } |
||
| 456 | } |
||
| 457 | $num_keys_salts = count( $keys_salts ); |
||
| 458 | ?> |
||
| 459 | <p> |
||
| 460 | <?php |
||
| 461 | if ( 1 == $num_keys_salts ) { |
||
| 462 | printf( |
||
| 463 | /* translators: 1: wp-config.php */ |
||
| 464 | __( 'This unique authentication key is also missing from your %s file.' ), |
||
| 465 | '<code>wp-config.php</code>' |
||
| 466 | ); |
||
| 467 | } else { |
||
| 468 | printf( |
||
| 469 | /* translators: 1: wp-config.php */ |
||
| 470 | __( 'These unique authentication keys are also missing from your %s file.' ), |
||
| 471 | '<code>wp-config.php</code>' |
||
| 472 | ); |
||
| 473 | } |
||
| 474 | ?> |
||
| 475 | <?php _e( 'To make your installation more secure, you should also add:' ); ?> |
||
| 476 | </p> |
||
| 477 | <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea> |
||
| 478 | <?php |
||
| 479 | } |
||
| 480 | ?> |
||
| 481 | </li> |
||
| 482 | <?php |
||
| 483 | if ( iis7_supports_permalinks() ) : |
||
| 484 | // IIS doesn't support RewriteBase, all your RewriteBase are belong to us |
||
| 485 | $iis_subdir_match = ltrim( $base, '/' ) . $subdir_match; |
||
| 486 | $iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base; |
||
| 487 | $iis_subdir_replacement = $subdomain_install ? '' : '{R:1}'; |
||
| 488 | |||
| 489 | $web_config_file = '<?xml version="1.0" encoding="UTF-8"?> |
||
| 490 | <configuration> |
||
| 491 | <system.webServer> |
||
| 492 | <rewrite> |
||
| 493 | <rules> |
||
| 494 | <rule name="WordPress Rule 1" stopProcessing="true"> |
||
| 495 | <match url="^index\.php$" ignoreCase="false" /> |
||
| 496 | <action type="None" /> |
||
| 497 | </rule>'; |
||
| 498 | View Code Duplication | if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) { |
|
| 499 | $web_config_file .= ' |
||
| 500 | <rule name="WordPress Rule for Files" stopProcessing="true"> |
||
| 501 | <match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" /> |
||
| 502 | <action type="Rewrite" url="' . $iis_rewrite_base . WPINC . '/ms-files.php?file={R:1}" appendQueryString="false" /> |
||
| 503 | </rule>'; |
||
| 504 | } |
||
| 505 | $web_config_file .= ' |
||
| 506 | <rule name="WordPress Rule 2" stopProcessing="true"> |
||
| 507 | <match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" /> |
||
| 508 | <action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" /> |
||
| 509 | </rule> |
||
| 510 | <rule name="WordPress Rule 3" stopProcessing="true"> |
||
| 511 | <match url="^" ignoreCase="false" /> |
||
| 512 | <conditions logicalGrouping="MatchAny"> |
||
| 513 | <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> |
||
| 514 | <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> |
||
| 515 | </conditions> |
||
| 516 | <action type="None" /> |
||
| 517 | </rule> |
||
| 518 | <rule name="WordPress Rule 4" stopProcessing="true"> |
||
| 519 | <match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" /> |
||
| 520 | <action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" /> |
||
| 521 | </rule> |
||
| 522 | <rule name="WordPress Rule 5" stopProcessing="true"> |
||
| 523 | <match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" /> |
||
| 524 | <action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" /> |
||
| 525 | </rule> |
||
| 526 | <rule name="WordPress Rule 6" stopProcessing="true"> |
||
| 527 | <match url="." ignoreCase="false" /> |
||
| 528 | <action type="Rewrite" url="index.php" /> |
||
| 529 | </rule> |
||
| 530 | </rules> |
||
| 531 | </rewrite> |
||
| 532 | </system.webServer> |
||
| 533 | </configuration> |
||
| 534 | '; |
||
| 535 | |||
| 536 | echo '<li><p>'; |
||
| 537 | printf( |
||
| 538 | /* translators: 1: a filename like .htaccess. 2: a file path. */ |
||
| 539 | __( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ), |
||
| 540 | '<code>web.config</code>', |
||
| 541 | '<code>' . $home_path . '</code>' |
||
| 542 | ); |
||
| 543 | echo '</p>'; |
||
| 544 | View Code Duplication | if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) |
|
| 545 | echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>'; |
||
| 546 | ?> |
||
| 547 | <textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?> |
||
| 548 | </textarea></li> |
||
| 549 | </ol> |
||
| 550 | |||
| 551 | <?php else : // end iis7_supports_permalinks(). construct an htaccess file instead: |
||
| 552 | |||
| 553 | $ms_files_rewriting = ''; |
||
| 554 | View Code Duplication | if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) { |
|
| 555 | $ms_files_rewriting = "\n# uploaded files\nRewriteRule ^"; |
||
| 556 | $ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n"; |
||
| 557 | } |
||
| 558 | |||
| 559 | $htaccess_file = <<<EOF |
||
| 560 | RewriteEngine On |
||
| 561 | RewriteBase {$base} |
||
| 562 | RewriteRule ^index\.php$ - [L] |
||
| 563 | {$ms_files_rewriting} |
||
| 564 | # add a trailing slash to /wp-admin |
||
| 565 | RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L] |
||
| 566 | |||
| 567 | RewriteCond %{REQUEST_FILENAME} -f [OR] |
||
| 568 | RewriteCond %{REQUEST_FILENAME} -d |
||
| 569 | RewriteRule ^ - [L] |
||
| 570 | RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L] |
||
| 571 | RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L] |
||
| 572 | RewriteRule . index.php [L] |
||
| 573 | |||
| 574 | EOF; |
||
| 575 | |||
| 576 | echo '<li><p>'; |
||
| 577 | printf( |
||
| 578 | /* translators: 1: a filename like .htaccess. 2: a file path. */ |
||
| 579 | __( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ), |
||
| 580 | '<code>.htaccess</code>', |
||
| 581 | '<code>' . $home_path . '</code>' |
||
| 582 | ); |
||
| 583 | echo '</p>'; |
||
| 584 | View Code Duplication | if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) |
|
| 585 | echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>'; |
||
| 586 | ?> |
||
| 587 | <textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>"> |
||
| 588 | <?php echo esc_textarea( $htaccess_file ); ?></textarea></li> |
||
| 589 | </ol> |
||
| 590 | |||
| 591 | <?php endif; // end IIS/Apache code branches. |
||
| 592 | |||
| 593 | if ( !is_multisite() ) { ?> |
||
| 594 | <p><?php _e( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.' ); ?> <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log In' ); ?></a></p> |
||
| 595 | <?php |
||
| 596 | } |
||
| 597 | } |
||
| 598 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: