From 718888b5c0f2de85e6af2da7ae637cce19b02059 Mon Sep 17 00:00:00 2001
From: patrickebates
Date: Sun, 24 Feb 2019 10:57:20 -0600
Subject: [PATCH] Clean up SHOW TABLES LIKE commands
---
wp-admin/includes/network.php | 952 +++++++++++++++++-----------------
wp-includes/functions.php | 2 +-
2 files changed, 477 insertions(+), 477 deletions(-)
diff --git a/wp-admin/includes/network.php b/wp-admin/includes/network.php
index 73dd1f390..901135db5 100644
--- a/wp-admin/includes/network.php
+++ b/wp-admin/includes/network.php
@@ -1,436 +1,436 @@
-prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) );
- if ( $wpdb->get_var( $sql ) ) {
+prepare( 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE %s', $wpdb->esc_like( $wpdb->site ) );
+ if ( $wpdb->get_var( $sql ) ) {
return $wpdb->get_var( "SELECT TOP 1 domain FROM $wpdb->site ORDER BY id ASC" );
- }
- return false;
-}
-
-/**
- * Allow subdomain installation
- *
- * @since 3.0.0
- * @return bool Whether subdomain installation is allowed
- */
-function allow_subdomain_install() {
- $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
+ }
+ return false;
+}
+
+/**
+ * Allow subdomain installation
+ *
+ * @since 3.0.0
+ * @return bool Whether subdomain installation is allowed
+ */
+function allow_subdomain_install() {
+ $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) {
- return false;
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Allow subdirectory installation.
+ *
+ * @since 3.0.0
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ *
+ * @return bool Whether subdirectory installation is allowed
+ */
+function allow_subdirectory_install() {
+ global $wpdb;
+ /**
+ * Filters whether to enable the subdirectory installation feature in Multisite.
+ *
+ * @since 3.0.0
+ *
+ * @param bool $allow Whether to enable the subdirectory installation feature in Multisite. Default is false.
+ */
+ if ( apply_filters( 'allow_subdirectory_install', false ) ) {
+ return true;
}
-
- return true;
-}
-
-/**
- * Allow subdirectory installation.
- *
- * @since 3.0.0
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- *
- * @return bool Whether subdirectory installation is allowed
- */
-function allow_subdirectory_install() {
- global $wpdb;
- /**
- * Filters whether to enable the subdirectory installation feature in Multisite.
- *
- * @since 3.0.0
- *
- * @param bool $allow Whether to enable the subdirectory installation feature in Multisite. Default is false.
- */
- if ( apply_filters( 'allow_subdirectory_install', false ) ) {
- return true;
- }
-
- if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) {
- return true;
- }
-
+
+ if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) {
+ return true;
+ }
+
$post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATEADD(MONTH, -1, GETDATE()) AND post_status = 'publish'" );
- if ( empty( $post ) ) {
- return true;
- }
-
- return false;
-}
-
-/**
- * Get base domain of network.
- *
- * @since 3.0.0
- * @return string Base domain.
- */
-function get_clean_basedomain() {
+ if ( empty( $post ) ) {
+ return true;
+ }
+
+ return false;
+}
+
+/**
+ * Get base domain of network.
+ *
+ * @since 3.0.0
+ * @return string Base domain.
+ */
+function get_clean_basedomain() {
if ( $existing_domain = network_domain_check() ) {
- return $existing_domain;
+ return $existing_domain;
}
- $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
+ $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
if ( $slash = strpos( $domain, '/' ) ) {
- $domain = substr( $domain, 0, $slash );
+ $domain = substr( $domain, 0, $slash );
}
- return $domain;
-}
-
-/**
- * Prints step 1 for Network installation process.
- *
- * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network
+ return $domain;
+}
+
+/**
+ * Prints step 1 for Network installation process.
+ *
+ * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network
* should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo.
- *
- * @since 3.0.0
- *
- * @global bool $is_apache
- *
- * @param WP_Error $errors
- */
-function network_step1( $errors = false ) {
- global $is_apache;
-
+ *
+ * @since 3.0.0
+ *
+ * @global bool $is_apache
+ *
+ * @param WP_Error $errors
+ */
+function network_step1( $errors = false ) {
+ global $is_apache;
+
if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
- echo '' . __( 'ERROR:' ) . ' ' . sprintf(
- /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
- __( 'The constant %s cannot be defined when creating a network.' ),
- 'DO_NOT_UPGRADE_GLOBAL_TABLES
'
- ) . '
';
- echo '';
- include( ABSPATH . 'wp-admin/admin-footer.php' );
- die();
- }
-
- $active_plugins = get_option( 'active_plugins' );
- if ( ! empty( $active_plugins ) ) {
- echo '' . __( 'Warning:' ) . ' ' . sprintf(
- /* translators: %s: Plugins screen URL */
- __( 'Please deactivate your plugins before enabling the Network feature.' ),
- admin_url( 'plugins.php?plugin_status=active' )
- ) . '
';
- echo '' . __( 'Once the network is created, you may reactivate your plugins.' ) . '
';
- echo '';
- include( ABSPATH . 'wp-admin/admin-footer.php' );
- die();
- }
-
+ echo '' . __( 'ERROR:' ) . ' ' . sprintf(
+ /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
+ __( 'The constant %s cannot be defined when creating a network.' ),
+ 'DO_NOT_UPGRADE_GLOBAL_TABLES
'
+ ) . '
';
+ echo '';
+ include( ABSPATH . 'wp-admin/admin-footer.php' );
+ die();
+ }
+
+ $active_plugins = get_option( 'active_plugins' );
+ if ( ! empty( $active_plugins ) ) {
+ echo '' . __( 'Warning:' ) . ' ' . sprintf(
+ /* translators: %s: Plugins screen URL */
+ __( 'Please deactivate your plugins before enabling the Network feature.' ),
+ admin_url( 'plugins.php?plugin_status=active' )
+ ) . '
';
+ echo '' . __( 'Once the network is created, you may reactivate your plugins.' ) . '
';
+ echo '';
+ include( ABSPATH . 'wp-admin/admin-footer.php' );
+ die();
+ }
+
$hostname = get_clean_basedomain();
- $has_ports = strstr( $hostname, ':' );
- if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
- echo '' . __( 'ERROR:' ) . ' ' . __( 'You cannot install a network of sites with your server address.' ) . '
';
- echo '' . sprintf(
- /* translators: %s: port number */
- __( 'You cannot use port numbers such as %s.' ),
- '' . $has_ports . '
'
- ) . '
';
- echo '' . __( 'Return to Dashboard' ) . '';
- echo '';
- include( ABSPATH . 'wp-admin/admin-footer.php' );
- die();
- }
-
- echo '
+ ' . $errors->get_error_message() . '';
+ echo '' . $errors->get_error_message() . '
';
}
-
- if ( $_POST ) {
+
+ if ( $_POST ) {
if ( allow_subdomain_install() ) {
- $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
+ $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
} else {
- $subdomain_install = false;
+ $subdomain_install = false;
}
- } else {
- if ( is_multisite() ) {
- $subdomain_install = is_subdomain_install();
+ } else {
+ if ( is_multisite() ) {
+ $subdomain_install = is_subdomain_install();
?>
-
+
get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
+ } else {
+ $subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
?>
-
-
+
+
-
-
+
+
-
+
above the line reading %3$s:' ),
- 'wp-config.php
',
- '' . $location_of_wp_config . '
',
- /*
- * translators: This string should only be translated if wp-config-sample.php is localized.
- * You can check the localized release package or
- * https://i18n.svn.wordpress.org//branches//dist/wp-config-sample.php
- */
+ __( 'Add the following to your %1$s file in %2$s above the line reading %3$s:' ),
+ 'wp-config.php
',
+ '' . $location_of_wp_config . '
',
+ /*
+ * translators: This string should only be translated if wp-config-sample.php is localized.
+ * You can check the localized release package or
+ * https://i18n.svn.wordpress.org//branches//dist/wp-config-sample.php
+ */
'/* ' . __( 'That’s all, stop editing! Happy publishing.' ) . ' */
'
);
?>
-
+
'',
@@ -498,29 +498,29 @@ function network_step2( $errors = false ) {
'LOGGED_IN_SALT' => '',
'NONCE_SALT' => '',
);
- foreach ( $keys_salts as $c => $v ) {
+ foreach ( $keys_salts as $c => $v ) {
if ( defined( $c ) ) {
- unset( $keys_salts[ $c ] );
+ unset( $keys_salts[ $c ] );
}
- }
-
- if ( ! empty( $keys_salts ) ) {
- $keys_salts_str = '';
+ }
+
+ if ( ! empty( $keys_salts ) ) {
+ $keys_salts_str = '';
$from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
- if ( is_wp_error( $from_api ) ) {
- foreach ( $keys_salts as $c => $v ) {
- $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
- }
- } else {
- $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
- foreach ( $keys_salts as $c => $v ) {
- $keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
- }
- }
- $num_keys_salts = count( $keys_salts );
+ if ( is_wp_error( $from_api ) ) {
+ foreach ( $keys_salts as $c => $v ) {
+ $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
+ }
+ } else {
+ $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
+ foreach ( $keys_salts as $c => $v ) {
+ $keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
+ }
+ }
+ $num_keys_salts = count( $keys_salts );
?>
- wp-config.php'
);
}
- ?>
-
-
-
+ ?>
+
+
+
-
+
-
-
-
-
-
-
-
- ';
+ $iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
+
+ $web_config_file = '
+
+
+
+
+
+
+
+ ';
if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
$web_config_file .= '
-
-
-
- ';
+
+
+
+ ';
}
$web_config_file .= '
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-';
-
+
+
+
+
+
+
+
+
+
+
+';
+
echo '';
printf(
/* translators: 1: a filename like .htaccess, 2: a file path */
@@ -603,63 +603,63 @@ function network_step2( $errors = false ) {
'web.config
',
'' . $home_path . '
'
);
- echo '
';
+ echo '';
if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) {
- echo '' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '
';
+ echo '' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '
';
}
- ?>
+ ?>
-
-
+
+
+
';
- printf(
+ $ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
+ }
+
+ $htaccess_file = <<';
+ printf(
/* translators: 1: a filename like .htaccess, 2: a file path */
- __( 'Add the following to your %1$s file in %2$s, replacing other WordPress rules:' ),
- '.htaccess
',
- '' . $home_path . '
'
- );
- echo '
';
+ __( 'Add the following to your %1$s file in %2$s, replacing other WordPress rules:' ),
+ '.htaccess
',
+ '' . $home_path . '
'
+ );
+ echo '
';
if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) {
- echo '' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '
';
+ echo '' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '
';
}
- ?>
-