Passed
Push — main ( 16d49b...d78e29 )
by TARIQ
111:03
created
brighty/wp-admin/includes/class-plugin-upgrader-skin.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -17,107 +17,107 @@
 block discarded – undo
17 17
  */
18 18
 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
19 19
 
20
-	/**
21
-	 * Holds the plugin slug in the Plugin Directory.
22
-	 *
23
-	 * @since 2.8.0
24
-	 *
25
-	 * @var string
26
-	 */
27
-	public $plugin = '';
20
+    /**
21
+     * Holds the plugin slug in the Plugin Directory.
22
+     *
23
+     * @since 2.8.0
24
+     *
25
+     * @var string
26
+     */
27
+    public $plugin = '';
28 28
 
29
-	/**
30
-	 * Whether the plugin is active.
31
-	 *
32
-	 * @since 2.8.0
33
-	 *
34
-	 * @var bool
35
-	 */
36
-	public $plugin_active = false;
29
+    /**
30
+     * Whether the plugin is active.
31
+     *
32
+     * @since 2.8.0
33
+     *
34
+     * @var bool
35
+     */
36
+    public $plugin_active = false;
37 37
 
38
-	/**
39
-	 * Whether the plugin is active for the entire network.
40
-	 *
41
-	 * @since 2.8.0
42
-	 *
43
-	 * @var bool
44
-	 */
45
-	public $plugin_network_active = false;
38
+    /**
39
+     * Whether the plugin is active for the entire network.
40
+     *
41
+     * @since 2.8.0
42
+     *
43
+     * @var bool
44
+     */
45
+    public $plugin_network_active = false;
46 46
 
47
-	/**
48
-	 * Constructor.
49
-	 *
50
-	 * Sets up the plugin upgrader skin.
51
-	 *
52
-	 * @since 2.8.0
53
-	 *
54
-	 * @param array $args Optional. The plugin upgrader skin arguments to
55
-	 *                    override default options. Default empty array.
56
-	 */
57
-	public function __construct( $args = array() ) {
58
-		$defaults = array(
59
-			'url'    => '',
60
-			'plugin' => '',
61
-			'nonce'  => '',
62
-			'title'  => __( 'Update Plugin' ),
63
-		);
64
-		$args     = wp_parse_args( $args, $defaults );
47
+    /**
48
+     * Constructor.
49
+     *
50
+     * Sets up the plugin upgrader skin.
51
+     *
52
+     * @since 2.8.0
53
+     *
54
+     * @param array $args Optional. The plugin upgrader skin arguments to
55
+     *                    override default options. Default empty array.
56
+     */
57
+    public function __construct( $args = array() ) {
58
+        $defaults = array(
59
+            'url'    => '',
60
+            'plugin' => '',
61
+            'nonce'  => '',
62
+            'title'  => __( 'Update Plugin' ),
63
+        );
64
+        $args     = wp_parse_args( $args, $defaults );
65 65
 
66
-		$this->plugin = $args['plugin'];
66
+        $this->plugin = $args['plugin'];
67 67
 
68
-		$this->plugin_active         = is_plugin_active( $this->plugin );
69
-		$this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
68
+        $this->plugin_active         = is_plugin_active( $this->plugin );
69
+        $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
70 70
 
71
-		parent::__construct( $args );
72
-	}
71
+        parent::__construct( $args );
72
+    }
73 73
 
74
-	/**
75
-	 * Action to perform following a single plugin update.
76
-	 *
77
-	 * @since 2.8.0
78
-	 */
79
-	public function after() {
80
-		$this->plugin = $this->upgrader->plugin_info();
81
-		if ( ! empty( $this->plugin ) && ! is_wp_error( $this->result ) && $this->plugin_active ) {
82
-			// Currently used only when JS is off for a single plugin update?
83
-			printf(
84
-				'<iframe title="%s" style="border:0;overflow:hidden" width="100%%" height="170" src="%s"></iframe>',
85
-				esc_attr__( 'Update progress' ),
86
-				wp_nonce_url( 'update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin )
87
-			);
88
-		}
74
+    /**
75
+     * Action to perform following a single plugin update.
76
+     *
77
+     * @since 2.8.0
78
+     */
79
+    public function after() {
80
+        $this->plugin = $this->upgrader->plugin_info();
81
+        if ( ! empty( $this->plugin ) && ! is_wp_error( $this->result ) && $this->plugin_active ) {
82
+            // Currently used only when JS is off for a single plugin update?
83
+            printf(
84
+                '<iframe title="%s" style="border:0;overflow:hidden" width="100%%" height="170" src="%s"></iframe>',
85
+                esc_attr__( 'Update progress' ),
86
+                wp_nonce_url( 'update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin )
87
+            );
88
+        }
89 89
 
90
-		$this->decrement_update_count( 'plugin' );
90
+        $this->decrement_update_count( 'plugin' );
91 91
 
92
-		$update_actions = array(
93
-			'activate_plugin' => sprintf(
94
-				'<a href="%s" target="_parent">%s</a>',
95
-				wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin ),
96
-				__( 'Activate Plugin' )
97
-			),
98
-			'plugins_page'    => sprintf(
99
-				'<a href="%s" target="_parent">%s</a>',
100
-				self_admin_url( 'plugins.php' ),
101
-				__( 'Go to Plugins page' )
102
-			),
103
-		);
92
+        $update_actions = array(
93
+            'activate_plugin' => sprintf(
94
+                '<a href="%s" target="_parent">%s</a>',
95
+                wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin ),
96
+                __( 'Activate Plugin' )
97
+            ),
98
+            'plugins_page'    => sprintf(
99
+                '<a href="%s" target="_parent">%s</a>',
100
+                self_admin_url( 'plugins.php' ),
101
+                __( 'Go to Plugins page' )
102
+            ),
103
+        );
104 104
 
105
-		if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugin', $this->plugin ) ) {
106
-			unset( $update_actions['activate_plugin'] );
107
-		}
105
+        if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugin', $this->plugin ) ) {
106
+            unset( $update_actions['activate_plugin'] );
107
+        }
108 108
 
109
-		/**
110
-		 * Filters the list of action links available following a single plugin update.
111
-		 *
112
-		 * @since 2.7.0
113
-		 *
114
-		 * @param string[] $update_actions Array of plugin action links.
115
-		 * @param string   $plugin         Path to the plugin file relative to the plugins directory.
116
-		 */
117
-		$update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
109
+        /**
110
+         * Filters the list of action links available following a single plugin update.
111
+         *
112
+         * @since 2.7.0
113
+         *
114
+         * @param string[] $update_actions Array of plugin action links.
115
+         * @param string   $plugin         Path to the plugin file relative to the plugins directory.
116
+         */
117
+        $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
118 118
 
119
-		if ( ! empty( $update_actions ) ) {
120
-			$this->feedback( implode( ' | ', (array) $update_actions ) );
121
-		}
122
-	}
119
+        if ( ! empty( $update_actions ) ) {
120
+            $this->feedback( implode( ' | ', (array) $update_actions ) );
121
+        }
122
+    }
123 123
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-core-upgrader.php 1 patch
Indentation   +382 added lines, -382 removed lines patch added patch discarded remove patch
@@ -20,399 +20,399 @@
 block discarded – undo
20 20
  */
21 21
 class Core_Upgrader extends WP_Upgrader {
22 22
 
23
-	/**
24
-	 * Initialize the upgrade strings.
25
-	 *
26
-	 * @since 2.8.0
27
-	 */
28
-	public function upgrade_strings() {
29
-		$this->strings['up_to_date'] = __( 'WordPress is at the latest version.' );
30
-		$this->strings['locked']     = __( 'Another update is currently in progress.' );
31
-		$this->strings['no_package'] = __( 'Update package not available.' );
32
-		/* translators: %s: Package URL. */
33
-		$this->strings['downloading_package']   = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
34
-		$this->strings['unpack_package']        = __( 'Unpacking the update&#8230;' );
35
-		$this->strings['copy_failed']           = __( 'Could not copy files.' );
36
-		$this->strings['copy_failed_space']     = __( 'Could not copy files. You may have run out of disk space.' );
37
-		$this->strings['start_rollback']        = __( 'Attempting to roll back to previous version.' );
38
-		$this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' );
39
-	}
40
-
41
-	/**
42
-	 * Upgrade WordPress core.
43
-	 *
44
-	 * @since 2.8.0
45
-	 *
46
-	 * @global WP_Filesystem_Base $wp_filesystem                WordPress filesystem subclass.
47
-	 * @global callable           $_wp_filesystem_direct_method
48
-	 *
49
-	 * @param object $current Response object for whether WordPress is current.
50
-	 * @param array  $args {
51
-	 *     Optional. Arguments for upgrading WordPress core. Default empty array.
52
-	 *
53
-	 *     @type bool $pre_check_md5    Whether to check the file checksums before
54
-	 *                                  attempting the upgrade. Default true.
55
-	 *     @type bool $attempt_rollback Whether to attempt to rollback the chances if
56
-	 *                                  there is a problem. Default false.
57
-	 *     @type bool $do_rollback      Whether to perform this "upgrade" as a rollback.
58
-	 *                                  Default false.
59
-	 * }
60
-	 * @return string|false|WP_Error New WordPress version on success, false or WP_Error on failure.
61
-	 */
62
-	public function upgrade( $current, $args = array() ) {
63
-		global $wp_filesystem;
64
-
65
-		require ABSPATH . WPINC . '/version.php'; // $wp_version;
66
-
67
-		$start_time = time();
68
-
69
-		$defaults    = array(
70
-			'pre_check_md5'                => true,
71
-			'attempt_rollback'             => false,
72
-			'do_rollback'                  => false,
73
-			'allow_relaxed_file_ownership' => false,
74
-		);
75
-		$parsed_args = wp_parse_args( $args, $defaults );
76
-
77
-		$this->init();
78
-		$this->upgrade_strings();
79
-
80
-		// Is an update available?
81
-		if ( ! isset( $current->response ) || 'latest' === $current->response ) {
82
-			return new WP_Error( 'up_to_date', $this->strings['up_to_date'] );
83
-		}
84
-
85
-		$res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] );
86
-		if ( ! $res || is_wp_error( $res ) ) {
87
-			return $res;
88
-		}
89
-
90
-		$wp_dir = trailingslashit( $wp_filesystem->abspath() );
91
-
92
-		$partial = true;
93
-		if ( $parsed_args['do_rollback'] ) {
94
-			$partial = false;
95
-		} elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) {
96
-			$partial = false;
97
-		}
98
-
99
-		/*
23
+    /**
24
+     * Initialize the upgrade strings.
25
+     *
26
+     * @since 2.8.0
27
+     */
28
+    public function upgrade_strings() {
29
+        $this->strings['up_to_date'] = __( 'WordPress is at the latest version.' );
30
+        $this->strings['locked']     = __( 'Another update is currently in progress.' );
31
+        $this->strings['no_package'] = __( 'Update package not available.' );
32
+        /* translators: %s: Package URL. */
33
+        $this->strings['downloading_package']   = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
34
+        $this->strings['unpack_package']        = __( 'Unpacking the update&#8230;' );
35
+        $this->strings['copy_failed']           = __( 'Could not copy files.' );
36
+        $this->strings['copy_failed_space']     = __( 'Could not copy files. You may have run out of disk space.' );
37
+        $this->strings['start_rollback']        = __( 'Attempting to roll back to previous version.' );
38
+        $this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' );
39
+    }
40
+
41
+    /**
42
+     * Upgrade WordPress core.
43
+     *
44
+     * @since 2.8.0
45
+     *
46
+     * @global WP_Filesystem_Base $wp_filesystem                WordPress filesystem subclass.
47
+     * @global callable           $_wp_filesystem_direct_method
48
+     *
49
+     * @param object $current Response object for whether WordPress is current.
50
+     * @param array  $args {
51
+     *     Optional. Arguments for upgrading WordPress core. Default empty array.
52
+     *
53
+     *     @type bool $pre_check_md5    Whether to check the file checksums before
54
+     *                                  attempting the upgrade. Default true.
55
+     *     @type bool $attempt_rollback Whether to attempt to rollback the chances if
56
+     *                                  there is a problem. Default false.
57
+     *     @type bool $do_rollback      Whether to perform this "upgrade" as a rollback.
58
+     *                                  Default false.
59
+     * }
60
+     * @return string|false|WP_Error New WordPress version on success, false or WP_Error on failure.
61
+     */
62
+    public function upgrade( $current, $args = array() ) {
63
+        global $wp_filesystem;
64
+
65
+        require ABSPATH . WPINC . '/version.php'; // $wp_version;
66
+
67
+        $start_time = time();
68
+
69
+        $defaults    = array(
70
+            'pre_check_md5'                => true,
71
+            'attempt_rollback'             => false,
72
+            'do_rollback'                  => false,
73
+            'allow_relaxed_file_ownership' => false,
74
+        );
75
+        $parsed_args = wp_parse_args( $args, $defaults );
76
+
77
+        $this->init();
78
+        $this->upgrade_strings();
79
+
80
+        // Is an update available?
81
+        if ( ! isset( $current->response ) || 'latest' === $current->response ) {
82
+            return new WP_Error( 'up_to_date', $this->strings['up_to_date'] );
83
+        }
84
+
85
+        $res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] );
86
+        if ( ! $res || is_wp_error( $res ) ) {
87
+            return $res;
88
+        }
89
+
90
+        $wp_dir = trailingslashit( $wp_filesystem->abspath() );
91
+
92
+        $partial = true;
93
+        if ( $parsed_args['do_rollback'] ) {
94
+            $partial = false;
95
+        } elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) {
96
+            $partial = false;
97
+        }
98
+
99
+        /*
100 100
 		 * If partial update is returned from the API, use that, unless we're doing
101 101
 		 * a reinstallation. If we cross the new_bundled version number, then use
102 102
 		 * the new_bundled zip. Don't though if the constant is set to skip bundled items.
103 103
 		 * If the API returns a no_content zip, go with it. Finally, default to the full zip.
104 104
 		 */
105
-		if ( $parsed_args['do_rollback'] && $current->packages->rollback ) {
106
-			$to_download = 'rollback';
107
-		} elseif ( $current->packages->partial && 'reinstall' !== $current->response && $wp_version === $current->partial_version && $partial ) {
108
-			$to_download = 'partial';
109
-		} elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
110
-			&& ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
111
-			$to_download = 'new_bundled';
112
-		} elseif ( $current->packages->no_content ) {
113
-			$to_download = 'no_content';
114
-		} else {
115
-			$to_download = 'full';
116
-		}
117
-
118
-		// Lock to prevent multiple Core Updates occurring.
119
-		$lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS );
120
-		if ( ! $lock ) {
121
-			return new WP_Error( 'locked', $this->strings['locked'] );
122
-		}
123
-
124
-		$download = $this->download_package( $current->packages->$to_download, true );
125
-
126
-		// Allow for signature soft-fail.
127
-		// WARNING: This may be removed in the future.
128
-		if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) {
129
-			// Output the failure error as a normal feedback, and not as an error:
130
-			/** This filter is documented in wp-admin/includes/update-core.php */
131
-			apply_filters( 'update_feedback', $download->get_error_message() );
132
-
133
-			// Report this failure back to WordPress.org for debugging purposes.
134
-			wp_version_check(
135
-				array(
136
-					'signature_failure_code' => $download->get_error_code(),
137
-					'signature_failure_data' => $download->get_error_data(),
138
-				)
139
-			);
140
-
141
-			// Pretend this error didn't happen.
142
-			$download = $download->get_error_data( 'softfail-filename' );
143
-		}
144
-
145
-		if ( is_wp_error( $download ) ) {
146
-			WP_Upgrader::release_lock( 'core_updater' );
147
-			return $download;
148
-		}
149
-
150
-		$working_dir = $this->unpack_package( $download );
151
-		if ( is_wp_error( $working_dir ) ) {
152
-			WP_Upgrader::release_lock( 'core_updater' );
153
-			return $working_dir;
154
-		}
155
-
156
-		// Copy update-core.php from the new version into place.
157
-		if ( ! $wp_filesystem->copy( $working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true ) ) {
158
-			$wp_filesystem->delete( $working_dir, true );
159
-			WP_Upgrader::release_lock( 'core_updater' );
160
-			return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php' );
161
-		}
162
-		$wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE );
163
-
164
-		wp_opcache_invalidate( ABSPATH . 'wp-admin/includes/update-core.php' );
165
-		require_once ABSPATH . 'wp-admin/includes/update-core.php';
166
-
167
-		if ( ! function_exists( 'update_core' ) ) {
168
-			WP_Upgrader::release_lock( 'core_updater' );
169
-			return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] );
170
-		}
171
-
172
-		$result = update_core( $working_dir, $wp_dir );
173
-
174
-		// In the event of an issue, we may be able to roll back.
175
-		if ( $parsed_args['attempt_rollback'] && $current->packages->rollback && ! $parsed_args['do_rollback'] ) {
176
-			$try_rollback = false;
177
-			if ( is_wp_error( $result ) ) {
178
-				$error_code = $result->get_error_code();
179
-				/*
105
+        if ( $parsed_args['do_rollback'] && $current->packages->rollback ) {
106
+            $to_download = 'rollback';
107
+        } elseif ( $current->packages->partial && 'reinstall' !== $current->response && $wp_version === $current->partial_version && $partial ) {
108
+            $to_download = 'partial';
109
+        } elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
110
+            && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
111
+            $to_download = 'new_bundled';
112
+        } elseif ( $current->packages->no_content ) {
113
+            $to_download = 'no_content';
114
+        } else {
115
+            $to_download = 'full';
116
+        }
117
+
118
+        // Lock to prevent multiple Core Updates occurring.
119
+        $lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS );
120
+        if ( ! $lock ) {
121
+            return new WP_Error( 'locked', $this->strings['locked'] );
122
+        }
123
+
124
+        $download = $this->download_package( $current->packages->$to_download, true );
125
+
126
+        // Allow for signature soft-fail.
127
+        // WARNING: This may be removed in the future.
128
+        if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) {
129
+            // Output the failure error as a normal feedback, and not as an error:
130
+            /** This filter is documented in wp-admin/includes/update-core.php */
131
+            apply_filters( 'update_feedback', $download->get_error_message() );
132
+
133
+            // Report this failure back to WordPress.org for debugging purposes.
134
+            wp_version_check(
135
+                array(
136
+                    'signature_failure_code' => $download->get_error_code(),
137
+                    'signature_failure_data' => $download->get_error_data(),
138
+                )
139
+            );
140
+
141
+            // Pretend this error didn't happen.
142
+            $download = $download->get_error_data( 'softfail-filename' );
143
+        }
144
+
145
+        if ( is_wp_error( $download ) ) {
146
+            WP_Upgrader::release_lock( 'core_updater' );
147
+            return $download;
148
+        }
149
+
150
+        $working_dir = $this->unpack_package( $download );
151
+        if ( is_wp_error( $working_dir ) ) {
152
+            WP_Upgrader::release_lock( 'core_updater' );
153
+            return $working_dir;
154
+        }
155
+
156
+        // Copy update-core.php from the new version into place.
157
+        if ( ! $wp_filesystem->copy( $working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true ) ) {
158
+            $wp_filesystem->delete( $working_dir, true );
159
+            WP_Upgrader::release_lock( 'core_updater' );
160
+            return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php' );
161
+        }
162
+        $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE );
163
+
164
+        wp_opcache_invalidate( ABSPATH . 'wp-admin/includes/update-core.php' );
165
+        require_once ABSPATH . 'wp-admin/includes/update-core.php';
166
+
167
+        if ( ! function_exists( 'update_core' ) ) {
168
+            WP_Upgrader::release_lock( 'core_updater' );
169
+            return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] );
170
+        }
171
+
172
+        $result = update_core( $working_dir, $wp_dir );
173
+
174
+        // In the event of an issue, we may be able to roll back.
175
+        if ( $parsed_args['attempt_rollback'] && $current->packages->rollback && ! $parsed_args['do_rollback'] ) {
176
+            $try_rollback = false;
177
+            if ( is_wp_error( $result ) ) {
178
+                $error_code = $result->get_error_code();
179
+                /*
180 180
 				 * Not all errors are equal. These codes are critical: copy_failed__copy_dir,
181 181
 				 * mkdir_failed__copy_dir, copy_failed__copy_dir_retry, and disk_full.
182 182
 				 * do_rollback allows for update_core() to trigger a rollback if needed.
183 183
 				 */
184
-				if ( false !== strpos( $error_code, 'do_rollback' ) ) {
185
-					$try_rollback = true;
186
-				} elseif ( false !== strpos( $error_code, '__copy_dir' ) ) {
187
-					$try_rollback = true;
188
-				} elseif ( 'disk_full' === $error_code ) {
189
-					$try_rollback = true;
190
-				}
191
-			}
192
-
193
-			if ( $try_rollback ) {
194
-				/** This filter is documented in wp-admin/includes/update-core.php */
195
-				apply_filters( 'update_feedback', $result );
196
-
197
-				/** This filter is documented in wp-admin/includes/update-core.php */
198
-				apply_filters( 'update_feedback', $this->strings['start_rollback'] );
199
-
200
-				$rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) );
201
-
202
-				$original_result = $result;
203
-				$result          = new WP_Error(
204
-					'rollback_was_required',
205
-					$this->strings['rollback_was_required'],
206
-					(object) array(
207
-						'update'   => $original_result,
208
-						'rollback' => $rollback_result,
209
-					)
210
-				);
211
-			}
212
-		}
213
-
214
-		/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
215
-		do_action(
216
-			'upgrader_process_complete',
217
-			$this,
218
-			array(
219
-				'action' => 'update',
220
-				'type'   => 'core',
221
-			)
222
-		);
223
-
224
-		// Clear the current updates.
225
-		delete_site_transient( 'update_core' );
226
-
227
-		if ( ! $parsed_args['do_rollback'] ) {
228
-			$stats = array(
229
-				'update_type'      => $current->response,
230
-				'success'          => true,
231
-				'fs_method'        => $wp_filesystem->method,
232
-				'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ),
233
-				'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '',
234
-				'time_taken'       => time() - $start_time,
235
-				'reported'         => $wp_version,
236
-				'attempted'        => $current->version,
237
-			);
238
-
239
-			if ( is_wp_error( $result ) ) {
240
-				$stats['success'] = false;
241
-				// Did a rollback occur?
242
-				if ( ! empty( $try_rollback ) ) {
243
-					$stats['error_code'] = $original_result->get_error_code();
244
-					$stats['error_data'] = $original_result->get_error_data();
245
-					// Was the rollback successful? If not, collect its error too.
246
-					$stats['rollback'] = ! is_wp_error( $rollback_result );
247
-					if ( is_wp_error( $rollback_result ) ) {
248
-						$stats['rollback_code'] = $rollback_result->get_error_code();
249
-						$stats['rollback_data'] = $rollback_result->get_error_data();
250
-					}
251
-				} else {
252
-					$stats['error_code'] = $result->get_error_code();
253
-					$stats['error_data'] = $result->get_error_data();
254
-				}
255
-			}
256
-
257
-			wp_version_check( $stats );
258
-		}
259
-
260
-		WP_Upgrader::release_lock( 'core_updater' );
261
-
262
-		return $result;
263
-	}
264
-
265
-	/**
266
-	 * Determines if this WordPress Core version should update to an offered version or not.
267
-	 *
268
-	 * @since 3.7.0
269
-	 *
270
-	 * @param string $offered_ver The offered version, of the format x.y.z.
271
-	 * @return bool True if we should update to the offered version, otherwise false.
272
-	 */
273
-	public static function should_update_to_version( $offered_ver ) {
274
-		require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z
275
-
276
-		$current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y
277
-		$new_branch     = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
278
-
279
-		$current_is_development_version = (bool) strpos( $wp_version, '-' );
280
-
281
-		// Defaults:
282
-		$upgrade_dev   = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
283
-		$upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
284
-		$upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';
285
-
286
-		// WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false.
287
-		if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
288
-			if ( false === WP_AUTO_UPDATE_CORE ) {
289
-				// Defaults to turned off, unless a filter allows it.
290
-				$upgrade_dev   = false;
291
-				$upgrade_minor = false;
292
-				$upgrade_major = false;
293
-			} elseif ( true === WP_AUTO_UPDATE_CORE
294
-				|| in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true )
295
-			) {
296
-				// ALL updates for core.
297
-				$upgrade_dev   = true;
298
-				$upgrade_minor = true;
299
-				$upgrade_major = true;
300
-			} elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
301
-				// Only minor updates for core.
302
-				$upgrade_dev   = false;
303
-				$upgrade_minor = true;
304
-				$upgrade_major = false;
305
-			}
306
-		}
307
-
308
-		// 1: If we're already on that version, not much point in updating?
309
-		if ( $offered_ver === $wp_version ) {
310
-			return false;
311
-		}
312
-
313
-		// 2: If we're running a newer version, that's a nope.
314
-		if ( version_compare( $wp_version, $offered_ver, '>' ) ) {
315
-			return false;
316
-		}
317
-
318
-		$failure_data = get_site_option( 'auto_core_update_failed' );
319
-		if ( $failure_data ) {
320
-			// If this was a critical update failure, cannot update.
321
-			if ( ! empty( $failure_data['critical'] ) ) {
322
-				return false;
323
-			}
324
-
325
-			// Don't claim we can update on update-core.php if we have a non-critical failure logged.
326
-			if ( $wp_version === $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) {
327
-				return false;
328
-			}
329
-
330
-			/*
184
+                if ( false !== strpos( $error_code, 'do_rollback' ) ) {
185
+                    $try_rollback = true;
186
+                } elseif ( false !== strpos( $error_code, '__copy_dir' ) ) {
187
+                    $try_rollback = true;
188
+                } elseif ( 'disk_full' === $error_code ) {
189
+                    $try_rollback = true;
190
+                }
191
+            }
192
+
193
+            if ( $try_rollback ) {
194
+                /** This filter is documented in wp-admin/includes/update-core.php */
195
+                apply_filters( 'update_feedback', $result );
196
+
197
+                /** This filter is documented in wp-admin/includes/update-core.php */
198
+                apply_filters( 'update_feedback', $this->strings['start_rollback'] );
199
+
200
+                $rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) );
201
+
202
+                $original_result = $result;
203
+                $result          = new WP_Error(
204
+                    'rollback_was_required',
205
+                    $this->strings['rollback_was_required'],
206
+                    (object) array(
207
+                        'update'   => $original_result,
208
+                        'rollback' => $rollback_result,
209
+                    )
210
+                );
211
+            }
212
+        }
213
+
214
+        /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
215
+        do_action(
216
+            'upgrader_process_complete',
217
+            $this,
218
+            array(
219
+                'action' => 'update',
220
+                'type'   => 'core',
221
+            )
222
+        );
223
+
224
+        // Clear the current updates.
225
+        delete_site_transient( 'update_core' );
226
+
227
+        if ( ! $parsed_args['do_rollback'] ) {
228
+            $stats = array(
229
+                'update_type'      => $current->response,
230
+                'success'          => true,
231
+                'fs_method'        => $wp_filesystem->method,
232
+                'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ),
233
+                'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '',
234
+                'time_taken'       => time() - $start_time,
235
+                'reported'         => $wp_version,
236
+                'attempted'        => $current->version,
237
+            );
238
+
239
+            if ( is_wp_error( $result ) ) {
240
+                $stats['success'] = false;
241
+                // Did a rollback occur?
242
+                if ( ! empty( $try_rollback ) ) {
243
+                    $stats['error_code'] = $original_result->get_error_code();
244
+                    $stats['error_data'] = $original_result->get_error_data();
245
+                    // Was the rollback successful? If not, collect its error too.
246
+                    $stats['rollback'] = ! is_wp_error( $rollback_result );
247
+                    if ( is_wp_error( $rollback_result ) ) {
248
+                        $stats['rollback_code'] = $rollback_result->get_error_code();
249
+                        $stats['rollback_data'] = $rollback_result->get_error_data();
250
+                    }
251
+                } else {
252
+                    $stats['error_code'] = $result->get_error_code();
253
+                    $stats['error_data'] = $result->get_error_data();
254
+                }
255
+            }
256
+
257
+            wp_version_check( $stats );
258
+        }
259
+
260
+        WP_Upgrader::release_lock( 'core_updater' );
261
+
262
+        return $result;
263
+    }
264
+
265
+    /**
266
+     * Determines if this WordPress Core version should update to an offered version or not.
267
+     *
268
+     * @since 3.7.0
269
+     *
270
+     * @param string $offered_ver The offered version, of the format x.y.z.
271
+     * @return bool True if we should update to the offered version, otherwise false.
272
+     */
273
+    public static function should_update_to_version( $offered_ver ) {
274
+        require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z
275
+
276
+        $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y
277
+        $new_branch     = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
278
+
279
+        $current_is_development_version = (bool) strpos( $wp_version, '-' );
280
+
281
+        // Defaults:
282
+        $upgrade_dev   = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
283
+        $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
284
+        $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';
285
+
286
+        // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false.
287
+        if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
288
+            if ( false === WP_AUTO_UPDATE_CORE ) {
289
+                // Defaults to turned off, unless a filter allows it.
290
+                $upgrade_dev   = false;
291
+                $upgrade_minor = false;
292
+                $upgrade_major = false;
293
+            } elseif ( true === WP_AUTO_UPDATE_CORE
294
+                || in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true )
295
+            ) {
296
+                // ALL updates for core.
297
+                $upgrade_dev   = true;
298
+                $upgrade_minor = true;
299
+                $upgrade_major = true;
300
+            } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
301
+                // Only minor updates for core.
302
+                $upgrade_dev   = false;
303
+                $upgrade_minor = true;
304
+                $upgrade_major = false;
305
+            }
306
+        }
307
+
308
+        // 1: If we're already on that version, not much point in updating?
309
+        if ( $offered_ver === $wp_version ) {
310
+            return false;
311
+        }
312
+
313
+        // 2: If we're running a newer version, that's a nope.
314
+        if ( version_compare( $wp_version, $offered_ver, '>' ) ) {
315
+            return false;
316
+        }
317
+
318
+        $failure_data = get_site_option( 'auto_core_update_failed' );
319
+        if ( $failure_data ) {
320
+            // If this was a critical update failure, cannot update.
321
+            if ( ! empty( $failure_data['critical'] ) ) {
322
+                return false;
323
+            }
324
+
325
+            // Don't claim we can update on update-core.php if we have a non-critical failure logged.
326
+            if ( $wp_version === $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) {
327
+                return false;
328
+            }
329
+
330
+            /*
331 331
 			 * Cannot update if we're retrying the same A to B update that caused a non-critical failure.
332 332
 			 * Some non-critical failures do allow retries, like download_failed.
333 333
 			 * 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2.
334 334
 			 */
335
-			if ( empty( $failure_data['retry'] ) && $wp_version === $failure_data['current'] && $offered_ver === $failure_data['attempted'] ) {
336
-				return false;
337
-			}
338
-		}
339
-
340
-		// 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2.
341
-		if ( $current_is_development_version ) {
342
-
343
-			/**
344
-			 * Filters whether to enable automatic core updates for development versions.
345
-			 *
346
-			 * @since 3.7.0
347
-			 *
348
-			 * @param bool $upgrade_dev Whether to enable automatic updates for
349
-			 *                          development versions.
350
-			 */
351
-			if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) {
352
-				return false;
353
-			}
354
-			// Else fall through to minor + major branches below.
355
-		}
356
-
357
-		// 4: Minor in-branch updates (3.7.0 -> 3.7.1 -> 3.7.2 -> 3.7.4).
358
-		if ( $current_branch === $new_branch ) {
359
-
360
-			/**
361
-			 * Filters whether to enable minor automatic core updates.
362
-			 *
363
-			 * @since 3.7.0
364
-			 *
365
-			 * @param bool $upgrade_minor Whether to enable minor automatic core updates.
366
-			 */
367
-			return apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor );
368
-		}
369
-
370
-		// 5: Major version updates (3.7.0 -> 3.8.0 -> 3.9.1).
371
-		if ( version_compare( $new_branch, $current_branch, '>' ) ) {
372
-
373
-			/**
374
-			 * Filters whether to enable major automatic core updates.
375
-			 *
376
-			 * @since 3.7.0
377
-			 *
378
-			 * @param bool $upgrade_major Whether to enable major automatic core updates.
379
-			 */
380
-			return apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
381
-		}
382
-
383
-		// If we're not sure, we don't want it.
384
-		return false;
385
-	}
386
-
387
-	/**
388
-	 * Compare the disk file checksums against the expected checksums.
389
-	 *
390
-	 * @since 3.7.0
391
-	 *
392
-	 * @global string $wp_version       The WordPress version string.
393
-	 * @global string $wp_local_package Locale code of the package.
394
-	 *
395
-	 * @return bool True if the checksums match, otherwise false.
396
-	 */
397
-	public function check_files() {
398
-		global $wp_version, $wp_local_package;
399
-
400
-		$checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
401
-
402
-		if ( ! is_array( $checksums ) ) {
403
-			return false;
404
-		}
405
-
406
-		foreach ( $checksums as $file => $checksum ) {
407
-			// Skip files which get updated.
408
-			if ( 'wp-content' === substr( $file, 0, 10 ) ) {
409
-				continue;
410
-			}
411
-			if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) {
412
-				return false;
413
-			}
414
-		}
415
-
416
-		return true;
417
-	}
335
+            if ( empty( $failure_data['retry'] ) && $wp_version === $failure_data['current'] && $offered_ver === $failure_data['attempted'] ) {
336
+                return false;
337
+            }
338
+        }
339
+
340
+        // 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2.
341
+        if ( $current_is_development_version ) {
342
+
343
+            /**
344
+             * Filters whether to enable automatic core updates for development versions.
345
+             *
346
+             * @since 3.7.0
347
+             *
348
+             * @param bool $upgrade_dev Whether to enable automatic updates for
349
+             *                          development versions.
350
+             */
351
+            if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) {
352
+                return false;
353
+            }
354
+            // Else fall through to minor + major branches below.
355
+        }
356
+
357
+        // 4: Minor in-branch updates (3.7.0 -> 3.7.1 -> 3.7.2 -> 3.7.4).
358
+        if ( $current_branch === $new_branch ) {
359
+
360
+            /**
361
+             * Filters whether to enable minor automatic core updates.
362
+             *
363
+             * @since 3.7.0
364
+             *
365
+             * @param bool $upgrade_minor Whether to enable minor automatic core updates.
366
+             */
367
+            return apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor );
368
+        }
369
+
370
+        // 5: Major version updates (3.7.0 -> 3.8.0 -> 3.9.1).
371
+        if ( version_compare( $new_branch, $current_branch, '>' ) ) {
372
+
373
+            /**
374
+             * Filters whether to enable major automatic core updates.
375
+             *
376
+             * @since 3.7.0
377
+             *
378
+             * @param bool $upgrade_major Whether to enable major automatic core updates.
379
+             */
380
+            return apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
381
+        }
382
+
383
+        // If we're not sure, we don't want it.
384
+        return false;
385
+    }
386
+
387
+    /**
388
+     * Compare the disk file checksums against the expected checksums.
389
+     *
390
+     * @since 3.7.0
391
+     *
392
+     * @global string $wp_version       The WordPress version string.
393
+     * @global string $wp_local_package Locale code of the package.
394
+     *
395
+     * @return bool True if the checksums match, otherwise false.
396
+     */
397
+    public function check_files() {
398
+        global $wp_version, $wp_local_package;
399
+
400
+        $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
401
+
402
+        if ( ! is_array( $checksums ) ) {
403
+            return false;
404
+        }
405
+
406
+        foreach ( $checksums as $file => $checksum ) {
407
+            // Skip files which get updated.
408
+            if ( 'wp-content' === substr( $file, 0, 10 ) ) {
409
+                continue;
410
+            }
411
+            if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) {
412
+                return false;
413
+            }
414
+        }
415
+
416
+        return true;
417
+    }
418 418
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-wp-list-table.php 1 patch
Indentation   +1443 added lines, -1443 removed lines patch added patch discarded remove patch
@@ -15,1263 +15,1263 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WP_List_Table {
17 17
 
18
-	/**
19
-	 * The current list of items.
20
-	 *
21
-	 * @since 3.1.0
22
-	 * @var array
23
-	 */
24
-	public $items;
25
-
26
-	/**
27
-	 * Various information about the current table.
28
-	 *
29
-	 * @since 3.1.0
30
-	 * @var array
31
-	 */
32
-	protected $_args;
33
-
34
-	/**
35
-	 * Various information needed for displaying the pagination.
36
-	 *
37
-	 * @since 3.1.0
38
-	 * @var array
39
-	 */
40
-	protected $_pagination_args = array();
41
-
42
-	/**
43
-	 * The current screen.
44
-	 *
45
-	 * @since 3.1.0
46
-	 * @var WP_Screen
47
-	 */
48
-	protected $screen;
49
-
50
-	/**
51
-	 * Cached bulk actions.
52
-	 *
53
-	 * @since 3.1.0
54
-	 * @var array
55
-	 */
56
-	private $_actions;
57
-
58
-	/**
59
-	 * Cached pagination output.
60
-	 *
61
-	 * @since 3.1.0
62
-	 * @var string
63
-	 */
64
-	private $_pagination;
65
-
66
-	/**
67
-	 * The view switcher modes.
68
-	 *
69
-	 * @since 4.1.0
70
-	 * @var array
71
-	 */
72
-	protected $modes = array();
73
-
74
-	/**
75
-	 * Stores the value returned by ->get_column_info().
76
-	 *
77
-	 * @since 4.1.0
78
-	 * @var array
79
-	 */
80
-	protected $_column_headers;
81
-
82
-	/**
83
-	 * {@internal Missing Summary}
84
-	 *
85
-	 * @var array
86
-	 */
87
-	protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
88
-
89
-	/**
90
-	 * {@internal Missing Summary}
91
-	 *
92
-	 * @var array
93
-	 */
94
-	protected $compat_methods = array(
95
-		'set_pagination_args',
96
-		'get_views',
97
-		'get_bulk_actions',
98
-		'bulk_actions',
99
-		'row_actions',
100
-		'months_dropdown',
101
-		'view_switcher',
102
-		'comments_bubble',
103
-		'get_items_per_page',
104
-		'pagination',
105
-		'get_sortable_columns',
106
-		'get_column_info',
107
-		'get_table_classes',
108
-		'display_tablenav',
109
-		'extra_tablenav',
110
-		'single_row_columns',
111
-	);
112
-
113
-	/**
114
-	 * Constructor.
115
-	 *
116
-	 * The child class should call this constructor from its own constructor to override
117
-	 * the default $args.
118
-	 *
119
-	 * @since 3.1.0
120
-	 *
121
-	 * @param array|string $args {
122
-	 *     Array or string of arguments.
123
-	 *
124
-	 *     @type string $plural   Plural value used for labels and the objects being listed.
125
-	 *                            This affects things such as CSS class-names and nonces used
126
-	 *                            in the list table, e.g. 'posts'. Default empty.
127
-	 *     @type string $singular Singular label for an object being listed, e.g. 'post'.
128
-	 *                            Default empty
129
-	 *     @type bool   $ajax     Whether the list table supports Ajax. This includes loading
130
-	 *                            and sorting data, for example. If true, the class will call
131
-	 *                            the _js_vars() method in the footer to provide variables
132
-	 *                            to any scripts handling Ajax events. Default false.
133
-	 *     @type string $screen   String containing the hook name used to determine the current
134
-	 *                            screen. If left null, the current screen will be automatically set.
135
-	 *                            Default null.
136
-	 * }
137
-	 */
138
-	public function __construct( $args = array() ) {
139
-		$args = wp_parse_args(
140
-			$args,
141
-			array(
142
-				'plural'   => '',
143
-				'singular' => '',
144
-				'ajax'     => false,
145
-				'screen'   => null,
146
-			)
147
-		);
148
-
149
-		$this->screen = convert_to_screen( $args['screen'] );
150
-
151
-		add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
152
-
153
-		if ( ! $args['plural'] ) {
154
-			$args['plural'] = $this->screen->base;
155
-		}
156
-
157
-		$args['plural']   = sanitize_key( $args['plural'] );
158
-		$args['singular'] = sanitize_key( $args['singular'] );
159
-
160
-		$this->_args = $args;
161
-
162
-		if ( $args['ajax'] ) {
163
-			// wp_enqueue_script( 'list-table' );
164
-			add_action( 'admin_footer', array( $this, '_js_vars' ) );
165
-		}
166
-
167
-		if ( empty( $this->modes ) ) {
168
-			$this->modes = array(
169
-				'list'    => __( 'Compact view' ),
170
-				'excerpt' => __( 'Extended view' ),
171
-			);
172
-		}
173
-	}
174
-
175
-	/**
176
-	 * Make private properties readable for backward compatibility.
177
-	 *
178
-	 * @since 4.0.0
179
-	 *
180
-	 * @param string $name Property to get.
181
-	 * @return mixed Property.
182
-	 */
183
-	public function __get( $name ) {
184
-		if ( in_array( $name, $this->compat_fields, true ) ) {
185
-			return $this->$name;
186
-		}
187
-	}
188
-
189
-	/**
190
-	 * Make private properties settable for backward compatibility.
191
-	 *
192
-	 * @since 4.0.0
193
-	 *
194
-	 * @param string $name  Property to check if set.
195
-	 * @param mixed  $value Property value.
196
-	 * @return mixed Newly-set property.
197
-	 */
198
-	public function __set( $name, $value ) {
199
-		if ( in_array( $name, $this->compat_fields, true ) ) {
200
-			return $this->$name = $value;
201
-		}
202
-	}
203
-
204
-	/**
205
-	 * Make private properties checkable for backward compatibility.
206
-	 *
207
-	 * @since 4.0.0
208
-	 *
209
-	 * @param string $name Property to check if set.
210
-	 * @return bool Whether the property is a back-compat property and it is set.
211
-	 */
212
-	public function __isset( $name ) {
213
-		if ( in_array( $name, $this->compat_fields, true ) ) {
214
-			return isset( $this->$name );
215
-		}
216
-
217
-		return false;
218
-	}
219
-
220
-	/**
221
-	 * Make private properties un-settable for backward compatibility.
222
-	 *
223
-	 * @since 4.0.0
224
-	 *
225
-	 * @param string $name Property to unset.
226
-	 */
227
-	public function __unset( $name ) {
228
-		if ( in_array( $name, $this->compat_fields, true ) ) {
229
-			unset( $this->$name );
230
-		}
231
-	}
232
-
233
-	/**
234
-	 * Make private/protected methods readable for backward compatibility.
235
-	 *
236
-	 * @since 4.0.0
237
-	 *
238
-	 * @param string $name      Method to call.
239
-	 * @param array  $arguments Arguments to pass when calling.
240
-	 * @return mixed|bool Return value of the callback, false otherwise.
241
-	 */
242
-	public function __call( $name, $arguments ) {
243
-		if ( in_array( $name, $this->compat_methods, true ) ) {
244
-			return $this->$name( ...$arguments );
245
-		}
246
-		return false;
247
-	}
248
-
249
-	/**
250
-	 * Checks the current user's permissions
251
-	 *
252
-	 * @since 3.1.0
253
-	 * @abstract
254
-	 */
255
-	public function ajax_user_can() {
256
-		die( 'function WP_List_Table::ajax_user_can() must be overridden in a subclass.' );
257
-	}
258
-
259
-	/**
260
-	 * Prepares the list of items for displaying.
261
-	 *
262
-	 * @uses WP_List_Table::set_pagination_args()
263
-	 *
264
-	 * @since 3.1.0
265
-	 * @abstract
266
-	 */
267
-	public function prepare_items() {
268
-		die( 'function WP_List_Table::prepare_items() must be overridden in a subclass.' );
269
-	}
270
-
271
-	/**
272
-	 * An internal method that sets all the necessary pagination arguments
273
-	 *
274
-	 * @since 3.1.0
275
-	 *
276
-	 * @param array|string $args Array or string of arguments with information about the pagination.
277
-	 */
278
-	protected function set_pagination_args( $args ) {
279
-		$args = wp_parse_args(
280
-			$args,
281
-			array(
282
-				'total_items' => 0,
283
-				'total_pages' => 0,
284
-				'per_page'    => 0,
285
-			)
286
-		);
287
-
288
-		if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
289
-			$args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
290
-		}
291
-
292
-		// Redirect if page number is invalid and headers are not already sent.
293
-		if ( ! headers_sent() && ! wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
294
-			wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
295
-			exit;
296
-		}
297
-
298
-		$this->_pagination_args = $args;
299
-	}
300
-
301
-	/**
302
-	 * Access the pagination args.
303
-	 *
304
-	 * @since 3.1.0
305
-	 *
306
-	 * @param string $key Pagination argument to retrieve. Common values include 'total_items',
307
-	 *                    'total_pages', 'per_page', or 'infinite_scroll'.
308
-	 * @return int Number of items that correspond to the given pagination argument.
309
-	 */
310
-	public function get_pagination_arg( $key ) {
311
-		if ( 'page' === $key ) {
312
-			return $this->get_pagenum();
313
-		}
314
-
315
-		if ( isset( $this->_pagination_args[ $key ] ) ) {
316
-			return $this->_pagination_args[ $key ];
317
-		}
318
-
319
-		return 0;
320
-	}
321
-
322
-	/**
323
-	 * Whether the table has items to display or not
324
-	 *
325
-	 * @since 3.1.0
326
-	 *
327
-	 * @return bool
328
-	 */
329
-	public function has_items() {
330
-		return ! empty( $this->items );
331
-	}
332
-
333
-	/**
334
-	 * Message to be displayed when there are no items
335
-	 *
336
-	 * @since 3.1.0
337
-	 */
338
-	public function no_items() {
339
-		_e( 'No items found.' );
340
-	}
341
-
342
-	/**
343
-	 * Displays the search box.
344
-	 *
345
-	 * @since 3.1.0
346
-	 *
347
-	 * @param string $text     The 'submit' button label.
348
-	 * @param string $input_id ID attribute value for the search input field.
349
-	 */
350
-	public function search_box( $text, $input_id ) {
351
-		if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
352
-			return;
353
-		}
354
-
355
-		$input_id = $input_id . '-search-input';
356
-
357
-		if ( ! empty( $_REQUEST['orderby'] ) ) {
358
-			echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
359
-		}
360
-		if ( ! empty( $_REQUEST['order'] ) ) {
361
-			echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
362
-		}
363
-		if ( ! empty( $_REQUEST['post_mime_type'] ) ) {
364
-			echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
365
-		}
366
-		if ( ! empty( $_REQUEST['detached'] ) ) {
367
-			echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
368
-		}
369
-		?>
18
+    /**
19
+     * The current list of items.
20
+     *
21
+     * @since 3.1.0
22
+     * @var array
23
+     */
24
+    public $items;
25
+
26
+    /**
27
+     * Various information about the current table.
28
+     *
29
+     * @since 3.1.0
30
+     * @var array
31
+     */
32
+    protected $_args;
33
+
34
+    /**
35
+     * Various information needed for displaying the pagination.
36
+     *
37
+     * @since 3.1.0
38
+     * @var array
39
+     */
40
+    protected $_pagination_args = array();
41
+
42
+    /**
43
+     * The current screen.
44
+     *
45
+     * @since 3.1.0
46
+     * @var WP_Screen
47
+     */
48
+    protected $screen;
49
+
50
+    /**
51
+     * Cached bulk actions.
52
+     *
53
+     * @since 3.1.0
54
+     * @var array
55
+     */
56
+    private $_actions;
57
+
58
+    /**
59
+     * Cached pagination output.
60
+     *
61
+     * @since 3.1.0
62
+     * @var string
63
+     */
64
+    private $_pagination;
65
+
66
+    /**
67
+     * The view switcher modes.
68
+     *
69
+     * @since 4.1.0
70
+     * @var array
71
+     */
72
+    protected $modes = array();
73
+
74
+    /**
75
+     * Stores the value returned by ->get_column_info().
76
+     *
77
+     * @since 4.1.0
78
+     * @var array
79
+     */
80
+    protected $_column_headers;
81
+
82
+    /**
83
+     * {@internal Missing Summary}
84
+     *
85
+     * @var array
86
+     */
87
+    protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
88
+
89
+    /**
90
+     * {@internal Missing Summary}
91
+     *
92
+     * @var array
93
+     */
94
+    protected $compat_methods = array(
95
+        'set_pagination_args',
96
+        'get_views',
97
+        'get_bulk_actions',
98
+        'bulk_actions',
99
+        'row_actions',
100
+        'months_dropdown',
101
+        'view_switcher',
102
+        'comments_bubble',
103
+        'get_items_per_page',
104
+        'pagination',
105
+        'get_sortable_columns',
106
+        'get_column_info',
107
+        'get_table_classes',
108
+        'display_tablenav',
109
+        'extra_tablenav',
110
+        'single_row_columns',
111
+    );
112
+
113
+    /**
114
+     * Constructor.
115
+     *
116
+     * The child class should call this constructor from its own constructor to override
117
+     * the default $args.
118
+     *
119
+     * @since 3.1.0
120
+     *
121
+     * @param array|string $args {
122
+     *     Array or string of arguments.
123
+     *
124
+     *     @type string $plural   Plural value used for labels and the objects being listed.
125
+     *                            This affects things such as CSS class-names and nonces used
126
+     *                            in the list table, e.g. 'posts'. Default empty.
127
+     *     @type string $singular Singular label for an object being listed, e.g. 'post'.
128
+     *                            Default empty
129
+     *     @type bool   $ajax     Whether the list table supports Ajax. This includes loading
130
+     *                            and sorting data, for example. If true, the class will call
131
+     *                            the _js_vars() method in the footer to provide variables
132
+     *                            to any scripts handling Ajax events. Default false.
133
+     *     @type string $screen   String containing the hook name used to determine the current
134
+     *                            screen. If left null, the current screen will be automatically set.
135
+     *                            Default null.
136
+     * }
137
+     */
138
+    public function __construct( $args = array() ) {
139
+        $args = wp_parse_args(
140
+            $args,
141
+            array(
142
+                'plural'   => '',
143
+                'singular' => '',
144
+                'ajax'     => false,
145
+                'screen'   => null,
146
+            )
147
+        );
148
+
149
+        $this->screen = convert_to_screen( $args['screen'] );
150
+
151
+        add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
152
+
153
+        if ( ! $args['plural'] ) {
154
+            $args['plural'] = $this->screen->base;
155
+        }
156
+
157
+        $args['plural']   = sanitize_key( $args['plural'] );
158
+        $args['singular'] = sanitize_key( $args['singular'] );
159
+
160
+        $this->_args = $args;
161
+
162
+        if ( $args['ajax'] ) {
163
+            // wp_enqueue_script( 'list-table' );
164
+            add_action( 'admin_footer', array( $this, '_js_vars' ) );
165
+        }
166
+
167
+        if ( empty( $this->modes ) ) {
168
+            $this->modes = array(
169
+                'list'    => __( 'Compact view' ),
170
+                'excerpt' => __( 'Extended view' ),
171
+            );
172
+        }
173
+    }
174
+
175
+    /**
176
+     * Make private properties readable for backward compatibility.
177
+     *
178
+     * @since 4.0.0
179
+     *
180
+     * @param string $name Property to get.
181
+     * @return mixed Property.
182
+     */
183
+    public function __get( $name ) {
184
+        if ( in_array( $name, $this->compat_fields, true ) ) {
185
+            return $this->$name;
186
+        }
187
+    }
188
+
189
+    /**
190
+     * Make private properties settable for backward compatibility.
191
+     *
192
+     * @since 4.0.0
193
+     *
194
+     * @param string $name  Property to check if set.
195
+     * @param mixed  $value Property value.
196
+     * @return mixed Newly-set property.
197
+     */
198
+    public function __set( $name, $value ) {
199
+        if ( in_array( $name, $this->compat_fields, true ) ) {
200
+            return $this->$name = $value;
201
+        }
202
+    }
203
+
204
+    /**
205
+     * Make private properties checkable for backward compatibility.
206
+     *
207
+     * @since 4.0.0
208
+     *
209
+     * @param string $name Property to check if set.
210
+     * @return bool Whether the property is a back-compat property and it is set.
211
+     */
212
+    public function __isset( $name ) {
213
+        if ( in_array( $name, $this->compat_fields, true ) ) {
214
+            return isset( $this->$name );
215
+        }
216
+
217
+        return false;
218
+    }
219
+
220
+    /**
221
+     * Make private properties un-settable for backward compatibility.
222
+     *
223
+     * @since 4.0.0
224
+     *
225
+     * @param string $name Property to unset.
226
+     */
227
+    public function __unset( $name ) {
228
+        if ( in_array( $name, $this->compat_fields, true ) ) {
229
+            unset( $this->$name );
230
+        }
231
+    }
232
+
233
+    /**
234
+     * Make private/protected methods readable for backward compatibility.
235
+     *
236
+     * @since 4.0.0
237
+     *
238
+     * @param string $name      Method to call.
239
+     * @param array  $arguments Arguments to pass when calling.
240
+     * @return mixed|bool Return value of the callback, false otherwise.
241
+     */
242
+    public function __call( $name, $arguments ) {
243
+        if ( in_array( $name, $this->compat_methods, true ) ) {
244
+            return $this->$name( ...$arguments );
245
+        }
246
+        return false;
247
+    }
248
+
249
+    /**
250
+     * Checks the current user's permissions
251
+     *
252
+     * @since 3.1.0
253
+     * @abstract
254
+     */
255
+    public function ajax_user_can() {
256
+        die( 'function WP_List_Table::ajax_user_can() must be overridden in a subclass.' );
257
+    }
258
+
259
+    /**
260
+     * Prepares the list of items for displaying.
261
+     *
262
+     * @uses WP_List_Table::set_pagination_args()
263
+     *
264
+     * @since 3.1.0
265
+     * @abstract
266
+     */
267
+    public function prepare_items() {
268
+        die( 'function WP_List_Table::prepare_items() must be overridden in a subclass.' );
269
+    }
270
+
271
+    /**
272
+     * An internal method that sets all the necessary pagination arguments
273
+     *
274
+     * @since 3.1.0
275
+     *
276
+     * @param array|string $args Array or string of arguments with information about the pagination.
277
+     */
278
+    protected function set_pagination_args( $args ) {
279
+        $args = wp_parse_args(
280
+            $args,
281
+            array(
282
+                'total_items' => 0,
283
+                'total_pages' => 0,
284
+                'per_page'    => 0,
285
+            )
286
+        );
287
+
288
+        if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
289
+            $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
290
+        }
291
+
292
+        // Redirect if page number is invalid and headers are not already sent.
293
+        if ( ! headers_sent() && ! wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
294
+            wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
295
+            exit;
296
+        }
297
+
298
+        $this->_pagination_args = $args;
299
+    }
300
+
301
+    /**
302
+     * Access the pagination args.
303
+     *
304
+     * @since 3.1.0
305
+     *
306
+     * @param string $key Pagination argument to retrieve. Common values include 'total_items',
307
+     *                    'total_pages', 'per_page', or 'infinite_scroll'.
308
+     * @return int Number of items that correspond to the given pagination argument.
309
+     */
310
+    public function get_pagination_arg( $key ) {
311
+        if ( 'page' === $key ) {
312
+            return $this->get_pagenum();
313
+        }
314
+
315
+        if ( isset( $this->_pagination_args[ $key ] ) ) {
316
+            return $this->_pagination_args[ $key ];
317
+        }
318
+
319
+        return 0;
320
+    }
321
+
322
+    /**
323
+     * Whether the table has items to display or not
324
+     *
325
+     * @since 3.1.0
326
+     *
327
+     * @return bool
328
+     */
329
+    public function has_items() {
330
+        return ! empty( $this->items );
331
+    }
332
+
333
+    /**
334
+     * Message to be displayed when there are no items
335
+     *
336
+     * @since 3.1.0
337
+     */
338
+    public function no_items() {
339
+        _e( 'No items found.' );
340
+    }
341
+
342
+    /**
343
+     * Displays the search box.
344
+     *
345
+     * @since 3.1.0
346
+     *
347
+     * @param string $text     The 'submit' button label.
348
+     * @param string $input_id ID attribute value for the search input field.
349
+     */
350
+    public function search_box( $text, $input_id ) {
351
+        if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
352
+            return;
353
+        }
354
+
355
+        $input_id = $input_id . '-search-input';
356
+
357
+        if ( ! empty( $_REQUEST['orderby'] ) ) {
358
+            echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
359
+        }
360
+        if ( ! empty( $_REQUEST['order'] ) ) {
361
+            echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
362
+        }
363
+        if ( ! empty( $_REQUEST['post_mime_type'] ) ) {
364
+            echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
365
+        }
366
+        if ( ! empty( $_REQUEST['detached'] ) ) {
367
+            echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
368
+        }
369
+        ?>
370 370
 <p class="search-box">
371 371
 	<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>
372 372
 	<input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" value="<?php _admin_search_query(); ?>" />
373 373
 		<?php submit_button( $text, '', '', false, array( 'id' => 'search-submit' ) ); ?>
374 374
 </p>
375 375
 		<?php
376
-	}
377
-
378
-	/**
379
-	 * Gets the list of views available on this table.
380
-	 *
381
-	 * The format is an associative array:
382
-	 * - `'id' => 'link'`
383
-	 *
384
-	 * @since 3.1.0
385
-	 *
386
-	 * @return array
387
-	 */
388
-	protected function get_views() {
389
-		return array();
390
-	}
391
-
392
-	/**
393
-	 * Displays the list of views available on this table.
394
-	 *
395
-	 * @since 3.1.0
396
-	 */
397
-	public function views() {
398
-		$views = $this->get_views();
399
-		/**
400
-		 * Filters the list of available list table views.
401
-		 *
402
-		 * The dynamic portion of the hook name, `$this->screen->id`, refers
403
-		 * to the ID of the current screen.
404
-		 *
405
-		 * @since 3.1.0
406
-		 *
407
-		 * @param string[] $views An array of available list table views.
408
-		 */
409
-		$views = apply_filters( "views_{$this->screen->id}", $views );
410
-
411
-		if ( empty( $views ) ) {
412
-			return;
413
-		}
414
-
415
-		$this->screen->render_screen_reader_content( 'heading_views' );
416
-
417
-		echo "<ul class='subsubsub'>\n";
418
-		foreach ( $views as $class => $view ) {
419
-			$views[ $class ] = "\t<li class='$class'>$view";
420
-		}
421
-		echo implode( " |</li>\n", $views ) . "</li>\n";
422
-		echo '</ul>';
423
-	}
424
-
425
-	/**
426
-	 * Retrieves the list of bulk actions available for this table.
427
-	 *
428
-	 * The format is an associative array where each element represents either a top level option value and label, or
429
-	 * an array representing an optgroup and its options.
430
-	 *
431
-	 * For a standard option, the array element key is the field value and the array element value is the field label.
432
-	 *
433
-	 * For an optgroup, the array element key is the label and the array element value is an associative array of
434
-	 * options as above.
435
-	 *
436
-	 * Example:
437
-	 *
438
-	 *     [
439
-	 *         'edit'         => 'Edit',
440
-	 *         'delete'       => 'Delete',
441
-	 *         'Change State' => [
442
-	 *             'feature' => 'Featured',
443
-	 *             'sale'    => 'On Sale',
444
-	 *         ]
445
-	 *     ]
446
-	 *
447
-	 * @since 3.1.0
448
-	 * @since 5.6.0 A bulk action can now contain an array of options in order to create an optgroup.
449
-	 *
450
-	 * @return array
451
-	 */
452
-	protected function get_bulk_actions() {
453
-		return array();
454
-	}
455
-
456
-	/**
457
-	 * Displays the bulk actions dropdown.
458
-	 *
459
-	 * @since 3.1.0
460
-	 *
461
-	 * @param string $which The location of the bulk actions: 'top' or 'bottom'.
462
-	 *                      This is designated as optional for backward compatibility.
463
-	 */
464
-	protected function bulk_actions( $which = '' ) {
465
-		if ( is_null( $this->_actions ) ) {
466
-			$this->_actions = $this->get_bulk_actions();
467
-
468
-			/**
469
-			 * Filters the items in the bulk actions menu of the list table.
470
-			 *
471
-			 * The dynamic portion of the hook name, `$this->screen->id`, refers
472
-			 * to the ID of the current screen.
473
-			 *
474
-			 * @since 3.1.0
475
-			 * @since 5.6.0 A bulk action can now contain an array of options in order to create an optgroup.
476
-			 *
477
-			 * @param array $actions An array of the available bulk actions.
478
-			 */
479
-			$this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
480
-
481
-			$two = '';
482
-		} else {
483
-			$two = '2';
484
-		}
485
-
486
-		if ( empty( $this->_actions ) ) {
487
-			return;
488
-		}
489
-
490
-		echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
491
-		echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
492
-		echo '<option value="-1">' . __( 'Bulk actions' ) . "</option>\n";
493
-
494
-		foreach ( $this->_actions as $key => $value ) {
495
-			if ( is_array( $value ) ) {
496
-				echo "\t" . '<optgroup label="' . esc_attr( $key ) . '">' . "\n";
497
-
498
-				foreach ( $value as $name => $title ) {
499
-					$class = ( 'edit' === $name ) ? ' class="hide-if-no-js"' : '';
500
-
501
-					echo "\t\t" . '<option value="' . esc_attr( $name ) . '"' . $class . '>' . $title . "</option>\n";
502
-				}
503
-				echo "\t" . "</optgroup>\n";
504
-			} else {
505
-				$class = ( 'edit' === $key ) ? ' class="hide-if-no-js"' : '';
506
-
507
-				echo "\t" . '<option value="' . esc_attr( $key ) . '"' . $class . '>' . $value . "</option>\n";
508
-			}
509
-		}
510
-
511
-		echo "</select>\n";
512
-
513
-		submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
514
-		echo "\n";
515
-	}
516
-
517
-	/**
518
-	 * Gets the current action selected from the bulk actions dropdown.
519
-	 *
520
-	 * @since 3.1.0
521
-	 *
522
-	 * @return string|false The action name. False if no action was selected.
523
-	 */
524
-	public function current_action() {
525
-		if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
526
-			return false;
527
-		}
528
-
529
-		if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) {
530
-			return $_REQUEST['action'];
531
-		}
532
-
533
-		return false;
534
-	}
535
-
536
-	/**
537
-	 * Generates the required HTML for a list of row action links.
538
-	 *
539
-	 * @since 3.1.0
540
-	 *
541
-	 * @param string[] $actions        An array of action links.
542
-	 * @param bool     $always_visible Whether the actions should be always visible.
543
-	 * @return string The HTML for the row actions.
544
-	 */
545
-	protected function row_actions( $actions, $always_visible = false ) {
546
-		$action_count = count( $actions );
547
-
548
-		if ( ! $action_count ) {
549
-			return '';
550
-		}
551
-
552
-		$mode = get_user_setting( 'posts_list_mode', 'list' );
553
-
554
-		if ( 'excerpt' === $mode ) {
555
-			$always_visible = true;
556
-		}
557
-
558
-		$out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
559
-
560
-		$i = 0;
561
-
562
-		foreach ( $actions as $action => $link ) {
563
-			++$i;
564
-
565
-			$sep = ( $i < $action_count ) ? ' | ' : '';
566
-
567
-			$out .= "<span class='$action'>$link$sep</span>";
568
-		}
569
-
570
-		$out .= '</div>';
571
-
572
-		$out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
573
-
574
-		return $out;
575
-	}
576
-
577
-	/**
578
-	 * Displays a dropdown for filtering items in the list table by month.
579
-	 *
580
-	 * @since 3.1.0
581
-	 *
582
-	 * @global wpdb      $wpdb      WordPress database abstraction object.
583
-	 * @global WP_Locale $wp_locale WordPress date and time locale object.
584
-	 *
585
-	 * @param string $post_type The post type.
586
-	 */
587
-	protected function months_dropdown( $post_type ) {
588
-		global $wpdb, $wp_locale;
589
-
590
-		/**
591
-		 * Filters whether to remove the 'Months' drop-down from the post list table.
592
-		 *
593
-		 * @since 4.2.0
594
-		 *
595
-		 * @param bool   $disable   Whether to disable the drop-down. Default false.
596
-		 * @param string $post_type The post type.
597
-		 */
598
-		if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
599
-			return;
600
-		}
601
-
602
-		/**
603
-		 * Filters to short-circuit performing the months dropdown query.
604
-		 *
605
-		 * @since 5.7.0
606
-		 *
607
-		 * @param object[]|false $months   'Months' drop-down results. Default false.
608
-		 * @param string         $post_type The post type.
609
-		 */
610
-		$months = apply_filters( 'pre_months_dropdown_query', false, $post_type );
611
-
612
-		if ( ! is_array( $months ) ) {
613
-			$extra_checks = "AND post_status != 'auto-draft'";
614
-			if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
615
-				$extra_checks .= " AND post_status != 'trash'";
616
-			} elseif ( isset( $_GET['post_status'] ) ) {
617
-				$extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
618
-			}
619
-
620
-			$months = $wpdb->get_results(
621
-				$wpdb->prepare(
622
-					"
376
+    }
377
+
378
+    /**
379
+     * Gets the list of views available on this table.
380
+     *
381
+     * The format is an associative array:
382
+     * - `'id' => 'link'`
383
+     *
384
+     * @since 3.1.0
385
+     *
386
+     * @return array
387
+     */
388
+    protected function get_views() {
389
+        return array();
390
+    }
391
+
392
+    /**
393
+     * Displays the list of views available on this table.
394
+     *
395
+     * @since 3.1.0
396
+     */
397
+    public function views() {
398
+        $views = $this->get_views();
399
+        /**
400
+         * Filters the list of available list table views.
401
+         *
402
+         * The dynamic portion of the hook name, `$this->screen->id`, refers
403
+         * to the ID of the current screen.
404
+         *
405
+         * @since 3.1.0
406
+         *
407
+         * @param string[] $views An array of available list table views.
408
+         */
409
+        $views = apply_filters( "views_{$this->screen->id}", $views );
410
+
411
+        if ( empty( $views ) ) {
412
+            return;
413
+        }
414
+
415
+        $this->screen->render_screen_reader_content( 'heading_views' );
416
+
417
+        echo "<ul class='subsubsub'>\n";
418
+        foreach ( $views as $class => $view ) {
419
+            $views[ $class ] = "\t<li class='$class'>$view";
420
+        }
421
+        echo implode( " |</li>\n", $views ) . "</li>\n";
422
+        echo '</ul>';
423
+    }
424
+
425
+    /**
426
+     * Retrieves the list of bulk actions available for this table.
427
+     *
428
+     * The format is an associative array where each element represents either a top level option value and label, or
429
+     * an array representing an optgroup and its options.
430
+     *
431
+     * For a standard option, the array element key is the field value and the array element value is the field label.
432
+     *
433
+     * For an optgroup, the array element key is the label and the array element value is an associative array of
434
+     * options as above.
435
+     *
436
+     * Example:
437
+     *
438
+     *     [
439
+     *         'edit'         => 'Edit',
440
+     *         'delete'       => 'Delete',
441
+     *         'Change State' => [
442
+     *             'feature' => 'Featured',
443
+     *             'sale'    => 'On Sale',
444
+     *         ]
445
+     *     ]
446
+     *
447
+     * @since 3.1.0
448
+     * @since 5.6.0 A bulk action can now contain an array of options in order to create an optgroup.
449
+     *
450
+     * @return array
451
+     */
452
+    protected function get_bulk_actions() {
453
+        return array();
454
+    }
455
+
456
+    /**
457
+     * Displays the bulk actions dropdown.
458
+     *
459
+     * @since 3.1.0
460
+     *
461
+     * @param string $which The location of the bulk actions: 'top' or 'bottom'.
462
+     *                      This is designated as optional for backward compatibility.
463
+     */
464
+    protected function bulk_actions( $which = '' ) {
465
+        if ( is_null( $this->_actions ) ) {
466
+            $this->_actions = $this->get_bulk_actions();
467
+
468
+            /**
469
+             * Filters the items in the bulk actions menu of the list table.
470
+             *
471
+             * The dynamic portion of the hook name, `$this->screen->id`, refers
472
+             * to the ID of the current screen.
473
+             *
474
+             * @since 3.1.0
475
+             * @since 5.6.0 A bulk action can now contain an array of options in order to create an optgroup.
476
+             *
477
+             * @param array $actions An array of the available bulk actions.
478
+             */
479
+            $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
480
+
481
+            $two = '';
482
+        } else {
483
+            $two = '2';
484
+        }
485
+
486
+        if ( empty( $this->_actions ) ) {
487
+            return;
488
+        }
489
+
490
+        echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
491
+        echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
492
+        echo '<option value="-1">' . __( 'Bulk actions' ) . "</option>\n";
493
+
494
+        foreach ( $this->_actions as $key => $value ) {
495
+            if ( is_array( $value ) ) {
496
+                echo "\t" . '<optgroup label="' . esc_attr( $key ) . '">' . "\n";
497
+
498
+                foreach ( $value as $name => $title ) {
499
+                    $class = ( 'edit' === $name ) ? ' class="hide-if-no-js"' : '';
500
+
501
+                    echo "\t\t" . '<option value="' . esc_attr( $name ) . '"' . $class . '>' . $title . "</option>\n";
502
+                }
503
+                echo "\t" . "</optgroup>\n";
504
+            } else {
505
+                $class = ( 'edit' === $key ) ? ' class="hide-if-no-js"' : '';
506
+
507
+                echo "\t" . '<option value="' . esc_attr( $key ) . '"' . $class . '>' . $value . "</option>\n";
508
+            }
509
+        }
510
+
511
+        echo "</select>\n";
512
+
513
+        submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
514
+        echo "\n";
515
+    }
516
+
517
+    /**
518
+     * Gets the current action selected from the bulk actions dropdown.
519
+     *
520
+     * @since 3.1.0
521
+     *
522
+     * @return string|false The action name. False if no action was selected.
523
+     */
524
+    public function current_action() {
525
+        if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
526
+            return false;
527
+        }
528
+
529
+        if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) {
530
+            return $_REQUEST['action'];
531
+        }
532
+
533
+        return false;
534
+    }
535
+
536
+    /**
537
+     * Generates the required HTML for a list of row action links.
538
+     *
539
+     * @since 3.1.0
540
+     *
541
+     * @param string[] $actions        An array of action links.
542
+     * @param bool     $always_visible Whether the actions should be always visible.
543
+     * @return string The HTML for the row actions.
544
+     */
545
+    protected function row_actions( $actions, $always_visible = false ) {
546
+        $action_count = count( $actions );
547
+
548
+        if ( ! $action_count ) {
549
+            return '';
550
+        }
551
+
552
+        $mode = get_user_setting( 'posts_list_mode', 'list' );
553
+
554
+        if ( 'excerpt' === $mode ) {
555
+            $always_visible = true;
556
+        }
557
+
558
+        $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
559
+
560
+        $i = 0;
561
+
562
+        foreach ( $actions as $action => $link ) {
563
+            ++$i;
564
+
565
+            $sep = ( $i < $action_count ) ? ' | ' : '';
566
+
567
+            $out .= "<span class='$action'>$link$sep</span>";
568
+        }
569
+
570
+        $out .= '</div>';
571
+
572
+        $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
573
+
574
+        return $out;
575
+    }
576
+
577
+    /**
578
+     * Displays a dropdown for filtering items in the list table by month.
579
+     *
580
+     * @since 3.1.0
581
+     *
582
+     * @global wpdb      $wpdb      WordPress database abstraction object.
583
+     * @global WP_Locale $wp_locale WordPress date and time locale object.
584
+     *
585
+     * @param string $post_type The post type.
586
+     */
587
+    protected function months_dropdown( $post_type ) {
588
+        global $wpdb, $wp_locale;
589
+
590
+        /**
591
+         * Filters whether to remove the 'Months' drop-down from the post list table.
592
+         *
593
+         * @since 4.2.0
594
+         *
595
+         * @param bool   $disable   Whether to disable the drop-down. Default false.
596
+         * @param string $post_type The post type.
597
+         */
598
+        if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
599
+            return;
600
+        }
601
+
602
+        /**
603
+         * Filters to short-circuit performing the months dropdown query.
604
+         *
605
+         * @since 5.7.0
606
+         *
607
+         * @param object[]|false $months   'Months' drop-down results. Default false.
608
+         * @param string         $post_type The post type.
609
+         */
610
+        $months = apply_filters( 'pre_months_dropdown_query', false, $post_type );
611
+
612
+        if ( ! is_array( $months ) ) {
613
+            $extra_checks = "AND post_status != 'auto-draft'";
614
+            if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
615
+                $extra_checks .= " AND post_status != 'trash'";
616
+            } elseif ( isset( $_GET['post_status'] ) ) {
617
+                $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
618
+            }
619
+
620
+            $months = $wpdb->get_results(
621
+                $wpdb->prepare(
622
+                    "
623 623
 				SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
624 624
 				FROM $wpdb->posts
625 625
 				WHERE post_type = %s
626 626
 				$extra_checks
627 627
 				ORDER BY post_date DESC
628 628
 			",
629
-					$post_type
630
-				)
631
-			);
632
-		}
633
-
634
-		/**
635
-		 * Filters the 'Months' drop-down results.
636
-		 *
637
-		 * @since 3.7.0
638
-		 *
639
-		 * @param object[] $months    Array of the months drop-down query results.
640
-		 * @param string   $post_type The post type.
641
-		 */
642
-		$months = apply_filters( 'months_dropdown_results', $months, $post_type );
643
-
644
-		$month_count = count( $months );
645
-
646
-		if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
647
-			return;
648
-		}
649
-
650
-		$m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
651
-		?>
629
+                    $post_type
630
+                )
631
+            );
632
+        }
633
+
634
+        /**
635
+         * Filters the 'Months' drop-down results.
636
+         *
637
+         * @since 3.7.0
638
+         *
639
+         * @param object[] $months    Array of the months drop-down query results.
640
+         * @param string   $post_type The post type.
641
+         */
642
+        $months = apply_filters( 'months_dropdown_results', $months, $post_type );
643
+
644
+        $month_count = count( $months );
645
+
646
+        if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
647
+            return;
648
+        }
649
+
650
+        $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
651
+        ?>
652 652
 		<label for="filter-by-date" class="screen-reader-text"><?php echo get_post_type_object( $post_type )->labels->filter_by_date; ?></label>
653 653
 		<select name="m" id="filter-by-date">
654 654
 			<option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
655 655
 		<?php
656
-		foreach ( $months as $arc_row ) {
657
-			if ( 0 == $arc_row->year ) {
658
-				continue;
659
-			}
660
-
661
-			$month = zeroise( $arc_row->month, 2 );
662
-			$year  = $arc_row->year;
663
-
664
-			printf(
665
-				"<option %s value='%s'>%s</option>\n",
666
-				selected( $m, $year . $month, false ),
667
-				esc_attr( $arc_row->year . $month ),
668
-				/* translators: 1: Month name, 2: 4-digit year. */
669
-				sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
670
-			);
671
-		}
672
-		?>
656
+        foreach ( $months as $arc_row ) {
657
+            if ( 0 == $arc_row->year ) {
658
+                continue;
659
+            }
660
+
661
+            $month = zeroise( $arc_row->month, 2 );
662
+            $year  = $arc_row->year;
663
+
664
+            printf(
665
+                "<option %s value='%s'>%s</option>\n",
666
+                selected( $m, $year . $month, false ),
667
+                esc_attr( $arc_row->year . $month ),
668
+                /* translators: 1: Month name, 2: 4-digit year. */
669
+                sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
670
+            );
671
+        }
672
+        ?>
673 673
 		</select>
674 674
 		<?php
675
-	}
676
-
677
-	/**
678
-	 * Displays a view switcher.
679
-	 *
680
-	 * @since 3.1.0
681
-	 *
682
-	 * @param string $current_mode
683
-	 */
684
-	protected function view_switcher( $current_mode ) {
685
-		?>
675
+    }
676
+
677
+    /**
678
+     * Displays a view switcher.
679
+     *
680
+     * @since 3.1.0
681
+     *
682
+     * @param string $current_mode
683
+     */
684
+    protected function view_switcher( $current_mode ) {
685
+        ?>
686 686
 		<input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
687 687
 		<div class="view-switch">
688 688
 		<?php
689
-		foreach ( $this->modes as $mode => $title ) {
690
-			$classes      = array( 'view-' . $mode );
691
-			$aria_current = '';
692
-
693
-			if ( $current_mode === $mode ) {
694
-				$classes[]    = 'current';
695
-				$aria_current = ' aria-current="page"';
696
-			}
697
-
698
-			printf(
699
-				"<a href='%s' class='%s' id='view-switch-$mode'$aria_current><span class='screen-reader-text'>%s</span></a>\n",
700
-				esc_url( remove_query_arg( 'attachment-filter', add_query_arg( 'mode', $mode ) ) ),
701
-				implode( ' ', $classes ),
702
-				$title
703
-			);
704
-		}
705
-		?>
689
+        foreach ( $this->modes as $mode => $title ) {
690
+            $classes      = array( 'view-' . $mode );
691
+            $aria_current = '';
692
+
693
+            if ( $current_mode === $mode ) {
694
+                $classes[]    = 'current';
695
+                $aria_current = ' aria-current="page"';
696
+            }
697
+
698
+            printf(
699
+                "<a href='%s' class='%s' id='view-switch-$mode'$aria_current><span class='screen-reader-text'>%s</span></a>\n",
700
+                esc_url( remove_query_arg( 'attachment-filter', add_query_arg( 'mode', $mode ) ) ),
701
+                implode( ' ', $classes ),
702
+                $title
703
+            );
704
+        }
705
+        ?>
706 706
 		</div>
707 707
 		<?php
708
-	}
709
-
710
-	/**
711
-	 * Displays a comment count bubble.
712
-	 *
713
-	 * @since 3.1.0
714
-	 *
715
-	 * @param int $post_id          The post ID.
716
-	 * @param int $pending_comments Number of pending comments.
717
-	 */
718
-	protected function comments_bubble( $post_id, $pending_comments ) {
719
-		$approved_comments = get_comments_number();
720
-
721
-		$approved_comments_number = number_format_i18n( $approved_comments );
722
-		$pending_comments_number  = number_format_i18n( $pending_comments );
723
-
724
-		$approved_only_phrase = sprintf(
725
-			/* translators: %s: Number of comments. */
726
-			_n( '%s comment', '%s comments', $approved_comments ),
727
-			$approved_comments_number
728
-		);
729
-
730
-		$approved_phrase = sprintf(
731
-			/* translators: %s: Number of comments. */
732
-			_n( '%s approved comment', '%s approved comments', $approved_comments ),
733
-			$approved_comments_number
734
-		);
735
-
736
-		$pending_phrase = sprintf(
737
-			/* translators: %s: Number of comments. */
738
-			_n( '%s pending comment', '%s pending comments', $pending_comments ),
739
-			$pending_comments_number
740
-		);
741
-
742
-		if ( ! $approved_comments && ! $pending_comments ) {
743
-			// No comments at all.
744
-			printf(
745
-				'<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
746
-				__( 'No comments' )
747
-			);
748
-		} elseif ( $approved_comments && 'trash' === get_post_status( $post_id ) ) {
749
-			// Don't link the comment bubble for a trashed post.
750
-			printf(
751
-				'<span class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
752
-				$approved_comments_number,
753
-				$pending_comments ? $approved_phrase : $approved_only_phrase
754
-			);
755
-		} elseif ( $approved_comments ) {
756
-			// Link the comment bubble to approved comments.
757
-			printf(
758
-				'<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
759
-				esc_url(
760
-					add_query_arg(
761
-						array(
762
-							'p'              => $post_id,
763
-							'comment_status' => 'approved',
764
-						),
765
-						admin_url( 'edit-comments.php' )
766
-					)
767
-				),
768
-				$approved_comments_number,
769
-				$pending_comments ? $approved_phrase : $approved_only_phrase
770
-			);
771
-		} else {
772
-			// Don't link the comment bubble when there are no approved comments.
773
-			printf(
774
-				'<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
775
-				$approved_comments_number,
776
-				$pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
777
-			);
778
-		}
779
-
780
-		if ( $pending_comments ) {
781
-			printf(
782
-				'<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
783
-				esc_url(
784
-					add_query_arg(
785
-						array(
786
-							'p'              => $post_id,
787
-							'comment_status' => 'moderated',
788
-						),
789
-						admin_url( 'edit-comments.php' )
790
-					)
791
-				),
792
-				$pending_comments_number,
793
-				$pending_phrase
794
-			);
795
-		} else {
796
-			printf(
797
-				'<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
798
-				$pending_comments_number,
799
-				$approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
800
-			);
801
-		}
802
-	}
803
-
804
-	/**
805
-	 * Gets the current page number.
806
-	 *
807
-	 * @since 3.1.0
808
-	 *
809
-	 * @return int
810
-	 */
811
-	public function get_pagenum() {
812
-		$pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
813
-
814
-		if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) {
815
-			$pagenum = $this->_pagination_args['total_pages'];
816
-		}
817
-
818
-		return max( 1, $pagenum );
819
-	}
820
-
821
-	/**
822
-	 * Gets the number of items to display on a single page.
823
-	 *
824
-	 * @since 3.1.0
825
-	 *
826
-	 * @param string $option        User option name.
827
-	 * @param int    $default_value Optional. The number of items to display. Default 20.
828
-	 * @return int
829
-	 */
830
-	protected function get_items_per_page( $option, $default_value = 20 ) {
831
-		$per_page = (int) get_user_option( $option );
832
-		if ( empty( $per_page ) || $per_page < 1 ) {
833
-			$per_page = $default_value;
834
-		}
835
-
836
-		/**
837
-		 * Filters the number of items to be displayed on each page of the list table.
838
-		 *
839
-		 * The dynamic hook name, `$option`, refers to the `per_page` option depending
840
-		 * on the type of list table in use. Possible filter names include:
841
-		 *
842
-		 *  - `edit_comments_per_page`
843
-		 *  - `sites_network_per_page`
844
-		 *  - `site_themes_network_per_page`
845
-		 *  - `themes_network_per_page'`
846
-		 *  - `users_network_per_page`
847
-		 *  - `edit_post_per_page`
848
-		 *  - `edit_page_per_page'`
849
-		 *  - `edit_{$post_type}_per_page`
850
-		 *  - `edit_post_tag_per_page`
851
-		 *  - `edit_category_per_page`
852
-		 *  - `edit_{$taxonomy}_per_page`
853
-		 *  - `site_users_network_per_page`
854
-		 *  - `users_per_page`
855
-		 *
856
-		 * @since 2.9.0
857
-		 *
858
-		 * @param int $per_page Number of items to be displayed. Default 20.
859
-		 */
860
-		return (int) apply_filters( "{$option}", $per_page );
861
-	}
862
-
863
-	/**
864
-	 * Displays the pagination.
865
-	 *
866
-	 * @since 3.1.0
867
-	 *
868
-	 * @param string $which
869
-	 */
870
-	protected function pagination( $which ) {
871
-		if ( empty( $this->_pagination_args ) ) {
872
-			return;
873
-		}
874
-
875
-		$total_items     = $this->_pagination_args['total_items'];
876
-		$total_pages     = $this->_pagination_args['total_pages'];
877
-		$infinite_scroll = false;
878
-		if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
879
-			$infinite_scroll = $this->_pagination_args['infinite_scroll'];
880
-		}
881
-
882
-		if ( 'top' === $which && $total_pages > 1 ) {
883
-			$this->screen->render_screen_reader_content( 'heading_pagination' );
884
-		}
885
-
886
-		$output = '<span class="displaying-num">' . sprintf(
887
-			/* translators: %s: Number of items. */
888
-			_n( '%s item', '%s items', $total_items ),
889
-			number_format_i18n( $total_items )
890
-		) . '</span>';
891
-
892
-		$current              = $this->get_pagenum();
893
-		$removable_query_args = wp_removable_query_args();
894
-
895
-		$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
896
-
897
-		$current_url = remove_query_arg( $removable_query_args, $current_url );
898
-
899
-		$page_links = array();
900
-
901
-		$total_pages_before = '<span class="paging-input">';
902
-		$total_pages_after  = '</span></span>';
903
-
904
-		$disable_first = false;
905
-		$disable_last  = false;
906
-		$disable_prev  = false;
907
-		$disable_next  = false;
908
-
909
-		if ( 1 == $current ) {
910
-			$disable_first = true;
911
-			$disable_prev  = true;
912
-		}
913
-		if ( $total_pages == $current ) {
914
-			$disable_last = true;
915
-			$disable_next = true;
916
-		}
917
-
918
-		if ( $disable_first ) {
919
-			$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
920
-		} else {
921
-			$page_links[] = sprintf(
922
-				"<a class='first-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
923
-				esc_url( remove_query_arg( 'paged', $current_url ) ),
924
-				__( 'First page' ),
925
-				'&laquo;'
926
-			);
927
-		}
928
-
929
-		if ( $disable_prev ) {
930
-			$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
931
-		} else {
932
-			$page_links[] = sprintf(
933
-				"<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
934
-				esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ),
935
-				__( 'Previous page' ),
936
-				'&lsaquo;'
937
-			);
938
-		}
939
-
940
-		if ( 'bottom' === $which ) {
941
-			$html_current_page  = $current;
942
-			$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
943
-		} else {
944
-			$html_current_page = sprintf(
945
-				"%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
946
-				'<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
947
-				$current,
948
-				strlen( $total_pages )
949
-			);
950
-		}
951
-		$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
952
-		$page_links[]     = $total_pages_before . sprintf(
953
-			/* translators: 1: Current page, 2: Total pages. */
954
-			_x( '%1$s of %2$s', 'paging' ),
955
-			$html_current_page,
956
-			$html_total_pages
957
-		) . $total_pages_after;
958
-
959
-		if ( $disable_next ) {
960
-			$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
961
-		} else {
962
-			$page_links[] = sprintf(
963
-				"<a class='next-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
964
-				esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ),
965
-				__( 'Next page' ),
966
-				'&rsaquo;'
967
-			);
968
-		}
969
-
970
-		if ( $disable_last ) {
971
-			$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
972
-		} else {
973
-			$page_links[] = sprintf(
974
-				"<a class='last-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
975
-				esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
976
-				__( 'Last page' ),
977
-				'&raquo;'
978
-			);
979
-		}
980
-
981
-		$pagination_links_class = 'pagination-links';
982
-		if ( ! empty( $infinite_scroll ) ) {
983
-			$pagination_links_class .= ' hide-if-js';
984
-		}
985
-		$output .= "\n<span class='$pagination_links_class'>" . implode( "\n", $page_links ) . '</span>';
986
-
987
-		if ( $total_pages ) {
988
-			$page_class = $total_pages < 2 ? ' one-page' : '';
989
-		} else {
990
-			$page_class = ' no-pages';
991
-		}
992
-		$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
993
-
994
-		echo $this->_pagination;
995
-	}
996
-
997
-	/**
998
-	 * Gets a list of columns.
999
-	 *
1000
-	 * The format is:
1001
-	 * - `'internal-name' => 'Title'`
1002
-	 *
1003
-	 * @since 3.1.0
1004
-	 * @abstract
1005
-	 *
1006
-	 * @return array
1007
-	 */
1008
-	public function get_columns() {
1009
-		die( 'function WP_List_Table::get_columns() must be overridden in a subclass.' );
1010
-	}
1011
-
1012
-	/**
1013
-	 * Gets a list of sortable columns.
1014
-	 *
1015
-	 * The format is:
1016
-	 * - `'internal-name' => 'orderby'`
1017
-	 * - `'internal-name' => array( 'orderby', 'asc' )` - The second element sets the initial sorting order.
1018
-	 * - `'internal-name' => array( 'orderby', true )`  - The second element makes the initial order descending.
1019
-	 *
1020
-	 * @since 3.1.0
1021
-	 *
1022
-	 * @return array
1023
-	 */
1024
-	protected function get_sortable_columns() {
1025
-		return array();
1026
-	}
1027
-
1028
-	/**
1029
-	 * Gets the name of the default primary column.
1030
-	 *
1031
-	 * @since 4.3.0
1032
-	 *
1033
-	 * @return string Name of the default primary column, in this case, an empty string.
1034
-	 */
1035
-	protected function get_default_primary_column_name() {
1036
-		$columns = $this->get_columns();
1037
-		$column  = '';
1038
-
1039
-		if ( empty( $columns ) ) {
1040
-			return $column;
1041
-		}
1042
-
1043
-		// We need a primary defined so responsive views show something,
1044
-		// so let's fall back to the first non-checkbox column.
1045
-		foreach ( $columns as $col => $column_name ) {
1046
-			if ( 'cb' === $col ) {
1047
-				continue;
1048
-			}
1049
-
1050
-			$column = $col;
1051
-			break;
1052
-		}
1053
-
1054
-		return $column;
1055
-	}
1056
-
1057
-	/**
1058
-	 * Public wrapper for WP_List_Table::get_default_primary_column_name().
1059
-	 *
1060
-	 * @since 4.4.0
1061
-	 *
1062
-	 * @return string Name of the default primary column.
1063
-	 */
1064
-	public function get_primary_column() {
1065
-		return $this->get_primary_column_name();
1066
-	}
1067
-
1068
-	/**
1069
-	 * Gets the name of the primary column.
1070
-	 *
1071
-	 * @since 4.3.0
1072
-	 *
1073
-	 * @return string The name of the primary column.
1074
-	 */
1075
-	protected function get_primary_column_name() {
1076
-		$columns = get_column_headers( $this->screen );
1077
-		$default = $this->get_default_primary_column_name();
1078
-
1079
-		// If the primary column doesn't exist,
1080
-		// fall back to the first non-checkbox column.
1081
-		if ( ! isset( $columns[ $default ] ) ) {
1082
-			$default = self::get_default_primary_column_name();
1083
-		}
1084
-
1085
-		/**
1086
-		 * Filters the name of the primary column for the current list table.
1087
-		 *
1088
-		 * @since 4.3.0
1089
-		 *
1090
-		 * @param string $default Column name default for the specific list table, e.g. 'name'.
1091
-		 * @param string $context Screen ID for specific list table, e.g. 'plugins'.
1092
-		 */
1093
-		$column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
1094
-
1095
-		if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
1096
-			$column = $default;
1097
-		}
1098
-
1099
-		return $column;
1100
-	}
1101
-
1102
-	/**
1103
-	 * Gets a list of all, hidden, and sortable columns, with filter applied.
1104
-	 *
1105
-	 * @since 3.1.0
1106
-	 *
1107
-	 * @return array
1108
-	 */
1109
-	protected function get_column_info() {
1110
-		// $_column_headers is already set / cached.
1111
-		if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
1112
-			/*
708
+    }
709
+
710
+    /**
711
+     * Displays a comment count bubble.
712
+     *
713
+     * @since 3.1.0
714
+     *
715
+     * @param int $post_id          The post ID.
716
+     * @param int $pending_comments Number of pending comments.
717
+     */
718
+    protected function comments_bubble( $post_id, $pending_comments ) {
719
+        $approved_comments = get_comments_number();
720
+
721
+        $approved_comments_number = number_format_i18n( $approved_comments );
722
+        $pending_comments_number  = number_format_i18n( $pending_comments );
723
+
724
+        $approved_only_phrase = sprintf(
725
+            /* translators: %s: Number of comments. */
726
+            _n( '%s comment', '%s comments', $approved_comments ),
727
+            $approved_comments_number
728
+        );
729
+
730
+        $approved_phrase = sprintf(
731
+            /* translators: %s: Number of comments. */
732
+            _n( '%s approved comment', '%s approved comments', $approved_comments ),
733
+            $approved_comments_number
734
+        );
735
+
736
+        $pending_phrase = sprintf(
737
+            /* translators: %s: Number of comments. */
738
+            _n( '%s pending comment', '%s pending comments', $pending_comments ),
739
+            $pending_comments_number
740
+        );
741
+
742
+        if ( ! $approved_comments && ! $pending_comments ) {
743
+            // No comments at all.
744
+            printf(
745
+                '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
746
+                __( 'No comments' )
747
+            );
748
+        } elseif ( $approved_comments && 'trash' === get_post_status( $post_id ) ) {
749
+            // Don't link the comment bubble for a trashed post.
750
+            printf(
751
+                '<span class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
752
+                $approved_comments_number,
753
+                $pending_comments ? $approved_phrase : $approved_only_phrase
754
+            );
755
+        } elseif ( $approved_comments ) {
756
+            // Link the comment bubble to approved comments.
757
+            printf(
758
+                '<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
759
+                esc_url(
760
+                    add_query_arg(
761
+                        array(
762
+                            'p'              => $post_id,
763
+                            'comment_status' => 'approved',
764
+                        ),
765
+                        admin_url( 'edit-comments.php' )
766
+                    )
767
+                ),
768
+                $approved_comments_number,
769
+                $pending_comments ? $approved_phrase : $approved_only_phrase
770
+            );
771
+        } else {
772
+            // Don't link the comment bubble when there are no approved comments.
773
+            printf(
774
+                '<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
775
+                $approved_comments_number,
776
+                $pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
777
+            );
778
+        }
779
+
780
+        if ( $pending_comments ) {
781
+            printf(
782
+                '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
783
+                esc_url(
784
+                    add_query_arg(
785
+                        array(
786
+                            'p'              => $post_id,
787
+                            'comment_status' => 'moderated',
788
+                        ),
789
+                        admin_url( 'edit-comments.php' )
790
+                    )
791
+                ),
792
+                $pending_comments_number,
793
+                $pending_phrase
794
+            );
795
+        } else {
796
+            printf(
797
+                '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
798
+                $pending_comments_number,
799
+                $approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
800
+            );
801
+        }
802
+    }
803
+
804
+    /**
805
+     * Gets the current page number.
806
+     *
807
+     * @since 3.1.0
808
+     *
809
+     * @return int
810
+     */
811
+    public function get_pagenum() {
812
+        $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
813
+
814
+        if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) {
815
+            $pagenum = $this->_pagination_args['total_pages'];
816
+        }
817
+
818
+        return max( 1, $pagenum );
819
+    }
820
+
821
+    /**
822
+     * Gets the number of items to display on a single page.
823
+     *
824
+     * @since 3.1.0
825
+     *
826
+     * @param string $option        User option name.
827
+     * @param int    $default_value Optional. The number of items to display. Default 20.
828
+     * @return int
829
+     */
830
+    protected function get_items_per_page( $option, $default_value = 20 ) {
831
+        $per_page = (int) get_user_option( $option );
832
+        if ( empty( $per_page ) || $per_page < 1 ) {
833
+            $per_page = $default_value;
834
+        }
835
+
836
+        /**
837
+         * Filters the number of items to be displayed on each page of the list table.
838
+         *
839
+         * The dynamic hook name, `$option`, refers to the `per_page` option depending
840
+         * on the type of list table in use. Possible filter names include:
841
+         *
842
+         *  - `edit_comments_per_page`
843
+         *  - `sites_network_per_page`
844
+         *  - `site_themes_network_per_page`
845
+         *  - `themes_network_per_page'`
846
+         *  - `users_network_per_page`
847
+         *  - `edit_post_per_page`
848
+         *  - `edit_page_per_page'`
849
+         *  - `edit_{$post_type}_per_page`
850
+         *  - `edit_post_tag_per_page`
851
+         *  - `edit_category_per_page`
852
+         *  - `edit_{$taxonomy}_per_page`
853
+         *  - `site_users_network_per_page`
854
+         *  - `users_per_page`
855
+         *
856
+         * @since 2.9.0
857
+         *
858
+         * @param int $per_page Number of items to be displayed. Default 20.
859
+         */
860
+        return (int) apply_filters( "{$option}", $per_page );
861
+    }
862
+
863
+    /**
864
+     * Displays the pagination.
865
+     *
866
+     * @since 3.1.0
867
+     *
868
+     * @param string $which
869
+     */
870
+    protected function pagination( $which ) {
871
+        if ( empty( $this->_pagination_args ) ) {
872
+            return;
873
+        }
874
+
875
+        $total_items     = $this->_pagination_args['total_items'];
876
+        $total_pages     = $this->_pagination_args['total_pages'];
877
+        $infinite_scroll = false;
878
+        if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
879
+            $infinite_scroll = $this->_pagination_args['infinite_scroll'];
880
+        }
881
+
882
+        if ( 'top' === $which && $total_pages > 1 ) {
883
+            $this->screen->render_screen_reader_content( 'heading_pagination' );
884
+        }
885
+
886
+        $output = '<span class="displaying-num">' . sprintf(
887
+            /* translators: %s: Number of items. */
888
+            _n( '%s item', '%s items', $total_items ),
889
+            number_format_i18n( $total_items )
890
+        ) . '</span>';
891
+
892
+        $current              = $this->get_pagenum();
893
+        $removable_query_args = wp_removable_query_args();
894
+
895
+        $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
896
+
897
+        $current_url = remove_query_arg( $removable_query_args, $current_url );
898
+
899
+        $page_links = array();
900
+
901
+        $total_pages_before = '<span class="paging-input">';
902
+        $total_pages_after  = '</span></span>';
903
+
904
+        $disable_first = false;
905
+        $disable_last  = false;
906
+        $disable_prev  = false;
907
+        $disable_next  = false;
908
+
909
+        if ( 1 == $current ) {
910
+            $disable_first = true;
911
+            $disable_prev  = true;
912
+        }
913
+        if ( $total_pages == $current ) {
914
+            $disable_last = true;
915
+            $disable_next = true;
916
+        }
917
+
918
+        if ( $disable_first ) {
919
+            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
920
+        } else {
921
+            $page_links[] = sprintf(
922
+                "<a class='first-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
923
+                esc_url( remove_query_arg( 'paged', $current_url ) ),
924
+                __( 'First page' ),
925
+                '&laquo;'
926
+            );
927
+        }
928
+
929
+        if ( $disable_prev ) {
930
+            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
931
+        } else {
932
+            $page_links[] = sprintf(
933
+                "<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
934
+                esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ),
935
+                __( 'Previous page' ),
936
+                '&lsaquo;'
937
+            );
938
+        }
939
+
940
+        if ( 'bottom' === $which ) {
941
+            $html_current_page  = $current;
942
+            $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
943
+        } else {
944
+            $html_current_page = sprintf(
945
+                "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
946
+                '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
947
+                $current,
948
+                strlen( $total_pages )
949
+            );
950
+        }
951
+        $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
952
+        $page_links[]     = $total_pages_before . sprintf(
953
+            /* translators: 1: Current page, 2: Total pages. */
954
+            _x( '%1$s of %2$s', 'paging' ),
955
+            $html_current_page,
956
+            $html_total_pages
957
+        ) . $total_pages_after;
958
+
959
+        if ( $disable_next ) {
960
+            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
961
+        } else {
962
+            $page_links[] = sprintf(
963
+                "<a class='next-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
964
+                esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ),
965
+                __( 'Next page' ),
966
+                '&rsaquo;'
967
+            );
968
+        }
969
+
970
+        if ( $disable_last ) {
971
+            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
972
+        } else {
973
+            $page_links[] = sprintf(
974
+                "<a class='last-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
975
+                esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
976
+                __( 'Last page' ),
977
+                '&raquo;'
978
+            );
979
+        }
980
+
981
+        $pagination_links_class = 'pagination-links';
982
+        if ( ! empty( $infinite_scroll ) ) {
983
+            $pagination_links_class .= ' hide-if-js';
984
+        }
985
+        $output .= "\n<span class='$pagination_links_class'>" . implode( "\n", $page_links ) . '</span>';
986
+
987
+        if ( $total_pages ) {
988
+            $page_class = $total_pages < 2 ? ' one-page' : '';
989
+        } else {
990
+            $page_class = ' no-pages';
991
+        }
992
+        $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
993
+
994
+        echo $this->_pagination;
995
+    }
996
+
997
+    /**
998
+     * Gets a list of columns.
999
+     *
1000
+     * The format is:
1001
+     * - `'internal-name' => 'Title'`
1002
+     *
1003
+     * @since 3.1.0
1004
+     * @abstract
1005
+     *
1006
+     * @return array
1007
+     */
1008
+    public function get_columns() {
1009
+        die( 'function WP_List_Table::get_columns() must be overridden in a subclass.' );
1010
+    }
1011
+
1012
+    /**
1013
+     * Gets a list of sortable columns.
1014
+     *
1015
+     * The format is:
1016
+     * - `'internal-name' => 'orderby'`
1017
+     * - `'internal-name' => array( 'orderby', 'asc' )` - The second element sets the initial sorting order.
1018
+     * - `'internal-name' => array( 'orderby', true )`  - The second element makes the initial order descending.
1019
+     *
1020
+     * @since 3.1.0
1021
+     *
1022
+     * @return array
1023
+     */
1024
+    protected function get_sortable_columns() {
1025
+        return array();
1026
+    }
1027
+
1028
+    /**
1029
+     * Gets the name of the default primary column.
1030
+     *
1031
+     * @since 4.3.0
1032
+     *
1033
+     * @return string Name of the default primary column, in this case, an empty string.
1034
+     */
1035
+    protected function get_default_primary_column_name() {
1036
+        $columns = $this->get_columns();
1037
+        $column  = '';
1038
+
1039
+        if ( empty( $columns ) ) {
1040
+            return $column;
1041
+        }
1042
+
1043
+        // We need a primary defined so responsive views show something,
1044
+        // so let's fall back to the first non-checkbox column.
1045
+        foreach ( $columns as $col => $column_name ) {
1046
+            if ( 'cb' === $col ) {
1047
+                continue;
1048
+            }
1049
+
1050
+            $column = $col;
1051
+            break;
1052
+        }
1053
+
1054
+        return $column;
1055
+    }
1056
+
1057
+    /**
1058
+     * Public wrapper for WP_List_Table::get_default_primary_column_name().
1059
+     *
1060
+     * @since 4.4.0
1061
+     *
1062
+     * @return string Name of the default primary column.
1063
+     */
1064
+    public function get_primary_column() {
1065
+        return $this->get_primary_column_name();
1066
+    }
1067
+
1068
+    /**
1069
+     * Gets the name of the primary column.
1070
+     *
1071
+     * @since 4.3.0
1072
+     *
1073
+     * @return string The name of the primary column.
1074
+     */
1075
+    protected function get_primary_column_name() {
1076
+        $columns = get_column_headers( $this->screen );
1077
+        $default = $this->get_default_primary_column_name();
1078
+
1079
+        // If the primary column doesn't exist,
1080
+        // fall back to the first non-checkbox column.
1081
+        if ( ! isset( $columns[ $default ] ) ) {
1082
+            $default = self::get_default_primary_column_name();
1083
+        }
1084
+
1085
+        /**
1086
+         * Filters the name of the primary column for the current list table.
1087
+         *
1088
+         * @since 4.3.0
1089
+         *
1090
+         * @param string $default Column name default for the specific list table, e.g. 'name'.
1091
+         * @param string $context Screen ID for specific list table, e.g. 'plugins'.
1092
+         */
1093
+        $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
1094
+
1095
+        if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
1096
+            $column = $default;
1097
+        }
1098
+
1099
+        return $column;
1100
+    }
1101
+
1102
+    /**
1103
+     * Gets a list of all, hidden, and sortable columns, with filter applied.
1104
+     *
1105
+     * @since 3.1.0
1106
+     *
1107
+     * @return array
1108
+     */
1109
+    protected function get_column_info() {
1110
+        // $_column_headers is already set / cached.
1111
+        if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
1112
+            /*
1113 1113
 			 * Backward compatibility for `$_column_headers` format prior to WordPress 4.3.
1114 1114
 			 *
1115 1115
 			 * In WordPress 4.3 the primary column name was added as a fourth item in the
1116 1116
 			 * column headers property. This ensures the primary column name is included
1117 1117
 			 * in plugins setting the property directly in the three item format.
1118 1118
 			 */
1119
-			$column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
1120
-			foreach ( $this->_column_headers as $key => $value ) {
1121
-				$column_headers[ $key ] = $value;
1122
-			}
1123
-
1124
-			return $column_headers;
1125
-		}
1126
-
1127
-		$columns = get_column_headers( $this->screen );
1128
-		$hidden  = get_hidden_columns( $this->screen );
1129
-
1130
-		$sortable_columns = $this->get_sortable_columns();
1131
-		/**
1132
-		 * Filters the list table sortable columns for a specific screen.
1133
-		 *
1134
-		 * The dynamic portion of the hook name, `$this->screen->id`, refers
1135
-		 * to the ID of the current screen.
1136
-		 *
1137
-		 * @since 3.1.0
1138
-		 *
1139
-		 * @param array $sortable_columns An array of sortable columns.
1140
-		 */
1141
-		$_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
1142
-
1143
-		$sortable = array();
1144
-		foreach ( $_sortable as $id => $data ) {
1145
-			if ( empty( $data ) ) {
1146
-				continue;
1147
-			}
1148
-
1149
-			$data = (array) $data;
1150
-			if ( ! isset( $data[1] ) ) {
1151
-				$data[1] = false;
1152
-			}
1153
-
1154
-			$sortable[ $id ] = $data;
1155
-		}
1156
-
1157
-		$primary               = $this->get_primary_column_name();
1158
-		$this->_column_headers = array( $columns, $hidden, $sortable, $primary );
1159
-
1160
-		return $this->_column_headers;
1161
-	}
1162
-
1163
-	/**
1164
-	 * Returns the number of visible columns.
1165
-	 *
1166
-	 * @since 3.1.0
1167
-	 *
1168
-	 * @return int
1169
-	 */
1170
-	public function get_column_count() {
1171
-		list ( $columns, $hidden ) = $this->get_column_info();
1172
-		$hidden                    = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
1173
-		return count( $columns ) - count( $hidden );
1174
-	}
1175
-
1176
-	/**
1177
-	 * Prints column headers, accounting for hidden and sortable columns.
1178
-	 *
1179
-	 * @since 3.1.0
1180
-	 *
1181
-	 * @param bool $with_id Whether to set the ID attribute or not
1182
-	 */
1183
-	public function print_column_headers( $with_id = true ) {
1184
-		list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1185
-
1186
-		$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1187
-		$current_url = remove_query_arg( 'paged', $current_url );
1188
-
1189
-		if ( isset( $_GET['orderby'] ) ) {
1190
-			$current_orderby = $_GET['orderby'];
1191
-		} else {
1192
-			$current_orderby = '';
1193
-		}
1194
-
1195
-		if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
1196
-			$current_order = 'desc';
1197
-		} else {
1198
-			$current_order = 'asc';
1199
-		}
1200
-
1201
-		if ( ! empty( $columns['cb'] ) ) {
1202
-			static $cb_counter = 1;
1203
-			$columns['cb']     = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
1204
-				. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
1205
-			$cb_counter++;
1206
-		}
1207
-
1208
-		foreach ( $columns as $column_key => $column_display_name ) {
1209
-			$class = array( 'manage-column', "column-$column_key" );
1210
-
1211
-			if ( in_array( $column_key, $hidden, true ) ) {
1212
-				$class[] = 'hidden';
1213
-			}
1214
-
1215
-			if ( 'cb' === $column_key ) {
1216
-				$class[] = 'check-column';
1217
-			} elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
1218
-				$class[] = 'num';
1219
-			}
1220
-
1221
-			if ( $column_key === $primary ) {
1222
-				$class[] = 'column-primary';
1223
-			}
1224
-
1225
-			if ( isset( $sortable[ $column_key ] ) ) {
1226
-				list( $orderby, $desc_first ) = $sortable[ $column_key ];
1227
-
1228
-				if ( $current_orderby === $orderby ) {
1229
-					$order = 'asc' === $current_order ? 'desc' : 'asc';
1230
-
1231
-					$class[] = 'sorted';
1232
-					$class[] = $current_order;
1233
-				} else {
1234
-					$order = strtolower( $desc_first );
1235
-
1236
-					if ( ! in_array( $order, array( 'desc', 'asc' ), true ) ) {
1237
-						$order = $desc_first ? 'desc' : 'asc';
1238
-					}
1239
-
1240
-					$class[] = 'sortable';
1241
-					$class[] = 'desc' === $order ? 'asc' : 'desc';
1242
-				}
1243
-
1244
-				$column_display_name = sprintf(
1245
-					'<a href="%s"><span>%s</span><span class="sorting-indicator"></span></a>',
1246
-					esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ),
1247
-					$column_display_name
1248
-				);
1249
-			}
1250
-
1251
-			$tag   = ( 'cb' === $column_key ) ? 'td' : 'th';
1252
-			$scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1253
-			$id    = $with_id ? "id='$column_key'" : '';
1254
-
1255
-			if ( ! empty( $class ) ) {
1256
-				$class = "class='" . implode( ' ', $class ) . "'";
1257
-			}
1258
-
1259
-			echo "<$tag $scope $id $class>$column_display_name</$tag>";
1260
-		}
1261
-	}
1262
-
1263
-	/**
1264
-	 * Displays the table.
1265
-	 *
1266
-	 * @since 3.1.0
1267
-	 */
1268
-	public function display() {
1269
-		$singular = $this->_args['singular'];
1270
-
1271
-		$this->display_tablenav( 'top' );
1272
-
1273
-		$this->screen->render_screen_reader_content( 'heading_list' );
1274
-		?>
1119
+            $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
1120
+            foreach ( $this->_column_headers as $key => $value ) {
1121
+                $column_headers[ $key ] = $value;
1122
+            }
1123
+
1124
+            return $column_headers;
1125
+        }
1126
+
1127
+        $columns = get_column_headers( $this->screen );
1128
+        $hidden  = get_hidden_columns( $this->screen );
1129
+
1130
+        $sortable_columns = $this->get_sortable_columns();
1131
+        /**
1132
+         * Filters the list table sortable columns for a specific screen.
1133
+         *
1134
+         * The dynamic portion of the hook name, `$this->screen->id`, refers
1135
+         * to the ID of the current screen.
1136
+         *
1137
+         * @since 3.1.0
1138
+         *
1139
+         * @param array $sortable_columns An array of sortable columns.
1140
+         */
1141
+        $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
1142
+
1143
+        $sortable = array();
1144
+        foreach ( $_sortable as $id => $data ) {
1145
+            if ( empty( $data ) ) {
1146
+                continue;
1147
+            }
1148
+
1149
+            $data = (array) $data;
1150
+            if ( ! isset( $data[1] ) ) {
1151
+                $data[1] = false;
1152
+            }
1153
+
1154
+            $sortable[ $id ] = $data;
1155
+        }
1156
+
1157
+        $primary               = $this->get_primary_column_name();
1158
+        $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
1159
+
1160
+        return $this->_column_headers;
1161
+    }
1162
+
1163
+    /**
1164
+     * Returns the number of visible columns.
1165
+     *
1166
+     * @since 3.1.0
1167
+     *
1168
+     * @return int
1169
+     */
1170
+    public function get_column_count() {
1171
+        list ( $columns, $hidden ) = $this->get_column_info();
1172
+        $hidden                    = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
1173
+        return count( $columns ) - count( $hidden );
1174
+    }
1175
+
1176
+    /**
1177
+     * Prints column headers, accounting for hidden and sortable columns.
1178
+     *
1179
+     * @since 3.1.0
1180
+     *
1181
+     * @param bool $with_id Whether to set the ID attribute or not
1182
+     */
1183
+    public function print_column_headers( $with_id = true ) {
1184
+        list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1185
+
1186
+        $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1187
+        $current_url = remove_query_arg( 'paged', $current_url );
1188
+
1189
+        if ( isset( $_GET['orderby'] ) ) {
1190
+            $current_orderby = $_GET['orderby'];
1191
+        } else {
1192
+            $current_orderby = '';
1193
+        }
1194
+
1195
+        if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
1196
+            $current_order = 'desc';
1197
+        } else {
1198
+            $current_order = 'asc';
1199
+        }
1200
+
1201
+        if ( ! empty( $columns['cb'] ) ) {
1202
+            static $cb_counter = 1;
1203
+            $columns['cb']     = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
1204
+                . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
1205
+            $cb_counter++;
1206
+        }
1207
+
1208
+        foreach ( $columns as $column_key => $column_display_name ) {
1209
+            $class = array( 'manage-column', "column-$column_key" );
1210
+
1211
+            if ( in_array( $column_key, $hidden, true ) ) {
1212
+                $class[] = 'hidden';
1213
+            }
1214
+
1215
+            if ( 'cb' === $column_key ) {
1216
+                $class[] = 'check-column';
1217
+            } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
1218
+                $class[] = 'num';
1219
+            }
1220
+
1221
+            if ( $column_key === $primary ) {
1222
+                $class[] = 'column-primary';
1223
+            }
1224
+
1225
+            if ( isset( $sortable[ $column_key ] ) ) {
1226
+                list( $orderby, $desc_first ) = $sortable[ $column_key ];
1227
+
1228
+                if ( $current_orderby === $orderby ) {
1229
+                    $order = 'asc' === $current_order ? 'desc' : 'asc';
1230
+
1231
+                    $class[] = 'sorted';
1232
+                    $class[] = $current_order;
1233
+                } else {
1234
+                    $order = strtolower( $desc_first );
1235
+
1236
+                    if ( ! in_array( $order, array( 'desc', 'asc' ), true ) ) {
1237
+                        $order = $desc_first ? 'desc' : 'asc';
1238
+                    }
1239
+
1240
+                    $class[] = 'sortable';
1241
+                    $class[] = 'desc' === $order ? 'asc' : 'desc';
1242
+                }
1243
+
1244
+                $column_display_name = sprintf(
1245
+                    '<a href="%s"><span>%s</span><span class="sorting-indicator"></span></a>',
1246
+                    esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ),
1247
+                    $column_display_name
1248
+                );
1249
+            }
1250
+
1251
+            $tag   = ( 'cb' === $column_key ) ? 'td' : 'th';
1252
+            $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1253
+            $id    = $with_id ? "id='$column_key'" : '';
1254
+
1255
+            if ( ! empty( $class ) ) {
1256
+                $class = "class='" . implode( ' ', $class ) . "'";
1257
+            }
1258
+
1259
+            echo "<$tag $scope $id $class>$column_display_name</$tag>";
1260
+        }
1261
+    }
1262
+
1263
+    /**
1264
+     * Displays the table.
1265
+     *
1266
+     * @since 3.1.0
1267
+     */
1268
+    public function display() {
1269
+        $singular = $this->_args['singular'];
1270
+
1271
+        $this->display_tablenav( 'top' );
1272
+
1273
+        $this->screen->render_screen_reader_content( 'heading_list' );
1274
+        ?>
1275 1275
 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
1276 1276
 	<thead>
1277 1277
 	<tr>
@@ -1281,10 +1281,10 @@  discard block
 block discarded – undo
1281 1281
 
1282 1282
 	<tbody id="the-list"
1283 1283
 		<?php
1284
-		if ( $singular ) {
1285
-			echo " data-wp-lists='list:$singular'";
1286
-		}
1287
-		?>
1284
+        if ( $singular ) {
1285
+            echo " data-wp-lists='list:$singular'";
1286
+        }
1287
+        ?>
1288 1288
 		>
1289 1289
 		<?php $this->display_rows_or_placeholder(); ?>
1290 1290
 	</tbody>
@@ -1297,35 +1297,35 @@  discard block
 block discarded – undo
1297 1297
 
1298 1298
 </table>
1299 1299
 		<?php
1300
-		$this->display_tablenav( 'bottom' );
1301
-	}
1302
-
1303
-	/**
1304
-	 * Gets a list of CSS classes for the WP_List_Table table tag.
1305
-	 *
1306
-	 * @since 3.1.0
1307
-	 *
1308
-	 * @return string[] Array of CSS classes for the table tag.
1309
-	 */
1310
-	protected function get_table_classes() {
1311
-		$mode = get_user_setting( 'posts_list_mode', 'list' );
1312
-
1313
-		$mode_class = esc_attr( 'table-view-' . $mode );
1314
-
1315
-		return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] );
1316
-	}
1317
-
1318
-	/**
1319
-	 * Generates the table navigation above or below the table
1320
-	 *
1321
-	 * @since 3.1.0
1322
-	 * @param string $which
1323
-	 */
1324
-	protected function display_tablenav( $which ) {
1325
-		if ( 'top' === $which ) {
1326
-			wp_nonce_field( 'bulk-' . $this->_args['plural'] );
1327
-		}
1328
-		?>
1300
+        $this->display_tablenav( 'bottom' );
1301
+    }
1302
+
1303
+    /**
1304
+     * Gets a list of CSS classes for the WP_List_Table table tag.
1305
+     *
1306
+     * @since 3.1.0
1307
+     *
1308
+     * @return string[] Array of CSS classes for the table tag.
1309
+     */
1310
+    protected function get_table_classes() {
1311
+        $mode = get_user_setting( 'posts_list_mode', 'list' );
1312
+
1313
+        $mode_class = esc_attr( 'table-view-' . $mode );
1314
+
1315
+        return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] );
1316
+    }
1317
+
1318
+    /**
1319
+     * Generates the table navigation above or below the table
1320
+     *
1321
+     * @since 3.1.0
1322
+     * @param string $which
1323
+     */
1324
+    protected function display_tablenav( $which ) {
1325
+        if ( 'top' === $which ) {
1326
+            wp_nonce_field( 'bulk-' . $this->_args['plural'] );
1327
+        }
1328
+        ?>
1329 1329
 	<div class="tablenav <?php echo esc_attr( $which ); ?>">
1330 1330
 
1331 1331
 		<?php if ( $this->has_items() ) : ?>
@@ -1333,190 +1333,190 @@  discard block
 block discarded – undo
1333 1333
 			<?php $this->bulk_actions( $which ); ?>
1334 1334
 		</div>
1335 1335
 			<?php
1336
-		endif;
1337
-		$this->extra_tablenav( $which );
1338
-		$this->pagination( $which );
1339
-		?>
1336
+        endif;
1337
+        $this->extra_tablenav( $which );
1338
+        $this->pagination( $which );
1339
+        ?>
1340 1340
 
1341 1341
 		<br class="clear" />
1342 1342
 	</div>
1343 1343
 		<?php
1344
-	}
1345
-
1346
-	/**
1347
-	 * Extra controls to be displayed between bulk actions and pagination.
1348
-	 *
1349
-	 * @since 3.1.0
1350
-	 *
1351
-	 * @param string $which
1352
-	 */
1353
-	protected function extra_tablenav( $which ) {}
1354
-
1355
-	/**
1356
-	 * Generates the tbody element for the list table.
1357
-	 *
1358
-	 * @since 3.1.0
1359
-	 */
1360
-	public function display_rows_or_placeholder() {
1361
-		if ( $this->has_items() ) {
1362
-			$this->display_rows();
1363
-		} else {
1364
-			echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
1365
-			$this->no_items();
1366
-			echo '</td></tr>';
1367
-		}
1368
-	}
1369
-
1370
-	/**
1371
-	 * Generates the table rows.
1372
-	 *
1373
-	 * @since 3.1.0
1374
-	 */
1375
-	public function display_rows() {
1376
-		foreach ( $this->items as $item ) {
1377
-			$this->single_row( $item );
1378
-		}
1379
-	}
1380
-
1381
-	/**
1382
-	 * Generates content for a single row of the table.
1383
-	 *
1384
-	 * @since 3.1.0
1385
-	 *
1386
-	 * @param object|array $item The current item
1387
-	 */
1388
-	public function single_row( $item ) {
1389
-		echo '<tr>';
1390
-		$this->single_row_columns( $item );
1391
-		echo '</tr>';
1392
-	}
1393
-
1394
-	/**
1395
-	 * @param object|array $item
1396
-	 * @param string $column_name
1397
-	 */
1398
-	protected function column_default( $item, $column_name ) {}
1399
-
1400
-	/**
1401
-	 * @param object|array $item
1402
-	 */
1403
-	protected function column_cb( $item ) {}
1404
-
1405
-	/**
1406
-	 * Generates the columns for a single row of the table.
1407
-	 *
1408
-	 * @since 3.1.0
1409
-	 *
1410
-	 * @param object|array $item The current item.
1411
-	 */
1412
-	protected function single_row_columns( $item ) {
1413
-		list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1414
-
1415
-		foreach ( $columns as $column_name => $column_display_name ) {
1416
-			$classes = "$column_name column-$column_name";
1417
-			if ( $primary === $column_name ) {
1418
-				$classes .= ' has-row-actions column-primary';
1419
-			}
1420
-
1421
-			if ( in_array( $column_name, $hidden, true ) ) {
1422
-				$classes .= ' hidden';
1423
-			}
1424
-
1425
-			// Comments column uses HTML in the display name with screen reader text.
1426
-			// Strip tags to get closer to a user-friendly string.
1427
-			$data = 'data-colname="' . esc_attr( wp_strip_all_tags( $column_display_name ) ) . '"';
1428
-
1429
-			$attributes = "class='$classes' $data";
1430
-
1431
-			if ( 'cb' === $column_name ) {
1432
-				echo '<th scope="row" class="check-column">';
1433
-				echo $this->column_cb( $item );
1434
-				echo '</th>';
1435
-			} elseif ( method_exists( $this, '_column_' . $column_name ) ) {
1436
-				echo call_user_func(
1437
-					array( $this, '_column_' . $column_name ),
1438
-					$item,
1439
-					$classes,
1440
-					$data,
1441
-					$primary
1442
-				);
1443
-			} elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1444
-				echo "<td $attributes>";
1445
-				echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1446
-				echo $this->handle_row_actions( $item, $column_name, $primary );
1447
-				echo '</td>';
1448
-			} else {
1449
-				echo "<td $attributes>";
1450
-				echo $this->column_default( $item, $column_name );
1451
-				echo $this->handle_row_actions( $item, $column_name, $primary );
1452
-				echo '</td>';
1453
-			}
1454
-		}
1455
-	}
1456
-
1457
-	/**
1458
-	 * Generates and display row actions links for the list table.
1459
-	 *
1460
-	 * @since 4.3.0
1461
-	 *
1462
-	 * @param object|array $item        The item being acted upon.
1463
-	 * @param string       $column_name Current column name.
1464
-	 * @param string       $primary     Primary column name.
1465
-	 * @return string The row actions HTML, or an empty string
1466
-	 *                if the current column is not the primary column.
1467
-	 */
1468
-	protected function handle_row_actions( $item, $column_name, $primary ) {
1469
-		return $column_name === $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : '';
1470
-	}
1471
-
1472
-	/**
1473
-	 * Handles an incoming ajax request (called from admin-ajax.php)
1474
-	 *
1475
-	 * @since 3.1.0
1476
-	 */
1477
-	public function ajax_response() {
1478
-		$this->prepare_items();
1479
-
1480
-		ob_start();
1481
-		if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1482
-			$this->display_rows();
1483
-		} else {
1484
-			$this->display_rows_or_placeholder();
1485
-		}
1486
-
1487
-		$rows = ob_get_clean();
1488
-
1489
-		$response = array( 'rows' => $rows );
1490
-
1491
-		if ( isset( $this->_pagination_args['total_items'] ) ) {
1492
-			$response['total_items_i18n'] = sprintf(
1493
-				/* translators: Number of items. */
1494
-				_n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
1495
-				number_format_i18n( $this->_pagination_args['total_items'] )
1496
-			);
1497
-		}
1498
-		if ( isset( $this->_pagination_args['total_pages'] ) ) {
1499
-			$response['total_pages']      = $this->_pagination_args['total_pages'];
1500
-			$response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1501
-		}
1502
-
1503
-		die( wp_json_encode( $response ) );
1504
-	}
1505
-
1506
-	/**
1507
-	 * Sends required variables to JavaScript land.
1508
-	 *
1509
-	 * @since 3.1.0
1510
-	 */
1511
-	public function _js_vars() {
1512
-		$args = array(
1513
-			'class'  => get_class( $this ),
1514
-			'screen' => array(
1515
-				'id'   => $this->screen->id,
1516
-				'base' => $this->screen->base,
1517
-			),
1518
-		);
1519
-
1520
-		printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
1521
-	}
1344
+    }
1345
+
1346
+    /**
1347
+     * Extra controls to be displayed between bulk actions and pagination.
1348
+     *
1349
+     * @since 3.1.0
1350
+     *
1351
+     * @param string $which
1352
+     */
1353
+    protected function extra_tablenav( $which ) {}
1354
+
1355
+    /**
1356
+     * Generates the tbody element for the list table.
1357
+     *
1358
+     * @since 3.1.0
1359
+     */
1360
+    public function display_rows_or_placeholder() {
1361
+        if ( $this->has_items() ) {
1362
+            $this->display_rows();
1363
+        } else {
1364
+            echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
1365
+            $this->no_items();
1366
+            echo '</td></tr>';
1367
+        }
1368
+    }
1369
+
1370
+    /**
1371
+     * Generates the table rows.
1372
+     *
1373
+     * @since 3.1.0
1374
+     */
1375
+    public function display_rows() {
1376
+        foreach ( $this->items as $item ) {
1377
+            $this->single_row( $item );
1378
+        }
1379
+    }
1380
+
1381
+    /**
1382
+     * Generates content for a single row of the table.
1383
+     *
1384
+     * @since 3.1.0
1385
+     *
1386
+     * @param object|array $item The current item
1387
+     */
1388
+    public function single_row( $item ) {
1389
+        echo '<tr>';
1390
+        $this->single_row_columns( $item );
1391
+        echo '</tr>';
1392
+    }
1393
+
1394
+    /**
1395
+     * @param object|array $item
1396
+     * @param string $column_name
1397
+     */
1398
+    protected function column_default( $item, $column_name ) {}
1399
+
1400
+    /**
1401
+     * @param object|array $item
1402
+     */
1403
+    protected function column_cb( $item ) {}
1404
+
1405
+    /**
1406
+     * Generates the columns for a single row of the table.
1407
+     *
1408
+     * @since 3.1.0
1409
+     *
1410
+     * @param object|array $item The current item.
1411
+     */
1412
+    protected function single_row_columns( $item ) {
1413
+        list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1414
+
1415
+        foreach ( $columns as $column_name => $column_display_name ) {
1416
+            $classes = "$column_name column-$column_name";
1417
+            if ( $primary === $column_name ) {
1418
+                $classes .= ' has-row-actions column-primary';
1419
+            }
1420
+
1421
+            if ( in_array( $column_name, $hidden, true ) ) {
1422
+                $classes .= ' hidden';
1423
+            }
1424
+
1425
+            // Comments column uses HTML in the display name with screen reader text.
1426
+            // Strip tags to get closer to a user-friendly string.
1427
+            $data = 'data-colname="' . esc_attr( wp_strip_all_tags( $column_display_name ) ) . '"';
1428
+
1429
+            $attributes = "class='$classes' $data";
1430
+
1431
+            if ( 'cb' === $column_name ) {
1432
+                echo '<th scope="row" class="check-column">';
1433
+                echo $this->column_cb( $item );
1434
+                echo '</th>';
1435
+            } elseif ( method_exists( $this, '_column_' . $column_name ) ) {
1436
+                echo call_user_func(
1437
+                    array( $this, '_column_' . $column_name ),
1438
+                    $item,
1439
+                    $classes,
1440
+                    $data,
1441
+                    $primary
1442
+                );
1443
+            } elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1444
+                echo "<td $attributes>";
1445
+                echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1446
+                echo $this->handle_row_actions( $item, $column_name, $primary );
1447
+                echo '</td>';
1448
+            } else {
1449
+                echo "<td $attributes>";
1450
+                echo $this->column_default( $item, $column_name );
1451
+                echo $this->handle_row_actions( $item, $column_name, $primary );
1452
+                echo '</td>';
1453
+            }
1454
+        }
1455
+    }
1456
+
1457
+    /**
1458
+     * Generates and display row actions links for the list table.
1459
+     *
1460
+     * @since 4.3.0
1461
+     *
1462
+     * @param object|array $item        The item being acted upon.
1463
+     * @param string       $column_name Current column name.
1464
+     * @param string       $primary     Primary column name.
1465
+     * @return string The row actions HTML, or an empty string
1466
+     *                if the current column is not the primary column.
1467
+     */
1468
+    protected function handle_row_actions( $item, $column_name, $primary ) {
1469
+        return $column_name === $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : '';
1470
+    }
1471
+
1472
+    /**
1473
+     * Handles an incoming ajax request (called from admin-ajax.php)
1474
+     *
1475
+     * @since 3.1.0
1476
+     */
1477
+    public function ajax_response() {
1478
+        $this->prepare_items();
1479
+
1480
+        ob_start();
1481
+        if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1482
+            $this->display_rows();
1483
+        } else {
1484
+            $this->display_rows_or_placeholder();
1485
+        }
1486
+
1487
+        $rows = ob_get_clean();
1488
+
1489
+        $response = array( 'rows' => $rows );
1490
+
1491
+        if ( isset( $this->_pagination_args['total_items'] ) ) {
1492
+            $response['total_items_i18n'] = sprintf(
1493
+                /* translators: Number of items. */
1494
+                _n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
1495
+                number_format_i18n( $this->_pagination_args['total_items'] )
1496
+            );
1497
+        }
1498
+        if ( isset( $this->_pagination_args['total_pages'] ) ) {
1499
+            $response['total_pages']      = $this->_pagination_args['total_pages'];
1500
+            $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1501
+        }
1502
+
1503
+        die( wp_json_encode( $response ) );
1504
+    }
1505
+
1506
+    /**
1507
+     * Sends required variables to JavaScript land.
1508
+     *
1509
+     * @since 3.1.0
1510
+     */
1511
+    public function _js_vars() {
1512
+        $args = array(
1513
+            'class'  => get_class( $this ),
1514
+            'screen' => array(
1515
+                'id'   => $this->screen->id,
1516
+                'base' => $this->screen->base,
1517
+            ),
1518
+        );
1519
+
1520
+        printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
1521
+    }
1522 1522
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/screen.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -15,29 +15,29 @@  discard block
 block discarded – undo
15 15
  * @return string[] The column header labels keyed by column ID.
16 16
  */
17 17
 function get_column_headers( $screen ) {
18
-	static $column_headers = array();
19
-
20
-	if ( is_string( $screen ) ) {
21
-		$screen = convert_to_screen( $screen );
22
-	}
23
-
24
-	if ( ! isset( $column_headers[ $screen->id ] ) ) {
25
-		/**
26
-		 * Filters the column headers for a list table on a specific screen.
27
-		 *
28
-		 * The dynamic portion of the hook name, `$screen->id`, refers to the
29
-		 * ID of a specific screen. For example, the screen ID for the Posts
30
-		 * list table is edit-post, so the filter for that screen would be
31
-		 * manage_edit-post_columns.
32
-		 *
33
-		 * @since 3.0.0
34
-		 *
35
-		 * @param string[] $columns The column header labels keyed by column ID.
36
-		 */
37
-		$column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
38
-	}
39
-
40
-	return $column_headers[ $screen->id ];
18
+    static $column_headers = array();
19
+
20
+    if ( is_string( $screen ) ) {
21
+        $screen = convert_to_screen( $screen );
22
+    }
23
+
24
+    if ( ! isset( $column_headers[ $screen->id ] ) ) {
25
+        /**
26
+         * Filters the column headers for a list table on a specific screen.
27
+         *
28
+         * The dynamic portion of the hook name, `$screen->id`, refers to the
29
+         * ID of a specific screen. For example, the screen ID for the Posts
30
+         * list table is edit-post, so the filter for that screen would be
31
+         * manage_edit-post_columns.
32
+         *
33
+         * @since 3.0.0
34
+         *
35
+         * @param string[] $columns The column header labels keyed by column ID.
36
+         */
37
+        $column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() );
38
+    }
39
+
40
+    return $column_headers[ $screen->id ];
41 41
 }
42 42
 
43 43
 /**
@@ -49,39 +49,39 @@  discard block
 block discarded – undo
49 49
  * @return string[] Array of IDs of hidden columns.
50 50
  */
51 51
 function get_hidden_columns( $screen ) {
52
-	if ( is_string( $screen ) ) {
53
-		$screen = convert_to_screen( $screen );
54
-	}
55
-
56
-	$hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' );
57
-
58
-	$use_defaults = ! is_array( $hidden );
59
-
60
-	if ( $use_defaults ) {
61
-		$hidden = array();
62
-
63
-		/**
64
-		 * Filters the default list of hidden columns.
65
-		 *
66
-		 * @since 4.4.0
67
-		 *
68
-		 * @param string[]  $hidden Array of IDs of columns hidden by default.
69
-		 * @param WP_Screen $screen WP_Screen object of the current screen.
70
-		 */
71
-		$hidden = apply_filters( 'default_hidden_columns', $hidden, $screen );
72
-	}
73
-
74
-	/**
75
-	 * Filters the list of hidden columns.
76
-	 *
77
-	 * @since 4.4.0
78
-	 * @since 4.4.1 Added the `use_defaults` parameter.
79
-	 *
80
-	 * @param string[]  $hidden       Array of IDs of hidden columns.
81
-	 * @param WP_Screen $screen       WP_Screen object of the current screen.
82
-	 * @param bool      $use_defaults Whether to show the default columns.
83
-	 */
84
-	return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults );
52
+    if ( is_string( $screen ) ) {
53
+        $screen = convert_to_screen( $screen );
54
+    }
55
+
56
+    $hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' );
57
+
58
+    $use_defaults = ! is_array( $hidden );
59
+
60
+    if ( $use_defaults ) {
61
+        $hidden = array();
62
+
63
+        /**
64
+         * Filters the default list of hidden columns.
65
+         *
66
+         * @since 4.4.0
67
+         *
68
+         * @param string[]  $hidden Array of IDs of columns hidden by default.
69
+         * @param WP_Screen $screen WP_Screen object of the current screen.
70
+         */
71
+        $hidden = apply_filters( 'default_hidden_columns', $hidden, $screen );
72
+    }
73
+
74
+    /**
75
+     * Filters the list of hidden columns.
76
+     *
77
+     * @since 4.4.0
78
+     * @since 4.4.1 Added the `use_defaults` parameter.
79
+     *
80
+     * @param string[]  $hidden       Array of IDs of hidden columns.
81
+     * @param WP_Screen $screen       WP_Screen object of the current screen.
82
+     * @param bool      $use_defaults Whether to show the default columns.
83
+     */
84
+    return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults );
85 85
 }
86 86
 
87 87
 /**
@@ -94,51 +94,51 @@  discard block
 block discarded – undo
94 94
  * @param WP_Screen $screen
95 95
  */
96 96
 function meta_box_prefs( $screen ) {
97
-	global $wp_meta_boxes;
98
-
99
-	if ( is_string( $screen ) ) {
100
-		$screen = convert_to_screen( $screen );
101
-	}
102
-
103
-	if ( empty( $wp_meta_boxes[ $screen->id ] ) ) {
104
-		return;
105
-	}
106
-
107
-	$hidden = get_hidden_meta_boxes( $screen );
108
-
109
-	foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) {
110
-		foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
111
-			if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) {
112
-				continue;
113
-			}
114
-
115
-			foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
116
-				if ( false === $box || ! $box['title'] ) {
117
-					continue;
118
-				}
119
-
120
-				// Submit box cannot be hidden.
121
-				if ( 'submitdiv' === $box['id'] || 'linksubmitdiv' === $box['id'] ) {
122
-					continue;
123
-				}
124
-
125
-				$widget_title = $box['title'];
126
-
127
-				if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
128
-					$widget_title = $box['args']['__widget_basename'];
129
-				}
130
-
131
-				$is_hidden = in_array( $box['id'], $hidden, true );
132
-
133
-				printf(
134
-					'<label for="%1$s-hide"><input class="hide-postbox-tog" name="%1$s-hide" type="checkbox" id="%1$s-hide" value="%1$s" %2$s />%3$s</label>',
135
-					esc_attr( $box['id'] ),
136
-					checked( $is_hidden, false, false ),
137
-					$widget_title
138
-				);
139
-			}
140
-		}
141
-	}
97
+    global $wp_meta_boxes;
98
+
99
+    if ( is_string( $screen ) ) {
100
+        $screen = convert_to_screen( $screen );
101
+    }
102
+
103
+    if ( empty( $wp_meta_boxes[ $screen->id ] ) ) {
104
+        return;
105
+    }
106
+
107
+    $hidden = get_hidden_meta_boxes( $screen );
108
+
109
+    foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) {
110
+        foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
111
+            if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) {
112
+                continue;
113
+            }
114
+
115
+            foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) {
116
+                if ( false === $box || ! $box['title'] ) {
117
+                    continue;
118
+                }
119
+
120
+                // Submit box cannot be hidden.
121
+                if ( 'submitdiv' === $box['id'] || 'linksubmitdiv' === $box['id'] ) {
122
+                    continue;
123
+                }
124
+
125
+                $widget_title = $box['title'];
126
+
127
+                if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
128
+                    $widget_title = $box['args']['__widget_basename'];
129
+                }
130
+
131
+                $is_hidden = in_array( $box['id'], $hidden, true );
132
+
133
+                printf(
134
+                    '<label for="%1$s-hide"><input class="hide-postbox-tog" name="%1$s-hide" type="checkbox" id="%1$s-hide" value="%1$s" %2$s />%3$s</label>',
135
+                    esc_attr( $box['id'] ),
136
+                    checked( $is_hidden, false, false ),
137
+                    $widget_title
138
+                );
139
+            }
140
+        }
141
+    }
142 142
 }
143 143
 
144 144
 /**
@@ -150,48 +150,48 @@  discard block
 block discarded – undo
150 150
  * @return string[] IDs of hidden meta boxes.
151 151
  */
152 152
 function get_hidden_meta_boxes( $screen ) {
153
-	if ( is_string( $screen ) ) {
154
-		$screen = convert_to_screen( $screen );
155
-	}
156
-
157
-	$hidden = get_user_option( "metaboxhidden_{$screen->id}" );
158
-
159
-	$use_defaults = ! is_array( $hidden );
160
-
161
-	// Hide slug boxes by default.
162
-	if ( $use_defaults ) {
163
-		$hidden = array();
164
-
165
-		if ( 'post' === $screen->base ) {
166
-			if ( in_array( $screen->post_type, array( 'post', 'page', 'attachment' ), true ) ) {
167
-				$hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' );
168
-			} else {
169
-				$hidden = array( 'slugdiv' );
170
-			}
171
-		}
172
-
173
-		/**
174
-		 * Filters the default list of hidden meta boxes.
175
-		 *
176
-		 * @since 3.1.0
177
-		 *
178
-		 * @param string[]  $hidden An array of IDs of meta boxes hidden by default.
179
-		 * @param WP_Screen $screen WP_Screen object of the current screen.
180
-		 */
181
-		$hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
182
-	}
183
-
184
-	/**
185
-	 * Filters the list of hidden meta boxes.
186
-	 *
187
-	 * @since 3.3.0
188
-	 *
189
-	 * @param string[]  $hidden       An array of IDs of hidden meta boxes.
190
-	 * @param WP_Screen $screen       WP_Screen object of the current screen.
191
-	 * @param bool      $use_defaults Whether to show the default meta boxes.
192
-	 *                                Default true.
193
-	 */
194
-	return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
153
+    if ( is_string( $screen ) ) {
154
+        $screen = convert_to_screen( $screen );
155
+    }
156
+
157
+    $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
158
+
159
+    $use_defaults = ! is_array( $hidden );
160
+
161
+    // Hide slug boxes by default.
162
+    if ( $use_defaults ) {
163
+        $hidden = array();
164
+
165
+        if ( 'post' === $screen->base ) {
166
+            if ( in_array( $screen->post_type, array( 'post', 'page', 'attachment' ), true ) ) {
167
+                $hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' );
168
+            } else {
169
+                $hidden = array( 'slugdiv' );
170
+            }
171
+        }
172
+
173
+        /**
174
+         * Filters the default list of hidden meta boxes.
175
+         *
176
+         * @since 3.1.0
177
+         *
178
+         * @param string[]  $hidden An array of IDs of meta boxes hidden by default.
179
+         * @param WP_Screen $screen WP_Screen object of the current screen.
180
+         */
181
+        $hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
182
+    }
183
+
184
+    /**
185
+     * Filters the list of hidden meta boxes.
186
+     *
187
+     * @since 3.3.0
188
+     *
189
+     * @param string[]  $hidden       An array of IDs of hidden meta boxes.
190
+     * @param WP_Screen $screen       WP_Screen object of the current screen.
191
+     * @param bool      $use_defaults Whether to show the default meta boxes.
192
+     *                                Default true.
193
+     */
194
+    return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
195 195
 }
196 196
 
197 197
 /**
@@ -203,13 +203,13 @@  discard block
 block discarded – undo
203 203
  * @param mixed  $args   Option-dependent arguments.
204 204
  */
205 205
 function add_screen_option( $option, $args = array() ) {
206
-	$current_screen = get_current_screen();
206
+    $current_screen = get_current_screen();
207 207
 
208
-	if ( ! $current_screen ) {
209
-		return;
210
-	}
208
+    if ( ! $current_screen ) {
209
+        return;
210
+    }
211 211
 
212
-	$current_screen->add_option( $option, $args );
212
+    $current_screen->add_option( $option, $args );
213 213
 }
214 214
 
215 215
 /**
@@ -222,13 +222,13 @@  discard block
 block discarded – undo
222 222
  * @return WP_Screen|null Current screen object or null when screen not defined.
223 223
  */
224 224
 function get_current_screen() {
225
-	global $current_screen;
225
+    global $current_screen;
226 226
 
227
-	if ( ! isset( $current_screen ) ) {
228
-		return null;
229
-	}
227
+    if ( ! isset( $current_screen ) ) {
228
+        return null;
229
+    }
230 230
 
231
-	return $current_screen;
231
+    return $current_screen;
232 232
 }
233 233
 
234 234
 /**
@@ -240,5 +240,5 @@  discard block
 block discarded – undo
240 240
  *                                    or an existing screen object.
241 241
  */
242 242
 function set_current_screen( $hook_name = '' ) {
243
-	WP_Screen::get( $hook_name )->set_current_screen();
243
+    WP_Screen::get( $hook_name )->set_current_screen();
244 244
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-wp-posts-list-table.php 1 patch
Indentation   +1665 added lines, -1665 removed lines patch added patch discarded remove patch
@@ -17,1598 +17,1598 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class WP_Posts_List_Table extends WP_List_Table {
19 19
 
20
-	/**
21
-	 * Whether the items should be displayed hierarchically or linearly.
22
-	 *
23
-	 * @since 3.1.0
24
-	 * @var bool
25
-	 */
26
-	protected $hierarchical_display;
27
-
28
-	/**
29
-	 * Holds the number of pending comments for each post.
30
-	 *
31
-	 * @since 3.1.0
32
-	 * @var array
33
-	 */
34
-	protected $comment_pending_count;
35
-
36
-	/**
37
-	 * Holds the number of posts for this user.
38
-	 *
39
-	 * @since 3.1.0
40
-	 * @var int
41
-	 */
42
-	private $user_posts_count;
43
-
44
-	/**
45
-	 * Holds the number of posts which are sticky.
46
-	 *
47
-	 * @since 3.1.0
48
-	 * @var int
49
-	 */
50
-	private $sticky_posts_count = 0;
51
-
52
-	private $is_trash;
53
-
54
-	/**
55
-	 * Current level for output.
56
-	 *
57
-	 * @since 4.3.0
58
-	 * @var int
59
-	 */
60
-	protected $current_level = 0;
61
-
62
-	/**
63
-	 * Constructor.
64
-	 *
65
-	 * @since 3.1.0
66
-	 *
67
-	 * @see WP_List_Table::__construct() for more information on default arguments.
68
-	 *
69
-	 * @global WP_Post_Type $post_type_object
70
-	 * @global wpdb         $wpdb             WordPress database abstraction object.
71
-	 *
72
-	 * @param array $args An associative array of arguments.
73
-	 */
74
-	public function __construct( $args = array() ) {
75
-		global $post_type_object, $wpdb;
76
-
77
-		parent::__construct(
78
-			array(
79
-				'plural' => 'posts',
80
-				'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
81
-			)
82
-		);
83
-
84
-		$post_type        = $this->screen->post_type;
85
-		$post_type_object = get_post_type_object( $post_type );
86
-
87
-		$exclude_states = get_post_stati(
88
-			array(
89
-				'show_in_admin_all_list' => false,
90
-			)
91
-		);
92
-
93
-		$this->user_posts_count = (int) $wpdb->get_var(
94
-			$wpdb->prepare(
95
-				"SELECT COUNT( 1 )
20
+    /**
21
+     * Whether the items should be displayed hierarchically or linearly.
22
+     *
23
+     * @since 3.1.0
24
+     * @var bool
25
+     */
26
+    protected $hierarchical_display;
27
+
28
+    /**
29
+     * Holds the number of pending comments for each post.
30
+     *
31
+     * @since 3.1.0
32
+     * @var array
33
+     */
34
+    protected $comment_pending_count;
35
+
36
+    /**
37
+     * Holds the number of posts for this user.
38
+     *
39
+     * @since 3.1.0
40
+     * @var int
41
+     */
42
+    private $user_posts_count;
43
+
44
+    /**
45
+     * Holds the number of posts which are sticky.
46
+     *
47
+     * @since 3.1.0
48
+     * @var int
49
+     */
50
+    private $sticky_posts_count = 0;
51
+
52
+    private $is_trash;
53
+
54
+    /**
55
+     * Current level for output.
56
+     *
57
+     * @since 4.3.0
58
+     * @var int
59
+     */
60
+    protected $current_level = 0;
61
+
62
+    /**
63
+     * Constructor.
64
+     *
65
+     * @since 3.1.0
66
+     *
67
+     * @see WP_List_Table::__construct() for more information on default arguments.
68
+     *
69
+     * @global WP_Post_Type $post_type_object
70
+     * @global wpdb         $wpdb             WordPress database abstraction object.
71
+     *
72
+     * @param array $args An associative array of arguments.
73
+     */
74
+    public function __construct( $args = array() ) {
75
+        global $post_type_object, $wpdb;
76
+
77
+        parent::__construct(
78
+            array(
79
+                'plural' => 'posts',
80
+                'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
81
+            )
82
+        );
83
+
84
+        $post_type        = $this->screen->post_type;
85
+        $post_type_object = get_post_type_object( $post_type );
86
+
87
+        $exclude_states = get_post_stati(
88
+            array(
89
+                'show_in_admin_all_list' => false,
90
+            )
91
+        );
92
+
93
+        $this->user_posts_count = (int) $wpdb->get_var(
94
+            $wpdb->prepare(
95
+                "SELECT COUNT( 1 )
96 96
 				FROM $wpdb->posts
97 97
 				WHERE post_type = %s
98 98
 				AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
99 99
 				AND post_author = %d",
100
-				$post_type,
101
-				get_current_user_id()
102
-			)
103
-		);
104
-
105
-		if ( $this->user_posts_count
106
-			&& ! current_user_can( $post_type_object->cap->edit_others_posts )
107
-			&& empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] )
108
-			&& empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] )
109
-		) {
110
-			$_GET['author'] = get_current_user_id();
111
-		}
112
-
113
-		$sticky_posts = get_option( 'sticky_posts' );
114
-
115
-		if ( 'post' === $post_type && $sticky_posts ) {
116
-			$sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
117
-
118
-			$this->sticky_posts_count = (int) $wpdb->get_var(
119
-				$wpdb->prepare(
120
-					"SELECT COUNT( 1 )
100
+                $post_type,
101
+                get_current_user_id()
102
+            )
103
+        );
104
+
105
+        if ( $this->user_posts_count
106
+            && ! current_user_can( $post_type_object->cap->edit_others_posts )
107
+            && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] )
108
+            && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] )
109
+        ) {
110
+            $_GET['author'] = get_current_user_id();
111
+        }
112
+
113
+        $sticky_posts = get_option( 'sticky_posts' );
114
+
115
+        if ( 'post' === $post_type && $sticky_posts ) {
116
+            $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
117
+
118
+            $this->sticky_posts_count = (int) $wpdb->get_var(
119
+                $wpdb->prepare(
120
+                    "SELECT COUNT( 1 )
121 121
 					FROM $wpdb->posts
122 122
 					WHERE post_type = %s
123 123
 					AND post_status NOT IN ('trash', 'auto-draft')
124 124
 					AND ID IN ($sticky_posts)",
125
-					$post_type
126
-				)
127
-			);
128
-		}
129
-	}
130
-
131
-	/**
132
-	 * Sets whether the table layout should be hierarchical or not.
133
-	 *
134
-	 * @since 4.2.0
135
-	 *
136
-	 * @param bool $display Whether the table layout should be hierarchical.
137
-	 */
138
-	public function set_hierarchical_display( $display ) {
139
-		$this->hierarchical_display = $display;
140
-	}
141
-
142
-	/**
143
-	 * @return bool
144
-	 */
145
-	public function ajax_user_can() {
146
-		return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
147
-	}
148
-
149
-	/**
150
-	 * @global string   $mode             List table view mode.
151
-	 * @global array    $avail_post_stati
152
-	 * @global WP_Query $wp_query         WordPress Query object.
153
-	 * @global int      $per_page
154
-	 */
155
-	public function prepare_items() {
156
-		global $mode, $avail_post_stati, $wp_query, $per_page;
157
-
158
-		if ( ! empty( $_REQUEST['mode'] ) ) {
159
-			$mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
160
-			set_user_setting( 'posts_list_mode', $mode );
161
-		} else {
162
-			$mode = get_user_setting( 'posts_list_mode', 'list' );
163
-		}
164
-
165
-		// Is going to call wp().
166
-		$avail_post_stati = wp_edit_posts_query();
167
-
168
-		$this->set_hierarchical_display(
169
-			is_post_type_hierarchical( $this->screen->post_type )
170
-			&& 'menu_order title' === $wp_query->query['orderby']
171
-		);
172
-
173
-		$post_type = $this->screen->post_type;
174
-		$per_page  = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
175
-
176
-		/** This filter is documented in wp-admin/includes/post.php */
177
-		$per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
178
-
179
-		if ( $this->hierarchical_display ) {
180
-			$total_items = $wp_query->post_count;
181
-		} elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) {
182
-			$total_items = $wp_query->found_posts;
183
-		} else {
184
-			$post_counts = (array) wp_count_posts( $post_type, 'readable' );
185
-
186
-			if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati, true ) ) {
187
-				$total_items = $post_counts[ $_REQUEST['post_status'] ];
188
-			} elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
189
-				$total_items = $this->sticky_posts_count;
190
-			} elseif ( isset( $_GET['author'] ) && get_current_user_id() === (int) $_GET['author'] ) {
191
-				$total_items = $this->user_posts_count;
192
-			} else {
193
-				$total_items = array_sum( $post_counts );
194
-
195
-				// Subtract post types that are not included in the admin all list.
196
-				foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
197
-					$total_items -= $post_counts[ $state ];
198
-				}
199
-			}
200
-		}
201
-
202
-		$this->is_trash = isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'];
203
-
204
-		$this->set_pagination_args(
205
-			array(
206
-				'total_items' => $total_items,
207
-				'per_page'    => $per_page,
208
-			)
209
-		);
210
-	}
211
-
212
-	/**
213
-	 * @return bool
214
-	 */
215
-	public function has_items() {
216
-		return have_posts();
217
-	}
218
-
219
-	/**
220
-	 */
221
-	public function no_items() {
222
-		if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) {
223
-			echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
224
-		} else {
225
-			echo get_post_type_object( $this->screen->post_type )->labels->not_found;
226
-		}
227
-	}
228
-
229
-	/**
230
-	 * Determine if the current view is the "All" view.
231
-	 *
232
-	 * @since 4.2.0
233
-	 *
234
-	 * @return bool Whether the current view is the "All" view.
235
-	 */
236
-	protected function is_base_request() {
237
-		$vars = $_GET;
238
-		unset( $vars['paged'] );
239
-
240
-		if ( empty( $vars ) ) {
241
-			return true;
242
-		} elseif ( 1 === count( $vars ) && ! empty( $vars['post_type'] ) ) {
243
-			return $this->screen->post_type === $vars['post_type'];
244
-		}
245
-
246
-		return 1 === count( $vars ) && ! empty( $vars['mode'] );
247
-	}
248
-
249
-	/**
250
-	 * Helper to create links to edit.php with params.
251
-	 *
252
-	 * @since 4.4.0
253
-	 *
254
-	 * @param string[] $args      Associative array of URL parameters for the link.
255
-	 * @param string   $link_text Link text.
256
-	 * @param string   $css_class Optional. Class attribute. Default empty string.
257
-	 * @return string The formatted link string.
258
-	 */
259
-	protected function get_edit_link( $args, $link_text, $css_class = '' ) {
260
-		$url = add_query_arg( $args, 'edit.php' );
261
-
262
-		$class_html   = '';
263
-		$aria_current = '';
264
-
265
-		if ( ! empty( $css_class ) ) {
266
-			$class_html = sprintf(
267
-				' class="%s"',
268
-				esc_attr( $css_class )
269
-			);
270
-
271
-			if ( 'current' === $css_class ) {
272
-				$aria_current = ' aria-current="page"';
273
-			}
274
-		}
275
-
276
-		return sprintf(
277
-			'<a href="%s"%s%s>%s</a>',
278
-			esc_url( $url ),
279
-			$class_html,
280
-			$aria_current,
281
-			$link_text
282
-		);
283
-	}
284
-
285
-	/**
286
-	 * @global array $locked_post_status This seems to be deprecated.
287
-	 * @global array $avail_post_stati
288
-	 * @return array
289
-	 */
290
-	protected function get_views() {
291
-		global $locked_post_status, $avail_post_stati;
292
-
293
-		$post_type = $this->screen->post_type;
294
-
295
-		if ( ! empty( $locked_post_status ) ) {
296
-			return array();
297
-		}
298
-
299
-		$status_links = array();
300
-		$num_posts    = wp_count_posts( $post_type, 'readable' );
301
-		$total_posts  = array_sum( (array) $num_posts );
302
-		$class        = '';
303
-
304
-		$current_user_id = get_current_user_id();
305
-		$all_args        = array( 'post_type' => $post_type );
306
-		$mine            = '';
307
-
308
-		// Subtract post types that are not included in the admin all list.
309
-		foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
310
-			$total_posts -= $num_posts->$state;
311
-		}
312
-
313
-		if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) {
314
-			if ( isset( $_GET['author'] ) && ( $current_user_id === (int) $_GET['author'] ) ) {
315
-				$class = 'current';
316
-			}
317
-
318
-			$mine_args = array(
319
-				'post_type' => $post_type,
320
-				'author'    => $current_user_id,
321
-			);
322
-
323
-			$mine_inner_html = sprintf(
324
-				/* translators: %s: Number of posts. */
325
-				_nx(
326
-					'Mine <span class="count">(%s)</span>',
327
-					'Mine <span class="count">(%s)</span>',
328
-					$this->user_posts_count,
329
-					'posts'
330
-				),
331
-				number_format_i18n( $this->user_posts_count )
332
-			);
333
-
334
-			$mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class );
335
-
336
-			$all_args['all_posts'] = 1;
337
-			$class                 = '';
338
-		}
339
-
340
-		if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) {
341
-			$class = 'current';
342
-		}
343
-
344
-		$all_inner_html = sprintf(
345
-			/* translators: %s: Number of posts. */
346
-			_nx(
347
-				'All <span class="count">(%s)</span>',
348
-				'All <span class="count">(%s)</span>',
349
-				$total_posts,
350
-				'posts'
351
-			),
352
-			number_format_i18n( $total_posts )
353
-		);
354
-
355
-		$status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
356
-
357
-		if ( $mine ) {
358
-			$status_links['mine'] = $mine;
359
-		}
360
-
361
-		foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) {
362
-			$class = '';
363
-
364
-			$status_name = $status->name;
365
-
366
-			if ( ! in_array( $status_name, $avail_post_stati, true ) || empty( $num_posts->$status_name ) ) {
367
-				continue;
368
-			}
369
-
370
-			if ( isset( $_REQUEST['post_status'] ) && $status_name === $_REQUEST['post_status'] ) {
371
-				$class = 'current';
372
-			}
373
-
374
-			$status_args = array(
375
-				'post_status' => $status_name,
376
-				'post_type'   => $post_type,
377
-			);
378
-
379
-			$status_label = sprintf(
380
-				translate_nooped_plural( $status->label_count, $num_posts->$status_name ),
381
-				number_format_i18n( $num_posts->$status_name )
382
-			);
383
-
384
-			$status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class );
385
-		}
386
-
387
-		if ( ! empty( $this->sticky_posts_count ) ) {
388
-			$class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : '';
389
-
390
-			$sticky_args = array(
391
-				'post_type'   => $post_type,
392
-				'show_sticky' => 1,
393
-			);
394
-
395
-			$sticky_inner_html = sprintf(
396
-				/* translators: %s: Number of posts. */
397
-				_nx(
398
-					'Sticky <span class="count">(%s)</span>',
399
-					'Sticky <span class="count">(%s)</span>',
400
-					$this->sticky_posts_count,
401
-					'posts'
402
-				),
403
-				number_format_i18n( $this->sticky_posts_count )
404
-			);
405
-
406
-			$sticky_link = array(
407
-				'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ),
408
-			);
409
-
410
-			// Sticky comes after Publish, or if not listed, after All.
411
-			$split        = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ), true );
412
-			$status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
413
-		}
414
-
415
-		return $status_links;
416
-	}
417
-
418
-	/**
419
-	 * @return array
420
-	 */
421
-	protected function get_bulk_actions() {
422
-		$actions       = array();
423
-		$post_type_obj = get_post_type_object( $this->screen->post_type );
424
-
425
-		if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
426
-			if ( $this->is_trash ) {
427
-				$actions['untrash'] = __( 'Restore' );
428
-			} else {
429
-				$actions['edit'] = __( 'Edit' );
430
-			}
431
-		}
432
-
433
-		if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
434
-			if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
435
-				$actions['delete'] = __( 'Delete permanently' );
436
-			} else {
437
-				$actions['trash'] = __( 'Move to Trash' );
438
-			}
439
-		}
440
-
441
-		return $actions;
442
-	}
443
-
444
-	/**
445
-	 * Displays a categories drop-down for filtering on the Posts list table.
446
-	 *
447
-	 * @since 4.6.0
448
-	 *
449
-	 * @global int $cat Currently selected category.
450
-	 *
451
-	 * @param string $post_type Post type slug.
452
-	 */
453
-	protected function categories_dropdown( $post_type ) {
454
-		global $cat;
455
-
456
-		/**
457
-		 * Filters whether to remove the 'Categories' drop-down from the post list table.
458
-		 *
459
-		 * @since 4.6.0
460
-		 *
461
-		 * @param bool   $disable   Whether to disable the categories drop-down. Default false.
462
-		 * @param string $post_type Post type slug.
463
-		 */
464
-		if ( false !== apply_filters( 'disable_categories_dropdown', false, $post_type ) ) {
465
-			return;
466
-		}
467
-
468
-		if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
469
-			$dropdown_options = array(
470
-				'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
471
-				'hide_empty'      => 0,
472
-				'hierarchical'    => 1,
473
-				'show_count'      => 0,
474
-				'orderby'         => 'name',
475
-				'selected'        => $cat,
476
-			);
477
-
478
-			echo '<label class="screen-reader-text" for="cat">' . get_taxonomy( 'category' )->labels->filter_by_item . '</label>';
479
-
480
-			wp_dropdown_categories( $dropdown_options );
481
-		}
482
-	}
483
-
484
-	/**
485
-	 * Displays a formats drop-down for filtering items.
486
-	 *
487
-	 * @since 5.2.0
488
-	 * @access protected
489
-	 *
490
-	 * @param string $post_type Post type slug.
491
-	 */
492
-	protected function formats_dropdown( $post_type ) {
493
-		/**
494
-		 * Filters whether to remove the 'Formats' drop-down from the post list table.
495
-		 *
496
-		 * @since 5.2.0
497
-		 * @since 5.5.0 The `$post_type` parameter was added.
498
-		 *
499
-		 * @param bool   $disable   Whether to disable the drop-down. Default false.
500
-		 * @param string $post_type Post type slug.
501
-		 */
502
-		if ( apply_filters( 'disable_formats_dropdown', false, $post_type ) ) {
503
-			return;
504
-		}
505
-
506
-		// Return if the post type doesn't have post formats or if we're in the Trash.
507
-		if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || $this->is_trash ) {
508
-			return;
509
-		}
510
-
511
-		// Make sure the dropdown shows only formats with a post count greater than 0.
512
-		$used_post_formats = get_terms(
513
-			array(
514
-				'taxonomy'   => 'post_format',
515
-				'hide_empty' => true,
516
-			)
517
-		);
518
-
519
-		// Return if there are no posts using formats.
520
-		if ( ! $used_post_formats ) {
521
-			return;
522
-		}
523
-
524
-		$displayed_post_format = isset( $_GET['post_format'] ) ? $_GET['post_format'] : '';
525
-		?>
125
+                    $post_type
126
+                )
127
+            );
128
+        }
129
+    }
130
+
131
+    /**
132
+     * Sets whether the table layout should be hierarchical or not.
133
+     *
134
+     * @since 4.2.0
135
+     *
136
+     * @param bool $display Whether the table layout should be hierarchical.
137
+     */
138
+    public function set_hierarchical_display( $display ) {
139
+        $this->hierarchical_display = $display;
140
+    }
141
+
142
+    /**
143
+     * @return bool
144
+     */
145
+    public function ajax_user_can() {
146
+        return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
147
+    }
148
+
149
+    /**
150
+     * @global string   $mode             List table view mode.
151
+     * @global array    $avail_post_stati
152
+     * @global WP_Query $wp_query         WordPress Query object.
153
+     * @global int      $per_page
154
+     */
155
+    public function prepare_items() {
156
+        global $mode, $avail_post_stati, $wp_query, $per_page;
157
+
158
+        if ( ! empty( $_REQUEST['mode'] ) ) {
159
+            $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
160
+            set_user_setting( 'posts_list_mode', $mode );
161
+        } else {
162
+            $mode = get_user_setting( 'posts_list_mode', 'list' );
163
+        }
164
+
165
+        // Is going to call wp().
166
+        $avail_post_stati = wp_edit_posts_query();
167
+
168
+        $this->set_hierarchical_display(
169
+            is_post_type_hierarchical( $this->screen->post_type )
170
+            && 'menu_order title' === $wp_query->query['orderby']
171
+        );
172
+
173
+        $post_type = $this->screen->post_type;
174
+        $per_page  = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
175
+
176
+        /** This filter is documented in wp-admin/includes/post.php */
177
+        $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
178
+
179
+        if ( $this->hierarchical_display ) {
180
+            $total_items = $wp_query->post_count;
181
+        } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) {
182
+            $total_items = $wp_query->found_posts;
183
+        } else {
184
+            $post_counts = (array) wp_count_posts( $post_type, 'readable' );
185
+
186
+            if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati, true ) ) {
187
+                $total_items = $post_counts[ $_REQUEST['post_status'] ];
188
+            } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
189
+                $total_items = $this->sticky_posts_count;
190
+            } elseif ( isset( $_GET['author'] ) && get_current_user_id() === (int) $_GET['author'] ) {
191
+                $total_items = $this->user_posts_count;
192
+            } else {
193
+                $total_items = array_sum( $post_counts );
194
+
195
+                // Subtract post types that are not included in the admin all list.
196
+                foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
197
+                    $total_items -= $post_counts[ $state ];
198
+                }
199
+            }
200
+        }
201
+
202
+        $this->is_trash = isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'];
203
+
204
+        $this->set_pagination_args(
205
+            array(
206
+                'total_items' => $total_items,
207
+                'per_page'    => $per_page,
208
+            )
209
+        );
210
+    }
211
+
212
+    /**
213
+     * @return bool
214
+     */
215
+    public function has_items() {
216
+        return have_posts();
217
+    }
218
+
219
+    /**
220
+     */
221
+    public function no_items() {
222
+        if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) {
223
+            echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
224
+        } else {
225
+            echo get_post_type_object( $this->screen->post_type )->labels->not_found;
226
+        }
227
+    }
228
+
229
+    /**
230
+     * Determine if the current view is the "All" view.
231
+     *
232
+     * @since 4.2.0
233
+     *
234
+     * @return bool Whether the current view is the "All" view.
235
+     */
236
+    protected function is_base_request() {
237
+        $vars = $_GET;
238
+        unset( $vars['paged'] );
239
+
240
+        if ( empty( $vars ) ) {
241
+            return true;
242
+        } elseif ( 1 === count( $vars ) && ! empty( $vars['post_type'] ) ) {
243
+            return $this->screen->post_type === $vars['post_type'];
244
+        }
245
+
246
+        return 1 === count( $vars ) && ! empty( $vars['mode'] );
247
+    }
248
+
249
+    /**
250
+     * Helper to create links to edit.php with params.
251
+     *
252
+     * @since 4.4.0
253
+     *
254
+     * @param string[] $args      Associative array of URL parameters for the link.
255
+     * @param string   $link_text Link text.
256
+     * @param string   $css_class Optional. Class attribute. Default empty string.
257
+     * @return string The formatted link string.
258
+     */
259
+    protected function get_edit_link( $args, $link_text, $css_class = '' ) {
260
+        $url = add_query_arg( $args, 'edit.php' );
261
+
262
+        $class_html   = '';
263
+        $aria_current = '';
264
+
265
+        if ( ! empty( $css_class ) ) {
266
+            $class_html = sprintf(
267
+                ' class="%s"',
268
+                esc_attr( $css_class )
269
+            );
270
+
271
+            if ( 'current' === $css_class ) {
272
+                $aria_current = ' aria-current="page"';
273
+            }
274
+        }
275
+
276
+        return sprintf(
277
+            '<a href="%s"%s%s>%s</a>',
278
+            esc_url( $url ),
279
+            $class_html,
280
+            $aria_current,
281
+            $link_text
282
+        );
283
+    }
284
+
285
+    /**
286
+     * @global array $locked_post_status This seems to be deprecated.
287
+     * @global array $avail_post_stati
288
+     * @return array
289
+     */
290
+    protected function get_views() {
291
+        global $locked_post_status, $avail_post_stati;
292
+
293
+        $post_type = $this->screen->post_type;
294
+
295
+        if ( ! empty( $locked_post_status ) ) {
296
+            return array();
297
+        }
298
+
299
+        $status_links = array();
300
+        $num_posts    = wp_count_posts( $post_type, 'readable' );
301
+        $total_posts  = array_sum( (array) $num_posts );
302
+        $class        = '';
303
+
304
+        $current_user_id = get_current_user_id();
305
+        $all_args        = array( 'post_type' => $post_type );
306
+        $mine            = '';
307
+
308
+        // Subtract post types that are not included in the admin all list.
309
+        foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
310
+            $total_posts -= $num_posts->$state;
311
+        }
312
+
313
+        if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) {
314
+            if ( isset( $_GET['author'] ) && ( $current_user_id === (int) $_GET['author'] ) ) {
315
+                $class = 'current';
316
+            }
317
+
318
+            $mine_args = array(
319
+                'post_type' => $post_type,
320
+                'author'    => $current_user_id,
321
+            );
322
+
323
+            $mine_inner_html = sprintf(
324
+                /* translators: %s: Number of posts. */
325
+                _nx(
326
+                    'Mine <span class="count">(%s)</span>',
327
+                    'Mine <span class="count">(%s)</span>',
328
+                    $this->user_posts_count,
329
+                    'posts'
330
+                ),
331
+                number_format_i18n( $this->user_posts_count )
332
+            );
333
+
334
+            $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class );
335
+
336
+            $all_args['all_posts'] = 1;
337
+            $class                 = '';
338
+        }
339
+
340
+        if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) {
341
+            $class = 'current';
342
+        }
343
+
344
+        $all_inner_html = sprintf(
345
+            /* translators: %s: Number of posts. */
346
+            _nx(
347
+                'All <span class="count">(%s)</span>',
348
+                'All <span class="count">(%s)</span>',
349
+                $total_posts,
350
+                'posts'
351
+            ),
352
+            number_format_i18n( $total_posts )
353
+        );
354
+
355
+        $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
356
+
357
+        if ( $mine ) {
358
+            $status_links['mine'] = $mine;
359
+        }
360
+
361
+        foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) {
362
+            $class = '';
363
+
364
+            $status_name = $status->name;
365
+
366
+            if ( ! in_array( $status_name, $avail_post_stati, true ) || empty( $num_posts->$status_name ) ) {
367
+                continue;
368
+            }
369
+
370
+            if ( isset( $_REQUEST['post_status'] ) && $status_name === $_REQUEST['post_status'] ) {
371
+                $class = 'current';
372
+            }
373
+
374
+            $status_args = array(
375
+                'post_status' => $status_name,
376
+                'post_type'   => $post_type,
377
+            );
378
+
379
+            $status_label = sprintf(
380
+                translate_nooped_plural( $status->label_count, $num_posts->$status_name ),
381
+                number_format_i18n( $num_posts->$status_name )
382
+            );
383
+
384
+            $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class );
385
+        }
386
+
387
+        if ( ! empty( $this->sticky_posts_count ) ) {
388
+            $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : '';
389
+
390
+            $sticky_args = array(
391
+                'post_type'   => $post_type,
392
+                'show_sticky' => 1,
393
+            );
394
+
395
+            $sticky_inner_html = sprintf(
396
+                /* translators: %s: Number of posts. */
397
+                _nx(
398
+                    'Sticky <span class="count">(%s)</span>',
399
+                    'Sticky <span class="count">(%s)</span>',
400
+                    $this->sticky_posts_count,
401
+                    'posts'
402
+                ),
403
+                number_format_i18n( $this->sticky_posts_count )
404
+            );
405
+
406
+            $sticky_link = array(
407
+                'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ),
408
+            );
409
+
410
+            // Sticky comes after Publish, or if not listed, after All.
411
+            $split        = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ), true );
412
+            $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
413
+        }
414
+
415
+        return $status_links;
416
+    }
417
+
418
+    /**
419
+     * @return array
420
+     */
421
+    protected function get_bulk_actions() {
422
+        $actions       = array();
423
+        $post_type_obj = get_post_type_object( $this->screen->post_type );
424
+
425
+        if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
426
+            if ( $this->is_trash ) {
427
+                $actions['untrash'] = __( 'Restore' );
428
+            } else {
429
+                $actions['edit'] = __( 'Edit' );
430
+            }
431
+        }
432
+
433
+        if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
434
+            if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
435
+                $actions['delete'] = __( 'Delete permanently' );
436
+            } else {
437
+                $actions['trash'] = __( 'Move to Trash' );
438
+            }
439
+        }
440
+
441
+        return $actions;
442
+    }
443
+
444
+    /**
445
+     * Displays a categories drop-down for filtering on the Posts list table.
446
+     *
447
+     * @since 4.6.0
448
+     *
449
+     * @global int $cat Currently selected category.
450
+     *
451
+     * @param string $post_type Post type slug.
452
+     */
453
+    protected function categories_dropdown( $post_type ) {
454
+        global $cat;
455
+
456
+        /**
457
+         * Filters whether to remove the 'Categories' drop-down from the post list table.
458
+         *
459
+         * @since 4.6.0
460
+         *
461
+         * @param bool   $disable   Whether to disable the categories drop-down. Default false.
462
+         * @param string $post_type Post type slug.
463
+         */
464
+        if ( false !== apply_filters( 'disable_categories_dropdown', false, $post_type ) ) {
465
+            return;
466
+        }
467
+
468
+        if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
469
+            $dropdown_options = array(
470
+                'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
471
+                'hide_empty'      => 0,
472
+                'hierarchical'    => 1,
473
+                'show_count'      => 0,
474
+                'orderby'         => 'name',
475
+                'selected'        => $cat,
476
+            );
477
+
478
+            echo '<label class="screen-reader-text" for="cat">' . get_taxonomy( 'category' )->labels->filter_by_item . '</label>';
479
+
480
+            wp_dropdown_categories( $dropdown_options );
481
+        }
482
+    }
483
+
484
+    /**
485
+     * Displays a formats drop-down for filtering items.
486
+     *
487
+     * @since 5.2.0
488
+     * @access protected
489
+     *
490
+     * @param string $post_type Post type slug.
491
+     */
492
+    protected function formats_dropdown( $post_type ) {
493
+        /**
494
+         * Filters whether to remove the 'Formats' drop-down from the post list table.
495
+         *
496
+         * @since 5.2.0
497
+         * @since 5.5.0 The `$post_type` parameter was added.
498
+         *
499
+         * @param bool   $disable   Whether to disable the drop-down. Default false.
500
+         * @param string $post_type Post type slug.
501
+         */
502
+        if ( apply_filters( 'disable_formats_dropdown', false, $post_type ) ) {
503
+            return;
504
+        }
505
+
506
+        // Return if the post type doesn't have post formats or if we're in the Trash.
507
+        if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || $this->is_trash ) {
508
+            return;
509
+        }
510
+
511
+        // Make sure the dropdown shows only formats with a post count greater than 0.
512
+        $used_post_formats = get_terms(
513
+            array(
514
+                'taxonomy'   => 'post_format',
515
+                'hide_empty' => true,
516
+            )
517
+        );
518
+
519
+        // Return if there are no posts using formats.
520
+        if ( ! $used_post_formats ) {
521
+            return;
522
+        }
523
+
524
+        $displayed_post_format = isset( $_GET['post_format'] ) ? $_GET['post_format'] : '';
525
+        ?>
526 526
 		<label for="filter-by-format" class="screen-reader-text"><?php _e( 'Filter by post format' ); ?></label>
527 527
 		<select name="post_format" id="filter-by-format">
528 528
 			<option<?php selected( $displayed_post_format, '' ); ?> value=""><?php _e( 'All formats' ); ?></option>
529 529
 			<?php
530
-			foreach ( $used_post_formats as $used_post_format ) {
531
-				// Post format slug.
532
-				$slug = str_replace( 'post-format-', '', $used_post_format->slug );
533
-				// Pretty, translated version of the post format slug.
534
-				$pretty_name = get_post_format_string( $slug );
535
-
536
-				// Skip the standard post format.
537
-				if ( 'standard' === $slug ) {
538
-					continue;
539
-				}
540
-				?>
530
+            foreach ( $used_post_formats as $used_post_format ) {
531
+                // Post format slug.
532
+                $slug = str_replace( 'post-format-', '', $used_post_format->slug );
533
+                // Pretty, translated version of the post format slug.
534
+                $pretty_name = get_post_format_string( $slug );
535
+
536
+                // Skip the standard post format.
537
+                if ( 'standard' === $slug ) {
538
+                    continue;
539
+                }
540
+                ?>
541 541
 				<option<?php selected( $displayed_post_format, $slug ); ?> value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $pretty_name ); ?></option>
542 542
 				<?php
543
-			}
544
-			?>
543
+            }
544
+            ?>
545 545
 		</select>
546 546
 		<?php
547
-	}
547
+    }
548 548
 
549
-	/**
550
-	 * @param string $which
551
-	 */
552
-	protected function extra_tablenav( $which ) {
553
-		?>
549
+    /**
550
+     * @param string $which
551
+     */
552
+    protected function extra_tablenav( $which ) {
553
+        ?>
554 554
 		<div class="alignleft actions">
555 555
 		<?php
556
-		if ( 'top' === $which ) {
557
-			ob_start();
558
-
559
-			$this->months_dropdown( $this->screen->post_type );
560
-			$this->categories_dropdown( $this->screen->post_type );
561
-			$this->formats_dropdown( $this->screen->post_type );
562
-
563
-			/**
564
-			 * Fires before the Filter button on the Posts and Pages list tables.
565
-			 *
566
-			 * The Filter button allows sorting by date and/or category on the
567
-			 * Posts list table, and sorting by date on the Pages list table.
568
-			 *
569
-			 * @since 2.1.0
570
-			 * @since 4.4.0 The `$post_type` parameter was added.
571
-			 * @since 4.6.0 The `$which` parameter was added.
572
-			 *
573
-			 * @param string $post_type The post type slug.
574
-			 * @param string $which     The location of the extra table nav markup:
575
-			 *                          'top' or 'bottom' for WP_Posts_List_Table,
576
-			 *                          'bar' for WP_Media_List_Table.
577
-			 */
578
-			do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
579
-
580
-			$output = ob_get_clean();
581
-
582
-			if ( ! empty( $output ) ) {
583
-				echo $output;
584
-				submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
585
-			}
586
-		}
587
-
588
-		if ( $this->is_trash && $this->has_items()
589
-			&& current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts )
590
-		) {
591
-			submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
592
-		}
593
-		?>
556
+        if ( 'top' === $which ) {
557
+            ob_start();
558
+
559
+            $this->months_dropdown( $this->screen->post_type );
560
+            $this->categories_dropdown( $this->screen->post_type );
561
+            $this->formats_dropdown( $this->screen->post_type );
562
+
563
+            /**
564
+             * Fires before the Filter button on the Posts and Pages list tables.
565
+             *
566
+             * The Filter button allows sorting by date and/or category on the
567
+             * Posts list table, and sorting by date on the Pages list table.
568
+             *
569
+             * @since 2.1.0
570
+             * @since 4.4.0 The `$post_type` parameter was added.
571
+             * @since 4.6.0 The `$which` parameter was added.
572
+             *
573
+             * @param string $post_type The post type slug.
574
+             * @param string $which     The location of the extra table nav markup:
575
+             *                          'top' or 'bottom' for WP_Posts_List_Table,
576
+             *                          'bar' for WP_Media_List_Table.
577
+             */
578
+            do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
579
+
580
+            $output = ob_get_clean();
581
+
582
+            if ( ! empty( $output ) ) {
583
+                echo $output;
584
+                submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
585
+            }
586
+        }
587
+
588
+        if ( $this->is_trash && $this->has_items()
589
+            && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts )
590
+        ) {
591
+            submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
592
+        }
593
+        ?>
594 594
 		</div>
595 595
 		<?php
596
-		/**
597
-		 * Fires immediately following the closing "actions" div in the tablenav for the posts
598
-		 * list table.
599
-		 *
600
-		 * @since 4.4.0
601
-		 *
602
-		 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
603
-		 */
604
-		do_action( 'manage_posts_extra_tablenav', $which );
605
-	}
606
-
607
-	/**
608
-	 * @return string
609
-	 */
610
-	public function current_action() {
611
-		if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
612
-			return 'delete_all';
613
-		}
614
-
615
-		return parent::current_action();
616
-	}
617
-
618
-	/**
619
-	 * @global string $mode List table view mode.
620
-	 *
621
-	 * @return array
622
-	 */
623
-	protected function get_table_classes() {
624
-		global $mode;
625
-
626
-		$mode_class = esc_attr( 'table-view-' . $mode );
627
-
628
-		return array(
629
-			'widefat',
630
-			'fixed',
631
-			'striped',
632
-			$mode_class,
633
-			is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts',
634
-		);
635
-	}
636
-
637
-	/**
638
-	 * @return array
639
-	 */
640
-	public function get_columns() {
641
-		$post_type = $this->screen->post_type;
642
-
643
-		$posts_columns = array();
644
-
645
-		$posts_columns['cb'] = '<input type="checkbox" />';
646
-
647
-		/* translators: Posts screen column name. */
648
-		$posts_columns['title'] = _x( 'Title', 'column name' );
649
-
650
-		if ( post_type_supports( $post_type, 'author' ) ) {
651
-			$posts_columns['author'] = __( 'Author' );
652
-		}
653
-
654
-		$taxonomies = get_object_taxonomies( $post_type, 'objects' );
655
-		$taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
656
-
657
-		/**
658
-		 * Filters the taxonomy columns in the Posts list table.
659
-		 *
660
-		 * The dynamic portion of the hook name, `$post_type`, refers to the post
661
-		 * type slug.
662
-		 *
663
-		 * Possible hook names include:
664
-		 *
665
-		 *  - `manage_taxonomies_for_post_columns`
666
-		 *  - `manage_taxonomies_for_page_columns`
667
-		 *
668
-		 * @since 3.5.0
669
-		 *
670
-		 * @param string[] $taxonomies Array of taxonomy names to show columns for.
671
-		 * @param string   $post_type  The post type.
672
-		 */
673
-		$taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
674
-		$taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
675
-
676
-		foreach ( $taxonomies as $taxonomy ) {
677
-			if ( 'category' === $taxonomy ) {
678
-				$column_key = 'categories';
679
-			} elseif ( 'post_tag' === $taxonomy ) {
680
-				$column_key = 'tags';
681
-			} else {
682
-				$column_key = 'taxonomy-' . $taxonomy;
683
-			}
684
-
685
-			$posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
686
-		}
687
-
688
-		$post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
689
-
690
-		if ( post_type_supports( $post_type, 'comments' )
691
-			&& ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true )
692
-		) {
693
-			$posts_columns['comments'] = sprintf(
694
-				'<span class="vers comment-grey-bubble" title="%1$s"><span class="screen-reader-text">%2$s</span></span>',
695
-				esc_attr__( 'Comments' ),
696
-				__( 'Comments' )
697
-			);
698
-		}
699
-
700
-		$posts_columns['date'] = __( 'Date' );
701
-
702
-		if ( 'page' === $post_type ) {
703
-
704
-			/**
705
-			 * Filters the columns displayed in the Pages list table.
706
-			 *
707
-			 * @since 2.5.0
708
-			 *
709
-			 * @param string[] $post_columns An associative array of column headings.
710
-			 */
711
-			$posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
712
-		} else {
713
-
714
-			/**
715
-			 * Filters the columns displayed in the Posts list table.
716
-			 *
717
-			 * @since 1.5.0
718
-			 *
719
-			 * @param string[] $post_columns An associative array of column headings.
720
-			 * @param string   $post_type    The post type slug.
721
-			 */
722
-			$posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
723
-		}
724
-
725
-		/**
726
-		 * Filters the columns displayed in the Posts list table for a specific post type.
727
-		 *
728
-		 * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
729
-		 *
730
-		 * Possible hook names include:
731
-		 *
732
-		 *  - `manage_post_posts_columns`
733
-		 *  - `manage_page_posts_columns`
734
-		 *
735
-		 * @since 3.0.0
736
-		 *
737
-		 * @param string[] $post_columns An associative array of column headings.
738
-		 */
739
-		return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
740
-	}
741
-
742
-	/**
743
-	 * @return array
744
-	 */
745
-	protected function get_sortable_columns() {
746
-		return array(
747
-			'title'    => 'title',
748
-			'parent'   => 'parent',
749
-			'comments' => 'comment_count',
750
-			'date'     => array( 'date', true ),
751
-		);
752
-	}
753
-
754
-	/**
755
-	 * @global WP_Query $wp_query WordPress Query object.
756
-	 * @global int $per_page
757
-	 * @param array $posts
758
-	 * @param int   $level
759
-	 */
760
-	public function display_rows( $posts = array(), $level = 0 ) {
761
-		global $wp_query, $per_page;
762
-
763
-		if ( empty( $posts ) ) {
764
-			$posts = $wp_query->posts;
765
-		}
766
-
767
-		add_filter( 'the_title', 'esc_html' );
768
-
769
-		if ( $this->hierarchical_display ) {
770
-			$this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
771
-		} else {
772
-			$this->_display_rows( $posts, $level );
773
-		}
774
-	}
775
-
776
-	/**
777
-	 * @param array $posts
778
-	 * @param int   $level
779
-	 */
780
-	private function _display_rows( $posts, $level = 0 ) {
781
-		$post_type = $this->screen->post_type;
782
-
783
-		// Create array of post IDs.
784
-		$post_ids = array();
785
-
786
-		foreach ( $posts as $a_post ) {
787
-			$post_ids[] = $a_post->ID;
788
-		}
789
-
790
-		if ( post_type_supports( $post_type, 'comments' ) ) {
791
-			$this->comment_pending_count = get_pending_comments_num( $post_ids );
792
-		}
793
-
794
-		foreach ( $posts as $post ) {
795
-			$this->single_row( $post, $level );
796
-		}
797
-	}
798
-
799
-	/**
800
-	 * @global wpdb    $wpdb WordPress database abstraction object.
801
-	 * @global WP_Post $post Global post object.
802
-	 * @param array $pages
803
-	 * @param int   $pagenum
804
-	 * @param int   $per_page
805
-	 */
806
-	private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
807
-		global $wpdb;
808
-
809
-		$level = 0;
810
-
811
-		if ( ! $pages ) {
812
-			$pages = get_pages( array( 'sort_column' => 'menu_order' ) );
813
-
814
-			if ( ! $pages ) {
815
-				return;
816
-			}
817
-		}
818
-
819
-		/*
596
+        /**
597
+         * Fires immediately following the closing "actions" div in the tablenav for the posts
598
+         * list table.
599
+         *
600
+         * @since 4.4.0
601
+         *
602
+         * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
603
+         */
604
+        do_action( 'manage_posts_extra_tablenav', $which );
605
+    }
606
+
607
+    /**
608
+     * @return string
609
+     */
610
+    public function current_action() {
611
+        if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
612
+            return 'delete_all';
613
+        }
614
+
615
+        return parent::current_action();
616
+    }
617
+
618
+    /**
619
+     * @global string $mode List table view mode.
620
+     *
621
+     * @return array
622
+     */
623
+    protected function get_table_classes() {
624
+        global $mode;
625
+
626
+        $mode_class = esc_attr( 'table-view-' . $mode );
627
+
628
+        return array(
629
+            'widefat',
630
+            'fixed',
631
+            'striped',
632
+            $mode_class,
633
+            is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts',
634
+        );
635
+    }
636
+
637
+    /**
638
+     * @return array
639
+     */
640
+    public function get_columns() {
641
+        $post_type = $this->screen->post_type;
642
+
643
+        $posts_columns = array();
644
+
645
+        $posts_columns['cb'] = '<input type="checkbox" />';
646
+
647
+        /* translators: Posts screen column name. */
648
+        $posts_columns['title'] = _x( 'Title', 'column name' );
649
+
650
+        if ( post_type_supports( $post_type, 'author' ) ) {
651
+            $posts_columns['author'] = __( 'Author' );
652
+        }
653
+
654
+        $taxonomies = get_object_taxonomies( $post_type, 'objects' );
655
+        $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
656
+
657
+        /**
658
+         * Filters the taxonomy columns in the Posts list table.
659
+         *
660
+         * The dynamic portion of the hook name, `$post_type`, refers to the post
661
+         * type slug.
662
+         *
663
+         * Possible hook names include:
664
+         *
665
+         *  - `manage_taxonomies_for_post_columns`
666
+         *  - `manage_taxonomies_for_page_columns`
667
+         *
668
+         * @since 3.5.0
669
+         *
670
+         * @param string[] $taxonomies Array of taxonomy names to show columns for.
671
+         * @param string   $post_type  The post type.
672
+         */
673
+        $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
674
+        $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
675
+
676
+        foreach ( $taxonomies as $taxonomy ) {
677
+            if ( 'category' === $taxonomy ) {
678
+                $column_key = 'categories';
679
+            } elseif ( 'post_tag' === $taxonomy ) {
680
+                $column_key = 'tags';
681
+            } else {
682
+                $column_key = 'taxonomy-' . $taxonomy;
683
+            }
684
+
685
+            $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
686
+        }
687
+
688
+        $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
689
+
690
+        if ( post_type_supports( $post_type, 'comments' )
691
+            && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true )
692
+        ) {
693
+            $posts_columns['comments'] = sprintf(
694
+                '<span class="vers comment-grey-bubble" title="%1$s"><span class="screen-reader-text">%2$s</span></span>',
695
+                esc_attr__( 'Comments' ),
696
+                __( 'Comments' )
697
+            );
698
+        }
699
+
700
+        $posts_columns['date'] = __( 'Date' );
701
+
702
+        if ( 'page' === $post_type ) {
703
+
704
+            /**
705
+             * Filters the columns displayed in the Pages list table.
706
+             *
707
+             * @since 2.5.0
708
+             *
709
+             * @param string[] $post_columns An associative array of column headings.
710
+             */
711
+            $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
712
+        } else {
713
+
714
+            /**
715
+             * Filters the columns displayed in the Posts list table.
716
+             *
717
+             * @since 1.5.0
718
+             *
719
+             * @param string[] $post_columns An associative array of column headings.
720
+             * @param string   $post_type    The post type slug.
721
+             */
722
+            $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
723
+        }
724
+
725
+        /**
726
+         * Filters the columns displayed in the Posts list table for a specific post type.
727
+         *
728
+         * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
729
+         *
730
+         * Possible hook names include:
731
+         *
732
+         *  - `manage_post_posts_columns`
733
+         *  - `manage_page_posts_columns`
734
+         *
735
+         * @since 3.0.0
736
+         *
737
+         * @param string[] $post_columns An associative array of column headings.
738
+         */
739
+        return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
740
+    }
741
+
742
+    /**
743
+     * @return array
744
+     */
745
+    protected function get_sortable_columns() {
746
+        return array(
747
+            'title'    => 'title',
748
+            'parent'   => 'parent',
749
+            'comments' => 'comment_count',
750
+            'date'     => array( 'date', true ),
751
+        );
752
+    }
753
+
754
+    /**
755
+     * @global WP_Query $wp_query WordPress Query object.
756
+     * @global int $per_page
757
+     * @param array $posts
758
+     * @param int   $level
759
+     */
760
+    public function display_rows( $posts = array(), $level = 0 ) {
761
+        global $wp_query, $per_page;
762
+
763
+        if ( empty( $posts ) ) {
764
+            $posts = $wp_query->posts;
765
+        }
766
+
767
+        add_filter( 'the_title', 'esc_html' );
768
+
769
+        if ( $this->hierarchical_display ) {
770
+            $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
771
+        } else {
772
+            $this->_display_rows( $posts, $level );
773
+        }
774
+    }
775
+
776
+    /**
777
+     * @param array $posts
778
+     * @param int   $level
779
+     */
780
+    private function _display_rows( $posts, $level = 0 ) {
781
+        $post_type = $this->screen->post_type;
782
+
783
+        // Create array of post IDs.
784
+        $post_ids = array();
785
+
786
+        foreach ( $posts as $a_post ) {
787
+            $post_ids[] = $a_post->ID;
788
+        }
789
+
790
+        if ( post_type_supports( $post_type, 'comments' ) ) {
791
+            $this->comment_pending_count = get_pending_comments_num( $post_ids );
792
+        }
793
+
794
+        foreach ( $posts as $post ) {
795
+            $this->single_row( $post, $level );
796
+        }
797
+    }
798
+
799
+    /**
800
+     * @global wpdb    $wpdb WordPress database abstraction object.
801
+     * @global WP_Post $post Global post object.
802
+     * @param array $pages
803
+     * @param int   $pagenum
804
+     * @param int   $per_page
805
+     */
806
+    private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
807
+        global $wpdb;
808
+
809
+        $level = 0;
810
+
811
+        if ( ! $pages ) {
812
+            $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
813
+
814
+            if ( ! $pages ) {
815
+                return;
816
+            }
817
+        }
818
+
819
+        /*
820 820
 		 * Arrange pages into two parts: top level pages and children_pages.
821 821
 		 * children_pages is two dimensional array. Example:
822 822
 		 * children_pages[10][] contains all sub-pages whose parent is 10.
823 823
 		 * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
824 824
 		 * If searching, ignore hierarchy and treat everything as top level
825 825
 		 */
826
-		if ( empty( $_REQUEST['s'] ) ) {
827
-			$top_level_pages = array();
828
-			$children_pages  = array();
829
-
830
-			foreach ( $pages as $page ) {
831
-				// Catch and repair bad pages.
832
-				if ( $page->post_parent === $page->ID ) {
833
-					$page->post_parent = 0;
834
-					$wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
835
-					clean_post_cache( $page );
836
-				}
837
-
838
-				if ( $page->post_parent > 0 ) {
839
-					$children_pages[ $page->post_parent ][] = $page;
840
-				} else {
841
-					$top_level_pages[] = $page;
842
-				}
843
-			}
844
-
845
-			$pages = &$top_level_pages;
846
-		}
847
-
848
-		$count      = 0;
849
-		$start      = ( $pagenum - 1 ) * $per_page;
850
-		$end        = $start + $per_page;
851
-		$to_display = array();
852
-
853
-		foreach ( $pages as $page ) {
854
-			if ( $count >= $end ) {
855
-				break;
856
-			}
857
-
858
-			if ( $count >= $start ) {
859
-				$to_display[ $page->ID ] = $level;
860
-			}
861
-
862
-			$count++;
863
-
864
-			if ( isset( $children_pages ) ) {
865
-				$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
866
-			}
867
-		}
868
-
869
-		// If it is the last pagenum and there are orphaned pages, display them with paging as well.
870
-		if ( isset( $children_pages ) && $count < $end ) {
871
-			foreach ( $children_pages as $orphans ) {
872
-				foreach ( $orphans as $op ) {
873
-					if ( $count >= $end ) {
874
-						break;
875
-					}
876
-
877
-					if ( $count >= $start ) {
878
-						$to_display[ $op->ID ] = 0;
879
-					}
880
-
881
-					$count++;
882
-				}
883
-			}
884
-		}
885
-
886
-		$ids = array_keys( $to_display );
887
-		_prime_post_caches( $ids );
888
-
889
-		if ( ! isset( $GLOBALS['post'] ) ) {
890
-			$GLOBALS['post'] = reset( $ids );
891
-		}
892
-
893
-		foreach ( $to_display as $page_id => $level ) {
894
-			echo "\t";
895
-			$this->single_row( $page_id, $level );
896
-		}
897
-	}
898
-
899
-	/**
900
-	 * Given a top level page ID, display the nested hierarchy of sub-pages
901
-	 * together with paging support
902
-	 *
903
-	 * @since 3.1.0 (Standalone function exists since 2.6.0)
904
-	 * @since 4.2.0 Added the `$to_display` parameter.
905
-	 *
906
-	 * @param array $children_pages
907
-	 * @param int   $count
908
-	 * @param int   $parent_page
909
-	 * @param int   $level
910
-	 * @param int   $pagenum
911
-	 * @param int   $per_page
912
-	 * @param array $to_display List of pages to be displayed. Passed by reference.
913
-	 */
914
-	private function _page_rows( &$children_pages, &$count, $parent_page, $level, $pagenum, $per_page, &$to_display ) {
915
-		if ( ! isset( $children_pages[ $parent_page ] ) ) {
916
-			return;
917
-		}
918
-
919
-		$start = ( $pagenum - 1 ) * $per_page;
920
-		$end   = $start + $per_page;
921
-
922
-		foreach ( $children_pages[ $parent_page ] as $page ) {
923
-			if ( $count >= $end ) {
924
-				break;
925
-			}
926
-
927
-			// If the page starts in a subtree, print the parents.
928
-			if ( $count === $start && $page->post_parent > 0 ) {
929
-				$my_parents = array();
930
-				$my_parent  = $page->post_parent;
931
-
932
-				while ( $my_parent ) {
933
-					// Get the ID from the list or the attribute if my_parent is an object.
934
-					$parent_id = $my_parent;
935
-
936
-					if ( is_object( $my_parent ) ) {
937
-						$parent_id = $my_parent->ID;
938
-					}
939
-
940
-					$my_parent    = get_post( $parent_id );
941
-					$my_parents[] = $my_parent;
942
-
943
-					if ( ! $my_parent->post_parent ) {
944
-						break;
945
-					}
946
-
947
-					$my_parent = $my_parent->post_parent;
948
-				}
949
-
950
-				$num_parents = count( $my_parents );
951
-
952
-				while ( $my_parent = array_pop( $my_parents ) ) {
953
-					$to_display[ $my_parent->ID ] = $level - $num_parents;
954
-					$num_parents--;
955
-				}
956
-			}
957
-
958
-			if ( $count >= $start ) {
959
-				$to_display[ $page->ID ] = $level;
960
-			}
961
-
962
-			$count++;
963
-
964
-			$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
965
-		}
966
-
967
-		unset( $children_pages[ $parent_page ] ); // Required in order to keep track of orphans.
968
-	}
969
-
970
-	/**
971
-	 * Handles the checkbox column output.
972
-	 *
973
-	 * @since 4.3.0
974
-	 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
975
-	 *
976
-	 * @param WP_Post $item The current WP_Post object.
977
-	 */
978
-	public function column_cb( $item ) {
979
-		// Restores the more descriptive, specific name for use within this method.
980
-		$post = $item;
981
-		$show = current_user_can( 'edit_post', $post->ID );
982
-
983
-		/**
984
-		 * Filters whether to show the bulk edit checkbox for a post in its list table.
985
-		 *
986
-		 * By default the checkbox is only shown if the current user can edit the post.
987
-		 *
988
-		 * @since 5.7.0
989
-		 *
990
-		 * @param bool    $show Whether to show the checkbox.
991
-		 * @param WP_Post $post The current WP_Post object.
992
-		 */
993
-		if ( apply_filters( 'wp_list_table_show_post_checkbox', $show, $post ) ) :
994
-			?>
826
+        if ( empty( $_REQUEST['s'] ) ) {
827
+            $top_level_pages = array();
828
+            $children_pages  = array();
829
+
830
+            foreach ( $pages as $page ) {
831
+                // Catch and repair bad pages.
832
+                if ( $page->post_parent === $page->ID ) {
833
+                    $page->post_parent = 0;
834
+                    $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
835
+                    clean_post_cache( $page );
836
+                }
837
+
838
+                if ( $page->post_parent > 0 ) {
839
+                    $children_pages[ $page->post_parent ][] = $page;
840
+                } else {
841
+                    $top_level_pages[] = $page;
842
+                }
843
+            }
844
+
845
+            $pages = &$top_level_pages;
846
+        }
847
+
848
+        $count      = 0;
849
+        $start      = ( $pagenum - 1 ) * $per_page;
850
+        $end        = $start + $per_page;
851
+        $to_display = array();
852
+
853
+        foreach ( $pages as $page ) {
854
+            if ( $count >= $end ) {
855
+                break;
856
+            }
857
+
858
+            if ( $count >= $start ) {
859
+                $to_display[ $page->ID ] = $level;
860
+            }
861
+
862
+            $count++;
863
+
864
+            if ( isset( $children_pages ) ) {
865
+                $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
866
+            }
867
+        }
868
+
869
+        // If it is the last pagenum and there are orphaned pages, display them with paging as well.
870
+        if ( isset( $children_pages ) && $count < $end ) {
871
+            foreach ( $children_pages as $orphans ) {
872
+                foreach ( $orphans as $op ) {
873
+                    if ( $count >= $end ) {
874
+                        break;
875
+                    }
876
+
877
+                    if ( $count >= $start ) {
878
+                        $to_display[ $op->ID ] = 0;
879
+                    }
880
+
881
+                    $count++;
882
+                }
883
+            }
884
+        }
885
+
886
+        $ids = array_keys( $to_display );
887
+        _prime_post_caches( $ids );
888
+
889
+        if ( ! isset( $GLOBALS['post'] ) ) {
890
+            $GLOBALS['post'] = reset( $ids );
891
+        }
892
+
893
+        foreach ( $to_display as $page_id => $level ) {
894
+            echo "\t";
895
+            $this->single_row( $page_id, $level );
896
+        }
897
+    }
898
+
899
+    /**
900
+     * Given a top level page ID, display the nested hierarchy of sub-pages
901
+     * together with paging support
902
+     *
903
+     * @since 3.1.0 (Standalone function exists since 2.6.0)
904
+     * @since 4.2.0 Added the `$to_display` parameter.
905
+     *
906
+     * @param array $children_pages
907
+     * @param int   $count
908
+     * @param int   $parent_page
909
+     * @param int   $level
910
+     * @param int   $pagenum
911
+     * @param int   $per_page
912
+     * @param array $to_display List of pages to be displayed. Passed by reference.
913
+     */
914
+    private function _page_rows( &$children_pages, &$count, $parent_page, $level, $pagenum, $per_page, &$to_display ) {
915
+        if ( ! isset( $children_pages[ $parent_page ] ) ) {
916
+            return;
917
+        }
918
+
919
+        $start = ( $pagenum - 1 ) * $per_page;
920
+        $end   = $start + $per_page;
921
+
922
+        foreach ( $children_pages[ $parent_page ] as $page ) {
923
+            if ( $count >= $end ) {
924
+                break;
925
+            }
926
+
927
+            // If the page starts in a subtree, print the parents.
928
+            if ( $count === $start && $page->post_parent > 0 ) {
929
+                $my_parents = array();
930
+                $my_parent  = $page->post_parent;
931
+
932
+                while ( $my_parent ) {
933
+                    // Get the ID from the list or the attribute if my_parent is an object.
934
+                    $parent_id = $my_parent;
935
+
936
+                    if ( is_object( $my_parent ) ) {
937
+                        $parent_id = $my_parent->ID;
938
+                    }
939
+
940
+                    $my_parent    = get_post( $parent_id );
941
+                    $my_parents[] = $my_parent;
942
+
943
+                    if ( ! $my_parent->post_parent ) {
944
+                        break;
945
+                    }
946
+
947
+                    $my_parent = $my_parent->post_parent;
948
+                }
949
+
950
+                $num_parents = count( $my_parents );
951
+
952
+                while ( $my_parent = array_pop( $my_parents ) ) {
953
+                    $to_display[ $my_parent->ID ] = $level - $num_parents;
954
+                    $num_parents--;
955
+                }
956
+            }
957
+
958
+            if ( $count >= $start ) {
959
+                $to_display[ $page->ID ] = $level;
960
+            }
961
+
962
+            $count++;
963
+
964
+            $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
965
+        }
966
+
967
+        unset( $children_pages[ $parent_page ] ); // Required in order to keep track of orphans.
968
+    }
969
+
970
+    /**
971
+     * Handles the checkbox column output.
972
+     *
973
+     * @since 4.3.0
974
+     * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
975
+     *
976
+     * @param WP_Post $item The current WP_Post object.
977
+     */
978
+    public function column_cb( $item ) {
979
+        // Restores the more descriptive, specific name for use within this method.
980
+        $post = $item;
981
+        $show = current_user_can( 'edit_post', $post->ID );
982
+
983
+        /**
984
+         * Filters whether to show the bulk edit checkbox for a post in its list table.
985
+         *
986
+         * By default the checkbox is only shown if the current user can edit the post.
987
+         *
988
+         * @since 5.7.0
989
+         *
990
+         * @param bool    $show Whether to show the checkbox.
991
+         * @param WP_Post $post The current WP_Post object.
992
+         */
993
+        if ( apply_filters( 'wp_list_table_show_post_checkbox', $show, $post ) ) :
994
+            ?>
995 995
 			<label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>">
996 996
 				<?php
997
-					/* translators: %s: Post title. */
998
-					printf( __( 'Select %s' ), _draft_or_post_title() );
999
-				?>
997
+                    /* translators: %s: Post title. */
998
+                    printf( __( 'Select %s' ), _draft_or_post_title() );
999
+                ?>
1000 1000
 			</label>
1001 1001
 			<input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
1002 1002
 			<div class="locked-indicator">
1003 1003
 				<span class="locked-indicator-icon" aria-hidden="true"></span>
1004 1004
 				<span class="screen-reader-text">
1005 1005
 				<?php
1006
-				printf(
1007
-					/* translators: %s: Post title. */
1008
-					__( '&#8220;%s&#8221; is locked' ),
1009
-					_draft_or_post_title()
1010
-				);
1011
-				?>
1006
+                printf(
1007
+                    /* translators: %s: Post title. */
1008
+                    __( '&#8220;%s&#8221; is locked' ),
1009
+                    _draft_or_post_title()
1010
+                );
1011
+                ?>
1012 1012
 				</span>
1013 1013
 			</div>
1014 1014
 			<?php
1015
-		endif;
1016
-	}
1017
-
1018
-	/**
1019
-	 * @since 4.3.0
1020
-	 *
1021
-	 * @param WP_Post $post
1022
-	 * @param string  $classes
1023
-	 * @param string  $data
1024
-	 * @param string  $primary
1025
-	 */
1026
-	protected function _column_title( $post, $classes, $data, $primary ) {
1027
-		echo '<td class="' . $classes . ' page-title" ', $data, '>';
1028
-		echo $this->column_title( $post );
1029
-		echo $this->handle_row_actions( $post, 'title', $primary );
1030
-		echo '</td>';
1031
-	}
1032
-
1033
-	/**
1034
-	 * Handles the title column output.
1035
-	 *
1036
-	 * @since 4.3.0
1037
-	 *
1038
-	 * @global string $mode List table view mode.
1039
-	 *
1040
-	 * @param WP_Post $post The current WP_Post object.
1041
-	 */
1042
-	public function column_title( $post ) {
1043
-		global $mode;
1044
-
1045
-		if ( $this->hierarchical_display ) {
1046
-			if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
1047
-				// Sent level 0 by accident, by default, or because we don't know the actual level.
1048
-				$find_main_page = (int) $post->post_parent;
1049
-
1050
-				while ( $find_main_page > 0 ) {
1051
-					$parent = get_post( $find_main_page );
1052
-
1053
-					if ( is_null( $parent ) ) {
1054
-						break;
1055
-					}
1056
-
1057
-					$this->current_level++;
1058
-					$find_main_page = (int) $parent->post_parent;
1059
-
1060
-					if ( ! isset( $parent_name ) ) {
1061
-						/** This filter is documented in wp-includes/post-template.php */
1062
-						$parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
1063
-					}
1064
-				}
1065
-			}
1066
-		}
1067
-
1068
-		$can_edit_post = current_user_can( 'edit_post', $post->ID );
1069
-
1070
-		if ( $can_edit_post && 'trash' !== $post->post_status ) {
1071
-			$lock_holder = wp_check_post_lock( $post->ID );
1072
-
1073
-			if ( $lock_holder ) {
1074
-				$lock_holder   = get_userdata( $lock_holder );
1075
-				$locked_avatar = get_avatar( $lock_holder->ID, 18 );
1076
-				/* translators: %s: User's display name. */
1077
-				$locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
1078
-			} else {
1079
-				$locked_avatar = '';
1080
-				$locked_text   = '';
1081
-			}
1082
-
1083
-			echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
1084
-		}
1085
-
1086
-		$pad = str_repeat( '&#8212; ', $this->current_level );
1087
-		echo '<strong>';
1088
-
1089
-		$title = _draft_or_post_title();
1090
-
1091
-		if ( $can_edit_post && 'trash' !== $post->post_status ) {
1092
-			printf(
1093
-				'<a class="row-title" href="%s" aria-label="%s">%s%s</a>',
1094
-				get_edit_post_link( $post->ID ),
1095
-				/* translators: %s: Post title. */
1096
-				esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) ),
1097
-				$pad,
1098
-				$title
1099
-			);
1100
-		} else {
1101
-			printf(
1102
-				'<span>%s%s</span>',
1103
-				$pad,
1104
-				$title
1105
-			);
1106
-		}
1107
-		_post_states( $post );
1108
-
1109
-		if ( isset( $parent_name ) ) {
1110
-			$post_type_object = get_post_type_object( $post->post_type );
1111
-			echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
1112
-		}
1113
-
1114
-		echo "</strong>\n";
1115
-
1116
-		if ( 'excerpt' === $mode
1117
-			&& ! is_post_type_hierarchical( $this->screen->post_type )
1118
-			&& current_user_can( 'read_post', $post->ID )
1119
-		) {
1120
-			if ( post_password_required( $post ) ) {
1121
-				echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
1122
-			} else {
1123
-				echo esc_html( get_the_excerpt() );
1124
-			}
1125
-		}
1126
-
1127
-		get_inline_data( $post );
1128
-	}
1129
-
1130
-	/**
1131
-	 * Handles the post date column output.
1132
-	 *
1133
-	 * @since 4.3.0
1134
-	 *
1135
-	 * @global string $mode List table view mode.
1136
-	 *
1137
-	 * @param WP_Post $post The current WP_Post object.
1138
-	 */
1139
-	public function column_date( $post ) {
1140
-		global $mode;
1141
-
1142
-		if ( '0000-00-00 00:00:00' === $post->post_date ) {
1143
-			$t_time    = __( 'Unpublished' );
1144
-			$time_diff = 0;
1145
-		} else {
1146
-			$t_time = sprintf(
1147
-				/* translators: 1: Post date, 2: Post time. */
1148
-				__( '%1$s at %2$s' ),
1149
-				/* translators: Post date format. See https://www.php.net/manual/datetime.format.php */
1150
-				get_the_time( __( 'Y/m/d' ), $post ),
1151
-				/* translators: Post time format. See https://www.php.net/manual/datetime.format.php */
1152
-				get_the_time( __( 'g:i a' ), $post )
1153
-			);
1154
-
1155
-			$time      = get_post_timestamp( $post );
1156
-			$time_diff = time() - $time;
1157
-		}
1158
-
1159
-		if ( 'publish' === $post->post_status ) {
1160
-			$status = __( 'Published' );
1161
-		} elseif ( 'future' === $post->post_status ) {
1162
-			if ( $time_diff > 0 ) {
1163
-				$status = '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
1164
-			} else {
1165
-				$status = __( 'Scheduled' );
1166
-			}
1167
-		} else {
1168
-			$status = __( 'Last Modified' );
1169
-		}
1170
-
1171
-		/**
1172
-		 * Filters the status text of the post.
1173
-		 *
1174
-		 * @since 4.8.0
1175
-		 *
1176
-		 * @param string  $status      The status text.
1177
-		 * @param WP_Post $post        Post object.
1178
-		 * @param string  $column_name The column name.
1179
-		 * @param string  $mode        The list display mode ('excerpt' or 'list').
1180
-		 */
1181
-		$status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
1182
-
1183
-		if ( $status ) {
1184
-			echo $status . '<br />';
1185
-		}
1186
-
1187
-		/**
1188
-		 * Filters the published time of the post.
1189
-		 *
1190
-		 * @since 2.5.1
1191
-		 * @since 5.5.0 Removed the difference between 'excerpt' and 'list' modes.
1192
-		 *              The published time and date are both displayed now,
1193
-		 *              which is equivalent to the previous 'excerpt' mode.
1194
-		 *
1195
-		 * @param string  $t_time      The published time.
1196
-		 * @param WP_Post $post        Post object.
1197
-		 * @param string  $column_name The column name.
1198
-		 * @param string  $mode        The list display mode ('excerpt' or 'list').
1199
-		 */
1200
-		echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
1201
-	}
1202
-
1203
-	/**
1204
-	 * Handles the comments column output.
1205
-	 *
1206
-	 * @since 4.3.0
1207
-	 *
1208
-	 * @param WP_Post $post The current WP_Post object.
1209
-	 */
1210
-	public function column_comments( $post ) {
1211
-		?>
1015
+        endif;
1016
+    }
1017
+
1018
+    /**
1019
+     * @since 4.3.0
1020
+     *
1021
+     * @param WP_Post $post
1022
+     * @param string  $classes
1023
+     * @param string  $data
1024
+     * @param string  $primary
1025
+     */
1026
+    protected function _column_title( $post, $classes, $data, $primary ) {
1027
+        echo '<td class="' . $classes . ' page-title" ', $data, '>';
1028
+        echo $this->column_title( $post );
1029
+        echo $this->handle_row_actions( $post, 'title', $primary );
1030
+        echo '</td>';
1031
+    }
1032
+
1033
+    /**
1034
+     * Handles the title column output.
1035
+     *
1036
+     * @since 4.3.0
1037
+     *
1038
+     * @global string $mode List table view mode.
1039
+     *
1040
+     * @param WP_Post $post The current WP_Post object.
1041
+     */
1042
+    public function column_title( $post ) {
1043
+        global $mode;
1044
+
1045
+        if ( $this->hierarchical_display ) {
1046
+            if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
1047
+                // Sent level 0 by accident, by default, or because we don't know the actual level.
1048
+                $find_main_page = (int) $post->post_parent;
1049
+
1050
+                while ( $find_main_page > 0 ) {
1051
+                    $parent = get_post( $find_main_page );
1052
+
1053
+                    if ( is_null( $parent ) ) {
1054
+                        break;
1055
+                    }
1056
+
1057
+                    $this->current_level++;
1058
+                    $find_main_page = (int) $parent->post_parent;
1059
+
1060
+                    if ( ! isset( $parent_name ) ) {
1061
+                        /** This filter is documented in wp-includes/post-template.php */
1062
+                        $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
1063
+                    }
1064
+                }
1065
+            }
1066
+        }
1067
+
1068
+        $can_edit_post = current_user_can( 'edit_post', $post->ID );
1069
+
1070
+        if ( $can_edit_post && 'trash' !== $post->post_status ) {
1071
+            $lock_holder = wp_check_post_lock( $post->ID );
1072
+
1073
+            if ( $lock_holder ) {
1074
+                $lock_holder   = get_userdata( $lock_holder );
1075
+                $locked_avatar = get_avatar( $lock_holder->ID, 18 );
1076
+                /* translators: %s: User's display name. */
1077
+                $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
1078
+            } else {
1079
+                $locked_avatar = '';
1080
+                $locked_text   = '';
1081
+            }
1082
+
1083
+            echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
1084
+        }
1085
+
1086
+        $pad = str_repeat( '&#8212; ', $this->current_level );
1087
+        echo '<strong>';
1088
+
1089
+        $title = _draft_or_post_title();
1090
+
1091
+        if ( $can_edit_post && 'trash' !== $post->post_status ) {
1092
+            printf(
1093
+                '<a class="row-title" href="%s" aria-label="%s">%s%s</a>',
1094
+                get_edit_post_link( $post->ID ),
1095
+                /* translators: %s: Post title. */
1096
+                esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) ),
1097
+                $pad,
1098
+                $title
1099
+            );
1100
+        } else {
1101
+            printf(
1102
+                '<span>%s%s</span>',
1103
+                $pad,
1104
+                $title
1105
+            );
1106
+        }
1107
+        _post_states( $post );
1108
+
1109
+        if ( isset( $parent_name ) ) {
1110
+            $post_type_object = get_post_type_object( $post->post_type );
1111
+            echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
1112
+        }
1113
+
1114
+        echo "</strong>\n";
1115
+
1116
+        if ( 'excerpt' === $mode
1117
+            && ! is_post_type_hierarchical( $this->screen->post_type )
1118
+            && current_user_can( 'read_post', $post->ID )
1119
+        ) {
1120
+            if ( post_password_required( $post ) ) {
1121
+                echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
1122
+            } else {
1123
+                echo esc_html( get_the_excerpt() );
1124
+            }
1125
+        }
1126
+
1127
+        get_inline_data( $post );
1128
+    }
1129
+
1130
+    /**
1131
+     * Handles the post date column output.
1132
+     *
1133
+     * @since 4.3.0
1134
+     *
1135
+     * @global string $mode List table view mode.
1136
+     *
1137
+     * @param WP_Post $post The current WP_Post object.
1138
+     */
1139
+    public function column_date( $post ) {
1140
+        global $mode;
1141
+
1142
+        if ( '0000-00-00 00:00:00' === $post->post_date ) {
1143
+            $t_time    = __( 'Unpublished' );
1144
+            $time_diff = 0;
1145
+        } else {
1146
+            $t_time = sprintf(
1147
+                /* translators: 1: Post date, 2: Post time. */
1148
+                __( '%1$s at %2$s' ),
1149
+                /* translators: Post date format. See https://www.php.net/manual/datetime.format.php */
1150
+                get_the_time( __( 'Y/m/d' ), $post ),
1151
+                /* translators: Post time format. See https://www.php.net/manual/datetime.format.php */
1152
+                get_the_time( __( 'g:i a' ), $post )
1153
+            );
1154
+
1155
+            $time      = get_post_timestamp( $post );
1156
+            $time_diff = time() - $time;
1157
+        }
1158
+
1159
+        if ( 'publish' === $post->post_status ) {
1160
+            $status = __( 'Published' );
1161
+        } elseif ( 'future' === $post->post_status ) {
1162
+            if ( $time_diff > 0 ) {
1163
+                $status = '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
1164
+            } else {
1165
+                $status = __( 'Scheduled' );
1166
+            }
1167
+        } else {
1168
+            $status = __( 'Last Modified' );
1169
+        }
1170
+
1171
+        /**
1172
+         * Filters the status text of the post.
1173
+         *
1174
+         * @since 4.8.0
1175
+         *
1176
+         * @param string  $status      The status text.
1177
+         * @param WP_Post $post        Post object.
1178
+         * @param string  $column_name The column name.
1179
+         * @param string  $mode        The list display mode ('excerpt' or 'list').
1180
+         */
1181
+        $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
1182
+
1183
+        if ( $status ) {
1184
+            echo $status . '<br />';
1185
+        }
1186
+
1187
+        /**
1188
+         * Filters the published time of the post.
1189
+         *
1190
+         * @since 2.5.1
1191
+         * @since 5.5.0 Removed the difference between 'excerpt' and 'list' modes.
1192
+         *              The published time and date are both displayed now,
1193
+         *              which is equivalent to the previous 'excerpt' mode.
1194
+         *
1195
+         * @param string  $t_time      The published time.
1196
+         * @param WP_Post $post        Post object.
1197
+         * @param string  $column_name The column name.
1198
+         * @param string  $mode        The list display mode ('excerpt' or 'list').
1199
+         */
1200
+        echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
1201
+    }
1202
+
1203
+    /**
1204
+     * Handles the comments column output.
1205
+     *
1206
+     * @since 4.3.0
1207
+     *
1208
+     * @param WP_Post $post The current WP_Post object.
1209
+     */
1210
+    public function column_comments( $post ) {
1211
+        ?>
1212 1212
 		<div class="post-com-count-wrapper">
1213 1213
 		<?php
1214
-			$pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0;
1214
+            $pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0;
1215 1215
 
1216
-			$this->comments_bubble( $post->ID, $pending_comments );
1217
-		?>
1216
+            $this->comments_bubble( $post->ID, $pending_comments );
1217
+        ?>
1218 1218
 		</div>
1219 1219
 		<?php
1220
-	}
1221
-
1222
-	/**
1223
-	 * Handles the post author column output.
1224
-	 *
1225
-	 * @since 4.3.0
1226
-	 *
1227
-	 * @param WP_Post $post The current WP_Post object.
1228
-	 */
1229
-	public function column_author( $post ) {
1230
-		$args = array(
1231
-			'post_type' => $post->post_type,
1232
-			'author'    => get_the_author_meta( 'ID' ),
1233
-		);
1234
-		echo $this->get_edit_link( $args, get_the_author() );
1235
-	}
1236
-
1237
-	/**
1238
-	 * Handles the default column output.
1239
-	 *
1240
-	 * @since 4.3.0
1241
-	 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
1242
-	 *
1243
-	 * @param WP_Post $item        The current WP_Post object.
1244
-	 * @param string  $column_name The current column name.
1245
-	 */
1246
-	public function column_default( $item, $column_name ) {
1247
-		// Restores the more descriptive, specific name for use within this method.
1248
-		$post = $item;
1249
-
1250
-		if ( 'categories' === $column_name ) {
1251
-			$taxonomy = 'category';
1252
-		} elseif ( 'tags' === $column_name ) {
1253
-			$taxonomy = 'post_tag';
1254
-		} elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
1255
-			$taxonomy = substr( $column_name, 9 );
1256
-		} else {
1257
-			$taxonomy = false;
1258
-		}
1259
-
1260
-		if ( $taxonomy ) {
1261
-			$taxonomy_object = get_taxonomy( $taxonomy );
1262
-			$terms           = get_the_terms( $post->ID, $taxonomy );
1263
-
1264
-			if ( is_array( $terms ) ) {
1265
-				$term_links = array();
1266
-
1267
-				foreach ( $terms as $t ) {
1268
-					$posts_in_term_qv = array();
1269
-
1270
-					if ( 'post' !== $post->post_type ) {
1271
-						$posts_in_term_qv['post_type'] = $post->post_type;
1272
-					}
1273
-
1274
-					if ( $taxonomy_object->query_var ) {
1275
-						$posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
1276
-					} else {
1277
-						$posts_in_term_qv['taxonomy'] = $taxonomy;
1278
-						$posts_in_term_qv['term']     = $t->slug;
1279
-					}
1280
-
1281
-					$label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
1282
-
1283
-					$term_links[] = $this->get_edit_link( $posts_in_term_qv, $label );
1284
-				}
1285
-
1286
-				/**
1287
-				 * Filters the links in `$taxonomy` column of edit.php.
1288
-				 *
1289
-				 * @since 5.2.0
1290
-				 *
1291
-				 * @param string[]  $term_links Array of term editing links.
1292
-				 * @param string    $taxonomy   Taxonomy name.
1293
-				 * @param WP_Term[] $terms      Array of term objects appearing in the post row.
1294
-				 */
1295
-				$term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms );
1296
-
1297
-				echo implode( wp_get_list_item_separator(), $term_links );
1298
-			} else {
1299
-				echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
1300
-			}
1301
-			return;
1302
-		}
1303
-
1304
-		if ( is_post_type_hierarchical( $post->post_type ) ) {
1305
-
1306
-			/**
1307
-			 * Fires in each custom column on the Posts list table.
1308
-			 *
1309
-			 * This hook only fires if the current post type is hierarchical,
1310
-			 * such as pages.
1311
-			 *
1312
-			 * @since 2.5.0
1313
-			 *
1314
-			 * @param string $column_name The name of the column to display.
1315
-			 * @param int    $post_id     The current post ID.
1316
-			 */
1317
-			do_action( 'manage_pages_custom_column', $column_name, $post->ID );
1318
-		} else {
1319
-
1320
-			/**
1321
-			 * Fires in each custom column in the Posts list table.
1322
-			 *
1323
-			 * This hook only fires if the current post type is non-hierarchical,
1324
-			 * such as posts.
1325
-			 *
1326
-			 * @since 1.5.0
1327
-			 *
1328
-			 * @param string $column_name The name of the column to display.
1329
-			 * @param int    $post_id     The current post ID.
1330
-			 */
1331
-			do_action( 'manage_posts_custom_column', $column_name, $post->ID );
1332
-		}
1333
-
1334
-		/**
1335
-		 * Fires for each custom column of a specific post type in the Posts list table.
1336
-		 *
1337
-		 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
1338
-		 *
1339
-		 * Possible hook names include:
1340
-		 *
1341
-		 *  - `manage_post_posts_custom_column`
1342
-		 *  - `manage_page_posts_custom_column`
1343
-		 *
1344
-		 * @since 3.1.0
1345
-		 *
1346
-		 * @param string $column_name The name of the column to display.
1347
-		 * @param int    $post_id     The current post ID.
1348
-		 */
1349
-		do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
1350
-	}
1351
-
1352
-	/**
1353
-	 * @global WP_Post $post Global post object.
1354
-	 *
1355
-	 * @param int|WP_Post $post
1356
-	 * @param int         $level
1357
-	 */
1358
-	public function single_row( $post, $level = 0 ) {
1359
-		$global_post = get_post();
1360
-
1361
-		$post                = get_post( $post );
1362
-		$this->current_level = $level;
1363
-
1364
-		$GLOBALS['post'] = $post;
1365
-		setup_postdata( $post );
1366
-
1367
-		$classes = 'iedit author-' . ( get_current_user_id() === (int) $post->post_author ? 'self' : 'other' );
1368
-
1369
-		$lock_holder = wp_check_post_lock( $post->ID );
1370
-
1371
-		if ( $lock_holder ) {
1372
-			$classes .= ' wp-locked';
1373
-		}
1374
-
1375
-		if ( $post->post_parent ) {
1376
-			$count    = count( get_post_ancestors( $post->ID ) );
1377
-			$classes .= ' level-' . $count;
1378
-		} else {
1379
-			$classes .= ' level-0';
1380
-		}
1381
-		?>
1220
+    }
1221
+
1222
+    /**
1223
+     * Handles the post author column output.
1224
+     *
1225
+     * @since 4.3.0
1226
+     *
1227
+     * @param WP_Post $post The current WP_Post object.
1228
+     */
1229
+    public function column_author( $post ) {
1230
+        $args = array(
1231
+            'post_type' => $post->post_type,
1232
+            'author'    => get_the_author_meta( 'ID' ),
1233
+        );
1234
+        echo $this->get_edit_link( $args, get_the_author() );
1235
+    }
1236
+
1237
+    /**
1238
+     * Handles the default column output.
1239
+     *
1240
+     * @since 4.3.0
1241
+     * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
1242
+     *
1243
+     * @param WP_Post $item        The current WP_Post object.
1244
+     * @param string  $column_name The current column name.
1245
+     */
1246
+    public function column_default( $item, $column_name ) {
1247
+        // Restores the more descriptive, specific name for use within this method.
1248
+        $post = $item;
1249
+
1250
+        if ( 'categories' === $column_name ) {
1251
+            $taxonomy = 'category';
1252
+        } elseif ( 'tags' === $column_name ) {
1253
+            $taxonomy = 'post_tag';
1254
+        } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
1255
+            $taxonomy = substr( $column_name, 9 );
1256
+        } else {
1257
+            $taxonomy = false;
1258
+        }
1259
+
1260
+        if ( $taxonomy ) {
1261
+            $taxonomy_object = get_taxonomy( $taxonomy );
1262
+            $terms           = get_the_terms( $post->ID, $taxonomy );
1263
+
1264
+            if ( is_array( $terms ) ) {
1265
+                $term_links = array();
1266
+
1267
+                foreach ( $terms as $t ) {
1268
+                    $posts_in_term_qv = array();
1269
+
1270
+                    if ( 'post' !== $post->post_type ) {
1271
+                        $posts_in_term_qv['post_type'] = $post->post_type;
1272
+                    }
1273
+
1274
+                    if ( $taxonomy_object->query_var ) {
1275
+                        $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
1276
+                    } else {
1277
+                        $posts_in_term_qv['taxonomy'] = $taxonomy;
1278
+                        $posts_in_term_qv['term']     = $t->slug;
1279
+                    }
1280
+
1281
+                    $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
1282
+
1283
+                    $term_links[] = $this->get_edit_link( $posts_in_term_qv, $label );
1284
+                }
1285
+
1286
+                /**
1287
+                 * Filters the links in `$taxonomy` column of edit.php.
1288
+                 *
1289
+                 * @since 5.2.0
1290
+                 *
1291
+                 * @param string[]  $term_links Array of term editing links.
1292
+                 * @param string    $taxonomy   Taxonomy name.
1293
+                 * @param WP_Term[] $terms      Array of term objects appearing in the post row.
1294
+                 */
1295
+                $term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms );
1296
+
1297
+                echo implode( wp_get_list_item_separator(), $term_links );
1298
+            } else {
1299
+                echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
1300
+            }
1301
+            return;
1302
+        }
1303
+
1304
+        if ( is_post_type_hierarchical( $post->post_type ) ) {
1305
+
1306
+            /**
1307
+             * Fires in each custom column on the Posts list table.
1308
+             *
1309
+             * This hook only fires if the current post type is hierarchical,
1310
+             * such as pages.
1311
+             *
1312
+             * @since 2.5.0
1313
+             *
1314
+             * @param string $column_name The name of the column to display.
1315
+             * @param int    $post_id     The current post ID.
1316
+             */
1317
+            do_action( 'manage_pages_custom_column', $column_name, $post->ID );
1318
+        } else {
1319
+
1320
+            /**
1321
+             * Fires in each custom column in the Posts list table.
1322
+             *
1323
+             * This hook only fires if the current post type is non-hierarchical,
1324
+             * such as posts.
1325
+             *
1326
+             * @since 1.5.0
1327
+             *
1328
+             * @param string $column_name The name of the column to display.
1329
+             * @param int    $post_id     The current post ID.
1330
+             */
1331
+            do_action( 'manage_posts_custom_column', $column_name, $post->ID );
1332
+        }
1333
+
1334
+        /**
1335
+         * Fires for each custom column of a specific post type in the Posts list table.
1336
+         *
1337
+         * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
1338
+         *
1339
+         * Possible hook names include:
1340
+         *
1341
+         *  - `manage_post_posts_custom_column`
1342
+         *  - `manage_page_posts_custom_column`
1343
+         *
1344
+         * @since 3.1.0
1345
+         *
1346
+         * @param string $column_name The name of the column to display.
1347
+         * @param int    $post_id     The current post ID.
1348
+         */
1349
+        do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
1350
+    }
1351
+
1352
+    /**
1353
+     * @global WP_Post $post Global post object.
1354
+     *
1355
+     * @param int|WP_Post $post
1356
+     * @param int         $level
1357
+     */
1358
+    public function single_row( $post, $level = 0 ) {
1359
+        $global_post = get_post();
1360
+
1361
+        $post                = get_post( $post );
1362
+        $this->current_level = $level;
1363
+
1364
+        $GLOBALS['post'] = $post;
1365
+        setup_postdata( $post );
1366
+
1367
+        $classes = 'iedit author-' . ( get_current_user_id() === (int) $post->post_author ? 'self' : 'other' );
1368
+
1369
+        $lock_holder = wp_check_post_lock( $post->ID );
1370
+
1371
+        if ( $lock_holder ) {
1372
+            $classes .= ' wp-locked';
1373
+        }
1374
+
1375
+        if ( $post->post_parent ) {
1376
+            $count    = count( get_post_ancestors( $post->ID ) );
1377
+            $classes .= ' level-' . $count;
1378
+        } else {
1379
+            $classes .= ' level-0';
1380
+        }
1381
+        ?>
1382 1382
 		<tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
1383 1383
 			<?php $this->single_row_columns( $post ); ?>
1384 1384
 		</tr>
1385 1385
 		<?php
1386
-		$GLOBALS['post'] = $global_post;
1387
-	}
1388
-
1389
-	/**
1390
-	 * Gets the name of the default primary column.
1391
-	 *
1392
-	 * @since 4.3.0
1393
-	 *
1394
-	 * @return string Name of the default primary column, in this case, 'title'.
1395
-	 */
1396
-	protected function get_default_primary_column_name() {
1397
-		return 'title';
1398
-	}
1399
-
1400
-	/**
1401
-	 * Generates and displays row action links.
1402
-	 *
1403
-	 * @since 4.3.0
1404
-	 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
1405
-	 *
1406
-	 * @param WP_Post $item        Post being acted upon.
1407
-	 * @param string  $column_name Current column name.
1408
-	 * @param string  $primary     Primary column name.
1409
-	 * @return string Row actions output for posts, or an empty string
1410
-	 *                if the current column is not the primary column.
1411
-	 */
1412
-	protected function handle_row_actions( $item, $column_name, $primary ) {
1413
-		if ( $primary !== $column_name ) {
1414
-			return '';
1415
-		}
1416
-
1417
-		// Restores the more descriptive, specific name for use within this method.
1418
-		$post             = $item;
1419
-		$post_type_object = get_post_type_object( $post->post_type );
1420
-		$can_edit_post    = current_user_can( 'edit_post', $post->ID );
1421
-		$actions          = array();
1422
-		$title            = _draft_or_post_title();
1423
-
1424
-		if ( $can_edit_post && 'trash' !== $post->post_status ) {
1425
-			$actions['edit'] = sprintf(
1426
-				'<a href="%s" aria-label="%s">%s</a>',
1427
-				get_edit_post_link( $post->ID ),
1428
-				/* translators: %s: Post title. */
1429
-				esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
1430
-				__( 'Edit' )
1431
-			);
1432
-
1433
-			if ( 'wp_block' !== $post->post_type ) {
1434
-				$actions['inline hide-if-no-js'] = sprintf(
1435
-					'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
1436
-					/* translators: %s: Post title. */
1437
-					esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $title ) ),
1438
-					__( 'Quick&nbsp;Edit' )
1439
-				);
1440
-			}
1441
-		}
1442
-
1443
-		if ( current_user_can( 'delete_post', $post->ID ) ) {
1444
-			if ( 'trash' === $post->post_status ) {
1445
-				$actions['untrash'] = sprintf(
1446
-					'<a href="%s" aria-label="%s">%s</a>',
1447
-					wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ),
1448
-					/* translators: %s: Post title. */
1449
-					esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $title ) ),
1450
-					__( 'Restore' )
1451
-				);
1452
-			} elseif ( EMPTY_TRASH_DAYS ) {
1453
-				$actions['trash'] = sprintf(
1454
-					'<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1455
-					get_delete_post_link( $post->ID ),
1456
-					/* translators: %s: Post title. */
1457
-					esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $title ) ),
1458
-					_x( 'Trash', 'verb' )
1459
-				);
1460
-			}
1461
-
1462
-			if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) {
1463
-				$actions['delete'] = sprintf(
1464
-					'<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1465
-					get_delete_post_link( $post->ID, '', true ),
1466
-					/* translators: %s: Post title. */
1467
-					esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $title ) ),
1468
-					__( 'Delete Permanently' )
1469
-				);
1470
-			}
1471
-		}
1472
-
1473
-		if ( is_post_type_viewable( $post_type_object ) ) {
1474
-			if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ), true ) ) {
1475
-				if ( $can_edit_post ) {
1476
-					$preview_link    = get_preview_post_link( $post );
1477
-					$actions['view'] = sprintf(
1478
-						'<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
1479
-						esc_url( $preview_link ),
1480
-						/* translators: %s: Post title. */
1481
-						esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ),
1482
-						__( 'Preview' )
1483
-					);
1484
-				}
1485
-			} elseif ( 'trash' !== $post->post_status ) {
1486
-				$actions['view'] = sprintf(
1487
-					'<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
1488
-					get_permalink( $post->ID ),
1489
-					/* translators: %s: Post title. */
1490
-					esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ),
1491
-					__( 'View' )
1492
-				);
1493
-			}
1494
-		}
1495
-
1496
-		if ( 'wp_block' === $post->post_type ) {
1497
-			$actions['export'] = sprintf(
1498
-				'<button type="button" class="wp-list-reusable-blocks__export button-link" data-id="%s" aria-label="%s">%s</button>',
1499
-				$post->ID,
1500
-				/* translators: %s: Post title. */
1501
-				esc_attr( sprintf( __( 'Export &#8220;%s&#8221; as JSON' ), $title ) ),
1502
-				__( 'Export as JSON' )
1503
-			);
1504
-		}
1505
-
1506
-		if ( is_post_type_hierarchical( $post->post_type ) ) {
1507
-
1508
-			/**
1509
-			 * Filters the array of row action links on the Pages list table.
1510
-			 *
1511
-			 * The filter is evaluated only for hierarchical post types.
1512
-			 *
1513
-			 * @since 2.8.0
1514
-			 *
1515
-			 * @param string[] $actions An array of row action links. Defaults are
1516
-			 *                          'Edit', 'Quick Edit', 'Restore', 'Trash',
1517
-			 *                          'Delete Permanently', 'Preview', and 'View'.
1518
-			 * @param WP_Post  $post    The post object.
1519
-			 */
1520
-			$actions = apply_filters( 'page_row_actions', $actions, $post );
1521
-		} else {
1522
-
1523
-			/**
1524
-			 * Filters the array of row action links on the Posts list table.
1525
-			 *
1526
-			 * The filter is evaluated only for non-hierarchical post types.
1527
-			 *
1528
-			 * @since 2.8.0
1529
-			 *
1530
-			 * @param string[] $actions An array of row action links. Defaults are
1531
-			 *                          'Edit', 'Quick Edit', 'Restore', 'Trash',
1532
-			 *                          'Delete Permanently', 'Preview', and 'View'.
1533
-			 * @param WP_Post  $post    The post object.
1534
-			 */
1535
-			$actions = apply_filters( 'post_row_actions', $actions, $post );
1536
-		}
1537
-
1538
-		return $this->row_actions( $actions );
1539
-	}
1540
-
1541
-	/**
1542
-	 * Outputs the hidden row displayed when inline editing
1543
-	 *
1544
-	 * @since 3.1.0
1545
-	 *
1546
-	 * @global string $mode List table view mode.
1547
-	 */
1548
-	public function inline_edit() {
1549
-		global $mode;
1550
-
1551
-		$screen = $this->screen;
1552
-
1553
-		$post             = get_default_post_to_edit( $screen->post_type );
1554
-		$post_type_object = get_post_type_object( $screen->post_type );
1555
-
1556
-		$taxonomy_names          = get_object_taxonomies( $screen->post_type );
1557
-		$hierarchical_taxonomies = array();
1558
-		$flat_taxonomies         = array();
1559
-
1560
-		foreach ( $taxonomy_names as $taxonomy_name ) {
1561
-			$taxonomy = get_taxonomy( $taxonomy_name );
1562
-
1563
-			$show_in_quick_edit = $taxonomy->show_in_quick_edit;
1564
-
1565
-			/**
1566
-			 * Filters whether the current taxonomy should be shown in the Quick Edit panel.
1567
-			 *
1568
-			 * @since 4.2.0
1569
-			 *
1570
-			 * @param bool   $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
1571
-			 * @param string $taxonomy_name      Taxonomy name.
1572
-			 * @param string $post_type          Post type of current Quick Edit post.
1573
-			 */
1574
-			if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
1575
-				continue;
1576
-			}
1577
-
1578
-			if ( $taxonomy->hierarchical ) {
1579
-				$hierarchical_taxonomies[] = $taxonomy;
1580
-			} else {
1581
-				$flat_taxonomies[] = $taxonomy;
1582
-			}
1583
-		}
1584
-
1585
-		$m            = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
1586
-		$can_publish  = current_user_can( $post_type_object->cap->publish_posts );
1587
-		$core_columns = array(
1588
-			'cb'         => true,
1589
-			'date'       => true,
1590
-			'title'      => true,
1591
-			'categories' => true,
1592
-			'tags'       => true,
1593
-			'comments'   => true,
1594
-			'author'     => true,
1595
-		);
1596
-		?>
1386
+        $GLOBALS['post'] = $global_post;
1387
+    }
1388
+
1389
+    /**
1390
+     * Gets the name of the default primary column.
1391
+     *
1392
+     * @since 4.3.0
1393
+     *
1394
+     * @return string Name of the default primary column, in this case, 'title'.
1395
+     */
1396
+    protected function get_default_primary_column_name() {
1397
+        return 'title';
1398
+    }
1399
+
1400
+    /**
1401
+     * Generates and displays row action links.
1402
+     *
1403
+     * @since 4.3.0
1404
+     * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
1405
+     *
1406
+     * @param WP_Post $item        Post being acted upon.
1407
+     * @param string  $column_name Current column name.
1408
+     * @param string  $primary     Primary column name.
1409
+     * @return string Row actions output for posts, or an empty string
1410
+     *                if the current column is not the primary column.
1411
+     */
1412
+    protected function handle_row_actions( $item, $column_name, $primary ) {
1413
+        if ( $primary !== $column_name ) {
1414
+            return '';
1415
+        }
1416
+
1417
+        // Restores the more descriptive, specific name for use within this method.
1418
+        $post             = $item;
1419
+        $post_type_object = get_post_type_object( $post->post_type );
1420
+        $can_edit_post    = current_user_can( 'edit_post', $post->ID );
1421
+        $actions          = array();
1422
+        $title            = _draft_or_post_title();
1423
+
1424
+        if ( $can_edit_post && 'trash' !== $post->post_status ) {
1425
+            $actions['edit'] = sprintf(
1426
+                '<a href="%s" aria-label="%s">%s</a>',
1427
+                get_edit_post_link( $post->ID ),
1428
+                /* translators: %s: Post title. */
1429
+                esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
1430
+                __( 'Edit' )
1431
+            );
1432
+
1433
+            if ( 'wp_block' !== $post->post_type ) {
1434
+                $actions['inline hide-if-no-js'] = sprintf(
1435
+                    '<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
1436
+                    /* translators: %s: Post title. */
1437
+                    esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $title ) ),
1438
+                    __( 'Quick&nbsp;Edit' )
1439
+                );
1440
+            }
1441
+        }
1442
+
1443
+        if ( current_user_can( 'delete_post', $post->ID ) ) {
1444
+            if ( 'trash' === $post->post_status ) {
1445
+                $actions['untrash'] = sprintf(
1446
+                    '<a href="%s" aria-label="%s">%s</a>',
1447
+                    wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ),
1448
+                    /* translators: %s: Post title. */
1449
+                    esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $title ) ),
1450
+                    __( 'Restore' )
1451
+                );
1452
+            } elseif ( EMPTY_TRASH_DAYS ) {
1453
+                $actions['trash'] = sprintf(
1454
+                    '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1455
+                    get_delete_post_link( $post->ID ),
1456
+                    /* translators: %s: Post title. */
1457
+                    esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $title ) ),
1458
+                    _x( 'Trash', 'verb' )
1459
+                );
1460
+            }
1461
+
1462
+            if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) {
1463
+                $actions['delete'] = sprintf(
1464
+                    '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1465
+                    get_delete_post_link( $post->ID, '', true ),
1466
+                    /* translators: %s: Post title. */
1467
+                    esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $title ) ),
1468
+                    __( 'Delete Permanently' )
1469
+                );
1470
+            }
1471
+        }
1472
+
1473
+        if ( is_post_type_viewable( $post_type_object ) ) {
1474
+            if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ), true ) ) {
1475
+                if ( $can_edit_post ) {
1476
+                    $preview_link    = get_preview_post_link( $post );
1477
+                    $actions['view'] = sprintf(
1478
+                        '<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
1479
+                        esc_url( $preview_link ),
1480
+                        /* translators: %s: Post title. */
1481
+                        esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ),
1482
+                        __( 'Preview' )
1483
+                    );
1484
+                }
1485
+            } elseif ( 'trash' !== $post->post_status ) {
1486
+                $actions['view'] = sprintf(
1487
+                    '<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
1488
+                    get_permalink( $post->ID ),
1489
+                    /* translators: %s: Post title. */
1490
+                    esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ),
1491
+                    __( 'View' )
1492
+                );
1493
+            }
1494
+        }
1495
+
1496
+        if ( 'wp_block' === $post->post_type ) {
1497
+            $actions['export'] = sprintf(
1498
+                '<button type="button" class="wp-list-reusable-blocks__export button-link" data-id="%s" aria-label="%s">%s</button>',
1499
+                $post->ID,
1500
+                /* translators: %s: Post title. */
1501
+                esc_attr( sprintf( __( 'Export &#8220;%s&#8221; as JSON' ), $title ) ),
1502
+                __( 'Export as JSON' )
1503
+            );
1504
+        }
1505
+
1506
+        if ( is_post_type_hierarchical( $post->post_type ) ) {
1507
+
1508
+            /**
1509
+             * Filters the array of row action links on the Pages list table.
1510
+             *
1511
+             * The filter is evaluated only for hierarchical post types.
1512
+             *
1513
+             * @since 2.8.0
1514
+             *
1515
+             * @param string[] $actions An array of row action links. Defaults are
1516
+             *                          'Edit', 'Quick Edit', 'Restore', 'Trash',
1517
+             *                          'Delete Permanently', 'Preview', and 'View'.
1518
+             * @param WP_Post  $post    The post object.
1519
+             */
1520
+            $actions = apply_filters( 'page_row_actions', $actions, $post );
1521
+        } else {
1522
+
1523
+            /**
1524
+             * Filters the array of row action links on the Posts list table.
1525
+             *
1526
+             * The filter is evaluated only for non-hierarchical post types.
1527
+             *
1528
+             * @since 2.8.0
1529
+             *
1530
+             * @param string[] $actions An array of row action links. Defaults are
1531
+             *                          'Edit', 'Quick Edit', 'Restore', 'Trash',
1532
+             *                          'Delete Permanently', 'Preview', and 'View'.
1533
+             * @param WP_Post  $post    The post object.
1534
+             */
1535
+            $actions = apply_filters( 'post_row_actions', $actions, $post );
1536
+        }
1537
+
1538
+        return $this->row_actions( $actions );
1539
+    }
1540
+
1541
+    /**
1542
+     * Outputs the hidden row displayed when inline editing
1543
+     *
1544
+     * @since 3.1.0
1545
+     *
1546
+     * @global string $mode List table view mode.
1547
+     */
1548
+    public function inline_edit() {
1549
+        global $mode;
1550
+
1551
+        $screen = $this->screen;
1552
+
1553
+        $post             = get_default_post_to_edit( $screen->post_type );
1554
+        $post_type_object = get_post_type_object( $screen->post_type );
1555
+
1556
+        $taxonomy_names          = get_object_taxonomies( $screen->post_type );
1557
+        $hierarchical_taxonomies = array();
1558
+        $flat_taxonomies         = array();
1559
+
1560
+        foreach ( $taxonomy_names as $taxonomy_name ) {
1561
+            $taxonomy = get_taxonomy( $taxonomy_name );
1562
+
1563
+            $show_in_quick_edit = $taxonomy->show_in_quick_edit;
1564
+
1565
+            /**
1566
+             * Filters whether the current taxonomy should be shown in the Quick Edit panel.
1567
+             *
1568
+             * @since 4.2.0
1569
+             *
1570
+             * @param bool   $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
1571
+             * @param string $taxonomy_name      Taxonomy name.
1572
+             * @param string $post_type          Post type of current Quick Edit post.
1573
+             */
1574
+            if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
1575
+                continue;
1576
+            }
1577
+
1578
+            if ( $taxonomy->hierarchical ) {
1579
+                $hierarchical_taxonomies[] = $taxonomy;
1580
+            } else {
1581
+                $flat_taxonomies[] = $taxonomy;
1582
+            }
1583
+        }
1584
+
1585
+        $m            = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
1586
+        $can_publish  = current_user_can( $post_type_object->cap->publish_posts );
1587
+        $core_columns = array(
1588
+            'cb'         => true,
1589
+            'date'       => true,
1590
+            'title'      => true,
1591
+            'categories' => true,
1592
+            'tags'       => true,
1593
+            'comments'   => true,
1594
+            'author'     => true,
1595
+        );
1596
+        ?>
1597 1597
 
1598 1598
 		<form method="get">
1599 1599
 		<table style="display: none"><tbody id="inlineedit">
1600 1600
 		<?php
1601
-		$hclass              = count( $hierarchical_taxonomies ) ? 'post' : 'page';
1602
-		$inline_edit_classes = "inline-edit-row inline-edit-row-$hclass";
1603
-		$bulk_edit_classes   = "bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}";
1604
-		$quick_edit_classes  = "quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}";
1601
+        $hclass              = count( $hierarchical_taxonomies ) ? 'post' : 'page';
1602
+        $inline_edit_classes = "inline-edit-row inline-edit-row-$hclass";
1603
+        $bulk_edit_classes   = "bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}";
1604
+        $quick_edit_classes  = "quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}";
1605 1605
 
1606
-		$bulk = 0;
1606
+        $bulk = 0;
1607 1607
 
1608
-		while ( $bulk < 2 ) :
1609
-			$classes  = $inline_edit_classes . ' ';
1610
-			$classes .= $bulk ? $bulk_edit_classes : $quick_edit_classes;
1611
-			?>
1608
+        while ( $bulk < 2 ) :
1609
+            $classes  = $inline_edit_classes . ' ';
1610
+            $classes .= $bulk ? $bulk_edit_classes : $quick_edit_classes;
1611
+            ?>
1612 1612
 			<tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="<?php echo $classes; ?>" style="display: none">
1613 1613
 			<td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
1614 1614
 			<div class="inline-edit-wrapper" role="region" aria-labelledby="<?php echo $bulk ? 'bulk' : 'quick'; ?>-edit-legend">
@@ -1653,57 +1653,57 @@  discard block
 block discarded – undo
1653 1653
 				<?php endif; // $bulk ?>
1654 1654
 
1655 1655
 				<?php
1656
-				if ( post_type_supports( $screen->post_type, 'author' ) ) {
1657
-					$authors_dropdown = '';
1658
-
1659
-					if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) {
1660
-						$dropdown_name  = 'post_author';
1661
-						$dropdown_class = 'authors';
1662
-						if ( wp_is_large_user_count() ) {
1663
-							$authors_dropdown = sprintf( '<select name="%s" class="%s hidden"></select>', esc_attr( $dropdown_name ), esc_attr( $dropdown_class ) );
1664
-						} else {
1665
-							$users_opt = array(
1666
-								'hide_if_only_one_author' => false,
1667
-								'capability'              => array( $post_type_object->cap->edit_posts ),
1668
-								'name'                    => $dropdown_name,
1669
-								'class'                   => $dropdown_class,
1670
-								'multi'                   => 1,
1671
-								'echo'                    => 0,
1672
-								'show'                    => 'display_name_with_login',
1673
-							);
1674
-
1675
-							if ( $bulk ) {
1676
-								$users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
1677
-							}
1678
-
1679
-							/**
1680
-							 * Filters the arguments used to generate the Quick Edit authors drop-down.
1681
-							 *
1682
-							 * @since 5.6.0
1683
-							 *
1684
-							 * @see wp_dropdown_users()
1685
-							 *
1686
-							 * @param array $users_opt An array of arguments passed to wp_dropdown_users().
1687
-							 * @param bool $bulk A flag to denote if it's a bulk action.
1688
-							 */
1689
-							$users_opt = apply_filters( 'quick_edit_dropdown_authors_args', $users_opt, $bulk );
1690
-
1691
-							$authors = wp_dropdown_users( $users_opt );
1692
-
1693
-							if ( $authors ) {
1694
-								$authors_dropdown  = '<label class="inline-edit-author">';
1695
-								$authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
1696
-								$authors_dropdown .= $authors;
1697
-								$authors_dropdown .= '</label>';
1698
-							}
1699
-						}
1700
-					} // current_user_can( 'edit_others_posts' )
1701
-
1702
-					if ( ! $bulk ) {
1703
-						echo $authors_dropdown;
1704
-					}
1705
-				} // post_type_supports( ... 'author' )
1706
-				?>
1656
+                if ( post_type_supports( $screen->post_type, 'author' ) ) {
1657
+                    $authors_dropdown = '';
1658
+
1659
+                    if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) {
1660
+                        $dropdown_name  = 'post_author';
1661
+                        $dropdown_class = 'authors';
1662
+                        if ( wp_is_large_user_count() ) {
1663
+                            $authors_dropdown = sprintf( '<select name="%s" class="%s hidden"></select>', esc_attr( $dropdown_name ), esc_attr( $dropdown_class ) );
1664
+                        } else {
1665
+                            $users_opt = array(
1666
+                                'hide_if_only_one_author' => false,
1667
+                                'capability'              => array( $post_type_object->cap->edit_posts ),
1668
+                                'name'                    => $dropdown_name,
1669
+                                'class'                   => $dropdown_class,
1670
+                                'multi'                   => 1,
1671
+                                'echo'                    => 0,
1672
+                                'show'                    => 'display_name_with_login',
1673
+                            );
1674
+
1675
+                            if ( $bulk ) {
1676
+                                $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
1677
+                            }
1678
+
1679
+                            /**
1680
+                             * Filters the arguments used to generate the Quick Edit authors drop-down.
1681
+                             *
1682
+                             * @since 5.6.0
1683
+                             *
1684
+                             * @see wp_dropdown_users()
1685
+                             *
1686
+                             * @param array $users_opt An array of arguments passed to wp_dropdown_users().
1687
+                             * @param bool $bulk A flag to denote if it's a bulk action.
1688
+                             */
1689
+                            $users_opt = apply_filters( 'quick_edit_dropdown_authors_args', $users_opt, $bulk );
1690
+
1691
+                            $authors = wp_dropdown_users( $users_opt );
1692
+
1693
+                            if ( $authors ) {
1694
+                                $authors_dropdown  = '<label class="inline-edit-author">';
1695
+                                $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
1696
+                                $authors_dropdown .= $authors;
1697
+                                $authors_dropdown .= '</label>';
1698
+                            }
1699
+                        }
1700
+                    } // current_user_can( 'edit_others_posts' )
1701
+
1702
+                    if ( ! $bulk ) {
1703
+                        echo $authors_dropdown;
1704
+                    }
1705
+                } // post_type_supports( ... 'author' )
1706
+                ?>
1707 1707
 
1708 1708
 				<?php if ( ! $bulk && $can_publish ) : ?>
1709 1709
 
@@ -1715,9 +1715,9 @@  discard block
 block discarded – undo
1715 1715
 
1716 1716
 						<span class="alignleft inline-edit-or">
1717 1717
 							<?php
1718
-							/* translators: Between password field and private checkbox on post quick edit interface. */
1719
-							_e( '&ndash;OR&ndash;' );
1720
-							?>
1718
+                            /* translators: Between password field and private checkbox on post quick edit interface. */
1719
+                            _e( '&ndash;OR&ndash;' );
1720
+                            ?>
1721 1721
 						</span>
1722 1722
 						<label class="alignleft inline-edit-private">
1723 1723
 							<input type="checkbox" name="keep_private" value="private" />
@@ -1754,10 +1754,10 @@  discard block
 block discarded – undo
1754 1754
 				<div class="inline-edit-col">
1755 1755
 
1756 1756
 				<?php
1757
-				if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) {
1758
-					echo $authors_dropdown;
1759
-				}
1760
-				?>
1757
+                if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) {
1758
+                    echo $authors_dropdown;
1759
+                }
1760
+                ?>
1761 1761
 
1762 1762
 				<?php if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) : ?>
1763 1763
 
@@ -1766,34 +1766,34 @@  discard block
 block discarded – undo
1766 1766
 						<label>
1767 1767
 							<span class="title"><?php _e( 'Parent' ); ?></span>
1768 1768
 							<?php
1769
-							$dropdown_args = array(
1770
-								'post_type'         => $post_type_object->name,
1771
-								'selected'          => $post->post_parent,
1772
-								'name'              => 'post_parent',
1773
-								'show_option_none'  => __( 'Main Page (no parent)' ),
1774
-								'option_none_value' => 0,
1775
-								'sort_column'       => 'menu_order, post_title',
1776
-							);
1777
-
1778
-							if ( $bulk ) {
1779
-								$dropdown_args['show_option_no_change'] = __( '&mdash; No Change &mdash;' );
1780
-							}
1781
-
1782
-							/**
1783
-							 * Filters the arguments used to generate the Quick Edit page-parent drop-down.
1784
-							 *
1785
-							 * @since 2.7.0
1786
-							 * @since 5.6.0 The `$bulk` parameter was added.
1787
-							 *
1788
-							 * @see wp_dropdown_pages()
1789
-							 *
1790
-							 * @param array $dropdown_args An array of arguments passed to wp_dropdown_pages().
1791
-							 * @param bool  $bulk          A flag to denote if it's a bulk action.
1792
-							 */
1793
-							$dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args, $bulk );
1794
-
1795
-							wp_dropdown_pages( $dropdown_args );
1796
-							?>
1769
+                            $dropdown_args = array(
1770
+                                'post_type'         => $post_type_object->name,
1771
+                                'selected'          => $post->post_parent,
1772
+                                'name'              => 'post_parent',
1773
+                                'show_option_none'  => __( 'Main Page (no parent)' ),
1774
+                                'option_none_value' => 0,
1775
+                                'sort_column'       => 'menu_order, post_title',
1776
+                            );
1777
+
1778
+                            if ( $bulk ) {
1779
+                                $dropdown_args['show_option_no_change'] = __( '&mdash; No Change &mdash;' );
1780
+                            }
1781
+
1782
+                            /**
1783
+                             * Filters the arguments used to generate the Quick Edit page-parent drop-down.
1784
+                             *
1785
+                             * @since 2.7.0
1786
+                             * @since 5.6.0 The `$bulk` parameter was added.
1787
+                             *
1788
+                             * @see wp_dropdown_pages()
1789
+                             *
1790
+                             * @param array $dropdown_args An array of arguments passed to wp_dropdown_pages().
1791
+                             * @param bool  $bulk          A flag to denote if it's a bulk action.
1792
+                             */
1793
+                            $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args, $bulk );
1794
+
1795
+                            wp_dropdown_pages( $dropdown_args );
1796
+                            ?>
1797 1797
 						</label>
1798 1798
 
1799 1799
 					<?php endif; // hierarchical ?>
@@ -1818,9 +1818,9 @@  discard block
 block discarded – undo
1818 1818
 							<option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1819 1819
 							<?php endif; // $bulk ?>
1820 1820
 							<?php
1821
-							/** This filter is documented in wp-admin/includes/meta-boxes.php */
1822
-							$default_title = apply_filters( 'default_page_template_title', __( 'Default template' ), 'quick-edit' );
1823
-							?>
1821
+                            /** This filter is documented in wp-admin/includes/meta-boxes.php */
1822
+                            $default_title = apply_filters( 'default_page_template_title', __( 'Default template' ), 'quick-edit' );
1823
+                            ?>
1824 1824
 							<option value="default"><?php echo esc_html( $default_title ); ?></option>
1825 1825
 							<?php page_template_dropdown( '', $screen->post_type ); ?>
1826 1826
 						</select>
@@ -1979,39 +1979,39 @@  discard block
 block discarded – undo
1979 1979
 			</fieldset>
1980 1980
 
1981 1981
 			<?php
1982
-			list( $columns ) = $this->get_column_info();
1983
-
1984
-			foreach ( $columns as $column_name => $column_display_name ) {
1985
-				if ( isset( $core_columns[ $column_name ] ) ) {
1986
-					continue;
1987
-				}
1988
-
1989
-				if ( $bulk ) {
1990
-
1991
-					/**
1992
-					 * Fires once for each column in Bulk Edit mode.
1993
-					 *
1994
-					 * @since 2.7.0
1995
-					 *
1996
-					 * @param string $column_name Name of the column to edit.
1997
-					 * @param string $post_type   The post type slug.
1998
-					 */
1999
-					do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
2000
-				} else {
2001
-
2002
-					/**
2003
-					 * Fires once for each column in Quick Edit mode.
2004
-					 *
2005
-					 * @since 2.7.0
2006
-					 *
2007
-					 * @param string $column_name Name of the column to edit.
2008
-					 * @param string $post_type   The post type slug, or current screen name if this is a taxonomy list table.
2009
-					 * @param string $taxonomy    The taxonomy name, if any.
2010
-					 */
2011
-					do_action( 'quick_edit_custom_box', $column_name, $screen->post_type, '' );
2012
-				}
2013
-			}
2014
-			?>
1982
+            list( $columns ) = $this->get_column_info();
1983
+
1984
+            foreach ( $columns as $column_name => $column_display_name ) {
1985
+                if ( isset( $core_columns[ $column_name ] ) ) {
1986
+                    continue;
1987
+                }
1988
+
1989
+                if ( $bulk ) {
1990
+
1991
+                    /**
1992
+                     * Fires once for each column in Bulk Edit mode.
1993
+                     *
1994
+                     * @since 2.7.0
1995
+                     *
1996
+                     * @param string $column_name Name of the column to edit.
1997
+                     * @param string $post_type   The post type slug.
1998
+                     */
1999
+                    do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
2000
+                } else {
2001
+
2002
+                    /**
2003
+                     * Fires once for each column in Quick Edit mode.
2004
+                     *
2005
+                     * @since 2.7.0
2006
+                     *
2007
+                     * @param string $column_name Name of the column to edit.
2008
+                     * @param string $post_type   The post type slug, or current screen name if this is a taxonomy list table.
2009
+                     * @param string $taxonomy    The taxonomy name, if any.
2010
+                     */
2011
+                    do_action( 'quick_edit_custom_box', $column_name, $screen->post_type, '' );
2012
+                }
2013
+            }
2014
+            ?>
2015 2015
 
2016 2016
 			<div class="submit inline-edit-save">
2017 2017
 				<?php if ( ! $bulk ) : ?>
@@ -2042,11 +2042,11 @@  discard block
 block discarded – undo
2042 2042
 			</td></tr>
2043 2043
 
2044 2044
 			<?php
2045
-			$bulk++;
2046
-		endwhile;
2047
-		?>
2045
+            $bulk++;
2046
+        endwhile;
2047
+        ?>
2048 2048
 		</tbody></table>
2049 2049
 		</form>
2050 2050
 		<?php
2051
-	}
2051
+    }
2052 2052
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-walker-nav-menu-edit.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -15,111 +15,111 @@  discard block
 block discarded – undo
15 15
  * @see Walker_Nav_Menu
16 16
  */
17 17
 class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
18
-	/**
19
-	 * Starts the list before the elements are added.
20
-	 *
21
-	 * @see Walker_Nav_Menu::start_lvl()
22
-	 *
23
-	 * @since 3.0.0
24
-	 *
25
-	 * @param string   $output Passed by reference.
26
-	 * @param int      $depth  Depth of menu item. Used for padding.
27
-	 * @param stdClass $args   Not used.
28
-	 */
29
-	public function start_lvl( &$output, $depth = 0, $args = null ) {}
18
+    /**
19
+     * Starts the list before the elements are added.
20
+     *
21
+     * @see Walker_Nav_Menu::start_lvl()
22
+     *
23
+     * @since 3.0.0
24
+     *
25
+     * @param string   $output Passed by reference.
26
+     * @param int      $depth  Depth of menu item. Used for padding.
27
+     * @param stdClass $args   Not used.
28
+     */
29
+    public function start_lvl( &$output, $depth = 0, $args = null ) {}
30 30
 
31
-	/**
32
-	 * Ends the list of after the elements are added.
33
-	 *
34
-	 * @see Walker_Nav_Menu::end_lvl()
35
-	 *
36
-	 * @since 3.0.0
37
-	 *
38
-	 * @param string   $output Passed by reference.
39
-	 * @param int      $depth  Depth of menu item. Used for padding.
40
-	 * @param stdClass $args   Not used.
41
-	 */
42
-	public function end_lvl( &$output, $depth = 0, $args = null ) {}
31
+    /**
32
+     * Ends the list of after the elements are added.
33
+     *
34
+     * @see Walker_Nav_Menu::end_lvl()
35
+     *
36
+     * @since 3.0.0
37
+     *
38
+     * @param string   $output Passed by reference.
39
+     * @param int      $depth  Depth of menu item. Used for padding.
40
+     * @param stdClass $args   Not used.
41
+     */
42
+    public function end_lvl( &$output, $depth = 0, $args = null ) {}
43 43
 
44
-	/**
45
-	 * Start the element output.
46
-	 *
47
-	 * @see Walker_Nav_Menu::start_el()
48
-	 * @since 3.0.0
49
-	 * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
50
-	 *              to match parent class for PHP 8 named parameter support.
51
-	 *
52
-	 * @global int $_wp_nav_menu_max_depth
53
-	 *
54
-	 * @param string   $output            Used to append additional content (passed by reference).
55
-	 * @param WP_Post  $data_object       Menu item data object.
56
-	 * @param int      $depth             Depth of menu item. Used for padding.
57
-	 * @param stdClass $args              Not used.
58
-	 * @param int      $current_object_id Optional. ID of the current menu item. Default 0.
59
-	 */
60
-	public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
61
-		global $_wp_nav_menu_max_depth;
44
+    /**
45
+     * Start the element output.
46
+     *
47
+     * @see Walker_Nav_Menu::start_el()
48
+     * @since 3.0.0
49
+     * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
50
+     *              to match parent class for PHP 8 named parameter support.
51
+     *
52
+     * @global int $_wp_nav_menu_max_depth
53
+     *
54
+     * @param string   $output            Used to append additional content (passed by reference).
55
+     * @param WP_Post  $data_object       Menu item data object.
56
+     * @param int      $depth             Depth of menu item. Used for padding.
57
+     * @param stdClass $args              Not used.
58
+     * @param int      $current_object_id Optional. ID of the current menu item. Default 0.
59
+     */
60
+    public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
61
+        global $_wp_nav_menu_max_depth;
62 62
 
63
-		// Restores the more descriptive, specific name for use within this method.
64
-		$menu_item              = $data_object;
65
-		$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
63
+        // Restores the more descriptive, specific name for use within this method.
64
+        $menu_item              = $data_object;
65
+        $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
66 66
 
67
-		ob_start();
68
-		$item_id      = esc_attr( $menu_item->ID );
69
-		$removed_args = array(
70
-			'action',
71
-			'customlink-tab',
72
-			'edit-menu-item',
73
-			'menu-item',
74
-			'page-tab',
75
-			'_wpnonce',
76
-		);
67
+        ob_start();
68
+        $item_id      = esc_attr( $menu_item->ID );
69
+        $removed_args = array(
70
+            'action',
71
+            'customlink-tab',
72
+            'edit-menu-item',
73
+            'menu-item',
74
+            'page-tab',
75
+            '_wpnonce',
76
+        );
77 77
 
78
-		$original_title = false;
78
+        $original_title = false;
79 79
 
80
-		if ( 'taxonomy' === $menu_item->type ) {
81
-			$original_object = get_term( (int) $menu_item->object_id, $menu_item->object );
82
-			if ( $original_object && ! is_wp_error( $original_object ) ) {
83
-				$original_title = $original_object->name;
84
-			}
85
-		} elseif ( 'post_type' === $menu_item->type ) {
86
-			$original_object = get_post( $menu_item->object_id );
87
-			if ( $original_object ) {
88
-				$original_title = get_the_title( $original_object->ID );
89
-			}
90
-		} elseif ( 'post_type_archive' === $menu_item->type ) {
91
-			$original_object = get_post_type_object( $menu_item->object );
92
-			if ( $original_object ) {
93
-				$original_title = $original_object->labels->archives;
94
-			}
95
-		}
80
+        if ( 'taxonomy' === $menu_item->type ) {
81
+            $original_object = get_term( (int) $menu_item->object_id, $menu_item->object );
82
+            if ( $original_object && ! is_wp_error( $original_object ) ) {
83
+                $original_title = $original_object->name;
84
+            }
85
+        } elseif ( 'post_type' === $menu_item->type ) {
86
+            $original_object = get_post( $menu_item->object_id );
87
+            if ( $original_object ) {
88
+                $original_title = get_the_title( $original_object->ID );
89
+            }
90
+        } elseif ( 'post_type_archive' === $menu_item->type ) {
91
+            $original_object = get_post_type_object( $menu_item->object );
92
+            if ( $original_object ) {
93
+                $original_title = $original_object->labels->archives;
94
+            }
95
+        }
96 96
 
97
-		$classes = array(
98
-			'menu-item menu-item-depth-' . $depth,
99
-			'menu-item-' . esc_attr( $menu_item->object ),
100
-			'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ),
101
-		);
97
+        $classes = array(
98
+            'menu-item menu-item-depth-' . $depth,
99
+            'menu-item-' . esc_attr( $menu_item->object ),
100
+            'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ),
101
+        );
102 102
 
103
-		$title = $menu_item->title;
103
+        $title = $menu_item->title;
104 104
 
105
-		if ( ! empty( $menu_item->_invalid ) ) {
106
-			$classes[] = 'menu-item-invalid';
107
-			/* translators: %s: Title of an invalid menu item. */
108
-			$title = sprintf( __( '%s (Invalid)' ), $menu_item->title );
109
-		} elseif ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) {
110
-			$classes[] = 'pending';
111
-			/* translators: %s: Title of a menu item in draft status. */
112
-			$title = sprintf( __( '%s (Pending)' ), $menu_item->title );
113
-		}
105
+        if ( ! empty( $menu_item->_invalid ) ) {
106
+            $classes[] = 'menu-item-invalid';
107
+            /* translators: %s: Title of an invalid menu item. */
108
+            $title = sprintf( __( '%s (Invalid)' ), $menu_item->title );
109
+        } elseif ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) {
110
+            $classes[] = 'pending';
111
+            /* translators: %s: Title of a menu item in draft status. */
112
+            $title = sprintf( __( '%s (Pending)' ), $menu_item->title );
113
+        }
114 114
 
115
-		$title = ( ! isset( $menu_item->label ) || '' === $menu_item->label ) ? $title : $menu_item->label;
115
+        $title = ( ! isset( $menu_item->label ) || '' === $menu_item->label ) ? $title : $menu_item->label;
116 116
 
117
-		$submenu_text = '';
118
-		if ( 0 === $depth ) {
119
-			$submenu_text = 'style="display: none;"';
120
-		}
117
+        $submenu_text = '';
118
+        if ( 0 === $depth ) {
119
+            $submenu_text = 'style="display: none;"';
120
+        }
121 121
 
122
-		?>
122
+        ?>
123 123
 		<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>">
124 124
 			<div class="menu-item-bar">
125 125
 				<div class="menu-item-handle">
@@ -132,59 +132,59 @@  discard block
 block discarded – undo
132 132
 						<span class="item-type"><?php echo esc_html( $menu_item->type_label ); ?></span>
133 133
 						<span class="item-order hide-if-js">
134 134
 							<?php
135
-							printf(
136
-								'<a href="%s" class="item-move-up" aria-label="%s">&#8593;</a>',
137
-								wp_nonce_url(
138
-									add_query_arg(
139
-										array(
140
-											'action'    => 'move-up-menu-item',
141
-											'menu-item' => $item_id,
142
-										),
143
-										remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
144
-									),
145
-									'move-menu_item'
146
-								),
147
-								esc_attr__( 'Move up' )
148
-							);
149
-							?>
135
+                            printf(
136
+                                '<a href="%s" class="item-move-up" aria-label="%s">&#8593;</a>',
137
+                                wp_nonce_url(
138
+                                    add_query_arg(
139
+                                        array(
140
+                                            'action'    => 'move-up-menu-item',
141
+                                            'menu-item' => $item_id,
142
+                                        ),
143
+                                        remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
144
+                                    ),
145
+                                    'move-menu_item'
146
+                                ),
147
+                                esc_attr__( 'Move up' )
148
+                            );
149
+                            ?>
150 150
 							|
151 151
 							<?php
152
-							printf(
153
-								'<a href="%s" class="item-move-down" aria-label="%s">&#8595;</a>',
154
-								wp_nonce_url(
155
-									add_query_arg(
156
-										array(
157
-											'action'    => 'move-down-menu-item',
158
-											'menu-item' => $item_id,
159
-										),
160
-										remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
161
-									),
162
-									'move-menu_item'
163
-								),
164
-								esc_attr__( 'Move down' )
165
-							);
166
-							?>
152
+                            printf(
153
+                                '<a href="%s" class="item-move-down" aria-label="%s">&#8595;</a>',
154
+                                wp_nonce_url(
155
+                                    add_query_arg(
156
+                                        array(
157
+                                            'action'    => 'move-down-menu-item',
158
+                                            'menu-item' => $item_id,
159
+                                        ),
160
+                                        remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
161
+                                    ),
162
+                                    'move-menu_item'
163
+                                ),
164
+                                esc_attr__( 'Move down' )
165
+                            );
166
+                            ?>
167 167
 						</span>
168 168
 						<?php
169
-						if ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) {
170
-							$edit_url = admin_url( 'nav-menus.php' );
171
-						} else {
172
-							$edit_url = add_query_arg(
173
-								array(
174
-									'edit-menu-item' => $item_id,
175
-								),
176
-								remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) )
177
-							);
178
-						}
169
+                        if ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) {
170
+                            $edit_url = admin_url( 'nav-menus.php' );
171
+                        } else {
172
+                            $edit_url = add_query_arg(
173
+                                array(
174
+                                    'edit-menu-item' => $item_id,
175
+                                ),
176
+                                remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) )
177
+                            );
178
+                        }
179 179
 
180
-						printf(
181
-							'<a class="item-edit" id="edit-%s" href="%s" aria-label="%s"><span class="screen-reader-text">%s</span></a>',
182
-							$item_id,
183
-							$edit_url,
184
-							esc_attr__( 'Edit menu item' ),
185
-							__( 'Edit' )
186
-						);
187
-						?>
180
+                        printf(
181
+                            '<a class="item-edit" id="edit-%s" href="%s" aria-label="%s"><span class="screen-reader-text">%s</span></a>',
182
+                            $item_id,
183
+                            $edit_url,
184
+                            esc_attr__( 'Edit menu item' ),
185
+                            __( 'Edit' )
186
+                        );
187
+                        ?>
188 188
 					</span>
189 189
 				</div>
190 190
 			</div>
@@ -237,19 +237,19 @@  discard block
 block discarded – undo
237 237
 				</p>
238 238
 
239 239
 				<?php
240
-				/**
241
-				 * Fires just before the move buttons of a nav menu item in the menu editor.
242
-				 *
243
-				 * @since 5.4.0
244
-				 *
245
-				 * @param string        $item_id           Menu item ID as a numeric string.
246
-				 * @param WP_Post       $menu_item         Menu item data object.
247
-				 * @param int           $depth             Depth of menu item. Used for padding.
248
-				 * @param stdClass|null $args              An object of menu item arguments.
249
-				 * @param int           $current_object_id Nav menu ID.
250
-				 */
251
-				do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id );
252
-				?>
240
+                /**
241
+                 * Fires just before the move buttons of a nav menu item in the menu editor.
242
+                 *
243
+                 * @since 5.4.0
244
+                 *
245
+                 * @param string        $item_id           Menu item ID as a numeric string.
246
+                 * @param WP_Post       $menu_item         Menu item data object.
247
+                 * @param int           $depth             Depth of menu item. Used for padding.
248
+                 * @param stdClass|null $args              An object of menu item arguments.
249
+                 * @param int           $current_object_id Nav menu ID.
250
+                 */
251
+                do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id );
252
+                ?>
253 253
 
254 254
 				<fieldset class="field-move hide-if-no-js description description-wide">
255 255
 					<span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move' ); ?></span>
@@ -264,47 +264,47 @@  discard block
 block discarded – undo
264 264
 					<?php if ( 'custom' !== $menu_item->type && false !== $original_title ) : ?>
265 265
 						<p class="link-to-original">
266 266
 							<?php
267
-							/* translators: %s: Link to menu item's original object. */
268
-							printf( __( 'Original: %s' ), '<a href="' . esc_attr( $menu_item->url ) . '">' . esc_html( $original_title ) . '</a>' );
269
-							?>
267
+                            /* translators: %s: Link to menu item's original object. */
268
+                            printf( __( 'Original: %s' ), '<a href="' . esc_attr( $menu_item->url ) . '">' . esc_html( $original_title ) . '</a>' );
269
+                            ?>
270 270
 						</p>
271 271
 					<?php endif; ?>
272 272
 
273 273
 					<?php
274
-					printf(
275
-						'<a class="item-delete submitdelete deletion" id="delete-%s" href="%s">%s</a>',
276
-						$item_id,
277
-						wp_nonce_url(
278
-							add_query_arg(
279
-								array(
280
-									'action'    => 'delete-menu-item',
281
-									'menu-item' => $item_id,
282
-								),
283
-								admin_url( 'nav-menus.php' )
284
-							),
285
-							'delete-menu_item_' . $item_id
286
-						),
287
-						__( 'Remove' )
288
-					);
289
-					?>
274
+                    printf(
275
+                        '<a class="item-delete submitdelete deletion" id="delete-%s" href="%s">%s</a>',
276
+                        $item_id,
277
+                        wp_nonce_url(
278
+                            add_query_arg(
279
+                                array(
280
+                                    'action'    => 'delete-menu-item',
281
+                                    'menu-item' => $item_id,
282
+                                ),
283
+                                admin_url( 'nav-menus.php' )
284
+                            ),
285
+                            'delete-menu_item_' . $item_id
286
+                        ),
287
+                        __( 'Remove' )
288
+                    );
289
+                    ?>
290 290
 					<span class="meta-sep hide-if-no-js"> | </span>
291 291
 					<?php
292
-					printf(
293
-						'<a class="item-cancel submitcancel hide-if-no-js" id="cancel-%s" href="%s#menu-item-settings-%s">%s</a>',
294
-						$item_id,
295
-						esc_url(
296
-							add_query_arg(
297
-								array(
298
-									'edit-menu-item' => $item_id,
299
-									'cancel'         => time(),
300
-								),
301
-								admin_url( 'nav-menus.php' )
302
-							)
303
-						),
304
-						$item_id,
305
-						__( 'Cancel' )
306
-					);
307
-					?>
292
+                    printf(
293
+                        '<a class="item-cancel submitcancel hide-if-no-js" id="cancel-%s" href="%s#menu-item-settings-%s">%s</a>',
294
+                        $item_id,
295
+                        esc_url(
296
+                            add_query_arg(
297
+                                array(
298
+                                    'edit-menu-item' => $item_id,
299
+                                    'cancel'         => time(),
300
+                                ),
301
+                                admin_url( 'nav-menus.php' )
302
+                            )
303
+                        ),
304
+                        $item_id,
305
+                        __( 'Cancel' )
306
+                    );
307
+                    ?>
308 308
 				</div>
309 309
 
310 310
 				<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 			</div><!-- .menu-item-settings-->
317 317
 			<ul class="menu-item-transport"></ul>
318 318
 		<?php
319
-		$output .= ob_get_clean();
320
-	}
319
+        $output .= ob_get_clean();
320
+    }
321 321
 
322 322
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-wp-ms-themes-list-table.php 1 patch
Indentation   +995 added lines, -995 removed lines patch added patch discarded remove patch
@@ -17,1007 +17,1007 @@
 block discarded – undo
17 17
  */
18 18
 class WP_MS_Themes_List_Table extends WP_List_Table {
19 19
 
20
-	public $site_id;
21
-	public $is_site_themes;
22
-
23
-	private $has_items;
24
-
25
-	/**
26
-	 * Whether to show the auto-updates UI.
27
-	 *
28
-	 * @since 5.5.0
29
-	 *
30
-	 * @var bool True if auto-updates UI is to be shown, false otherwise.
31
-	 */
32
-	protected $show_autoupdates = true;
33
-
34
-	/**
35
-	 * Constructor.
36
-	 *
37
-	 * @since 3.1.0
38
-	 *
39
-	 * @see WP_List_Table::__construct() for more information on default arguments.
40
-	 *
41
-	 * @global string $status
42
-	 * @global int    $page
43
-	 *
44
-	 * @param array $args An associative array of arguments.
45
-	 */
46
-	public function __construct( $args = array() ) {
47
-		global $status, $page;
48
-
49
-		parent::__construct(
50
-			array(
51
-				'plural' => 'themes',
52
-				'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
53
-			)
54
-		);
55
-
56
-		$status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
57
-		if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken', 'auto-update-enabled', 'auto-update-disabled' ), true ) ) {
58
-			$status = 'all';
59
-		}
60
-
61
-		$page = $this->get_pagenum();
62
-
63
-		$this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false;
64
-
65
-		if ( $this->is_site_themes ) {
66
-			$this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
67
-		}
68
-
69
-		$this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'theme' ) &&
70
-			! $this->is_site_themes && current_user_can( 'update_themes' );
71
-	}
72
-
73
-	/**
74
-	 * @return array
75
-	 */
76
-	protected function get_table_classes() {
77
-		// @todo Remove and add CSS for .themes.
78
-		return array( 'widefat', 'plugins' );
79
-	}
80
-
81
-	/**
82
-	 * @return bool
83
-	 */
84
-	public function ajax_user_can() {
85
-		if ( $this->is_site_themes ) {
86
-			return current_user_can( 'manage_sites' );
87
-		} else {
88
-			return current_user_can( 'manage_network_themes' );
89
-		}
90
-	}
91
-
92
-	/**
93
-	 * @global string $status
94
-	 * @global array $totals
95
-	 * @global int $page
96
-	 * @global string $orderby
97
-	 * @global string $order
98
-	 * @global string $s
99
-	 */
100
-	public function prepare_items() {
101
-		global $status, $totals, $page, $orderby, $order, $s;
102
-
103
-		wp_reset_vars( array( 'orderby', 'order', 's' ) );
104
-
105
-		$themes = array(
106
-			/**
107
-			 * Filters the full array of WP_Theme objects to list in the Multisite
108
-			 * themes list table.
109
-			 *
110
-			 * @since 3.1.0
111
-			 *
112
-			 * @param WP_Theme[] $all Array of WP_Theme objects to display in the list table.
113
-			 */
114
-			'all'      => apply_filters( 'all_themes', wp_get_themes() ),
115
-			'search'   => array(),
116
-			'enabled'  => array(),
117
-			'disabled' => array(),
118
-			'upgrade'  => array(),
119
-			'broken'   => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
120
-		);
121
-
122
-		if ( $this->show_autoupdates ) {
123
-			$auto_updates = (array) get_site_option( 'auto_update_themes', array() );
124
-
125
-			$themes['auto-update-enabled']  = array();
126
-			$themes['auto-update-disabled'] = array();
127
-		}
128
-
129
-		if ( $this->is_site_themes ) {
130
-			$themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
131
-			$allowed_where   = 'site';
132
-		} else {
133
-			$themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
134
-			$allowed_where   = 'network';
135
-		}
136
-
137
-		$current      = get_site_transient( 'update_themes' );
138
-		$maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current;
139
-
140
-		foreach ( (array) $themes['all'] as $key => $theme ) {
141
-			if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
142
-				unset( $themes['all'][ $key ] );
143
-				continue;
144
-			}
145
-
146
-			if ( $maybe_update && isset( $current->response[ $key ] ) ) {
147
-				$themes['all'][ $key ]->update = true;
148
-				$themes['upgrade'][ $key ]     = $themes['all'][ $key ];
149
-			}
150
-
151
-			$filter                    = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
152
-			$themes[ $filter ][ $key ] = $themes['all'][ $key ];
153
-
154
-			$theme_data = array(
155
-				'update_supported' => isset( $theme->update_supported ) ? $theme->update_supported : true,
156
-			);
157
-
158
-			// Extra info if known. array_merge() ensures $theme_data has precedence if keys collide.
159
-			if ( isset( $current->response[ $key ] ) ) {
160
-				$theme_data = array_merge( (array) $current->response[ $key ], $theme_data );
161
-			} elseif ( isset( $current->no_update[ $key ] ) ) {
162
-				$theme_data = array_merge( (array) $current->no_update[ $key ], $theme_data );
163
-			} else {
164
-				$theme_data['update_supported'] = false;
165
-			}
166
-
167
-			$theme->update_supported = $theme_data['update_supported'];
168
-
169
-			/*
20
+    public $site_id;
21
+    public $is_site_themes;
22
+
23
+    private $has_items;
24
+
25
+    /**
26
+     * Whether to show the auto-updates UI.
27
+     *
28
+     * @since 5.5.0
29
+     *
30
+     * @var bool True if auto-updates UI is to be shown, false otherwise.
31
+     */
32
+    protected $show_autoupdates = true;
33
+
34
+    /**
35
+     * Constructor.
36
+     *
37
+     * @since 3.1.0
38
+     *
39
+     * @see WP_List_Table::__construct() for more information on default arguments.
40
+     *
41
+     * @global string $status
42
+     * @global int    $page
43
+     *
44
+     * @param array $args An associative array of arguments.
45
+     */
46
+    public function __construct( $args = array() ) {
47
+        global $status, $page;
48
+
49
+        parent::__construct(
50
+            array(
51
+                'plural' => 'themes',
52
+                'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
53
+            )
54
+        );
55
+
56
+        $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
57
+        if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken', 'auto-update-enabled', 'auto-update-disabled' ), true ) ) {
58
+            $status = 'all';
59
+        }
60
+
61
+        $page = $this->get_pagenum();
62
+
63
+        $this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false;
64
+
65
+        if ( $this->is_site_themes ) {
66
+            $this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
67
+        }
68
+
69
+        $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'theme' ) &&
70
+            ! $this->is_site_themes && current_user_can( 'update_themes' );
71
+    }
72
+
73
+    /**
74
+     * @return array
75
+     */
76
+    protected function get_table_classes() {
77
+        // @todo Remove and add CSS for .themes.
78
+        return array( 'widefat', 'plugins' );
79
+    }
80
+
81
+    /**
82
+     * @return bool
83
+     */
84
+    public function ajax_user_can() {
85
+        if ( $this->is_site_themes ) {
86
+            return current_user_can( 'manage_sites' );
87
+        } else {
88
+            return current_user_can( 'manage_network_themes' );
89
+        }
90
+    }
91
+
92
+    /**
93
+     * @global string $status
94
+     * @global array $totals
95
+     * @global int $page
96
+     * @global string $orderby
97
+     * @global string $order
98
+     * @global string $s
99
+     */
100
+    public function prepare_items() {
101
+        global $status, $totals, $page, $orderby, $order, $s;
102
+
103
+        wp_reset_vars( array( 'orderby', 'order', 's' ) );
104
+
105
+        $themes = array(
106
+            /**
107
+             * Filters the full array of WP_Theme objects to list in the Multisite
108
+             * themes list table.
109
+             *
110
+             * @since 3.1.0
111
+             *
112
+             * @param WP_Theme[] $all Array of WP_Theme objects to display in the list table.
113
+             */
114
+            'all'      => apply_filters( 'all_themes', wp_get_themes() ),
115
+            'search'   => array(),
116
+            'enabled'  => array(),
117
+            'disabled' => array(),
118
+            'upgrade'  => array(),
119
+            'broken'   => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
120
+        );
121
+
122
+        if ( $this->show_autoupdates ) {
123
+            $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
124
+
125
+            $themes['auto-update-enabled']  = array();
126
+            $themes['auto-update-disabled'] = array();
127
+        }
128
+
129
+        if ( $this->is_site_themes ) {
130
+            $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
131
+            $allowed_where   = 'site';
132
+        } else {
133
+            $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
134
+            $allowed_where   = 'network';
135
+        }
136
+
137
+        $current      = get_site_transient( 'update_themes' );
138
+        $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current;
139
+
140
+        foreach ( (array) $themes['all'] as $key => $theme ) {
141
+            if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
142
+                unset( $themes['all'][ $key ] );
143
+                continue;
144
+            }
145
+
146
+            if ( $maybe_update && isset( $current->response[ $key ] ) ) {
147
+                $themes['all'][ $key ]->update = true;
148
+                $themes['upgrade'][ $key ]     = $themes['all'][ $key ];
149
+            }
150
+
151
+            $filter                    = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
152
+            $themes[ $filter ][ $key ] = $themes['all'][ $key ];
153
+
154
+            $theme_data = array(
155
+                'update_supported' => isset( $theme->update_supported ) ? $theme->update_supported : true,
156
+            );
157
+
158
+            // Extra info if known. array_merge() ensures $theme_data has precedence if keys collide.
159
+            if ( isset( $current->response[ $key ] ) ) {
160
+                $theme_data = array_merge( (array) $current->response[ $key ], $theme_data );
161
+            } elseif ( isset( $current->no_update[ $key ] ) ) {
162
+                $theme_data = array_merge( (array) $current->no_update[ $key ], $theme_data );
163
+            } else {
164
+                $theme_data['update_supported'] = false;
165
+            }
166
+
167
+            $theme->update_supported = $theme_data['update_supported'];
168
+
169
+            /*
170 170
 			 * Create the expected payload for the auto_update_theme filter, this is the same data
171 171
 			 * as contained within $updates or $no_updates but used when the Theme is not known.
172 172
 			 */
173
-			$filter_payload = array(
174
-				'theme'        => $key,
175
-				'new_version'  => '',
176
-				'url'          => '',
177
-				'package'      => '',
178
-				'requires'     => '',
179
-				'requires_php' => '',
180
-			);
181
-
182
-			$filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) );
183
-
184
-			$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $filter_payload );
185
-
186
-			if ( ! is_null( $auto_update_forced ) ) {
187
-				$theme->auto_update_forced = $auto_update_forced;
188
-			}
189
-
190
-			if ( $this->show_autoupdates ) {
191
-				$enabled = in_array( $key, $auto_updates, true ) && $theme->update_supported;
192
-				if ( isset( $theme->auto_update_forced ) ) {
193
-					$enabled = (bool) $theme->auto_update_forced;
194
-				}
195
-
196
-				if ( $enabled ) {
197
-					$themes['auto-update-enabled'][ $key ] = $theme;
198
-				} else {
199
-					$themes['auto-update-disabled'][ $key ] = $theme;
200
-				}
201
-			}
202
-		}
203
-
204
-		if ( $s ) {
205
-			$status           = 'search';
206
-			$themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
207
-		}
208
-
209
-		$totals    = array();
210
-		$js_themes = array();
211
-		foreach ( $themes as $type => $list ) {
212
-			$totals[ $type ]    = count( $list );
213
-			$js_themes[ $type ] = array_keys( $list );
214
-		}
215
-
216
-		if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) {
217
-			$status = 'all';
218
-		}
219
-
220
-		$this->items = $themes[ $status ];
221
-		WP_Theme::sort_by_name( $this->items );
222
-
223
-		$this->has_items = ! empty( $themes['all'] );
224
-		$total_this_page = $totals[ $status ];
225
-
226
-		wp_localize_script(
227
-			'updates',
228
-			'_wpUpdatesItemCounts',
229
-			array(
230
-				'themes' => $js_themes,
231
-				'totals' => wp_get_update_data(),
232
-			)
233
-		);
234
-
235
-		if ( $orderby ) {
236
-			$orderby = ucfirst( $orderby );
237
-			$order   = strtoupper( $order );
238
-
239
-			if ( 'Name' === $orderby ) {
240
-				if ( 'ASC' === $order ) {
241
-					$this->items = array_reverse( $this->items );
242
-				}
243
-			} else {
244
-				uasort( $this->items, array( $this, '_order_callback' ) );
245
-			}
246
-		}
247
-
248
-		$start = ( $page - 1 ) * $themes_per_page;
249
-
250
-		if ( $total_this_page > $themes_per_page ) {
251
-			$this->items = array_slice( $this->items, $start, $themes_per_page, true );
252
-		}
253
-
254
-		$this->set_pagination_args(
255
-			array(
256
-				'total_items' => $total_this_page,
257
-				'per_page'    => $themes_per_page,
258
-			)
259
-		);
260
-	}
261
-
262
-	/**
263
-	 * @param WP_Theme $theme
264
-	 * @return bool
265
-	 */
266
-	public function _search_callback( $theme ) {
267
-		static $term = null;
268
-		if ( is_null( $term ) ) {
269
-			$term = wp_unslash( $_REQUEST['s'] );
270
-		}
271
-
272
-		foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
273
-			// Don't mark up; Do translate.
274
-			if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) {
275
-				return true;
276
-			}
277
-		}
278
-
279
-		if ( false !== stripos( $theme->get_stylesheet(), $term ) ) {
280
-			return true;
281
-		}
282
-
283
-		if ( false !== stripos( $theme->get_template(), $term ) ) {
284
-			return true;
285
-		}
286
-
287
-		return false;
288
-	}
289
-
290
-	// Not used by any core columns.
291
-	/**
292
-	 * @global string $orderby
293
-	 * @global string $order
294
-	 * @param array $theme_a
295
-	 * @param array $theme_b
296
-	 * @return int
297
-	 */
298
-	public function _order_callback( $theme_a, $theme_b ) {
299
-		global $orderby, $order;
300
-
301
-		$a = $theme_a[ $orderby ];
302
-		$b = $theme_b[ $orderby ];
303
-
304
-		if ( $a === $b ) {
305
-			return 0;
306
-		}
307
-
308
-		if ( 'DESC' === $order ) {
309
-			return ( $a < $b ) ? 1 : -1;
310
-		} else {
311
-			return ( $a < $b ) ? -1 : 1;
312
-		}
313
-	}
314
-
315
-	/**
316
-	 */
317
-	public function no_items() {
318
-		if ( $this->has_items ) {
319
-			_e( 'No themes found.' );
320
-		} else {
321
-			_e( 'No themes are currently available.' );
322
-		}
323
-	}
324
-
325
-	/**
326
-	 * @return array
327
-	 */
328
-	public function get_columns() {
329
-		$columns = array(
330
-			'cb'          => '<input type="checkbox" />',
331
-			'name'        => __( 'Theme' ),
332
-			'description' => __( 'Description' ),
333
-		);
334
-
335
-		if ( $this->show_autoupdates ) {
336
-			$columns['auto-updates'] = __( 'Automatic Updates' );
337
-		}
338
-
339
-		return $columns;
340
-	}
341
-
342
-	/**
343
-	 * @return array
344
-	 */
345
-	protected function get_sortable_columns() {
346
-		return array(
347
-			'name' => 'name',
348
-		);
349
-	}
350
-
351
-	/**
352
-	 * Gets the name of the primary column.
353
-	 *
354
-	 * @since 4.3.0
355
-	 *
356
-	 * @return string Unalterable name of the primary column name, in this case, 'name'.
357
-	 */
358
-	protected function get_primary_column_name() {
359
-		return 'name';
360
-	}
361
-
362
-	/**
363
-	 * @global array $totals
364
-	 * @global string $status
365
-	 * @return array
366
-	 */
367
-	protected function get_views() {
368
-		global $totals, $status;
369
-
370
-		$status_links = array();
371
-		foreach ( $totals as $type => $count ) {
372
-			if ( ! $count ) {
373
-				continue;
374
-			}
375
-
376
-			switch ( $type ) {
377
-				case 'all':
378
-					/* translators: %s: Number of themes. */
379
-					$text = _nx(
380
-						'All <span class="count">(%s)</span>',
381
-						'All <span class="count">(%s)</span>',
382
-						$count,
383
-						'themes'
384
-					);
385
-					break;
386
-				case 'enabled':
387
-					/* translators: %s: Number of themes. */
388
-					$text = _nx(
389
-						'Enabled <span class="count">(%s)</span>',
390
-						'Enabled <span class="count">(%s)</span>',
391
-						$count,
392
-						'themes'
393
-					);
394
-					break;
395
-				case 'disabled':
396
-					/* translators: %s: Number of themes. */
397
-					$text = _nx(
398
-						'Disabled <span class="count">(%s)</span>',
399
-						'Disabled <span class="count">(%s)</span>',
400
-						$count,
401
-						'themes'
402
-					);
403
-					break;
404
-				case 'upgrade':
405
-					/* translators: %s: Number of themes. */
406
-					$text = _nx(
407
-						'Update Available <span class="count">(%s)</span>',
408
-						'Update Available <span class="count">(%s)</span>',
409
-						$count,
410
-						'themes'
411
-					);
412
-					break;
413
-				case 'broken':
414
-					/* translators: %s: Number of themes. */
415
-					$text = _nx(
416
-						'Broken <span class="count">(%s)</span>',
417
-						'Broken <span class="count">(%s)</span>',
418
-						$count,
419
-						'themes'
420
-					);
421
-					break;
422
-				case 'auto-update-enabled':
423
-					/* translators: %s: Number of themes. */
424
-					$text = _n(
425
-						'Auto-updates Enabled <span class="count">(%s)</span>',
426
-						'Auto-updates Enabled <span class="count">(%s)</span>',
427
-						$count
428
-					);
429
-					break;
430
-				case 'auto-update-disabled':
431
-					/* translators: %s: Number of themes. */
432
-					$text = _n(
433
-						'Auto-updates Disabled <span class="count">(%s)</span>',
434
-						'Auto-updates Disabled <span class="count">(%s)</span>',
435
-						$count
436
-					);
437
-					break;
438
-			}
439
-
440
-			if ( $this->is_site_themes ) {
441
-				$url = 'site-themes.php?id=' . $this->site_id;
442
-			} else {
443
-				$url = 'themes.php';
444
-			}
445
-
446
-			if ( 'search' !== $type ) {
447
-				$status_links[ $type ] = sprintf(
448
-					"<a href='%s'%s>%s</a>",
449
-					esc_url( add_query_arg( 'theme_status', $type, $url ) ),
450
-					( $type === $status ) ? ' class="current" aria-current="page"' : '',
451
-					sprintf( $text, number_format_i18n( $count ) )
452
-				);
453
-			}
454
-		}
455
-
456
-		return $status_links;
457
-	}
458
-
459
-	/**
460
-	 * @global string $status
461
-	 *
462
-	 * @return array
463
-	 */
464
-	protected function get_bulk_actions() {
465
-		global $status;
466
-
467
-		$actions = array();
468
-		if ( 'enabled' !== $status ) {
469
-			$actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
470
-		}
471
-		if ( 'disabled' !== $status ) {
472
-			$actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
473
-		}
474
-		if ( ! $this->is_site_themes ) {
475
-			if ( current_user_can( 'update_themes' ) ) {
476
-				$actions['update-selected'] = __( 'Update' );
477
-			}
478
-			if ( current_user_can( 'delete_themes' ) ) {
479
-				$actions['delete-selected'] = __( 'Delete' );
480
-			}
481
-		}
482
-
483
-		if ( $this->show_autoupdates ) {
484
-			if ( 'auto-update-enabled' !== $status ) {
485
-				$actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' );
486
-			}
487
-
488
-			if ( 'auto-update-disabled' !== $status ) {
489
-				$actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' );
490
-			}
491
-		}
492
-
493
-		return $actions;
494
-	}
495
-
496
-	/**
497
-	 */
498
-	public function display_rows() {
499
-		foreach ( $this->items as $theme ) {
500
-			$this->single_row( $theme );
501
-		}
502
-	}
503
-
504
-	/**
505
-	 * Handles the checkbox column output.
506
-	 *
507
-	 * @since 4.3.0
508
-	 * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support.
509
-	 *
510
-	 * @param WP_Theme $item The current WP_Theme object.
511
-	 */
512
-	public function column_cb( $item ) {
513
-		// Restores the more descriptive, specific name for use within this method.
514
-		$theme       = $item;
515
-		$checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
516
-		?>
173
+            $filter_payload = array(
174
+                'theme'        => $key,
175
+                'new_version'  => '',
176
+                'url'          => '',
177
+                'package'      => '',
178
+                'requires'     => '',
179
+                'requires_php' => '',
180
+            );
181
+
182
+            $filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) );
183
+
184
+            $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $filter_payload );
185
+
186
+            if ( ! is_null( $auto_update_forced ) ) {
187
+                $theme->auto_update_forced = $auto_update_forced;
188
+            }
189
+
190
+            if ( $this->show_autoupdates ) {
191
+                $enabled = in_array( $key, $auto_updates, true ) && $theme->update_supported;
192
+                if ( isset( $theme->auto_update_forced ) ) {
193
+                    $enabled = (bool) $theme->auto_update_forced;
194
+                }
195
+
196
+                if ( $enabled ) {
197
+                    $themes['auto-update-enabled'][ $key ] = $theme;
198
+                } else {
199
+                    $themes['auto-update-disabled'][ $key ] = $theme;
200
+                }
201
+            }
202
+        }
203
+
204
+        if ( $s ) {
205
+            $status           = 'search';
206
+            $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
207
+        }
208
+
209
+        $totals    = array();
210
+        $js_themes = array();
211
+        foreach ( $themes as $type => $list ) {
212
+            $totals[ $type ]    = count( $list );
213
+            $js_themes[ $type ] = array_keys( $list );
214
+        }
215
+
216
+        if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) {
217
+            $status = 'all';
218
+        }
219
+
220
+        $this->items = $themes[ $status ];
221
+        WP_Theme::sort_by_name( $this->items );
222
+
223
+        $this->has_items = ! empty( $themes['all'] );
224
+        $total_this_page = $totals[ $status ];
225
+
226
+        wp_localize_script(
227
+            'updates',
228
+            '_wpUpdatesItemCounts',
229
+            array(
230
+                'themes' => $js_themes,
231
+                'totals' => wp_get_update_data(),
232
+            )
233
+        );
234
+
235
+        if ( $orderby ) {
236
+            $orderby = ucfirst( $orderby );
237
+            $order   = strtoupper( $order );
238
+
239
+            if ( 'Name' === $orderby ) {
240
+                if ( 'ASC' === $order ) {
241
+                    $this->items = array_reverse( $this->items );
242
+                }
243
+            } else {
244
+                uasort( $this->items, array( $this, '_order_callback' ) );
245
+            }
246
+        }
247
+
248
+        $start = ( $page - 1 ) * $themes_per_page;
249
+
250
+        if ( $total_this_page > $themes_per_page ) {
251
+            $this->items = array_slice( $this->items, $start, $themes_per_page, true );
252
+        }
253
+
254
+        $this->set_pagination_args(
255
+            array(
256
+                'total_items' => $total_this_page,
257
+                'per_page'    => $themes_per_page,
258
+            )
259
+        );
260
+    }
261
+
262
+    /**
263
+     * @param WP_Theme $theme
264
+     * @return bool
265
+     */
266
+    public function _search_callback( $theme ) {
267
+        static $term = null;
268
+        if ( is_null( $term ) ) {
269
+            $term = wp_unslash( $_REQUEST['s'] );
270
+        }
271
+
272
+        foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
273
+            // Don't mark up; Do translate.
274
+            if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) {
275
+                return true;
276
+            }
277
+        }
278
+
279
+        if ( false !== stripos( $theme->get_stylesheet(), $term ) ) {
280
+            return true;
281
+        }
282
+
283
+        if ( false !== stripos( $theme->get_template(), $term ) ) {
284
+            return true;
285
+        }
286
+
287
+        return false;
288
+    }
289
+
290
+    // Not used by any core columns.
291
+    /**
292
+     * @global string $orderby
293
+     * @global string $order
294
+     * @param array $theme_a
295
+     * @param array $theme_b
296
+     * @return int
297
+     */
298
+    public function _order_callback( $theme_a, $theme_b ) {
299
+        global $orderby, $order;
300
+
301
+        $a = $theme_a[ $orderby ];
302
+        $b = $theme_b[ $orderby ];
303
+
304
+        if ( $a === $b ) {
305
+            return 0;
306
+        }
307
+
308
+        if ( 'DESC' === $order ) {
309
+            return ( $a < $b ) ? 1 : -1;
310
+        } else {
311
+            return ( $a < $b ) ? -1 : 1;
312
+        }
313
+    }
314
+
315
+    /**
316
+     */
317
+    public function no_items() {
318
+        if ( $this->has_items ) {
319
+            _e( 'No themes found.' );
320
+        } else {
321
+            _e( 'No themes are currently available.' );
322
+        }
323
+    }
324
+
325
+    /**
326
+     * @return array
327
+     */
328
+    public function get_columns() {
329
+        $columns = array(
330
+            'cb'          => '<input type="checkbox" />',
331
+            'name'        => __( 'Theme' ),
332
+            'description' => __( 'Description' ),
333
+        );
334
+
335
+        if ( $this->show_autoupdates ) {
336
+            $columns['auto-updates'] = __( 'Automatic Updates' );
337
+        }
338
+
339
+        return $columns;
340
+    }
341
+
342
+    /**
343
+     * @return array
344
+     */
345
+    protected function get_sortable_columns() {
346
+        return array(
347
+            'name' => 'name',
348
+        );
349
+    }
350
+
351
+    /**
352
+     * Gets the name of the primary column.
353
+     *
354
+     * @since 4.3.0
355
+     *
356
+     * @return string Unalterable name of the primary column name, in this case, 'name'.
357
+     */
358
+    protected function get_primary_column_name() {
359
+        return 'name';
360
+    }
361
+
362
+    /**
363
+     * @global array $totals
364
+     * @global string $status
365
+     * @return array
366
+     */
367
+    protected function get_views() {
368
+        global $totals, $status;
369
+
370
+        $status_links = array();
371
+        foreach ( $totals as $type => $count ) {
372
+            if ( ! $count ) {
373
+                continue;
374
+            }
375
+
376
+            switch ( $type ) {
377
+                case 'all':
378
+                    /* translators: %s: Number of themes. */
379
+                    $text = _nx(
380
+                        'All <span class="count">(%s)</span>',
381
+                        'All <span class="count">(%s)</span>',
382
+                        $count,
383
+                        'themes'
384
+                    );
385
+                    break;
386
+                case 'enabled':
387
+                    /* translators: %s: Number of themes. */
388
+                    $text = _nx(
389
+                        'Enabled <span class="count">(%s)</span>',
390
+                        'Enabled <span class="count">(%s)</span>',
391
+                        $count,
392
+                        'themes'
393
+                    );
394
+                    break;
395
+                case 'disabled':
396
+                    /* translators: %s: Number of themes. */
397
+                    $text = _nx(
398
+                        'Disabled <span class="count">(%s)</span>',
399
+                        'Disabled <span class="count">(%s)</span>',
400
+                        $count,
401
+                        'themes'
402
+                    );
403
+                    break;
404
+                case 'upgrade':
405
+                    /* translators: %s: Number of themes. */
406
+                    $text = _nx(
407
+                        'Update Available <span class="count">(%s)</span>',
408
+                        'Update Available <span class="count">(%s)</span>',
409
+                        $count,
410
+                        'themes'
411
+                    );
412
+                    break;
413
+                case 'broken':
414
+                    /* translators: %s: Number of themes. */
415
+                    $text = _nx(
416
+                        'Broken <span class="count">(%s)</span>',
417
+                        'Broken <span class="count">(%s)</span>',
418
+                        $count,
419
+                        'themes'
420
+                    );
421
+                    break;
422
+                case 'auto-update-enabled':
423
+                    /* translators: %s: Number of themes. */
424
+                    $text = _n(
425
+                        'Auto-updates Enabled <span class="count">(%s)</span>',
426
+                        'Auto-updates Enabled <span class="count">(%s)</span>',
427
+                        $count
428
+                    );
429
+                    break;
430
+                case 'auto-update-disabled':
431
+                    /* translators: %s: Number of themes. */
432
+                    $text = _n(
433
+                        'Auto-updates Disabled <span class="count">(%s)</span>',
434
+                        'Auto-updates Disabled <span class="count">(%s)</span>',
435
+                        $count
436
+                    );
437
+                    break;
438
+            }
439
+
440
+            if ( $this->is_site_themes ) {
441
+                $url = 'site-themes.php?id=' . $this->site_id;
442
+            } else {
443
+                $url = 'themes.php';
444
+            }
445
+
446
+            if ( 'search' !== $type ) {
447
+                $status_links[ $type ] = sprintf(
448
+                    "<a href='%s'%s>%s</a>",
449
+                    esc_url( add_query_arg( 'theme_status', $type, $url ) ),
450
+                    ( $type === $status ) ? ' class="current" aria-current="page"' : '',
451
+                    sprintf( $text, number_format_i18n( $count ) )
452
+                );
453
+            }
454
+        }
455
+
456
+        return $status_links;
457
+    }
458
+
459
+    /**
460
+     * @global string $status
461
+     *
462
+     * @return array
463
+     */
464
+    protected function get_bulk_actions() {
465
+        global $status;
466
+
467
+        $actions = array();
468
+        if ( 'enabled' !== $status ) {
469
+            $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
470
+        }
471
+        if ( 'disabled' !== $status ) {
472
+            $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
473
+        }
474
+        if ( ! $this->is_site_themes ) {
475
+            if ( current_user_can( 'update_themes' ) ) {
476
+                $actions['update-selected'] = __( 'Update' );
477
+            }
478
+            if ( current_user_can( 'delete_themes' ) ) {
479
+                $actions['delete-selected'] = __( 'Delete' );
480
+            }
481
+        }
482
+
483
+        if ( $this->show_autoupdates ) {
484
+            if ( 'auto-update-enabled' !== $status ) {
485
+                $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' );
486
+            }
487
+
488
+            if ( 'auto-update-disabled' !== $status ) {
489
+                $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' );
490
+            }
491
+        }
492
+
493
+        return $actions;
494
+    }
495
+
496
+    /**
497
+     */
498
+    public function display_rows() {
499
+        foreach ( $this->items as $theme ) {
500
+            $this->single_row( $theme );
501
+        }
502
+    }
503
+
504
+    /**
505
+     * Handles the checkbox column output.
506
+     *
507
+     * @since 4.3.0
508
+     * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support.
509
+     *
510
+     * @param WP_Theme $item The current WP_Theme object.
511
+     */
512
+    public function column_cb( $item ) {
513
+        // Restores the more descriptive, specific name for use within this method.
514
+        $theme       = $item;
515
+        $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
516
+        ?>
517 517
 		<input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" id="<?php echo $checkbox_id; ?>" />
518 518
 		<label class="screen-reader-text" for="<?php echo $checkbox_id; ?>" ><?php _e( 'Select' ); ?>  <?php echo $theme->display( 'Name' ); ?></label>
519 519
 		<?php
520
-	}
521
-
522
-	/**
523
-	 * Handles the name column output.
524
-	 *
525
-	 * @since 4.3.0
526
-	 *
527
-	 * @global string $status
528
-	 * @global int    $page
529
-	 * @global string $s
530
-	 *
531
-	 * @param WP_Theme $theme The current WP_Theme object.
532
-	 */
533
-	public function column_name( $theme ) {
534
-		global $status, $page, $s;
535
-
536
-		$context = $status;
537
-
538
-		if ( $this->is_site_themes ) {
539
-			$url     = "site-themes.php?id={$this->site_id}&amp;";
540
-			$allowed = $theme->is_allowed( 'site', $this->site_id );
541
-		} else {
542
-			$url     = 'themes.php?';
543
-			$allowed = $theme->is_allowed( 'network' );
544
-		}
545
-
546
-		// Pre-order.
547
-		$actions = array(
548
-			'enable'  => '',
549
-			'disable' => '',
550
-			'delete'  => '',
551
-		);
552
-
553
-		$stylesheet = $theme->get_stylesheet();
554
-		$theme_key  = urlencode( $stylesheet );
555
-
556
-		if ( ! $allowed ) {
557
-			if ( ! $theme->errors() ) {
558
-				$url = add_query_arg(
559
-					array(
560
-						'action' => 'enable',
561
-						'theme'  => $theme_key,
562
-						'paged'  => $page,
563
-						's'      => $s,
564
-					),
565
-					$url
566
-				);
567
-
568
-				if ( $this->is_site_themes ) {
569
-					/* translators: %s: Theme name. */
570
-					$aria_label = sprintf( __( 'Enable %s' ), $theme->display( 'Name' ) );
571
-				} else {
572
-					/* translators: %s: Theme name. */
573
-					$aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) );
574
-				}
575
-
576
-				$actions['enable'] = sprintf(
577
-					'<a href="%s" class="edit" aria-label="%s">%s</a>',
578
-					esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ),
579
-					esc_attr( $aria_label ),
580
-					( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) )
581
-				);
582
-			}
583
-		} else {
584
-			$url = add_query_arg(
585
-				array(
586
-					'action' => 'disable',
587
-					'theme'  => $theme_key,
588
-					'paged'  => $page,
589
-					's'      => $s,
590
-				),
591
-				$url
592
-			);
593
-
594
-			if ( $this->is_site_themes ) {
595
-				/* translators: %s: Theme name. */
596
-				$aria_label = sprintf( __( 'Disable %s' ), $theme->display( 'Name' ) );
597
-			} else {
598
-				/* translators: %s: Theme name. */
599
-				$aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) );
600
-			}
601
-
602
-			$actions['disable'] = sprintf(
603
-				'<a href="%s" aria-label="%s">%s</a>',
604
-				esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ),
605
-				esc_attr( $aria_label ),
606
-				( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) )
607
-			);
608
-		}
609
-
610
-		if ( ! $allowed && ! $this->is_site_themes
611
-			&& current_user_can( 'delete_themes' )
612
-			&& get_option( 'stylesheet' ) !== $stylesheet
613
-			&& get_option( 'template' ) !== $stylesheet
614
-		) {
615
-			$url = add_query_arg(
616
-				array(
617
-					'action'       => 'delete-selected',
618
-					'checked[]'    => $theme_key,
619
-					'theme_status' => $context,
620
-					'paged'        => $page,
621
-					's'            => $s,
622
-				),
623
-				'themes.php'
624
-			);
625
-
626
-			/* translators: %s: Theme name. */
627
-			$aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) );
628
-
629
-			$actions['delete'] = sprintf(
630
-				'<a href="%s" class="delete" aria-label="%s">%s</a>',
631
-				esc_url( wp_nonce_url( $url, 'bulk-themes' ) ),
632
-				esc_attr( $aria_label ),
633
-				__( 'Delete' )
634
-			);
635
-		}
636
-		/**
637
-		 * Filters the action links displayed for each theme in the Multisite
638
-		 * themes list table.
639
-		 *
640
-		 * The action links displayed are determined by the theme's status, and
641
-		 * which Multisite themes list table is being displayed - the Network
642
-		 * themes list table (themes.php), which displays all installed themes,
643
-		 * or the Site themes list table (site-themes.php), which displays the
644
-		 * non-network enabled themes when editing a site in the Network admin.
645
-		 *
646
-		 * The default action links for the Network themes list table include
647
-		 * 'Network Enable', 'Network Disable', and 'Delete'.
648
-		 *
649
-		 * The default action links for the Site themes list table include
650
-		 * 'Enable', and 'Disable'.
651
-		 *
652
-		 * @since 2.8.0
653
-		 *
654
-		 * @param string[] $actions An array of action links.
655
-		 * @param WP_Theme $theme   The current WP_Theme object.
656
-		 * @param string   $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
657
-		 */
658
-		$actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
659
-
660
-		/**
661
-		 * Filters the action links of a specific theme in the Multisite themes
662
-		 * list table.
663
-		 *
664
-		 * The dynamic portion of the hook name, `$stylesheet`, refers to the
665
-		 * directory name of the theme, which in most cases is synonymous
666
-		 * with the template name.
667
-		 *
668
-		 * @since 3.1.0
669
-		 *
670
-		 * @param string[] $actions An array of action links.
671
-		 * @param WP_Theme $theme   The current WP_Theme object.
672
-		 * @param string   $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
673
-		 */
674
-		$actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, $context );
675
-
676
-		echo $this->row_actions( $actions, true );
677
-	}
678
-
679
-	/**
680
-	 * Handles the description column output.
681
-	 *
682
-	 * @since 4.3.0
683
-	 *
684
-	 * @global string $status
685
-	 * @global array  $totals
686
-	 *
687
-	 * @param WP_Theme $theme The current WP_Theme object.
688
-	 */
689
-	public function column_description( $theme ) {
690
-		global $status, $totals;
691
-
692
-		if ( $theme->errors() ) {
693
-			$pre = 'broken' === $status ? __( 'Broken Theme:' ) . ' ' : '';
694
-			echo '<p><strong class="error-message">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
695
-		}
696
-
697
-		if ( $this->is_site_themes ) {
698
-			$allowed = $theme->is_allowed( 'site', $this->site_id );
699
-		} else {
700
-			$allowed = $theme->is_allowed( 'network' );
701
-		}
702
-
703
-		$class = ! $allowed ? 'inactive' : 'active';
704
-		if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
705
-			$class .= ' update';
706
-		}
707
-
708
-		echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
520
+    }
521
+
522
+    /**
523
+     * Handles the name column output.
524
+     *
525
+     * @since 4.3.0
526
+     *
527
+     * @global string $status
528
+     * @global int    $page
529
+     * @global string $s
530
+     *
531
+     * @param WP_Theme $theme The current WP_Theme object.
532
+     */
533
+    public function column_name( $theme ) {
534
+        global $status, $page, $s;
535
+
536
+        $context = $status;
537
+
538
+        if ( $this->is_site_themes ) {
539
+            $url     = "site-themes.php?id={$this->site_id}&amp;";
540
+            $allowed = $theme->is_allowed( 'site', $this->site_id );
541
+        } else {
542
+            $url     = 'themes.php?';
543
+            $allowed = $theme->is_allowed( 'network' );
544
+        }
545
+
546
+        // Pre-order.
547
+        $actions = array(
548
+            'enable'  => '',
549
+            'disable' => '',
550
+            'delete'  => '',
551
+        );
552
+
553
+        $stylesheet = $theme->get_stylesheet();
554
+        $theme_key  = urlencode( $stylesheet );
555
+
556
+        if ( ! $allowed ) {
557
+            if ( ! $theme->errors() ) {
558
+                $url = add_query_arg(
559
+                    array(
560
+                        'action' => 'enable',
561
+                        'theme'  => $theme_key,
562
+                        'paged'  => $page,
563
+                        's'      => $s,
564
+                    ),
565
+                    $url
566
+                );
567
+
568
+                if ( $this->is_site_themes ) {
569
+                    /* translators: %s: Theme name. */
570
+                    $aria_label = sprintf( __( 'Enable %s' ), $theme->display( 'Name' ) );
571
+                } else {
572
+                    /* translators: %s: Theme name. */
573
+                    $aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) );
574
+                }
575
+
576
+                $actions['enable'] = sprintf(
577
+                    '<a href="%s" class="edit" aria-label="%s">%s</a>',
578
+                    esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ),
579
+                    esc_attr( $aria_label ),
580
+                    ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) )
581
+                );
582
+            }
583
+        } else {
584
+            $url = add_query_arg(
585
+                array(
586
+                    'action' => 'disable',
587
+                    'theme'  => $theme_key,
588
+                    'paged'  => $page,
589
+                    's'      => $s,
590
+                ),
591
+                $url
592
+            );
593
+
594
+            if ( $this->is_site_themes ) {
595
+                /* translators: %s: Theme name. */
596
+                $aria_label = sprintf( __( 'Disable %s' ), $theme->display( 'Name' ) );
597
+            } else {
598
+                /* translators: %s: Theme name. */
599
+                $aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) );
600
+            }
601
+
602
+            $actions['disable'] = sprintf(
603
+                '<a href="%s" aria-label="%s">%s</a>',
604
+                esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ),
605
+                esc_attr( $aria_label ),
606
+                ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) )
607
+            );
608
+        }
609
+
610
+        if ( ! $allowed && ! $this->is_site_themes
611
+            && current_user_can( 'delete_themes' )
612
+            && get_option( 'stylesheet' ) !== $stylesheet
613
+            && get_option( 'template' ) !== $stylesheet
614
+        ) {
615
+            $url = add_query_arg(
616
+                array(
617
+                    'action'       => 'delete-selected',
618
+                    'checked[]'    => $theme_key,
619
+                    'theme_status' => $context,
620
+                    'paged'        => $page,
621
+                    's'            => $s,
622
+                ),
623
+                'themes.php'
624
+            );
625
+
626
+            /* translators: %s: Theme name. */
627
+            $aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) );
628
+
629
+            $actions['delete'] = sprintf(
630
+                '<a href="%s" class="delete" aria-label="%s">%s</a>',
631
+                esc_url( wp_nonce_url( $url, 'bulk-themes' ) ),
632
+                esc_attr( $aria_label ),
633
+                __( 'Delete' )
634
+            );
635
+        }
636
+        /**
637
+         * Filters the action links displayed for each theme in the Multisite
638
+         * themes list table.
639
+         *
640
+         * The action links displayed are determined by the theme's status, and
641
+         * which Multisite themes list table is being displayed - the Network
642
+         * themes list table (themes.php), which displays all installed themes,
643
+         * or the Site themes list table (site-themes.php), which displays the
644
+         * non-network enabled themes when editing a site in the Network admin.
645
+         *
646
+         * The default action links for the Network themes list table include
647
+         * 'Network Enable', 'Network Disable', and 'Delete'.
648
+         *
649
+         * The default action links for the Site themes list table include
650
+         * 'Enable', and 'Disable'.
651
+         *
652
+         * @since 2.8.0
653
+         *
654
+         * @param string[] $actions An array of action links.
655
+         * @param WP_Theme $theme   The current WP_Theme object.
656
+         * @param string   $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
657
+         */
658
+        $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
659
+
660
+        /**
661
+         * Filters the action links of a specific theme in the Multisite themes
662
+         * list table.
663
+         *
664
+         * The dynamic portion of the hook name, `$stylesheet`, refers to the
665
+         * directory name of the theme, which in most cases is synonymous
666
+         * with the template name.
667
+         *
668
+         * @since 3.1.0
669
+         *
670
+         * @param string[] $actions An array of action links.
671
+         * @param WP_Theme $theme   The current WP_Theme object.
672
+         * @param string   $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
673
+         */
674
+        $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, $context );
675
+
676
+        echo $this->row_actions( $actions, true );
677
+    }
678
+
679
+    /**
680
+     * Handles the description column output.
681
+     *
682
+     * @since 4.3.0
683
+     *
684
+     * @global string $status
685
+     * @global array  $totals
686
+     *
687
+     * @param WP_Theme $theme The current WP_Theme object.
688
+     */
689
+    public function column_description( $theme ) {
690
+        global $status, $totals;
691
+
692
+        if ( $theme->errors() ) {
693
+            $pre = 'broken' === $status ? __( 'Broken Theme:' ) . ' ' : '';
694
+            echo '<p><strong class="error-message">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
695
+        }
696
+
697
+        if ( $this->is_site_themes ) {
698
+            $allowed = $theme->is_allowed( 'site', $this->site_id );
699
+        } else {
700
+            $allowed = $theme->is_allowed( 'network' );
701
+        }
702
+
703
+        $class = ! $allowed ? 'inactive' : 'active';
704
+        if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
705
+            $class .= ' update';
706
+        }
707
+
708
+        echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
709 709
 			<div class='$class second theme-version-author-uri'>";
710 710
 
711
-		$stylesheet = $theme->get_stylesheet();
712
-		$theme_meta = array();
713
-
714
-		if ( $theme->get( 'Version' ) ) {
715
-			/* translators: %s: Theme version. */
716
-			$theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) );
717
-		}
718
-
719
-		/* translators: %s: Theme author. */
720
-		$theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) );
721
-
722
-		if ( $theme->get( 'ThemeURI' ) ) {
723
-			/* translators: %s: Theme name. */
724
-			$aria_label = sprintf( __( 'Visit theme site for %s' ), $theme->display( 'Name' ) );
725
-
726
-			$theme_meta[] = sprintf(
727
-				'<a href="%s" aria-label="%s">%s</a>',
728
-				$theme->display( 'ThemeURI' ),
729
-				esc_attr( $aria_label ),
730
-				__( 'Visit Theme Site' )
731
-			);
732
-		}
733
-
734
-		if ( $theme->parent() ) {
735
-			$theme_meta[] = sprintf(
736
-				/* translators: %s: Theme name. */
737
-				__( 'Child theme of %s' ),
738
-				'<strong>' . $theme->parent()->display( 'Name' ) . '</strong>'
739
-			);
740
-		}
741
-
742
-		/**
743
-		 * Filters the array of row meta for each theme in the Multisite themes
744
-		 * list table.
745
-		 *
746
-		 * @since 3.1.0
747
-		 *
748
-		 * @param string[] $theme_meta An array of the theme's metadata, including
749
-		 *                             the version, author, and theme URI.
750
-		 * @param string   $stylesheet Directory name of the theme.
751
-		 * @param WP_Theme $theme      WP_Theme object.
752
-		 * @param string   $status     Status of the theme.
753
-		 */
754
-		$theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
755
-
756
-		echo implode( ' | ', $theme_meta );
757
-
758
-		echo '</div>';
759
-	}
760
-
761
-	/**
762
-	 * Handles the auto-updates column output.
763
-	 *
764
-	 * @since 5.5.0
765
-	 *
766
-	 * @global string $status
767
-	 * @global int  $page
768
-	 *
769
-	 * @param WP_Theme $theme The current WP_Theme object.
770
-	 */
771
-	public function column_autoupdates( $theme ) {
772
-		global $status, $page;
773
-
774
-		static $auto_updates, $available_updates;
775
-
776
-		if ( ! $auto_updates ) {
777
-			$auto_updates = (array) get_site_option( 'auto_update_themes', array() );
778
-		}
779
-		if ( ! $available_updates ) {
780
-			$available_updates = get_site_transient( 'update_themes' );
781
-		}
782
-
783
-		$stylesheet = $theme->get_stylesheet();
784
-
785
-		if ( isset( $theme->auto_update_forced ) ) {
786
-			if ( $theme->auto_update_forced ) {
787
-				// Forced on.
788
-				$text = __( 'Auto-updates enabled' );
789
-			} else {
790
-				$text = __( 'Auto-updates disabled' );
791
-			}
792
-			$action     = 'unavailable';
793
-			$time_class = ' hidden';
794
-		} elseif ( empty( $theme->update_supported ) ) {
795
-			$text       = '';
796
-			$action     = 'unavailable';
797
-			$time_class = ' hidden';
798
-		} elseif ( in_array( $stylesheet, $auto_updates, true ) ) {
799
-			$text       = __( 'Disable auto-updates' );
800
-			$action     = 'disable';
801
-			$time_class = '';
802
-		} else {
803
-			$text       = __( 'Enable auto-updates' );
804
-			$action     = 'enable';
805
-			$time_class = ' hidden';
806
-		}
807
-
808
-		$query_args = array(
809
-			'action'       => "{$action}-auto-update",
810
-			'theme'        => $stylesheet,
811
-			'paged'        => $page,
812
-			'theme_status' => $status,
813
-		);
814
-
815
-		$url = add_query_arg( $query_args, 'themes.php' );
816
-
817
-		if ( 'unavailable' === $action ) {
818
-			$html[] = '<span class="label">' . $text . '</span>';
819
-		} else {
820
-			$html[] = sprintf(
821
-				'<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
822
-				wp_nonce_url( $url, 'updates' ),
823
-				$action
824
-			);
825
-
826
-			$html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
827
-			$html[] = '<span class="label">' . $text . '</span>';
828
-			$html[] = '</a>';
829
-
830
-		}
831
-
832
-		if ( isset( $available_updates->response[ $stylesheet ] ) ) {
833
-			$html[] = sprintf(
834
-				'<div class="auto-update-time%s">%s</div>',
835
-				$time_class,
836
-				wp_get_auto_update_message()
837
-			);
838
-		}
839
-
840
-		$html = implode( '', $html );
841
-
842
-		/**
843
-		 * Filters the HTML of the auto-updates setting for each theme in the Themes list table.
844
-		 *
845
-		 * @since 5.5.0
846
-		 *
847
-		 * @param string   $html       The HTML for theme's auto-update setting, including
848
-		 *                             toggle auto-update action link and time to next update.
849
-		 * @param string   $stylesheet Directory name of the theme.
850
-		 * @param WP_Theme $theme      WP_Theme object.
851
-		 */
852
-		echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme );
853
-
854
-		echo '<div class="notice notice-error notice-alt inline hidden"><p></p></div>';
855
-	}
856
-
857
-	/**
858
-	 * Handles default column output.
859
-	 *
860
-	 * @since 4.3.0
861
-	 * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support.
862
-	 *
863
-	 * @param WP_Theme $item        The current WP_Theme object.
864
-	 * @param string   $column_name The current column name.
865
-	 */
866
-	public function column_default( $item, $column_name ) {
867
-		/**
868
-		 * Fires inside each custom column of the Multisite themes list table.
869
-		 *
870
-		 * @since 3.1.0
871
-		 *
872
-		 * @param string   $column_name Name of the column.
873
-		 * @param string   $stylesheet  Directory name of the theme.
874
-		 * @param WP_Theme $theme       Current WP_Theme object.
875
-		 */
876
-		do_action(
877
-			'manage_themes_custom_column',
878
-			$column_name,
879
-			$item->get_stylesheet(), // Directory name of the theme.
880
-			$item // Theme object.
881
-		);
882
-	}
883
-
884
-	/**
885
-	 * Handles the output for a single table row.
886
-	 *
887
-	 * @since 4.3.0
888
-	 *
889
-	 * @param WP_Theme $item The current WP_Theme object.
890
-	 */
891
-	public function single_row_columns( $item ) {
892
-		list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
893
-
894
-		foreach ( $columns as $column_name => $column_display_name ) {
895
-			$extra_classes = '';
896
-			if ( in_array( $column_name, $hidden, true ) ) {
897
-				$extra_classes .= ' hidden';
898
-			}
899
-
900
-			switch ( $column_name ) {
901
-				case 'cb':
902
-					echo '<th scope="row" class="check-column">';
903
-
904
-					$this->column_cb( $item );
905
-
906
-					echo '</th>';
907
-					break;
908
-
909
-				case 'name':
910
-					$active_theme_label = '';
911
-
912
-					/* The presence of the site_id property means that this is a subsite view and a label for the active theme needs to be added */
913
-					if ( ! empty( $this->site_id ) ) {
914
-						$stylesheet = get_blog_option( $this->site_id, 'stylesheet' );
915
-						$template   = get_blog_option( $this->site_id, 'template' );
916
-
917
-						/* Add a label for the active template */
918
-						if ( $item->get_template() === $template ) {
919
-							$active_theme_label = ' &mdash; ' . __( 'Active Theme' );
920
-						}
921
-
922
-						/* In case this is a child theme, label it properly */
923
-						if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
924
-							$active_theme_label = ' &mdash; ' . __( 'Active Child Theme' );
925
-						}
926
-					}
927
-
928
-					echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display( 'Name' ) . $active_theme_label . '</strong>';
929
-
930
-					$this->column_name( $item );
931
-
932
-					echo '</td>';
933
-					break;
934
-
935
-				case 'description':
936
-					echo "<td class='column-description desc{$extra_classes}'>";
937
-
938
-					$this->column_description( $item );
939
-
940
-					echo '</td>';
941
-					break;
942
-
943
-				case 'auto-updates':
944
-					echo "<td class='column-auto-updates{$extra_classes}'>";
945
-
946
-					$this->column_autoupdates( $item );
947
-
948
-					echo '</td>';
949
-					break;
950
-				default:
951
-					echo "<td class='$column_name column-$column_name{$extra_classes}'>";
952
-
953
-					$this->column_default( $item, $column_name );
954
-
955
-					echo '</td>';
956
-					break;
957
-			}
958
-		}
959
-	}
960
-
961
-	/**
962
-	 * @global string $status
963
-	 * @global array  $totals
964
-	 *
965
-	 * @param WP_Theme $theme
966
-	 */
967
-	public function single_row( $theme ) {
968
-		global $status, $totals;
969
-
970
-		if ( $this->is_site_themes ) {
971
-			$allowed = $theme->is_allowed( 'site', $this->site_id );
972
-		} else {
973
-			$allowed = $theme->is_allowed( 'network' );
974
-		}
975
-
976
-		$stylesheet = $theme->get_stylesheet();
977
-
978
-		$class = ! $allowed ? 'inactive' : 'active';
979
-		if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
980
-			$class .= ' update';
981
-		}
982
-
983
-		printf(
984
-			'<tr class="%s" data-slug="%s">',
985
-			esc_attr( $class ),
986
-			esc_attr( $stylesheet )
987
-		);
988
-
989
-		$this->single_row_columns( $theme );
990
-
991
-		echo '</tr>';
992
-
993
-		if ( $this->is_site_themes ) {
994
-			remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
995
-		}
996
-
997
-		/**
998
-		 * Fires after each row in the Multisite themes list table.
999
-		 *
1000
-		 * @since 3.1.0
1001
-		 *
1002
-		 * @param string   $stylesheet Directory name of the theme.
1003
-		 * @param WP_Theme $theme      Current WP_Theme object.
1004
-		 * @param string   $status     Status of the theme.
1005
-		 */
1006
-		do_action( 'after_theme_row', $stylesheet, $theme, $status );
1007
-
1008
-		/**
1009
-		 * Fires after each specific row in the Multisite themes list table.
1010
-		 *
1011
-		 * The dynamic portion of the hook name, `$stylesheet`, refers to the
1012
-		 * directory name of the theme, most often synonymous with the template
1013
-		 * name of the theme.
1014
-		 *
1015
-		 * @since 3.5.0
1016
-		 *
1017
-		 * @param string   $stylesheet Directory name of the theme.
1018
-		 * @param WP_Theme $theme      Current WP_Theme object.
1019
-		 * @param string   $status     Status of the theme.
1020
-		 */
1021
-		do_action( "after_theme_row_{$stylesheet}", $stylesheet, $theme, $status );
1022
-	}
711
+        $stylesheet = $theme->get_stylesheet();
712
+        $theme_meta = array();
713
+
714
+        if ( $theme->get( 'Version' ) ) {
715
+            /* translators: %s: Theme version. */
716
+            $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) );
717
+        }
718
+
719
+        /* translators: %s: Theme author. */
720
+        $theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) );
721
+
722
+        if ( $theme->get( 'ThemeURI' ) ) {
723
+            /* translators: %s: Theme name. */
724
+            $aria_label = sprintf( __( 'Visit theme site for %s' ), $theme->display( 'Name' ) );
725
+
726
+            $theme_meta[] = sprintf(
727
+                '<a href="%s" aria-label="%s">%s</a>',
728
+                $theme->display( 'ThemeURI' ),
729
+                esc_attr( $aria_label ),
730
+                __( 'Visit Theme Site' )
731
+            );
732
+        }
733
+
734
+        if ( $theme->parent() ) {
735
+            $theme_meta[] = sprintf(
736
+                /* translators: %s: Theme name. */
737
+                __( 'Child theme of %s' ),
738
+                '<strong>' . $theme->parent()->display( 'Name' ) . '</strong>'
739
+            );
740
+        }
741
+
742
+        /**
743
+         * Filters the array of row meta for each theme in the Multisite themes
744
+         * list table.
745
+         *
746
+         * @since 3.1.0
747
+         *
748
+         * @param string[] $theme_meta An array of the theme's metadata, including
749
+         *                             the version, author, and theme URI.
750
+         * @param string   $stylesheet Directory name of the theme.
751
+         * @param WP_Theme $theme      WP_Theme object.
752
+         * @param string   $status     Status of the theme.
753
+         */
754
+        $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
755
+
756
+        echo implode( ' | ', $theme_meta );
757
+
758
+        echo '</div>';
759
+    }
760
+
761
+    /**
762
+     * Handles the auto-updates column output.
763
+     *
764
+     * @since 5.5.0
765
+     *
766
+     * @global string $status
767
+     * @global int  $page
768
+     *
769
+     * @param WP_Theme $theme The current WP_Theme object.
770
+     */
771
+    public function column_autoupdates( $theme ) {
772
+        global $status, $page;
773
+
774
+        static $auto_updates, $available_updates;
775
+
776
+        if ( ! $auto_updates ) {
777
+            $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
778
+        }
779
+        if ( ! $available_updates ) {
780
+            $available_updates = get_site_transient( 'update_themes' );
781
+        }
782
+
783
+        $stylesheet = $theme->get_stylesheet();
784
+
785
+        if ( isset( $theme->auto_update_forced ) ) {
786
+            if ( $theme->auto_update_forced ) {
787
+                // Forced on.
788
+                $text = __( 'Auto-updates enabled' );
789
+            } else {
790
+                $text = __( 'Auto-updates disabled' );
791
+            }
792
+            $action     = 'unavailable';
793
+            $time_class = ' hidden';
794
+        } elseif ( empty( $theme->update_supported ) ) {
795
+            $text       = '';
796
+            $action     = 'unavailable';
797
+            $time_class = ' hidden';
798
+        } elseif ( in_array( $stylesheet, $auto_updates, true ) ) {
799
+            $text       = __( 'Disable auto-updates' );
800
+            $action     = 'disable';
801
+            $time_class = '';
802
+        } else {
803
+            $text       = __( 'Enable auto-updates' );
804
+            $action     = 'enable';
805
+            $time_class = ' hidden';
806
+        }
807
+
808
+        $query_args = array(
809
+            'action'       => "{$action}-auto-update",
810
+            'theme'        => $stylesheet,
811
+            'paged'        => $page,
812
+            'theme_status' => $status,
813
+        );
814
+
815
+        $url = add_query_arg( $query_args, 'themes.php' );
816
+
817
+        if ( 'unavailable' === $action ) {
818
+            $html[] = '<span class="label">' . $text . '</span>';
819
+        } else {
820
+            $html[] = sprintf(
821
+                '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
822
+                wp_nonce_url( $url, 'updates' ),
823
+                $action
824
+            );
825
+
826
+            $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
827
+            $html[] = '<span class="label">' . $text . '</span>';
828
+            $html[] = '</a>';
829
+
830
+        }
831
+
832
+        if ( isset( $available_updates->response[ $stylesheet ] ) ) {
833
+            $html[] = sprintf(
834
+                '<div class="auto-update-time%s">%s</div>',
835
+                $time_class,
836
+                wp_get_auto_update_message()
837
+            );
838
+        }
839
+
840
+        $html = implode( '', $html );
841
+
842
+        /**
843
+         * Filters the HTML of the auto-updates setting for each theme in the Themes list table.
844
+         *
845
+         * @since 5.5.0
846
+         *
847
+         * @param string   $html       The HTML for theme's auto-update setting, including
848
+         *                             toggle auto-update action link and time to next update.
849
+         * @param string   $stylesheet Directory name of the theme.
850
+         * @param WP_Theme $theme      WP_Theme object.
851
+         */
852
+        echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme );
853
+
854
+        echo '<div class="notice notice-error notice-alt inline hidden"><p></p></div>';
855
+    }
856
+
857
+    /**
858
+     * Handles default column output.
859
+     *
860
+     * @since 4.3.0
861
+     * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support.
862
+     *
863
+     * @param WP_Theme $item        The current WP_Theme object.
864
+     * @param string   $column_name The current column name.
865
+     */
866
+    public function column_default( $item, $column_name ) {
867
+        /**
868
+         * Fires inside each custom column of the Multisite themes list table.
869
+         *
870
+         * @since 3.1.0
871
+         *
872
+         * @param string   $column_name Name of the column.
873
+         * @param string   $stylesheet  Directory name of the theme.
874
+         * @param WP_Theme $theme       Current WP_Theme object.
875
+         */
876
+        do_action(
877
+            'manage_themes_custom_column',
878
+            $column_name,
879
+            $item->get_stylesheet(), // Directory name of the theme.
880
+            $item // Theme object.
881
+        );
882
+    }
883
+
884
+    /**
885
+     * Handles the output for a single table row.
886
+     *
887
+     * @since 4.3.0
888
+     *
889
+     * @param WP_Theme $item The current WP_Theme object.
890
+     */
891
+    public function single_row_columns( $item ) {
892
+        list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
893
+
894
+        foreach ( $columns as $column_name => $column_display_name ) {
895
+            $extra_classes = '';
896
+            if ( in_array( $column_name, $hidden, true ) ) {
897
+                $extra_classes .= ' hidden';
898
+            }
899
+
900
+            switch ( $column_name ) {
901
+                case 'cb':
902
+                    echo '<th scope="row" class="check-column">';
903
+
904
+                    $this->column_cb( $item );
905
+
906
+                    echo '</th>';
907
+                    break;
908
+
909
+                case 'name':
910
+                    $active_theme_label = '';
911
+
912
+                    /* The presence of the site_id property means that this is a subsite view and a label for the active theme needs to be added */
913
+                    if ( ! empty( $this->site_id ) ) {
914
+                        $stylesheet = get_blog_option( $this->site_id, 'stylesheet' );
915
+                        $template   = get_blog_option( $this->site_id, 'template' );
916
+
917
+                        /* Add a label for the active template */
918
+                        if ( $item->get_template() === $template ) {
919
+                            $active_theme_label = ' &mdash; ' . __( 'Active Theme' );
920
+                        }
921
+
922
+                        /* In case this is a child theme, label it properly */
923
+                        if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
924
+                            $active_theme_label = ' &mdash; ' . __( 'Active Child Theme' );
925
+                        }
926
+                    }
927
+
928
+                    echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display( 'Name' ) . $active_theme_label . '</strong>';
929
+
930
+                    $this->column_name( $item );
931
+
932
+                    echo '</td>';
933
+                    break;
934
+
935
+                case 'description':
936
+                    echo "<td class='column-description desc{$extra_classes}'>";
937
+
938
+                    $this->column_description( $item );
939
+
940
+                    echo '</td>';
941
+                    break;
942
+
943
+                case 'auto-updates':
944
+                    echo "<td class='column-auto-updates{$extra_classes}'>";
945
+
946
+                    $this->column_autoupdates( $item );
947
+
948
+                    echo '</td>';
949
+                    break;
950
+                default:
951
+                    echo "<td class='$column_name column-$column_name{$extra_classes}'>";
952
+
953
+                    $this->column_default( $item, $column_name );
954
+
955
+                    echo '</td>';
956
+                    break;
957
+            }
958
+        }
959
+    }
960
+
961
+    /**
962
+     * @global string $status
963
+     * @global array  $totals
964
+     *
965
+     * @param WP_Theme $theme
966
+     */
967
+    public function single_row( $theme ) {
968
+        global $status, $totals;
969
+
970
+        if ( $this->is_site_themes ) {
971
+            $allowed = $theme->is_allowed( 'site', $this->site_id );
972
+        } else {
973
+            $allowed = $theme->is_allowed( 'network' );
974
+        }
975
+
976
+        $stylesheet = $theme->get_stylesheet();
977
+
978
+        $class = ! $allowed ? 'inactive' : 'active';
979
+        if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
980
+            $class .= ' update';
981
+        }
982
+
983
+        printf(
984
+            '<tr class="%s" data-slug="%s">',
985
+            esc_attr( $class ),
986
+            esc_attr( $stylesheet )
987
+        );
988
+
989
+        $this->single_row_columns( $theme );
990
+
991
+        echo '</tr>';
992
+
993
+        if ( $this->is_site_themes ) {
994
+            remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
995
+        }
996
+
997
+        /**
998
+         * Fires after each row in the Multisite themes list table.
999
+         *
1000
+         * @since 3.1.0
1001
+         *
1002
+         * @param string   $stylesheet Directory name of the theme.
1003
+         * @param WP_Theme $theme      Current WP_Theme object.
1004
+         * @param string   $status     Status of the theme.
1005
+         */
1006
+        do_action( 'after_theme_row', $stylesheet, $theme, $status );
1007
+
1008
+        /**
1009
+         * Fires after each specific row in the Multisite themes list table.
1010
+         *
1011
+         * The dynamic portion of the hook name, `$stylesheet`, refers to the
1012
+         * directory name of the theme, most often synonymous with the template
1013
+         * name of the theme.
1014
+         *
1015
+         * @since 3.5.0
1016
+         *
1017
+         * @param string   $stylesheet Directory name of the theme.
1018
+         * @param WP_Theme $theme      Current WP_Theme object.
1019
+         * @param string   $status     Status of the theme.
1020
+         */
1021
+        do_action( "after_theme_row_{$stylesheet}", $stylesheet, $theme, $status );
1022
+    }
1023 1023
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-wp-filesystem-ssh2.php 1 patch
Indentation   +775 added lines, -775 removed lines patch added patch discarded remove patch
@@ -35,779 +35,779 @@
 block discarded – undo
35 35
  */
36 36
 class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
37 37
 
38
-	/**
39
-	 * @since 2.7.0
40
-	 * @var resource
41
-	 */
42
-	public $link = false;
43
-
44
-	/**
45
-	 * @since 2.7.0
46
-	 * @var resource
47
-	 */
48
-	public $sftp_link;
49
-
50
-	/**
51
-	 * @since 2.7.0
52
-	 * @var bool
53
-	 */
54
-	public $keys = false;
55
-
56
-	/**
57
-	 * Constructor.
58
-	 *
59
-	 * @since 2.7.0
60
-	 *
61
-	 * @param array $opt
62
-	 */
63
-	public function __construct( $opt = '' ) {
64
-		$this->method = 'ssh2';
65
-		$this->errors = new WP_Error();
66
-
67
-		// Check if possible to use ssh2 functions.
68
-		if ( ! extension_loaded( 'ssh2' ) ) {
69
-			$this->errors->add( 'no_ssh2_ext', __( 'The ssh2 PHP extension is not available' ) );
70
-			return;
71
-		}
72
-
73
-		// Set defaults:
74
-		if ( empty( $opt['port'] ) ) {
75
-			$this->options['port'] = 22;
76
-		} else {
77
-			$this->options['port'] = $opt['port'];
78
-		}
79
-
80
-		if ( empty( $opt['hostname'] ) ) {
81
-			$this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) );
82
-		} else {
83
-			$this->options['hostname'] = $opt['hostname'];
84
-		}
85
-
86
-		// Check if the options provided are OK.
87
-		if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) {
88
-			$this->options['public_key']  = $opt['public_key'];
89
-			$this->options['private_key'] = $opt['private_key'];
90
-
91
-			$this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa,ssh-ed25519' );
92
-
93
-			$this->keys = true;
94
-		} elseif ( empty( $opt['username'] ) ) {
95
-			$this->errors->add( 'empty_username', __( 'SSH2 username is required' ) );
96
-		}
97
-
98
-		if ( ! empty( $opt['username'] ) ) {
99
-			$this->options['username'] = $opt['username'];
100
-		}
101
-
102
-		if ( empty( $opt['password'] ) ) {
103
-			// Password can be blank if we are using keys.
104
-			if ( ! $this->keys ) {
105
-				$this->errors->add( 'empty_password', __( 'SSH2 password is required' ) );
106
-			}
107
-		} else {
108
-			$this->options['password'] = $opt['password'];
109
-		}
110
-	}
111
-
112
-	/**
113
-	 * Connects filesystem.
114
-	 *
115
-	 * @since 2.7.0
116
-	 *
117
-	 * @return bool True on success, false on failure.
118
-	 */
119
-	public function connect() {
120
-		if ( ! $this->keys ) {
121
-			$this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'] );
122
-		} else {
123
-			$this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'], $this->options['hostkey'] );
124
-		}
125
-
126
-		if ( ! $this->link ) {
127
-			$this->errors->add(
128
-				'connect',
129
-				sprintf(
130
-					/* translators: %s: hostname:port */
131
-					__( 'Failed to connect to SSH2 Server %s' ),
132
-					$this->options['hostname'] . ':' . $this->options['port']
133
-				)
134
-			);
135
-
136
-			return false;
137
-		}
138
-
139
-		if ( ! $this->keys ) {
140
-			if ( ! @ssh2_auth_password( $this->link, $this->options['username'], $this->options['password'] ) ) {
141
-				$this->errors->add(
142
-					'auth',
143
-					sprintf(
144
-						/* translators: %s: Username. */
145
-						__( 'Username/Password incorrect for %s' ),
146
-						$this->options['username']
147
-					)
148
-				);
149
-
150
-				return false;
151
-			}
152
-		} else {
153
-			if ( ! @ssh2_auth_pubkey_file( $this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) {
154
-				$this->errors->add(
155
-					'auth',
156
-					sprintf(
157
-						/* translators: %s: Username. */
158
-						__( 'Public and Private keys incorrect for %s' ),
159
-						$this->options['username']
160
-					)
161
-				);
162
-
163
-				return false;
164
-			}
165
-		}
166
-
167
-		$this->sftp_link = ssh2_sftp( $this->link );
168
-
169
-		if ( ! $this->sftp_link ) {
170
-			$this->errors->add(
171
-				'connect',
172
-				sprintf(
173
-					/* translators: %s: hostname:port */
174
-					__( 'Failed to initialize a SFTP subsystem session with the SSH2 Server %s' ),
175
-					$this->options['hostname'] . ':' . $this->options['port']
176
-				)
177
-			);
178
-
179
-			return false;
180
-		}
181
-
182
-		return true;
183
-	}
184
-
185
-	/**
186
-	 * Gets the ssh2.sftp PHP stream wrapper path to open for the given file.
187
-	 *
188
-	 * This method also works around a PHP bug where the root directory (/) cannot
189
-	 * be opened by PHP functions, causing a false failure. In order to work around
190
-	 * this, the path is converted to /./ which is semantically the same as /
191
-	 * See https://bugs.php.net/bug.php?id=64169 for more details.
192
-	 *
193
-	 * @since 4.4.0
194
-	 *
195
-	 * @param string $path The File/Directory path on the remote server to return
196
-	 * @return string The ssh2.sftp:// wrapped path to use.
197
-	 */
198
-	public function sftp_path( $path ) {
199
-		if ( '/' === $path ) {
200
-			$path = '/./';
201
-		}
202
-
203
-		return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' );
204
-	}
205
-
206
-	/**
207
-	 * @since 2.7.0
208
-	 *
209
-	 * @param string $command
210
-	 * @param bool   $returnbool
211
-	 * @return bool|string True on success, false on failure. String if the command was executed, `$returnbool`
212
-	 *                     is false (default), and data from the resulting stream was retrieved.
213
-	 */
214
-	public function run_command( $command, $returnbool = false ) {
215
-		if ( ! $this->link ) {
216
-			return false;
217
-		}
218
-
219
-		$stream = ssh2_exec( $this->link, $command );
220
-
221
-		if ( ! $stream ) {
222
-			$this->errors->add(
223
-				'command',
224
-				sprintf(
225
-					/* translators: %s: Command. */
226
-					__( 'Unable to perform command: %s' ),
227
-					$command
228
-				)
229
-			);
230
-		} else {
231
-			stream_set_blocking( $stream, true );
232
-			stream_set_timeout( $stream, FS_TIMEOUT );
233
-			$data = stream_get_contents( $stream );
234
-			fclose( $stream );
235
-
236
-			if ( $returnbool ) {
237
-				return ( false === $data ) ? false : '' !== trim( $data );
238
-			} else {
239
-				return $data;
240
-			}
241
-		}
242
-
243
-		return false;
244
-	}
245
-
246
-	/**
247
-	 * Reads entire file into a string.
248
-	 *
249
-	 * @since 2.7.0
250
-	 *
251
-	 * @param string $file Name of the file to read.
252
-	 * @return string|false Read data on success, false if no temporary file could be opened,
253
-	 *                      or if the file couldn't be retrieved.
254
-	 */
255
-	public function get_contents( $file ) {
256
-		return file_get_contents( $this->sftp_path( $file ) );
257
-	}
258
-
259
-	/**
260
-	 * Reads entire file into an array.
261
-	 *
262
-	 * @since 2.7.0
263
-	 *
264
-	 * @param string $file Path to the file.
265
-	 * @return array|false File contents in an array on success, false on failure.
266
-	 */
267
-	public function get_contents_array( $file ) {
268
-		return file( $this->sftp_path( $file ) );
269
-	}
270
-
271
-	/**
272
-	 * Writes a string to a file.
273
-	 *
274
-	 * @since 2.7.0
275
-	 *
276
-	 * @param string    $file     Remote path to the file where to write the data.
277
-	 * @param string    $contents The data to write.
278
-	 * @param int|false $mode     Optional. The file permissions as octal number, usually 0644.
279
-	 *                            Default false.
280
-	 * @return bool True on success, false on failure.
281
-	 */
282
-	public function put_contents( $file, $contents, $mode = false ) {
283
-		$ret = file_put_contents( $this->sftp_path( $file ), $contents );
284
-
285
-		if ( strlen( $contents ) !== $ret ) {
286
-			return false;
287
-		}
288
-
289
-		$this->chmod( $file, $mode );
290
-
291
-		return true;
292
-	}
293
-
294
-	/**
295
-	 * Gets the current working directory.
296
-	 *
297
-	 * @since 2.7.0
298
-	 *
299
-	 * @return string|false The current working directory on success, false on failure.
300
-	 */
301
-	public function cwd() {
302
-		$cwd = ssh2_sftp_realpath( $this->sftp_link, '.' );
303
-
304
-		if ( $cwd ) {
305
-			$cwd = trailingslashit( trim( $cwd ) );
306
-		}
307
-
308
-		return $cwd;
309
-	}
310
-
311
-	/**
312
-	 * Changes current directory.
313
-	 *
314
-	 * @since 2.7.0
315
-	 *
316
-	 * @param string $dir The new current directory.
317
-	 * @return bool True on success, false on failure.
318
-	 */
319
-	public function chdir( $dir ) {
320
-		return $this->run_command( 'cd ' . $dir, true );
321
-	}
322
-
323
-	/**
324
-	 * Changes the file group.
325
-	 *
326
-	 * @since 2.7.0
327
-	 *
328
-	 * @param string     $file      Path to the file.
329
-	 * @param string|int $group     A group name or number.
330
-	 * @param bool       $recursive Optional. If set to true, changes file group recursively.
331
-	 *                              Default false.
332
-	 * @return bool True on success, false on failure.
333
-	 */
334
-	public function chgrp( $file, $group, $recursive = false ) {
335
-		if ( ! $this->exists( $file ) ) {
336
-			return false;
337
-		}
338
-
339
-		if ( ! $recursive || ! $this->is_dir( $file ) ) {
340
-			return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
341
-		}
342
-
343
-		return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
344
-	}
345
-
346
-	/**
347
-	 * Changes filesystem permissions.
348
-	 *
349
-	 * @since 2.7.0
350
-	 *
351
-	 * @param string    $file      Path to the file.
352
-	 * @param int|false $mode      Optional. The permissions as octal number, usually 0644 for files,
353
-	 *                             0755 for directories. Default false.
354
-	 * @param bool      $recursive Optional. If set to true, changes file permissions recursively.
355
-	 *                             Default false.
356
-	 * @return bool True on success, false on failure.
357
-	 */
358
-	public function chmod( $file, $mode = false, $recursive = false ) {
359
-		if ( ! $this->exists( $file ) ) {
360
-			return false;
361
-		}
362
-
363
-		if ( ! $mode ) {
364
-			if ( $this->is_file( $file ) ) {
365
-				$mode = FS_CHMOD_FILE;
366
-			} elseif ( $this->is_dir( $file ) ) {
367
-				$mode = FS_CHMOD_DIR;
368
-			} else {
369
-				return false;
370
-			}
371
-		}
372
-
373
-		if ( ! $recursive || ! $this->is_dir( $file ) ) {
374
-			return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true );
375
-		}
376
-
377
-		return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true );
378
-	}
379
-
380
-	/**
381
-	 * Changes the owner of a file or directory.
382
-	 *
383
-	 * @since 2.7.0
384
-	 *
385
-	 * @param string     $file      Path to the file or directory.
386
-	 * @param string|int $owner     A user name or number.
387
-	 * @param bool       $recursive Optional. If set to true, changes file owner recursively.
388
-	 *                              Default false.
389
-	 * @return bool True on success, false on failure.
390
-	 */
391
-	public function chown( $file, $owner, $recursive = false ) {
392
-		if ( ! $this->exists( $file ) ) {
393
-			return false;
394
-		}
395
-
396
-		if ( ! $recursive || ! $this->is_dir( $file ) ) {
397
-			return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
398
-		}
399
-
400
-		return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
401
-	}
402
-
403
-	/**
404
-	 * Gets the file owner.
405
-	 *
406
-	 * @since 2.7.0
407
-	 *
408
-	 * @param string $file Path to the file.
409
-	 * @return string|false Username of the owner on success, false on failure.
410
-	 */
411
-	public function owner( $file ) {
412
-		$owneruid = @fileowner( $this->sftp_path( $file ) );
413
-
414
-		if ( ! $owneruid ) {
415
-			return false;
416
-		}
417
-
418
-		if ( ! function_exists( 'posix_getpwuid' ) ) {
419
-			return $owneruid;
420
-		}
421
-
422
-		$ownerarray = posix_getpwuid( $owneruid );
423
-
424
-		if ( ! $ownerarray ) {
425
-			return false;
426
-		}
427
-
428
-		return $ownerarray['name'];
429
-	}
430
-
431
-	/**
432
-	 * Gets the permissions of the specified file or filepath in their octal format.
433
-	 *
434
-	 * @since 2.7.0
435
-	 *
436
-	 * @param string $file Path to the file.
437
-	 * @return string Mode of the file (the last 3 digits).
438
-	 */
439
-	public function getchmod( $file ) {
440
-		return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 );
441
-	}
442
-
443
-	/**
444
-	 * Gets the file's group.
445
-	 *
446
-	 * @since 2.7.0
447
-	 *
448
-	 * @param string $file Path to the file.
449
-	 * @return string|false The group on success, false on failure.
450
-	 */
451
-	public function group( $file ) {
452
-		$gid = @filegroup( $this->sftp_path( $file ) );
453
-
454
-		if ( ! $gid ) {
455
-			return false;
456
-		}
457
-
458
-		if ( ! function_exists( 'posix_getgrgid' ) ) {
459
-			return $gid;
460
-		}
461
-
462
-		$grouparray = posix_getgrgid( $gid );
463
-
464
-		if ( ! $grouparray ) {
465
-			return false;
466
-		}
467
-
468
-		return $grouparray['name'];
469
-	}
470
-
471
-	/**
472
-	 * Copies a file.
473
-	 *
474
-	 * @since 2.7.0
475
-	 *
476
-	 * @param string    $source      Path to the source file.
477
-	 * @param string    $destination Path to the destination file.
478
-	 * @param bool      $overwrite   Optional. Whether to overwrite the destination file if it exists.
479
-	 *                               Default false.
480
-	 * @param int|false $mode        Optional. The permissions as octal number, usually 0644 for files,
481
-	 *                               0755 for dirs. Default false.
482
-	 * @return bool True on success, false on failure.
483
-	 */
484
-	public function copy( $source, $destination, $overwrite = false, $mode = false ) {
485
-		if ( ! $overwrite && $this->exists( $destination ) ) {
486
-			return false;
487
-		}
488
-
489
-		$content = $this->get_contents( $source );
490
-
491
-		if ( false === $content ) {
492
-			return false;
493
-		}
494
-
495
-		return $this->put_contents( $destination, $content, $mode );
496
-	}
497
-
498
-	/**
499
-	 * Moves a file.
500
-	 *
501
-	 * @since 2.7.0
502
-	 *
503
-	 * @param string $source      Path to the source file.
504
-	 * @param string $destination Path to the destination file.
505
-	 * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
506
-	 *                            Default false.
507
-	 * @return bool True on success, false on failure.
508
-	 */
509
-	public function move( $source, $destination, $overwrite = false ) {
510
-		if ( $this->exists( $destination ) ) {
511
-			if ( $overwrite ) {
512
-				// We need to remove the destination file before we can rename the source.
513
-				$this->delete( $destination, false, 'f' );
514
-			} else {
515
-				// If we're not overwriting, the rename will fail, so return early.
516
-				return false;
517
-			}
518
-		}
519
-
520
-		return ssh2_sftp_rename( $this->sftp_link, $source, $destination );
521
-	}
522
-
523
-	/**
524
-	 * Deletes a file or directory.
525
-	 *
526
-	 * @since 2.7.0
527
-	 *
528
-	 * @param string       $file      Path to the file or directory.
529
-	 * @param bool         $recursive Optional. If set to true, deletes files and folders recursively.
530
-	 *                                Default false.
531
-	 * @param string|false $type      Type of resource. 'f' for file, 'd' for directory.
532
-	 *                                Default false.
533
-	 * @return bool True on success, false on failure.
534
-	 */
535
-	public function delete( $file, $recursive = false, $type = false ) {
536
-		if ( 'f' === $type || $this->is_file( $file ) ) {
537
-			return ssh2_sftp_unlink( $this->sftp_link, $file );
538
-		}
539
-
540
-		if ( ! $recursive ) {
541
-			return ssh2_sftp_rmdir( $this->sftp_link, $file );
542
-		}
543
-
544
-		$filelist = $this->dirlist( $file );
545
-
546
-		if ( is_array( $filelist ) ) {
547
-			foreach ( $filelist as $filename => $fileinfo ) {
548
-				$this->delete( $file . '/' . $filename, $recursive, $fileinfo['type'] );
549
-			}
550
-		}
551
-
552
-		return ssh2_sftp_rmdir( $this->sftp_link, $file );
553
-	}
554
-
555
-	/**
556
-	 * Checks if a file or directory exists.
557
-	 *
558
-	 * @since 2.7.0
559
-	 *
560
-	 * @param string $file Path to file or directory.
561
-	 * @return bool Whether $file exists or not.
562
-	 */
563
-	public function exists( $file ) {
564
-		return file_exists( $this->sftp_path( $file ) );
565
-	}
566
-
567
-	/**
568
-	 * Checks if resource is a file.
569
-	 *
570
-	 * @since 2.7.0
571
-	 *
572
-	 * @param string $file File path.
573
-	 * @return bool Whether $file is a file.
574
-	 */
575
-	public function is_file( $file ) {
576
-		return is_file( $this->sftp_path( $file ) );
577
-	}
578
-
579
-	/**
580
-	 * Checks if resource is a directory.
581
-	 *
582
-	 * @since 2.7.0
583
-	 *
584
-	 * @param string $path Directory path.
585
-	 * @return bool Whether $path is a directory.
586
-	 */
587
-	public function is_dir( $path ) {
588
-		return is_dir( $this->sftp_path( $path ) );
589
-	}
590
-
591
-	/**
592
-	 * Checks if a file is readable.
593
-	 *
594
-	 * @since 2.7.0
595
-	 *
596
-	 * @param string $file Path to file.
597
-	 * @return bool Whether $file is readable.
598
-	 */
599
-	public function is_readable( $file ) {
600
-		return is_readable( $this->sftp_path( $file ) );
601
-	}
602
-
603
-	/**
604
-	 * Checks if a file or directory is writable.
605
-	 *
606
-	 * @since 2.7.0
607
-	 *
608
-	 * @param string $file Path to file or directory.
609
-	 * @return bool Whether $file is writable.
610
-	 */
611
-	public function is_writable( $file ) {
612
-		// PHP will base its writable checks on system_user === file_owner, not ssh_user === file_owner.
613
-		return true;
614
-	}
615
-
616
-	/**
617
-	 * Gets the file's last access time.
618
-	 *
619
-	 * @since 2.7.0
620
-	 *
621
-	 * @param string $file Path to file.
622
-	 * @return int|false Unix timestamp representing last access time, false on failure.
623
-	 */
624
-	public function atime( $file ) {
625
-		return fileatime( $this->sftp_path( $file ) );
626
-	}
627
-
628
-	/**
629
-	 * Gets the file modification time.
630
-	 *
631
-	 * @since 2.7.0
632
-	 *
633
-	 * @param string $file Path to file.
634
-	 * @return int|false Unix timestamp representing modification time, false on failure.
635
-	 */
636
-	public function mtime( $file ) {
637
-		return filemtime( $this->sftp_path( $file ) );
638
-	}
639
-
640
-	/**
641
-	 * Gets the file size (in bytes).
642
-	 *
643
-	 * @since 2.7.0
644
-	 *
645
-	 * @param string $file Path to file.
646
-	 * @return int|false Size of the file in bytes on success, false on failure.
647
-	 */
648
-	public function size( $file ) {
649
-		return filesize( $this->sftp_path( $file ) );
650
-	}
651
-
652
-	/**
653
-	 * Sets the access and modification times of a file.
654
-	 *
655
-	 * Note: Not implemented.
656
-	 *
657
-	 * @since 2.7.0
658
-	 *
659
-	 * @param string $file  Path to file.
660
-	 * @param int    $time  Optional. Modified time to set for file.
661
-	 *                      Default 0.
662
-	 * @param int    $atime Optional. Access time to set for file.
663
-	 *                      Default 0.
664
-	 */
665
-	public function touch( $file, $time = 0, $atime = 0 ) {
666
-		// Not implemented.
667
-	}
668
-
669
-	/**
670
-	 * Creates a directory.
671
-	 *
672
-	 * @since 2.7.0
673
-	 *
674
-	 * @param string           $path  Path for new directory.
675
-	 * @param int|false        $chmod Optional. The permissions as octal number (or false to skip chmod).
676
-	 *                                Default false.
677
-	 * @param string|int|false $chown Optional. A user name or number (or false to skip chown).
678
-	 *                                Default false.
679
-	 * @param string|int|false $chgrp Optional. A group name or number (or false to skip chgrp).
680
-	 *                                Default false.
681
-	 * @return bool True on success, false on failure.
682
-	 */
683
-	public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
684
-		$path = untrailingslashit( $path );
685
-
686
-		if ( empty( $path ) ) {
687
-			return false;
688
-		}
689
-
690
-		if ( ! $chmod ) {
691
-			$chmod = FS_CHMOD_DIR;
692
-		}
693
-
694
-		if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) {
695
-			return false;
696
-		}
697
-
698
-		// Set directory permissions.
699
-		ssh2_sftp_chmod( $this->sftp_link, $path, $chmod );
700
-
701
-		if ( $chown ) {
702
-			$this->chown( $path, $chown );
703
-		}
704
-
705
-		if ( $chgrp ) {
706
-			$this->chgrp( $path, $chgrp );
707
-		}
708
-
709
-		return true;
710
-	}
711
-
712
-	/**
713
-	 * Deletes a directory.
714
-	 *
715
-	 * @since 2.7.0
716
-	 *
717
-	 * @param string $path      Path to directory.
718
-	 * @param bool   $recursive Optional. Whether to recursively remove files/directories.
719
-	 *                          Default false.
720
-	 * @return bool True on success, false on failure.
721
-	 */
722
-	public function rmdir( $path, $recursive = false ) {
723
-		return $this->delete( $path, $recursive );
724
-	}
725
-
726
-	/**
727
-	 * Gets details for files in a directory or a specific file.
728
-	 *
729
-	 * @since 2.7.0
730
-	 *
731
-	 * @param string $path           Path to directory or file.
732
-	 * @param bool   $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
733
-	 *                               Default true.
734
-	 * @param bool   $recursive      Optional. Whether to recursively include file details in nested directories.
735
-	 *                               Default false.
736
-	 * @return array|false {
737
-	 *     Array of files. False if unable to list directory contents.
738
-	 *
739
-	 *     @type string $name        Name of the file or directory.
740
-	 *     @type string $perms       *nix representation of permissions.
741
-	 *     @type string $permsn      Octal representation of permissions.
742
-	 *     @type string $owner       Owner name or ID.
743
-	 *     @type int    $size        Size of file in bytes.
744
-	 *     @type int    $lastmodunix Last modified unix timestamp.
745
-	 *     @type mixed  $lastmod     Last modified month (3 letter) and day (without leading 0).
746
-	 *     @type int    $time        Last modified time.
747
-	 *     @type string $type        Type of resource. 'f' for file, 'd' for directory.
748
-	 *     @type mixed  $files       If a directory and `$recursive` is true, contains another array of files.
749
-	 * }
750
-	 */
751
-	public function dirlist( $path, $include_hidden = true, $recursive = false ) {
752
-		if ( $this->is_file( $path ) ) {
753
-			$limit_file = basename( $path );
754
-			$path       = dirname( $path );
755
-		} else {
756
-			$limit_file = false;
757
-		}
758
-
759
-		if ( ! $this->is_dir( $path ) || ! $this->is_readable( $path ) ) {
760
-			return false;
761
-		}
762
-
763
-		$ret = array();
764
-		$dir = dir( $this->sftp_path( $path ) );
765
-
766
-		if ( ! $dir ) {
767
-			return false;
768
-		}
769
-
770
-		while ( false !== ( $entry = $dir->read() ) ) {
771
-			$struc         = array();
772
-			$struc['name'] = $entry;
773
-
774
-			if ( '.' === $struc['name'] || '..' === $struc['name'] ) {
775
-				continue; // Do not care about these folders.
776
-			}
777
-
778
-			if ( ! $include_hidden && '.' === $struc['name'][0] ) {
779
-				continue;
780
-			}
781
-
782
-			if ( $limit_file && $struc['name'] !== $limit_file ) {
783
-				continue;
784
-			}
785
-
786
-			$struc['perms']       = $this->gethchmod( $path . '/' . $entry );
787
-			$struc['permsn']      = $this->getnumchmodfromh( $struc['perms'] );
788
-			$struc['number']      = false;
789
-			$struc['owner']       = $this->owner( $path . '/' . $entry );
790
-			$struc['group']       = $this->group( $path . '/' . $entry );
791
-			$struc['size']        = $this->size( $path . '/' . $entry );
792
-			$struc['lastmodunix'] = $this->mtime( $path . '/' . $entry );
793
-			$struc['lastmod']     = gmdate( 'M j', $struc['lastmodunix'] );
794
-			$struc['time']        = gmdate( 'h:i:s', $struc['lastmodunix'] );
795
-			$struc['type']        = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f';
796
-
797
-			if ( 'd' === $struc['type'] ) {
798
-				if ( $recursive ) {
799
-					$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
800
-				} else {
801
-					$struc['files'] = array();
802
-				}
803
-			}
804
-
805
-			$ret[ $struc['name'] ] = $struc;
806
-		}
807
-
808
-		$dir->close();
809
-		unset( $dir );
810
-
811
-		return $ret;
812
-	}
38
+    /**
39
+     * @since 2.7.0
40
+     * @var resource
41
+     */
42
+    public $link = false;
43
+
44
+    /**
45
+     * @since 2.7.0
46
+     * @var resource
47
+     */
48
+    public $sftp_link;
49
+
50
+    /**
51
+     * @since 2.7.0
52
+     * @var bool
53
+     */
54
+    public $keys = false;
55
+
56
+    /**
57
+     * Constructor.
58
+     *
59
+     * @since 2.7.0
60
+     *
61
+     * @param array $opt
62
+     */
63
+    public function __construct( $opt = '' ) {
64
+        $this->method = 'ssh2';
65
+        $this->errors = new WP_Error();
66
+
67
+        // Check if possible to use ssh2 functions.
68
+        if ( ! extension_loaded( 'ssh2' ) ) {
69
+            $this->errors->add( 'no_ssh2_ext', __( 'The ssh2 PHP extension is not available' ) );
70
+            return;
71
+        }
72
+
73
+        // Set defaults:
74
+        if ( empty( $opt['port'] ) ) {
75
+            $this->options['port'] = 22;
76
+        } else {
77
+            $this->options['port'] = $opt['port'];
78
+        }
79
+
80
+        if ( empty( $opt['hostname'] ) ) {
81
+            $this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) );
82
+        } else {
83
+            $this->options['hostname'] = $opt['hostname'];
84
+        }
85
+
86
+        // Check if the options provided are OK.
87
+        if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) {
88
+            $this->options['public_key']  = $opt['public_key'];
89
+            $this->options['private_key'] = $opt['private_key'];
90
+
91
+            $this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa,ssh-ed25519' );
92
+
93
+            $this->keys = true;
94
+        } elseif ( empty( $opt['username'] ) ) {
95
+            $this->errors->add( 'empty_username', __( 'SSH2 username is required' ) );
96
+        }
97
+
98
+        if ( ! empty( $opt['username'] ) ) {
99
+            $this->options['username'] = $opt['username'];
100
+        }
101
+
102
+        if ( empty( $opt['password'] ) ) {
103
+            // Password can be blank if we are using keys.
104
+            if ( ! $this->keys ) {
105
+                $this->errors->add( 'empty_password', __( 'SSH2 password is required' ) );
106
+            }
107
+        } else {
108
+            $this->options['password'] = $opt['password'];
109
+        }
110
+    }
111
+
112
+    /**
113
+     * Connects filesystem.
114
+     *
115
+     * @since 2.7.0
116
+     *
117
+     * @return bool True on success, false on failure.
118
+     */
119
+    public function connect() {
120
+        if ( ! $this->keys ) {
121
+            $this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'] );
122
+        } else {
123
+            $this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'], $this->options['hostkey'] );
124
+        }
125
+
126
+        if ( ! $this->link ) {
127
+            $this->errors->add(
128
+                'connect',
129
+                sprintf(
130
+                    /* translators: %s: hostname:port */
131
+                    __( 'Failed to connect to SSH2 Server %s' ),
132
+                    $this->options['hostname'] . ':' . $this->options['port']
133
+                )
134
+            );
135
+
136
+            return false;
137
+        }
138
+
139
+        if ( ! $this->keys ) {
140
+            if ( ! @ssh2_auth_password( $this->link, $this->options['username'], $this->options['password'] ) ) {
141
+                $this->errors->add(
142
+                    'auth',
143
+                    sprintf(
144
+                        /* translators: %s: Username. */
145
+                        __( 'Username/Password incorrect for %s' ),
146
+                        $this->options['username']
147
+                    )
148
+                );
149
+
150
+                return false;
151
+            }
152
+        } else {
153
+            if ( ! @ssh2_auth_pubkey_file( $this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) {
154
+                $this->errors->add(
155
+                    'auth',
156
+                    sprintf(
157
+                        /* translators: %s: Username. */
158
+                        __( 'Public and Private keys incorrect for %s' ),
159
+                        $this->options['username']
160
+                    )
161
+                );
162
+
163
+                return false;
164
+            }
165
+        }
166
+
167
+        $this->sftp_link = ssh2_sftp( $this->link );
168
+
169
+        if ( ! $this->sftp_link ) {
170
+            $this->errors->add(
171
+                'connect',
172
+                sprintf(
173
+                    /* translators: %s: hostname:port */
174
+                    __( 'Failed to initialize a SFTP subsystem session with the SSH2 Server %s' ),
175
+                    $this->options['hostname'] . ':' . $this->options['port']
176
+                )
177
+            );
178
+
179
+            return false;
180
+        }
181
+
182
+        return true;
183
+    }
184
+
185
+    /**
186
+     * Gets the ssh2.sftp PHP stream wrapper path to open for the given file.
187
+     *
188
+     * This method also works around a PHP bug where the root directory (/) cannot
189
+     * be opened by PHP functions, causing a false failure. In order to work around
190
+     * this, the path is converted to /./ which is semantically the same as /
191
+     * See https://bugs.php.net/bug.php?id=64169 for more details.
192
+     *
193
+     * @since 4.4.0
194
+     *
195
+     * @param string $path The File/Directory path on the remote server to return
196
+     * @return string The ssh2.sftp:// wrapped path to use.
197
+     */
198
+    public function sftp_path( $path ) {
199
+        if ( '/' === $path ) {
200
+            $path = '/./';
201
+        }
202
+
203
+        return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' );
204
+    }
205
+
206
+    /**
207
+     * @since 2.7.0
208
+     *
209
+     * @param string $command
210
+     * @param bool   $returnbool
211
+     * @return bool|string True on success, false on failure. String if the command was executed, `$returnbool`
212
+     *                     is false (default), and data from the resulting stream was retrieved.
213
+     */
214
+    public function run_command( $command, $returnbool = false ) {
215
+        if ( ! $this->link ) {
216
+            return false;
217
+        }
218
+
219
+        $stream = ssh2_exec( $this->link, $command );
220
+
221
+        if ( ! $stream ) {
222
+            $this->errors->add(
223
+                'command',
224
+                sprintf(
225
+                    /* translators: %s: Command. */
226
+                    __( 'Unable to perform command: %s' ),
227
+                    $command
228
+                )
229
+            );
230
+        } else {
231
+            stream_set_blocking( $stream, true );
232
+            stream_set_timeout( $stream, FS_TIMEOUT );
233
+            $data = stream_get_contents( $stream );
234
+            fclose( $stream );
235
+
236
+            if ( $returnbool ) {
237
+                return ( false === $data ) ? false : '' !== trim( $data );
238
+            } else {
239
+                return $data;
240
+            }
241
+        }
242
+
243
+        return false;
244
+    }
245
+
246
+    /**
247
+     * Reads entire file into a string.
248
+     *
249
+     * @since 2.7.0
250
+     *
251
+     * @param string $file Name of the file to read.
252
+     * @return string|false Read data on success, false if no temporary file could be opened,
253
+     *                      or if the file couldn't be retrieved.
254
+     */
255
+    public function get_contents( $file ) {
256
+        return file_get_contents( $this->sftp_path( $file ) );
257
+    }
258
+
259
+    /**
260
+     * Reads entire file into an array.
261
+     *
262
+     * @since 2.7.0
263
+     *
264
+     * @param string $file Path to the file.
265
+     * @return array|false File contents in an array on success, false on failure.
266
+     */
267
+    public function get_contents_array( $file ) {
268
+        return file( $this->sftp_path( $file ) );
269
+    }
270
+
271
+    /**
272
+     * Writes a string to a file.
273
+     *
274
+     * @since 2.7.0
275
+     *
276
+     * @param string    $file     Remote path to the file where to write the data.
277
+     * @param string    $contents The data to write.
278
+     * @param int|false $mode     Optional. The file permissions as octal number, usually 0644.
279
+     *                            Default false.
280
+     * @return bool True on success, false on failure.
281
+     */
282
+    public function put_contents( $file, $contents, $mode = false ) {
283
+        $ret = file_put_contents( $this->sftp_path( $file ), $contents );
284
+
285
+        if ( strlen( $contents ) !== $ret ) {
286
+            return false;
287
+        }
288
+
289
+        $this->chmod( $file, $mode );
290
+
291
+        return true;
292
+    }
293
+
294
+    /**
295
+     * Gets the current working directory.
296
+     *
297
+     * @since 2.7.0
298
+     *
299
+     * @return string|false The current working directory on success, false on failure.
300
+     */
301
+    public function cwd() {
302
+        $cwd = ssh2_sftp_realpath( $this->sftp_link, '.' );
303
+
304
+        if ( $cwd ) {
305
+            $cwd = trailingslashit( trim( $cwd ) );
306
+        }
307
+
308
+        return $cwd;
309
+    }
310
+
311
+    /**
312
+     * Changes current directory.
313
+     *
314
+     * @since 2.7.0
315
+     *
316
+     * @param string $dir The new current directory.
317
+     * @return bool True on success, false on failure.
318
+     */
319
+    public function chdir( $dir ) {
320
+        return $this->run_command( 'cd ' . $dir, true );
321
+    }
322
+
323
+    /**
324
+     * Changes the file group.
325
+     *
326
+     * @since 2.7.0
327
+     *
328
+     * @param string     $file      Path to the file.
329
+     * @param string|int $group     A group name or number.
330
+     * @param bool       $recursive Optional. If set to true, changes file group recursively.
331
+     *                              Default false.
332
+     * @return bool True on success, false on failure.
333
+     */
334
+    public function chgrp( $file, $group, $recursive = false ) {
335
+        if ( ! $this->exists( $file ) ) {
336
+            return false;
337
+        }
338
+
339
+        if ( ! $recursive || ! $this->is_dir( $file ) ) {
340
+            return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
341
+        }
342
+
343
+        return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
344
+    }
345
+
346
+    /**
347
+     * Changes filesystem permissions.
348
+     *
349
+     * @since 2.7.0
350
+     *
351
+     * @param string    $file      Path to the file.
352
+     * @param int|false $mode      Optional. The permissions as octal number, usually 0644 for files,
353
+     *                             0755 for directories. Default false.
354
+     * @param bool      $recursive Optional. If set to true, changes file permissions recursively.
355
+     *                             Default false.
356
+     * @return bool True on success, false on failure.
357
+     */
358
+    public function chmod( $file, $mode = false, $recursive = false ) {
359
+        if ( ! $this->exists( $file ) ) {
360
+            return false;
361
+        }
362
+
363
+        if ( ! $mode ) {
364
+            if ( $this->is_file( $file ) ) {
365
+                $mode = FS_CHMOD_FILE;
366
+            } elseif ( $this->is_dir( $file ) ) {
367
+                $mode = FS_CHMOD_DIR;
368
+            } else {
369
+                return false;
370
+            }
371
+        }
372
+
373
+        if ( ! $recursive || ! $this->is_dir( $file ) ) {
374
+            return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true );
375
+        }
376
+
377
+        return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true );
378
+    }
379
+
380
+    /**
381
+     * Changes the owner of a file or directory.
382
+     *
383
+     * @since 2.7.0
384
+     *
385
+     * @param string     $file      Path to the file or directory.
386
+     * @param string|int $owner     A user name or number.
387
+     * @param bool       $recursive Optional. If set to true, changes file owner recursively.
388
+     *                              Default false.
389
+     * @return bool True on success, false on failure.
390
+     */
391
+    public function chown( $file, $owner, $recursive = false ) {
392
+        if ( ! $this->exists( $file ) ) {
393
+            return false;
394
+        }
395
+
396
+        if ( ! $recursive || ! $this->is_dir( $file ) ) {
397
+            return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
398
+        }
399
+
400
+        return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
401
+    }
402
+
403
+    /**
404
+     * Gets the file owner.
405
+     *
406
+     * @since 2.7.0
407
+     *
408
+     * @param string $file Path to the file.
409
+     * @return string|false Username of the owner on success, false on failure.
410
+     */
411
+    public function owner( $file ) {
412
+        $owneruid = @fileowner( $this->sftp_path( $file ) );
413
+
414
+        if ( ! $owneruid ) {
415
+            return false;
416
+        }
417
+
418
+        if ( ! function_exists( 'posix_getpwuid' ) ) {
419
+            return $owneruid;
420
+        }
421
+
422
+        $ownerarray = posix_getpwuid( $owneruid );
423
+
424
+        if ( ! $ownerarray ) {
425
+            return false;
426
+        }
427
+
428
+        return $ownerarray['name'];
429
+    }
430
+
431
+    /**
432
+     * Gets the permissions of the specified file or filepath in their octal format.
433
+     *
434
+     * @since 2.7.0
435
+     *
436
+     * @param string $file Path to the file.
437
+     * @return string Mode of the file (the last 3 digits).
438
+     */
439
+    public function getchmod( $file ) {
440
+        return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 );
441
+    }
442
+
443
+    /**
444
+     * Gets the file's group.
445
+     *
446
+     * @since 2.7.0
447
+     *
448
+     * @param string $file Path to the file.
449
+     * @return string|false The group on success, false on failure.
450
+     */
451
+    public function group( $file ) {
452
+        $gid = @filegroup( $this->sftp_path( $file ) );
453
+
454
+        if ( ! $gid ) {
455
+            return false;
456
+        }
457
+
458
+        if ( ! function_exists( 'posix_getgrgid' ) ) {
459
+            return $gid;
460
+        }
461
+
462
+        $grouparray = posix_getgrgid( $gid );
463
+
464
+        if ( ! $grouparray ) {
465
+            return false;
466
+        }
467
+
468
+        return $grouparray['name'];
469
+    }
470
+
471
+    /**
472
+     * Copies a file.
473
+     *
474
+     * @since 2.7.0
475
+     *
476
+     * @param string    $source      Path to the source file.
477
+     * @param string    $destination Path to the destination file.
478
+     * @param bool      $overwrite   Optional. Whether to overwrite the destination file if it exists.
479
+     *                               Default false.
480
+     * @param int|false $mode        Optional. The permissions as octal number, usually 0644 for files,
481
+     *                               0755 for dirs. Default false.
482
+     * @return bool True on success, false on failure.
483
+     */
484
+    public function copy( $source, $destination, $overwrite = false, $mode = false ) {
485
+        if ( ! $overwrite && $this->exists( $destination ) ) {
486
+            return false;
487
+        }
488
+
489
+        $content = $this->get_contents( $source );
490
+
491
+        if ( false === $content ) {
492
+            return false;
493
+        }
494
+
495
+        return $this->put_contents( $destination, $content, $mode );
496
+    }
497
+
498
+    /**
499
+     * Moves a file.
500
+     *
501
+     * @since 2.7.0
502
+     *
503
+     * @param string $source      Path to the source file.
504
+     * @param string $destination Path to the destination file.
505
+     * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
506
+     *                            Default false.
507
+     * @return bool True on success, false on failure.
508
+     */
509
+    public function move( $source, $destination, $overwrite = false ) {
510
+        if ( $this->exists( $destination ) ) {
511
+            if ( $overwrite ) {
512
+                // We need to remove the destination file before we can rename the source.
513
+                $this->delete( $destination, false, 'f' );
514
+            } else {
515
+                // If we're not overwriting, the rename will fail, so return early.
516
+                return false;
517
+            }
518
+        }
519
+
520
+        return ssh2_sftp_rename( $this->sftp_link, $source, $destination );
521
+    }
522
+
523
+    /**
524
+     * Deletes a file or directory.
525
+     *
526
+     * @since 2.7.0
527
+     *
528
+     * @param string       $file      Path to the file or directory.
529
+     * @param bool         $recursive Optional. If set to true, deletes files and folders recursively.
530
+     *                                Default false.
531
+     * @param string|false $type      Type of resource. 'f' for file, 'd' for directory.
532
+     *                                Default false.
533
+     * @return bool True on success, false on failure.
534
+     */
535
+    public function delete( $file, $recursive = false, $type = false ) {
536
+        if ( 'f' === $type || $this->is_file( $file ) ) {
537
+            return ssh2_sftp_unlink( $this->sftp_link, $file );
538
+        }
539
+
540
+        if ( ! $recursive ) {
541
+            return ssh2_sftp_rmdir( $this->sftp_link, $file );
542
+        }
543
+
544
+        $filelist = $this->dirlist( $file );
545
+
546
+        if ( is_array( $filelist ) ) {
547
+            foreach ( $filelist as $filename => $fileinfo ) {
548
+                $this->delete( $file . '/' . $filename, $recursive, $fileinfo['type'] );
549
+            }
550
+        }
551
+
552
+        return ssh2_sftp_rmdir( $this->sftp_link, $file );
553
+    }
554
+
555
+    /**
556
+     * Checks if a file or directory exists.
557
+     *
558
+     * @since 2.7.0
559
+     *
560
+     * @param string $file Path to file or directory.
561
+     * @return bool Whether $file exists or not.
562
+     */
563
+    public function exists( $file ) {
564
+        return file_exists( $this->sftp_path( $file ) );
565
+    }
566
+
567
+    /**
568
+     * Checks if resource is a file.
569
+     *
570
+     * @since 2.7.0
571
+     *
572
+     * @param string $file File path.
573
+     * @return bool Whether $file is a file.
574
+     */
575
+    public function is_file( $file ) {
576
+        return is_file( $this->sftp_path( $file ) );
577
+    }
578
+
579
+    /**
580
+     * Checks if resource is a directory.
581
+     *
582
+     * @since 2.7.0
583
+     *
584
+     * @param string $path Directory path.
585
+     * @return bool Whether $path is a directory.
586
+     */
587
+    public function is_dir( $path ) {
588
+        return is_dir( $this->sftp_path( $path ) );
589
+    }
590
+
591
+    /**
592
+     * Checks if a file is readable.
593
+     *
594
+     * @since 2.7.0
595
+     *
596
+     * @param string $file Path to file.
597
+     * @return bool Whether $file is readable.
598
+     */
599
+    public function is_readable( $file ) {
600
+        return is_readable( $this->sftp_path( $file ) );
601
+    }
602
+
603
+    /**
604
+     * Checks if a file or directory is writable.
605
+     *
606
+     * @since 2.7.0
607
+     *
608
+     * @param string $file Path to file or directory.
609
+     * @return bool Whether $file is writable.
610
+     */
611
+    public function is_writable( $file ) {
612
+        // PHP will base its writable checks on system_user === file_owner, not ssh_user === file_owner.
613
+        return true;
614
+    }
615
+
616
+    /**
617
+     * Gets the file's last access time.
618
+     *
619
+     * @since 2.7.0
620
+     *
621
+     * @param string $file Path to file.
622
+     * @return int|false Unix timestamp representing last access time, false on failure.
623
+     */
624
+    public function atime( $file ) {
625
+        return fileatime( $this->sftp_path( $file ) );
626
+    }
627
+
628
+    /**
629
+     * Gets the file modification time.
630
+     *
631
+     * @since 2.7.0
632
+     *
633
+     * @param string $file Path to file.
634
+     * @return int|false Unix timestamp representing modification time, false on failure.
635
+     */
636
+    public function mtime( $file ) {
637
+        return filemtime( $this->sftp_path( $file ) );
638
+    }
639
+
640
+    /**
641
+     * Gets the file size (in bytes).
642
+     *
643
+     * @since 2.7.0
644
+     *
645
+     * @param string $file Path to file.
646
+     * @return int|false Size of the file in bytes on success, false on failure.
647
+     */
648
+    public function size( $file ) {
649
+        return filesize( $this->sftp_path( $file ) );
650
+    }
651
+
652
+    /**
653
+     * Sets the access and modification times of a file.
654
+     *
655
+     * Note: Not implemented.
656
+     *
657
+     * @since 2.7.0
658
+     *
659
+     * @param string $file  Path to file.
660
+     * @param int    $time  Optional. Modified time to set for file.
661
+     *                      Default 0.
662
+     * @param int    $atime Optional. Access time to set for file.
663
+     *                      Default 0.
664
+     */
665
+    public function touch( $file, $time = 0, $atime = 0 ) {
666
+        // Not implemented.
667
+    }
668
+
669
+    /**
670
+     * Creates a directory.
671
+     *
672
+     * @since 2.7.0
673
+     *
674
+     * @param string           $path  Path for new directory.
675
+     * @param int|false        $chmod Optional. The permissions as octal number (or false to skip chmod).
676
+     *                                Default false.
677
+     * @param string|int|false $chown Optional. A user name or number (or false to skip chown).
678
+     *                                Default false.
679
+     * @param string|int|false $chgrp Optional. A group name or number (or false to skip chgrp).
680
+     *                                Default false.
681
+     * @return bool True on success, false on failure.
682
+     */
683
+    public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
684
+        $path = untrailingslashit( $path );
685
+
686
+        if ( empty( $path ) ) {
687
+            return false;
688
+        }
689
+
690
+        if ( ! $chmod ) {
691
+            $chmod = FS_CHMOD_DIR;
692
+        }
693
+
694
+        if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) {
695
+            return false;
696
+        }
697
+
698
+        // Set directory permissions.
699
+        ssh2_sftp_chmod( $this->sftp_link, $path, $chmod );
700
+
701
+        if ( $chown ) {
702
+            $this->chown( $path, $chown );
703
+        }
704
+
705
+        if ( $chgrp ) {
706
+            $this->chgrp( $path, $chgrp );
707
+        }
708
+
709
+        return true;
710
+    }
711
+
712
+    /**
713
+     * Deletes a directory.
714
+     *
715
+     * @since 2.7.0
716
+     *
717
+     * @param string $path      Path to directory.
718
+     * @param bool   $recursive Optional. Whether to recursively remove files/directories.
719
+     *                          Default false.
720
+     * @return bool True on success, false on failure.
721
+     */
722
+    public function rmdir( $path, $recursive = false ) {
723
+        return $this->delete( $path, $recursive );
724
+    }
725
+
726
+    /**
727
+     * Gets details for files in a directory or a specific file.
728
+     *
729
+     * @since 2.7.0
730
+     *
731
+     * @param string $path           Path to directory or file.
732
+     * @param bool   $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
733
+     *                               Default true.
734
+     * @param bool   $recursive      Optional. Whether to recursively include file details in nested directories.
735
+     *                               Default false.
736
+     * @return array|false {
737
+     *     Array of files. False if unable to list directory contents.
738
+     *
739
+     *     @type string $name        Name of the file or directory.
740
+     *     @type string $perms       *nix representation of permissions.
741
+     *     @type string $permsn      Octal representation of permissions.
742
+     *     @type string $owner       Owner name or ID.
743
+     *     @type int    $size        Size of file in bytes.
744
+     *     @type int    $lastmodunix Last modified unix timestamp.
745
+     *     @type mixed  $lastmod     Last modified month (3 letter) and day (without leading 0).
746
+     *     @type int    $time        Last modified time.
747
+     *     @type string $type        Type of resource. 'f' for file, 'd' for directory.
748
+     *     @type mixed  $files       If a directory and `$recursive` is true, contains another array of files.
749
+     * }
750
+     */
751
+    public function dirlist( $path, $include_hidden = true, $recursive = false ) {
752
+        if ( $this->is_file( $path ) ) {
753
+            $limit_file = basename( $path );
754
+            $path       = dirname( $path );
755
+        } else {
756
+            $limit_file = false;
757
+        }
758
+
759
+        if ( ! $this->is_dir( $path ) || ! $this->is_readable( $path ) ) {
760
+            return false;
761
+        }
762
+
763
+        $ret = array();
764
+        $dir = dir( $this->sftp_path( $path ) );
765
+
766
+        if ( ! $dir ) {
767
+            return false;
768
+        }
769
+
770
+        while ( false !== ( $entry = $dir->read() ) ) {
771
+            $struc         = array();
772
+            $struc['name'] = $entry;
773
+
774
+            if ( '.' === $struc['name'] || '..' === $struc['name'] ) {
775
+                continue; // Do not care about these folders.
776
+            }
777
+
778
+            if ( ! $include_hidden && '.' === $struc['name'][0] ) {
779
+                continue;
780
+            }
781
+
782
+            if ( $limit_file && $struc['name'] !== $limit_file ) {
783
+                continue;
784
+            }
785
+
786
+            $struc['perms']       = $this->gethchmod( $path . '/' . $entry );
787
+            $struc['permsn']      = $this->getnumchmodfromh( $struc['perms'] );
788
+            $struc['number']      = false;
789
+            $struc['owner']       = $this->owner( $path . '/' . $entry );
790
+            $struc['group']       = $this->group( $path . '/' . $entry );
791
+            $struc['size']        = $this->size( $path . '/' . $entry );
792
+            $struc['lastmodunix'] = $this->mtime( $path . '/' . $entry );
793
+            $struc['lastmod']     = gmdate( 'M j', $struc['lastmodunix'] );
794
+            $struc['time']        = gmdate( 'h:i:s', $struc['lastmodunix'] );
795
+            $struc['type']        = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f';
796
+
797
+            if ( 'd' === $struc['type'] ) {
798
+                if ( $recursive ) {
799
+                    $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
800
+                } else {
801
+                    $struc['files'] = array();
802
+                }
803
+            }
804
+
805
+            $ret[ $struc['name'] ] = $struc;
806
+        }
807
+
808
+        $dir->close();
809
+        unset( $dir );
810
+
811
+        return $ret;
812
+    }
813 813
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/upgrade.php 1 patch
Indentation   +2574 added lines, -2574 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
 /** Include user installation customization script. */
12 12
 if ( file_exists( WP_CONTENT_DIR . '/install.php' ) ) {
13
-	require WP_CONTENT_DIR . '/install.php';
13
+    require WP_CONTENT_DIR . '/install.php';
14 14
 }
15 15
 
16 16
 /** WordPress Administration API */
@@ -20,456 +20,456 @@  discard block
 block discarded – undo
20 20
 require_once ABSPATH . 'wp-admin/includes/schema.php';
21 21
 
22 22
 if ( ! function_exists( 'wp_install' ) ) :
23
-	/**
24
-	 * Installs the site.
25
-	 *
26
-	 * Runs the required functions to set up and populate the database,
27
-	 * including primary admin user and initial options.
28
-	 *
29
-	 * @since 2.1.0
30
-	 *
31
-	 * @param string $blog_title    Site title.
32
-	 * @param string $user_name     User's username.
33
-	 * @param string $user_email    User's email.
34
-	 * @param bool   $is_public     Whether the site is public.
35
-	 * @param string $deprecated    Optional. Not used.
36
-	 * @param string $user_password Optional. User's chosen password. Default empty (random password).
37
-	 * @param string $language      Optional. Language chosen. Default empty.
38
-	 * @return array {
39
-	 *     Data for the newly installed site.
40
-	 *
41
-	 *     @type string $url              The URL of the site.
42
-	 *     @type int    $user_id          The ID of the site owner.
43
-	 *     @type string $password         The password of the site owner, if their user account didn't already exist.
44
-	 *     @type string $password_message The explanatory message regarding the password.
45
-	 * }
46
-	 */
47
-	function wp_install( $blog_title, $user_name, $user_email, $is_public, $deprecated = '', $user_password = '', $language = '' ) {
48
-		if ( ! empty( $deprecated ) ) {
49
-			_deprecated_argument( __FUNCTION__, '2.6.0' );
50
-		}
51
-
52
-		wp_check_mysql_version();
53
-		wp_cache_flush();
54
-		make_db_current_silent();
55
-		populate_options();
56
-		populate_roles();
57
-
58
-		update_option( 'blogname', $blog_title );
59
-		update_option( 'admin_email', $user_email );
60
-		update_option( 'blog_public', $is_public );
61
-
62
-		// Freshness of site - in the future, this could get more specific about actions taken, perhaps.
63
-		update_option( 'fresh_site', 1 );
64
-
65
-		if ( $language ) {
66
-			update_option( 'WPLANG', $language );
67
-		}
68
-
69
-		$guessurl = wp_guess_url();
70
-
71
-		update_option( 'siteurl', $guessurl );
72
-
73
-		// If not a public site, don't ping.
74
-		if ( ! $is_public ) {
75
-			update_option( 'default_pingback_flag', 0 );
76
-		}
77
-
78
-		/*
23
+    /**
24
+     * Installs the site.
25
+     *
26
+     * Runs the required functions to set up and populate the database,
27
+     * including primary admin user and initial options.
28
+     *
29
+     * @since 2.1.0
30
+     *
31
+     * @param string $blog_title    Site title.
32
+     * @param string $user_name     User's username.
33
+     * @param string $user_email    User's email.
34
+     * @param bool   $is_public     Whether the site is public.
35
+     * @param string $deprecated    Optional. Not used.
36
+     * @param string $user_password Optional. User's chosen password. Default empty (random password).
37
+     * @param string $language      Optional. Language chosen. Default empty.
38
+     * @return array {
39
+     *     Data for the newly installed site.
40
+     *
41
+     *     @type string $url              The URL of the site.
42
+     *     @type int    $user_id          The ID of the site owner.
43
+     *     @type string $password         The password of the site owner, if their user account didn't already exist.
44
+     *     @type string $password_message The explanatory message regarding the password.
45
+     * }
46
+     */
47
+    function wp_install( $blog_title, $user_name, $user_email, $is_public, $deprecated = '', $user_password = '', $language = '' ) {
48
+        if ( ! empty( $deprecated ) ) {
49
+            _deprecated_argument( __FUNCTION__, '2.6.0' );
50
+        }
51
+
52
+        wp_check_mysql_version();
53
+        wp_cache_flush();
54
+        make_db_current_silent();
55
+        populate_options();
56
+        populate_roles();
57
+
58
+        update_option( 'blogname', $blog_title );
59
+        update_option( 'admin_email', $user_email );
60
+        update_option( 'blog_public', $is_public );
61
+
62
+        // Freshness of site - in the future, this could get more specific about actions taken, perhaps.
63
+        update_option( 'fresh_site', 1 );
64
+
65
+        if ( $language ) {
66
+            update_option( 'WPLANG', $language );
67
+        }
68
+
69
+        $guessurl = wp_guess_url();
70
+
71
+        update_option( 'siteurl', $guessurl );
72
+
73
+        // If not a public site, don't ping.
74
+        if ( ! $is_public ) {
75
+            update_option( 'default_pingback_flag', 0 );
76
+        }
77
+
78
+        /*
79 79
 		 * Create default user. If the user already exists, the user tables are
80 80
 		 * being shared among sites. Just set the role in that case.
81 81
 		 */
82
-		$user_id        = username_exists( $user_name );
83
-		$user_password  = trim( $user_password );
84
-		$email_password = false;
85
-		$user_created   = false;
86
-
87
-		if ( ! $user_id && empty( $user_password ) ) {
88
-			$user_password = wp_generate_password( 12, false );
89
-			$message       = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
90
-			$user_id       = wp_create_user( $user_name, $user_password, $user_email );
91
-			update_user_meta( $user_id, 'default_password_nag', true );
92
-			$email_password = true;
93
-			$user_created   = true;
94
-		} elseif ( ! $user_id ) {
95
-			// Password has been provided.
96
-			$message      = '<em>' . __( 'Your chosen password.' ) . '</em>';
97
-			$user_id      = wp_create_user( $user_name, $user_password, $user_email );
98
-			$user_created = true;
99
-		} else {
100
-			$message = __( 'User already exists. Password inherited.' );
101
-		}
102
-
103
-		$user = new WP_User( $user_id );
104
-		$user->set_role( 'administrator' );
105
-
106
-		if ( $user_created ) {
107
-			$user->user_url = $guessurl;
108
-			wp_update_user( $user );
109
-		}
110
-
111
-		wp_install_defaults( $user_id );
112
-
113
-		wp_install_maybe_enable_pretty_permalinks();
114
-
115
-		flush_rewrite_rules();
116
-
117
-		wp_new_blog_notification( $blog_title, $guessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.' ) ) );
118
-
119
-		wp_cache_flush();
120
-
121
-		/**
122
-		 * Fires after a site is fully installed.
123
-		 *
124
-		 * @since 3.9.0
125
-		 *
126
-		 * @param WP_User $user The site owner.
127
-		 */
128
-		do_action( 'wp_install', $user );
129
-
130
-		return array(
131
-			'url'              => $guessurl,
132
-			'user_id'          => $user_id,
133
-			'password'         => $user_password,
134
-			'password_message' => $message,
135
-		);
136
-	}
82
+        $user_id        = username_exists( $user_name );
83
+        $user_password  = trim( $user_password );
84
+        $email_password = false;
85
+        $user_created   = false;
86
+
87
+        if ( ! $user_id && empty( $user_password ) ) {
88
+            $user_password = wp_generate_password( 12, false );
89
+            $message       = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
90
+            $user_id       = wp_create_user( $user_name, $user_password, $user_email );
91
+            update_user_meta( $user_id, 'default_password_nag', true );
92
+            $email_password = true;
93
+            $user_created   = true;
94
+        } elseif ( ! $user_id ) {
95
+            // Password has been provided.
96
+            $message      = '<em>' . __( 'Your chosen password.' ) . '</em>';
97
+            $user_id      = wp_create_user( $user_name, $user_password, $user_email );
98
+            $user_created = true;
99
+        } else {
100
+            $message = __( 'User already exists. Password inherited.' );
101
+        }
102
+
103
+        $user = new WP_User( $user_id );
104
+        $user->set_role( 'administrator' );
105
+
106
+        if ( $user_created ) {
107
+            $user->user_url = $guessurl;
108
+            wp_update_user( $user );
109
+        }
110
+
111
+        wp_install_defaults( $user_id );
112
+
113
+        wp_install_maybe_enable_pretty_permalinks();
114
+
115
+        flush_rewrite_rules();
116
+
117
+        wp_new_blog_notification( $blog_title, $guessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.' ) ) );
118
+
119
+        wp_cache_flush();
120
+
121
+        /**
122
+         * Fires after a site is fully installed.
123
+         *
124
+         * @since 3.9.0
125
+         *
126
+         * @param WP_User $user The site owner.
127
+         */
128
+        do_action( 'wp_install', $user );
129
+
130
+        return array(
131
+            'url'              => $guessurl,
132
+            'user_id'          => $user_id,
133
+            'password'         => $user_password,
134
+            'password_message' => $message,
135
+        );
136
+    }
137 137
 endif;
138 138
 
139 139
 if ( ! function_exists( 'wp_install_defaults' ) ) :
140
-	/**
141
-	 * Creates the initial content for a newly-installed site.
142
-	 *
143
-	 * Adds the default "Uncategorized" category, the first post (with comment),
144
-	 * first page, and default widgets for default theme for the current version.
145
-	 *
146
-	 * @since 2.1.0
147
-	 *
148
-	 * @global wpdb       $wpdb         WordPress database abstraction object.
149
-	 * @global WP_Rewrite $wp_rewrite   WordPress rewrite component.
150
-	 * @global string     $table_prefix
151
-	 *
152
-	 * @param int $user_id User ID.
153
-	 */
154
-	function wp_install_defaults( $user_id ) {
155
-		global $wpdb, $wp_rewrite, $table_prefix;
156
-
157
-		// Default category.
158
-		$cat_name = __( 'Uncategorized' );
159
-		/* translators: Default category slug. */
160
-		$cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
161
-
162
-		if ( global_terms_enabled() ) {
163
-			$cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
164
-			if ( null == $cat_id ) {
165
-				$wpdb->insert(
166
-					$wpdb->sitecategories,
167
-					array(
168
-						'cat_ID'            => 0,
169
-						'cat_name'          => $cat_name,
170
-						'category_nicename' => $cat_slug,
171
-						'last_updated'      => current_time( 'mysql', true ),
172
-					)
173
-				);
174
-				$cat_id = $wpdb->insert_id;
175
-			}
176
-			update_option( 'default_category', $cat_id );
177
-		} else {
178
-			$cat_id = 1;
179
-		}
180
-
181
-		$wpdb->insert(
182
-			$wpdb->terms,
183
-			array(
184
-				'term_id'    => $cat_id,
185
-				'name'       => $cat_name,
186
-				'slug'       => $cat_slug,
187
-				'term_group' => 0,
188
-			)
189
-		);
190
-		$wpdb->insert(
191
-			$wpdb->term_taxonomy,
192
-			array(
193
-				'term_id'     => $cat_id,
194
-				'taxonomy'    => 'category',
195
-				'description' => '',
196
-				'parent'      => 0,
197
-				'count'       => 1,
198
-			)
199
-		);
200
-		$cat_tt_id = $wpdb->insert_id;
201
-
202
-		// First post.
203
-		$now             = current_time( 'mysql' );
204
-		$now_gmt         = current_time( 'mysql', 1 );
205
-		$first_post_guid = get_option( 'home' ) . '/?p=1';
206
-
207
-		if ( is_multisite() ) {
208
-			$first_post = get_site_option( 'first_post' );
209
-
210
-			if ( ! $first_post ) {
211
-				$first_post = "<!-- wp:paragraph -->\n<p>" .
212
-				/* translators: First post content. %s: Site link. */
213
-				__( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ) .
214
-				"</p>\n<!-- /wp:paragraph -->";
215
-			}
216
-
217
-			$first_post = sprintf(
218
-				$first_post,
219
-				sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name )
220
-			);
221
-
222
-			// Back-compat for pre-4.4.
223
-			$first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post );
224
-			$first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post );
225
-		} else {
226
-			$first_post = "<!-- wp:paragraph -->\n<p>" .
227
-			/* translators: First post content. %s: Site link. */
228
-			__( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ) .
229
-			"</p>\n<!-- /wp:paragraph -->";
230
-		}
231
-
232
-		$wpdb->insert(
233
-			$wpdb->posts,
234
-			array(
235
-				'post_author'           => $user_id,
236
-				'post_date'             => $now,
237
-				'post_date_gmt'         => $now_gmt,
238
-				'post_content'          => $first_post,
239
-				'post_excerpt'          => '',
240
-				'post_title'            => __( 'Hello world!' ),
241
-				/* translators: Default post slug. */
242
-				'post_name'             => sanitize_title( _x( 'hello-world', 'Default post slug' ) ),
243
-				'post_modified'         => $now,
244
-				'post_modified_gmt'     => $now_gmt,
245
-				'guid'                  => $first_post_guid,
246
-				'comment_count'         => 1,
247
-				'to_ping'               => '',
248
-				'pinged'                => '',
249
-				'post_content_filtered' => '',
250
-			)
251
-		);
252
-
253
-		if ( is_multisite() ) {
254
-			update_posts_count();
255
-		}
256
-
257
-		$wpdb->insert(
258
-			$wpdb->term_relationships,
259
-			array(
260
-				'term_taxonomy_id' => $cat_tt_id,
261
-				'object_id'        => 1,
262
-			)
263
-		);
264
-
265
-		// Default comment.
266
-		if ( is_multisite() ) {
267
-			$first_comment_author = get_site_option( 'first_comment_author' );
268
-			$first_comment_email  = get_site_option( 'first_comment_email' );
269
-			$first_comment_url    = get_site_option( 'first_comment_url', network_home_url() );
270
-			$first_comment        = get_site_option( 'first_comment' );
271
-		}
272
-
273
-		$first_comment_author = ! empty( $first_comment_author ) ? $first_comment_author : __( 'A WordPress Commenter' );
274
-		$first_comment_email  = ! empty( $first_comment_email ) ? $first_comment_email : '[email protected]';
275
-		$first_comment_url    = ! empty( $first_comment_url ) ? $first_comment_url : esc_url( __( 'https://wordpress.org/' ) );
276
-		$first_comment        = ! empty( $first_comment ) ? $first_comment : sprintf(
277
-			/* translators: %s: Gravatar URL. */
278
-			__(
279
-				'Hi, this is a comment.
140
+    /**
141
+     * Creates the initial content for a newly-installed site.
142
+     *
143
+     * Adds the default "Uncategorized" category, the first post (with comment),
144
+     * first page, and default widgets for default theme for the current version.
145
+     *
146
+     * @since 2.1.0
147
+     *
148
+     * @global wpdb       $wpdb         WordPress database abstraction object.
149
+     * @global WP_Rewrite $wp_rewrite   WordPress rewrite component.
150
+     * @global string     $table_prefix
151
+     *
152
+     * @param int $user_id User ID.
153
+     */
154
+    function wp_install_defaults( $user_id ) {
155
+        global $wpdb, $wp_rewrite, $table_prefix;
156
+
157
+        // Default category.
158
+        $cat_name = __( 'Uncategorized' );
159
+        /* translators: Default category slug. */
160
+        $cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
161
+
162
+        if ( global_terms_enabled() ) {
163
+            $cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
164
+            if ( null == $cat_id ) {
165
+                $wpdb->insert(
166
+                    $wpdb->sitecategories,
167
+                    array(
168
+                        'cat_ID'            => 0,
169
+                        'cat_name'          => $cat_name,
170
+                        'category_nicename' => $cat_slug,
171
+                        'last_updated'      => current_time( 'mysql', true ),
172
+                    )
173
+                );
174
+                $cat_id = $wpdb->insert_id;
175
+            }
176
+            update_option( 'default_category', $cat_id );
177
+        } else {
178
+            $cat_id = 1;
179
+        }
180
+
181
+        $wpdb->insert(
182
+            $wpdb->terms,
183
+            array(
184
+                'term_id'    => $cat_id,
185
+                'name'       => $cat_name,
186
+                'slug'       => $cat_slug,
187
+                'term_group' => 0,
188
+            )
189
+        );
190
+        $wpdb->insert(
191
+            $wpdb->term_taxonomy,
192
+            array(
193
+                'term_id'     => $cat_id,
194
+                'taxonomy'    => 'category',
195
+                'description' => '',
196
+                'parent'      => 0,
197
+                'count'       => 1,
198
+            )
199
+        );
200
+        $cat_tt_id = $wpdb->insert_id;
201
+
202
+        // First post.
203
+        $now             = current_time( 'mysql' );
204
+        $now_gmt         = current_time( 'mysql', 1 );
205
+        $first_post_guid = get_option( 'home' ) . '/?p=1';
206
+
207
+        if ( is_multisite() ) {
208
+            $first_post = get_site_option( 'first_post' );
209
+
210
+            if ( ! $first_post ) {
211
+                $first_post = "<!-- wp:paragraph -->\n<p>" .
212
+                /* translators: First post content. %s: Site link. */
213
+                __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ) .
214
+                "</p>\n<!-- /wp:paragraph -->";
215
+            }
216
+
217
+            $first_post = sprintf(
218
+                $first_post,
219
+                sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name )
220
+            );
221
+
222
+            // Back-compat for pre-4.4.
223
+            $first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post );
224
+            $first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post );
225
+        } else {
226
+            $first_post = "<!-- wp:paragraph -->\n<p>" .
227
+            /* translators: First post content. %s: Site link. */
228
+            __( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ) .
229
+            "</p>\n<!-- /wp:paragraph -->";
230
+        }
231
+
232
+        $wpdb->insert(
233
+            $wpdb->posts,
234
+            array(
235
+                'post_author'           => $user_id,
236
+                'post_date'             => $now,
237
+                'post_date_gmt'         => $now_gmt,
238
+                'post_content'          => $first_post,
239
+                'post_excerpt'          => '',
240
+                'post_title'            => __( 'Hello world!' ),
241
+                /* translators: Default post slug. */
242
+                'post_name'             => sanitize_title( _x( 'hello-world', 'Default post slug' ) ),
243
+                'post_modified'         => $now,
244
+                'post_modified_gmt'     => $now_gmt,
245
+                'guid'                  => $first_post_guid,
246
+                'comment_count'         => 1,
247
+                'to_ping'               => '',
248
+                'pinged'                => '',
249
+                'post_content_filtered' => '',
250
+            )
251
+        );
252
+
253
+        if ( is_multisite() ) {
254
+            update_posts_count();
255
+        }
256
+
257
+        $wpdb->insert(
258
+            $wpdb->term_relationships,
259
+            array(
260
+                'term_taxonomy_id' => $cat_tt_id,
261
+                'object_id'        => 1,
262
+            )
263
+        );
264
+
265
+        // Default comment.
266
+        if ( is_multisite() ) {
267
+            $first_comment_author = get_site_option( 'first_comment_author' );
268
+            $first_comment_email  = get_site_option( 'first_comment_email' );
269
+            $first_comment_url    = get_site_option( 'first_comment_url', network_home_url() );
270
+            $first_comment        = get_site_option( 'first_comment' );
271
+        }
272
+
273
+        $first_comment_author = ! empty( $first_comment_author ) ? $first_comment_author : __( 'A WordPress Commenter' );
274
+        $first_comment_email  = ! empty( $first_comment_email ) ? $first_comment_email : '[email protected]';
275
+        $first_comment_url    = ! empty( $first_comment_url ) ? $first_comment_url : esc_url( __( 'https://wordpress.org/' ) );
276
+        $first_comment        = ! empty( $first_comment ) ? $first_comment : sprintf(
277
+            /* translators: %s: Gravatar URL. */
278
+            __(
279
+                'Hi, this is a comment.
280 280
 To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
281 281
 Commenter avatars come from <a href="%s">Gravatar</a>.'
282
-			),
283
-			esc_url( __( 'https://en.gravatar.com/' ) )
284
-		);
285
-		$wpdb->insert(
286
-			$wpdb->comments,
287
-			array(
288
-				'comment_post_ID'      => 1,
289
-				'comment_author'       => $first_comment_author,
290
-				'comment_author_email' => $first_comment_email,
291
-				'comment_author_url'   => $first_comment_url,
292
-				'comment_date'         => $now,
293
-				'comment_date_gmt'     => $now_gmt,
294
-				'comment_content'      => $first_comment,
295
-				'comment_type'         => 'comment',
296
-			)
297
-		);
298
-
299
-		// First page.
300
-		if ( is_multisite() ) {
301
-			$first_page = get_site_option( 'first_page' );
302
-		}
303
-
304
-		if ( empty( $first_page ) ) {
305
-			$first_page = "<!-- wp:paragraph -->\n<p>";
306
-			/* translators: First page content. */
307
-			$first_page .= __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:" );
308
-			$first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
309
-
310
-			$first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
311
-			/* translators: First page content. */
312
-			$first_page .= __( "Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)" );
313
-			$first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
314
-
315
-			$first_page .= "<!-- wp:paragraph -->\n<p>";
316
-			/* translators: First page content. */
317
-			$first_page .= __( '...or something like this:' );
318
-			$first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
319
-
320
-			$first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
321
-			/* translators: First page content. */
322
-			$first_page .= __( 'The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.' );
323
-			$first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
324
-
325
-			$first_page .= "<!-- wp:paragraph -->\n<p>";
326
-			$first_page .= sprintf(
327
-				/* translators: First page content. %s: Site admin URL. */
328
-				__( 'As a new WordPress user, you should go to <a href="%s">your dashboard</a> to delete this page and create new pages for your content. Have fun!' ),
329
-				admin_url()
330
-			);
331
-			$first_page .= "</p>\n<!-- /wp:paragraph -->";
332
-		}
333
-
334
-		$first_post_guid = get_option( 'home' ) . '/?page_id=2';
335
-		$wpdb->insert(
336
-			$wpdb->posts,
337
-			array(
338
-				'post_author'           => $user_id,
339
-				'post_date'             => $now,
340
-				'post_date_gmt'         => $now_gmt,
341
-				'post_content'          => $first_page,
342
-				'post_excerpt'          => '',
343
-				'comment_status'        => 'closed',
344
-				'post_title'            => __( 'Sample Page' ),
345
-				/* translators: Default page slug. */
346
-				'post_name'             => __( 'sample-page' ),
347
-				'post_modified'         => $now,
348
-				'post_modified_gmt'     => $now_gmt,
349
-				'guid'                  => $first_post_guid,
350
-				'post_type'             => 'page',
351
-				'to_ping'               => '',
352
-				'pinged'                => '',
353
-				'post_content_filtered' => '',
354
-			)
355
-		);
356
-		$wpdb->insert(
357
-			$wpdb->postmeta,
358
-			array(
359
-				'post_id'    => 2,
360
-				'meta_key'   => '_wp_page_template',
361
-				'meta_value' => 'default',
362
-			)
363
-		);
364
-
365
-		// Privacy Policy page.
366
-		if ( is_multisite() ) {
367
-			// Disable by default unless the suggested content is provided.
368
-			$privacy_policy_content = get_site_option( 'default_privacy_policy_content' );
369
-		} else {
370
-			if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
371
-				include_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
372
-			}
373
-
374
-			$privacy_policy_content = WP_Privacy_Policy_Content::get_default_content();
375
-		}
376
-
377
-		if ( ! empty( $privacy_policy_content ) ) {
378
-			$privacy_policy_guid = get_option( 'home' ) . '/?page_id=3';
379
-
380
-			$wpdb->insert(
381
-				$wpdb->posts,
382
-				array(
383
-					'post_author'           => $user_id,
384
-					'post_date'             => $now,
385
-					'post_date_gmt'         => $now_gmt,
386
-					'post_content'          => $privacy_policy_content,
387
-					'post_excerpt'          => '',
388
-					'comment_status'        => 'closed',
389
-					'post_title'            => __( 'Privacy Policy' ),
390
-					/* translators: Privacy Policy page slug. */
391
-					'post_name'             => __( 'privacy-policy' ),
392
-					'post_modified'         => $now,
393
-					'post_modified_gmt'     => $now_gmt,
394
-					'guid'                  => $privacy_policy_guid,
395
-					'post_type'             => 'page',
396
-					'post_status'           => 'draft',
397
-					'to_ping'               => '',
398
-					'pinged'                => '',
399
-					'post_content_filtered' => '',
400
-				)
401
-			);
402
-			$wpdb->insert(
403
-				$wpdb->postmeta,
404
-				array(
405
-					'post_id'    => 3,
406
-					'meta_key'   => '_wp_page_template',
407
-					'meta_value' => 'default',
408
-				)
409
-			);
410
-			update_option( 'wp_page_for_privacy_policy', 3 );
411
-		}
412
-
413
-		// Set up default widgets for default theme.
414
-		update_option(
415
-			'widget_block',
416
-			array(
417
-				2              => array( 'content' => '<!-- wp:search /-->' ),
418
-				3              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Posts' ) . '</h2><!-- /wp:heading --><!-- wp:latest-posts /--></div><!-- /wp:group -->' ),
419
-				4              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Comments' ) . '</h2><!-- /wp:heading --><!-- wp:latest-comments {"displayAvatar":false,"displayDate":false,"displayExcerpt":false} /--></div><!-- /wp:group -->' ),
420
-				5              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Archives' ) . '</h2><!-- /wp:heading --><!-- wp:archives /--></div><!-- /wp:group -->' ),
421
-				6              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Categories' ) . '</h2><!-- /wp:heading --><!-- wp:categories /--></div><!-- /wp:group -->' ),
422
-				'_multiwidget' => 1,
423
-			)
424
-		);
425
-		update_option(
426
-			'sidebars_widgets',
427
-			array(
428
-				'wp_inactive_widgets' => array(),
429
-				'sidebar-1'           => array(
430
-					0 => 'block-2',
431
-					1 => 'block-3',
432
-					2 => 'block-4',
433
-				),
434
-				'sidebar-2'           => array(
435
-					0 => 'block-5',
436
-					1 => 'block-6',
437
-				),
438
-				'array_version'       => 3,
439
-			)
440
-		);
441
-
442
-		if ( ! is_multisite() ) {
443
-			update_user_meta( $user_id, 'show_welcome_panel', 1 );
444
-		} elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) {
445
-			update_user_meta( $user_id, 'show_welcome_panel', 2 );
446
-		}
447
-
448
-		if ( is_multisite() ) {
449
-			// Flush rules to pick up the new page.
450
-			$wp_rewrite->init();
451
-			$wp_rewrite->flush_rules();
452
-
453
-			$user = new WP_User( $user_id );
454
-			$wpdb->update( $wpdb->options, array( 'option_value' => $user->user_email ), array( 'option_name' => 'admin_email' ) );
455
-
456
-			// Remove all perms except for the login user.
457
-			$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level' ) );
458
-			$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities' ) );
459
-
460
-			// Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.)
461
-			// TODO: Get previous_blog_id.
462
-			if ( ! is_super_admin( $user_id ) && 1 != $user_id ) {
463
-				$wpdb->delete(
464
-					$wpdb->usermeta,
465
-					array(
466
-						'user_id'  => $user_id,
467
-						'meta_key' => $wpdb->base_prefix . '1_capabilities',
468
-					)
469
-				);
470
-			}
471
-		}
472
-	}
282
+            ),
283
+            esc_url( __( 'https://en.gravatar.com/' ) )
284
+        );
285
+        $wpdb->insert(
286
+            $wpdb->comments,
287
+            array(
288
+                'comment_post_ID'      => 1,
289
+                'comment_author'       => $first_comment_author,
290
+                'comment_author_email' => $first_comment_email,
291
+                'comment_author_url'   => $first_comment_url,
292
+                'comment_date'         => $now,
293
+                'comment_date_gmt'     => $now_gmt,
294
+                'comment_content'      => $first_comment,
295
+                'comment_type'         => 'comment',
296
+            )
297
+        );
298
+
299
+        // First page.
300
+        if ( is_multisite() ) {
301
+            $first_page = get_site_option( 'first_page' );
302
+        }
303
+
304
+        if ( empty( $first_page ) ) {
305
+            $first_page = "<!-- wp:paragraph -->\n<p>";
306
+            /* translators: First page content. */
307
+            $first_page .= __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:" );
308
+            $first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
309
+
310
+            $first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
311
+            /* translators: First page content. */
312
+            $first_page .= __( "Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)" );
313
+            $first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
314
+
315
+            $first_page .= "<!-- wp:paragraph -->\n<p>";
316
+            /* translators: First page content. */
317
+            $first_page .= __( '...or something like this:' );
318
+            $first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
319
+
320
+            $first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
321
+            /* translators: First page content. */
322
+            $first_page .= __( 'The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.' );
323
+            $first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
324
+
325
+            $first_page .= "<!-- wp:paragraph -->\n<p>";
326
+            $first_page .= sprintf(
327
+                /* translators: First page content. %s: Site admin URL. */
328
+                __( 'As a new WordPress user, you should go to <a href="%s">your dashboard</a> to delete this page and create new pages for your content. Have fun!' ),
329
+                admin_url()
330
+            );
331
+            $first_page .= "</p>\n<!-- /wp:paragraph -->";
332
+        }
333
+
334
+        $first_post_guid = get_option( 'home' ) . '/?page_id=2';
335
+        $wpdb->insert(
336
+            $wpdb->posts,
337
+            array(
338
+                'post_author'           => $user_id,
339
+                'post_date'             => $now,
340
+                'post_date_gmt'         => $now_gmt,
341
+                'post_content'          => $first_page,
342
+                'post_excerpt'          => '',
343
+                'comment_status'        => 'closed',
344
+                'post_title'            => __( 'Sample Page' ),
345
+                /* translators: Default page slug. */
346
+                'post_name'             => __( 'sample-page' ),
347
+                'post_modified'         => $now,
348
+                'post_modified_gmt'     => $now_gmt,
349
+                'guid'                  => $first_post_guid,
350
+                'post_type'             => 'page',
351
+                'to_ping'               => '',
352
+                'pinged'                => '',
353
+                'post_content_filtered' => '',
354
+            )
355
+        );
356
+        $wpdb->insert(
357
+            $wpdb->postmeta,
358
+            array(
359
+                'post_id'    => 2,
360
+                'meta_key'   => '_wp_page_template',
361
+                'meta_value' => 'default',
362
+            )
363
+        );
364
+
365
+        // Privacy Policy page.
366
+        if ( is_multisite() ) {
367
+            // Disable by default unless the suggested content is provided.
368
+            $privacy_policy_content = get_site_option( 'default_privacy_policy_content' );
369
+        } else {
370
+            if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
371
+                include_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
372
+            }
373
+
374
+            $privacy_policy_content = WP_Privacy_Policy_Content::get_default_content();
375
+        }
376
+
377
+        if ( ! empty( $privacy_policy_content ) ) {
378
+            $privacy_policy_guid = get_option( 'home' ) . '/?page_id=3';
379
+
380
+            $wpdb->insert(
381
+                $wpdb->posts,
382
+                array(
383
+                    'post_author'           => $user_id,
384
+                    'post_date'             => $now,
385
+                    'post_date_gmt'         => $now_gmt,
386
+                    'post_content'          => $privacy_policy_content,
387
+                    'post_excerpt'          => '',
388
+                    'comment_status'        => 'closed',
389
+                    'post_title'            => __( 'Privacy Policy' ),
390
+                    /* translators: Privacy Policy page slug. */
391
+                    'post_name'             => __( 'privacy-policy' ),
392
+                    'post_modified'         => $now,
393
+                    'post_modified_gmt'     => $now_gmt,
394
+                    'guid'                  => $privacy_policy_guid,
395
+                    'post_type'             => 'page',
396
+                    'post_status'           => 'draft',
397
+                    'to_ping'               => '',
398
+                    'pinged'                => '',
399
+                    'post_content_filtered' => '',
400
+                )
401
+            );
402
+            $wpdb->insert(
403
+                $wpdb->postmeta,
404
+                array(
405
+                    'post_id'    => 3,
406
+                    'meta_key'   => '_wp_page_template',
407
+                    'meta_value' => 'default',
408
+                )
409
+            );
410
+            update_option( 'wp_page_for_privacy_policy', 3 );
411
+        }
412
+
413
+        // Set up default widgets for default theme.
414
+        update_option(
415
+            'widget_block',
416
+            array(
417
+                2              => array( 'content' => '<!-- wp:search /-->' ),
418
+                3              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Posts' ) . '</h2><!-- /wp:heading --><!-- wp:latest-posts /--></div><!-- /wp:group -->' ),
419
+                4              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Comments' ) . '</h2><!-- /wp:heading --><!-- wp:latest-comments {"displayAvatar":false,"displayDate":false,"displayExcerpt":false} /--></div><!-- /wp:group -->' ),
420
+                5              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Archives' ) . '</h2><!-- /wp:heading --><!-- wp:archives /--></div><!-- /wp:group -->' ),
421
+                6              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Categories' ) . '</h2><!-- /wp:heading --><!-- wp:categories /--></div><!-- /wp:group -->' ),
422
+                '_multiwidget' => 1,
423
+            )
424
+        );
425
+        update_option(
426
+            'sidebars_widgets',
427
+            array(
428
+                'wp_inactive_widgets' => array(),
429
+                'sidebar-1'           => array(
430
+                    0 => 'block-2',
431
+                    1 => 'block-3',
432
+                    2 => 'block-4',
433
+                ),
434
+                'sidebar-2'           => array(
435
+                    0 => 'block-5',
436
+                    1 => 'block-6',
437
+                ),
438
+                'array_version'       => 3,
439
+            )
440
+        );
441
+
442
+        if ( ! is_multisite() ) {
443
+            update_user_meta( $user_id, 'show_welcome_panel', 1 );
444
+        } elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) {
445
+            update_user_meta( $user_id, 'show_welcome_panel', 2 );
446
+        }
447
+
448
+        if ( is_multisite() ) {
449
+            // Flush rules to pick up the new page.
450
+            $wp_rewrite->init();
451
+            $wp_rewrite->flush_rules();
452
+
453
+            $user = new WP_User( $user_id );
454
+            $wpdb->update( $wpdb->options, array( 'option_value' => $user->user_email ), array( 'option_name' => 'admin_email' ) );
455
+
456
+            // Remove all perms except for the login user.
457
+            $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level' ) );
458
+            $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities' ) );
459
+
460
+            // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.)
461
+            // TODO: Get previous_blog_id.
462
+            if ( ! is_super_admin( $user_id ) && 1 != $user_id ) {
463
+                $wpdb->delete(
464
+                    $wpdb->usermeta,
465
+                    array(
466
+                        'user_id'  => $user_id,
467
+                        'meta_key' => $wpdb->base_prefix . '1_capabilities',
468
+                    )
469
+                );
470
+            }
471
+        }
472
+    }
473 473
 endif;
474 474
 
475 475
 /**
@@ -484,14 +484,14 @@  discard block
 block discarded – undo
484 484
  * @return bool Whether pretty permalinks are enabled. False otherwise.
485 485
  */
486 486
 function wp_install_maybe_enable_pretty_permalinks() {
487
-	global $wp_rewrite;
487
+    global $wp_rewrite;
488 488
 
489
-	// Bail if a permalink structure is already enabled.
490
-	if ( get_option( 'permalink_structure' ) ) {
491
-		return true;
492
-	}
489
+    // Bail if a permalink structure is already enabled.
490
+    if ( get_option( 'permalink_structure' ) ) {
491
+        return true;
492
+    }
493 493
 
494
-	/*
494
+    /*
495 495
 	 * The Permalink structures to attempt.
496 496
 	 *
497 497
 	 * The first is designed for mod_rewrite or nginx rewriting.
@@ -499,79 +499,79 @@  discard block
 block discarded – undo
499 499
 	 * The second is PATHINFO-based permalinks for web server configurations
500 500
 	 * without a true rewrite module enabled.
501 501
 	 */
502
-	$permalink_structures = array(
503
-		'/%year%/%monthnum%/%day%/%postname%/',
504
-		'/index.php/%year%/%monthnum%/%day%/%postname%/',
505
-	);
502
+    $permalink_structures = array(
503
+        '/%year%/%monthnum%/%day%/%postname%/',
504
+        '/index.php/%year%/%monthnum%/%day%/%postname%/',
505
+    );
506 506
 
507
-	foreach ( (array) $permalink_structures as $permalink_structure ) {
508
-		$wp_rewrite->set_permalink_structure( $permalink_structure );
507
+    foreach ( (array) $permalink_structures as $permalink_structure ) {
508
+        $wp_rewrite->set_permalink_structure( $permalink_structure );
509 509
 
510
-		/*
510
+        /*
511 511
 		 * Flush rules with the hard option to force refresh of the web-server's
512 512
 		 * rewrite config file (e.g. .htaccess or web.config).
513 513
 		 */
514
-		$wp_rewrite->flush_rules( true );
514
+        $wp_rewrite->flush_rules( true );
515 515
 
516
-		$test_url = '';
516
+        $test_url = '';
517 517
 
518
-		// Test against a real WordPress post.
519
-		$first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
520
-		if ( $first_post ) {
521
-			$test_url = get_permalink( $first_post->ID );
522
-		}
518
+        // Test against a real WordPress post.
519
+        $first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
520
+        if ( $first_post ) {
521
+            $test_url = get_permalink( $first_post->ID );
522
+        }
523 523
 
524
-		/*
524
+        /*
525 525
 		 * Send a request to the site, and check whether
526 526
 		 * the 'x-pingback' header is returned as expected.
527 527
 		 *
528 528
 		 * Uses wp_remote_get() instead of wp_remote_head() because web servers
529 529
 		 * can block head requests.
530 530
 		 */
531
-		$response          = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
532
-		$x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
533
-		$pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header;
531
+        $response          = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
532
+        $x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
533
+        $pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header;
534 534
 
535
-		if ( $pretty_permalinks ) {
536
-			return true;
537
-		}
538
-	}
535
+        if ( $pretty_permalinks ) {
536
+            return true;
537
+        }
538
+    }
539 539
 
540
-	/*
540
+    /*
541 541
 	 * If it makes it this far, pretty permalinks failed.
542 542
 	 * Fallback to query-string permalinks.
543 543
 	 */
544
-	$wp_rewrite->set_permalink_structure( '' );
545
-	$wp_rewrite->flush_rules( true );
544
+    $wp_rewrite->set_permalink_structure( '' );
545
+    $wp_rewrite->flush_rules( true );
546 546
 
547
-	return false;
547
+    return false;
548 548
 }
549 549
 
550 550
 if ( ! function_exists( 'wp_new_blog_notification' ) ) :
551
-	/**
552
-	 * Notifies the site admin that the installation of WordPress is complete.
553
-	 *
554
-	 * Sends an email to the new administrator that the installation is complete
555
-	 * and provides them with a record of their login credentials.
556
-	 *
557
-	 * @since 2.1.0
558
-	 *
559
-	 * @param string $blog_title Site title.
560
-	 * @param string $blog_url   Site URL.
561
-	 * @param int    $user_id    Administrator's user ID.
562
-	 * @param string $password   Administrator's password. Note that a placeholder message is
563
-	 *                           usually passed instead of the actual password.
564
-	 */
565
-	function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
566
-		$user      = new WP_User( $user_id );
567
-		$email     = $user->user_email;
568
-		$name      = $user->user_login;
569
-		$login_url = wp_login_url();
570
-
571
-		$message = sprintf(
572
-			/* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL. */
573
-			__(
574
-				'Your new WordPress site has been successfully set up at:
551
+    /**
552
+     * Notifies the site admin that the installation of WordPress is complete.
553
+     *
554
+     * Sends an email to the new administrator that the installation is complete
555
+     * and provides them with a record of their login credentials.
556
+     *
557
+     * @since 2.1.0
558
+     *
559
+     * @param string $blog_title Site title.
560
+     * @param string $blog_url   Site URL.
561
+     * @param int    $user_id    Administrator's user ID.
562
+     * @param string $password   Administrator's password. Note that a placeholder message is
563
+     *                           usually passed instead of the actual password.
564
+     */
565
+    function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
566
+        $user      = new WP_User( $user_id );
567
+        $email     = $user->user_email;
568
+        $name      = $user->user_login;
569
+        $login_url = wp_login_url();
570
+
571
+        $message = sprintf(
572
+            /* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL. */
573
+            __(
574
+                'Your new WordPress site has been successfully set up at:
575 575
 
576 576
 %1$s
577 577
 
@@ -586,101 +586,101 @@  discard block
 block discarded – undo
586 586
 --The WordPress Team
587 587
 https://wordpress.org/
588 588
 '
589
-			),
590
-			$blog_url,
591
-			$name,
592
-			$password,
593
-			$login_url
594
-		);
595
-
596
-		$installed_email = array(
597
-			'to'      => $email,
598
-			'subject' => __( 'New WordPress Site' ),
599
-			'message' => $message,
600
-			'headers' => '',
601
-		);
602
-
603
-		/**
604
-		 * Filters the contents of the email sent to the site administrator when WordPress is installed.
605
-		 *
606
-		 * @since 5.6.0
607
-		 *
608
-		 * @param array $installed_email {
609
-		 *     Used to build wp_mail().
610
-		 *
611
-		 *     @type string $to      The email address of the recipient.
612
-		 *     @type string $subject The subject of the email.
613
-		 *     @type string $message The content of the email.
614
-		 *     @type string $headers Headers.
615
-		 * }
616
-		 * @param WP_User $user          The site administrator user object.
617
-		 * @param string  $blog_title    The site title.
618
-		 * @param string  $blog_url      The site URL.
619
-		 * @param string  $password      The site administrator's password. Note that a placeholder message
620
-		 *                               is usually passed instead of the user's actual password.
621
-		 */
622
-		$installed_email = apply_filters( 'wp_installed_email', $installed_email, $user, $blog_title, $blog_url, $password );
623
-
624
-		wp_mail(
625
-			$installed_email['to'],
626
-			$installed_email['subject'],
627
-			$installed_email['message'],
628
-			$installed_email['headers']
629
-		);
630
-	}
589
+            ),
590
+            $blog_url,
591
+            $name,
592
+            $password,
593
+            $login_url
594
+        );
595
+
596
+        $installed_email = array(
597
+            'to'      => $email,
598
+            'subject' => __( 'New WordPress Site' ),
599
+            'message' => $message,
600
+            'headers' => '',
601
+        );
602
+
603
+        /**
604
+         * Filters the contents of the email sent to the site administrator when WordPress is installed.
605
+         *
606
+         * @since 5.6.0
607
+         *
608
+         * @param array $installed_email {
609
+         *     Used to build wp_mail().
610
+         *
611
+         *     @type string $to      The email address of the recipient.
612
+         *     @type string $subject The subject of the email.
613
+         *     @type string $message The content of the email.
614
+         *     @type string $headers Headers.
615
+         * }
616
+         * @param WP_User $user          The site administrator user object.
617
+         * @param string  $blog_title    The site title.
618
+         * @param string  $blog_url      The site URL.
619
+         * @param string  $password      The site administrator's password. Note that a placeholder message
620
+         *                               is usually passed instead of the user's actual password.
621
+         */
622
+        $installed_email = apply_filters( 'wp_installed_email', $installed_email, $user, $blog_title, $blog_url, $password );
623
+
624
+        wp_mail(
625
+            $installed_email['to'],
626
+            $installed_email['subject'],
627
+            $installed_email['message'],
628
+            $installed_email['headers']
629
+        );
630
+    }
631 631
 endif;
632 632
 
633 633
 if ( ! function_exists( 'wp_upgrade' ) ) :
634
-	/**
635
-	 * Runs WordPress Upgrade functions.
636
-	 *
637
-	 * Upgrades the database if needed during a site update.
638
-	 *
639
-	 * @since 2.1.0
640
-	 *
641
-	 * @global int  $wp_current_db_version The old (current) database version.
642
-	 * @global int  $wp_db_version         The new database version.
643
-	 * @global wpdb $wpdb                  WordPress database abstraction object.
644
-	 */
645
-	function wp_upgrade() {
646
-		global $wp_current_db_version, $wp_db_version, $wpdb;
647
-
648
-		$wp_current_db_version = __get_option( 'db_version' );
649
-
650
-		// We are up to date. Nothing to do.
651
-		if ( $wp_db_version == $wp_current_db_version ) {
652
-			return;
653
-		}
654
-
655
-		if ( ! is_blog_installed() ) {
656
-			return;
657
-		}
658
-
659
-		wp_check_mysql_version();
660
-		wp_cache_flush();
661
-		pre_schema_upgrade();
662
-		make_db_current_silent();
663
-		upgrade_all();
664
-		if ( is_multisite() && is_main_site() ) {
665
-			upgrade_network();
666
-		}
667
-		wp_cache_flush();
668
-
669
-		if ( is_multisite() ) {
670
-			update_site_meta( get_current_blog_id(), 'db_version', $wp_db_version );
671
-			update_site_meta( get_current_blog_id(), 'db_last_updated', microtime() );
672
-		}
673
-
674
-		/**
675
-		 * Fires after a site is fully upgraded.
676
-		 *
677
-		 * @since 3.9.0
678
-		 *
679
-		 * @param int $wp_db_version         The new $wp_db_version.
680
-		 * @param int $wp_current_db_version The old (current) $wp_db_version.
681
-		 */
682
-		do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version );
683
-	}
634
+    /**
635
+     * Runs WordPress Upgrade functions.
636
+     *
637
+     * Upgrades the database if needed during a site update.
638
+     *
639
+     * @since 2.1.0
640
+     *
641
+     * @global int  $wp_current_db_version The old (current) database version.
642
+     * @global int  $wp_db_version         The new database version.
643
+     * @global wpdb $wpdb                  WordPress database abstraction object.
644
+     */
645
+    function wp_upgrade() {
646
+        global $wp_current_db_version, $wp_db_version, $wpdb;
647
+
648
+        $wp_current_db_version = __get_option( 'db_version' );
649
+
650
+        // We are up to date. Nothing to do.
651
+        if ( $wp_db_version == $wp_current_db_version ) {
652
+            return;
653
+        }
654
+
655
+        if ( ! is_blog_installed() ) {
656
+            return;
657
+        }
658
+
659
+        wp_check_mysql_version();
660
+        wp_cache_flush();
661
+        pre_schema_upgrade();
662
+        make_db_current_silent();
663
+        upgrade_all();
664
+        if ( is_multisite() && is_main_site() ) {
665
+            upgrade_network();
666
+        }
667
+        wp_cache_flush();
668
+
669
+        if ( is_multisite() ) {
670
+            update_site_meta( get_current_blog_id(), 'db_version', $wp_db_version );
671
+            update_site_meta( get_current_blog_id(), 'db_last_updated', microtime() );
672
+        }
673
+
674
+        /**
675
+         * Fires after a site is fully upgraded.
676
+         *
677
+         * @since 3.9.0
678
+         *
679
+         * @param int $wp_db_version         The new $wp_db_version.
680
+         * @param int $wp_current_db_version The old (current) $wp_db_version.
681
+         */
682
+        do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version );
683
+    }
684 684
 endif;
685 685
 
686 686
 /**
@@ -696,165 +696,165 @@  discard block
 block discarded – undo
696 696
  * @global int $wp_db_version         The new database version.
697 697
  */
698 698
 function upgrade_all() {
699
-	global $wp_current_db_version, $wp_db_version;
699
+    global $wp_current_db_version, $wp_db_version;
700 700
 
701
-	$wp_current_db_version = __get_option( 'db_version' );
702
-
703
-	// We are up to date. Nothing to do.
704
-	if ( $wp_db_version == $wp_current_db_version ) {
705
-		return;
706
-	}
701
+    $wp_current_db_version = __get_option( 'db_version' );
702
+
703
+    // We are up to date. Nothing to do.
704
+    if ( $wp_db_version == $wp_current_db_version ) {
705
+        return;
706
+    }
707 707
 
708
-	// If the version is not set in the DB, try to guess the version.
709
-	if ( empty( $wp_current_db_version ) ) {
710
-		$wp_current_db_version = 0;
708
+    // If the version is not set in the DB, try to guess the version.
709
+    if ( empty( $wp_current_db_version ) ) {
710
+        $wp_current_db_version = 0;
711 711
 
712
-		// If the template option exists, we have 1.5.
713
-		$template = __get_option( 'template' );
714
-		if ( ! empty( $template ) ) {
715
-			$wp_current_db_version = 2541;
716
-		}
717
-	}
718
-
719
-	if ( $wp_current_db_version < 6039 ) {
720
-		upgrade_230_options_table();
721
-	}
722
-
723
-	populate_options();
712
+        // If the template option exists, we have 1.5.
713
+        $template = __get_option( 'template' );
714
+        if ( ! empty( $template ) ) {
715
+            $wp_current_db_version = 2541;
716
+        }
717
+    }
718
+
719
+    if ( $wp_current_db_version < 6039 ) {
720
+        upgrade_230_options_table();
721
+    }
722
+
723
+    populate_options();
724 724
 
725
-	if ( $wp_current_db_version < 2541 ) {
726
-		upgrade_100();
727
-		upgrade_101();
728
-		upgrade_110();
729
-		upgrade_130();
730
-	}
725
+    if ( $wp_current_db_version < 2541 ) {
726
+        upgrade_100();
727
+        upgrade_101();
728
+        upgrade_110();
729
+        upgrade_130();
730
+    }
731 731
 
732
-	if ( $wp_current_db_version < 3308 ) {
733
-		upgrade_160();
734
-	}
732
+    if ( $wp_current_db_version < 3308 ) {
733
+        upgrade_160();
734
+    }
735 735
 
736
-	if ( $wp_current_db_version < 4772 ) {
737
-		upgrade_210();
738
-	}
736
+    if ( $wp_current_db_version < 4772 ) {
737
+        upgrade_210();
738
+    }
739 739
 
740
-	if ( $wp_current_db_version < 4351 ) {
741
-		upgrade_old_slugs();
742
-	}
740
+    if ( $wp_current_db_version < 4351 ) {
741
+        upgrade_old_slugs();
742
+    }
743 743
 
744
-	if ( $wp_current_db_version < 5539 ) {
745
-		upgrade_230();
746
-	}
744
+    if ( $wp_current_db_version < 5539 ) {
745
+        upgrade_230();
746
+    }
747 747
 
748
-	if ( $wp_current_db_version < 6124 ) {
749
-		upgrade_230_old_tables();
750
-	}
748
+    if ( $wp_current_db_version < 6124 ) {
749
+        upgrade_230_old_tables();
750
+    }
751 751
 
752
-	if ( $wp_current_db_version < 7499 ) {
753
-		upgrade_250();
754
-	}
752
+    if ( $wp_current_db_version < 7499 ) {
753
+        upgrade_250();
754
+    }
755 755
 
756
-	if ( $wp_current_db_version < 7935 ) {
757
-		upgrade_252();
758
-	}
756
+    if ( $wp_current_db_version < 7935 ) {
757
+        upgrade_252();
758
+    }
759 759
 
760
-	if ( $wp_current_db_version < 8201 ) {
761
-		upgrade_260();
762
-	}
760
+    if ( $wp_current_db_version < 8201 ) {
761
+        upgrade_260();
762
+    }
763 763
 
764
-	if ( $wp_current_db_version < 8989 ) {
765
-		upgrade_270();
766
-	}
764
+    if ( $wp_current_db_version < 8989 ) {
765
+        upgrade_270();
766
+    }
767 767
 
768
-	if ( $wp_current_db_version < 10360 ) {
769
-		upgrade_280();
770
-	}
768
+    if ( $wp_current_db_version < 10360 ) {
769
+        upgrade_280();
770
+    }
771 771
 
772
-	if ( $wp_current_db_version < 11958 ) {
773
-		upgrade_290();
774
-	}
772
+    if ( $wp_current_db_version < 11958 ) {
773
+        upgrade_290();
774
+    }
775 775
 
776
-	if ( $wp_current_db_version < 15260 ) {
777
-		upgrade_300();
778
-	}
776
+    if ( $wp_current_db_version < 15260 ) {
777
+        upgrade_300();
778
+    }
779 779
 
780
-	if ( $wp_current_db_version < 19389 ) {
781
-		upgrade_330();
782
-	}
780
+    if ( $wp_current_db_version < 19389 ) {
781
+        upgrade_330();
782
+    }
783 783
 
784
-	if ( $wp_current_db_version < 20080 ) {
785
-		upgrade_340();
786
-	}
784
+    if ( $wp_current_db_version < 20080 ) {
785
+        upgrade_340();
786
+    }
787 787
 
788
-	if ( $wp_current_db_version < 22422 ) {
789
-		upgrade_350();
790
-	}
788
+    if ( $wp_current_db_version < 22422 ) {
789
+        upgrade_350();
790
+    }
791 791
 
792
-	if ( $wp_current_db_version < 25824 ) {
793
-		upgrade_370();
794
-	}
792
+    if ( $wp_current_db_version < 25824 ) {
793
+        upgrade_370();
794
+    }
795 795
 
796
-	if ( $wp_current_db_version < 26148 ) {
797
-		upgrade_372();
798
-	}
796
+    if ( $wp_current_db_version < 26148 ) {
797
+        upgrade_372();
798
+    }
799 799
 
800
-	if ( $wp_current_db_version < 26691 ) {
801
-		upgrade_380();
802
-	}
800
+    if ( $wp_current_db_version < 26691 ) {
801
+        upgrade_380();
802
+    }
803 803
 
804
-	if ( $wp_current_db_version < 29630 ) {
805
-		upgrade_400();
806
-	}
804
+    if ( $wp_current_db_version < 29630 ) {
805
+        upgrade_400();
806
+    }
807 807
 
808
-	if ( $wp_current_db_version < 33055 ) {
809
-		upgrade_430();
810
-	}
808
+    if ( $wp_current_db_version < 33055 ) {
809
+        upgrade_430();
810
+    }
811 811
 
812
-	if ( $wp_current_db_version < 33056 ) {
813
-		upgrade_431();
814
-	}
812
+    if ( $wp_current_db_version < 33056 ) {
813
+        upgrade_431();
814
+    }
815 815
 
816
-	if ( $wp_current_db_version < 35700 ) {
817
-		upgrade_440();
818
-	}
816
+    if ( $wp_current_db_version < 35700 ) {
817
+        upgrade_440();
818
+    }
819 819
 
820
-	if ( $wp_current_db_version < 36686 ) {
821
-		upgrade_450();
822
-	}
820
+    if ( $wp_current_db_version < 36686 ) {
821
+        upgrade_450();
822
+    }
823 823
 
824
-	if ( $wp_current_db_version < 37965 ) {
825
-		upgrade_460();
826
-	}
824
+    if ( $wp_current_db_version < 37965 ) {
825
+        upgrade_460();
826
+    }
827 827
 
828
-	if ( $wp_current_db_version < 44719 ) {
829
-		upgrade_510();
830
-	}
828
+    if ( $wp_current_db_version < 44719 ) {
829
+        upgrade_510();
830
+    }
831 831
 
832
-	if ( $wp_current_db_version < 45744 ) {
833
-		upgrade_530();
834
-	}
832
+    if ( $wp_current_db_version < 45744 ) {
833
+        upgrade_530();
834
+    }
835 835
 
836
-	if ( $wp_current_db_version < 48575 ) {
837
-		upgrade_550();
838
-	}
836
+    if ( $wp_current_db_version < 48575 ) {
837
+        upgrade_550();
838
+    }
839 839
 
840
-	if ( $wp_current_db_version < 49752 ) {
841
-		upgrade_560();
842
-	}
840
+    if ( $wp_current_db_version < 49752 ) {
841
+        upgrade_560();
842
+    }
843 843
 
844
-	if ( $wp_current_db_version < 51917 ) {
845
-		upgrade_590();
846
-	}
844
+    if ( $wp_current_db_version < 51917 ) {
845
+        upgrade_590();
846
+    }
847 847
 
848
-	if ( $wp_current_db_version < 53011 ) {
849
-		upgrade_600();
850
-	}
848
+    if ( $wp_current_db_version < 53011 ) {
849
+        upgrade_600();
850
+    }
851 851
 
852
-	maybe_disable_link_manager();
852
+    maybe_disable_link_manager();
853 853
 
854
-	maybe_disable_automattic_widgets();
854
+    maybe_disable_automattic_widgets();
855 855
 
856
-	update_option( 'db_version', $wp_db_version );
857
-	update_option( 'db_upgraded', true );
856
+    update_option( 'db_version', $wp_db_version );
857
+    update_option( 'db_upgraded', true );
858 858
 }
859 859
 
860 860
 /**
@@ -866,60 +866,60 @@  discard block
 block discarded – undo
866 866
  * @global wpdb $wpdb WordPress database abstraction object.
867 867
  */
868 868
 function upgrade_100() {
869
-	global $wpdb;
870
-
871
-	// Get the title and ID of every post, post_name to check if it already has a value.
872
-	$posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" );
873
-	if ( $posts ) {
874
-		foreach ( $posts as $post ) {
875
-			if ( '' === $post->post_name ) {
876
-				$newtitle = sanitize_title( $post->post_title );
877
-				$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID ) );
878
-			}
879
-		}
880
-	}
881
-
882
-	$categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" );
883
-	foreach ( $categories as $category ) {
884
-		if ( '' === $category->category_nicename ) {
885
-			$newtitle = sanitize_title( $category->cat_name );
886
-			$wpdb->update( $wpdb->categories, array( 'category_nicename' => $newtitle ), array( 'cat_ID' => $category->cat_ID ) );
887
-		}
888
-	}
889
-
890
-	$sql = "UPDATE $wpdb->options
869
+    global $wpdb;
870
+
871
+    // Get the title and ID of every post, post_name to check if it already has a value.
872
+    $posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" );
873
+    if ( $posts ) {
874
+        foreach ( $posts as $post ) {
875
+            if ( '' === $post->post_name ) {
876
+                $newtitle = sanitize_title( $post->post_title );
877
+                $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID ) );
878
+            }
879
+        }
880
+    }
881
+
882
+    $categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" );
883
+    foreach ( $categories as $category ) {
884
+        if ( '' === $category->category_nicename ) {
885
+            $newtitle = sanitize_title( $category->cat_name );
886
+            $wpdb->update( $wpdb->categories, array( 'category_nicename' => $newtitle ), array( 'cat_ID' => $category->cat_ID ) );
887
+        }
888
+    }
889
+
890
+    $sql = "UPDATE $wpdb->options
891 891
 		SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
892 892
 		WHERE option_name LIKE %s
893 893
 		AND option_value LIKE %s";
894
-	$wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) );
895
-
896
-	$done_ids = $wpdb->get_results( "SELECT DISTINCT post_id FROM $wpdb->post2cat" );
897
-	if ( $done_ids ) :
898
-		$done_posts = array();
899
-		foreach ( $done_ids as $done_id ) :
900
-			$done_posts[] = $done_id->post_id;
901
-		endforeach;
902
-		$catwhere = ' AND ID NOT IN (' . implode( ',', $done_posts ) . ')';
903
-	else :
904
-		$catwhere = '';
905
-	endif;
906
-
907
-	$allposts = $wpdb->get_results( "SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere" );
908
-	if ( $allposts ) :
909
-		foreach ( $allposts as $post ) {
910
-			// Check to see if it's already been imported.
911
-			$cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
912
-			if ( ! $cat && 0 != $post->post_category ) { // If there's no result.
913
-				$wpdb->insert(
914
-					$wpdb->post2cat,
915
-					array(
916
-						'post_id'     => $post->ID,
917
-						'category_id' => $post->post_category,
918
-					)
919
-				);
920
-			}
921
-		}
922
-	endif;
894
+    $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) );
895
+
896
+    $done_ids = $wpdb->get_results( "SELECT DISTINCT post_id FROM $wpdb->post2cat" );
897
+    if ( $done_ids ) :
898
+        $done_posts = array();
899
+        foreach ( $done_ids as $done_id ) :
900
+            $done_posts[] = $done_id->post_id;
901
+        endforeach;
902
+        $catwhere = ' AND ID NOT IN (' . implode( ',', $done_posts ) . ')';
903
+    else :
904
+        $catwhere = '';
905
+    endif;
906
+
907
+    $allposts = $wpdb->get_results( "SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere" );
908
+    if ( $allposts ) :
909
+        foreach ( $allposts as $post ) {
910
+            // Check to see if it's already been imported.
911
+            $cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
912
+            if ( ! $cat && 0 != $post->post_category ) { // If there's no result.
913
+                $wpdb->insert(
914
+                    $wpdb->post2cat,
915
+                    array(
916
+                        'post_id'     => $post->ID,
917
+                        'category_id' => $post->post_category,
918
+                    )
919
+                );
920
+            }
921
+        }
922
+    endif;
923 923
 }
924 924
 
925 925
 /**
@@ -931,16 +931,16 @@  discard block
 block discarded – undo
931 931
  * @global wpdb $wpdb WordPress database abstraction object.
932 932
  */
933 933
 function upgrade_101() {
934
-	global $wpdb;
935
-
936
-	// Clean up indices, add a few.
937
-	add_clean_index( $wpdb->posts, 'post_name' );
938
-	add_clean_index( $wpdb->posts, 'post_status' );
939
-	add_clean_index( $wpdb->categories, 'category_nicename' );
940
-	add_clean_index( $wpdb->comments, 'comment_approved' );
941
-	add_clean_index( $wpdb->comments, 'comment_post_ID' );
942
-	add_clean_index( $wpdb->links, 'link_category' );
943
-	add_clean_index( $wpdb->links, 'link_visible' );
934
+    global $wpdb;
935
+
936
+    // Clean up indices, add a few.
937
+    add_clean_index( $wpdb->posts, 'post_name' );
938
+    add_clean_index( $wpdb->posts, 'post_status' );
939
+    add_clean_index( $wpdb->categories, 'category_nicename' );
940
+    add_clean_index( $wpdb->comments, 'comment_approved' );
941
+    add_clean_index( $wpdb->comments, 'comment_post_ID' );
942
+    add_clean_index( $wpdb->links, 'link_category' );
943
+    add_clean_index( $wpdb->links, 'link_visible' );
944 944
 }
945 945
 
946 946
 /**
@@ -952,59 +952,59 @@  discard block
 block discarded – undo
952 952
  * @global wpdb $wpdb WordPress database abstraction object.
953 953
  */
954 954
 function upgrade_110() {
955
-	global $wpdb;
956
-
957
-	// Set user_nicename.
958
-	$users = $wpdb->get_results( "SELECT ID, user_nickname, user_nicename FROM $wpdb->users" );
959
-	foreach ( $users as $user ) {
960
-		if ( '' === $user->user_nicename ) {
961
-			$newname = sanitize_title( $user->user_nickname );
962
-			$wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
963
-		}
964
-	}
965
-
966
-	$users = $wpdb->get_results( "SELECT ID, user_pass from $wpdb->users" );
967
-	foreach ( $users as $row ) {
968
-		if ( ! preg_match( '/^[A-Fa-f0-9]{32}$/', $row->user_pass ) ) {
969
-			$wpdb->update( $wpdb->users, array( 'user_pass' => md5( $row->user_pass ) ), array( 'ID' => $row->ID ) );
970
-		}
971
-	}
972
-
973
-	// Get the GMT offset, we'll use that later on.
974
-	$all_options = get_alloptions_110();
975
-
976
-	$time_difference = $all_options->time_difference;
977
-
978
-		$server_time = time() + gmdate( 'Z' );
979
-	$weblogger_time  = $server_time + $time_difference * HOUR_IN_SECONDS;
980
-	$gmt_time        = time();
981
-
982
-	$diff_gmt_server       = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS;
983
-	$diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS;
984
-	$diff_gmt_weblogger    = $diff_gmt_server - $diff_weblogger_server;
985
-	$gmt_offset            = -$diff_gmt_weblogger;
986
-
987
-	// Add a gmt_offset option, with value $gmt_offset.
988
-	add_option( 'gmt_offset', $gmt_offset );
989
-
990
-	/*
955
+    global $wpdb;
956
+
957
+    // Set user_nicename.
958
+    $users = $wpdb->get_results( "SELECT ID, user_nickname, user_nicename FROM $wpdb->users" );
959
+    foreach ( $users as $user ) {
960
+        if ( '' === $user->user_nicename ) {
961
+            $newname = sanitize_title( $user->user_nickname );
962
+            $wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
963
+        }
964
+    }
965
+
966
+    $users = $wpdb->get_results( "SELECT ID, user_pass from $wpdb->users" );
967
+    foreach ( $users as $row ) {
968
+        if ( ! preg_match( '/^[A-Fa-f0-9]{32}$/', $row->user_pass ) ) {
969
+            $wpdb->update( $wpdb->users, array( 'user_pass' => md5( $row->user_pass ) ), array( 'ID' => $row->ID ) );
970
+        }
971
+    }
972
+
973
+    // Get the GMT offset, we'll use that later on.
974
+    $all_options = get_alloptions_110();
975
+
976
+    $time_difference = $all_options->time_difference;
977
+
978
+        $server_time = time() + gmdate( 'Z' );
979
+    $weblogger_time  = $server_time + $time_difference * HOUR_IN_SECONDS;
980
+    $gmt_time        = time();
981
+
982
+    $diff_gmt_server       = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS;
983
+    $diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS;
984
+    $diff_gmt_weblogger    = $diff_gmt_server - $diff_weblogger_server;
985
+    $gmt_offset            = -$diff_gmt_weblogger;
986
+
987
+    // Add a gmt_offset option, with value $gmt_offset.
988
+    add_option( 'gmt_offset', $gmt_offset );
989
+
990
+    /*
991 991
 	 * Check if we already set the GMT fields. If we did, then
992 992
 	 * MAX(post_date_gmt) can't be '0000-00-00 00:00:00'.
993 993
 	 * <michel_v> I just slapped myself silly for not thinking about it earlier.
994 994
 	 */
995
-	$got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) );
995
+    $got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) );
996 996
 
997
-	if ( ! $got_gmt_fields ) {
997
+    if ( ! $got_gmt_fields ) {
998 998
 
999
-		// Add or subtract time to all dates, to get GMT dates.
1000
-		$add_hours   = (int) $diff_gmt_weblogger;
1001
-		$add_minutes = (int) ( 60 * ( $diff_gmt_weblogger - $add_hours ) );
1002
-		$wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
1003
-		$wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" );
1004
-		$wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" );
1005
-		$wpdb->query( "UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
1006
-		$wpdb->query( "UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
1007
-	}
999
+        // Add or subtract time to all dates, to get GMT dates.
1000
+        $add_hours   = (int) $diff_gmt_weblogger;
1001
+        $add_minutes = (int) ( 60 * ( $diff_gmt_weblogger - $add_hours ) );
1002
+        $wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
1003
+        $wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" );
1004
+        $wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" );
1005
+        $wpdb->query( "UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
1006
+        $wpdb->query( "UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
1007
+    }
1008 1008
 
1009 1009
 }
1010 1010
 
@@ -1017,83 +1017,83 @@  discard block
 block discarded – undo
1017 1017
  * @global wpdb $wpdb WordPress database abstraction object.
1018 1018
  */
1019 1019
 function upgrade_130() {
1020
-	global $wpdb;
1021
-
1022
-	// Remove extraneous backslashes.
1023
-	$posts = $wpdb->get_results( "SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts" );
1024
-	if ( $posts ) {
1025
-		foreach ( $posts as $post ) {
1026
-			$post_content = addslashes( deslash( $post->post_content ) );
1027
-			$post_title   = addslashes( deslash( $post->post_title ) );
1028
-			$post_excerpt = addslashes( deslash( $post->post_excerpt ) );
1029
-			if ( empty( $post->guid ) ) {
1030
-				$guid = get_permalink( $post->ID );
1031
-			} else {
1032
-				$guid = $post->guid;
1033
-			}
1034
-
1035
-			$wpdb->update( $wpdb->posts, compact( 'post_title', 'post_content', 'post_excerpt', 'guid' ), array( 'ID' => $post->ID ) );
1036
-
1037
-		}
1038
-	}
1039
-
1040
-	// Remove extraneous backslashes.
1041
-	$comments = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments" );
1042
-	if ( $comments ) {
1043
-		foreach ( $comments as $comment ) {
1044
-			$comment_content = deslash( $comment->comment_content );
1045
-			$comment_author  = deslash( $comment->comment_author );
1046
-
1047
-			$wpdb->update( $wpdb->comments, compact( 'comment_content', 'comment_author' ), array( 'comment_ID' => $comment->comment_ID ) );
1048
-		}
1049
-	}
1050
-
1051
-	// Remove extraneous backslashes.
1052
-	$links = $wpdb->get_results( "SELECT link_id, link_name, link_description FROM $wpdb->links" );
1053
-	if ( $links ) {
1054
-		foreach ( $links as $link ) {
1055
-			$link_name        = deslash( $link->link_name );
1056
-			$link_description = deslash( $link->link_description );
1057
-
1058
-			$wpdb->update( $wpdb->links, compact( 'link_name', 'link_description' ), array( 'link_id' => $link->link_id ) );
1059
-		}
1060
-	}
1061
-
1062
-	$active_plugins = __get_option( 'active_plugins' );
1063
-
1064
-	/*
1020
+    global $wpdb;
1021
+
1022
+    // Remove extraneous backslashes.
1023
+    $posts = $wpdb->get_results( "SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts" );
1024
+    if ( $posts ) {
1025
+        foreach ( $posts as $post ) {
1026
+            $post_content = addslashes( deslash( $post->post_content ) );
1027
+            $post_title   = addslashes( deslash( $post->post_title ) );
1028
+            $post_excerpt = addslashes( deslash( $post->post_excerpt ) );
1029
+            if ( empty( $post->guid ) ) {
1030
+                $guid = get_permalink( $post->ID );
1031
+            } else {
1032
+                $guid = $post->guid;
1033
+            }
1034
+
1035
+            $wpdb->update( $wpdb->posts, compact( 'post_title', 'post_content', 'post_excerpt', 'guid' ), array( 'ID' => $post->ID ) );
1036
+
1037
+        }
1038
+    }
1039
+
1040
+    // Remove extraneous backslashes.
1041
+    $comments = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments" );
1042
+    if ( $comments ) {
1043
+        foreach ( $comments as $comment ) {
1044
+            $comment_content = deslash( $comment->comment_content );
1045
+            $comment_author  = deslash( $comment->comment_author );
1046
+
1047
+            $wpdb->update( $wpdb->comments, compact( 'comment_content', 'comment_author' ), array( 'comment_ID' => $comment->comment_ID ) );
1048
+        }
1049
+    }
1050
+
1051
+    // Remove extraneous backslashes.
1052
+    $links = $wpdb->get_results( "SELECT link_id, link_name, link_description FROM $wpdb->links" );
1053
+    if ( $links ) {
1054
+        foreach ( $links as $link ) {
1055
+            $link_name        = deslash( $link->link_name );
1056
+            $link_description = deslash( $link->link_description );
1057
+
1058
+            $wpdb->update( $wpdb->links, compact( 'link_name', 'link_description' ), array( 'link_id' => $link->link_id ) );
1059
+        }
1060
+    }
1061
+
1062
+    $active_plugins = __get_option( 'active_plugins' );
1063
+
1064
+    /*
1065 1065
 	 * If plugins are not stored in an array, they're stored in the old
1066 1066
 	 * newline separated format. Convert to new format.
1067 1067
 	 */
1068
-	if ( ! is_array( $active_plugins ) ) {
1069
-		$active_plugins = explode( "\n", trim( $active_plugins ) );
1070
-		update_option( 'active_plugins', $active_plugins );
1071
-	}
1072
-
1073
-	// Obsolete tables.
1074
-	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' );
1075
-	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' );
1076
-	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups' );
1077
-	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' );
1078
-
1079
-	// Update comments table to use comment_type.
1080
-	$wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" );
1081
-	$wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );
1082
-
1083
-	// Some versions have multiple duplicate option_name rows with the same values.
1084
-	$options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
1085
-	foreach ( $options as $option ) {
1086
-		if ( 1 != $option->dupes ) { // Could this be done in the query?
1087
-			$limit    = $option->dupes - 1;
1088
-			$dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
1089
-			if ( $dupe_ids ) {
1090
-				$dupe_ids = implode( ',', $dupe_ids );
1091
-				$wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
1092
-			}
1093
-		}
1094
-	}
1095
-
1096
-	make_site_theme();
1068
+    if ( ! is_array( $active_plugins ) ) {
1069
+        $active_plugins = explode( "\n", trim( $active_plugins ) );
1070
+        update_option( 'active_plugins', $active_plugins );
1071
+    }
1072
+
1073
+    // Obsolete tables.
1074
+    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' );
1075
+    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' );
1076
+    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups' );
1077
+    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' );
1078
+
1079
+    // Update comments table to use comment_type.
1080
+    $wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" );
1081
+    $wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );
1082
+
1083
+    // Some versions have multiple duplicate option_name rows with the same values.
1084
+    $options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
1085
+    foreach ( $options as $option ) {
1086
+        if ( 1 != $option->dupes ) { // Could this be done in the query?
1087
+            $limit    = $option->dupes - 1;
1088
+            $dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
1089
+            if ( $dupe_ids ) {
1090
+                $dupe_ids = implode( ',', $dupe_ids );
1091
+                $wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
1092
+            }
1093
+        }
1094
+    }
1095
+
1096
+    make_site_theme();
1097 1097
 }
1098 1098
 
1099 1099
 /**
@@ -1106,113 +1106,113 @@  discard block
 block discarded – undo
1106 1106
  * @global int  $wp_current_db_version The old (current) database version.
1107 1107
  */
1108 1108
 function upgrade_160() {
1109
-	global $wpdb, $wp_current_db_version;
1110
-
1111
-	populate_roles_160();
1112
-
1113
-	$users = $wpdb->get_results( "SELECT * FROM $wpdb->users" );
1114
-	foreach ( $users as $user ) :
1115
-		if ( ! empty( $user->user_firstname ) ) {
1116
-			update_user_meta( $user->ID, 'first_name', wp_slash( $user->user_firstname ) );
1117
-		}
1118
-		if ( ! empty( $user->user_lastname ) ) {
1119
-			update_user_meta( $user->ID, 'last_name', wp_slash( $user->user_lastname ) );
1120
-		}
1121
-		if ( ! empty( $user->user_nickname ) ) {
1122
-			update_user_meta( $user->ID, 'nickname', wp_slash( $user->user_nickname ) );
1123
-		}
1124
-		if ( ! empty( $user->user_level ) ) {
1125
-			update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
1126
-		}
1127
-		if ( ! empty( $user->user_icq ) ) {
1128
-			update_user_meta( $user->ID, 'icq', wp_slash( $user->user_icq ) );
1129
-		}
1130
-		if ( ! empty( $user->user_aim ) ) {
1131
-			update_user_meta( $user->ID, 'aim', wp_slash( $user->user_aim ) );
1132
-		}
1133
-		if ( ! empty( $user->user_msn ) ) {
1134
-			update_user_meta( $user->ID, 'msn', wp_slash( $user->user_msn ) );
1135
-		}
1136
-		if ( ! empty( $user->user_yim ) ) {
1137
-			update_user_meta( $user->ID, 'yim', wp_slash( $user->user_icq ) );
1138
-		}
1139
-		if ( ! empty( $user->user_description ) ) {
1140
-			update_user_meta( $user->ID, 'description', wp_slash( $user->user_description ) );
1141
-		}
1142
-
1143
-		if ( isset( $user->user_idmode ) ) :
1144
-			$idmode = $user->user_idmode;
1145
-			if ( 'nickname' === $idmode ) {
1146
-				$id = $user->user_nickname;
1147
-			}
1148
-			if ( 'login' === $idmode ) {
1149
-				$id = $user->user_login;
1150
-			}
1151
-			if ( 'firstname' === $idmode ) {
1152
-				$id = $user->user_firstname;
1153
-			}
1154
-			if ( 'lastname' === $idmode ) {
1155
-				$id = $user->user_lastname;
1156
-			}
1157
-			if ( 'namefl' === $idmode ) {
1158
-				$id = $user->user_firstname . ' ' . $user->user_lastname;
1159
-			}
1160
-			if ( 'namelf' === $idmode ) {
1161
-				$id = $user->user_lastname . ' ' . $user->user_firstname;
1162
-			}
1163
-			if ( ! $idmode ) {
1164
-				$id = $user->user_nickname;
1165
-			}
1166
-			$wpdb->update( $wpdb->users, array( 'display_name' => $id ), array( 'ID' => $user->ID ) );
1167
-		endif;
1168
-
1169
-		// FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
1170
-		$caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities' );
1171
-		if ( empty( $caps ) || defined( 'RESET_CAPS' ) ) {
1172
-			$level = get_user_meta( $user->ID, $wpdb->prefix . 'user_level', true );
1173
-			$role  = translate_level_to_role( $level );
1174
-			update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array( $role => true ) );
1175
-		}
1176
-
1177
-	endforeach;
1178
-	$old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' );
1179
-	$wpdb->hide_errors();
1180
-	foreach ( $old_user_fields as $old ) {
1181
-		$wpdb->query( "ALTER TABLE $wpdb->users DROP $old" );
1182
-	}
1183
-	$wpdb->show_errors();
1184
-
1185
-	// Populate comment_count field of posts table.
1186
-	$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
1187
-	if ( is_array( $comments ) ) {
1188
-		foreach ( $comments as $comment ) {
1189
-			$wpdb->update( $wpdb->posts, array( 'comment_count' => $comment->c ), array( 'ID' => $comment->comment_post_ID ) );
1190
-		}
1191
-	}
1192
-
1193
-	/*
1109
+    global $wpdb, $wp_current_db_version;
1110
+
1111
+    populate_roles_160();
1112
+
1113
+    $users = $wpdb->get_results( "SELECT * FROM $wpdb->users" );
1114
+    foreach ( $users as $user ) :
1115
+        if ( ! empty( $user->user_firstname ) ) {
1116
+            update_user_meta( $user->ID, 'first_name', wp_slash( $user->user_firstname ) );
1117
+        }
1118
+        if ( ! empty( $user->user_lastname ) ) {
1119
+            update_user_meta( $user->ID, 'last_name', wp_slash( $user->user_lastname ) );
1120
+        }
1121
+        if ( ! empty( $user->user_nickname ) ) {
1122
+            update_user_meta( $user->ID, 'nickname', wp_slash( $user->user_nickname ) );
1123
+        }
1124
+        if ( ! empty( $user->user_level ) ) {
1125
+            update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
1126
+        }
1127
+        if ( ! empty( $user->user_icq ) ) {
1128
+            update_user_meta( $user->ID, 'icq', wp_slash( $user->user_icq ) );
1129
+        }
1130
+        if ( ! empty( $user->user_aim ) ) {
1131
+            update_user_meta( $user->ID, 'aim', wp_slash( $user->user_aim ) );
1132
+        }
1133
+        if ( ! empty( $user->user_msn ) ) {
1134
+            update_user_meta( $user->ID, 'msn', wp_slash( $user->user_msn ) );
1135
+        }
1136
+        if ( ! empty( $user->user_yim ) ) {
1137
+            update_user_meta( $user->ID, 'yim', wp_slash( $user->user_icq ) );
1138
+        }
1139
+        if ( ! empty( $user->user_description ) ) {
1140
+            update_user_meta( $user->ID, 'description', wp_slash( $user->user_description ) );
1141
+        }
1142
+
1143
+        if ( isset( $user->user_idmode ) ) :
1144
+            $idmode = $user->user_idmode;
1145
+            if ( 'nickname' === $idmode ) {
1146
+                $id = $user->user_nickname;
1147
+            }
1148
+            if ( 'login' === $idmode ) {
1149
+                $id = $user->user_login;
1150
+            }
1151
+            if ( 'firstname' === $idmode ) {
1152
+                $id = $user->user_firstname;
1153
+            }
1154
+            if ( 'lastname' === $idmode ) {
1155
+                $id = $user->user_lastname;
1156
+            }
1157
+            if ( 'namefl' === $idmode ) {
1158
+                $id = $user->user_firstname . ' ' . $user->user_lastname;
1159
+            }
1160
+            if ( 'namelf' === $idmode ) {
1161
+                $id = $user->user_lastname . ' ' . $user->user_firstname;
1162
+            }
1163
+            if ( ! $idmode ) {
1164
+                $id = $user->user_nickname;
1165
+            }
1166
+            $wpdb->update( $wpdb->users, array( 'display_name' => $id ), array( 'ID' => $user->ID ) );
1167
+        endif;
1168
+
1169
+        // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
1170
+        $caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities' );
1171
+        if ( empty( $caps ) || defined( 'RESET_CAPS' ) ) {
1172
+            $level = get_user_meta( $user->ID, $wpdb->prefix . 'user_level', true );
1173
+            $role  = translate_level_to_role( $level );
1174
+            update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array( $role => true ) );
1175
+        }
1176
+
1177
+    endforeach;
1178
+    $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' );
1179
+    $wpdb->hide_errors();
1180
+    foreach ( $old_user_fields as $old ) {
1181
+        $wpdb->query( "ALTER TABLE $wpdb->users DROP $old" );
1182
+    }
1183
+    $wpdb->show_errors();
1184
+
1185
+    // Populate comment_count field of posts table.
1186
+    $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
1187
+    if ( is_array( $comments ) ) {
1188
+        foreach ( $comments as $comment ) {
1189
+            $wpdb->update( $wpdb->posts, array( 'comment_count' => $comment->c ), array( 'ID' => $comment->comment_post_ID ) );
1190
+        }
1191
+    }
1192
+
1193
+    /*
1194 1194
 	 * Some alpha versions used a post status of object instead of attachment
1195 1195
 	 * and put the mime type in post_type instead of post_mime_type.
1196 1196
 	 */
1197
-	if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
1198
-		$objects = $wpdb->get_results( "SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'" );
1199
-		foreach ( $objects as $object ) {
1200
-			$wpdb->update(
1201
-				$wpdb->posts,
1202
-				array(
1203
-					'post_status'    => 'attachment',
1204
-					'post_mime_type' => $object->post_type,
1205
-					'post_type'      => '',
1206
-				),
1207
-				array( 'ID' => $object->ID )
1208
-			);
1209
-
1210
-			$meta = get_post_meta( $object->ID, 'imagedata', true );
1211
-			if ( ! empty( $meta['file'] ) ) {
1212
-				update_attached_file( $object->ID, $meta['file'] );
1213
-			}
1214
-		}
1215
-	}
1197
+    if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
1198
+        $objects = $wpdb->get_results( "SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'" );
1199
+        foreach ( $objects as $object ) {
1200
+            $wpdb->update(
1201
+                $wpdb->posts,
1202
+                array(
1203
+                    'post_status'    => 'attachment',
1204
+                    'post_mime_type' => $object->post_type,
1205
+                    'post_type'      => '',
1206
+                ),
1207
+                array( 'ID' => $object->ID )
1208
+            );
1209
+
1210
+            $meta = get_post_meta( $object->ID, 'imagedata', true );
1211
+            if ( ! empty( $meta['file'] ) ) {
1212
+                update_attached_file( $object->ID, $meta['file'] );
1213
+            }
1214
+        }
1215
+    }
1216 1216
 }
1217 1217
 
1218 1218
 /**
@@ -1225,46 +1225,46 @@  discard block
 block discarded – undo
1225 1225
  * @global wpdb $wpdb                  WordPress database abstraction object.
1226 1226
  */
1227 1227
 function upgrade_210() {
1228
-	global $wp_current_db_version, $wpdb;
1229
-
1230
-	if ( $wp_current_db_version < 3506 ) {
1231
-		// Update status and type.
1232
-		$posts = $wpdb->get_results( "SELECT ID, post_status FROM $wpdb->posts" );
1233
-
1234
-		if ( ! empty( $posts ) ) {
1235
-			foreach ( $posts as $post ) {
1236
-				$status = $post->post_status;
1237
-				$type   = 'post';
1238
-
1239
-				if ( 'static' === $status ) {
1240
-					$status = 'publish';
1241
-					$type   = 'page';
1242
-				} elseif ( 'attachment' === $status ) {
1243
-					$status = 'inherit';
1244
-					$type   = 'attachment';
1245
-				}
1246
-
1247
-				$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID ) );
1248
-			}
1249
-		}
1250
-	}
1251
-
1252
-	if ( $wp_current_db_version < 3845 ) {
1253
-		populate_roles_210();
1254
-	}
1255
-
1256
-	if ( $wp_current_db_version < 3531 ) {
1257
-		// Give future posts a post_status of future.
1258
-		$now = gmdate( 'Y-m-d H:i:59' );
1259
-		$wpdb->query( "UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'" );
1260
-
1261
-		$posts = $wpdb->get_results( "SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'" );
1262
-		if ( ! empty( $posts ) ) {
1263
-			foreach ( $posts as $post ) {
1264
-				wp_schedule_single_event( mysql2date( 'U', $post->post_date, false ), 'publish_future_post', array( $post->ID ) );
1265
-			}
1266
-		}
1267
-	}
1228
+    global $wp_current_db_version, $wpdb;
1229
+
1230
+    if ( $wp_current_db_version < 3506 ) {
1231
+        // Update status and type.
1232
+        $posts = $wpdb->get_results( "SELECT ID, post_status FROM $wpdb->posts" );
1233
+
1234
+        if ( ! empty( $posts ) ) {
1235
+            foreach ( $posts as $post ) {
1236
+                $status = $post->post_status;
1237
+                $type   = 'post';
1238
+
1239
+                if ( 'static' === $status ) {
1240
+                    $status = 'publish';
1241
+                    $type   = 'page';
1242
+                } elseif ( 'attachment' === $status ) {
1243
+                    $status = 'inherit';
1244
+                    $type   = 'attachment';
1245
+                }
1246
+
1247
+                $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID ) );
1248
+            }
1249
+        }
1250
+    }
1251
+
1252
+    if ( $wp_current_db_version < 3845 ) {
1253
+        populate_roles_210();
1254
+    }
1255
+
1256
+    if ( $wp_current_db_version < 3531 ) {
1257
+        // Give future posts a post_status of future.
1258
+        $now = gmdate( 'Y-m-d H:i:59' );
1259
+        $wpdb->query( "UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'" );
1260
+
1261
+        $posts = $wpdb->get_results( "SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'" );
1262
+        if ( ! empty( $posts ) ) {
1263
+            foreach ( $posts as $post ) {
1264
+                wp_schedule_single_event( mysql2date( 'U', $post->post_date, false ), 'publish_future_post', array( $post->ID ) );
1265
+            }
1266
+        }
1267
+    }
1268 1268
 }
1269 1269
 
1270 1270
 /**
@@ -1277,221 +1277,221 @@  discard block
 block discarded – undo
1277 1277
  * @global wpdb $wpdb                  WordPress database abstraction object.
1278 1278
  */
1279 1279
 function upgrade_230() {
1280
-	global $wp_current_db_version, $wpdb;
1281
-
1282
-	if ( $wp_current_db_version < 5200 ) {
1283
-		populate_roles_230();
1284
-	}
1285
-
1286
-	// Convert categories to terms.
1287
-	$tt_ids     = array();
1288
-	$have_tags  = false;
1289
-	$categories = $wpdb->get_results( "SELECT * FROM $wpdb->categories ORDER BY cat_ID" );
1290
-	foreach ( $categories as $category ) {
1291
-		$term_id     = (int) $category->cat_ID;
1292
-		$name        = $category->cat_name;
1293
-		$description = $category->category_description;
1294
-		$slug        = $category->category_nicename;
1295
-		$parent      = $category->category_parent;
1296
-		$term_group  = 0;
1297
-
1298
-		// Associate terms with the same slug in a term group and make slugs unique.
1299
-		$exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
1300
-		if ( $exists ) {
1301
-			$term_group = $exists[0]->term_group;
1302
-			$id         = $exists[0]->term_id;
1303
-			$num        = 2;
1304
-			do {
1305
-				$alt_slug = $slug . "-$num";
1306
-				$num++;
1307
-				$slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) );
1308
-			} while ( $slug_check );
1309
-
1310
-			$slug = $alt_slug;
1311
-
1312
-			if ( empty( $term_group ) ) {
1313
-				$term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group" ) + 1;
1314
-				$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id ) );
1315
-			}
1316
-		}
1317
-
1318
-		$wpdb->query(
1319
-			$wpdb->prepare(
1320
-				"INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES
1280
+    global $wp_current_db_version, $wpdb;
1281
+
1282
+    if ( $wp_current_db_version < 5200 ) {
1283
+        populate_roles_230();
1284
+    }
1285
+
1286
+    // Convert categories to terms.
1287
+    $tt_ids     = array();
1288
+    $have_tags  = false;
1289
+    $categories = $wpdb->get_results( "SELECT * FROM $wpdb->categories ORDER BY cat_ID" );
1290
+    foreach ( $categories as $category ) {
1291
+        $term_id     = (int) $category->cat_ID;
1292
+        $name        = $category->cat_name;
1293
+        $description = $category->category_description;
1294
+        $slug        = $category->category_nicename;
1295
+        $parent      = $category->category_parent;
1296
+        $term_group  = 0;
1297
+
1298
+        // Associate terms with the same slug in a term group and make slugs unique.
1299
+        $exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
1300
+        if ( $exists ) {
1301
+            $term_group = $exists[0]->term_group;
1302
+            $id         = $exists[0]->term_id;
1303
+            $num        = 2;
1304
+            do {
1305
+                $alt_slug = $slug . "-$num";
1306
+                $num++;
1307
+                $slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) );
1308
+            } while ( $slug_check );
1309
+
1310
+            $slug = $alt_slug;
1311
+
1312
+            if ( empty( $term_group ) ) {
1313
+                $term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group" ) + 1;
1314
+                $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id ) );
1315
+            }
1316
+        }
1317
+
1318
+        $wpdb->query(
1319
+            $wpdb->prepare(
1320
+                "INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES
1321 1321
 		(%d, %s, %s, %d)",
1322
-				$term_id,
1323
-				$name,
1324
-				$slug,
1325
-				$term_group
1326
-			)
1327
-		);
1328
-
1329
-		$count = 0;
1330
-		if ( ! empty( $category->category_count ) ) {
1331
-			$count    = (int) $category->category_count;
1332
-			$taxonomy = 'category';
1333
-			$wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
1334
-			$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1335
-		}
1336
-
1337
-		if ( ! empty( $category->link_count ) ) {
1338
-			$count    = (int) $category->link_count;
1339
-			$taxonomy = 'link_category';
1340
-			$wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
1341
-			$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1342
-		}
1343
-
1344
-		if ( ! empty( $category->tag_count ) ) {
1345
-			$have_tags = true;
1346
-			$count     = (int) $category->tag_count;
1347
-			$taxonomy  = 'post_tag';
1348
-			$wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
1349
-			$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1350
-		}
1351
-
1352
-		if ( empty( $count ) ) {
1353
-			$count    = 0;
1354
-			$taxonomy = 'category';
1355
-			$wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
1356
-			$tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1357
-		}
1358
-	}
1359
-
1360
-	$select = 'post_id, category_id';
1361
-	if ( $have_tags ) {
1362
-		$select .= ', rel_type';
1363
-	}
1364
-
1365
-	$posts = $wpdb->get_results( "SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id" );
1366
-	foreach ( $posts as $post ) {
1367
-		$post_id  = (int) $post->post_id;
1368
-		$term_id  = (int) $post->category_id;
1369
-		$taxonomy = 'category';
1370
-		if ( ! empty( $post->rel_type ) && 'tag' === $post->rel_type ) {
1371
-			$taxonomy = 'tag';
1372
-		}
1373
-		$tt_id = $tt_ids[ $term_id ][ $taxonomy ];
1374
-		if ( empty( $tt_id ) ) {
1375
-			continue;
1376
-		}
1377
-
1378
-		$wpdb->insert(
1379
-			$wpdb->term_relationships,
1380
-			array(
1381
-				'object_id'        => $post_id,
1382
-				'term_taxonomy_id' => $tt_id,
1383
-			)
1384
-		);
1385
-	}
1386
-
1387
-	// < 3570 we used linkcategories. >= 3570 we used categories and link2cat.
1388
-	if ( $wp_current_db_version < 3570 ) {
1389
-		/*
1322
+                $term_id,
1323
+                $name,
1324
+                $slug,
1325
+                $term_group
1326
+            )
1327
+        );
1328
+
1329
+        $count = 0;
1330
+        if ( ! empty( $category->category_count ) ) {
1331
+            $count    = (int) $category->category_count;
1332
+            $taxonomy = 'category';
1333
+            $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
1334
+            $tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1335
+        }
1336
+
1337
+        if ( ! empty( $category->link_count ) ) {
1338
+            $count    = (int) $category->link_count;
1339
+            $taxonomy = 'link_category';
1340
+            $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
1341
+            $tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1342
+        }
1343
+
1344
+        if ( ! empty( $category->tag_count ) ) {
1345
+            $have_tags = true;
1346
+            $count     = (int) $category->tag_count;
1347
+            $taxonomy  = 'post_tag';
1348
+            $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
1349
+            $tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1350
+        }
1351
+
1352
+        if ( empty( $count ) ) {
1353
+            $count    = 0;
1354
+            $taxonomy = 'category';
1355
+            $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
1356
+            $tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1357
+        }
1358
+    }
1359
+
1360
+    $select = 'post_id, category_id';
1361
+    if ( $have_tags ) {
1362
+        $select .= ', rel_type';
1363
+    }
1364
+
1365
+    $posts = $wpdb->get_results( "SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id" );
1366
+    foreach ( $posts as $post ) {
1367
+        $post_id  = (int) $post->post_id;
1368
+        $term_id  = (int) $post->category_id;
1369
+        $taxonomy = 'category';
1370
+        if ( ! empty( $post->rel_type ) && 'tag' === $post->rel_type ) {
1371
+            $taxonomy = 'tag';
1372
+        }
1373
+        $tt_id = $tt_ids[ $term_id ][ $taxonomy ];
1374
+        if ( empty( $tt_id ) ) {
1375
+            continue;
1376
+        }
1377
+
1378
+        $wpdb->insert(
1379
+            $wpdb->term_relationships,
1380
+            array(
1381
+                'object_id'        => $post_id,
1382
+                'term_taxonomy_id' => $tt_id,
1383
+            )
1384
+        );
1385
+    }
1386
+
1387
+    // < 3570 we used linkcategories. >= 3570 we used categories and link2cat.
1388
+    if ( $wp_current_db_version < 3570 ) {
1389
+        /*
1390 1390
 		 * Create link_category terms for link categories. Create a map of link
1391 1391
 		 * category IDs to link_category terms.
1392 1392
 		 */
1393
-		$link_cat_id_map  = array();
1394
-		$default_link_cat = 0;
1395
-		$tt_ids           = array();
1396
-		$link_cats        = $wpdb->get_results( 'SELECT cat_id, cat_name FROM ' . $wpdb->prefix . 'linkcategories' );
1397
-		foreach ( $link_cats as $category ) {
1398
-			$cat_id     = (int) $category->cat_id;
1399
-			$term_id    = 0;
1400
-			$name       = wp_slash( $category->cat_name );
1401
-			$slug       = sanitize_title( $name );
1402
-			$term_group = 0;
1403
-
1404
-			// Associate terms with the same slug in a term group and make slugs unique.
1405
-			$exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
1406
-			if ( $exists ) {
1407
-				$term_group = $exists[0]->term_group;
1408
-				$term_id    = $exists[0]->term_id;
1409
-			}
1410
-
1411
-			if ( empty( $term_id ) ) {
1412
-				$wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) );
1413
-				$term_id = (int) $wpdb->insert_id;
1414
-			}
1415
-
1416
-			$link_cat_id_map[ $cat_id ] = $term_id;
1417
-			$default_link_cat           = $term_id;
1418
-
1419
-			$wpdb->insert(
1420
-				$wpdb->term_taxonomy,
1421
-				array(
1422
-					'term_id'     => $term_id,
1423
-					'taxonomy'    => 'link_category',
1424
-					'description' => '',
1425
-					'parent'      => 0,
1426
-					'count'       => 0,
1427
-				)
1428
-			);
1429
-			$tt_ids[ $term_id ] = (int) $wpdb->insert_id;
1430
-		}
1431
-
1432
-		// Associate links to categories.
1433
-		$links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" );
1434
-		if ( ! empty( $links ) ) {
1435
-			foreach ( $links as $link ) {
1436
-				if ( 0 == $link->link_category ) {
1437
-					continue;
1438
-				}
1439
-				if ( ! isset( $link_cat_id_map[ $link->link_category ] ) ) {
1440
-					continue;
1441
-				}
1442
-				$term_id = $link_cat_id_map[ $link->link_category ];
1443
-				$tt_id   = $tt_ids[ $term_id ];
1444
-				if ( empty( $tt_id ) ) {
1445
-					continue;
1446
-				}
1447
-
1448
-				$wpdb->insert(
1449
-					$wpdb->term_relationships,
1450
-					array(
1451
-						'object_id'        => $link->link_id,
1452
-						'term_taxonomy_id' => $tt_id,
1453
-					)
1454
-				);
1455
-			}
1456
-		}
1457
-
1458
-		// Set default to the last category we grabbed during the upgrade loop.
1459
-		update_option( 'default_link_category', $default_link_cat );
1460
-	} else {
1461
-		$links = $wpdb->get_results( "SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id" );
1462
-		foreach ( $links as $link ) {
1463
-			$link_id  = (int) $link->link_id;
1464
-			$term_id  = (int) $link->category_id;
1465
-			$taxonomy = 'link_category';
1466
-			$tt_id    = $tt_ids[ $term_id ][ $taxonomy ];
1467
-			if ( empty( $tt_id ) ) {
1468
-				continue;
1469
-			}
1470
-			$wpdb->insert(
1471
-				$wpdb->term_relationships,
1472
-				array(
1473
-					'object_id'        => $link_id,
1474
-					'term_taxonomy_id' => $tt_id,
1475
-				)
1476
-			);
1477
-		}
1478
-	}
1479
-
1480
-	if ( $wp_current_db_version < 4772 ) {
1481
-		// Obsolete linkcategories table.
1482
-		$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' );
1483
-	}
1484
-
1485
-	// Recalculate all counts.
1486
-	$terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" );
1487
-	foreach ( (array) $terms as $term ) {
1488
-		if ( 'post_tag' === $term->taxonomy || 'category' === $term->taxonomy ) {
1489
-			$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id ) );
1490
-		} else {
1491
-			$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id ) );
1492
-		}
1493
-		$wpdb->update( $wpdb->term_taxonomy, array( 'count' => $count ), array( 'term_taxonomy_id' => $term->term_taxonomy_id ) );
1494
-	}
1393
+        $link_cat_id_map  = array();
1394
+        $default_link_cat = 0;
1395
+        $tt_ids           = array();
1396
+        $link_cats        = $wpdb->get_results( 'SELECT cat_id, cat_name FROM ' . $wpdb->prefix . 'linkcategories' );
1397
+        foreach ( $link_cats as $category ) {
1398
+            $cat_id     = (int) $category->cat_id;
1399
+            $term_id    = 0;
1400
+            $name       = wp_slash( $category->cat_name );
1401
+            $slug       = sanitize_title( $name );
1402
+            $term_group = 0;
1403
+
1404
+            // Associate terms with the same slug in a term group and make slugs unique.
1405
+            $exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
1406
+            if ( $exists ) {
1407
+                $term_group = $exists[0]->term_group;
1408
+                $term_id    = $exists[0]->term_id;
1409
+            }
1410
+
1411
+            if ( empty( $term_id ) ) {
1412
+                $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) );
1413
+                $term_id = (int) $wpdb->insert_id;
1414
+            }
1415
+
1416
+            $link_cat_id_map[ $cat_id ] = $term_id;
1417
+            $default_link_cat           = $term_id;
1418
+
1419
+            $wpdb->insert(
1420
+                $wpdb->term_taxonomy,
1421
+                array(
1422
+                    'term_id'     => $term_id,
1423
+                    'taxonomy'    => 'link_category',
1424
+                    'description' => '',
1425
+                    'parent'      => 0,
1426
+                    'count'       => 0,
1427
+                )
1428
+            );
1429
+            $tt_ids[ $term_id ] = (int) $wpdb->insert_id;
1430
+        }
1431
+
1432
+        // Associate links to categories.
1433
+        $links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" );
1434
+        if ( ! empty( $links ) ) {
1435
+            foreach ( $links as $link ) {
1436
+                if ( 0 == $link->link_category ) {
1437
+                    continue;
1438
+                }
1439
+                if ( ! isset( $link_cat_id_map[ $link->link_category ] ) ) {
1440
+                    continue;
1441
+                }
1442
+                $term_id = $link_cat_id_map[ $link->link_category ];
1443
+                $tt_id   = $tt_ids[ $term_id ];
1444
+                if ( empty( $tt_id ) ) {
1445
+                    continue;
1446
+                }
1447
+
1448
+                $wpdb->insert(
1449
+                    $wpdb->term_relationships,
1450
+                    array(
1451
+                        'object_id'        => $link->link_id,
1452
+                        'term_taxonomy_id' => $tt_id,
1453
+                    )
1454
+                );
1455
+            }
1456
+        }
1457
+
1458
+        // Set default to the last category we grabbed during the upgrade loop.
1459
+        update_option( 'default_link_category', $default_link_cat );
1460
+    } else {
1461
+        $links = $wpdb->get_results( "SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id" );
1462
+        foreach ( $links as $link ) {
1463
+            $link_id  = (int) $link->link_id;
1464
+            $term_id  = (int) $link->category_id;
1465
+            $taxonomy = 'link_category';
1466
+            $tt_id    = $tt_ids[ $term_id ][ $taxonomy ];
1467
+            if ( empty( $tt_id ) ) {
1468
+                continue;
1469
+            }
1470
+            $wpdb->insert(
1471
+                $wpdb->term_relationships,
1472
+                array(
1473
+                    'object_id'        => $link_id,
1474
+                    'term_taxonomy_id' => $tt_id,
1475
+                )
1476
+            );
1477
+        }
1478
+    }
1479
+
1480
+    if ( $wp_current_db_version < 4772 ) {
1481
+        // Obsolete linkcategories table.
1482
+        $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' );
1483
+    }
1484
+
1485
+    // Recalculate all counts.
1486
+    $terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" );
1487
+    foreach ( (array) $terms as $term ) {
1488
+        if ( 'post_tag' === $term->taxonomy || 'category' === $term->taxonomy ) {
1489
+            $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id ) );
1490
+        } else {
1491
+            $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id ) );
1492
+        }
1493
+        $wpdb->update( $wpdb->term_taxonomy, array( 'count' => $count ), array( 'term_taxonomy_id' => $term->term_taxonomy_id ) );
1494
+    }
1495 1495
 }
1496 1496
 
1497 1497
 /**
@@ -1503,13 +1503,13 @@  discard block
 block discarded – undo
1503 1503
  * @global wpdb $wpdb WordPress database abstraction object.
1504 1504
  */
1505 1505
 function upgrade_230_options_table() {
1506
-	global $wpdb;
1507
-	$old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' );
1508
-	$wpdb->hide_errors();
1509
-	foreach ( $old_options_fields as $old ) {
1510
-		$wpdb->query( "ALTER TABLE $wpdb->options DROP $old" );
1511
-	}
1512
-	$wpdb->show_errors();
1506
+    global $wpdb;
1507
+    $old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' );
1508
+    $wpdb->hide_errors();
1509
+    foreach ( $old_options_fields as $old ) {
1510
+        $wpdb->query( "ALTER TABLE $wpdb->options DROP $old" );
1511
+    }
1512
+    $wpdb->show_errors();
1513 1513
 }
1514 1514
 
1515 1515
 /**
@@ -1521,10 +1521,10 @@  discard block
 block discarded – undo
1521 1521
  * @global wpdb $wpdb WordPress database abstraction object.
1522 1522
  */
1523 1523
 function upgrade_230_old_tables() {
1524
-	global $wpdb;
1525
-	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories' );
1526
-	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat' );
1527
-	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat' );
1524
+    global $wpdb;
1525
+    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories' );
1526
+    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat' );
1527
+    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat' );
1528 1528
 }
1529 1529
 
1530 1530
 /**
@@ -1536,9 +1536,9 @@  discard block
 block discarded – undo
1536 1536
  * @global wpdb $wpdb WordPress database abstraction object.
1537 1537
  */
1538 1538
 function upgrade_old_slugs() {
1539
-	// Upgrade people who were using the Redirect Old Slugs plugin.
1540
-	global $wpdb;
1541
-	$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'" );
1539
+    // Upgrade people who were using the Redirect Old Slugs plugin.
1540
+    global $wpdb;
1541
+    $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'" );
1542 1542
 }
1543 1543
 
1544 1544
 /**
@@ -1550,11 +1550,11 @@  discard block
 block discarded – undo
1550 1550
  * @global int $wp_current_db_version The old (current) database version.
1551 1551
  */
1552 1552
 function upgrade_250() {
1553
-	global $wp_current_db_version;
1553
+    global $wp_current_db_version;
1554 1554
 
1555
-	if ( $wp_current_db_version < 6689 ) {
1556
-		populate_roles_250();
1557
-	}
1555
+    if ( $wp_current_db_version < 6689 ) {
1556
+        populate_roles_250();
1557
+    }
1558 1558
 
1559 1559
 }
1560 1560
 
@@ -1567,9 +1567,9 @@  discard block
 block discarded – undo
1567 1567
  * @global wpdb $wpdb WordPress database abstraction object.
1568 1568
  */
1569 1569
 function upgrade_252() {
1570
-	global $wpdb;
1570
+    global $wpdb;
1571 1571
 
1572
-	$wpdb->query( "UPDATE $wpdb->users SET user_activation_key = ''" );
1572
+    $wpdb->query( "UPDATE $wpdb->users SET user_activation_key = ''" );
1573 1573
 }
1574 1574
 
1575 1575
 /**
@@ -1581,11 +1581,11 @@  discard block
 block discarded – undo
1581 1581
  * @global int $wp_current_db_version The old (current) database version.
1582 1582
  */
1583 1583
 function upgrade_260() {
1584
-	global $wp_current_db_version;
1584
+    global $wp_current_db_version;
1585 1585
 
1586
-	if ( $wp_current_db_version < 8000 ) {
1587
-		populate_roles_260();
1588
-	}
1586
+    if ( $wp_current_db_version < 8000 ) {
1587
+        populate_roles_260();
1588
+    }
1589 1589
 }
1590 1590
 
1591 1591
 /**
@@ -1598,16 +1598,16 @@  discard block
 block discarded – undo
1598 1598
  * @global wpdb $wpdb                  WordPress database abstraction object.
1599 1599
  */
1600 1600
 function upgrade_270() {
1601
-	global $wp_current_db_version, $wpdb;
1601
+    global $wp_current_db_version, $wpdb;
1602 1602
 
1603
-	if ( $wp_current_db_version < 8980 ) {
1604
-		populate_roles_270();
1605
-	}
1603
+    if ( $wp_current_db_version < 8980 ) {
1604
+        populate_roles_270();
1605
+    }
1606 1606
 
1607
-	// Update post_date for unpublished posts with empty timestamp.
1608
-	if ( $wp_current_db_version < 8921 ) {
1609
-		$wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
1610
-	}
1607
+    // Update post_date for unpublished posts with empty timestamp.
1608
+    if ( $wp_current_db_version < 8921 ) {
1609
+        $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
1610
+    }
1611 1611
 }
1612 1612
 
1613 1613
 /**
@@ -1620,27 +1620,27 @@  discard block
 block discarded – undo
1620 1620
  * @global wpdb $wpdb                  WordPress database abstraction object.
1621 1621
  */
1622 1622
 function upgrade_280() {
1623
-	global $wp_current_db_version, $wpdb;
1624
-
1625
-	if ( $wp_current_db_version < 10360 ) {
1626
-		populate_roles_280();
1627
-	}
1628
-	if ( is_multisite() ) {
1629
-		$start = 0;
1630
-		while ( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
1631
-			foreach ( $rows as $row ) {
1632
-				$value = maybe_unserialize( $row->option_value );
1633
-				if ( $value === $row->option_value ) {
1634
-					$value = stripslashes( $value );
1635
-				}
1636
-				if ( $value !== $row->option_value ) {
1637
-					update_option( $row->option_name, $value );
1638
-				}
1639
-			}
1640
-			$start += 20;
1641
-		}
1642
-		clean_blog_cache( get_current_blog_id() );
1643
-	}
1623
+    global $wp_current_db_version, $wpdb;
1624
+
1625
+    if ( $wp_current_db_version < 10360 ) {
1626
+        populate_roles_280();
1627
+    }
1628
+    if ( is_multisite() ) {
1629
+        $start = 0;
1630
+        while ( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
1631
+            foreach ( $rows as $row ) {
1632
+                $value = maybe_unserialize( $row->option_value );
1633
+                if ( $value === $row->option_value ) {
1634
+                    $value = stripslashes( $value );
1635
+                }
1636
+                if ( $value !== $row->option_value ) {
1637
+                    update_option( $row->option_name, $value );
1638
+                }
1639
+            }
1640
+            $start += 20;
1641
+        }
1642
+        clean_blog_cache( get_current_blog_id() );
1643
+    }
1644 1644
 }
1645 1645
 
1646 1646
 /**
@@ -1652,16 +1652,16 @@  discard block
 block discarded – undo
1652 1652
  * @global int $wp_current_db_version The old (current) database version.
1653 1653
  */
1654 1654
 function upgrade_290() {
1655
-	global $wp_current_db_version;
1656
-
1657
-	if ( $wp_current_db_version < 11958 ) {
1658
-		// Previously, setting depth to 1 would redundantly disable threading,
1659
-		// but now 2 is the minimum depth to avoid confusion.
1660
-		if ( get_option( 'thread_comments_depth' ) == '1' ) {
1661
-			update_option( 'thread_comments_depth', 2 );
1662
-			update_option( 'thread_comments', 0 );
1663
-		}
1664
-	}
1655
+    global $wp_current_db_version;
1656
+
1657
+    if ( $wp_current_db_version < 11958 ) {
1658
+        // Previously, setting depth to 1 would redundantly disable threading,
1659
+        // but now 2 is the minimum depth to avoid confusion.
1660
+        if ( get_option( 'thread_comments_depth' ) == '1' ) {
1661
+            update_option( 'thread_comments_depth', 2 );
1662
+            update_option( 'thread_comments', 0 );
1663
+        }
1664
+    }
1665 1665
 }
1666 1666
 
1667 1667
 /**
@@ -1674,19 +1674,19 @@  discard block
 block discarded – undo
1674 1674
  * @global wpdb $wpdb                  WordPress database abstraction object.
1675 1675
  */
1676 1676
 function upgrade_300() {
1677
-	global $wp_current_db_version, $wpdb;
1677
+    global $wp_current_db_version, $wpdb;
1678 1678
 
1679
-	if ( $wp_current_db_version < 15093 ) {
1680
-		populate_roles_300();
1681
-	}
1679
+    if ( $wp_current_db_version < 15093 ) {
1680
+        populate_roles_300();
1681
+    }
1682 1682
 
1683
-	if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false ) {
1684
-		add_site_option( 'siteurl', '' );
1685
-	}
1683
+    if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false ) {
1684
+        add_site_option( 'siteurl', '' );
1685
+    }
1686 1686
 
1687
-	// 3.0 screen options key name changes.
1688
-	if ( wp_should_upgrade_global_tables() ) {
1689
-		$sql    = "DELETE FROM $wpdb->usermeta
1687
+    // 3.0 screen options key name changes.
1688
+    if ( wp_should_upgrade_global_tables() ) {
1689
+        $sql    = "DELETE FROM $wpdb->usermeta
1690 1690
 			WHERE meta_key LIKE %s
1691 1691
 			OR meta_key LIKE %s
1692 1692
 			OR meta_key LIKE %s
@@ -1699,19 +1699,19 @@  discard block
 block discarded – undo
1699 1699
 			OR meta_key = 'manageeditcolumnshidden'
1700 1700
 			OR meta_key = 'categories_per_page'
1701 1701
 			OR meta_key = 'edit_tags_per_page'";
1702
-		$prefix = $wpdb->esc_like( $wpdb->base_prefix );
1703
-		$wpdb->query(
1704
-			$wpdb->prepare(
1705
-				$sql,
1706
-				$prefix . '%' . $wpdb->esc_like( 'meta-box-hidden' ) . '%',
1707
-				$prefix . '%' . $wpdb->esc_like( 'closedpostboxes' ) . '%',
1708
-				$prefix . '%' . $wpdb->esc_like( 'manage-' ) . '%' . $wpdb->esc_like( '-columns-hidden' ) . '%',
1709
-				$prefix . '%' . $wpdb->esc_like( 'meta-box-order' ) . '%',
1710
-				$prefix . '%' . $wpdb->esc_like( 'metaboxorder' ) . '%',
1711
-				$prefix . '%' . $wpdb->esc_like( 'screen_layout' ) . '%'
1712
-			)
1713
-		);
1714
-	}
1702
+        $prefix = $wpdb->esc_like( $wpdb->base_prefix );
1703
+        $wpdb->query(
1704
+            $wpdb->prepare(
1705
+                $sql,
1706
+                $prefix . '%' . $wpdb->esc_like( 'meta-box-hidden' ) . '%',
1707
+                $prefix . '%' . $wpdb->esc_like( 'closedpostboxes' ) . '%',
1708
+                $prefix . '%' . $wpdb->esc_like( 'manage-' ) . '%' . $wpdb->esc_like( '-columns-hidden' ) . '%',
1709
+                $prefix . '%' . $wpdb->esc_like( 'meta-box-order' ) . '%',
1710
+                $prefix . '%' . $wpdb->esc_like( 'metaboxorder' ) . '%',
1711
+                $prefix . '%' . $wpdb->esc_like( 'screen_layout' ) . '%'
1712
+            )
1713
+        );
1714
+    }
1715 1715
 
1716 1716
 }
1717 1717
 
@@ -1727,73 +1727,73 @@  discard block
 block discarded – undo
1727 1727
  * @global array $sidebars_widgets
1728 1728
  */
1729 1729
 function upgrade_330() {
1730
-	global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets;
1731
-
1732
-	if ( $wp_current_db_version < 19061 && wp_should_upgrade_global_tables() ) {
1733
-		$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" );
1734
-	}
1735
-
1736
-	if ( $wp_current_db_version >= 11548 ) {
1737
-		return;
1738
-	}
1739
-
1740
-	$sidebars_widgets  = get_option( 'sidebars_widgets', array() );
1741
-	$_sidebars_widgets = array();
1742
-
1743
-	if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) || empty( $sidebars_widgets ) ) {
1744
-		$sidebars_widgets['array_version'] = 3;
1745
-	} elseif ( ! isset( $sidebars_widgets['array_version'] ) ) {
1746
-		$sidebars_widgets['array_version'] = 1;
1747
-	}
1748
-
1749
-	switch ( $sidebars_widgets['array_version'] ) {
1750
-		case 1:
1751
-			foreach ( (array) $sidebars_widgets as $index => $sidebar ) {
1752
-				if ( is_array( $sidebar ) ) {
1753
-					foreach ( (array) $sidebar as $i => $name ) {
1754
-						$id = strtolower( $name );
1755
-						if ( isset( $wp_registered_widgets[ $id ] ) ) {
1756
-							$_sidebars_widgets[ $index ][ $i ] = $id;
1757
-							continue;
1758
-						}
1759
-						$id = sanitize_title( $name );
1760
-						if ( isset( $wp_registered_widgets[ $id ] ) ) {
1761
-							$_sidebars_widgets[ $index ][ $i ] = $id;
1762
-							continue;
1763
-						}
1764
-
1765
-						$found = false;
1766
-
1767
-						foreach ( $wp_registered_widgets as $widget_id => $widget ) {
1768
-							if ( strtolower( $widget['name'] ) == strtolower( $name ) ) {
1769
-								$_sidebars_widgets[ $index ][ $i ] = $widget['id'];
1770
-								$found                             = true;
1771
-								break;
1772
-							} elseif ( sanitize_title( $widget['name'] ) == sanitize_title( $name ) ) {
1773
-								$_sidebars_widgets[ $index ][ $i ] = $widget['id'];
1774
-								$found                             = true;
1775
-								break;
1776
-							}
1777
-						}
1778
-
1779
-						if ( $found ) {
1780
-							continue;
1781
-						}
1782
-
1783
-						unset( $_sidebars_widgets[ $index ][ $i ] );
1784
-					}
1785
-				}
1786
-			}
1787
-			$_sidebars_widgets['array_version'] = 2;
1788
-			$sidebars_widgets                   = $_sidebars_widgets;
1789
-			unset( $_sidebars_widgets );
1790
-
1791
-			// Intentional fall-through to upgrade to the next version.
1792
-		case 2:
1793
-			$sidebars_widgets                  = retrieve_widgets();
1794
-			$sidebars_widgets['array_version'] = 3;
1795
-			update_option( 'sidebars_widgets', $sidebars_widgets );
1796
-	}
1730
+    global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets;
1731
+
1732
+    if ( $wp_current_db_version < 19061 && wp_should_upgrade_global_tables() ) {
1733
+        $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" );
1734
+    }
1735
+
1736
+    if ( $wp_current_db_version >= 11548 ) {
1737
+        return;
1738
+    }
1739
+
1740
+    $sidebars_widgets  = get_option( 'sidebars_widgets', array() );
1741
+    $_sidebars_widgets = array();
1742
+
1743
+    if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) || empty( $sidebars_widgets ) ) {
1744
+        $sidebars_widgets['array_version'] = 3;
1745
+    } elseif ( ! isset( $sidebars_widgets['array_version'] ) ) {
1746
+        $sidebars_widgets['array_version'] = 1;
1747
+    }
1748
+
1749
+    switch ( $sidebars_widgets['array_version'] ) {
1750
+        case 1:
1751
+            foreach ( (array) $sidebars_widgets as $index => $sidebar ) {
1752
+                if ( is_array( $sidebar ) ) {
1753
+                    foreach ( (array) $sidebar as $i => $name ) {
1754
+                        $id = strtolower( $name );
1755
+                        if ( isset( $wp_registered_widgets[ $id ] ) ) {
1756
+                            $_sidebars_widgets[ $index ][ $i ] = $id;
1757
+                            continue;
1758
+                        }
1759
+                        $id = sanitize_title( $name );
1760
+                        if ( isset( $wp_registered_widgets[ $id ] ) ) {
1761
+                            $_sidebars_widgets[ $index ][ $i ] = $id;
1762
+                            continue;
1763
+                        }
1764
+
1765
+                        $found = false;
1766
+
1767
+                        foreach ( $wp_registered_widgets as $widget_id => $widget ) {
1768
+                            if ( strtolower( $widget['name'] ) == strtolower( $name ) ) {
1769
+                                $_sidebars_widgets[ $index ][ $i ] = $widget['id'];
1770
+                                $found                             = true;
1771
+                                break;
1772
+                            } elseif ( sanitize_title( $widget['name'] ) == sanitize_title( $name ) ) {
1773
+                                $_sidebars_widgets[ $index ][ $i ] = $widget['id'];
1774
+                                $found                             = true;
1775
+                                break;
1776
+                            }
1777
+                        }
1778
+
1779
+                        if ( $found ) {
1780
+                            continue;
1781
+                        }
1782
+
1783
+                        unset( $_sidebars_widgets[ $index ][ $i ] );
1784
+                    }
1785
+                }
1786
+            }
1787
+            $_sidebars_widgets['array_version'] = 2;
1788
+            $sidebars_widgets                   = $_sidebars_widgets;
1789
+            unset( $_sidebars_widgets );
1790
+
1791
+            // Intentional fall-through to upgrade to the next version.
1792
+        case 2:
1793
+            $sidebars_widgets                  = retrieve_widgets();
1794
+            $sidebars_widgets['array_version'] = 3;
1795
+            update_option( 'sidebars_widgets', $sidebars_widgets );
1796
+    }
1797 1797
 }
1798 1798
 
1799 1799
 /**
@@ -1806,31 +1806,31 @@  discard block
 block discarded – undo
1806 1806
  * @global wpdb $wpdb                  WordPress database abstraction object.
1807 1807
  */
1808 1808
 function upgrade_340() {
1809
-	global $wp_current_db_version, $wpdb;
1810
-
1811
-	if ( $wp_current_db_version < 19798 ) {
1812
-		$wpdb->hide_errors();
1813
-		$wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" );
1814
-		$wpdb->show_errors();
1815
-	}
1816
-
1817
-	if ( $wp_current_db_version < 19799 ) {
1818
-		$wpdb->hide_errors();
1819
-		$wpdb->query( "ALTER TABLE $wpdb->comments DROP INDEX comment_approved" );
1820
-		$wpdb->show_errors();
1821
-	}
1822
-
1823
-	if ( $wp_current_db_version < 20022 && wp_should_upgrade_global_tables() ) {
1824
-		$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" );
1825
-	}
1826
-
1827
-	if ( $wp_current_db_version < 20080 ) {
1828
-		if ( 'yes' === $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
1829
-			$uninstall_plugins = get_option( 'uninstall_plugins' );
1830
-			delete_option( 'uninstall_plugins' );
1831
-			add_option( 'uninstall_plugins', $uninstall_plugins, null, 'no' );
1832
-		}
1833
-	}
1809
+    global $wp_current_db_version, $wpdb;
1810
+
1811
+    if ( $wp_current_db_version < 19798 ) {
1812
+        $wpdb->hide_errors();
1813
+        $wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" );
1814
+        $wpdb->show_errors();
1815
+    }
1816
+
1817
+    if ( $wp_current_db_version < 19799 ) {
1818
+        $wpdb->hide_errors();
1819
+        $wpdb->query( "ALTER TABLE $wpdb->comments DROP INDEX comment_approved" );
1820
+        $wpdb->show_errors();
1821
+    }
1822
+
1823
+    if ( $wp_current_db_version < 20022 && wp_should_upgrade_global_tables() ) {
1824
+        $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" );
1825
+    }
1826
+
1827
+    if ( $wp_current_db_version < 20080 ) {
1828
+        if ( 'yes' === $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
1829
+            $uninstall_plugins = get_option( 'uninstall_plugins' );
1830
+            delete_option( 'uninstall_plugins' );
1831
+            add_option( 'uninstall_plugins', $uninstall_plugins, null, 'no' );
1832
+        }
1833
+    }
1834 1834
 }
1835 1835
 
1836 1836
 /**
@@ -1843,31 +1843,31 @@  discard block
 block discarded – undo
1843 1843
  * @global wpdb $wpdb                  WordPress database abstraction object.
1844 1844
  */
1845 1845
 function upgrade_350() {
1846
-	global $wp_current_db_version, $wpdb;
1847
-
1848
-	if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
1849
-		update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options().
1850
-	}
1851
-
1852
-	if ( $wp_current_db_version < 21811 && wp_should_upgrade_global_tables() ) {
1853
-		$meta_keys = array();
1854
-		foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) {
1855
-			if ( false !== strpos( $name, '-' ) ) {
1856
-				$meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page';
1857
-			}
1858
-		}
1859
-		if ( $meta_keys ) {
1860
-			$meta_keys = implode( "', '", $meta_keys );
1861
-			$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')" );
1862
-		}
1863
-	}
1864
-
1865
-	if ( $wp_current_db_version < 22422 ) {
1866
-		$term = get_term_by( 'slug', 'post-format-standard', 'post_format' );
1867
-		if ( $term ) {
1868
-			wp_delete_term( $term->term_id, 'post_format' );
1869
-		}
1870
-	}
1846
+    global $wp_current_db_version, $wpdb;
1847
+
1848
+    if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
1849
+        update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options().
1850
+    }
1851
+
1852
+    if ( $wp_current_db_version < 21811 && wp_should_upgrade_global_tables() ) {
1853
+        $meta_keys = array();
1854
+        foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) {
1855
+            if ( false !== strpos( $name, '-' ) ) {
1856
+                $meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page';
1857
+            }
1858
+        }
1859
+        if ( $meta_keys ) {
1860
+            $meta_keys = implode( "', '", $meta_keys );
1861
+            $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')" );
1862
+        }
1863
+    }
1864
+
1865
+    if ( $wp_current_db_version < 22422 ) {
1866
+        $term = get_term_by( 'slug', 'post-format-standard', 'post_format' );
1867
+        if ( $term ) {
1868
+            wp_delete_term( $term->term_id, 'post_format' );
1869
+        }
1870
+    }
1871 1871
 }
1872 1872
 
1873 1873
 /**
@@ -1879,11 +1879,11 @@  discard block
 block discarded – undo
1879 1879
  * @global int $wp_current_db_version The old (current) database version.
1880 1880
  */
1881 1881
 function upgrade_370() {
1882
-	global $wp_current_db_version;
1882
+    global $wp_current_db_version;
1883 1883
 
1884
-	if ( $wp_current_db_version < 25824 ) {
1885
-		wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' );
1886
-	}
1884
+    if ( $wp_current_db_version < 25824 ) {
1885
+        wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' );
1886
+    }
1887 1887
 }
1888 1888
 
1889 1889
 /**
@@ -1895,11 +1895,11 @@  discard block
 block discarded – undo
1895 1895
  * @global int $wp_current_db_version The old (current) database version.
1896 1896
  */
1897 1897
 function upgrade_372() {
1898
-	global $wp_current_db_version;
1898
+    global $wp_current_db_version;
1899 1899
 
1900
-	if ( $wp_current_db_version < 26148 ) {
1901
-		wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
1902
-	}
1900
+    if ( $wp_current_db_version < 26148 ) {
1901
+        wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
1902
+    }
1903 1903
 }
1904 1904
 
1905 1905
 /**
@@ -1911,11 +1911,11 @@  discard block
 block discarded – undo
1911 1911
  * @global int $wp_current_db_version The old (current) database version.
1912 1912
  */
1913 1913
 function upgrade_380() {
1914
-	global $wp_current_db_version;
1914
+    global $wp_current_db_version;
1915 1915
 
1916
-	if ( $wp_current_db_version < 26691 ) {
1917
-		deactivate_plugins( array( 'mp6/mp6.php' ), true );
1918
-	}
1916
+    if ( $wp_current_db_version < 26691 ) {
1917
+        deactivate_plugins( array( 'mp6/mp6.php' ), true );
1918
+    }
1919 1919
 }
1920 1920
 
1921 1921
 /**
@@ -1927,17 +1927,17 @@  discard block
 block discarded – undo
1927 1927
  * @global int $wp_current_db_version The old (current) database version.
1928 1928
  */
1929 1929
 function upgrade_400() {
1930
-	global $wp_current_db_version;
1931
-
1932
-	if ( $wp_current_db_version < 29630 ) {
1933
-		if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) {
1934
-			if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages(), true ) ) {
1935
-				update_option( 'WPLANG', WPLANG );
1936
-			} else {
1937
-				update_option( 'WPLANG', '' );
1938
-			}
1939
-		}
1940
-	}
1930
+    global $wp_current_db_version;
1931
+
1932
+    if ( $wp_current_db_version < 29630 ) {
1933
+        if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) {
1934
+            if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages(), true ) ) {
1935
+                update_option( 'WPLANG', WPLANG );
1936
+            } else {
1937
+                update_option( 'WPLANG', '' );
1938
+            }
1939
+        }
1940
+    }
1941 1941
 }
1942 1942
 
1943 1943
 /**
@@ -1958,33 +1958,33 @@  discard block
 block discarded – undo
1958 1958
  * @global wpdb $wpdb                  WordPress database abstraction object.
1959 1959
  */
1960 1960
 function upgrade_430() {
1961
-	global $wp_current_db_version, $wpdb;
1962
-
1963
-	if ( $wp_current_db_version < 32364 ) {
1964
-		upgrade_430_fix_comments();
1965
-	}
1966
-
1967
-	// Shared terms are split in a separate process.
1968
-	if ( $wp_current_db_version < 32814 ) {
1969
-		update_option( 'finished_splitting_shared_terms', 0 );
1970
-		wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' );
1971
-	}
1972
-
1973
-	if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
1974
-		if ( is_multisite() ) {
1975
-			$tables = $wpdb->tables( 'blog' );
1976
-		} else {
1977
-			$tables = $wpdb->tables( 'all' );
1978
-			if ( ! wp_should_upgrade_global_tables() ) {
1979
-				$global_tables = $wpdb->tables( 'global' );
1980
-				$tables        = array_diff_assoc( $tables, $global_tables );
1981
-			}
1982
-		}
1983
-
1984
-		foreach ( $tables as $table ) {
1985
-			maybe_convert_table_to_utf8mb4( $table );
1986
-		}
1987
-	}
1961
+    global $wp_current_db_version, $wpdb;
1962
+
1963
+    if ( $wp_current_db_version < 32364 ) {
1964
+        upgrade_430_fix_comments();
1965
+    }
1966
+
1967
+    // Shared terms are split in a separate process.
1968
+    if ( $wp_current_db_version < 32814 ) {
1969
+        update_option( 'finished_splitting_shared_terms', 0 );
1970
+        wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' );
1971
+    }
1972
+
1973
+    if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
1974
+        if ( is_multisite() ) {
1975
+            $tables = $wpdb->tables( 'blog' );
1976
+        } else {
1977
+            $tables = $wpdb->tables( 'all' );
1978
+            if ( ! wp_should_upgrade_global_tables() ) {
1979
+                $global_tables = $wpdb->tables( 'global' );
1980
+                $tables        = array_diff_assoc( $tables, $global_tables );
1981
+            }
1982
+        }
1983
+
1984
+        foreach ( $tables as $table ) {
1985
+            maybe_convert_table_to_utf8mb4( $table );
1986
+        }
1987
+    }
1988 1988
 }
1989 1989
 
1990 1990
 /**
@@ -1996,44 +1996,44 @@  discard block
 block discarded – undo
1996 1996
  * @global wpdb $wpdb WordPress database abstraction object.
1997 1997
  */
1998 1998
 function upgrade_430_fix_comments() {
1999
-	global $wpdb;
2000
-
2001
-	$content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
2002
-
2003
-	if ( is_wp_error( $content_length ) ) {
2004
-		return;
2005
-	}
2006
-
2007
-	if ( false === $content_length ) {
2008
-		$content_length = array(
2009
-			'type'   => 'byte',
2010
-			'length' => 65535,
2011
-		);
2012
-	} elseif ( ! is_array( $content_length ) ) {
2013
-		$length         = (int) $content_length > 0 ? (int) $content_length : 65535;
2014
-		$content_length = array(
2015
-			'type'   => 'byte',
2016
-			'length' => $length,
2017
-		);
2018
-	}
2019
-
2020
-	if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) {
2021
-		// Sites with malformed DB schemas are on their own.
2022
-		return;
2023
-	}
2024
-
2025
-	$allowed_length = (int) $content_length['length'] - 10;
2026
-
2027
-	$comments = $wpdb->get_results(
2028
-		"SELECT `comment_ID` FROM `{$wpdb->comments}`
1999
+    global $wpdb;
2000
+
2001
+    $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
2002
+
2003
+    if ( is_wp_error( $content_length ) ) {
2004
+        return;
2005
+    }
2006
+
2007
+    if ( false === $content_length ) {
2008
+        $content_length = array(
2009
+            'type'   => 'byte',
2010
+            'length' => 65535,
2011
+        );
2012
+    } elseif ( ! is_array( $content_length ) ) {
2013
+        $length         = (int) $content_length > 0 ? (int) $content_length : 65535;
2014
+        $content_length = array(
2015
+            'type'   => 'byte',
2016
+            'length' => $length,
2017
+        );
2018
+    }
2019
+
2020
+    if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) {
2021
+        // Sites with malformed DB schemas are on their own.
2022
+        return;
2023
+    }
2024
+
2025
+    $allowed_length = (int) $content_length['length'] - 10;
2026
+
2027
+    $comments = $wpdb->get_results(
2028
+        "SELECT `comment_ID` FROM `{$wpdb->comments}`
2029 2029
 			WHERE `comment_date_gmt` > '2015-04-26'
2030 2030
 			AND LENGTH( `comment_content` ) >= {$allowed_length}
2031 2031
 			AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )"
2032
-	);
2032
+    );
2033 2033
 
2034
-	foreach ( $comments as $comment ) {
2035
-		wp_delete_comment( $comment->comment_ID, true );
2036
-	}
2034
+    foreach ( $comments as $comment ) {
2035
+        wp_delete_comment( $comment->comment_ID, true );
2036
+    }
2037 2037
 }
2038 2038
 
2039 2039
 /**
@@ -2043,12 +2043,12 @@  discard block
 block discarded – undo
2043 2043
  * @since 4.3.1
2044 2044
  */
2045 2045
 function upgrade_431() {
2046
-	// Fix incorrect cron entries for term splitting.
2047
-	$cron_array = _get_cron_array();
2048
-	if ( isset( $cron_array['wp_batch_split_terms'] ) ) {
2049
-		unset( $cron_array['wp_batch_split_terms'] );
2050
-		_set_cron_array( $cron_array );
2051
-	}
2046
+    // Fix incorrect cron entries for term splitting.
2047
+    $cron_array = _get_cron_array();
2048
+    if ( isset( $cron_array['wp_batch_split_terms'] ) ) {
2049
+        unset( $cron_array['wp_batch_split_terms'] );
2050
+        _set_cron_array( $cron_array );
2051
+    }
2052 2052
 }
2053 2053
 
2054 2054
 /**
@@ -2061,19 +2061,19 @@  discard block
 block discarded – undo
2061 2061
  * @global wpdb $wpdb                  WordPress database abstraction object.
2062 2062
  */
2063 2063
 function upgrade_440() {
2064
-	global $wp_current_db_version, $wpdb;
2065
-
2066
-	if ( $wp_current_db_version < 34030 ) {
2067
-		$wpdb->query( "ALTER TABLE {$wpdb->options} MODIFY option_name VARCHAR(191)" );
2068
-	}
2069
-
2070
-	// Remove the unused 'add_users' role.
2071
-	$roles = wp_roles();
2072
-	foreach ( $roles->role_objects as $role ) {
2073
-		if ( $role->has_cap( 'add_users' ) ) {
2074
-			$role->remove_cap( 'add_users' );
2075
-		}
2076
-	}
2064
+    global $wp_current_db_version, $wpdb;
2065
+
2066
+    if ( $wp_current_db_version < 34030 ) {
2067
+        $wpdb->query( "ALTER TABLE {$wpdb->options} MODIFY option_name VARCHAR(191)" );
2068
+    }
2069
+
2070
+    // Remove the unused 'add_users' role.
2071
+    $roles = wp_roles();
2072
+    foreach ( $roles->role_objects as $role ) {
2073
+        if ( $role->has_cap( 'add_users' ) ) {
2074
+            $role->remove_cap( 'add_users' );
2075
+        }
2076
+    }
2077 2077
 }
2078 2078
 
2079 2079
 /**
@@ -2086,19 +2086,19 @@  discard block
 block discarded – undo
2086 2086
  * @global wpdb $wpdb                  WordPress database abstraction object.
2087 2087
  */
2088 2088
 function upgrade_450() {
2089
-	global $wp_current_db_version, $wpdb;
2089
+    global $wp_current_db_version, $wpdb;
2090 2090
 
2091
-	if ( $wp_current_db_version < 36180 ) {
2092
-		wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
2093
-	}
2091
+    if ( $wp_current_db_version < 36180 ) {
2092
+        wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
2093
+    }
2094 2094
 
2095
-	// Remove unused email confirmation options, moved to usermeta.
2096
-	if ( $wp_current_db_version < 36679 && is_multisite() ) {
2097
-		$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^[0-9]+_new_email$'" );
2098
-	}
2095
+    // Remove unused email confirmation options, moved to usermeta.
2096
+    if ( $wp_current_db_version < 36679 && is_multisite() ) {
2097
+        $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^[0-9]+_new_email$'" );
2098
+    }
2099 2099
 
2100
-	// Remove unused user setting for wpLink.
2101
-	delete_user_setting( 'wplink' );
2100
+    // Remove unused user setting for wpLink.
2101
+    delete_user_setting( 'wplink' );
2102 2102
 }
2103 2103
 
2104 2104
 /**
@@ -2110,27 +2110,27 @@  discard block
 block discarded – undo
2110 2110
  * @global int $wp_current_db_version The old (current) database version.
2111 2111
  */
2112 2112
 function upgrade_460() {
2113
-	global $wp_current_db_version;
2114
-
2115
-	// Remove unused post meta.
2116
-	if ( $wp_current_db_version < 37854 ) {
2117
-		delete_post_meta_by_key( '_post_restored_from' );
2118
-	}
2119
-
2120
-	// Remove plugins with callback as an array object/method as the uninstall hook, see #13786.
2121
-	if ( $wp_current_db_version < 37965 ) {
2122
-		$uninstall_plugins = get_option( 'uninstall_plugins', array() );
2123
-
2124
-		if ( ! empty( $uninstall_plugins ) ) {
2125
-			foreach ( $uninstall_plugins as $basename => $callback ) {
2126
-				if ( is_array( $callback ) && is_object( $callback[0] ) ) {
2127
-					unset( $uninstall_plugins[ $basename ] );
2128
-				}
2129
-			}
2130
-
2131
-			update_option( 'uninstall_plugins', $uninstall_plugins );
2132
-		}
2133
-	}
2113
+    global $wp_current_db_version;
2114
+
2115
+    // Remove unused post meta.
2116
+    if ( $wp_current_db_version < 37854 ) {
2117
+        delete_post_meta_by_key( '_post_restored_from' );
2118
+    }
2119
+
2120
+    // Remove plugins with callback as an array object/method as the uninstall hook, see #13786.
2121
+    if ( $wp_current_db_version < 37965 ) {
2122
+        $uninstall_plugins = get_option( 'uninstall_plugins', array() );
2123
+
2124
+        if ( ! empty( $uninstall_plugins ) ) {
2125
+            foreach ( $uninstall_plugins as $basename => $callback ) {
2126
+                if ( is_array( $callback ) && is_object( $callback[0] ) ) {
2127
+                    unset( $uninstall_plugins[ $basename ] );
2128
+                }
2129
+            }
2130
+
2131
+            update_option( 'uninstall_plugins', $uninstall_plugins );
2132
+        }
2133
+    }
2134 2134
 }
2135 2135
 
2136 2136
 /**
@@ -2150,7 +2150,7 @@  discard block
 block discarded – undo
2150 2150
  * @since 5.1.0
2151 2151
  */
2152 2152
 function upgrade_510() {
2153
-	delete_site_option( 'upgrade_500_was_gutenberg_active' );
2153
+    delete_site_option( 'upgrade_500_was_gutenberg_active' );
2154 2154
 }
2155 2155
 
2156 2156
 /**
@@ -2160,16 +2160,16 @@  discard block
 block discarded – undo
2160 2160
  * @since 5.3.0
2161 2161
  */
2162 2162
 function upgrade_530() {
2163
-	/*
2163
+    /*
2164 2164
 	 * The `admin_email_lifespan` option may have been set by an admin that just logged in,
2165 2165
 	 * saw the verification screen, clicked on a button there, and is now upgrading the db,
2166 2166
 	 * or by populate_options() that is called earlier in upgrade_all().
2167 2167
 	 * In the second case `admin_email_lifespan` should be reset so the verification screen
2168 2168
 	 * is shown next time an admin logs in.
2169 2169
 	 */
2170
-	if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) {
2171
-		update_option( 'admin_email_lifespan', 0 );
2172
-	}
2170
+    if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) {
2171
+        update_option( 'admin_email_lifespan', 0 );
2172
+    }
2173 2173
 }
2174 2174
 
2175 2175
 /**
@@ -2179,35 +2179,35 @@  discard block
 block discarded – undo
2179 2179
  * @since 5.5.0
2180 2180
  */
2181 2181
 function upgrade_550() {
2182
-	global $wp_current_db_version;
2182
+    global $wp_current_db_version;
2183 2183
 
2184
-	if ( $wp_current_db_version < 48121 ) {
2185
-		$comment_previously_approved = get_option( 'comment_whitelist', '' );
2186
-		update_option( 'comment_previously_approved', $comment_previously_approved );
2187
-		delete_option( 'comment_whitelist' );
2188
-	}
2184
+    if ( $wp_current_db_version < 48121 ) {
2185
+        $comment_previously_approved = get_option( 'comment_whitelist', '' );
2186
+        update_option( 'comment_previously_approved', $comment_previously_approved );
2187
+        delete_option( 'comment_whitelist' );
2188
+    }
2189 2189
 
2190
-	if ( $wp_current_db_version < 48575 ) {
2191
-		// Use more clear and inclusive language.
2192
-		$disallowed_list = get_option( 'blacklist_keys' );
2190
+    if ( $wp_current_db_version < 48575 ) {
2191
+        // Use more clear and inclusive language.
2192
+        $disallowed_list = get_option( 'blacklist_keys' );
2193 2193
 
2194
-		/*
2194
+        /*
2195 2195
 		 * This option key was briefly renamed `blocklist_keys`.
2196 2196
 		 * Account for sites that have this key present when the original key does not exist.
2197 2197
 		 */
2198
-		if ( false === $disallowed_list ) {
2199
-			$disallowed_list = get_option( 'blocklist_keys' );
2200
-		}
2201
-
2202
-		update_option( 'disallowed_keys', $disallowed_list );
2203
-		delete_option( 'blacklist_keys' );
2204
-		delete_option( 'blocklist_keys' );
2205
-	}
2206
-
2207
-	if ( $wp_current_db_version < 48748 ) {
2208
-		update_option( 'finished_updating_comment_type', 0 );
2209
-		wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
2210
-	}
2198
+        if ( false === $disallowed_list ) {
2199
+            $disallowed_list = get_option( 'blocklist_keys' );
2200
+        }
2201
+
2202
+        update_option( 'disallowed_keys', $disallowed_list );
2203
+        delete_option( 'blacklist_keys' );
2204
+        delete_option( 'blocklist_keys' );
2205
+    }
2206
+
2207
+    if ( $wp_current_db_version < 48748 ) {
2208
+        update_option( 'finished_updating_comment_type', 0 );
2209
+        wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
2210
+    }
2211 2211
 }
2212 2212
 
2213 2213
 /**
@@ -2217,51 +2217,51 @@  discard block
 block discarded – undo
2217 2217
  * @since 5.6.0
2218 2218
  */
2219 2219
 function upgrade_560() {
2220
-	global $wp_current_db_version, $wpdb;
2220
+    global $wp_current_db_version, $wpdb;
2221 2221
 
2222
-	if ( $wp_current_db_version < 49572 ) {
2223
-		/*
2222
+    if ( $wp_current_db_version < 49572 ) {
2223
+        /*
2224 2224
 		 * Clean up the `post_category` column removed from schema in version 2.8.0.
2225 2225
 		 * Its presence may conflict with `WP_Post::__get()`.
2226 2226
 		 */
2227
-		$post_category_exists = $wpdb->get_var( "SHOW COLUMNS FROM $wpdb->posts LIKE 'post_category'" );
2228
-		if ( ! is_null( $post_category_exists ) ) {
2229
-			$wpdb->query( "ALTER TABLE $wpdb->posts DROP COLUMN `post_category`" );
2230
-		}
2227
+        $post_category_exists = $wpdb->get_var( "SHOW COLUMNS FROM $wpdb->posts LIKE 'post_category'" );
2228
+        if ( ! is_null( $post_category_exists ) ) {
2229
+            $wpdb->query( "ALTER TABLE $wpdb->posts DROP COLUMN `post_category`" );
2230
+        }
2231 2231
 
2232
-		/*
2232
+        /*
2233 2233
 		 * When upgrading from WP < 5.6.0 set the core major auto-updates option to `unset` by default.
2234 2234
 		 * This overrides the same option from populate_options() that is intended for new installs.
2235 2235
 		 * See https://core.trac.wordpress.org/ticket/51742.
2236 2236
 		 */
2237
-		update_option( 'auto_update_core_major', 'unset' );
2238
-	}
2237
+        update_option( 'auto_update_core_major', 'unset' );
2238
+    }
2239 2239
 
2240
-	if ( $wp_current_db_version < 49632 ) {
2241
-		/*
2240
+    if ( $wp_current_db_version < 49632 ) {
2241
+        /*
2242 2242
 		 * Regenerate the .htaccess file to add the `HTTP_AUTHORIZATION` rewrite rule.
2243 2243
 		 * See https://core.trac.wordpress.org/ticket/51723.
2244 2244
 		 */
2245
-		save_mod_rewrite_rules();
2246
-	}
2247
-
2248
-	if ( $wp_current_db_version < 49735 ) {
2249
-		delete_transient( 'dirsize_cache' );
2250
-	}
2251
-
2252
-	if ( $wp_current_db_version < 49752 ) {
2253
-		$results = $wpdb->get_results(
2254
-			$wpdb->prepare(
2255
-				"SELECT 1 FROM {$wpdb->usermeta} WHERE meta_key = %s LIMIT 1",
2256
-				WP_Application_Passwords::USERMETA_KEY_APPLICATION_PASSWORDS
2257
-			)
2258
-		);
2259
-
2260
-		if ( ! empty( $results ) ) {
2261
-			$network_id = get_main_network_id();
2262
-			update_network_option( $network_id, WP_Application_Passwords::OPTION_KEY_IN_USE, 1 );
2263
-		}
2264
-	}
2245
+        save_mod_rewrite_rules();
2246
+    }
2247
+
2248
+    if ( $wp_current_db_version < 49735 ) {
2249
+        delete_transient( 'dirsize_cache' );
2250
+    }
2251
+
2252
+    if ( $wp_current_db_version < 49752 ) {
2253
+        $results = $wpdb->get_results(
2254
+            $wpdb->prepare(
2255
+                "SELECT 1 FROM {$wpdb->usermeta} WHERE meta_key = %s LIMIT 1",
2256
+                WP_Application_Passwords::USERMETA_KEY_APPLICATION_PASSWORDS
2257
+            )
2258
+        );
2259
+
2260
+        if ( ! empty( $results ) ) {
2261
+            $network_id = get_main_network_id();
2262
+            update_network_option( $network_id, WP_Application_Passwords::OPTION_KEY_IN_USE, 1 );
2263
+        }
2264
+    }
2265 2265
 }
2266 2266
 
2267 2267
 /**
@@ -2273,17 +2273,17 @@  discard block
 block discarded – undo
2273 2273
  * @global int $wp_current_db_version The old (current) database version.
2274 2274
  */
2275 2275
 function upgrade_590() {
2276
-	global $wp_current_db_version;
2276
+    global $wp_current_db_version;
2277 2277
 
2278
-	if ( $wp_current_db_version < 51917 ) {
2279
-		$crons = _get_cron_array();
2278
+    if ( $wp_current_db_version < 51917 ) {
2279
+        $crons = _get_cron_array();
2280 2280
 
2281
-		if ( $crons && is_array( $crons ) ) {
2282
-			// Remove errant `false` values, see #53950, #54906.
2283
-			$crons = array_filter( $crons );
2284
-			_set_cron_array( $crons );
2285
-		}
2286
-	}
2281
+        if ( $crons && is_array( $crons ) ) {
2282
+            // Remove errant `false` values, see #53950, #54906.
2283
+            $crons = array_filter( $crons );
2284
+            _set_cron_array( $crons );
2285
+        }
2286
+    }
2287 2287
 }
2288 2288
 
2289 2289
 /**
@@ -2295,11 +2295,11 @@  discard block
 block discarded – undo
2295 2295
  * @global int $wp_current_db_version The old (current) database version.
2296 2296
  */
2297 2297
 function upgrade_600() {
2298
-	global $wp_current_db_version;
2298
+    global $wp_current_db_version;
2299 2299
 
2300
-	if ( $wp_current_db_version < 53011 ) {
2301
-		wp_update_user_counts();
2302
-	}
2300
+    if ( $wp_current_db_version < 53011 ) {
2301
+        wp_update_user_counts();
2302
+    }
2303 2303
 }
2304 2304
 
2305 2305
 /**
@@ -2311,147 +2311,147 @@  discard block
 block discarded – undo
2311 2311
  * @global wpdb $wpdb                  WordPress database abstraction object.
2312 2312
  */
2313 2313
 function upgrade_network() {
2314
-	global $wp_current_db_version, $wpdb;
2315
-
2316
-	// Always clear expired transients.
2317
-	delete_expired_transients( true );
2318
-
2319
-	// 2.8.0
2320
-	if ( $wp_current_db_version < 11549 ) {
2321
-		$wpmu_sitewide_plugins   = get_site_option( 'wpmu_sitewide_plugins' );
2322
-		$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
2323
-		if ( $wpmu_sitewide_plugins ) {
2324
-			if ( ! $active_sitewide_plugins ) {
2325
-				$sitewide_plugins = (array) $wpmu_sitewide_plugins;
2326
-			} else {
2327
-				$sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins );
2328
-			}
2329
-
2330
-			update_site_option( 'active_sitewide_plugins', $sitewide_plugins );
2331
-		}
2332
-		delete_site_option( 'wpmu_sitewide_plugins' );
2333
-		delete_site_option( 'deactivated_sitewide_plugins' );
2334
-
2335
-		$start = 0;
2336
-		while ( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) {
2337
-			foreach ( $rows as $row ) {
2338
-				$value = $row->meta_value;
2339
-				if ( ! @unserialize( $value ) ) {
2340
-					$value = stripslashes( $value );
2341
-				}
2342
-				if ( $value !== $row->meta_value ) {
2343
-					update_site_option( $row->meta_key, $value );
2344
-				}
2345
-			}
2346
-			$start += 20;
2347
-		}
2348
-	}
2349
-
2350
-	// 3.0.0
2351
-	if ( $wp_current_db_version < 13576 ) {
2352
-		update_site_option( 'global_terms_enabled', '1' );
2353
-	}
2354
-
2355
-	// 3.3.0
2356
-	if ( $wp_current_db_version < 19390 ) {
2357
-		update_site_option( 'initial_db_version', $wp_current_db_version );
2358
-	}
2359
-
2360
-	if ( $wp_current_db_version < 19470 ) {
2361
-		if ( false === get_site_option( 'active_sitewide_plugins' ) ) {
2362
-			update_site_option( 'active_sitewide_plugins', array() );
2363
-		}
2364
-	}
2365
-
2366
-	// 3.4.0
2367
-	if ( $wp_current_db_version < 20148 ) {
2368
-		// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
2369
-		$allowedthemes  = get_site_option( 'allowedthemes' );
2370
-		$allowed_themes = get_site_option( 'allowed_themes' );
2371
-		if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) {
2372
-			$converted = array();
2373
-			$themes    = wp_get_themes();
2374
-			foreach ( $themes as $stylesheet => $theme_data ) {
2375
-				if ( isset( $allowed_themes[ $theme_data->get( 'Name' ) ] ) ) {
2376
-					$converted[ $stylesheet ] = true;
2377
-				}
2378
-			}
2379
-			update_site_option( 'allowedthemes', $converted );
2380
-			delete_site_option( 'allowed_themes' );
2381
-		}
2382
-	}
2383
-
2384
-	// 3.5.0
2385
-	if ( $wp_current_db_version < 21823 ) {
2386
-		update_site_option( 'ms_files_rewriting', '1' );
2387
-	}
2388
-
2389
-	// 3.5.2
2390
-	if ( $wp_current_db_version < 24448 ) {
2391
-		$illegal_names = get_site_option( 'illegal_names' );
2392
-		if ( is_array( $illegal_names ) && count( $illegal_names ) === 1 ) {
2393
-			$illegal_name  = reset( $illegal_names );
2394
-			$illegal_names = explode( ' ', $illegal_name );
2395
-			update_site_option( 'illegal_names', $illegal_names );
2396
-		}
2397
-	}
2398
-
2399
-	// 4.2.0
2400
-	if ( $wp_current_db_version < 31351 && 'utf8mb4' === $wpdb->charset ) {
2401
-		if ( wp_should_upgrade_global_tables() ) {
2402
-			$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
2403
-			$wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
2404
-			$wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
2405
-			$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
2406
-
2407
-			$tables = $wpdb->tables( 'global' );
2408
-
2409
-			// sitecategories may not exist.
2410
-			if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) {
2411
-				unset( $tables['sitecategories'] );
2412
-			}
2413
-
2414
-			foreach ( $tables as $table ) {
2415
-				maybe_convert_table_to_utf8mb4( $table );
2416
-			}
2417
-		}
2418
-	}
2419
-
2420
-	// 4.3.0
2421
-	if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
2422
-		if ( wp_should_upgrade_global_tables() ) {
2423
-			$upgrade = false;
2424
-			$indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" );
2425
-			foreach ( $indexes as $index ) {
2426
-				if ( 'domain_path' === $index->Key_name && 'domain' === $index->Column_name && 140 != $index->Sub_part ) {
2427
-					$upgrade = true;
2428
-					break;
2429
-				}
2430
-			}
2431
-
2432
-			if ( $upgrade ) {
2433
-				$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
2434
-			}
2435
-
2436
-			$tables = $wpdb->tables( 'global' );
2437
-
2438
-			// sitecategories may not exist.
2439
-			if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) {
2440
-				unset( $tables['sitecategories'] );
2441
-			}
2442
-
2443
-			foreach ( $tables as $table ) {
2444
-				maybe_convert_table_to_utf8mb4( $table );
2445
-			}
2446
-		}
2447
-	}
2448
-
2449
-	// 5.1.0
2450
-	if ( $wp_current_db_version < 44467 ) {
2451
-		$network_id = get_main_network_id();
2452
-		delete_network_option( $network_id, 'site_meta_supported' );
2453
-		is_site_meta_supported();
2454
-	}
2314
+    global $wp_current_db_version, $wpdb;
2315
+
2316
+    // Always clear expired transients.
2317
+    delete_expired_transients( true );
2318
+
2319
+    // 2.8.0
2320
+    if ( $wp_current_db_version < 11549 ) {
2321
+        $wpmu_sitewide_plugins   = get_site_option( 'wpmu_sitewide_plugins' );
2322
+        $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
2323
+        if ( $wpmu_sitewide_plugins ) {
2324
+            if ( ! $active_sitewide_plugins ) {
2325
+                $sitewide_plugins = (array) $wpmu_sitewide_plugins;
2326
+            } else {
2327
+                $sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins );
2328
+            }
2329
+
2330
+            update_site_option( 'active_sitewide_plugins', $sitewide_plugins );
2331
+        }
2332
+        delete_site_option( 'wpmu_sitewide_plugins' );
2333
+        delete_site_option( 'deactivated_sitewide_plugins' );
2334
+
2335
+        $start = 0;
2336
+        while ( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) {
2337
+            foreach ( $rows as $row ) {
2338
+                $value = $row->meta_value;
2339
+                if ( ! @unserialize( $value ) ) {
2340
+                    $value = stripslashes( $value );
2341
+                }
2342
+                if ( $value !== $row->meta_value ) {
2343
+                    update_site_option( $row->meta_key, $value );
2344
+                }
2345
+            }
2346
+            $start += 20;
2347
+        }
2348
+    }
2349
+
2350
+    // 3.0.0
2351
+    if ( $wp_current_db_version < 13576 ) {
2352
+        update_site_option( 'global_terms_enabled', '1' );
2353
+    }
2354
+
2355
+    // 3.3.0
2356
+    if ( $wp_current_db_version < 19390 ) {
2357
+        update_site_option( 'initial_db_version', $wp_current_db_version );
2358
+    }
2359
+
2360
+    if ( $wp_current_db_version < 19470 ) {
2361
+        if ( false === get_site_option( 'active_sitewide_plugins' ) ) {
2362
+            update_site_option( 'active_sitewide_plugins', array() );
2363
+        }
2364
+    }
2365
+
2366
+    // 3.4.0
2367
+    if ( $wp_current_db_version < 20148 ) {
2368
+        // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
2369
+        $allowedthemes  = get_site_option( 'allowedthemes' );
2370
+        $allowed_themes = get_site_option( 'allowed_themes' );
2371
+        if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) {
2372
+            $converted = array();
2373
+            $themes    = wp_get_themes();
2374
+            foreach ( $themes as $stylesheet => $theme_data ) {
2375
+                if ( isset( $allowed_themes[ $theme_data->get( 'Name' ) ] ) ) {
2376
+                    $converted[ $stylesheet ] = true;
2377
+                }
2378
+            }
2379
+            update_site_option( 'allowedthemes', $converted );
2380
+            delete_site_option( 'allowed_themes' );
2381
+        }
2382
+    }
2383
+
2384
+    // 3.5.0
2385
+    if ( $wp_current_db_version < 21823 ) {
2386
+        update_site_option( 'ms_files_rewriting', '1' );
2387
+    }
2388
+
2389
+    // 3.5.2
2390
+    if ( $wp_current_db_version < 24448 ) {
2391
+        $illegal_names = get_site_option( 'illegal_names' );
2392
+        if ( is_array( $illegal_names ) && count( $illegal_names ) === 1 ) {
2393
+            $illegal_name  = reset( $illegal_names );
2394
+            $illegal_names = explode( ' ', $illegal_name );
2395
+            update_site_option( 'illegal_names', $illegal_names );
2396
+        }
2397
+    }
2398
+
2399
+    // 4.2.0
2400
+    if ( $wp_current_db_version < 31351 && 'utf8mb4' === $wpdb->charset ) {
2401
+        if ( wp_should_upgrade_global_tables() ) {
2402
+            $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
2403
+            $wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
2404
+            $wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
2405
+            $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
2406
+
2407
+            $tables = $wpdb->tables( 'global' );
2408
+
2409
+            // sitecategories may not exist.
2410
+            if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) {
2411
+                unset( $tables['sitecategories'] );
2412
+            }
2413
+
2414
+            foreach ( $tables as $table ) {
2415
+                maybe_convert_table_to_utf8mb4( $table );
2416
+            }
2417
+        }
2418
+    }
2419
+
2420
+    // 4.3.0
2421
+    if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
2422
+        if ( wp_should_upgrade_global_tables() ) {
2423
+            $upgrade = false;
2424
+            $indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" );
2425
+            foreach ( $indexes as $index ) {
2426
+                if ( 'domain_path' === $index->Key_name && 'domain' === $index->Column_name && 140 != $index->Sub_part ) {
2427
+                    $upgrade = true;
2428
+                    break;
2429
+                }
2430
+            }
2431
+
2432
+            if ( $upgrade ) {
2433
+                $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
2434
+            }
2435
+
2436
+            $tables = $wpdb->tables( 'global' );
2437
+
2438
+            // sitecategories may not exist.
2439
+            if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) {
2440
+                unset( $tables['sitecategories'] );
2441
+            }
2442
+
2443
+            foreach ( $tables as $table ) {
2444
+                maybe_convert_table_to_utf8mb4( $table );
2445
+            }
2446
+        }
2447
+    }
2448
+
2449
+    // 5.1.0
2450
+    if ( $wp_current_db_version < 44467 ) {
2451
+        $network_id = get_main_network_id();
2452
+        delete_network_option( $network_id, 'site_meta_supported' );
2453
+        is_site_meta_supported();
2454
+    }
2455 2455
 }
2456 2456
 
2457 2457
 //
@@ -2474,23 +2474,23 @@  discard block
 block discarded – undo
2474 2474
  * @return bool True on success or if the table already exists. False on failure.
2475 2475
  */
2476 2476
 function maybe_create_table( $table_name, $create_ddl ) {
2477
-	global $wpdb;
2477
+    global $wpdb;
2478 2478
 
2479
-	$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
2479
+    $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
2480 2480
 
2481
-	if ( $wpdb->get_var( $query ) === $table_name ) {
2482
-		return true;
2483
-	}
2481
+    if ( $wpdb->get_var( $query ) === $table_name ) {
2482
+        return true;
2483
+    }
2484 2484
 
2485
-	// Didn't find it, so try to create it.
2486
-	$wpdb->query( $create_ddl );
2485
+    // Didn't find it, so try to create it.
2486
+    $wpdb->query( $create_ddl );
2487 2487
 
2488
-	// We cannot directly tell that whether this succeeded!
2489
-	if ( $wpdb->get_var( $query ) === $table_name ) {
2490
-		return true;
2491
-	}
2488
+    // We cannot directly tell that whether this succeeded!
2489
+    if ( $wpdb->get_var( $query ) === $table_name ) {
2490
+        return true;
2491
+    }
2492 2492
 
2493
-	return false;
2493
+    return false;
2494 2494
 }
2495 2495
 
2496 2496
 /**
@@ -2505,20 +2505,20 @@  discard block
 block discarded – undo
2505 2505
  * @return true True, when finished.
2506 2506
  */
2507 2507
 function drop_index( $table, $index ) {
2508
-	global $wpdb;
2508
+    global $wpdb;
2509 2509
 
2510
-	$wpdb->hide_errors();
2510
+    $wpdb->hide_errors();
2511 2511
 
2512
-	$wpdb->query( "ALTER TABLE `$table` DROP INDEX `$index`" );
2512
+    $wpdb->query( "ALTER TABLE `$table` DROP INDEX `$index`" );
2513 2513
 
2514
-	// Now we need to take out all the extra ones we may have created.
2515
-	for ( $i = 0; $i < 25; $i++ ) {
2516
-		$wpdb->query( "ALTER TABLE `$table` DROP INDEX `{$index}_$i`" );
2517
-	}
2514
+    // Now we need to take out all the extra ones we may have created.
2515
+    for ( $i = 0; $i < 25; $i++ ) {
2516
+        $wpdb->query( "ALTER TABLE `$table` DROP INDEX `{$index}_$i`" );
2517
+    }
2518 2518
 
2519
-	$wpdb->show_errors();
2519
+    $wpdb->show_errors();
2520 2520
 
2521
-	return true;
2521
+    return true;
2522 2522
 }
2523 2523
 
2524 2524
 /**
@@ -2533,12 +2533,12 @@  discard block
 block discarded – undo
2533 2533
  * @return true True, when done with execution.
2534 2534
  */
2535 2535
 function add_clean_index( $table, $index ) {
2536
-	global $wpdb;
2536
+    global $wpdb;
2537 2537
 
2538
-	drop_index( $table, $index );
2539
-	$wpdb->query( "ALTER TABLE `$table` ADD INDEX ( `$index` )" );
2538
+    drop_index( $table, $index );
2539
+    $wpdb->query( "ALTER TABLE `$table` ADD INDEX ( `$index` )" );
2540 2540
 
2541
-	return true;
2541
+    return true;
2542 2542
 }
2543 2543
 
2544 2544
 /**
@@ -2554,25 +2554,25 @@  discard block
 block discarded – undo
2554 2554
  * @return bool True on success or if the column already exists. False on failure.
2555 2555
  */
2556 2556
 function maybe_add_column( $table_name, $column_name, $create_ddl ) {
2557
-	global $wpdb;
2557
+    global $wpdb;
2558 2558
 
2559
-	foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
2560
-		if ( $column === $column_name ) {
2561
-			return true;
2562
-		}
2563
-	}
2559
+    foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
2560
+        if ( $column === $column_name ) {
2561
+            return true;
2562
+        }
2563
+    }
2564 2564
 
2565
-	// Didn't find it, so try to create it.
2566
-	$wpdb->query( $create_ddl );
2565
+    // Didn't find it, so try to create it.
2566
+    $wpdb->query( $create_ddl );
2567 2567
 
2568
-	// We cannot directly tell that whether this succeeded!
2569
-	foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
2570
-		if ( $column === $column_name ) {
2571
-			return true;
2572
-		}
2573
-	}
2568
+    // We cannot directly tell that whether this succeeded!
2569
+    foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
2570
+        if ( $column === $column_name ) {
2571
+            return true;
2572
+        }
2573
+    }
2574 2574
 
2575
-	return false;
2575
+    return false;
2576 2576
 }
2577 2577
 
2578 2578
 /**
@@ -2586,36 +2586,36 @@  discard block
 block discarded – undo
2586 2586
  * @return bool True if the table was converted, false if it wasn't.
2587 2587
  */
2588 2588
 function maybe_convert_table_to_utf8mb4( $table ) {
2589
-	global $wpdb;
2590
-
2591
-	$results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" );
2592
-	if ( ! $results ) {
2593
-		return false;
2594
-	}
2595
-
2596
-	foreach ( $results as $column ) {
2597
-		if ( $column->Collation ) {
2598
-			list( $charset ) = explode( '_', $column->Collation );
2599
-			$charset         = strtolower( $charset );
2600
-			if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
2601
-				// Don't upgrade tables that have non-utf8 columns.
2602
-				return false;
2603
-			}
2604
-		}
2605
-	}
2606
-
2607
-	$table_details = $wpdb->get_row( "SHOW TABLE STATUS LIKE '$table'" );
2608
-	if ( ! $table_details ) {
2609
-		return false;
2610
-	}
2611
-
2612
-	list( $table_charset ) = explode( '_', $table_details->Collation );
2613
-	$table_charset         = strtolower( $table_charset );
2614
-	if ( 'utf8mb4' === $table_charset ) {
2615
-		return true;
2616
-	}
2617
-
2618
-	return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" );
2589
+    global $wpdb;
2590
+
2591
+    $results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" );
2592
+    if ( ! $results ) {
2593
+        return false;
2594
+    }
2595
+
2596
+    foreach ( $results as $column ) {
2597
+        if ( $column->Collation ) {
2598
+            list( $charset ) = explode( '_', $column->Collation );
2599
+            $charset         = strtolower( $charset );
2600
+            if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
2601
+                // Don't upgrade tables that have non-utf8 columns.
2602
+                return false;
2603
+            }
2604
+        }
2605
+    }
2606
+
2607
+    $table_details = $wpdb->get_row( "SHOW TABLE STATUS LIKE '$table'" );
2608
+    if ( ! $table_details ) {
2609
+        return false;
2610
+    }
2611
+
2612
+    list( $table_charset ) = explode( '_', $table_details->Collation );
2613
+    $table_charset         = strtolower( $table_charset );
2614
+    if ( 'utf8mb4' === $table_charset ) {
2615
+        return true;
2616
+    }
2617
+
2618
+    return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" );
2619 2619
 }
2620 2620
 
2621 2621
 /**
@@ -2628,18 +2628,18 @@  discard block
 block discarded – undo
2628 2628
  * @return stdClass List of options.
2629 2629
  */
2630 2630
 function get_alloptions_110() {
2631
-	global $wpdb;
2632
-	$all_options = new stdClass;
2633
-	$options     = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
2634
-	if ( $options ) {
2635
-		foreach ( $options as $option ) {
2636
-			if ( 'siteurl' === $option->option_name || 'home' === $option->option_name || 'category_base' === $option->option_name ) {
2637
-				$option->option_value = untrailingslashit( $option->option_value );
2638
-			}
2639
-			$all_options->{$option->option_name} = stripslashes( $option->option_value );
2640
-		}
2641
-	}
2642
-	return $all_options;
2631
+    global $wpdb;
2632
+    $all_options = new stdClass;
2633
+    $options     = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
2634
+    if ( $options ) {
2635
+        foreach ( $options as $option ) {
2636
+            if ( 'siteurl' === $option->option_name || 'home' === $option->option_name || 'category_base' === $option->option_name ) {
2637
+                $option->option_value = untrailingslashit( $option->option_value );
2638
+            }
2639
+            $all_options->{$option->option_name} = stripslashes( $option->option_value );
2640
+        }
2641
+    }
2642
+    return $all_options;
2643 2643
 }
2644 2644
 
2645 2645
 /**
@@ -2655,27 +2655,27 @@  discard block
 block discarded – undo
2655 2655
  * @return mixed
2656 2656
  */
2657 2657
 function __get_option( $setting ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
2658
-	global $wpdb;
2658
+    global $wpdb;
2659 2659
 
2660
-	if ( 'home' === $setting && defined( 'WP_HOME' ) ) {
2661
-		return untrailingslashit( WP_HOME );
2662
-	}
2660
+    if ( 'home' === $setting && defined( 'WP_HOME' ) ) {
2661
+        return untrailingslashit( WP_HOME );
2662
+    }
2663 2663
 
2664
-	if ( 'siteurl' === $setting && defined( 'WP_SITEURL' ) ) {
2665
-		return untrailingslashit( WP_SITEURL );
2666
-	}
2664
+    if ( 'siteurl' === $setting && defined( 'WP_SITEURL' ) ) {
2665
+        return untrailingslashit( WP_SITEURL );
2666
+    }
2667 2667
 
2668
-	$option = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) );
2668
+    $option = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) );
2669 2669
 
2670
-	if ( 'home' === $setting && ! $option ) {
2671
-		return __get_option( 'siteurl' );
2672
-	}
2670
+    if ( 'home' === $setting && ! $option ) {
2671
+        return __get_option( 'siteurl' );
2672
+    }
2673 2673
 
2674
-	if ( in_array( $setting, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) {
2675
-		$option = untrailingslashit( $option );
2676
-	}
2674
+    if ( in_array( $setting, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) {
2675
+        $option = untrailingslashit( $option );
2676
+    }
2677 2677
 
2678
-	return maybe_unserialize( $option );
2678
+    return maybe_unserialize( $option );
2679 2679
 }
2680 2680
 
2681 2681
 /**
@@ -2687,24 +2687,24 @@  discard block
 block discarded – undo
2687 2687
  * @return string The de-slashed content.
2688 2688
  */
2689 2689
 function deslash( $content ) {
2690
-	// Note: \\\ inside a regex denotes a single backslash.
2690
+    // Note: \\\ inside a regex denotes a single backslash.
2691 2691
 
2692
-	/*
2692
+    /*
2693 2693
 	 * Replace one or more backslashes followed by a single quote with
2694 2694
 	 * a single quote.
2695 2695
 	 */
2696
-	$content = preg_replace( "/\\\+'/", "'", $content );
2696
+    $content = preg_replace( "/\\\+'/", "'", $content );
2697 2697
 
2698
-	/*
2698
+    /*
2699 2699
 	 * Replace one or more backslashes followed by a double quote with
2700 2700
 	 * a double quote.
2701 2701
 	 */
2702
-	$content = preg_replace( '/\\\+"/', '"', $content );
2702
+    $content = preg_replace( '/\\\+"/', '"', $content );
2703 2703
 
2704
-	// Replace one or more backslashes with one backslash.
2705
-	$content = preg_replace( '/\\\+/', '\\', $content );
2704
+    // Replace one or more backslashes with one backslash.
2705
+    $content = preg_replace( '/\\\+/', '\\', $content );
2706 2706
 
2707
-	return $content;
2707
+    return $content;
2708 2708
 }
2709 2709
 
2710 2710
 /**
@@ -2724,123 +2724,123 @@  discard block
 block discarded – undo
2724 2724
  * @return array Strings containing the results of the various update queries.
2725 2725
  */
2726 2726
 function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
2727
-	global $wpdb;
2728
-
2729
-	if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) {
2730
-		$queries = wp_get_db_schema( $queries );
2731
-	}
2732
-
2733
-	// Separate individual queries into an array.
2734
-	if ( ! is_array( $queries ) ) {
2735
-		$queries = explode( ';', $queries );
2736
-		$queries = array_filter( $queries );
2737
-	}
2738
-
2739
-	/**
2740
-	 * Filters the dbDelta SQL queries.
2741
-	 *
2742
-	 * @since 3.3.0
2743
-	 *
2744
-	 * @param string[] $queries An array of dbDelta SQL queries.
2745
-	 */
2746
-	$queries = apply_filters( 'dbdelta_queries', $queries );
2747
-
2748
-	$cqueries   = array(); // Creation queries.
2749
-	$iqueries   = array(); // Insertion queries.
2750
-	$for_update = array();
2751
-
2752
-	// Create a tablename index for an array ($cqueries) of queries.
2753
-	foreach ( $queries as $qry ) {
2754
-		if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
2755
-			$cqueries[ trim( $matches[1], '`' ) ] = $qry;
2756
-			$for_update[ $matches[1] ]            = 'Created table ' . $matches[1];
2757
-		} elseif ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) {
2758
-			array_unshift( $cqueries, $qry );
2759
-		} elseif ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) {
2760
-			$iqueries[] = $qry;
2761
-		} elseif ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) {
2762
-			$iqueries[] = $qry;
2763
-		} else {
2764
-			// Unrecognized query type.
2765
-		}
2766
-	}
2767
-
2768
-	/**
2769
-	 * Filters the dbDelta SQL queries for creating tables and/or databases.
2770
-	 *
2771
-	 * Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE".
2772
-	 *
2773
-	 * @since 3.3.0
2774
-	 *
2775
-	 * @param string[] $cqueries An array of dbDelta create SQL queries.
2776
-	 */
2777
-	$cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
2778
-
2779
-	/**
2780
-	 * Filters the dbDelta SQL queries for inserting or updating.
2781
-	 *
2782
-	 * Queries filterable via this hook contain "INSERT INTO" or "UPDATE".
2783
-	 *
2784
-	 * @since 3.3.0
2785
-	 *
2786
-	 * @param string[] $iqueries An array of dbDelta insert or update SQL queries.
2787
-	 */
2788
-	$iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
2789
-
2790
-	$text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' );
2791
-	$blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' );
2792
-
2793
-	$global_tables = $wpdb->tables( 'global' );
2794
-	foreach ( $cqueries as $table => $qry ) {
2795
-		// Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal.
2796
-		if ( in_array( $table, $global_tables, true ) && ! wp_should_upgrade_global_tables() ) {
2797
-			unset( $cqueries[ $table ], $for_update[ $table ] );
2798
-			continue;
2799
-		}
2800
-
2801
-		// Fetch the table column structure from the database.
2802
-		$suppress    = $wpdb->suppress_errors();
2803
-		$tablefields = $wpdb->get_results( "DESCRIBE {$table};" );
2804
-		$wpdb->suppress_errors( $suppress );
2805
-
2806
-		if ( ! $tablefields ) {
2807
-			continue;
2808
-		}
2809
-
2810
-		// Clear the field and index arrays.
2811
-		$cfields                  = array();
2812
-		$indices                  = array();
2813
-		$indices_without_subparts = array();
2814
-
2815
-		// Get all of the field names in the query from between the parentheses.
2816
-		preg_match( '|\((.*)\)|ms', $qry, $match2 );
2817
-		$qryline = trim( $match2[1] );
2818
-
2819
-		// Separate field lines into an array.
2820
-		$flds = explode( "\n", $qryline );
2821
-
2822
-		// For every field line specified in the query.
2823
-		foreach ( $flds as $fld ) {
2824
-			$fld = trim( $fld, " \t\n\r\0\x0B," ); // Default trim characters, plus ','.
2825
-
2826
-			// Extract the field name.
2827
-			preg_match( '|^([^ ]*)|', $fld, $fvals );
2828
-			$fieldname            = trim( $fvals[1], '`' );
2829
-			$fieldname_lowercased = strtolower( $fieldname );
2830
-
2831
-			// Verify the found field name.
2832
-			$validfield = true;
2833
-			switch ( $fieldname_lowercased ) {
2834
-				case '':
2835
-				case 'primary':
2836
-				case 'index':
2837
-				case 'fulltext':
2838
-				case 'unique':
2839
-				case 'key':
2840
-				case 'spatial':
2841
-					$validfield = false;
2842
-
2843
-					/*
2727
+    global $wpdb;
2728
+
2729
+    if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) {
2730
+        $queries = wp_get_db_schema( $queries );
2731
+    }
2732
+
2733
+    // Separate individual queries into an array.
2734
+    if ( ! is_array( $queries ) ) {
2735
+        $queries = explode( ';', $queries );
2736
+        $queries = array_filter( $queries );
2737
+    }
2738
+
2739
+    /**
2740
+     * Filters the dbDelta SQL queries.
2741
+     *
2742
+     * @since 3.3.0
2743
+     *
2744
+     * @param string[] $queries An array of dbDelta SQL queries.
2745
+     */
2746
+    $queries = apply_filters( 'dbdelta_queries', $queries );
2747
+
2748
+    $cqueries   = array(); // Creation queries.
2749
+    $iqueries   = array(); // Insertion queries.
2750
+    $for_update = array();
2751
+
2752
+    // Create a tablename index for an array ($cqueries) of queries.
2753
+    foreach ( $queries as $qry ) {
2754
+        if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
2755
+            $cqueries[ trim( $matches[1], '`' ) ] = $qry;
2756
+            $for_update[ $matches[1] ]            = 'Created table ' . $matches[1];
2757
+        } elseif ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) {
2758
+            array_unshift( $cqueries, $qry );
2759
+        } elseif ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) {
2760
+            $iqueries[] = $qry;
2761
+        } elseif ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) {
2762
+            $iqueries[] = $qry;
2763
+        } else {
2764
+            // Unrecognized query type.
2765
+        }
2766
+    }
2767
+
2768
+    /**
2769
+     * Filters the dbDelta SQL queries for creating tables and/or databases.
2770
+     *
2771
+     * Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE".
2772
+     *
2773
+     * @since 3.3.0
2774
+     *
2775
+     * @param string[] $cqueries An array of dbDelta create SQL queries.
2776
+     */
2777
+    $cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
2778
+
2779
+    /**
2780
+     * Filters the dbDelta SQL queries for inserting or updating.
2781
+     *
2782
+     * Queries filterable via this hook contain "INSERT INTO" or "UPDATE".
2783
+     *
2784
+     * @since 3.3.0
2785
+     *
2786
+     * @param string[] $iqueries An array of dbDelta insert or update SQL queries.
2787
+     */
2788
+    $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
2789
+
2790
+    $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' );
2791
+    $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' );
2792
+
2793
+    $global_tables = $wpdb->tables( 'global' );
2794
+    foreach ( $cqueries as $table => $qry ) {
2795
+        // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal.
2796
+        if ( in_array( $table, $global_tables, true ) && ! wp_should_upgrade_global_tables() ) {
2797
+            unset( $cqueries[ $table ], $for_update[ $table ] );
2798
+            continue;
2799
+        }
2800
+
2801
+        // Fetch the table column structure from the database.
2802
+        $suppress    = $wpdb->suppress_errors();
2803
+        $tablefields = $wpdb->get_results( "DESCRIBE {$table};" );
2804
+        $wpdb->suppress_errors( $suppress );
2805
+
2806
+        if ( ! $tablefields ) {
2807
+            continue;
2808
+        }
2809
+
2810
+        // Clear the field and index arrays.
2811
+        $cfields                  = array();
2812
+        $indices                  = array();
2813
+        $indices_without_subparts = array();
2814
+
2815
+        // Get all of the field names in the query from between the parentheses.
2816
+        preg_match( '|\((.*)\)|ms', $qry, $match2 );
2817
+        $qryline = trim( $match2[1] );
2818
+
2819
+        // Separate field lines into an array.
2820
+        $flds = explode( "\n", $qryline );
2821
+
2822
+        // For every field line specified in the query.
2823
+        foreach ( $flds as $fld ) {
2824
+            $fld = trim( $fld, " \t\n\r\0\x0B," ); // Default trim characters, plus ','.
2825
+
2826
+            // Extract the field name.
2827
+            preg_match( '|^([^ ]*)|', $fld, $fvals );
2828
+            $fieldname            = trim( $fvals[1], '`' );
2829
+            $fieldname_lowercased = strtolower( $fieldname );
2830
+
2831
+            // Verify the found field name.
2832
+            $validfield = true;
2833
+            switch ( $fieldname_lowercased ) {
2834
+                case '':
2835
+                case 'primary':
2836
+                case 'index':
2837
+                case 'fulltext':
2838
+                case 'unique':
2839
+                case 'key':
2840
+                case 'spatial':
2841
+                    $validfield = false;
2842
+
2843
+                    /*
2844 2844
 					 * Normalize the index definition.
2845 2845
 					 *
2846 2846
 					 * This is done so the definition can be compared against the result of a
@@ -2848,246 +2848,246 @@  discard block
 block discarded – undo
2848 2848
 					 * index information.
2849 2849
 					 */
2850 2850
 
2851
-					// Extract type, name and columns from the definition.
2852
-					// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
2853
-					preg_match(
2854
-						'/^'
2855
-						.   '(?P<index_type>'             // 1) Type of the index.
2856
-						.       'PRIMARY\s+KEY|(?:UNIQUE|FULLTEXT|SPATIAL)\s+(?:KEY|INDEX)|KEY|INDEX'
2857
-						.   ')'
2858
-						.   '\s+'                         // Followed by at least one white space character.
2859
-						.   '(?:'                         // Name of the index. Optional if type is PRIMARY KEY.
2860
-						.       '`?'                      // Name can be escaped with a backtick.
2861
-						.           '(?P<index_name>'     // 2) Name of the index.
2862
-						.               '(?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+'
2863
-						.           ')'
2864
-						.       '`?'                      // Name can be escaped with a backtick.
2865
-						.       '\s+'                     // Followed by at least one white space character.
2866
-						.   ')*'
2867
-						.   '\('                          // Opening bracket for the columns.
2868
-						.       '(?P<index_columns>'
2869
-						.           '.+?'                 // 3) Column names, index prefixes, and orders.
2870
-						.       ')'
2871
-						.   '\)'                          // Closing bracket for the columns.
2872
-						. '$/im',
2873
-						$fld,
2874
-						$index_matches
2875
-					);
2876
-					// phpcs:enable
2877
-
2878
-					// Uppercase the index type and normalize space characters.
2879
-					$index_type = strtoupper( preg_replace( '/\s+/', ' ', trim( $index_matches['index_type'] ) ) );
2880
-
2881
-					// 'INDEX' is a synonym for 'KEY', standardize on 'KEY'.
2882
-					$index_type = str_replace( 'INDEX', 'KEY', $index_type );
2883
-
2884
-					// Escape the index name with backticks. An index for a primary key has no name.
2885
-					$index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . strtolower( $index_matches['index_name'] ) . '`';
2886
-
2887
-					// Parse the columns. Multiple columns are separated by a comma.
2888
-					$index_columns                  = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) );
2889
-					$index_columns_without_subparts = $index_columns;
2890
-
2891
-					// Normalize columns.
2892
-					foreach ( $index_columns as $id => &$index_column ) {
2893
-						// Extract column name and number of indexed characters (sub_part).
2894
-						preg_match(
2895
-							'/'
2896
-							. '`?'                      // Name can be escaped with a backtick.
2897
-							. '(?P<column_name>'    // 1) Name of the column.
2898
-							. '(?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+'
2899
-							. ')'
2900
-							. '`?'                      // Name can be escaped with a backtick.
2901
-							. '(?:'                     // Optional sub part.
2902
-							. '\s*'                 // Optional white space character between name and opening bracket.
2903
-							. '\('                  // Opening bracket for the sub part.
2904
-							. '\s*'             // Optional white space character after opening bracket.
2905
-							. '(?P<sub_part>'
2906
-							. '\d+'         // 2) Number of indexed characters.
2907
-							. ')'
2908
-							. '\s*'             // Optional white space character before closing bracket.
2909
-							. '\)'                 // Closing bracket for the sub part.
2910
-							. ')?'
2911
-							. '/',
2912
-							$index_column,
2913
-							$index_column_matches
2914
-						);
2915
-
2916
-						// Escape the column name with backticks.
2917
-						$index_column = '`' . $index_column_matches['column_name'] . '`';
2918
-
2919
-						// We don't need to add the subpart to $index_columns_without_subparts
2920
-						$index_columns_without_subparts[ $id ] = $index_column;
2921
-
2922
-						// Append the optional sup part with the number of indexed characters.
2923
-						if ( isset( $index_column_matches['sub_part'] ) ) {
2924
-							$index_column .= '(' . $index_column_matches['sub_part'] . ')';
2925
-						}
2926
-					}
2927
-
2928
-					// Build the normalized index definition and add it to the list of indices.
2929
-					$indices[]                  = "{$index_type} {$index_name} (" . implode( ',', $index_columns ) . ')';
2930
-					$indices_without_subparts[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns_without_subparts ) . ')';
2931
-
2932
-					// Destroy no longer needed variables.
2933
-					unset( $index_column, $index_column_matches, $index_matches, $index_type, $index_name, $index_columns, $index_columns_without_subparts );
2934
-
2935
-					break;
2936
-			}
2937
-
2938
-			// If it's a valid field, add it to the field array.
2939
-			if ( $validfield ) {
2940
-				$cfields[ $fieldname_lowercased ] = $fld;
2941
-			}
2942
-		}
2943
-
2944
-		// For every field in the table.
2945
-		foreach ( $tablefields as $tablefield ) {
2946
-			$tablefield_field_lowercased = strtolower( $tablefield->Field );
2947
-			$tablefield_type_lowercased  = strtolower( $tablefield->Type );
2948
-
2949
-			// If the table field exists in the field array...
2950
-			if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
2951
-
2952
-				// Get the field type from the query.
2953
-				preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
2954
-				$fieldtype            = $matches[1];
2955
-				$fieldtype_lowercased = strtolower( $fieldtype );
2956
-
2957
-				// Is actual field type different from the field type in query?
2958
-				if ( $tablefield->Type != $fieldtype ) {
2959
-					$do_change = true;
2960
-					if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) {
2961
-						if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) {
2962
-							$do_change = false;
2963
-						}
2964
-					}
2965
-
2966
-					if ( in_array( $fieldtype_lowercased, $blob_fields, true ) && in_array( $tablefield_type_lowercased, $blob_fields, true ) ) {
2967
-						if ( array_search( $fieldtype_lowercased, $blob_fields, true ) < array_search( $tablefield_type_lowercased, $blob_fields, true ) ) {
2968
-							$do_change = false;
2969
-						}
2970
-					}
2971
-
2972
-					if ( $do_change ) {
2973
-						// Add a query to change the column type.
2974
-						$cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ];
2975
-
2976
-						$for_update[ $table . '.' . $tablefield->Field ] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
2977
-					}
2978
-				}
2979
-
2980
-				// Get the default value from the array.
2981
-				if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) {
2982
-					$default_value = $matches[1];
2983
-					if ( $tablefield->Default != $default_value ) {
2984
-						// Add a query to change the column's default value
2985
-						$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
2986
-
2987
-						$for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
2988
-					}
2989
-				}
2990
-
2991
-				// Remove the field from the array (so it's not added).
2992
-				unset( $cfields[ $tablefield_field_lowercased ] );
2993
-			} else {
2994
-				// This field exists in the table, but not in the creation queries?
2995
-			}
2996
-		}
2997
-
2998
-		// For every remaining field specified for the table.
2999
-		foreach ( $cfields as $fieldname => $fielddef ) {
3000
-			// Push a query line into $cqueries that adds the field to that table.
3001
-			$cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
3002
-
3003
-			$for_update[ $table . '.' . $fieldname ] = 'Added column ' . $table . '.' . $fieldname;
3004
-		}
3005
-
3006
-		// Index stuff goes here. Fetch the table index structure from the database.
3007
-		$tableindices = $wpdb->get_results( "SHOW INDEX FROM {$table};" );
3008
-
3009
-		if ( $tableindices ) {
3010
-			// Clear the index array.
3011
-			$index_ary = array();
3012
-
3013
-			// For every index in the table.
3014
-			foreach ( $tableindices as $tableindex ) {
3015
-				$keyname = strtolower( $tableindex->Key_name );
3016
-
3017
-				// Add the index to the index data array.
3018
-				$index_ary[ $keyname ]['columns'][]  = array(
3019
-					'fieldname' => $tableindex->Column_name,
3020
-					'subpart'   => $tableindex->Sub_part,
3021
-				);
3022
-				$index_ary[ $keyname ]['unique']     = ( 0 == $tableindex->Non_unique ) ? true : false;
3023
-				$index_ary[ $keyname ]['index_type'] = $tableindex->Index_type;
3024
-			}
3025
-
3026
-			// For each actual index in the index array.
3027
-			foreach ( $index_ary as $index_name => $index_data ) {
3028
-
3029
-				// Build a create string to compare to the query.
3030
-				$index_string = '';
3031
-				if ( 'primary' === $index_name ) {
3032
-					$index_string .= 'PRIMARY ';
3033
-				} elseif ( $index_data['unique'] ) {
3034
-					$index_string .= 'UNIQUE ';
3035
-				}
3036
-				if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) {
3037
-					$index_string .= 'FULLTEXT ';
3038
-				}
3039
-				if ( 'SPATIAL' === strtoupper( $index_data['index_type'] ) ) {
3040
-					$index_string .= 'SPATIAL ';
3041
-				}
3042
-				$index_string .= 'KEY ';
3043
-				if ( 'primary' !== $index_name ) {
3044
-					$index_string .= '`' . $index_name . '`';
3045
-				}
3046
-				$index_columns = '';
3047
-
3048
-				// For each column in the index.
3049
-				foreach ( $index_data['columns'] as $column_data ) {
3050
-					if ( '' !== $index_columns ) {
3051
-						$index_columns .= ',';
3052
-					}
3053
-
3054
-					// Add the field to the column list string.
3055
-					$index_columns .= '`' . $column_data['fieldname'] . '`';
3056
-				}
3057
-
3058
-				// Add the column list to the index create string.
3059
-				$index_string .= " ($index_columns)";
3060
-
3061
-				// Check if the index definition exists, ignoring subparts.
3062
-				$aindex = array_search( $index_string, $indices_without_subparts, true );
3063
-				if ( false !== $aindex ) {
3064
-					// If the index already exists (even with different subparts), we don't need to create it.
3065
-					unset( $indices_without_subparts[ $aindex ] );
3066
-					unset( $indices[ $aindex ] );
3067
-				}
3068
-			}
3069
-		}
3070
-
3071
-		// For every remaining index specified for the table.
3072
-		foreach ( (array) $indices as $index ) {
3073
-			// Push a query line into $cqueries that adds the index to that table.
3074
-			$cqueries[] = "ALTER TABLE {$table} ADD $index";
3075
-
3076
-			$for_update[] = 'Added index ' . $table . ' ' . $index;
3077
-		}
3078
-
3079
-		// Remove the original table creation query from processing.
3080
-		unset( $cqueries[ $table ], $for_update[ $table ] );
3081
-	}
3082
-
3083
-	$allqueries = array_merge( $cqueries, $iqueries );
3084
-	if ( $execute ) {
3085
-		foreach ( $allqueries as $query ) {
3086
-			$wpdb->query( $query );
3087
-		}
3088
-	}
3089
-
3090
-	return $for_update;
2851
+                    // Extract type, name and columns from the definition.
2852
+                    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
2853
+                    preg_match(
2854
+                        '/^'
2855
+                        .   '(?P<index_type>'             // 1) Type of the index.
2856
+                        .       'PRIMARY\s+KEY|(?:UNIQUE|FULLTEXT|SPATIAL)\s+(?:KEY|INDEX)|KEY|INDEX'
2857
+                        .   ')'
2858
+                        .   '\s+'                         // Followed by at least one white space character.
2859
+                        .   '(?:'                         // Name of the index. Optional if type is PRIMARY KEY.
2860
+                        .       '`?'                      // Name can be escaped with a backtick.
2861
+                        .           '(?P<index_name>'     // 2) Name of the index.
2862
+                        .               '(?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+'
2863
+                        .           ')'
2864
+                        .       '`?'                      // Name can be escaped with a backtick.
2865
+                        .       '\s+'                     // Followed by at least one white space character.
2866
+                        .   ')*'
2867
+                        .   '\('                          // Opening bracket for the columns.
2868
+                        .       '(?P<index_columns>'
2869
+                        .           '.+?'                 // 3) Column names, index prefixes, and orders.
2870
+                        .       ')'
2871
+                        .   '\)'                          // Closing bracket for the columns.
2872
+                        . '$/im',
2873
+                        $fld,
2874
+                        $index_matches
2875
+                    );
2876
+                    // phpcs:enable
2877
+
2878
+                    // Uppercase the index type and normalize space characters.
2879
+                    $index_type = strtoupper( preg_replace( '/\s+/', ' ', trim( $index_matches['index_type'] ) ) );
2880
+
2881
+                    // 'INDEX' is a synonym for 'KEY', standardize on 'KEY'.
2882
+                    $index_type = str_replace( 'INDEX', 'KEY', $index_type );
2883
+
2884
+                    // Escape the index name with backticks. An index for a primary key has no name.
2885
+                    $index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . strtolower( $index_matches['index_name'] ) . '`';
2886
+
2887
+                    // Parse the columns. Multiple columns are separated by a comma.
2888
+                    $index_columns                  = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) );
2889
+                    $index_columns_without_subparts = $index_columns;
2890
+
2891
+                    // Normalize columns.
2892
+                    foreach ( $index_columns as $id => &$index_column ) {
2893
+                        // Extract column name and number of indexed characters (sub_part).
2894
+                        preg_match(
2895
+                            '/'
2896
+                            . '`?'                      // Name can be escaped with a backtick.
2897
+                            . '(?P<column_name>'    // 1) Name of the column.
2898
+                            . '(?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+'
2899
+                            . ')'
2900
+                            . '`?'                      // Name can be escaped with a backtick.
2901
+                            . '(?:'                     // Optional sub part.
2902
+                            . '\s*'                 // Optional white space character between name and opening bracket.
2903
+                            . '\('                  // Opening bracket for the sub part.
2904
+                            . '\s*'             // Optional white space character after opening bracket.
2905
+                            . '(?P<sub_part>'
2906
+                            . '\d+'         // 2) Number of indexed characters.
2907
+                            . ')'
2908
+                            . '\s*'             // Optional white space character before closing bracket.
2909
+                            . '\)'                 // Closing bracket for the sub part.
2910
+                            . ')?'
2911
+                            . '/',
2912
+                            $index_column,
2913
+                            $index_column_matches
2914
+                        );
2915
+
2916
+                        // Escape the column name with backticks.
2917
+                        $index_column = '`' . $index_column_matches['column_name'] . '`';
2918
+
2919
+                        // We don't need to add the subpart to $index_columns_without_subparts
2920
+                        $index_columns_without_subparts[ $id ] = $index_column;
2921
+
2922
+                        // Append the optional sup part with the number of indexed characters.
2923
+                        if ( isset( $index_column_matches['sub_part'] ) ) {
2924
+                            $index_column .= '(' . $index_column_matches['sub_part'] . ')';
2925
+                        }
2926
+                    }
2927
+
2928
+                    // Build the normalized index definition and add it to the list of indices.
2929
+                    $indices[]                  = "{$index_type} {$index_name} (" . implode( ',', $index_columns ) . ')';
2930
+                    $indices_without_subparts[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns_without_subparts ) . ')';
2931
+
2932
+                    // Destroy no longer needed variables.
2933
+                    unset( $index_column, $index_column_matches, $index_matches, $index_type, $index_name, $index_columns, $index_columns_without_subparts );
2934
+
2935
+                    break;
2936
+            }
2937
+
2938
+            // If it's a valid field, add it to the field array.
2939
+            if ( $validfield ) {
2940
+                $cfields[ $fieldname_lowercased ] = $fld;
2941
+            }
2942
+        }
2943
+
2944
+        // For every field in the table.
2945
+        foreach ( $tablefields as $tablefield ) {
2946
+            $tablefield_field_lowercased = strtolower( $tablefield->Field );
2947
+            $tablefield_type_lowercased  = strtolower( $tablefield->Type );
2948
+
2949
+            // If the table field exists in the field array...
2950
+            if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
2951
+
2952
+                // Get the field type from the query.
2953
+                preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
2954
+                $fieldtype            = $matches[1];
2955
+                $fieldtype_lowercased = strtolower( $fieldtype );
2956
+
2957
+                // Is actual field type different from the field type in query?
2958
+                if ( $tablefield->Type != $fieldtype ) {
2959
+                    $do_change = true;
2960
+                    if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) {
2961
+                        if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) {
2962
+                            $do_change = false;
2963
+                        }
2964
+                    }
2965
+
2966
+                    if ( in_array( $fieldtype_lowercased, $blob_fields, true ) && in_array( $tablefield_type_lowercased, $blob_fields, true ) ) {
2967
+                        if ( array_search( $fieldtype_lowercased, $blob_fields, true ) < array_search( $tablefield_type_lowercased, $blob_fields, true ) ) {
2968
+                            $do_change = false;
2969
+                        }
2970
+                    }
2971
+
2972
+                    if ( $do_change ) {
2973
+                        // Add a query to change the column type.
2974
+                        $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ];
2975
+
2976
+                        $for_update[ $table . '.' . $tablefield->Field ] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
2977
+                    }
2978
+                }
2979
+
2980
+                // Get the default value from the array.
2981
+                if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) {
2982
+                    $default_value = $matches[1];
2983
+                    if ( $tablefield->Default != $default_value ) {
2984
+                        // Add a query to change the column's default value
2985
+                        $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
2986
+
2987
+                        $for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
2988
+                    }
2989
+                }
2990
+
2991
+                // Remove the field from the array (so it's not added).
2992
+                unset( $cfields[ $tablefield_field_lowercased ] );
2993
+            } else {
2994
+                // This field exists in the table, but not in the creation queries?
2995
+            }
2996
+        }
2997
+
2998
+        // For every remaining field specified for the table.
2999
+        foreach ( $cfields as $fieldname => $fielddef ) {
3000
+            // Push a query line into $cqueries that adds the field to that table.
3001
+            $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
3002
+
3003
+            $for_update[ $table . '.' . $fieldname ] = 'Added column ' . $table . '.' . $fieldname;
3004
+        }
3005
+
3006
+        // Index stuff goes here. Fetch the table index structure from the database.
3007
+        $tableindices = $wpdb->get_results( "SHOW INDEX FROM {$table};" );
3008
+
3009
+        if ( $tableindices ) {
3010
+            // Clear the index array.
3011
+            $index_ary = array();
3012
+
3013
+            // For every index in the table.
3014
+            foreach ( $tableindices as $tableindex ) {
3015
+                $keyname = strtolower( $tableindex->Key_name );
3016
+
3017
+                // Add the index to the index data array.
3018
+                $index_ary[ $keyname ]['columns'][]  = array(
3019
+                    'fieldname' => $tableindex->Column_name,
3020
+                    'subpart'   => $tableindex->Sub_part,
3021
+                );
3022
+                $index_ary[ $keyname ]['unique']     = ( 0 == $tableindex->Non_unique ) ? true : false;
3023
+                $index_ary[ $keyname ]['index_type'] = $tableindex->Index_type;
3024
+            }
3025
+
3026
+            // For each actual index in the index array.
3027
+            foreach ( $index_ary as $index_name => $index_data ) {
3028
+
3029
+                // Build a create string to compare to the query.
3030
+                $index_string = '';
3031
+                if ( 'primary' === $index_name ) {
3032
+                    $index_string .= 'PRIMARY ';
3033
+                } elseif ( $index_data['unique'] ) {
3034
+                    $index_string .= 'UNIQUE ';
3035
+                }
3036
+                if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) {
3037
+                    $index_string .= 'FULLTEXT ';
3038
+                }
3039
+                if ( 'SPATIAL' === strtoupper( $index_data['index_type'] ) ) {
3040
+                    $index_string .= 'SPATIAL ';
3041
+                }
3042
+                $index_string .= 'KEY ';
3043
+                if ( 'primary' !== $index_name ) {
3044
+                    $index_string .= '`' . $index_name . '`';
3045
+                }
3046
+                $index_columns = '';
3047
+
3048
+                // For each column in the index.
3049
+                foreach ( $index_data['columns'] as $column_data ) {
3050
+                    if ( '' !== $index_columns ) {
3051
+                        $index_columns .= ',';
3052
+                    }
3053
+
3054
+                    // Add the field to the column list string.
3055
+                    $index_columns .= '`' . $column_data['fieldname'] . '`';
3056
+                }
3057
+
3058
+                // Add the column list to the index create string.
3059
+                $index_string .= " ($index_columns)";
3060
+
3061
+                // Check if the index definition exists, ignoring subparts.
3062
+                $aindex = array_search( $index_string, $indices_without_subparts, true );
3063
+                if ( false !== $aindex ) {
3064
+                    // If the index already exists (even with different subparts), we don't need to create it.
3065
+                    unset( $indices_without_subparts[ $aindex ] );
3066
+                    unset( $indices[ $aindex ] );
3067
+                }
3068
+            }
3069
+        }
3070
+
3071
+        // For every remaining index specified for the table.
3072
+        foreach ( (array) $indices as $index ) {
3073
+            // Push a query line into $cqueries that adds the index to that table.
3074
+            $cqueries[] = "ALTER TABLE {$table} ADD $index";
3075
+
3076
+            $for_update[] = 'Added index ' . $table . ' ' . $index;
3077
+        }
3078
+
3079
+        // Remove the original table creation query from processing.
3080
+        unset( $cqueries[ $table ], $for_update[ $table ] );
3081
+    }
3082
+
3083
+    $allqueries = array_merge( $cqueries, $iqueries );
3084
+    if ( $execute ) {
3085
+        foreach ( $allqueries as $query ) {
3086
+            $wpdb->query( $query );
3087
+        }
3088
+    }
3089
+
3090
+    return $for_update;
3091 3091
 }
3092 3092
 
3093 3093
 /**
@@ -3103,12 +3103,12 @@  discard block
 block discarded – undo
3103 3103
  * @param string $tables Optional. Which set of tables to update. Default is 'all'.
3104 3104
  */
3105 3105
 function make_db_current( $tables = 'all' ) {
3106
-	$alterations = dbDelta( $tables );
3107
-	echo "<ol>\n";
3108
-	foreach ( $alterations as $alteration ) {
3109
-		echo "<li>$alteration</li>\n";
3110
-	}
3111
-	echo "</ol>\n";
3106
+    $alterations = dbDelta( $tables );
3107
+    echo "<ol>\n";
3108
+    foreach ( $alterations as $alteration ) {
3109
+        echo "<li>$alteration</li>\n";
3110
+    }
3111
+    echo "</ol>\n";
3112 3112
 }
3113 3113
 
3114 3114
 /**
@@ -3124,7 +3124,7 @@  discard block
 block discarded – undo
3124 3124
  * @param string $tables Optional. Which set of tables to update. Default is 'all'.
3125 3125
  */
3126 3126
 function make_db_current_silent( $tables = 'all' ) {
3127
-	dbDelta( $tables );
3127
+    dbDelta( $tables );
3128 3128
 }
3129 3129
 
3130 3130
 /**
@@ -3139,85 +3139,85 @@  discard block
 block discarded – undo
3139 3139
  * @return bool
3140 3140
  */
3141 3141
 function make_site_theme_from_oldschool( $theme_name, $template ) {
3142
-	$home_path = get_home_path();
3143
-	$site_dir  = WP_CONTENT_DIR . "/themes/$template";
3142
+    $home_path = get_home_path();
3143
+    $site_dir  = WP_CONTENT_DIR . "/themes/$template";
3144 3144
 
3145
-	if ( ! file_exists( "$home_path/index.php" ) ) {
3146
-		return false;
3147
-	}
3145
+    if ( ! file_exists( "$home_path/index.php" ) ) {
3146
+        return false;
3147
+    }
3148 3148
 
3149
-	/*
3149
+    /*
3150 3150
 	 * Copy files from the old locations to the site theme.
3151 3151
 	 * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
3152 3152
 	 */
3153
-	$files = array(
3154
-		'index.php'             => 'index.php',
3155
-		'wp-layout.css'         => 'style.css',
3156
-		'wp-comments.php'       => 'comments.php',
3157
-		'wp-comments-popup.php' => 'comments-popup.php',
3158
-	);
3159
-
3160
-	foreach ( $files as $oldfile => $newfile ) {
3161
-		if ( 'index.php' === $oldfile ) {
3162
-			$oldpath = $home_path;
3163
-		} else {
3164
-			$oldpath = ABSPATH;
3165
-		}
3166
-
3167
-		// Check to make sure it's not a new index.
3168
-		if ( 'index.php' === $oldfile ) {
3169
-			$index = implode( '', file( "$oldpath/$oldfile" ) );
3170
-			if ( strpos( $index, 'WP_USE_THEMES' ) !== false ) {
3171
-				if ( ! copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) {
3172
-					return false;
3173
-				}
3174
-
3175
-				// Don't copy anything.
3176
-				continue;
3177
-			}
3178
-		}
3179
-
3180
-		if ( ! copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) {
3181
-			return false;
3182
-		}
3183
-
3184
-		chmod( "$site_dir/$newfile", 0777 );
3185
-
3186
-		// Update the blog header include in each file.
3187
-		$lines = explode( "\n", implode( '', file( "$site_dir/$newfile" ) ) );
3188
-		if ( $lines ) {
3189
-			$f = fopen( "$site_dir/$newfile", 'w' );
3190
-
3191
-			foreach ( $lines as $line ) {
3192
-				if ( preg_match( '/require.*wp-blog-header/', $line ) ) {
3193
-					$line = '//' . $line;
3194
-				}
3195
-
3196
-				// Update stylesheet references.
3197
-				$line = str_replace( "<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line );
3198
-
3199
-				// Update comments template inclusion.
3200
-				$line = str_replace( "<?php include(ABSPATH . 'wp-comments.php'); ?>", '<?php comments_template(); ?>', $line );
3201
-
3202
-				fwrite( $f, "{$line}\n" );
3203
-			}
3204
-			fclose( $f );
3205
-		}
3206
-	}
3207
-
3208
-	// Add a theme header.
3209
-	$header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option( 'siteurl' ) . "\nDescription: A theme automatically created by the update.\nVersion: 1.0\nAuthor: Moi\n*/\n";
3210
-
3211
-	$stylelines = file_get_contents( "$site_dir/style.css" );
3212
-	if ( $stylelines ) {
3213
-		$f = fopen( "$site_dir/style.css", 'w' );
3214
-
3215
-		fwrite( $f, $header );
3216
-		fwrite( $f, $stylelines );
3217
-		fclose( $f );
3218
-	}
3219
-
3220
-	return true;
3153
+    $files = array(
3154
+        'index.php'             => 'index.php',
3155
+        'wp-layout.css'         => 'style.css',
3156
+        'wp-comments.php'       => 'comments.php',
3157
+        'wp-comments-popup.php' => 'comments-popup.php',
3158
+    );
3159
+
3160
+    foreach ( $files as $oldfile => $newfile ) {
3161
+        if ( 'index.php' === $oldfile ) {
3162
+            $oldpath = $home_path;
3163
+        } else {
3164
+            $oldpath = ABSPATH;
3165
+        }
3166
+
3167
+        // Check to make sure it's not a new index.
3168
+        if ( 'index.php' === $oldfile ) {
3169
+            $index = implode( '', file( "$oldpath/$oldfile" ) );
3170
+            if ( strpos( $index, 'WP_USE_THEMES' ) !== false ) {
3171
+                if ( ! copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) {
3172
+                    return false;
3173
+                }
3174
+
3175
+                // Don't copy anything.
3176
+                continue;
3177
+            }
3178
+        }
3179
+
3180
+        if ( ! copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) {
3181
+            return false;
3182
+        }
3183
+
3184
+        chmod( "$site_dir/$newfile", 0777 );
3185
+
3186
+        // Update the blog header include in each file.
3187
+        $lines = explode( "\n", implode( '', file( "$site_dir/$newfile" ) ) );
3188
+        if ( $lines ) {
3189
+            $f = fopen( "$site_dir/$newfile", 'w' );
3190
+
3191
+            foreach ( $lines as $line ) {
3192
+                if ( preg_match( '/require.*wp-blog-header/', $line ) ) {
3193
+                    $line = '//' . $line;
3194
+                }
3195
+
3196
+                // Update stylesheet references.
3197
+                $line = str_replace( "<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line );
3198
+
3199
+                // Update comments template inclusion.
3200
+                $line = str_replace( "<?php include(ABSPATH . 'wp-comments.php'); ?>", '<?php comments_template(); ?>', $line );
3201
+
3202
+                fwrite( $f, "{$line}\n" );
3203
+            }
3204
+            fclose( $f );
3205
+        }
3206
+    }
3207
+
3208
+    // Add a theme header.
3209
+    $header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option( 'siteurl' ) . "\nDescription: A theme automatically created by the update.\nVersion: 1.0\nAuthor: Moi\n*/\n";
3210
+
3211
+    $stylelines = file_get_contents( "$site_dir/style.css" );
3212
+    if ( $stylelines ) {
3213
+        $f = fopen( "$site_dir/style.css", 'w' );
3214
+
3215
+        fwrite( $f, $header );
3216
+        fwrite( $f, $stylelines );
3217
+        fclose( $f );
3218
+    }
3219
+
3220
+    return true;
3221 3221
 }
3222 3222
 
3223 3223
 /**
@@ -3232,69 +3232,69 @@  discard block
 block discarded – undo
3232 3232
  * @return void|false
3233 3233
  */
3234 3234
 function make_site_theme_from_default( $theme_name, $template ) {
3235
-	$site_dir    = WP_CONTENT_DIR . "/themes/$template";
3236
-	$default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
3237
-
3238
-	// Copy files from the default theme to the site theme.
3239
-	// $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' );
3240
-
3241
-	$theme_dir = @opendir( $default_dir );
3242
-	if ( $theme_dir ) {
3243
-		while ( ( $theme_file = readdir( $theme_dir ) ) !== false ) {
3244
-			if ( is_dir( "$default_dir/$theme_file" ) ) {
3245
-				continue;
3246
-			}
3247
-			if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) {
3248
-				return;
3249
-			}
3250
-			chmod( "$site_dir/$theme_file", 0777 );
3251
-		}
3252
-
3253
-		closedir( $theme_dir );
3254
-	}
3255
-
3256
-	// Rewrite the theme header.
3257
-	$stylelines = explode( "\n", implode( '', file( "$site_dir/style.css" ) ) );
3258
-	if ( $stylelines ) {
3259
-		$f = fopen( "$site_dir/style.css", 'w' );
3260
-
3261
-		foreach ( $stylelines as $line ) {
3262
-			if ( strpos( $line, 'Theme Name:' ) !== false ) {
3263
-				$line = 'Theme Name: ' . $theme_name;
3264
-			} elseif ( strpos( $line, 'Theme URI:' ) !== false ) {
3265
-				$line = 'Theme URI: ' . __get_option( 'url' );
3266
-			} elseif ( strpos( $line, 'Description:' ) !== false ) {
3267
-				$line = 'Description: Your theme.';
3268
-			} elseif ( strpos( $line, 'Version:' ) !== false ) {
3269
-				$line = 'Version: 1';
3270
-			} elseif ( strpos( $line, 'Author:' ) !== false ) {
3271
-				$line = 'Author: You';
3272
-			}
3273
-			fwrite( $f, $line . "\n" );
3274
-		}
3275
-		fclose( $f );
3276
-	}
3277
-
3278
-	// Copy the images.
3279
-	umask( 0 );
3280
-	if ( ! mkdir( "$site_dir/images", 0777 ) ) {
3281
-		return false;
3282
-	}
3283
-
3284
-	$images_dir = @opendir( "$default_dir/images" );
3285
-	if ( $images_dir ) {
3286
-		while ( ( $image = readdir( $images_dir ) ) !== false ) {
3287
-			if ( is_dir( "$default_dir/images/$image" ) ) {
3288
-				continue;
3289
-			}
3290
-			if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) {
3291
-				return;
3292
-			}
3293
-			chmod( "$site_dir/images/$image", 0777 );
3294
-		}
3295
-
3296
-		closedir( $images_dir );
3297
-	}
3235
+    $site_dir    = WP_CONTENT_DIR . "/themes/$template";
3236
+    $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
3237
+
3238
+    // Copy files from the default theme to the site theme.
3239
+    // $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' );
3240
+
3241
+    $theme_dir = @opendir( $default_dir );
3242
+    if ( $theme_dir ) {
3243
+        while ( ( $theme_file = readdir( $theme_dir ) ) !== false ) {
3244
+            if ( is_dir( "$default_dir/$theme_file" ) ) {
3245
+                continue;
3246
+            }
3247
+            if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) {
3248
+                return;
3249
+            }
3250
+            chmod( "$site_dir/$theme_file", 0777 );
3251
+        }
3252
+
3253
+        closedir( $theme_dir );
3254
+    }
3255
+
3256
+    // Rewrite the theme header.
3257
+    $stylelines = explode( "\n", implode( '', file( "$site_dir/style.css" ) ) );
3258
+    if ( $stylelines ) {
3259
+        $f = fopen( "$site_dir/style.css", 'w' );
3260
+
3261
+        foreach ( $stylelines as $line ) {
3262
+            if ( strpos( $line, 'Theme Name:' ) !== false ) {
3263
+                $line = 'Theme Name: ' . $theme_name;
3264
+            } elseif ( strpos( $line, 'Theme URI:' ) !== false ) {
3265
+                $line = 'Theme URI: ' . __get_option( 'url' );
3266
+            } elseif ( strpos( $line, 'Description:' ) !== false ) {
3267
+                $line = 'Description: Your theme.';
3268
+            } elseif ( strpos( $line, 'Version:' ) !== false ) {
3269
+                $line = 'Version: 1';
3270
+            } elseif ( strpos( $line, 'Author:' ) !== false ) {
3271
+                $line = 'Author: You';
3272
+            }
3273
+            fwrite( $f, $line . "\n" );
3274
+        }
3275
+        fclose( $f );
3276
+    }
3277
+
3278
+    // Copy the images.
3279
+    umask( 0 );
3280
+    if ( ! mkdir( "$site_dir/images", 0777 ) ) {
3281
+        return false;
3282
+    }
3283
+
3284
+    $images_dir = @opendir( "$default_dir/images" );
3285
+    if ( $images_dir ) {
3286
+        while ( ( $image = readdir( $images_dir ) ) !== false ) {
3287
+            if ( is_dir( "$default_dir/images/$image" ) ) {
3288
+                continue;
3289
+            }
3290
+            if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) {
3291
+                return;
3292
+            }
3293
+            chmod( "$site_dir/images/$image", 0777 );
3294
+        }
3295
+
3296
+        closedir( $images_dir );
3297
+    }
3298 3298
 }
3299 3299
 
3300 3300
 /**
@@ -3307,45 +3307,45 @@  discard block
 block discarded – undo
3307 3307
  * @return string|false
3308 3308
  */
3309 3309
 function make_site_theme() {
3310
-	// Name the theme after the blog.
3311
-	$theme_name = __get_option( 'blogname' );
3312
-	$template   = sanitize_title( $theme_name );
3313
-	$site_dir   = WP_CONTENT_DIR . "/themes/$template";
3314
-
3315
-	// If the theme already exists, nothing to do.
3316
-	if ( is_dir( $site_dir ) ) {
3317
-		return false;
3318
-	}
3319
-
3320
-	// We must be able to write to the themes dir.
3321
-	if ( ! is_writable( WP_CONTENT_DIR . '/themes' ) ) {
3322
-		return false;
3323
-	}
3324
-
3325
-	umask( 0 );
3326
-	if ( ! mkdir( $site_dir, 0777 ) ) {
3327
-		return false;
3328
-	}
3329
-
3330
-	if ( file_exists( ABSPATH . 'wp-layout.css' ) ) {
3331
-		if ( ! make_site_theme_from_oldschool( $theme_name, $template ) ) {
3332
-			// TODO: rm -rf the site theme directory.
3333
-			return false;
3334
-		}
3335
-	} else {
3336
-		if ( ! make_site_theme_from_default( $theme_name, $template ) ) {
3337
-			// TODO: rm -rf the site theme directory.
3338
-			return false;
3339
-		}
3340
-	}
3341
-
3342
-	// Make the new site theme active.
3343
-	$current_template = __get_option( 'template' );
3344
-	if ( WP_DEFAULT_THEME == $current_template ) {
3345
-		update_option( 'template', $template );
3346
-		update_option( 'stylesheet', $template );
3347
-	}
3348
-	return $template;
3310
+    // Name the theme after the blog.
3311
+    $theme_name = __get_option( 'blogname' );
3312
+    $template   = sanitize_title( $theme_name );
3313
+    $site_dir   = WP_CONTENT_DIR . "/themes/$template";
3314
+
3315
+    // If the theme already exists, nothing to do.
3316
+    if ( is_dir( $site_dir ) ) {
3317
+        return false;
3318
+    }
3319
+
3320
+    // We must be able to write to the themes dir.
3321
+    if ( ! is_writable( WP_CONTENT_DIR . '/themes' ) ) {
3322
+        return false;
3323
+    }
3324
+
3325
+    umask( 0 );
3326
+    if ( ! mkdir( $site_dir, 0777 ) ) {
3327
+        return false;
3328
+    }
3329
+
3330
+    if ( file_exists( ABSPATH . 'wp-layout.css' ) ) {
3331
+        if ( ! make_site_theme_from_oldschool( $theme_name, $template ) ) {
3332
+            // TODO: rm -rf the site theme directory.
3333
+            return false;
3334
+        }
3335
+    } else {
3336
+        if ( ! make_site_theme_from_default( $theme_name, $template ) ) {
3337
+            // TODO: rm -rf the site theme directory.
3338
+            return false;
3339
+        }
3340
+    }
3341
+
3342
+    // Make the new site theme active.
3343
+    $current_template = __get_option( 'template' );
3344
+    if ( WP_DEFAULT_THEME == $current_template ) {
3345
+        update_option( 'template', $template );
3346
+        update_option( 'stylesheet', $template );
3347
+    }
3348
+    return $template;
3349 3349
 }
3350 3350
 
3351 3351
 /**
@@ -3357,25 +3357,25 @@  discard block
 block discarded – undo
3357 3357
  * @return string User role name.
3358 3358
  */
3359 3359
 function translate_level_to_role( $level ) {
3360
-	switch ( $level ) {
3361
-		case 10:
3362
-		case 9:
3363
-		case 8:
3364
-			return 'administrator';
3365
-		case 7:
3366
-		case 6:
3367
-		case 5:
3368
-			return 'editor';
3369
-		case 4:
3370
-		case 3:
3371
-		case 2:
3372
-			return 'author';
3373
-		case 1:
3374
-			return 'contributor';
3375
-		case 0:
3376
-		default:
3377
-			return 'subscriber';
3378
-	}
3360
+    switch ( $level ) {
3361
+        case 10:
3362
+        case 9:
3363
+        case 8:
3364
+            return 'administrator';
3365
+        case 7:
3366
+        case 6:
3367
+        case 5:
3368
+            return 'editor';
3369
+        case 4:
3370
+        case 3:
3371
+        case 2:
3372
+            return 'author';
3373
+        case 1:
3374
+            return 'contributor';
3375
+        case 0:
3376
+        default:
3377
+            return 'subscriber';
3378
+    }
3379 3379
 }
3380 3380
 
3381 3381
 /**
@@ -3386,11 +3386,11 @@  discard block
 block discarded – undo
3386 3386
  * @global wpdb $wpdb WordPress database abstraction object.
3387 3387
  */
3388 3388
 function wp_check_mysql_version() {
3389
-	global $wpdb;
3390
-	$result = $wpdb->check_database_version();
3391
-	if ( is_wp_error( $result ) ) {
3392
-		wp_die( $result );
3393
-	}
3389
+    global $wpdb;
3390
+    $result = $wpdb->check_database_version();
3391
+    if ( is_wp_error( $result ) ) {
3392
+        wp_die( $result );
3393
+    }
3394 3394
 }
3395 3395
 
3396 3396
 /**
@@ -3399,15 +3399,15 @@  discard block
 block discarded – undo
3399 3399
  * @since 2.2.0
3400 3400
  */
3401 3401
 function maybe_disable_automattic_widgets() {
3402
-	$plugins = __get_option( 'active_plugins' );
3403
-
3404
-	foreach ( (array) $plugins as $plugin ) {
3405
-		if ( 'widgets.php' === basename( $plugin ) ) {
3406
-			array_splice( $plugins, array_search( $plugin, $plugins, true ), 1 );
3407
-			update_option( 'active_plugins', $plugins );
3408
-			break;
3409
-		}
3410
-	}
3402
+    $plugins = __get_option( 'active_plugins' );
3403
+
3404
+    foreach ( (array) $plugins as $plugin ) {
3405
+        if ( 'widgets.php' === basename( $plugin ) ) {
3406
+            array_splice( $plugins, array_search( $plugin, $plugins, true ), 1 );
3407
+            update_option( 'active_plugins', $plugins );
3408
+            break;
3409
+        }
3410
+    }
3411 3411
 }
3412 3412
 
3413 3413
 /**
@@ -3419,11 +3419,11 @@  discard block
 block discarded – undo
3419 3419
  * @global wpdb $wpdb                  WordPress database abstraction object.
3420 3420
  */
3421 3421
 function maybe_disable_link_manager() {
3422
-	global $wp_current_db_version, $wpdb;
3422
+    global $wp_current_db_version, $wpdb;
3423 3423
 
3424
-	if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
3425
-		update_option( 'link_manager_enabled', 0 );
3426
-	}
3424
+    if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
3425
+        update_option( 'link_manager_enabled', 0 );
3426
+    }
3427 3427
 }
3428 3428
 
3429 3429
 /**
@@ -3435,71 +3435,71 @@  discard block
 block discarded – undo
3435 3435
  * @global wpdb $wpdb                  WordPress database abstraction object.
3436 3436
  */
3437 3437
 function pre_schema_upgrade() {
3438
-	global $wp_current_db_version, $wpdb;
3439
-
3440
-	// Upgrade versions prior to 2.9.
3441
-	if ( $wp_current_db_version < 11557 ) {
3442
-		// Delete duplicate options. Keep the option with the highest option_id.
3443
-		$wpdb->query( "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id" );
3444
-
3445
-		// Drop the old primary key and add the new.
3446
-		$wpdb->query( "ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)" );
3447
-
3448
-		// Drop the old option_name index. dbDelta() doesn't do the drop.
3449
-		$wpdb->query( "ALTER TABLE $wpdb->options DROP INDEX option_name" );
3450
-	}
3451
-
3452
-	// Multisite schema upgrades.
3453
-	if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) {
3454
-
3455
-		// Upgrade versions prior to 3.7.
3456
-		if ( $wp_current_db_version < 25179 ) {
3457
-			// New primary key for signups.
3458
-			$wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
3459
-			$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain" );
3460
-		}
3461
-
3462
-		if ( $wp_current_db_version < 25448 ) {
3463
-			// Convert archived from enum to tinyint.
3464
-			$wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" );
3465
-			$wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" );
3466
-		}
3467
-	}
3468
-
3469
-	// Upgrade versions prior to 4.2.
3470
-	if ( $wp_current_db_version < 31351 ) {
3471
-		if ( ! is_multisite() && wp_should_upgrade_global_tables() ) {
3472
-			$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3473
-		}
3474
-		$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" );
3475
-		$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" );
3476
-		$wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3477
-		$wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3478
-		$wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" );
3479
-	}
3480
-
3481
-	// Upgrade versions prior to 4.4.
3482
-	if ( $wp_current_db_version < 34978 ) {
3483
-		// If compatible termmeta table is found, use it, but enforce a proper index and update collation.
3484
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->termmeta}'" ) && $wpdb->get_results( "SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'" ) ) {
3485
-			$wpdb->query( "ALTER TABLE $wpdb->termmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3486
-			maybe_convert_table_to_utf8mb4( $wpdb->termmeta );
3487
-		}
3488
-	}
3438
+    global $wp_current_db_version, $wpdb;
3439
+
3440
+    // Upgrade versions prior to 2.9.
3441
+    if ( $wp_current_db_version < 11557 ) {
3442
+        // Delete duplicate options. Keep the option with the highest option_id.
3443
+        $wpdb->query( "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id" );
3444
+
3445
+        // Drop the old primary key and add the new.
3446
+        $wpdb->query( "ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)" );
3447
+
3448
+        // Drop the old option_name index. dbDelta() doesn't do the drop.
3449
+        $wpdb->query( "ALTER TABLE $wpdb->options DROP INDEX option_name" );
3450
+    }
3451
+
3452
+    // Multisite schema upgrades.
3453
+    if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) {
3454
+
3455
+        // Upgrade versions prior to 3.7.
3456
+        if ( $wp_current_db_version < 25179 ) {
3457
+            // New primary key for signups.
3458
+            $wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
3459
+            $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain" );
3460
+        }
3461
+
3462
+        if ( $wp_current_db_version < 25448 ) {
3463
+            // Convert archived from enum to tinyint.
3464
+            $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" );
3465
+            $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" );
3466
+        }
3467
+    }
3468
+
3469
+    // Upgrade versions prior to 4.2.
3470
+    if ( $wp_current_db_version < 31351 ) {
3471
+        if ( ! is_multisite() && wp_should_upgrade_global_tables() ) {
3472
+            $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3473
+        }
3474
+        $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" );
3475
+        $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" );
3476
+        $wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3477
+        $wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3478
+        $wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" );
3479
+    }
3480
+
3481
+    // Upgrade versions prior to 4.4.
3482
+    if ( $wp_current_db_version < 34978 ) {
3483
+        // If compatible termmeta table is found, use it, but enforce a proper index and update collation.
3484
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->termmeta}'" ) && $wpdb->get_results( "SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'" ) ) {
3485
+            $wpdb->query( "ALTER TABLE $wpdb->termmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3486
+            maybe_convert_table_to_utf8mb4( $wpdb->termmeta );
3487
+        }
3488
+    }
3489 3489
 }
3490 3490
 
3491 3491
 if ( ! function_exists( 'install_global_terms' ) ) :
3492
-	/**
3493
-	 * Install global terms.
3494
-	 *
3495
-	 * @since 3.0.0
3496
-	 *
3497
-	 * @global wpdb   $wpdb            WordPress database abstraction object.
3498
-	 * @global string $charset_collate
3499
-	 */
3500
-	function install_global_terms() {
3501
-		global $wpdb, $charset_collate;
3502
-		$ms_queries = "
3492
+    /**
3493
+     * Install global terms.
3494
+     *
3495
+     * @since 3.0.0
3496
+     *
3497
+     * @global wpdb   $wpdb            WordPress database abstraction object.
3498
+     * @global string $charset_collate
3499
+     */
3500
+    function install_global_terms() {
3501
+        global $wpdb, $charset_collate;
3502
+        $ms_queries = "
3503 3503
 CREATE TABLE $wpdb->sitecategories (
3504 3504
   cat_ID bigint(20) NOT NULL auto_increment,
3505 3505
   cat_name varchar(55) NOT NULL default '',
@@ -3510,9 +3510,9 @@  discard block
 block discarded – undo
3510 3510
   KEY last_updated (last_updated)
3511 3511
 ) $charset_collate;
3512 3512
 ";
3513
-		// Now create tables.
3514
-		dbDelta( $ms_queries );
3515
-	}
3513
+        // Now create tables.
3514
+        dbDelta( $ms_queries );
3515
+    }
3516 3516
 endif;
3517 3517
 
3518 3518
 /**
@@ -3535,30 +3535,30 @@  discard block
 block discarded – undo
3535 3535
  */
3536 3536
 function wp_should_upgrade_global_tables() {
3537 3537
 
3538
-	// Return false early if explicitly not upgrading.
3539
-	if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
3540
-		return false;
3541
-	}
3542
-
3543
-	// Assume global tables should be upgraded.
3544
-	$should_upgrade = true;
3545
-
3546
-	// Set to false if not on main network (does not matter if not multi-network).
3547
-	if ( ! is_main_network() ) {
3548
-		$should_upgrade = false;
3549
-	}
3550
-
3551
-	// Set to false if not on main site of current network (does not matter if not multi-site).
3552
-	if ( ! is_main_site() ) {
3553
-		$should_upgrade = false;
3554
-	}
3555
-
3556
-	/**
3557
-	 * Filters if upgrade routines should be run on global tables.
3558
-	 *
3559
-	 * @since 4.3.0
3560
-	 *
3561
-	 * @param bool $should_upgrade Whether to run the upgrade routines on global tables.
3562
-	 */
3563
-	return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade );
3538
+    // Return false early if explicitly not upgrading.
3539
+    if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
3540
+        return false;
3541
+    }
3542
+
3543
+    // Assume global tables should be upgraded.
3544
+    $should_upgrade = true;
3545
+
3546
+    // Set to false if not on main network (does not matter if not multi-network).
3547
+    if ( ! is_main_network() ) {
3548
+        $should_upgrade = false;
3549
+    }
3550
+
3551
+    // Set to false if not on main site of current network (does not matter if not multi-site).
3552
+    if ( ! is_main_site() ) {
3553
+        $should_upgrade = false;
3554
+    }
3555
+
3556
+    /**
3557
+     * Filters if upgrade routines should be run on global tables.
3558
+     *
3559
+     * @since 4.3.0
3560
+     *
3561
+     * @param bool $should_upgrade Whether to run the upgrade routines on global tables.
3562
+     */
3563
+    return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade );
3564 3564
 }
Please login to merge, or discard this patch.