wp/wp-admin/admin.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 19 3d72ae0968f4
--- a/wp/wp-admin/admin.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/admin.php	Tue Dec 15 13:49:49 2020 +0100
@@ -31,11 +31,12 @@
 	define( 'WP_LOAD_IMPORTERS', true );
 }
 
-require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
+require_once dirname( __DIR__ ) . '/wp-load.php';
 
 nocache_headers();
 
 if ( get_option( 'db_upgraded' ) ) {
+
 	flush_rewrite_rules();
 	update_option( 'db_upgraded', false );
 
@@ -45,34 +46,39 @@
 	 * @since 2.8.0
 	 */
 	do_action( 'after_db_upgrade' );
-} elseif ( get_option( 'db_version' ) != $wp_db_version && empty( $_POST ) ) {
+
+} elseif ( ! wp_doing_ajax() && empty( $_POST )
+	&& (int) get_option( 'db_version' ) !== $wp_db_version
+) {
+
 	if ( ! is_multisite() ) {
 		wp_redirect( admin_url( 'upgrade.php?_wp_http_referer=' . urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
 		exit;
+	}
 
-		/**
-		 * Filters whether to attempt to perform the multisite DB upgrade routine.
-		 *
-		 * In single site, the user would be redirected to wp-admin/upgrade.php.
-		 * In multisite, the DB upgrade routine is automatically fired, but only
-		 * when this filter returns true.
-		 *
-		 * If the network is 50 sites or less, it will run every time. Otherwise,
-		 * it will throttle itself to reduce load.
-		 *
-		 * @since 3.0.0
-		 *
-		 * @param bool $do_mu_upgrade Whether to perform the Multisite upgrade routine. Default true.
-		 */
-	} elseif ( apply_filters( 'do_mu_upgrade', true ) ) {
+	/**
+	 * Filters whether to attempt to perform the multisite DB upgrade routine.
+	 *
+	 * In single site, the user would be redirected to wp-admin/upgrade.php.
+	 * In multisite, the DB upgrade routine is automatically fired, but only
+	 * when this filter returns true.
+	 *
+	 * If the network is 50 sites or less, it will run every time. Otherwise,
+	 * it will throttle itself to reduce load.
+	 *
+	 * @since MU (3.0.0)
+	 *
+	 * @param bool $do_mu_upgrade Whether to perform the Multisite upgrade routine. Default true.
+	 */
+	if ( apply_filters( 'do_mu_upgrade', true ) ) {
 		$c = get_blog_count();
 
 		/*
 		 * If there are 50 or fewer sites, run every time. Otherwise, throttle to reduce load:
 		 * attempt to do no more than threshold value, with some +/- allowed.
 		 */
-		if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int) ( $c / 50 ) ) == 1 ) ) {
-			require_once( ABSPATH . WPINC . '/http.php' );
+		if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int) ( $c / 50 ) ) === 1 ) ) {
+			require_once ABSPATH . WPINC . '/http.php';
 			$response = wp_remote_get(
 				admin_url( 'upgrade.php?step=1' ),
 				array(
@@ -88,16 +94,16 @@
 	}
 }
 
-require_once( ABSPATH . 'wp-admin/includes/admin.php' );
+require_once ABSPATH . 'wp-admin/includes/admin.php';
 
 auth_redirect();
 
-// Schedule trash collection
+// Schedule Trash collection.
 if ( ! wp_next_scheduled( 'wp_scheduled_delete' ) && ! wp_installing() ) {
 	wp_schedule_event( time(), 'daily', 'wp_scheduled_delete' );
 }
 
-// Schedule Transient cleanup.
+// Schedule transient cleanup.
 if ( ! wp_next_scheduled( 'delete_expired_transients' ) && ! wp_installing() ) {
 	wp_schedule_event( time(), 'daily', 'delete_expired_transients' );
 }
@@ -145,11 +151,11 @@
 }
 
 if ( WP_NETWORK_ADMIN ) {
-	require( ABSPATH . 'wp-admin/network/menu.php' );
+	require ABSPATH . 'wp-admin/network/menu.php';
 } elseif ( WP_USER_ADMIN ) {
-	require( ABSPATH . 'wp-admin/user/menu.php' );
+	require ABSPATH . 'wp-admin/user/menu.php';
 } else {
-	require( ABSPATH . 'wp-admin/menu.php' );
+	require ABSPATH . 'wp-admin/menu.php';
 }
 
 if ( current_user_can( 'manage_options' ) ) {
@@ -180,8 +186,8 @@
 		$page_hook = get_plugin_page_hook( $plugin_page, $plugin_page );
 
 		// Back-compat for plugins using add_management_page().
-		if ( empty( $page_hook ) && 'edit.php' == $pagenow && '' != get_plugin_page_hook( $plugin_page, 'tools.php' ) ) {
-			// There could be plugin specific params on the URL, so we need the whole query string
+		if ( empty( $page_hook ) && 'edit.php' === $pagenow && get_plugin_page_hook( $plugin_page, 'tools.php' ) ) {
+			// There could be plugin specific params on the URL, so we need the whole query string.
 			if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
 				$query_string = $_SERVER['QUERY_STRING'];
 			} else {
@@ -228,9 +234,9 @@
 		 *
 		 * @since 2.1.0
 		 */
-		do_action( "load-{$page_hook}" );
+		do_action( "load-{$page_hook}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 		if ( ! isset( $_GET['noheader'] ) ) {
-			require_once( ABSPATH . 'wp-admin/admin-header.php' );
+			require_once ABSPATH . 'wp-admin/admin-header.php';
 		}
 
 		/**
@@ -256,7 +262,10 @@
 			wp_die( __( 'Invalid plugin page.' ) );
 		}
 
-		if ( ! ( file_exists( WP_PLUGIN_DIR . "/$plugin_page" ) && is_file( WP_PLUGIN_DIR . "/$plugin_page" ) ) && ! ( file_exists( WPMU_PLUGIN_DIR . "/$plugin_page" ) && is_file( WPMU_PLUGIN_DIR . "/$plugin_page" ) ) ) {
+		if ( ! ( file_exists( WP_PLUGIN_DIR . "/$plugin_page" ) && is_file( WP_PLUGIN_DIR . "/$plugin_page" ) )
+			&& ! ( file_exists( WPMU_PLUGIN_DIR . "/$plugin_page" ) && is_file( WPMU_PLUGIN_DIR . "/$plugin_page" ) )
+		) {
+			/* translators: %s: Admin page generated by a plugin. */
 			wp_die( sprintf( __( 'Cannot load %s.' ), htmlentities( $plugin_page ) ) );
 		}
 
@@ -272,28 +281,28 @@
 		 *
 		 * @since 1.5.0
 		 */
-		do_action( "load-{$plugin_page}" );
+		do_action( "load-{$plugin_page}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 
 		if ( ! isset( $_GET['noheader'] ) ) {
-			require_once( ABSPATH . 'wp-admin/admin-header.php' );
+			require_once ABSPATH . 'wp-admin/admin-header.php';
 		}
 
 		if ( file_exists( WPMU_PLUGIN_DIR . "/$plugin_page" ) ) {
-			include( WPMU_PLUGIN_DIR . "/$plugin_page" );
+			include WPMU_PLUGIN_DIR . "/$plugin_page";
 		} else {
-			include( WP_PLUGIN_DIR . "/$plugin_page" );
+			include WP_PLUGIN_DIR . "/$plugin_page";
 		}
 	}
 
-	include( ABSPATH . 'wp-admin/admin-footer.php' );
+	require_once ABSPATH . 'wp-admin/admin-footer.php';
 
-	exit();
+	exit;
 } elseif ( isset( $_GET['import'] ) ) {
 
 	$importer = $_GET['import'];
 
 	if ( ! current_user_can( 'import' ) ) {
-		wp_die( __( 'Sorry, you are not allowed to import content.' ) );
+		wp_die( __( 'Sorry, you are not allowed to import content into this site.' ) );
 	}
 
 	if ( validate_file( $importer ) ) {
@@ -313,17 +322,17 @@
 	 *
 	 * @since 3.5.0
 	 */
-	do_action( "load-importer-{$importer}" );
+	do_action( "load-importer-{$importer}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 
 	$parent_file  = 'tools.php';
 	$submenu_file = 'import.php';
 	$title        = __( 'Import' );
 
 	if ( ! isset( $_GET['noheader'] ) ) {
-		require_once( ABSPATH . 'wp-admin/admin-header.php' );
+		require_once ABSPATH . 'wp-admin/admin-header.php';
 	}
 
-	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
+	require_once ABSPATH . 'wp-admin/includes/upgrade.php';
 
 	define( 'WP_IMPORTING', true );
 
@@ -343,12 +352,12 @@
 
 	call_user_func( $wp_importers[ $importer ][2] );
 
-	include( ABSPATH . 'wp-admin/admin-footer.php' );
+	require_once ABSPATH . 'wp-admin/admin-footer.php';
 
-	// Make sure rules are flushed
+	// Make sure rules are flushed.
 	flush_rewrite_rules( false );
 
-	exit();
+	exit;
 } else {
 	/**
 	 * Fires before a particular screen is loaded.
@@ -362,26 +371,26 @@
 	 *
 	 * @since 2.1.0
 	 */
-	do_action( "load-{$pagenow}" );
+	do_action( "load-{$pagenow}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 
 	/*
 	 * The following hooks are fired to ensure backward compatibility.
 	 * In all other cases, 'load-' . $pagenow should be used instead.
 	 */
-	if ( $typenow == 'page' ) {
-		if ( $pagenow == 'post-new.php' ) {
-			do_action( 'load-page-new.php' );
-		} elseif ( $pagenow == 'post.php' ) {
-			do_action( 'load-page.php' );
+	if ( 'page' === $typenow ) {
+		if ( 'post-new.php' === $pagenow ) {
+			do_action( 'load-page-new.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
+		} elseif ( 'post.php' === $pagenow ) {
+			do_action( 'load-page.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 		}
-	} elseif ( $pagenow == 'edit-tags.php' ) {
-		if ( $taxnow == 'category' ) {
-			do_action( 'load-categories.php' );
-		} elseif ( $taxnow == 'link_category' ) {
-			do_action( 'load-edit-link-categories.php' );
+	} elseif ( 'edit-tags.php' === $pagenow ) {
+		if ( 'category' === $taxnow ) {
+			do_action( 'load-categories.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
+		} elseif ( 'link_category' === $taxnow ) {
+			do_action( 'load-edit-link-categories.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 		}
 	} elseif ( 'term.php' === $pagenow ) {
-		do_action( 'load-edit-tags.php' );
+		do_action( 'load-edit-tags.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 	}
 }