Passed
Push — main ( 16d49b...d78e29 )
by TARIQ
111:03
created
brighty/wp-admin/update-core.php 1 patch
Indentation   +917 added lines, -917 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@  discard block
 block discarded – undo
15 15
 add_thickbox();
16 16
 
17 17
 if ( is_multisite() && ! is_network_admin() ) {
18
-	wp_redirect( network_admin_url( 'update-core.php' ) );
19
-	exit;
18
+    wp_redirect( network_admin_url( 'update-core.php' ) );
19
+    exit;
20 20
 }
21 21
 
22 22
 if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_languages' ) ) {
23
-	wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
23
+    wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
24 24
 }
25 25
 
26 26
 /**
@@ -34,163 +34,163 @@  discard block
 block discarded – undo
34 34
  * @param object $update
35 35
  */
36 36
 function list_core_update( $update ) {
37
-	global $wp_local_package, $wpdb;
38
-	static $first_pass = true;
39
-
40
-	$wp_version     = get_bloginfo( 'version' );
41
-	$version_string = sprintf( '%s–%s', $update->current, get_locale() );
42
-
43
-	if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
44
-		$version_string = $update->current;
45
-	} elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) {
46
-		$updates = get_core_updates();
47
-		if ( $updates && 1 === count( $updates ) ) {
48
-			// If the only available update is a partial builds, it doesn't need a language-specific version string.
49
-			$version_string = $update->current;
50
-		}
51
-	} elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() ) {
52
-		$version_string = sprintf( '%s–%s', $update->current, $update->locale );
53
-	}
54
-
55
-	$current = false;
56
-	if ( ! isset( $update->response ) || 'latest' === $update->response ) {
57
-		$current = true;
58
-	}
59
-
60
-	$message       = '';
61
-	$form_action   = 'update-core.php?action=do-core-upgrade';
62
-	$php_version   = phpversion();
63
-	$mysql_version = $wpdb->db_version();
64
-	$show_buttons  = true;
65
-
66
-	// Nightly build versions have two hyphens and a commit number.
67
-	if ( preg_match( '/-\w+-\d+/', $update->current ) ) {
68
-		// Retrieve the major version number.
69
-		preg_match( '/^\d+.\d+/', $update->current, $update_major );
70
-		/* translators: %s: WordPress version. */
71
-		$submit = sprintf( __( 'Update to latest %s nightly' ), $update_major[0] );
72
-	} else {
73
-		/* translators: %s: WordPress version. */
74
-		$submit = sprintf( __( 'Update to version %s' ), $version_string );
75
-	}
76
-
77
-	if ( 'development' === $update->response ) {
78
-		$message = __( 'You can update to the latest nightly build manually:' );
79
-	} else {
80
-		if ( $current ) {
81
-			/* translators: %s: WordPress version. */
82
-			$submit      = sprintf( __( 'Re-install version %s' ), $version_string );
83
-			$form_action = 'update-core.php?action=do-core-reinstall';
84
-		} else {
85
-			$php_compat = version_compare( $php_version, $update->php_version, '>=' );
86
-			if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
87
-				$mysql_compat = true;
88
-			} else {
89
-				$mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
90
-			}
91
-
92
-			$version_url = sprintf(
93
-				/* translators: %s: WordPress version. */
94
-				esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
95
-				sanitize_title( $update->current )
96
-			);
97
-
98
-			$php_update_message = '</p><p>' . sprintf(
99
-				/* translators: %s: URL to Update PHP page. */
100
-				__( '<a href="%s">Learn more about updating PHP</a>.' ),
101
-				esc_url( wp_get_update_php_url() )
102
-			);
103
-
104
-			$annotation = wp_get_update_php_annotation();
105
-
106
-			if ( $annotation ) {
107
-				$php_update_message .= '</p><p><em>' . $annotation . '</em>';
108
-			}
109
-
110
-			if ( ! $mysql_compat && ! $php_compat ) {
111
-				$message = sprintf(
112
-					/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number. */
113
-					__( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ),
114
-					$version_url,
115
-					$update->current,
116
-					$update->php_version,
117
-					$update->mysql_version,
118
-					$php_version,
119
-					$mysql_version
120
-				) . $php_update_message;
121
-			} elseif ( ! $php_compat ) {
122
-				$message = sprintf(
123
-					/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
124
-					__( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ),
125
-					$version_url,
126
-					$update->current,
127
-					$update->php_version,
128
-					$php_version
129
-				) . $php_update_message;
130
-			} elseif ( ! $mysql_compat ) {
131
-				$message = sprintf(
132
-					/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
133
-					__( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ),
134
-					$version_url,
135
-					$update->current,
136
-					$update->mysql_version,
137
-					$mysql_version
138
-				);
139
-			} else {
140
-				$message = sprintf(
141
-					/* translators: 1: Installed WordPress version number, 2: URL to WordPress release notes, 3: New WordPress version number, including locale if necessary. */
142
-					__( 'You can update from WordPress %1$s to <a href="%2$s">WordPress %3$s</a> manually:' ),
143
-					$wp_version,
144
-					$version_url,
145
-					$version_string
146
-				);
147
-			}
148
-
149
-			if ( ! $mysql_compat || ! $php_compat ) {
150
-				$show_buttons = false;
151
-			}
152
-		}
153
-	}
154
-
155
-	echo '<p>';
156
-	echo $message;
157
-	echo '</p>';
158
-
159
-	echo '<form method="post" action="' . esc_url( $form_action ) . '" name="upgrade" class="upgrade">';
160
-	wp_nonce_field( 'upgrade-core' );
161
-
162
-	echo '<p>';
163
-	echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden" />';
164
-	echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden" />';
165
-	if ( $show_buttons ) {
166
-		if ( $first_pass ) {
167
-			submit_button( $submit, $current ? '' : 'primary regular', 'upgrade', false );
168
-			$first_pass = false;
169
-		} else {
170
-			submit_button( $submit, '', 'upgrade', false );
171
-		}
172
-	}
173
-	if ( 'en_US' !== $update->locale ) {
174
-		if ( ! isset( $update->dismissed ) || ! $update->dismissed ) {
175
-			submit_button( __( 'Hide this update' ), '', 'dismiss', false );
176
-		} else {
177
-			submit_button( __( 'Bring back this update' ), '', 'undismiss', false );
178
-		}
179
-	}
180
-	echo '</p>';
181
-
182
-	if ( 'en_US' !== $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
183
-		echo '<p class="hint">' . __( 'This localized version contains both the translation and various other localization fixes.' ) . '</p>';
184
-	} elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
185
-		// Partial builds don't need language-specific warnings.
186
-		echo '<p class="hint">' . sprintf(
187
-			/* translators: %s: WordPress version. */
188
-			__( 'You are about to install WordPress %s <strong>in English (US).</strong> There is a chance this update will break your translation. You may prefer to wait for the localized version to be released.' ),
189
-			'development' !== $update->response ? $update->current : ''
190
-		) . '</p>';
191
-	}
192
-
193
-	echo '</form>';
37
+    global $wp_local_package, $wpdb;
38
+    static $first_pass = true;
39
+
40
+    $wp_version     = get_bloginfo( 'version' );
41
+    $version_string = sprintf( '%s&ndash;%s', $update->current, get_locale() );
42
+
43
+    if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
44
+        $version_string = $update->current;
45
+    } elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) {
46
+        $updates = get_core_updates();
47
+        if ( $updates && 1 === count( $updates ) ) {
48
+            // If the only available update is a partial builds, it doesn't need a language-specific version string.
49
+            $version_string = $update->current;
50
+        }
51
+    } elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() ) {
52
+        $version_string = sprintf( '%s&ndash;%s', $update->current, $update->locale );
53
+    }
54
+
55
+    $current = false;
56
+    if ( ! isset( $update->response ) || 'latest' === $update->response ) {
57
+        $current = true;
58
+    }
59
+
60
+    $message       = '';
61
+    $form_action   = 'update-core.php?action=do-core-upgrade';
62
+    $php_version   = phpversion();
63
+    $mysql_version = $wpdb->db_version();
64
+    $show_buttons  = true;
65
+
66
+    // Nightly build versions have two hyphens and a commit number.
67
+    if ( preg_match( '/-\w+-\d+/', $update->current ) ) {
68
+        // Retrieve the major version number.
69
+        preg_match( '/^\d+.\d+/', $update->current, $update_major );
70
+        /* translators: %s: WordPress version. */
71
+        $submit = sprintf( __( 'Update to latest %s nightly' ), $update_major[0] );
72
+    } else {
73
+        /* translators: %s: WordPress version. */
74
+        $submit = sprintf( __( 'Update to version %s' ), $version_string );
75
+    }
76
+
77
+    if ( 'development' === $update->response ) {
78
+        $message = __( 'You can update to the latest nightly build manually:' );
79
+    } else {
80
+        if ( $current ) {
81
+            /* translators: %s: WordPress version. */
82
+            $submit      = sprintf( __( 'Re-install version %s' ), $version_string );
83
+            $form_action = 'update-core.php?action=do-core-reinstall';
84
+        } else {
85
+            $php_compat = version_compare( $php_version, $update->php_version, '>=' );
86
+            if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
87
+                $mysql_compat = true;
88
+            } else {
89
+                $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
90
+            }
91
+
92
+            $version_url = sprintf(
93
+                /* translators: %s: WordPress version. */
94
+                esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
95
+                sanitize_title( $update->current )
96
+            );
97
+
98
+            $php_update_message = '</p><p>' . sprintf(
99
+                /* translators: %s: URL to Update PHP page. */
100
+                __( '<a href="%s">Learn more about updating PHP</a>.' ),
101
+                esc_url( wp_get_update_php_url() )
102
+            );
103
+
104
+            $annotation = wp_get_update_php_annotation();
105
+
106
+            if ( $annotation ) {
107
+                $php_update_message .= '</p><p><em>' . $annotation . '</em>';
108
+            }
109
+
110
+            if ( ! $mysql_compat && ! $php_compat ) {
111
+                $message = sprintf(
112
+                    /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number. */
113
+                    __( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ),
114
+                    $version_url,
115
+                    $update->current,
116
+                    $update->php_version,
117
+                    $update->mysql_version,
118
+                    $php_version,
119
+                    $mysql_version
120
+                ) . $php_update_message;
121
+            } elseif ( ! $php_compat ) {
122
+                $message = sprintf(
123
+                    /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
124
+                    __( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ),
125
+                    $version_url,
126
+                    $update->current,
127
+                    $update->php_version,
128
+                    $php_version
129
+                ) . $php_update_message;
130
+            } elseif ( ! $mysql_compat ) {
131
+                $message = sprintf(
132
+                    /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
133
+                    __( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ),
134
+                    $version_url,
135
+                    $update->current,
136
+                    $update->mysql_version,
137
+                    $mysql_version
138
+                );
139
+            } else {
140
+                $message = sprintf(
141
+                    /* translators: 1: Installed WordPress version number, 2: URL to WordPress release notes, 3: New WordPress version number, including locale if necessary. */
142
+                    __( 'You can update from WordPress %1$s to <a href="%2$s">WordPress %3$s</a> manually:' ),
143
+                    $wp_version,
144
+                    $version_url,
145
+                    $version_string
146
+                );
147
+            }
148
+
149
+            if ( ! $mysql_compat || ! $php_compat ) {
150
+                $show_buttons = false;
151
+            }
152
+        }
153
+    }
154
+
155
+    echo '<p>';
156
+    echo $message;
157
+    echo '</p>';
158
+
159
+    echo '<form method="post" action="' . esc_url( $form_action ) . '" name="upgrade" class="upgrade">';
160
+    wp_nonce_field( 'upgrade-core' );
161
+
162
+    echo '<p>';
163
+    echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden" />';
164
+    echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden" />';
165
+    if ( $show_buttons ) {
166
+        if ( $first_pass ) {
167
+            submit_button( $submit, $current ? '' : 'primary regular', 'upgrade', false );
168
+            $first_pass = false;
169
+        } else {
170
+            submit_button( $submit, '', 'upgrade', false );
171
+        }
172
+    }
173
+    if ( 'en_US' !== $update->locale ) {
174
+        if ( ! isset( $update->dismissed ) || ! $update->dismissed ) {
175
+            submit_button( __( 'Hide this update' ), '', 'dismiss', false );
176
+        } else {
177
+            submit_button( __( 'Bring back this update' ), '', 'undismiss', false );
178
+        }
179
+    }
180
+    echo '</p>';
181
+
182
+    if ( 'en_US' !== $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
183
+        echo '<p class="hint">' . __( 'This localized version contains both the translation and various other localization fixes.' ) . '</p>';
184
+    } elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
185
+        // Partial builds don't need language-specific warnings.
186
+        echo '<p class="hint">' . sprintf(
187
+            /* translators: %s: WordPress version. */
188
+            __( 'You are about to install WordPress %s <strong>in English (US).</strong> There is a chance this update will break your translation. You may prefer to wait for the localized version to be released.' ),
189
+            'development' !== $update->response ? $update->current : ''
190
+        ) . '</p>';
191
+    }
192
+
193
+    echo '</form>';
194 194
 
195 195
 }
196 196
 
@@ -200,17 +200,17 @@  discard block
 block discarded – undo
200 200
  * @since 2.7.0
201 201
  */
202 202
 function dismissed_updates() {
203
-	$dismissed = get_core_updates(
204
-		array(
205
-			'dismissed' => true,
206
-			'available' => false,
207
-		)
208
-	);
209
-
210
-	if ( $dismissed ) {
211
-		$show_text = esc_js( __( 'Show hidden updates' ) );
212
-		$hide_text = esc_js( __( 'Hide hidden updates' ) );
213
-		?>
203
+    $dismissed = get_core_updates(
204
+        array(
205
+            'dismissed' => true,
206
+            'available' => false,
207
+        )
208
+    );
209
+
210
+    if ( $dismissed ) {
211
+        $show_text = esc_js( __( 'Show hidden updates' ) );
212
+        $hide_text = esc_js( __( 'Hide hidden updates' ) );
213
+        ?>
214 214
 		<script type="text/javascript">
215 215
 			jQuery( function( $ ) {
216 216
 				$( '#show-dismissed' ).on( 'click', function() {
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
 			});
228 228
 		</script>
229 229
 		<?php
230
-		echo '<p class="hide-if-no-js"><button type="button" class="button" id="show-dismissed" aria-expanded="false">' . __( 'Show hidden updates' ) . '</button></p>';
231
-		echo '<ul id="dismissed-updates" class="core-updates dismissed">';
232
-		foreach ( (array) $dismissed as $update ) {
233
-			echo '<li>';
234
-			list_core_update( $update );
235
-			echo '</li>';
236
-		}
237
-		echo '</ul>';
238
-	}
230
+        echo '<p class="hide-if-no-js"><button type="button" class="button" id="show-dismissed" aria-expanded="false">' . __( 'Show hidden updates' ) . '</button></p>';
231
+        echo '<ul id="dismissed-updates" class="core-updates dismissed">';
232
+        foreach ( (array) $dismissed as $update ) {
233
+            echo '<li>';
234
+            list_core_update( $update );
235
+            echo '</li>';
236
+        }
237
+        echo '</ul>';
238
+    }
239 239
 }
240 240
 
241 241
 /**
@@ -247,56 +247,56 @@  discard block
 block discarded – undo
247 247
  * @global string $required_mysql_version The required MySQL version string.
248 248
  */
249 249
 function core_upgrade_preamble() {
250
-	global $required_php_version, $required_mysql_version;
251
-
252
-	$updates = get_core_updates();
253
-
254
-	// Include an unmodified $wp_version.
255
-	require ABSPATH . WPINC . '/version.php';
256
-
257
-	$is_development_version = preg_match( '/alpha|beta|RC/', $wp_version );
258
-
259
-	if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
260
-		echo '<h2 class="response">';
261
-		_e( 'An updated version of WordPress is available.' );
262
-		echo '</h2>';
263
-
264
-		echo '<div class="notice notice-warning inline"><p>';
265
-		printf(
266
-			/* translators: 1: Documentation on WordPress backups, 2: Documentation on updating WordPress. */
267
-			__( '<strong>Important:</strong> Before updating, please <a href="%1$s">back up your database and files</a>. For help with updates, visit the <a href="%2$s">Updating WordPress</a> documentation page.' ),
268
-			__( 'https://wordpress.org/support/article/wordpress-backups/' ),
269
-			__( 'https://wordpress.org/support/article/updating-wordpress/' )
270
-		);
271
-		echo '</p></div>';
272
-	} elseif ( $is_development_version ) {
273
-		echo '<h2 class="response">' . __( 'You are using a development version of WordPress.' ) . '</h2>';
274
-	} else {
275
-		echo '<h2 class="response">' . __( 'You have the latest version of WordPress.' ) . '</h2>';
276
-	}
277
-
278
-	echo '<ul class="core-updates">';
279
-	foreach ( (array) $updates as $update ) {
280
-		echo '<li>';
281
-		list_core_update( $update );
282
-		echo '</li>';
283
-	}
284
-	echo '</ul>';
285
-
286
-	// Don't show the maintenance mode notice when we are only showing a single re-install option.
287
-	if ( $updates && ( count( $updates ) > 1 || 'latest' !== $updates[0]->response ) ) {
288
-		echo '<p>' . __( 'While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, this mode will be deactivated.' ) . '</p>';
289
-	} elseif ( ! $updates ) {
290
-		list( $normalized_version ) = explode( '-', $wp_version );
291
-		echo '<p>' . sprintf(
292
-			/* translators: 1: URL to About screen, 2: WordPress version. */
293
-			__( '<a href="%1$s">Learn more about WordPress %2$s</a>.' ),
294
-			esc_url( self_admin_url( 'about.php' ) ),
295
-			$normalized_version
296
-		) . '</p>';
297
-	}
298
-
299
-	dismissed_updates();
250
+    global $required_php_version, $required_mysql_version;
251
+
252
+    $updates = get_core_updates();
253
+
254
+    // Include an unmodified $wp_version.
255
+    require ABSPATH . WPINC . '/version.php';
256
+
257
+    $is_development_version = preg_match( '/alpha|beta|RC/', $wp_version );
258
+
259
+    if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
260
+        echo '<h2 class="response">';
261
+        _e( 'An updated version of WordPress is available.' );
262
+        echo '</h2>';
263
+
264
+        echo '<div class="notice notice-warning inline"><p>';
265
+        printf(
266
+            /* translators: 1: Documentation on WordPress backups, 2: Documentation on updating WordPress. */
267
+            __( '<strong>Important:</strong> Before updating, please <a href="%1$s">back up your database and files</a>. For help with updates, visit the <a href="%2$s">Updating WordPress</a> documentation page.' ),
268
+            __( 'https://wordpress.org/support/article/wordpress-backups/' ),
269
+            __( 'https://wordpress.org/support/article/updating-wordpress/' )
270
+        );
271
+        echo '</p></div>';
272
+    } elseif ( $is_development_version ) {
273
+        echo '<h2 class="response">' . __( 'You are using a development version of WordPress.' ) . '</h2>';
274
+    } else {
275
+        echo '<h2 class="response">' . __( 'You have the latest version of WordPress.' ) . '</h2>';
276
+    }
277
+
278
+    echo '<ul class="core-updates">';
279
+    foreach ( (array) $updates as $update ) {
280
+        echo '<li>';
281
+        list_core_update( $update );
282
+        echo '</li>';
283
+    }
284
+    echo '</ul>';
285
+
286
+    // Don't show the maintenance mode notice when we are only showing a single re-install option.
287
+    if ( $updates && ( count( $updates ) > 1 || 'latest' !== $updates[0]->response ) ) {
288
+        echo '<p>' . __( 'While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, this mode will be deactivated.' ) . '</p>';
289
+    } elseif ( ! $updates ) {
290
+        list( $normalized_version ) = explode( '-', $wp_version );
291
+        echo '<p>' . sprintf(
292
+            /* translators: 1: URL to About screen, 2: WordPress version. */
293
+            __( '<a href="%1$s">Learn more about WordPress %2$s</a>.' ),
294
+            esc_url( self_admin_url( 'about.php' ) ),
295
+            $normalized_version
296
+        ) . '</p>';
297
+    }
298
+
299
+    dismissed_updates();
300 300
 }
301 301
 
302 302
 /**
@@ -305,142 +305,142 @@  discard block
 block discarded – undo
305 305
  * @since 5.6.0
306 306
  */
307 307
 function core_auto_updates_settings() {
308
-	if ( isset( $_GET['core-major-auto-updates-saved'] ) ) {
309
-		if ( 'enabled' === $_GET['core-major-auto-updates-saved'] ) {
310
-			$notice_text = __( 'Automatic updates for all WordPress versions have been enabled. Thank you!' );
311
-			echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
312
-		} elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) {
313
-			$notice_text = __( 'WordPress will only receive automatic security and maintenance releases from now on.' );
314
-			echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
315
-		}
316
-	}
317
-
318
-	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
319
-	$updater = new WP_Automatic_Updater();
320
-
321
-	// Defaults:
322
-	$upgrade_dev   = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
323
-	$upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
324
-	$upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';
325
-
326
-	$can_set_update_option = true;
327
-	// WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false.
328
-	if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
329
-		if ( false === WP_AUTO_UPDATE_CORE ) {
330
-			// Defaults to turned off, unless a filter allows it.
331
-			$upgrade_dev   = false;
332
-			$upgrade_minor = false;
333
-			$upgrade_major = false;
334
-		} elseif ( true === WP_AUTO_UPDATE_CORE
335
-			|| in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true )
336
-		) {
337
-			// ALL updates for core.
338
-			$upgrade_dev   = true;
339
-			$upgrade_minor = true;
340
-			$upgrade_major = true;
341
-		} elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
342
-			// Only minor updates for core.
343
-			$upgrade_dev   = false;
344
-			$upgrade_minor = true;
345
-			$upgrade_major = false;
346
-		}
347
-
348
-		// The UI is overridden by the `WP_AUTO_UPDATE_CORE` constant.
349
-		$can_set_update_option = false;
350
-	}
351
-
352
-	if ( $updater->is_disabled() ) {
353
-		$upgrade_dev   = false;
354
-		$upgrade_minor = false;
355
-		$upgrade_major = false;
356
-
357
-		/*
308
+    if ( isset( $_GET['core-major-auto-updates-saved'] ) ) {
309
+        if ( 'enabled' === $_GET['core-major-auto-updates-saved'] ) {
310
+            $notice_text = __( 'Automatic updates for all WordPress versions have been enabled. Thank you!' );
311
+            echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
312
+        } elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) {
313
+            $notice_text = __( 'WordPress will only receive automatic security and maintenance releases from now on.' );
314
+            echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
315
+        }
316
+    }
317
+
318
+    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
319
+    $updater = new WP_Automatic_Updater();
320
+
321
+    // Defaults:
322
+    $upgrade_dev   = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
323
+    $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
324
+    $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';
325
+
326
+    $can_set_update_option = true;
327
+    // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false.
328
+    if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
329
+        if ( false === WP_AUTO_UPDATE_CORE ) {
330
+            // Defaults to turned off, unless a filter allows it.
331
+            $upgrade_dev   = false;
332
+            $upgrade_minor = false;
333
+            $upgrade_major = false;
334
+        } elseif ( true === WP_AUTO_UPDATE_CORE
335
+            || in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true )
336
+        ) {
337
+            // ALL updates for core.
338
+            $upgrade_dev   = true;
339
+            $upgrade_minor = true;
340
+            $upgrade_major = true;
341
+        } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
342
+            // Only minor updates for core.
343
+            $upgrade_dev   = false;
344
+            $upgrade_minor = true;
345
+            $upgrade_major = false;
346
+        }
347
+
348
+        // The UI is overridden by the `WP_AUTO_UPDATE_CORE` constant.
349
+        $can_set_update_option = false;
350
+    }
351
+
352
+    if ( $updater->is_disabled() ) {
353
+        $upgrade_dev   = false;
354
+        $upgrade_minor = false;
355
+        $upgrade_major = false;
356
+
357
+        /*
358 358
 		 * The UI is overridden by the `AUTOMATIC_UPDATER_DISABLED` constant
359 359
 		 * or the `automatic_updater_disabled` filter,
360 360
 		 * or by `wp_is_file_mod_allowed( 'automatic_updater' )`.
361 361
 		 * See `WP_Automatic_Updater::is_disabled()`.
362 362
 		 */
363
-		$can_set_update_option = false;
364
-	}
365
-
366
-	// Is the UI overridden by a plugin using the `allow_major_auto_core_updates` filter?
367
-	if ( has_filter( 'allow_major_auto_core_updates' ) ) {
368
-		$can_set_update_option = false;
369
-	}
370
-
371
-	/** This filter is documented in wp-admin/includes/class-core-upgrader.php */
372
-	$upgrade_dev = apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev );
373
-	/** This filter is documented in wp-admin/includes/class-core-upgrader.php */
374
-	$upgrade_minor = apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor );
375
-	/** This filter is documented in wp-admin/includes/class-core-upgrader.php */
376
-	$upgrade_major = apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
377
-
378
-	$auto_update_settings = array(
379
-		'dev'   => $upgrade_dev,
380
-		'minor' => $upgrade_minor,
381
-		'major' => $upgrade_major,
382
-	);
383
-
384
-	if ( $upgrade_major ) {
385
-		$wp_version = get_bloginfo( 'version' );
386
-		$updates    = get_core_updates();
387
-
388
-		if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
389
-			echo '<p>' . wp_get_auto_update_message() . '</p>';
390
-		}
391
-	}
392
-
393
-	$action_url = self_admin_url( 'update-core.php?action=core-major-auto-updates-settings' );
394
-	?>
363
+        $can_set_update_option = false;
364
+    }
365
+
366
+    // Is the UI overridden by a plugin using the `allow_major_auto_core_updates` filter?
367
+    if ( has_filter( 'allow_major_auto_core_updates' ) ) {
368
+        $can_set_update_option = false;
369
+    }
370
+
371
+    /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
372
+    $upgrade_dev = apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev );
373
+    /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
374
+    $upgrade_minor = apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor );
375
+    /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
376
+    $upgrade_major = apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
377
+
378
+    $auto_update_settings = array(
379
+        'dev'   => $upgrade_dev,
380
+        'minor' => $upgrade_minor,
381
+        'major' => $upgrade_major,
382
+    );
383
+
384
+    if ( $upgrade_major ) {
385
+        $wp_version = get_bloginfo( 'version' );
386
+        $updates    = get_core_updates();
387
+
388
+        if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
389
+            echo '<p>' . wp_get_auto_update_message() . '</p>';
390
+        }
391
+    }
392
+
393
+    $action_url = self_admin_url( 'update-core.php?action=core-major-auto-updates-settings' );
394
+    ?>
395 395
 
396 396
 	<p class="auto-update-status">
397 397
 		<?php
398 398
 
399
-		if ( $updater->is_vcs_checkout( ABSPATH ) ) {
400
-			_e( 'This site appears to be under version control. Automatic updates are disabled.' );
401
-		} elseif ( $upgrade_major ) {
402
-			_e( 'This site is automatically kept up to date with each new version of WordPress.' );
403
-
404
-			if ( $can_set_update_option ) {
405
-				echo '<br>';
406
-				printf(
407
-					'<a href="%s" class="core-auto-update-settings-link core-auto-update-settings-link-disable">%s</a>',
408
-					wp_nonce_url( add_query_arg( 'value', 'disable', $action_url ), 'core-major-auto-updates-nonce' ),
409
-					__( 'Switch to automatic updates for maintenance and security releases only.' )
410
-				);
411
-			}
412
-		} elseif ( $upgrade_minor ) {
413
-			_e( 'This site is automatically kept up to date with maintenance and security releases of WordPress only.' );
414
-
415
-			if ( $can_set_update_option ) {
416
-				echo '<br>';
417
-				printf(
418
-					'<a href="%s" class="core-auto-update-settings-link core-auto-update-settings-link-enable">%s</a>',
419
-					wp_nonce_url( add_query_arg( 'value', 'enable', $action_url ), 'core-major-auto-updates-nonce' ),
420
-					__( 'Enable automatic updates for all new versions of WordPress.' )
421
-				);
422
-			}
423
-		} else {
424
-			_e( 'This site will not receive automatic updates for new versions of WordPress.' );
425
-		}
426
-		?>
399
+        if ( $updater->is_vcs_checkout( ABSPATH ) ) {
400
+            _e( 'This site appears to be under version control. Automatic updates are disabled.' );
401
+        } elseif ( $upgrade_major ) {
402
+            _e( 'This site is automatically kept up to date with each new version of WordPress.' );
403
+
404
+            if ( $can_set_update_option ) {
405
+                echo '<br>';
406
+                printf(
407
+                    '<a href="%s" class="core-auto-update-settings-link core-auto-update-settings-link-disable">%s</a>',
408
+                    wp_nonce_url( add_query_arg( 'value', 'disable', $action_url ), 'core-major-auto-updates-nonce' ),
409
+                    __( 'Switch to automatic updates for maintenance and security releases only.' )
410
+                );
411
+            }
412
+        } elseif ( $upgrade_minor ) {
413
+            _e( 'This site is automatically kept up to date with maintenance and security releases of WordPress only.' );
414
+
415
+            if ( $can_set_update_option ) {
416
+                echo '<br>';
417
+                printf(
418
+                    '<a href="%s" class="core-auto-update-settings-link core-auto-update-settings-link-enable">%s</a>',
419
+                    wp_nonce_url( add_query_arg( 'value', 'enable', $action_url ), 'core-major-auto-updates-nonce' ),
420
+                    __( 'Enable automatic updates for all new versions of WordPress.' )
421
+                );
422
+            }
423
+        } else {
424
+            _e( 'This site will not receive automatic updates for new versions of WordPress.' );
425
+        }
426
+        ?>
427 427
 	</p>
428 428
 
429 429
 	<?php
430
-	/**
431
-	 * Fires after the major core auto-update settings.
432
-	 *
433
-	 * @since 5.6.0
434
-	 *
435
-	 * @param array $auto_update_settings {
436
-	 *     Array of core auto-update settings.
437
-	 *
438
-	 *     @type bool $dev   Whether to enable automatic updates for development versions.
439
-	 *     @type bool $minor Whether to enable minor automatic core updates.
440
-	 *     @type bool $major Whether to enable major automatic core updates.
441
-	 * }
442
-	 */
443
-	do_action( 'after_core_auto_updates_settings', $auto_update_settings );
430
+    /**
431
+     * Fires after the major core auto-update settings.
432
+     *
433
+     * @since 5.6.0
434
+     *
435
+     * @param array $auto_update_settings {
436
+     *     Array of core auto-update settings.
437
+     *
438
+     *     @type bool $dev   Whether to enable automatic updates for development versions.
439
+     *     @type bool $minor Whether to enable minor automatic core updates.
440
+     *     @type bool $major Whether to enable major automatic core updates.
441
+     * }
442
+     */
443
+    do_action( 'after_core_auto_updates_settings', $auto_update_settings );
444 444
 }
445 445
 
446 446
 /**
@@ -449,35 +449,35 @@  discard block
 block discarded – undo
449 449
  * @since 2.9.0
450 450
  */
451 451
 function list_plugin_updates() {
452
-	$wp_version     = get_bloginfo( 'version' );
453
-	$cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
454
-
455
-	require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
456
-	$plugins = get_plugin_updates();
457
-	if ( empty( $plugins ) ) {
458
-		echo '<h2>' . __( 'Plugins' ) . '</h2>';
459
-		echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
460
-		return;
461
-	}
462
-	$form_action = 'update-core.php?action=do-plugin-upgrade';
463
-
464
-	$core_updates = get_core_updates();
465
-	if ( ! isset( $core_updates[0]->response ) || 'latest' === $core_updates[0]->response || 'development' === $core_updates[0]->response || version_compare( $core_updates[0]->current, $cur_wp_version, '=' ) ) {
466
-		$core_update_version = false;
467
-	} else {
468
-		$core_update_version = $core_updates[0]->current;
469
-	}
470
-
471
-	$plugins_count = count( $plugins );
472
-	?>
452
+    $wp_version     = get_bloginfo( 'version' );
453
+    $cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
454
+
455
+    require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
456
+    $plugins = get_plugin_updates();
457
+    if ( empty( $plugins ) ) {
458
+        echo '<h2>' . __( 'Plugins' ) . '</h2>';
459
+        echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
460
+        return;
461
+    }
462
+    $form_action = 'update-core.php?action=do-plugin-upgrade';
463
+
464
+    $core_updates = get_core_updates();
465
+    if ( ! isset( $core_updates[0]->response ) || 'latest' === $core_updates[0]->response || 'development' === $core_updates[0]->response || version_compare( $core_updates[0]->current, $cur_wp_version, '=' ) ) {
466
+        $core_update_version = false;
467
+    } else {
468
+        $core_update_version = $core_updates[0]->current;
469
+    }
470
+
471
+    $plugins_count = count( $plugins );
472
+    ?>
473 473
 <h2>
474 474
 	<?php
475
-	printf(
476
-		'%s <span class="count">(%d)</span>',
477
-		__( 'Plugins' ),
478
-		number_format_i18n( $plugins_count )
479
-	);
480
-	?>
475
+    printf(
476
+        '%s <span class="count">(%d)</span>',
477
+        __( 'Plugins' ),
478
+        number_format_i18n( $plugins_count )
479
+    );
480
+    ?>
481 481
 </h2>
482 482
 <p><?php _e( 'The following plugins have new versions available. Check the ones you want to update and then click &#8220;Update Plugins&#8221;.' ); ?></p>
483 483
 <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
@@ -494,89 +494,89 @@  discard block
 block discarded – undo
494 494
 	<tbody class="plugins">
495 495
 	<?php
496 496
 
497
-	$auto_updates = array();
498
-	if ( wp_is_auto_update_enabled_for_type( 'plugin' ) ) {
499
-		$auto_updates       = (array) get_site_option( 'auto_update_plugins', array() );
500
-		$auto_update_notice = ' | ' . wp_get_auto_update_message();
501
-	}
502
-
503
-	foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
504
-		$plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
505
-
506
-		$icon            = '<span class="dashicons dashicons-admin-plugins"></span>';
507
-		$preferred_icons = array( 'svg', '2x', '1x', 'default' );
508
-		foreach ( $preferred_icons as $preferred_icon ) {
509
-			if ( ! empty( $plugin_data->update->icons[ $preferred_icon ] ) ) {
510
-				$icon = '<img src="' . esc_url( $plugin_data->update->icons[ $preferred_icon ] ) . '" alt="" />';
511
-				break;
512
-			}
513
-		}
514
-
515
-		// Get plugin compat for running version of WordPress.
516
-		if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $cur_wp_version, '>=' ) ) {
517
-			/* translators: %s: WordPress version. */
518
-			$compat = '<br />' . sprintf( __( 'Compatibility with WordPress %s: 100%% (according to its author)' ), $cur_wp_version );
519
-		} else {
520
-			/* translators: %s: WordPress version. */
521
-			$compat = '<br />' . sprintf( __( 'Compatibility with WordPress %s: Unknown' ), $cur_wp_version );
522
-		}
523
-		// Get plugin compat for updated version of WordPress.
524
-		if ( $core_update_version ) {
525
-			if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
526
-				/* translators: %s: WordPress version. */
527
-				$compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %s: 100%% (according to its author)' ), $core_update_version );
528
-			} else {
529
-				/* translators: %s: WordPress version. */
530
-				$compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %s: Unknown' ), $core_update_version );
531
-			}
532
-		}
533
-
534
-		$requires_php   = isset( $plugin_data->update->requires_php ) ? $plugin_data->update->requires_php : null;
535
-		$compatible_php = is_php_version_compatible( $requires_php );
536
-
537
-		if ( ! $compatible_php && current_user_can( 'update_php' ) ) {
538
-			$compat .= '<br>' . __( 'This update does not work with your version of PHP.' ) . '&nbsp;';
539
-			$compat .= sprintf(
540
-				/* translators: %s: URL to Update PHP page. */
541
-				__( '<a href="%s">Learn more about updating PHP</a>.' ),
542
-				esc_url( wp_get_update_php_url() )
543
-			);
544
-
545
-			$annotation = wp_get_update_php_annotation();
546
-
547
-			if ( $annotation ) {
548
-				$compat .= '</p><p><em>' . $annotation . '</em>';
549
-			}
550
-		}
551
-
552
-		// Get the upgrade notice for the new plugin version.
553
-		if ( isset( $plugin_data->update->upgrade_notice ) ) {
554
-			$upgrade_notice = '<br />' . strip_tags( $plugin_data->update->upgrade_notice );
555
-		} else {
556
-			$upgrade_notice = '';
557
-		}
558
-
559
-		$details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data->update->slug . '&section=changelog&TB_iframe=true&width=640&height=662' );
560
-		$details     = sprintf(
561
-			'<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
562
-			esc_url( $details_url ),
563
-			/* translators: 1: Plugin name, 2: Version number. */
564
-			esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
565
-			/* translators: %s: Plugin version. */
566
-			sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
567
-		);
568
-
569
-		$checkbox_id = 'checkbox_' . md5( $plugin_file );
570
-		?>
497
+    $auto_updates = array();
498
+    if ( wp_is_auto_update_enabled_for_type( 'plugin' ) ) {
499
+        $auto_updates       = (array) get_site_option( 'auto_update_plugins', array() );
500
+        $auto_update_notice = ' | ' . wp_get_auto_update_message();
501
+    }
502
+
503
+    foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
504
+        $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
505
+
506
+        $icon            = '<span class="dashicons dashicons-admin-plugins"></span>';
507
+        $preferred_icons = array( 'svg', '2x', '1x', 'default' );
508
+        foreach ( $preferred_icons as $preferred_icon ) {
509
+            if ( ! empty( $plugin_data->update->icons[ $preferred_icon ] ) ) {
510
+                $icon = '<img src="' . esc_url( $plugin_data->update->icons[ $preferred_icon ] ) . '" alt="" />';
511
+                break;
512
+            }
513
+        }
514
+
515
+        // Get plugin compat for running version of WordPress.
516
+        if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $cur_wp_version, '>=' ) ) {
517
+            /* translators: %s: WordPress version. */
518
+            $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %s: 100%% (according to its author)' ), $cur_wp_version );
519
+        } else {
520
+            /* translators: %s: WordPress version. */
521
+            $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %s: Unknown' ), $cur_wp_version );
522
+        }
523
+        // Get plugin compat for updated version of WordPress.
524
+        if ( $core_update_version ) {
525
+            if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
526
+                /* translators: %s: WordPress version. */
527
+                $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %s: 100%% (according to its author)' ), $core_update_version );
528
+            } else {
529
+                /* translators: %s: WordPress version. */
530
+                $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %s: Unknown' ), $core_update_version );
531
+            }
532
+        }
533
+
534
+        $requires_php   = isset( $plugin_data->update->requires_php ) ? $plugin_data->update->requires_php : null;
535
+        $compatible_php = is_php_version_compatible( $requires_php );
536
+
537
+        if ( ! $compatible_php && current_user_can( 'update_php' ) ) {
538
+            $compat .= '<br>' . __( 'This update does not work with your version of PHP.' ) . '&nbsp;';
539
+            $compat .= sprintf(
540
+                /* translators: %s: URL to Update PHP page. */
541
+                __( '<a href="%s">Learn more about updating PHP</a>.' ),
542
+                esc_url( wp_get_update_php_url() )
543
+            );
544
+
545
+            $annotation = wp_get_update_php_annotation();
546
+
547
+            if ( $annotation ) {
548
+                $compat .= '</p><p><em>' . $annotation . '</em>';
549
+            }
550
+        }
551
+
552
+        // Get the upgrade notice for the new plugin version.
553
+        if ( isset( $plugin_data->update->upgrade_notice ) ) {
554
+            $upgrade_notice = '<br />' . strip_tags( $plugin_data->update->upgrade_notice );
555
+        } else {
556
+            $upgrade_notice = '';
557
+        }
558
+
559
+        $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data->update->slug . '&section=changelog&TB_iframe=true&width=640&height=662' );
560
+        $details     = sprintf(
561
+            '<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
562
+            esc_url( $details_url ),
563
+            /* translators: 1: Plugin name, 2: Version number. */
564
+            esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
565
+            /* translators: %s: Plugin version. */
566
+            sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
567
+        );
568
+
569
+        $checkbox_id = 'checkbox_' . md5( $plugin_file );
570
+        ?>
571 571
 	<tr>
572 572
 		<td class="check-column">
573 573
 			<?php if ( $compatible_php ) : ?>
574 574
 				<input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
575 575
 				<label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
576 576
 					<?php
577
-					/* translators: %s: Plugin name. */
578
-					printf( __( 'Select %s' ), $plugin_data->Name );
579
-					?>
577
+                    /* translators: %s: Plugin name. */
578
+                    printf( __( 'Select %s' ), $plugin_data->Name );
579
+                    ?>
580 580
 				</label>
581 581
 			<?php endif; ?>
582 582
 		</td>
@@ -584,24 +584,24 @@  discard block
 block discarded – undo
584 584
 			<?php echo $icon; ?>
585 585
 			<strong><?php echo $plugin_data->Name; ?></strong>
586 586
 			<?php
587
-			printf(
588
-				/* translators: 1: Plugin version, 2: New version. */
589
-				__( 'You have version %1$s installed. Update to %2$s.' ),
590
-				$plugin_data->Version,
591
-				$plugin_data->update->new_version
592
-			);
593
-
594
-			echo ' ' . $details . $compat . $upgrade_notice;
595
-
596
-			if ( in_array( $plugin_file, $auto_updates, true ) ) {
597
-				echo $auto_update_notice;
598
-			}
599
-			?>
587
+            printf(
588
+                /* translators: 1: Plugin version, 2: New version. */
589
+                __( 'You have version %1$s installed. Update to %2$s.' ),
590
+                $plugin_data->Version,
591
+                $plugin_data->update->new_version
592
+            );
593
+
594
+            echo ' ' . $details . $compat . $upgrade_notice;
595
+
596
+            if ( in_array( $plugin_file, $auto_updates, true ) ) {
597
+                echo $auto_update_notice;
598
+            }
599
+            ?>
600 600
 		</p></td>
601 601
 	</tr>
602 602
 			<?php
603
-	}
604
-	?>
603
+    }
604
+    ?>
605 605
 	</tbody>
606 606
 
607 607
 	<tfoot>
@@ -622,35 +622,35 @@  discard block
 block discarded – undo
622 622
  * @since 2.9.0
623 623
  */
624 624
 function list_theme_updates() {
625
-	$themes = get_theme_updates();
626
-	if ( empty( $themes ) ) {
627
-		echo '<h2>' . __( 'Themes' ) . '</h2>';
628
-		echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
629
-		return;
630
-	}
625
+    $themes = get_theme_updates();
626
+    if ( empty( $themes ) ) {
627
+        echo '<h2>' . __( 'Themes' ) . '</h2>';
628
+        echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
629
+        return;
630
+    }
631 631
 
632
-	$form_action = 'update-core.php?action=do-theme-upgrade';
632
+    $form_action = 'update-core.php?action=do-theme-upgrade';
633 633
 
634
-	$themes_count = count( $themes );
635
-	?>
634
+    $themes_count = count( $themes );
635
+    ?>
636 636
 <h2>
637 637
 	<?php
638
-	printf(
639
-		'%s <span class="count">(%d)</span>',
640
-		__( 'Themes' ),
641
-		number_format_i18n( $themes_count )
642
-	);
643
-	?>
638
+    printf(
639
+        '%s <span class="count">(%d)</span>',
640
+        __( 'Themes' ),
641
+        number_format_i18n( $themes_count )
642
+    );
643
+    ?>
644 644
 </h2>
645 645
 <p><?php _e( 'The following themes have new versions available. Check the ones you want to update and then click &#8220;Update Themes&#8221;.' ); ?></p>
646 646
 <p>
647 647
 	<?php
648
-	printf(
649
-		/* translators: %s: Link to documentation on child themes. */
650
-		__( '<strong>Please Note:</strong> Any customizations you have made to theme files will be lost. Please consider using <a href="%s">child themes</a> for modifications.' ),
651
-		__( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' )
652
-	);
653
-	?>
648
+    printf(
649
+        /* translators: %s: Link to documentation on child themes. */
650
+        __( '<strong>Please Note:</strong> Any customizations you have made to theme files will be lost. Please consider using <a href="%s">child themes</a> for modifications.' ),
651
+        __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' )
652
+    );
653
+    ?>
654 654
 </p>
655 655
 <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
656 656
 	<?php wp_nonce_field( 'upgrade-core' ); ?>
@@ -665,92 +665,92 @@  discard block
 block discarded – undo
665 665
 
666 666
 	<tbody class="plugins">
667 667
 	<?php
668
-	$auto_updates = array();
669
-	if ( wp_is_auto_update_enabled_for_type( 'theme' ) ) {
670
-		$auto_updates       = (array) get_site_option( 'auto_update_themes', array() );
671
-		$auto_update_notice = ' | ' . wp_get_auto_update_message();
672
-	}
673
-
674
-	foreach ( $themes as $stylesheet => $theme ) {
675
-		$requires_wp  = isset( $theme->update['requires'] ) ? $theme->update['requires'] : null;
676
-		$requires_php = isset( $theme->update['requires_php'] ) ? $theme->update['requires_php'] : null;
677
-
678
-		$compatible_wp  = is_wp_version_compatible( $requires_wp );
679
-		$compatible_php = is_php_version_compatible( $requires_php );
680
-
681
-		$compat = '';
682
-
683
-		if ( ! $compatible_wp && ! $compatible_php ) {
684
-			$compat .= '<br>' . __( 'This update does not work with your versions of WordPress and PHP.' ) . '&nbsp;';
685
-			if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
686
-				$compat .= sprintf(
687
-					/* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
688
-					__( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
689
-					self_admin_url( 'update-core.php' ),
690
-					esc_url( wp_get_update_php_url() )
691
-				);
692
-
693
-				$annotation = wp_get_update_php_annotation();
694
-
695
-				if ( $annotation ) {
696
-					$compat .= '</p><p><em>' . $annotation . '</em>';
697
-				}
698
-			} elseif ( current_user_can( 'update_core' ) ) {
699
-				$compat .= sprintf(
700
-					/* translators: %s: URL to WordPress Updates screen. */
701
-					__( '<a href="%s">Please update WordPress</a>.' ),
702
-					self_admin_url( 'update-core.php' )
703
-				);
704
-			} elseif ( current_user_can( 'update_php' ) ) {
705
-				$compat .= sprintf(
706
-					/* translators: %s: URL to Update PHP page. */
707
-					__( '<a href="%s">Learn more about updating PHP</a>.' ),
708
-					esc_url( wp_get_update_php_url() )
709
-				);
710
-
711
-				$annotation = wp_get_update_php_annotation();
712
-
713
-				if ( $annotation ) {
714
-					$compat .= '</p><p><em>' . $annotation . '</em>';
715
-				}
716
-			}
717
-		} elseif ( ! $compatible_wp ) {
718
-			$compat .= '<br>' . __( 'This update does not work with your version of WordPress.' ) . '&nbsp;';
719
-			if ( current_user_can( 'update_core' ) ) {
720
-				$compat .= sprintf(
721
-					/* translators: %s: URL to WordPress Updates screen. */
722
-					__( '<a href="%s">Please update WordPress</a>.' ),
723
-					self_admin_url( 'update-core.php' )
724
-				);
725
-			}
726
-		} elseif ( ! $compatible_php ) {
727
-			$compat .= '<br>' . __( 'This update does not work with your version of PHP.' ) . '&nbsp;';
728
-			if ( current_user_can( 'update_php' ) ) {
729
-				$compat .= sprintf(
730
-					/* translators: %s: URL to Update PHP page. */
731
-					__( '<a href="%s">Learn more about updating PHP</a>.' ),
732
-					esc_url( wp_get_update_php_url() )
733
-				);
734
-
735
-				$annotation = wp_get_update_php_annotation();
736
-
737
-				if ( $annotation ) {
738
-					$compat .= '</p><p><em>' . $annotation . '</em>';
739
-				}
740
-			}
741
-		}
742
-
743
-		$checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
744
-		?>
668
+    $auto_updates = array();
669
+    if ( wp_is_auto_update_enabled_for_type( 'theme' ) ) {
670
+        $auto_updates       = (array) get_site_option( 'auto_update_themes', array() );
671
+        $auto_update_notice = ' | ' . wp_get_auto_update_message();
672
+    }
673
+
674
+    foreach ( $themes as $stylesheet => $theme ) {
675
+        $requires_wp  = isset( $theme->update['requires'] ) ? $theme->update['requires'] : null;
676
+        $requires_php = isset( $theme->update['requires_php'] ) ? $theme->update['requires_php'] : null;
677
+
678
+        $compatible_wp  = is_wp_version_compatible( $requires_wp );
679
+        $compatible_php = is_php_version_compatible( $requires_php );
680
+
681
+        $compat = '';
682
+
683
+        if ( ! $compatible_wp && ! $compatible_php ) {
684
+            $compat .= '<br>' . __( 'This update does not work with your versions of WordPress and PHP.' ) . '&nbsp;';
685
+            if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
686
+                $compat .= sprintf(
687
+                    /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
688
+                    __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
689
+                    self_admin_url( 'update-core.php' ),
690
+                    esc_url( wp_get_update_php_url() )
691
+                );
692
+
693
+                $annotation = wp_get_update_php_annotation();
694
+
695
+                if ( $annotation ) {
696
+                    $compat .= '</p><p><em>' . $annotation . '</em>';
697
+                }
698
+            } elseif ( current_user_can( 'update_core' ) ) {
699
+                $compat .= sprintf(
700
+                    /* translators: %s: URL to WordPress Updates screen. */
701
+                    __( '<a href="%s">Please update WordPress</a>.' ),
702
+                    self_admin_url( 'update-core.php' )
703
+                );
704
+            } elseif ( current_user_can( 'update_php' ) ) {
705
+                $compat .= sprintf(
706
+                    /* translators: %s: URL to Update PHP page. */
707
+                    __( '<a href="%s">Learn more about updating PHP</a>.' ),
708
+                    esc_url( wp_get_update_php_url() )
709
+                );
710
+
711
+                $annotation = wp_get_update_php_annotation();
712
+
713
+                if ( $annotation ) {
714
+                    $compat .= '</p><p><em>' . $annotation . '</em>';
715
+                }
716
+            }
717
+        } elseif ( ! $compatible_wp ) {
718
+            $compat .= '<br>' . __( 'This update does not work with your version of WordPress.' ) . '&nbsp;';
719
+            if ( current_user_can( 'update_core' ) ) {
720
+                $compat .= sprintf(
721
+                    /* translators: %s: URL to WordPress Updates screen. */
722
+                    __( '<a href="%s">Please update WordPress</a>.' ),
723
+                    self_admin_url( 'update-core.php' )
724
+                );
725
+            }
726
+        } elseif ( ! $compatible_php ) {
727
+            $compat .= '<br>' . __( 'This update does not work with your version of PHP.' ) . '&nbsp;';
728
+            if ( current_user_can( 'update_php' ) ) {
729
+                $compat .= sprintf(
730
+                    /* translators: %s: URL to Update PHP page. */
731
+                    __( '<a href="%s">Learn more about updating PHP</a>.' ),
732
+                    esc_url( wp_get_update_php_url() )
733
+                );
734
+
735
+                $annotation = wp_get_update_php_annotation();
736
+
737
+                if ( $annotation ) {
738
+                    $compat .= '</p><p><em>' . $annotation . '</em>';
739
+                }
740
+            }
741
+        }
742
+
743
+        $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
744
+        ?>
745 745
 	<tr>
746 746
 		<td class="check-column">
747 747
 			<?php if ( $compatible_wp && $compatible_php ) : ?>
748 748
 				<input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
749 749
 				<label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
750 750
 					<?php
751
-					/* translators: %s: Theme name. */
752
-					printf( __( 'Select %s' ), $theme->display( 'Name' ) );
753
-					?>
751
+                    /* translators: %s: Theme name. */
752
+                    printf( __( 'Select %s' ), $theme->display( 'Name' ) );
753
+                    ?>
754 754
 				</label>
755 755
 			<?php endif; ?>
756 756
 		</td>
@@ -758,24 +758,24 @@  discard block
 block discarded – undo
758 758
 			<img src="<?php echo esc_url( $theme->get_screenshot() . '?ver=' . $theme->version ); ?>" width="85" height="64" class="updates-table-screenshot" alt="" />
759 759
 			<strong><?php echo $theme->display( 'Name' ); ?></strong>
760 760
 			<?php
761
-			printf(
762
-				/* translators: 1: Theme version, 2: New version. */
763
-				__( 'You have version %1$s installed. Update to %2$s.' ),
764
-				$theme->display( 'Version' ),
765
-				$theme->update['new_version']
766
-			);
767
-
768
-			echo ' ' . $compat;
769
-
770
-			if ( in_array( $stylesheet, $auto_updates, true ) ) {
771
-				echo $auto_update_notice;
772
-			}
773
-			?>
761
+            printf(
762
+                /* translators: 1: Theme version, 2: New version. */
763
+                __( 'You have version %1$s installed. Update to %2$s.' ),
764
+                $theme->display( 'Version' ),
765
+                $theme->update['new_version']
766
+            );
767
+
768
+            echo ' ' . $compat;
769
+
770
+            if ( in_array( $stylesheet, $auto_updates, true ) ) {
771
+                echo $auto_update_notice;
772
+            }
773
+            ?>
774 774
 		</p></td>
775 775
 	</tr>
776 776
 			<?php
777
-	}
778
-	?>
777
+    }
778
+    ?>
779 779
 	</tbody>
780 780
 
781 781
 	<tfoot>
@@ -796,17 +796,17 @@  discard block
 block discarded – undo
796 796
  * @since 3.7.0
797 797
  */
798 798
 function list_translation_updates() {
799
-	$updates = wp_get_translation_updates();
800
-	if ( ! $updates ) {
801
-		if ( 'en_US' !== get_locale() ) {
802
-			echo '<h2>' . __( 'Translations' ) . '</h2>';
803
-			echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
804
-		}
805
-		return;
806
-	}
807
-
808
-	$form_action = 'update-core.php?action=do-translation-upgrade';
809
-	?>
799
+    $updates = wp_get_translation_updates();
800
+    if ( ! $updates ) {
801
+        if ( 'en_US' !== get_locale() ) {
802
+            echo '<h2>' . __( 'Translations' ) . '</h2>';
803
+            echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
804
+        }
805
+        return;
806
+    }
807
+
808
+    $form_action = 'update-core.php?action=do-translation-upgrade';
809
+    ?>
810 810
 	<h2><?php _e( 'Translations' ); ?></h2>
811 811
 	<form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
812 812
 		<p><?php _e( 'New translations are available.' ); ?></p>
@@ -826,95 +826,95 @@  discard block
 block discarded – undo
826 826
  * @param bool $reinstall
827 827
  */
828 828
 function do_core_upgrade( $reinstall = false ) {
829
-	global $wp_filesystem;
829
+    global $wp_filesystem;
830 830
 
831
-	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
831
+    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
832 832
 
833
-	if ( $reinstall ) {
834
-		$url = 'update-core.php?action=do-core-reinstall';
835
-	} else {
836
-		$url = 'update-core.php?action=do-core-upgrade';
837
-	}
838
-	$url = wp_nonce_url( $url, 'upgrade-core' );
833
+    if ( $reinstall ) {
834
+        $url = 'update-core.php?action=do-core-reinstall';
835
+    } else {
836
+        $url = 'update-core.php?action=do-core-upgrade';
837
+    }
838
+    $url = wp_nonce_url( $url, 'upgrade-core' );
839 839
 
840
-	$version = isset( $_POST['version'] ) ? $_POST['version'] : false;
841
-	$locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
842
-	$update  = find_core_update( $version, $locale );
843
-	if ( ! $update ) {
844
-		return;
845
-	}
840
+    $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
841
+    $locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
842
+    $update  = find_core_update( $version, $locale );
843
+    if ( ! $update ) {
844
+        return;
845
+    }
846 846
 
847
-	// Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
848
-	// that it's safe to do so. This only happens when there are no new files to create.
849
-	$allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;
847
+    // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
848
+    // that it's safe to do so. This only happens when there are no new files to create.
849
+    $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;
850 850
 
851
-	?>
851
+    ?>
852 852
 	<div class="wrap">
853 853
 	<h1><?php _e( 'Update WordPress' ); ?></h1>
854 854
 	<?php
855 855
 
856
-	$credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
857
-	if ( false === $credentials ) {
858
-		echo '</div>';
859
-		return;
860
-	}
861
-
862
-	if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
863
-		// Failed to connect. Error and request again.
864
-		request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
865
-		echo '</div>';
866
-		return;
867
-	}
868
-
869
-	if ( $wp_filesystem->errors->has_errors() ) {
870
-		foreach ( $wp_filesystem->errors->get_error_messages() as $message ) {
871
-			show_message( $message );
872
-		}
873
-		echo '</div>';
874
-		return;
875
-	}
876
-
877
-	if ( $reinstall ) {
878
-		$update->response = 'reinstall';
879
-	}
880
-
881
-	add_filter( 'update_feedback', 'show_message' );
882
-
883
-	$upgrader = new Core_Upgrader();
884
-	$result   = $upgrader->upgrade(
885
-		$update,
886
-		array(
887
-			'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
888
-		)
889
-	);
890
-
891
-	if ( is_wp_error( $result ) ) {
892
-		show_message( $result );
893
-		if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() ) {
894
-			show_message( __( 'Installation failed.' ) );
895
-		}
896
-		echo '</div>';
897
-		return;
898
-	}
899
-
900
-	show_message( __( 'WordPress updated successfully.' ) );
901
-	show_message(
902
-		'<span class="hide-if-no-js">' . sprintf(
903
-			/* translators: 1: WordPress version, 2: URL to About screen. */
904
-			__( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ),
905
-			$result,
906
-			esc_url( self_admin_url( 'about.php?updated' ) )
907
-		) . '</span>'
908
-	);
909
-	show_message(
910
-		'<span class="hide-if-js">' . sprintf(
911
-			/* translators: 1: WordPress version, 2: URL to About screen. */
912
-			__( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ),
913
-			$result,
914
-			esc_url( self_admin_url( 'about.php?updated' ) )
915
-		) . '</span>'
916
-	);
917
-	?>
856
+    $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
857
+    if ( false === $credentials ) {
858
+        echo '</div>';
859
+        return;
860
+    }
861
+
862
+    if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
863
+        // Failed to connect. Error and request again.
864
+        request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
865
+        echo '</div>';
866
+        return;
867
+    }
868
+
869
+    if ( $wp_filesystem->errors->has_errors() ) {
870
+        foreach ( $wp_filesystem->errors->get_error_messages() as $message ) {
871
+            show_message( $message );
872
+        }
873
+        echo '</div>';
874
+        return;
875
+    }
876
+
877
+    if ( $reinstall ) {
878
+        $update->response = 'reinstall';
879
+    }
880
+
881
+    add_filter( 'update_feedback', 'show_message' );
882
+
883
+    $upgrader = new Core_Upgrader();
884
+    $result   = $upgrader->upgrade(
885
+        $update,
886
+        array(
887
+            'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
888
+        )
889
+    );
890
+
891
+    if ( is_wp_error( $result ) ) {
892
+        show_message( $result );
893
+        if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() ) {
894
+            show_message( __( 'Installation failed.' ) );
895
+        }
896
+        echo '</div>';
897
+        return;
898
+    }
899
+
900
+    show_message( __( 'WordPress updated successfully.' ) );
901
+    show_message(
902
+        '<span class="hide-if-no-js">' . sprintf(
903
+            /* translators: 1: WordPress version, 2: URL to About screen. */
904
+            __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ),
905
+            $result,
906
+            esc_url( self_admin_url( 'about.php?updated' ) )
907
+        ) . '</span>'
908
+    );
909
+    show_message(
910
+        '<span class="hide-if-js">' . sprintf(
911
+            /* translators: 1: WordPress version, 2: URL to About screen. */
912
+            __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ),
913
+            $result,
914
+            esc_url( self_admin_url( 'about.php?updated' ) )
915
+        ) . '</span>'
916
+    );
917
+    ?>
918 918
 	</div>
919 919
 	<script type="text/javascript">
920 920
 	window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
@@ -928,15 +928,15 @@  discard block
 block discarded – undo
928 928
  * @since 2.7.0
929 929
  */
930 930
 function do_dismiss_core_update() {
931
-	$version = isset( $_POST['version'] ) ? $_POST['version'] : false;
932
-	$locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
933
-	$update  = find_core_update( $version, $locale );
934
-	if ( ! $update ) {
935
-		return;
936
-	}
937
-	dismiss_core_update( $update );
938
-	wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
939
-	exit;
931
+    $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
932
+    $locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
933
+    $update  = find_core_update( $version, $locale );
934
+    if ( ! $update ) {
935
+        return;
936
+    }
937
+    dismiss_core_update( $update );
938
+    wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
939
+    exit;
940 940
 }
941 941
 
942 942
 /**
@@ -945,24 +945,24 @@  discard block
 block discarded – undo
945 945
  * @since 2.7.0
946 946
  */
947 947
 function do_undismiss_core_update() {
948
-	$version = isset( $_POST['version'] ) ? $_POST['version'] : false;
949
-	$locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
950
-	$update  = find_core_update( $version, $locale );
951
-	if ( ! $update ) {
952
-		return;
953
-	}
954
-	undismiss_core_update( $version, $locale );
955
-	wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
956
-	exit;
948
+    $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
949
+    $locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
950
+    $update  = find_core_update( $version, $locale );
951
+    if ( ! $update ) {
952
+        return;
953
+    }
954
+    undismiss_core_update( $version, $locale );
955
+    wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
956
+    exit;
957 957
 }
958 958
 
959 959
 $action = isset( $_GET['action'] ) ? $_GET['action'] : 'upgrade-core';
960 960
 
961 961
 $upgrade_error = false;
962 962
 if ( ( 'do-theme-upgrade' === $action || ( 'do-plugin-upgrade' === $action && ! isset( $_GET['plugins'] ) ) )
963
-	&& ! isset( $_POST['checked'] ) ) {
964
-	$upgrade_error = ( 'do-theme-upgrade' === $action ) ? 'themes' : 'plugins';
965
-	$action        = 'upgrade-core';
963
+    && ! isset( $_POST['checked'] ) ) {
964
+    $upgrade_error = ( 'do-theme-upgrade' === $action ) ? 'themes' : 'plugins';
965
+    $action        = 'upgrade-core';
966 966
 }
967 967
 
968 968
 $title       = __( 'WordPress Updates' );
@@ -972,302 +972,302 @@  discard block
 block discarded – undo
972 972
 $updates_overview .= '<p>' . __( 'If an update is available, you&#8127;ll see a notification appear in the Toolbar and navigation menu.' ) . ' ' . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' ) . '</p>';
973 973
 
974 974
 get_current_screen()->add_help_tab(
975
-	array(
976
-		'id'      => 'overview',
977
-		'title'   => __( 'Overview' ),
978
-		'content' => $updates_overview,
979
-	)
975
+    array(
976
+        'id'      => 'overview',
977
+        'title'   => __( 'Overview' ),
978
+        'content' => $updates_overview,
979
+    )
980 980
 );
981 981
 
982 982
 $updates_howto  = '<p>' . __( '<strong>WordPress</strong> &mdash; Updating your WordPress installation is a simple one-click procedure: just <strong>click on the &#8220;Update now&#8221; button</strong> when you are notified that a new version is available.' ) . ' ' . __( 'In most cases, WordPress will automatically apply maintenance and security updates in the background for you.' ) . '</p>';
983 983
 $updates_howto .= '<p>' . __( '<strong>Themes and Plugins</strong> &mdash; To update individual themes or plugins from this screen, use the checkboxes to make your selection, then <strong>click on the appropriate &#8220;Update&#8221; button</strong>. To update all of your themes or plugins at once, you can check the box at the top of the section to select all before clicking the update button.' ) . '</p>';
984 984
 
985 985
 if ( 'en_US' !== get_locale() ) {
986
-	$updates_howto .= '<p>' . __( '<strong>Translations</strong> &mdash; The files translating WordPress into your language are updated for you whenever any other updates occur. But if these files are out of date, you can <strong>click the &#8220;Update Translations&#8221;</strong> button.' ) . '</p>';
986
+    $updates_howto .= '<p>' . __( '<strong>Translations</strong> &mdash; The files translating WordPress into your language are updated for you whenever any other updates occur. But if these files are out of date, you can <strong>click the &#8220;Update Translations&#8221;</strong> button.' ) . '</p>';
987 987
 }
988 988
 
989 989
 get_current_screen()->add_help_tab(
990
-	array(
991
-		'id'      => 'how-to-update',
992
-		'title'   => __( 'How to Update' ),
993
-		'content' => $updates_howto,
994
-	)
990
+    array(
991
+        'id'      => 'how-to-update',
992
+        'title'   => __( 'How to Update' ),
993
+        'content' => $updates_howto,
994
+    )
995 995
 );
996 996
 
997 997
 $help_sidebar_autoupdates = '';
998 998
 
999 999
 if ( ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) || ( current_user_can( 'update_plugins' ) && wp_is_auto_update_enabled_for_type( 'plugin' ) ) ) {
1000
-	$help_tab_autoupdates  = '<p>' . __( 'Auto-updates can be enabled or disabled for WordPress major versions and for each individual theme or plugin. Themes or plugins with auto-updates enabled will display the estimated date of the next auto-update. Auto-updates depends on the WP-Cron task scheduling system.' ) . '</p>';
1001
-	$help_tab_autoupdates .= '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>';
1002
-
1003
-	get_current_screen()->add_help_tab(
1004
-		array(
1005
-			'id'      => 'plugins-themes-auto-updates',
1006
-			'title'   => __( 'Auto-updates' ),
1007
-			'content' => $help_tab_autoupdates,
1008
-		)
1009
-	);
1010
-
1011
-	$help_sidebar_autoupdates = '<p>' . __( '<a href="https://wordpress.org/support/article/plugins-themes-auto-updates/">Learn more: Auto-updates documentation</a>' ) . '</p>';
1000
+    $help_tab_autoupdates  = '<p>' . __( 'Auto-updates can be enabled or disabled for WordPress major versions and for each individual theme or plugin. Themes or plugins with auto-updates enabled will display the estimated date of the next auto-update. Auto-updates depends on the WP-Cron task scheduling system.' ) . '</p>';
1001
+    $help_tab_autoupdates .= '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>';
1002
+
1003
+    get_current_screen()->add_help_tab(
1004
+        array(
1005
+            'id'      => 'plugins-themes-auto-updates',
1006
+            'title'   => __( 'Auto-updates' ),
1007
+            'content' => $help_tab_autoupdates,
1008
+        )
1009
+    );
1010
+
1011
+    $help_sidebar_autoupdates = '<p>' . __( '<a href="https://wordpress.org/support/article/plugins-themes-auto-updates/">Learn more: Auto-updates documentation</a>' ) . '</p>';
1012 1012
 }
1013 1013
 
1014 1014
 get_current_screen()->set_help_sidebar(
1015
-	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
1016
-	'<p>' . __( '<a href="https://wordpress.org/support/article/dashboard-updates-screen/">Documentation on Updating WordPress</a>' ) . '</p>' .
1017
-	$help_sidebar_autoupdates .
1018
-	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
1015
+    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
1016
+    '<p>' . __( '<a href="https://wordpress.org/support/article/dashboard-updates-screen/">Documentation on Updating WordPress</a>' ) . '</p>' .
1017
+    $help_sidebar_autoupdates .
1018
+    '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
1019 1019
 );
1020 1020
 
1021 1021
 if ( 'upgrade-core' === $action ) {
1022
-	// Force a update check when requested.
1023
-	$force_check = ! empty( $_GET['force-check'] );
1024
-	wp_version_check( array(), $force_check );
1022
+    // Force a update check when requested.
1023
+    $force_check = ! empty( $_GET['force-check'] );
1024
+    wp_version_check( array(), $force_check );
1025 1025
 
1026
-	require_once ABSPATH . 'wp-admin/admin-header.php';
1027
-	?>
1026
+    require_once ABSPATH . 'wp-admin/admin-header.php';
1027
+    ?>
1028 1028
 	<div class="wrap">
1029 1029
 	<h1><?php _e( 'WordPress Updates' ); ?></h1>
1030 1030
 	<p><?php _e( 'Here you can find information about updates, set auto-updates and see what plugins or themes need updating.' ); ?></p>
1031 1031
 
1032 1032
 	<?php
1033
-	if ( $upgrade_error ) {
1034
-		echo '<div class="error"><p>';
1035
-		if ( 'themes' === $upgrade_error ) {
1036
-			_e( 'Please select one or more themes to update.' );
1037
-		} else {
1038
-			_e( 'Please select one or more plugins to update.' );
1039
-		}
1040
-		echo '</p></div>';
1041
-	}
1042
-
1043
-	$last_update_check = false;
1044
-	$current           = get_site_transient( 'update_core' );
1045
-
1046
-	if ( $current && isset( $current->last_checked ) ) {
1047
-		$last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
1048
-	}
1049
-
1050
-	echo '<h2 class="wp-current-version">';
1051
-	/* translators: Current version of WordPress. */
1052
-	printf( __( 'Current version: %s' ), get_bloginfo( 'version' ) );
1053
-	echo '</h2>';
1054
-
1055
-	echo '<p class="update-last-checked">';
1056
-	/* translators: 1: Date, 2: Time. */
1057
-	printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ), $last_update_check ), date_i18n( __( 'g:i a T' ), $last_update_check ) );
1058
-	echo ' <a href="' . esc_url( self_admin_url( 'update-core.php?force-check=1' ) ) . '">' . __( 'Check again.' ) . '</a>';
1059
-	echo '</p>';
1060
-
1061
-	if ( current_user_can( 'update_core' ) ) {
1062
-		core_auto_updates_settings();
1063
-		core_upgrade_preamble();
1064
-	}
1065
-	if ( current_user_can( 'update_plugins' ) ) {
1066
-		list_plugin_updates();
1067
-	}
1068
-	if ( current_user_can( 'update_themes' ) ) {
1069
-		list_theme_updates();
1070
-	}
1071
-	if ( current_user_can( 'update_languages' ) ) {
1072
-		list_translation_updates();
1073
-	}
1074
-
1075
-	/**
1076
-	 * Fires after the core, plugin, and theme update tables.
1077
-	 *
1078
-	 * @since 2.9.0
1079
-	 */
1080
-	do_action( 'core_upgrade_preamble' );
1081
-	echo '</div>';
1082
-
1083
-	wp_localize_script(
1084
-		'updates',
1085
-		'_wpUpdatesItemCounts',
1086
-		array(
1087
-			'totals' => wp_get_update_data(),
1088
-		)
1089
-	);
1090
-
1091
-	require_once ABSPATH . 'wp-admin/admin-footer.php';
1033
+    if ( $upgrade_error ) {
1034
+        echo '<div class="error"><p>';
1035
+        if ( 'themes' === $upgrade_error ) {
1036
+            _e( 'Please select one or more themes to update.' );
1037
+        } else {
1038
+            _e( 'Please select one or more plugins to update.' );
1039
+        }
1040
+        echo '</p></div>';
1041
+    }
1042
+
1043
+    $last_update_check = false;
1044
+    $current           = get_site_transient( 'update_core' );
1045
+
1046
+    if ( $current && isset( $current->last_checked ) ) {
1047
+        $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
1048
+    }
1049
+
1050
+    echo '<h2 class="wp-current-version">';
1051
+    /* translators: Current version of WordPress. */
1052
+    printf( __( 'Current version: %s' ), get_bloginfo( 'version' ) );
1053
+    echo '</h2>';
1054
+
1055
+    echo '<p class="update-last-checked">';
1056
+    /* translators: 1: Date, 2: Time. */
1057
+    printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ), $last_update_check ), date_i18n( __( 'g:i a T' ), $last_update_check ) );
1058
+    echo ' <a href="' . esc_url( self_admin_url( 'update-core.php?force-check=1' ) ) . '">' . __( 'Check again.' ) . '</a>';
1059
+    echo '</p>';
1060
+
1061
+    if ( current_user_can( 'update_core' ) ) {
1062
+        core_auto_updates_settings();
1063
+        core_upgrade_preamble();
1064
+    }
1065
+    if ( current_user_can( 'update_plugins' ) ) {
1066
+        list_plugin_updates();
1067
+    }
1068
+    if ( current_user_can( 'update_themes' ) ) {
1069
+        list_theme_updates();
1070
+    }
1071
+    if ( current_user_can( 'update_languages' ) ) {
1072
+        list_translation_updates();
1073
+    }
1074
+
1075
+    /**
1076
+     * Fires after the core, plugin, and theme update tables.
1077
+     *
1078
+     * @since 2.9.0
1079
+     */
1080
+    do_action( 'core_upgrade_preamble' );
1081
+    echo '</div>';
1082
+
1083
+    wp_localize_script(
1084
+        'updates',
1085
+        '_wpUpdatesItemCounts',
1086
+        array(
1087
+            'totals' => wp_get_update_data(),
1088
+        )
1089
+    );
1090
+
1091
+    require_once ABSPATH . 'wp-admin/admin-footer.php';
1092 1092
 
1093 1093
 } elseif ( 'do-core-upgrade' === $action || 'do-core-reinstall' === $action ) {
1094 1094
 
1095
-	if ( ! current_user_can( 'update_core' ) ) {
1096
-		wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1097
-	}
1095
+    if ( ! current_user_can( 'update_core' ) ) {
1096
+        wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1097
+    }
1098 1098
 
1099
-	check_admin_referer( 'upgrade-core' );
1099
+    check_admin_referer( 'upgrade-core' );
1100 1100
 
1101
-	// Do the (un)dismiss actions before headers, so that they can redirect.
1102
-	if ( isset( $_POST['dismiss'] ) ) {
1103
-		do_dismiss_core_update();
1104
-	} elseif ( isset( $_POST['undismiss'] ) ) {
1105
-		do_undismiss_core_update();
1106
-	}
1101
+    // Do the (un)dismiss actions before headers, so that they can redirect.
1102
+    if ( isset( $_POST['dismiss'] ) ) {
1103
+        do_dismiss_core_update();
1104
+    } elseif ( isset( $_POST['undismiss'] ) ) {
1105
+        do_undismiss_core_update();
1106
+    }
1107 1107
 
1108
-	require_once ABSPATH . 'wp-admin/admin-header.php';
1109
-	if ( 'do-core-reinstall' === $action ) {
1110
-		$reinstall = true;
1111
-	} else {
1112
-		$reinstall = false;
1113
-	}
1108
+    require_once ABSPATH . 'wp-admin/admin-header.php';
1109
+    if ( 'do-core-reinstall' === $action ) {
1110
+        $reinstall = true;
1111
+    } else {
1112
+        $reinstall = false;
1113
+    }
1114 1114
 
1115
-	if ( isset( $_POST['upgrade'] ) ) {
1116
-		do_core_upgrade( $reinstall );
1117
-	}
1115
+    if ( isset( $_POST['upgrade'] ) ) {
1116
+        do_core_upgrade( $reinstall );
1117
+    }
1118 1118
 
1119
-	wp_localize_script(
1120
-		'updates',
1121
-		'_wpUpdatesItemCounts',
1122
-		array(
1123
-			'totals' => wp_get_update_data(),
1124
-		)
1125
-	);
1119
+    wp_localize_script(
1120
+        'updates',
1121
+        '_wpUpdatesItemCounts',
1122
+        array(
1123
+            'totals' => wp_get_update_data(),
1124
+        )
1125
+    );
1126 1126
 
1127
-	require_once ABSPATH . 'wp-admin/admin-footer.php';
1127
+    require_once ABSPATH . 'wp-admin/admin-footer.php';
1128 1128
 
1129 1129
 } elseif ( 'do-plugin-upgrade' === $action ) {
1130 1130
 
1131
-	if ( ! current_user_can( 'update_plugins' ) ) {
1132
-		wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1133
-	}
1131
+    if ( ! current_user_can( 'update_plugins' ) ) {
1132
+        wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1133
+    }
1134 1134
 
1135
-	check_admin_referer( 'upgrade-core' );
1135
+    check_admin_referer( 'upgrade-core' );
1136 1136
 
1137
-	if ( isset( $_GET['plugins'] ) ) {
1138
-		$plugins = explode( ',', $_GET['plugins'] );
1139
-	} elseif ( isset( $_POST['checked'] ) ) {
1140
-		$plugins = (array) $_POST['checked'];
1141
-	} else {
1142
-		wp_redirect( admin_url( 'update-core.php' ) );
1143
-		exit;
1144
-	}
1137
+    if ( isset( $_GET['plugins'] ) ) {
1138
+        $plugins = explode( ',', $_GET['plugins'] );
1139
+    } elseif ( isset( $_POST['checked'] ) ) {
1140
+        $plugins = (array) $_POST['checked'];
1141
+    } else {
1142
+        wp_redirect( admin_url( 'update-core.php' ) );
1143
+        exit;
1144
+    }
1145 1145
 
1146
-	$url = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) );
1147
-	$url = wp_nonce_url( $url, 'bulk-update-plugins' );
1146
+    $url = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) );
1147
+    $url = wp_nonce_url( $url, 'bulk-update-plugins' );
1148 1148
 
1149
-	// Used in the HTML title tag.
1150
-	$title = __( 'Update Plugins' );
1149
+    // Used in the HTML title tag.
1150
+    $title = __( 'Update Plugins' );
1151 1151
 
1152
-	require_once ABSPATH . 'wp-admin/admin-header.php';
1153
-	?>
1152
+    require_once ABSPATH . 'wp-admin/admin-header.php';
1153
+    ?>
1154 1154
 	<div class="wrap">
1155 1155
 		<h1><?php _e( 'Update Plugins' ); ?></h1>
1156 1156
 		<iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
1157 1157
 	</div>
1158 1158
 	<?php
1159 1159
 
1160
-	wp_localize_script(
1161
-		'updates',
1162
-		'_wpUpdatesItemCounts',
1163
-		array(
1164
-			'totals' => wp_get_update_data(),
1165
-		)
1166
-	);
1160
+    wp_localize_script(
1161
+        'updates',
1162
+        '_wpUpdatesItemCounts',
1163
+        array(
1164
+            'totals' => wp_get_update_data(),
1165
+        )
1166
+    );
1167 1167
 
1168
-	require_once ABSPATH . 'wp-admin/admin-footer.php';
1168
+    require_once ABSPATH . 'wp-admin/admin-footer.php';
1169 1169
 
1170 1170
 } elseif ( 'do-theme-upgrade' === $action ) {
1171 1171
 
1172
-	if ( ! current_user_can( 'update_themes' ) ) {
1173
-		wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1174
-	}
1172
+    if ( ! current_user_can( 'update_themes' ) ) {
1173
+        wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1174
+    }
1175 1175
 
1176
-	check_admin_referer( 'upgrade-core' );
1176
+    check_admin_referer( 'upgrade-core' );
1177 1177
 
1178
-	if ( isset( $_GET['themes'] ) ) {
1179
-		$themes = explode( ',', $_GET['themes'] );
1180
-	} elseif ( isset( $_POST['checked'] ) ) {
1181
-		$themes = (array) $_POST['checked'];
1182
-	} else {
1183
-		wp_redirect( admin_url( 'update-core.php' ) );
1184
-		exit;
1185
-	}
1178
+    if ( isset( $_GET['themes'] ) ) {
1179
+        $themes = explode( ',', $_GET['themes'] );
1180
+    } elseif ( isset( $_POST['checked'] ) ) {
1181
+        $themes = (array) $_POST['checked'];
1182
+    } else {
1183
+        wp_redirect( admin_url( 'update-core.php' ) );
1184
+        exit;
1185
+    }
1186 1186
 
1187
-	$url = 'update.php?action=update-selected-themes&themes=' . urlencode( implode( ',', $themes ) );
1188
-	$url = wp_nonce_url( $url, 'bulk-update-themes' );
1187
+    $url = 'update.php?action=update-selected-themes&themes=' . urlencode( implode( ',', $themes ) );
1188
+    $url = wp_nonce_url( $url, 'bulk-update-themes' );
1189 1189
 
1190
-	// Used in the HTML title tag.
1191
-	$title = __( 'Update Themes' );
1190
+    // Used in the HTML title tag.
1191
+    $title = __( 'Update Themes' );
1192 1192
 
1193
-	require_once ABSPATH . 'wp-admin/admin-header.php';
1194
-	?>
1193
+    require_once ABSPATH . 'wp-admin/admin-header.php';
1194
+    ?>
1195 1195
 	<div class="wrap">
1196 1196
 		<h1><?php _e( 'Update Themes' ); ?></h1>
1197 1197
 		<iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
1198 1198
 	</div>
1199 1199
 	<?php
1200 1200
 
1201
-	wp_localize_script(
1202
-		'updates',
1203
-		'_wpUpdatesItemCounts',
1204
-		array(
1205
-			'totals' => wp_get_update_data(),
1206
-		)
1207
-	);
1201
+    wp_localize_script(
1202
+        'updates',
1203
+        '_wpUpdatesItemCounts',
1204
+        array(
1205
+            'totals' => wp_get_update_data(),
1206
+        )
1207
+    );
1208 1208
 
1209
-	require_once ABSPATH . 'wp-admin/admin-footer.php';
1209
+    require_once ABSPATH . 'wp-admin/admin-footer.php';
1210 1210
 
1211 1211
 } elseif ( 'do-translation-upgrade' === $action ) {
1212 1212
 
1213
-	if ( ! current_user_can( 'update_languages' ) ) {
1214
-		wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1215
-	}
1213
+    if ( ! current_user_can( 'update_languages' ) ) {
1214
+        wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1215
+    }
1216 1216
 
1217
-	check_admin_referer( 'upgrade-translations' );
1217
+    check_admin_referer( 'upgrade-translations' );
1218 1218
 
1219
-	require_once ABSPATH . 'wp-admin/admin-header.php';
1220
-	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1219
+    require_once ABSPATH . 'wp-admin/admin-header.php';
1220
+    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1221 1221
 
1222
-	$url     = 'update-core.php?action=do-translation-upgrade';
1223
-	$nonce   = 'upgrade-translations';
1224
-	$title   = __( 'Update Translations' );
1225
-	$context = WP_LANG_DIR;
1222
+    $url     = 'update-core.php?action=do-translation-upgrade';
1223
+    $nonce   = 'upgrade-translations';
1224
+    $title   = __( 'Update Translations' );
1225
+    $context = WP_LANG_DIR;
1226 1226
 
1227
-	$upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
1228
-	$result   = $upgrader->bulk_upgrade();
1227
+    $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
1228
+    $result   = $upgrader->bulk_upgrade();
1229 1229
 
1230
-	wp_localize_script(
1231
-		'updates',
1232
-		'_wpUpdatesItemCounts',
1233
-		array(
1234
-			'totals' => wp_get_update_data(),
1235
-		)
1236
-	);
1230
+    wp_localize_script(
1231
+        'updates',
1232
+        '_wpUpdatesItemCounts',
1233
+        array(
1234
+            'totals' => wp_get_update_data(),
1235
+        )
1236
+    );
1237 1237
 
1238
-	require_once ABSPATH . 'wp-admin/admin-footer.php';
1238
+    require_once ABSPATH . 'wp-admin/admin-footer.php';
1239 1239
 
1240 1240
 } elseif ( 'core-major-auto-updates-settings' === $action ) {
1241 1241
 
1242
-	if ( ! current_user_can( 'update_core' ) ) {
1243
-		wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1244
-	}
1242
+    if ( ! current_user_can( 'update_core' ) ) {
1243
+        wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
1244
+    }
1245 1245
 
1246
-	$redirect_url = self_admin_url( 'update-core.php' );
1246
+    $redirect_url = self_admin_url( 'update-core.php' );
1247 1247
 
1248
-	if ( isset( $_GET['value'] ) ) {
1249
-		check_admin_referer( 'core-major-auto-updates-nonce' );
1248
+    if ( isset( $_GET['value'] ) ) {
1249
+        check_admin_referer( 'core-major-auto-updates-nonce' );
1250 1250
 
1251
-		if ( 'enable' === $_GET['value'] ) {
1252
-			update_site_option( 'auto_update_core_major', 'enabled' );
1253
-			$redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'enabled', $redirect_url );
1254
-		} elseif ( 'disable' === $_GET['value'] ) {
1255
-			update_site_option( 'auto_update_core_major', 'disabled' );
1256
-			$redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'disabled', $redirect_url );
1257
-		}
1258
-	}
1251
+        if ( 'enable' === $_GET['value'] ) {
1252
+            update_site_option( 'auto_update_core_major', 'enabled' );
1253
+            $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'enabled', $redirect_url );
1254
+        } elseif ( 'disable' === $_GET['value'] ) {
1255
+            update_site_option( 'auto_update_core_major', 'disabled' );
1256
+            $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'disabled', $redirect_url );
1257
+        }
1258
+    }
1259 1259
 
1260
-	wp_redirect( $redirect_url );
1261
-	exit;
1260
+    wp_redirect( $redirect_url );
1261
+    exit;
1262 1262
 } else {
1263
-	/**
1264
-	 * Fires for each custom update action on the WordPress Updates screen.
1265
-	 *
1266
-	 * The dynamic portion of the hook name, `$action`, refers to the
1267
-	 * passed update action. The hook fires in lieu of all available
1268
-	 * default update actions.
1269
-	 *
1270
-	 * @since 3.2.0
1271
-	 */
1272
-	do_action( "update-core-custom_{$action}" );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1263
+    /**
1264
+     * Fires for each custom update action on the WordPress Updates screen.
1265
+     *
1266
+     * The dynamic portion of the hook name, `$action`, refers to the
1267
+     * passed update action. The hook fires in lieu of all available
1268
+     * default update actions.
1269
+     *
1270
+     * @since 3.2.0
1271
+     */
1272
+    do_action( "update-core-custom_{$action}" );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1273 1273
 }
Please login to merge, or discard this patch.
brighty/wp-admin/my-sites.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -10,11 +10,11 @@  discard block
 block discarded – undo
10 10
 require_once __DIR__ . '/admin.php';
11 11
 
12 12
 if ( ! is_multisite() ) {
13
-	wp_die( __( 'Multisite support is not enabled.' ) );
13
+    wp_die( __( 'Multisite support is not enabled.' ) );
14 14
 }
15 15
 
16 16
 if ( ! current_user_can( 'read' ) ) {
17
-	wp_die( __( 'Sorry, you are not allowed to access this page.' ) );
17
+    wp_die( __( 'Sorry, you are not allowed to access this page.' ) );
18 18
 }
19 19
 
20 20
 $action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 
24 24
 $updated = false;
25 25
 if ( 'updateblogsettings' === $action && isset( $_POST['primary_blog'] ) ) {
26
-	check_admin_referer( 'update-my-sites' );
27
-
28
-	$blog = get_site( (int) $_POST['primary_blog'] );
29
-	if ( $blog && isset( $blog->domain ) ) {
30
-		update_user_meta( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'] );
31
-		$updated = true;
32
-	} else {
33
-		wp_die( __( 'The primary site you chose does not exist.' ) );
34
-	}
26
+    check_admin_referer( 'update-my-sites' );
27
+
28
+    $blog = get_site( (int) $_POST['primary_blog'] );
29
+    if ( $blog && isset( $blog->domain ) ) {
30
+        update_user_meta( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'] );
31
+        $updated = true;
32
+    } else {
33
+        wp_die( __( 'The primary site you chose does not exist.' ) );
34
+    }
35 35
 }
36 36
 
37 37
 // Used in the HTML title tag.
@@ -39,18 +39,18 @@  discard block
 block discarded – undo
39 39
 $parent_file = 'index.php';
40 40
 
41 41
 get_current_screen()->add_help_tab(
42
-	array(
43
-		'id'      => 'overview',
44
-		'title'   => __( 'Overview' ),
45
-		'content' =>
46
-			'<p>' . __( 'This screen shows an individual user all of their sites in this network, and also allows that user to set a primary site. They can use the links under each site to visit either the front end or the dashboard for that site.' ) . '</p>',
47
-	)
42
+    array(
43
+        'id'      => 'overview',
44
+        'title'   => __( 'Overview' ),
45
+        'content' =>
46
+            '<p>' . __( 'This screen shows an individual user all of their sites in this network, and also allows that user to set a primary site. They can use the links under each site to visit either the front end or the dashboard for that site.' ) . '</p>',
47
+    )
48 48
 );
49 49
 
50 50
 get_current_screen()->set_help_sidebar(
51
-	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
52
-	'<p>' . __( '<a href="https://codex.wordpress.org/Dashboard_My_Sites_Screen">Documentation on My Sites</a>' ) . '</p>' .
53
-	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
51
+    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
52
+    '<p>' . __( '<a href="https://codex.wordpress.org/Dashboard_My_Sites_Screen">Documentation on My Sites</a>' ) . '</p>' .
53
+    '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
54 54
 );
55 55
 
56 56
 require_once ABSPATH . 'wp-admin/admin-header.php';
@@ -68,96 +68,96 @@  discard block
 block discarded – undo
68 68
 
69 69
 <?php
70 70
 if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ), true ) ) {
71
-	/** This filter is documented in wp-login.php */
72
-	$sign_up_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) );
73
-	printf( ' <a href="%s" class="page-title-action">%s</a>', esc_url( $sign_up_url ), esc_html_x( 'Add New', 'site' ) );
71
+    /** This filter is documented in wp-login.php */
72
+    $sign_up_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) );
73
+    printf( ' <a href="%s" class="page-title-action">%s</a>', esc_url( $sign_up_url ), esc_html_x( 'Add New', 'site' ) );
74 74
 }
75 75
 
76 76
 if ( empty( $blogs ) ) :
77
-	echo '<p>';
78
-	_e( 'You must be a member of at least one site to use this page.' );
79
-	echo '</p>';
77
+    echo '<p>';
78
+    _e( 'You must be a member of at least one site to use this page.' );
79
+    echo '</p>';
80 80
 else :
81
-	?>
81
+    ?>
82 82
 
83 83
 <hr class="wp-header-end">
84 84
 
85 85
 <form id="myblogs" method="post">
86 86
 	<?php
87
-	choose_primary_blog();
88
-	/**
89
-	 * Fires before the sites list on the My Sites screen.
90
-	 *
91
-	 * @since 3.0.0
92
-	 */
93
-	do_action( 'myblogs_allblogs_options' );
94
-	?>
87
+    choose_primary_blog();
88
+    /**
89
+     * Fires before the sites list on the My Sites screen.
90
+     *
91
+     * @since 3.0.0
92
+     */
93
+    do_action( 'myblogs_allblogs_options' );
94
+    ?>
95 95
 	<br clear="all" />
96 96
 	<ul class="my-sites striped">
97 97
 	<?php
98
-	/**
99
-	 * Enable the Global Settings section on the My Sites screen.
100
-	 *
101
-	 * By default, the Global Settings section is hidden. Passing a non-empty
102
-	 * string to this filter will enable the section, and allow new settings
103
-	 * to be added, either globally or for specific sites.
104
-	 *
105
-	 * @since MU (3.0.0)
106
-	 *
107
-	 * @param string $settings_html The settings HTML markup. Default empty.
108
-	 * @param string $context       Context of the setting (global or site-specific). Default 'global'.
109
-	 */
110
-	$settings_html = apply_filters( 'myblogs_options', '', 'global' );
111
-
112
-	if ( $settings_html ) {
113
-		echo '<h3>' . __( 'Global Settings' ) . '</h3>';
114
-		echo $settings_html;
115
-	}
116
-
117
-	reset( $blogs );
118
-
119
-	foreach ( $blogs as $user_blog ) {
120
-		switch_to_blog( $user_blog->userblog_id );
121
-
122
-		echo '<li>';
123
-		echo "<h3>{$user_blog->blogname}</h3>";
124
-
125
-		$actions = "<a href='" . esc_url( home_url() ) . "'>" . __( 'Visit' ) . '</a>';
126
-
127
-		if ( current_user_can( 'read' ) ) {
128
-			$actions .= " | <a href='" . esc_url( admin_url() ) . "'>" . __( 'Dashboard' ) . '</a>';
129
-		}
130
-
131
-		/**
132
-		 * Filters the row links displayed for each site on the My Sites screen.
133
-		 *
134
-		 * @since MU (3.0.0)
135
-		 *
136
-		 * @param string $actions   The HTML site link markup.
137
-		 * @param object $user_blog An object containing the site data.
138
-		 */
139
-		$actions = apply_filters( 'myblogs_blog_actions', $actions, $user_blog );
140
-
141
-		echo "<p class='my-sites-actions'>" . $actions . '</p>';
142
-
143
-		/** This filter is documented in wp-admin/my-sites.php */
144
-		echo apply_filters( 'myblogs_options', '', $user_blog );
145
-
146
-		echo '</li>';
147
-
148
-		restore_current_blog();
149
-	}
150
-	?>
98
+    /**
99
+     * Enable the Global Settings section on the My Sites screen.
100
+     *
101
+     * By default, the Global Settings section is hidden. Passing a non-empty
102
+     * string to this filter will enable the section, and allow new settings
103
+     * to be added, either globally or for specific sites.
104
+     *
105
+     * @since MU (3.0.0)
106
+     *
107
+     * @param string $settings_html The settings HTML markup. Default empty.
108
+     * @param string $context       Context of the setting (global or site-specific). Default 'global'.
109
+     */
110
+    $settings_html = apply_filters( 'myblogs_options', '', 'global' );
111
+
112
+    if ( $settings_html ) {
113
+        echo '<h3>' . __( 'Global Settings' ) . '</h3>';
114
+        echo $settings_html;
115
+    }
116
+
117
+    reset( $blogs );
118
+
119
+    foreach ( $blogs as $user_blog ) {
120
+        switch_to_blog( $user_blog->userblog_id );
121
+
122
+        echo '<li>';
123
+        echo "<h3>{$user_blog->blogname}</h3>";
124
+
125
+        $actions = "<a href='" . esc_url( home_url() ) . "'>" . __( 'Visit' ) . '</a>';
126
+
127
+        if ( current_user_can( 'read' ) ) {
128
+            $actions .= " | <a href='" . esc_url( admin_url() ) . "'>" . __( 'Dashboard' ) . '</a>';
129
+        }
130
+
131
+        /**
132
+         * Filters the row links displayed for each site on the My Sites screen.
133
+         *
134
+         * @since MU (3.0.0)
135
+         *
136
+         * @param string $actions   The HTML site link markup.
137
+         * @param object $user_blog An object containing the site data.
138
+         */
139
+        $actions = apply_filters( 'myblogs_blog_actions', $actions, $user_blog );
140
+
141
+        echo "<p class='my-sites-actions'>" . $actions . '</p>';
142
+
143
+        /** This filter is documented in wp-admin/my-sites.php */
144
+        echo apply_filters( 'myblogs_options', '', $user_blog );
145
+
146
+        echo '</li>';
147
+
148
+        restore_current_blog();
149
+    }
150
+    ?>
151 151
 	</ul>
152 152
 	<?php
153
-	if ( count( $blogs ) > 1 || has_action( 'myblogs_allblogs_options' ) || has_filter( 'myblogs_options' ) ) {
154
-		?>
153
+    if ( count( $blogs ) > 1 || has_action( 'myblogs_allblogs_options' ) || has_filter( 'myblogs_options' ) ) {
154
+        ?>
155 155
 		<input type="hidden" name="action" value="updateblogsettings" />
156 156
 		<?php
157
-		wp_nonce_field( 'update-my-sites' );
158
-		submit_button();
159
-	}
160
-	?>
157
+        wp_nonce_field( 'update-my-sites' );
158
+        submit_button();
159
+    }
160
+    ?>
161 161
 	</form>
162 162
 <?php endif; ?>
163 163
 	</div>
Please login to merge, or discard this patch.
brighty/wp-admin/widgets.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@  discard block
 block discarded – undo
13 13
 require_once ABSPATH . 'wp-admin/includes/widgets.php';
14 14
 
15 15
 if ( ! current_user_can( 'edit_theme_options' ) ) {
16
-	wp_die(
17
-		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
18
-		'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
19
-		403
20
-	);
16
+    wp_die(
17
+        '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
18
+        '<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
19
+        403
20
+    );
21 21
 }
22 22
 
23 23
 if ( ! current_theme_supports( 'widgets' ) ) {
24
-	wp_die( __( 'The theme you are currently using is not widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please <a href="https://developer.wordpress.org/themes/functionality/widgets/">follow these instructions</a>.' ) );
24
+    wp_die( __( 'The theme you are currently using is not widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please <a href="https://developer.wordpress.org/themes/functionality/widgets/">follow these instructions</a>.' ) );
25 25
 }
26 26
 
27 27
 // Used in the HTML title tag.
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 $parent_file = 'themes.php';
30 30
 
31 31
 if ( wp_use_widgets_block_editor() ) {
32
-	require ABSPATH . 'wp-admin/widgets-form-blocks.php';
32
+    require ABSPATH . 'wp-admin/widgets-form-blocks.php';
33 33
 } else {
34
-	require ABSPATH . 'wp-admin/widgets-form.php';
34
+    require ABSPATH . 'wp-admin/widgets-form.php';
35 35
 }
Please login to merge, or discard this patch.
brighty/wp-admin/users.php 1 patch
Indentation   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
 require_once __DIR__ . '/admin.php';
12 12
 
13 13
 if ( ! current_user_can( 'list_users' ) ) {
14
-	wp_die(
15
-		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
16
-		'<p>' . __( 'Sorry, you are not allowed to list users.' ) . '</p>',
17
-		403
18
-	);
14
+    wp_die(
15
+        '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
16
+        '<p>' . __( 'Sorry, you are not allowed to list users.' ) . '</p>',
17
+        403
18
+    );
19 19
 }
20 20
 
21 21
 $wp_list_table = _get_list_table( 'WP_Users_List_Table' );
@@ -29,289 +29,289 @@  discard block
 block discarded – undo
29 29
 
30 30
 // Contextual help - choose Help on the top right of admin panel to preview this.
31 31
 get_current_screen()->add_help_tab(
32
-	array(
33
-		'id'      => 'overview',
34
-		'title'   => __( 'Overview' ),
35
-		'content' => '<p>' . __( 'This screen lists all the existing users for your site. Each user has one of five defined roles as set by the site admin: Site Administrator, Editor, Author, Contributor, or Subscriber. Users with roles other than Administrator will see fewer options in the dashboard navigation when they are logged in, based on their role.' ) . '</p>' .
36
-						'<p>' . __( 'To add a new user for your site, click the Add New button at the top of the screen or Add New in the Users menu section.' ) . '</p>',
37
-	)
32
+    array(
33
+        'id'      => 'overview',
34
+        'title'   => __( 'Overview' ),
35
+        'content' => '<p>' . __( 'This screen lists all the existing users for your site. Each user has one of five defined roles as set by the site admin: Site Administrator, Editor, Author, Contributor, or Subscriber. Users with roles other than Administrator will see fewer options in the dashboard navigation when they are logged in, based on their role.' ) . '</p>' .
36
+                        '<p>' . __( 'To add a new user for your site, click the Add New button at the top of the screen or Add New in the Users menu section.' ) . '</p>',
37
+    )
38 38
 );
39 39
 
40 40
 get_current_screen()->add_help_tab(
41
-	array(
42
-		'id'      => 'screen-content',
43
-		'title'   => __( 'Screen Content' ),
44
-		'content' => '<p>' . __( 'You can customize the display of this screen in a number of ways:' ) . '</p>' .
45
-						'<ul>' .
46
-						'<li>' . __( 'You can hide/display columns based on your needs and decide how many users to list per screen using the Screen Options tab.' ) . '</li>' .
47
-						'<li>' . __( 'You can filter the list of users by User Role using the text links above the users list to show All, Administrator, Editor, Author, Contributor, or Subscriber. The default view is to show all users. Unused User Roles are not listed.' ) . '</li>' .
48
-						'<li>' . __( 'You can view all posts made by a user by clicking on the number under the Posts column.' ) . '</li>' .
49
-						'</ul>',
50
-	)
41
+    array(
42
+        'id'      => 'screen-content',
43
+        'title'   => __( 'Screen Content' ),
44
+        'content' => '<p>' . __( 'You can customize the display of this screen in a number of ways:' ) . '</p>' .
45
+                        '<ul>' .
46
+                        '<li>' . __( 'You can hide/display columns based on your needs and decide how many users to list per screen using the Screen Options tab.' ) . '</li>' .
47
+                        '<li>' . __( 'You can filter the list of users by User Role using the text links above the users list to show All, Administrator, Editor, Author, Contributor, or Subscriber. The default view is to show all users. Unused User Roles are not listed.' ) . '</li>' .
48
+                        '<li>' . __( 'You can view all posts made by a user by clicking on the number under the Posts column.' ) . '</li>' .
49
+                        '</ul>',
50
+    )
51 51
 );
52 52
 
53 53
 $help = '<p>' . __( 'Hovering over a row in the users list will display action links that allow you to manage users. You can perform the following actions:' ) . '</p>' .
54
-	'<ul>' .
55
-	'<li>' . __( '<strong>Edit</strong> takes you to the editable profile screen for that user. You can also reach that screen by clicking on the username.' ) . '</li>';
54
+    '<ul>' .
55
+    '<li>' . __( '<strong>Edit</strong> takes you to the editable profile screen for that user. You can also reach that screen by clicking on the username.' ) . '</li>';
56 56
 
57 57
 if ( is_multisite() ) {
58
-	$help .= '<li>' . __( '<strong>Remove</strong> allows you to remove a user from your site. It does not delete their content. You can also remove multiple users at once by using bulk actions.' ) . '</li>';
58
+    $help .= '<li>' . __( '<strong>Remove</strong> allows you to remove a user from your site. It does not delete their content. You can also remove multiple users at once by using bulk actions.' ) . '</li>';
59 59
 } else {
60
-	$help .= '<li>' . __( '<strong>Delete</strong> brings you to the Delete Users screen for confirmation, where you can permanently remove a user from your site and delete their content. You can also delete multiple users at once by using bulk actions.' ) . '</li>';
60
+    $help .= '<li>' . __( '<strong>Delete</strong> brings you to the Delete Users screen for confirmation, where you can permanently remove a user from your site and delete their content. You can also delete multiple users at once by using bulk actions.' ) . '</li>';
61 61
 }
62 62
 
63 63
 $help .= '</ul>';
64 64
 
65 65
 get_current_screen()->add_help_tab(
66
-	array(
67
-		'id'      => 'action-links',
68
-		'title'   => __( 'Available Actions' ),
69
-		'content' => $help,
70
-	)
66
+    array(
67
+        'id'      => 'action-links',
68
+        'title'   => __( 'Available Actions' ),
69
+        'content' => $help,
70
+    )
71 71
 );
72 72
 unset( $help );
73 73
 
74 74
 get_current_screen()->set_help_sidebar(
75
-	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
76
-	'<p>' . __( '<a href="https://wordpress.org/support/article/users-screen/">Documentation on Managing Users</a>' ) . '</p>' .
77
-	'<p>' . __( '<a href="https://wordpress.org/support/article/roles-and-capabilities/">Descriptions of Roles and Capabilities</a>' ) . '</p>' .
78
-	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
75
+    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
76
+    '<p>' . __( '<a href="https://wordpress.org/support/article/users-screen/">Documentation on Managing Users</a>' ) . '</p>' .
77
+    '<p>' . __( '<a href="https://wordpress.org/support/article/roles-and-capabilities/">Descriptions of Roles and Capabilities</a>' ) . '</p>' .
78
+    '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
79 79
 );
80 80
 
81 81
 get_current_screen()->set_screen_reader_content(
82
-	array(
83
-		'heading_views'      => __( 'Filter users list' ),
84
-		'heading_pagination' => __( 'Users list navigation' ),
85
-		'heading_list'       => __( 'Users list' ),
86
-	)
82
+    array(
83
+        'heading_views'      => __( 'Filter users list' ),
84
+        'heading_pagination' => __( 'Users list navigation' ),
85
+        'heading_list'       => __( 'Users list' ),
86
+    )
87 87
 );
88 88
 
89 89
 if ( empty( $_REQUEST ) ) {
90
-	$referer = '<input type="hidden" name="wp_http_referer" value="' . esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
90
+    $referer = '<input type="hidden" name="wp_http_referer" value="' . esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
91 91
 } elseif ( isset( $_REQUEST['wp_http_referer'] ) ) {
92
-	$redirect = remove_query_arg( array( 'wp_http_referer', 'updated', 'delete_count' ), wp_unslash( $_REQUEST['wp_http_referer'] ) );
93
-	$referer  = '<input type="hidden" name="wp_http_referer" value="' . esc_attr( $redirect ) . '" />';
92
+    $redirect = remove_query_arg( array( 'wp_http_referer', 'updated', 'delete_count' ), wp_unslash( $_REQUEST['wp_http_referer'] ) );
93
+    $referer  = '<input type="hidden" name="wp_http_referer" value="' . esc_attr( $redirect ) . '" />';
94 94
 } else {
95
-	$redirect = 'users.php';
96
-	$referer  = '';
95
+    $redirect = 'users.php';
96
+    $referer  = '';
97 97
 }
98 98
 
99 99
 $update = '';
100 100
 
101 101
 switch ( $wp_list_table->current_action() ) {
102 102
 
103
-	/* Bulk Dropdown menu Role changes */
104
-	case 'promote':
105
-		check_admin_referer( 'bulk-users' );
106
-
107
-		if ( ! current_user_can( 'promote_users' ) ) {
108
-			wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
109
-		}
110
-
111
-		if ( empty( $_REQUEST['users'] ) ) {
112
-			wp_redirect( $redirect );
113
-			exit;
114
-		}
115
-
116
-		$editable_roles = get_editable_roles();
117
-		$role           = $_REQUEST['new_role'];
118
-
119
-		// Mocking the `none` role so we are able to save it to the database
120
-		$editable_roles['none'] = array(
121
-			'name' => __( '&mdash; No role for this site &mdash;' ),
122
-		);
123
-
124
-		if ( ! $role || empty( $editable_roles[ $role ] ) ) {
125
-			wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
126
-		}
127
-
128
-		if ( 'none' === $role ) {
129
-			$role = '';
130
-		}
131
-
132
-		$userids = $_REQUEST['users'];
133
-		$update  = 'promote';
134
-		foreach ( $userids as $id ) {
135
-			$id = (int) $id;
136
-
137
-			if ( ! current_user_can( 'promote_user', $id ) ) {
138
-				wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
139
-			}
140
-
141
-			// The new role of the current user must also have the promote_users cap or be a multisite super admin.
142
-			if ( $id == $current_user->ID && ! $wp_roles->role_objects[ $role ]->has_cap( 'promote_users' )
143
-			&& ! ( is_multisite() && current_user_can( 'manage_network_users' ) ) ) {
144
-					$update = 'err_admin_role';
145
-					continue;
146
-			}
147
-
148
-			// If the user doesn't already belong to the blog, bail.
149
-			if ( is_multisite() && ! is_user_member_of_blog( $id ) ) {
150
-				wp_die(
151
-					'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
152
-					'<p>' . __( 'One of the selected users is not a member of this site.' ) . '</p>',
153
-					403
154
-				);
155
-			}
156
-
157
-			$user = get_userdata( $id );
158
-			$user->set_role( $role );
159
-		}
160
-
161
-		wp_redirect( add_query_arg( 'update', $update, $redirect ) );
162
-		exit;
163
-
164
-	case 'dodelete':
165
-		if ( is_multisite() ) {
166
-			wp_die( __( 'User deletion is not allowed from this screen.' ), 400 );
167
-		}
168
-
169
-		check_admin_referer( 'delete-users' );
170
-
171
-		if ( empty( $_REQUEST['users'] ) ) {
172
-			wp_redirect( $redirect );
173
-			exit;
174
-		}
175
-
176
-		$userids = array_map( 'intval', (array) $_REQUEST['users'] );
177
-
178
-		if ( empty( $_REQUEST['delete_option'] ) ) {
179
-			$url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) . '&error=true' );
180
-			$url = str_replace( '&amp;', '&', wp_nonce_url( $url, 'bulk-users' ) );
181
-			wp_redirect( $url );
182
-			exit;
183
-		}
184
-
185
-		if ( ! current_user_can( 'delete_users' ) ) {
186
-			wp_die( __( 'Sorry, you are not allowed to delete users.' ), 403 );
187
-		}
188
-
189
-		$update       = 'del';
190
-		$delete_count = 0;
191
-
192
-		foreach ( $userids as $id ) {
193
-			if ( ! current_user_can( 'delete_user', $id ) ) {
194
-				wp_die( __( 'Sorry, you are not allowed to delete that user.' ), 403 );
195
-			}
196
-
197
-			if ( $id == $current_user->ID ) {
198
-				$update = 'err_admin_del';
199
-				continue;
200
-			}
201
-			switch ( $_REQUEST['delete_option'] ) {
202
-				case 'delete':
203
-					wp_delete_user( $id );
204
-					break;
205
-				case 'reassign':
206
-					wp_delete_user( $id, $_REQUEST['reassign_user'] );
207
-					break;
208
-			}
209
-			++$delete_count;
210
-		}
211
-
212
-		$redirect = add_query_arg(
213
-			array(
214
-				'delete_count' => $delete_count,
215
-				'update'       => $update,
216
-			),
217
-			$redirect
218
-		);
219
-		wp_redirect( $redirect );
220
-		exit;
221
-
222
-	case 'resetpassword':
223
-		check_admin_referer( 'bulk-users' );
224
-		if ( ! current_user_can( 'edit_users' ) ) {
225
-			$errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to edit users.' ) );
226
-		}
227
-		if ( empty( $_REQUEST['users'] ) ) {
228
-			wp_redirect( $redirect );
229
-			exit();
230
-		}
231
-		$userids = array_map( 'intval', (array) $_REQUEST['users'] );
232
-
233
-		$reset_count = 0;
234
-
235
-		foreach ( $userids as $id ) {
236
-			if ( ! current_user_can( 'edit_user', $id ) ) {
237
-				wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
238
-			}
239
-
240
-			if ( $id === $current_user->ID ) {
241
-				$update = 'err_admin_reset';
242
-				continue;
243
-			}
244
-
245
-			// Send the password reset link.
246
-			$user = get_userdata( $id );
247
-			if ( retrieve_password( $user->user_login ) ) {
248
-				++$reset_count;
249
-			}
250
-		}
251
-
252
-		$redirect = add_query_arg(
253
-			array(
254
-				'reset_count' => $reset_count,
255
-				'update'      => 'resetpassword',
256
-			),
257
-			$redirect
258
-		);
259
-		wp_redirect( $redirect );
260
-		exit;
261
-
262
-	case 'delete':
263
-		if ( is_multisite() ) {
264
-			wp_die( __( 'User deletion is not allowed from this screen.' ), 400 );
265
-		}
266
-
267
-		check_admin_referer( 'bulk-users' );
268
-
269
-		if ( empty( $_REQUEST['users'] ) && empty( $_REQUEST['user'] ) ) {
270
-			wp_redirect( $redirect );
271
-			exit;
272
-		}
273
-
274
-		if ( ! current_user_can( 'delete_users' ) ) {
275
-			$errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to delete users.' ) );
276
-		}
277
-
278
-		if ( empty( $_REQUEST['users'] ) ) {
279
-			$userids = array( (int) $_REQUEST['user'] );
280
-		} else {
281
-			$userids = array_map( 'intval', (array) $_REQUEST['users'] );
282
-		}
283
-
284
-		$all_userids = $userids;
285
-
286
-		if ( in_array( $current_user->ID, $userids, true ) ) {
287
-			$userids = array_diff( $userids, array( $current_user->ID ) );
288
-		}
289
-
290
-		/**
291
-		 * Filters whether the users being deleted have additional content
292
-		 * associated with them outside of the `post_author` and `link_owner` relationships.
293
-		 *
294
-		 * @since 5.2.0
295
-		 *
296
-		 * @param bool  $users_have_additional_content Whether the users have additional content. Default false.
297
-		 * @param int[] $userids                       Array of IDs for users being deleted.
298
-		 */
299
-		$users_have_content = (bool) apply_filters( 'users_have_additional_content', false, $userids );
300
-
301
-		if ( $userids && ! $users_have_content ) {
302
-			if ( $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_author IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) {
303
-				$users_have_content = true;
304
-			} elseif ( $wpdb->get_var( "SELECT link_id FROM {$wpdb->links} WHERE link_owner IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) {
305
-				$users_have_content = true;
306
-			}
307
-		}
308
-
309
-		if ( $users_have_content ) {
310
-			add_action( 'admin_head', 'delete_users_add_js' );
311
-		}
312
-
313
-		require_once ABSPATH . 'wp-admin/admin-header.php';
314
-		?>
103
+    /* Bulk Dropdown menu Role changes */
104
+    case 'promote':
105
+        check_admin_referer( 'bulk-users' );
106
+
107
+        if ( ! current_user_can( 'promote_users' ) ) {
108
+            wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
109
+        }
110
+
111
+        if ( empty( $_REQUEST['users'] ) ) {
112
+            wp_redirect( $redirect );
113
+            exit;
114
+        }
115
+
116
+        $editable_roles = get_editable_roles();
117
+        $role           = $_REQUEST['new_role'];
118
+
119
+        // Mocking the `none` role so we are able to save it to the database
120
+        $editable_roles['none'] = array(
121
+            'name' => __( '&mdash; No role for this site &mdash;' ),
122
+        );
123
+
124
+        if ( ! $role || empty( $editable_roles[ $role ] ) ) {
125
+            wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
126
+        }
127
+
128
+        if ( 'none' === $role ) {
129
+            $role = '';
130
+        }
131
+
132
+        $userids = $_REQUEST['users'];
133
+        $update  = 'promote';
134
+        foreach ( $userids as $id ) {
135
+            $id = (int) $id;
136
+
137
+            if ( ! current_user_can( 'promote_user', $id ) ) {
138
+                wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
139
+            }
140
+
141
+            // The new role of the current user must also have the promote_users cap or be a multisite super admin.
142
+            if ( $id == $current_user->ID && ! $wp_roles->role_objects[ $role ]->has_cap( 'promote_users' )
143
+            && ! ( is_multisite() && current_user_can( 'manage_network_users' ) ) ) {
144
+                    $update = 'err_admin_role';
145
+                    continue;
146
+            }
147
+
148
+            // If the user doesn't already belong to the blog, bail.
149
+            if ( is_multisite() && ! is_user_member_of_blog( $id ) ) {
150
+                wp_die(
151
+                    '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
152
+                    '<p>' . __( 'One of the selected users is not a member of this site.' ) . '</p>',
153
+                    403
154
+                );
155
+            }
156
+
157
+            $user = get_userdata( $id );
158
+            $user->set_role( $role );
159
+        }
160
+
161
+        wp_redirect( add_query_arg( 'update', $update, $redirect ) );
162
+        exit;
163
+
164
+    case 'dodelete':
165
+        if ( is_multisite() ) {
166
+            wp_die( __( 'User deletion is not allowed from this screen.' ), 400 );
167
+        }
168
+
169
+        check_admin_referer( 'delete-users' );
170
+
171
+        if ( empty( $_REQUEST['users'] ) ) {
172
+            wp_redirect( $redirect );
173
+            exit;
174
+        }
175
+
176
+        $userids = array_map( 'intval', (array) $_REQUEST['users'] );
177
+
178
+        if ( empty( $_REQUEST['delete_option'] ) ) {
179
+            $url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) . '&error=true' );
180
+            $url = str_replace( '&amp;', '&', wp_nonce_url( $url, 'bulk-users' ) );
181
+            wp_redirect( $url );
182
+            exit;
183
+        }
184
+
185
+        if ( ! current_user_can( 'delete_users' ) ) {
186
+            wp_die( __( 'Sorry, you are not allowed to delete users.' ), 403 );
187
+        }
188
+
189
+        $update       = 'del';
190
+        $delete_count = 0;
191
+
192
+        foreach ( $userids as $id ) {
193
+            if ( ! current_user_can( 'delete_user', $id ) ) {
194
+                wp_die( __( 'Sorry, you are not allowed to delete that user.' ), 403 );
195
+            }
196
+
197
+            if ( $id == $current_user->ID ) {
198
+                $update = 'err_admin_del';
199
+                continue;
200
+            }
201
+            switch ( $_REQUEST['delete_option'] ) {
202
+                case 'delete':
203
+                    wp_delete_user( $id );
204
+                    break;
205
+                case 'reassign':
206
+                    wp_delete_user( $id, $_REQUEST['reassign_user'] );
207
+                    break;
208
+            }
209
+            ++$delete_count;
210
+        }
211
+
212
+        $redirect = add_query_arg(
213
+            array(
214
+                'delete_count' => $delete_count,
215
+                'update'       => $update,
216
+            ),
217
+            $redirect
218
+        );
219
+        wp_redirect( $redirect );
220
+        exit;
221
+
222
+    case 'resetpassword':
223
+        check_admin_referer( 'bulk-users' );
224
+        if ( ! current_user_can( 'edit_users' ) ) {
225
+            $errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to edit users.' ) );
226
+        }
227
+        if ( empty( $_REQUEST['users'] ) ) {
228
+            wp_redirect( $redirect );
229
+            exit();
230
+        }
231
+        $userids = array_map( 'intval', (array) $_REQUEST['users'] );
232
+
233
+        $reset_count = 0;
234
+
235
+        foreach ( $userids as $id ) {
236
+            if ( ! current_user_can( 'edit_user', $id ) ) {
237
+                wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
238
+            }
239
+
240
+            if ( $id === $current_user->ID ) {
241
+                $update = 'err_admin_reset';
242
+                continue;
243
+            }
244
+
245
+            // Send the password reset link.
246
+            $user = get_userdata( $id );
247
+            if ( retrieve_password( $user->user_login ) ) {
248
+                ++$reset_count;
249
+            }
250
+        }
251
+
252
+        $redirect = add_query_arg(
253
+            array(
254
+                'reset_count' => $reset_count,
255
+                'update'      => 'resetpassword',
256
+            ),
257
+            $redirect
258
+        );
259
+        wp_redirect( $redirect );
260
+        exit;
261
+
262
+    case 'delete':
263
+        if ( is_multisite() ) {
264
+            wp_die( __( 'User deletion is not allowed from this screen.' ), 400 );
265
+        }
266
+
267
+        check_admin_referer( 'bulk-users' );
268
+
269
+        if ( empty( $_REQUEST['users'] ) && empty( $_REQUEST['user'] ) ) {
270
+            wp_redirect( $redirect );
271
+            exit;
272
+        }
273
+
274
+        if ( ! current_user_can( 'delete_users' ) ) {
275
+            $errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to delete users.' ) );
276
+        }
277
+
278
+        if ( empty( $_REQUEST['users'] ) ) {
279
+            $userids = array( (int) $_REQUEST['user'] );
280
+        } else {
281
+            $userids = array_map( 'intval', (array) $_REQUEST['users'] );
282
+        }
283
+
284
+        $all_userids = $userids;
285
+
286
+        if ( in_array( $current_user->ID, $userids, true ) ) {
287
+            $userids = array_diff( $userids, array( $current_user->ID ) );
288
+        }
289
+
290
+        /**
291
+         * Filters whether the users being deleted have additional content
292
+         * associated with them outside of the `post_author` and `link_owner` relationships.
293
+         *
294
+         * @since 5.2.0
295
+         *
296
+         * @param bool  $users_have_additional_content Whether the users have additional content. Default false.
297
+         * @param int[] $userids                       Array of IDs for users being deleted.
298
+         */
299
+        $users_have_content = (bool) apply_filters( 'users_have_additional_content', false, $userids );
300
+
301
+        if ( $userids && ! $users_have_content ) {
302
+            if ( $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_author IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) {
303
+                $users_have_content = true;
304
+            } elseif ( $wpdb->get_var( "SELECT link_id FROM {$wpdb->links} WHERE link_owner IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) {
305
+                $users_have_content = true;
306
+            }
307
+        }
308
+
309
+        if ( $users_have_content ) {
310
+            add_action( 'admin_head', 'delete_users_add_js' );
311
+        }
312
+
313
+        require_once ABSPATH . 'wp-admin/admin-header.php';
314
+        ?>
315 315
 	<form method="post" name="updateusers" id="updateusers">
316 316
 		<?php wp_nonce_field( 'delete-users' ); ?>
317 317
 		<?php echo $referer; ?>
@@ -332,25 +332,25 @@  discard block
 block discarded – undo
332 332
 
333 333
 <ul>
334 334
 		<?php
335
-		$go_delete = 0;
336
-		foreach ( $all_userids as $id ) {
337
-			$user = get_userdata( $id );
338
-			if ( $id == $current_user->ID ) {
339
-				/* translators: 1: User ID, 2: User login. */
340
-				echo '<li>' . sprintf( __( 'ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>' ), $id, $user->user_login ) . "</li>\n";
341
-			} else {
342
-				/* translators: 1: User ID, 2: User login. */
343
-				echo '<li><input type="hidden" name="users[]" value="' . esc_attr( $id ) . '" />' . sprintf( __( 'ID #%1$s: %2$s' ), $id, $user->user_login ) . "</li>\n";
344
-				$go_delete++;
345
-			}
346
-		}
347
-		?>
335
+        $go_delete = 0;
336
+        foreach ( $all_userids as $id ) {
337
+            $user = get_userdata( $id );
338
+            if ( $id == $current_user->ID ) {
339
+                /* translators: 1: User ID, 2: User login. */
340
+                echo '<li>' . sprintf( __( 'ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>' ), $id, $user->user_login ) . "</li>\n";
341
+            } else {
342
+                /* translators: 1: User ID, 2: User login. */
343
+                echo '<li><input type="hidden" name="users[]" value="' . esc_attr( $id ) . '" />' . sprintf( __( 'ID #%1$s: %2$s' ), $id, $user->user_login ) . "</li>\n";
344
+                $go_delete++;
345
+            }
346
+        }
347
+        ?>
348 348
 	</ul>
349 349
 		<?php
350
-		if ( $go_delete ) :
350
+        if ( $go_delete ) :
351 351
 
352
-			if ( ! $users_have_content ) :
353
-				?>
352
+            if ( ! $users_have_content ) :
353
+                ?>
354 354
 			<input type="hidden" name="delete_option" value="delete" />
355 355
 			<?php else : ?>
356 356
 				<?php if ( 1 == $go_delete ) : ?>
@@ -363,30 +363,30 @@  discard block
 block discarded – undo
363 363
 				<?php _e( 'Delete all content.' ); ?></label></li>
364 364
 			<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
365 365
 				<?php
366
-				echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
367
-				wp_dropdown_users(
368
-					array(
369
-						'name'    => 'reassign_user',
370
-						'exclude' => $userids,
371
-						'show'    => 'display_name_with_login',
372
-					)
373
-				);
374
-				?>
366
+                echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
367
+                wp_dropdown_users(
368
+                    array(
369
+                        'name'    => 'reassign_user',
370
+                        'exclude' => $userids,
371
+                        'show'    => 'display_name_with_login',
372
+                    )
373
+                );
374
+                ?>
375 375
 			</li>
376 376
 		</ul></fieldset>
377 377
 				<?php
378
-	endif;
379
-			/**
380
-			 * Fires at the end of the delete users form prior to the confirm button.
381
-			 *
382
-			 * @since 4.0.0
383
-			 * @since 4.5.0 The `$userids` parameter was added.
384
-			 *
385
-			 * @param WP_User $current_user WP_User object for the current user.
386
-			 * @param int[]   $userids      Array of IDs for users being deleted.
387
-			 */
388
-			do_action( 'delete_user_form', $current_user, $userids );
389
-			?>
378
+    endif;
379
+            /**
380
+             * Fires at the end of the delete users form prior to the confirm button.
381
+             *
382
+             * @since 4.0.0
383
+             * @since 4.5.0 The `$userids` parameter was added.
384
+             *
385
+             * @param WP_User $current_user WP_User object for the current user.
386
+             * @param int[]   $userids      Array of IDs for users being deleted.
387
+             */
388
+            do_action( 'delete_user_form', $current_user, $userids );
389
+            ?>
390 390
 	<input type="hidden" name="action" value="dodelete" />
391 391
 			<?php submit_button( __( 'Confirm Deletion' ), 'primary' ); ?>
392 392
 	<?php else : ?>
@@ -396,64 +396,64 @@  discard block
 block discarded – undo
396 396
 	</form>
397 397
 		<?php
398 398
 
399
-		break;
399
+        break;
400 400
 
401
-	case 'doremove':
402
-		check_admin_referer( 'remove-users' );
401
+    case 'doremove':
402
+        check_admin_referer( 'remove-users' );
403 403
 
404
-		if ( ! is_multisite() ) {
405
-			wp_die( __( 'You cannot remove users.' ), 400 );
406
-		}
404
+        if ( ! is_multisite() ) {
405
+            wp_die( __( 'You cannot remove users.' ), 400 );
406
+        }
407 407
 
408
-		if ( empty( $_REQUEST['users'] ) ) {
409
-			wp_redirect( $redirect );
410
-			exit;
411
-		}
408
+        if ( empty( $_REQUEST['users'] ) ) {
409
+            wp_redirect( $redirect );
410
+            exit;
411
+        }
412 412
 
413
-		if ( ! current_user_can( 'remove_users' ) ) {
414
-			wp_die( __( 'Sorry, you are not allowed to remove users.' ), 403 );
415
-		}
413
+        if ( ! current_user_can( 'remove_users' ) ) {
414
+            wp_die( __( 'Sorry, you are not allowed to remove users.' ), 403 );
415
+        }
416 416
 
417
-		$userids = $_REQUEST['users'];
417
+        $userids = $_REQUEST['users'];
418 418
 
419
-		$update = 'remove';
420
-		foreach ( $userids as $id ) {
421
-			$id = (int) $id;
422
-			if ( ! current_user_can( 'remove_user', $id ) ) {
423
-				$update = 'err_admin_remove';
424
-				continue;
425
-			}
426
-			remove_user_from_blog( $id, $blog_id );
427
-		}
419
+        $update = 'remove';
420
+        foreach ( $userids as $id ) {
421
+            $id = (int) $id;
422
+            if ( ! current_user_can( 'remove_user', $id ) ) {
423
+                $update = 'err_admin_remove';
424
+                continue;
425
+            }
426
+            remove_user_from_blog( $id, $blog_id );
427
+        }
428 428
 
429
-		$redirect = add_query_arg( array( 'update' => $update ), $redirect );
430
-		wp_redirect( $redirect );
431
-		exit;
429
+        $redirect = add_query_arg( array( 'update' => $update ), $redirect );
430
+        wp_redirect( $redirect );
431
+        exit;
432 432
 
433
-	case 'remove':
434
-		check_admin_referer( 'bulk-users' );
433
+    case 'remove':
434
+        check_admin_referer( 'bulk-users' );
435 435
 
436
-		if ( ! is_multisite() ) {
437
-			wp_die( __( 'You cannot remove users.' ), 400 );
438
-		}
436
+        if ( ! is_multisite() ) {
437
+            wp_die( __( 'You cannot remove users.' ), 400 );
438
+        }
439 439
 
440
-		if ( empty( $_REQUEST['users'] ) && empty( $_REQUEST['user'] ) ) {
441
-			wp_redirect( $redirect );
442
-			exit;
443
-		}
440
+        if ( empty( $_REQUEST['users'] ) && empty( $_REQUEST['user'] ) ) {
441
+            wp_redirect( $redirect );
442
+            exit;
443
+        }
444 444
 
445
-		if ( ! current_user_can( 'remove_users' ) ) {
446
-			$error = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to remove users.' ) );
447
-		}
445
+        if ( ! current_user_can( 'remove_users' ) ) {
446
+            $error = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to remove users.' ) );
447
+        }
448 448
 
449
-		if ( empty( $_REQUEST['users'] ) ) {
450
-			$userids = array( (int) $_REQUEST['user'] );
451
-		} else {
452
-			$userids = $_REQUEST['users'];
453
-		}
449
+        if ( empty( $_REQUEST['users'] ) ) {
450
+            $userids = array( (int) $_REQUEST['user'] );
451
+        } else {
452
+            $userids = $_REQUEST['users'];
453
+        }
454 454
 
455
-		require_once ABSPATH . 'wp-admin/admin-header.php';
456
-		?>
455
+        require_once ABSPATH . 'wp-admin/admin-header.php';
456
+        ?>
457 457
 	<form method="post" name="updateusers" id="updateusers">
458 458
 		<?php wp_nonce_field( 'remove-users' ); ?>
459 459
 		<?php echo $referer; ?>
@@ -469,20 +469,20 @@  discard block
 block discarded – undo
469 469
 
470 470
 <ul>
471 471
 		<?php
472
-		$go_remove = false;
473
-		foreach ( $userids as $id ) {
474
-			$id   = (int) $id;
475
-			$user = get_userdata( $id );
476
-			if ( ! current_user_can( 'remove_user', $id ) ) {
477
-				/* translators: 1: User ID, 2: User login. */
478
-				echo '<li>' . sprintf( __( 'ID #%1$s: %2$s <strong>Sorry, you are not allowed to remove this user.</strong>' ), $id, $user->user_login ) . "</li>\n";
479
-			} else {
480
-				/* translators: 1: User ID, 2: User login. */
481
-				echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf( __( 'ID #%1$s: %2$s' ), $id, $user->user_login ) . "</li>\n";
482
-				$go_remove = true;
483
-			}
484
-		}
485
-		?>
472
+        $go_remove = false;
473
+        foreach ( $userids as $id ) {
474
+            $id   = (int) $id;
475
+            $user = get_userdata( $id );
476
+            if ( ! current_user_can( 'remove_user', $id ) ) {
477
+                /* translators: 1: User ID, 2: User login. */
478
+                echo '<li>' . sprintf( __( 'ID #%1$s: %2$s <strong>Sorry, you are not allowed to remove this user.</strong>' ), $id, $user->user_login ) . "</li>\n";
479
+            } else {
480
+                /* translators: 1: User ID, 2: User login. */
481
+                echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf( __( 'ID #%1$s: %2$s' ), $id, $user->user_login ) . "</li>\n";
482
+                $go_remove = true;
483
+            }
484
+        }
485
+        ?>
486 486
 	</ul>
487 487
 		<?php if ( $go_remove ) : ?>
488 488
 		<input type="hidden" name="action" value="doremove" />
@@ -494,131 +494,131 @@  discard block
 block discarded – undo
494 494
 	</form>
495 495
 		<?php
496 496
 
497
-		break;
498
-
499
-	default:
500
-		if ( ! empty( $_GET['_wp_http_referer'] ) ) {
501
-			wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
502
-			exit;
503
-		}
504
-
505
-		if ( $wp_list_table->current_action() && ! empty( $_REQUEST['users'] ) ) {
506
-			$screen   = get_current_screen()->id;
507
-			$sendback = wp_get_referer();
508
-			$userids  = $_REQUEST['users'];
509
-
510
-			/** This action is documented in wp-admin/edit.php */
511
-			$sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback, $wp_list_table->current_action(), $userids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
512
-
513
-			wp_safe_redirect( $sendback );
514
-			exit;
515
-		}
516
-
517
-		$wp_list_table->prepare_items();
518
-		$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
519
-		if ( $pagenum > $total_pages && $total_pages > 0 ) {
520
-			wp_redirect( add_query_arg( 'paged', $total_pages ) );
521
-			exit;
522
-		}
523
-
524
-		require_once ABSPATH . 'wp-admin/admin-header.php';
525
-
526
-		$messages = array();
527
-		if ( isset( $_GET['update'] ) ) :
528
-			switch ( $_GET['update'] ) {
529
-				case 'del':
530
-				case 'del_many':
531
-					$delete_count = isset( $_GET['delete_count'] ) ? (int) $_GET['delete_count'] : 0;
532
-					if ( 1 == $delete_count ) {
533
-						$message = __( 'User deleted.' );
534
-					} else {
535
-						/* translators: %s: Number of users. */
536
-						$message = _n( '%s user deleted.', '%s users deleted.', $delete_count );
537
-					}
538
-					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $delete_count ) ) . '</p></div>';
539
-					break;
540
-				case 'add':
541
-					$message = __( 'New user created.' );
542
-
543
-					$user_id = isset( $_GET['id'] ) ? $_GET['id'] : false;
544
-					if ( $user_id && current_user_can( 'edit_user', $user_id ) ) {
545
-						$message .= sprintf(
546
-							' <a href="%s">%s</a>',
547
-							esc_url(
548
-								add_query_arg(
549
-									'wp_http_referer',
550
-									urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
551
-									self_admin_url( 'user-edit.php?user_id=' . $user_id )
552
-								)
553
-							),
554
-							__( 'Edit user' )
555
-						);
556
-					}
557
-
558
-					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . $message . '</p></div>';
559
-					break;
560
-				case 'resetpassword':
561
-					$reset_count = isset( $_GET['reset_count'] ) ? (int) $_GET['reset_count'] : 0;
562
-					if ( 1 === $reset_count ) {
563
-						$message = __( 'Password reset link sent.' );
564
-					} else {
565
-						/* translators: %s: Number of users. */
566
-						$message = _n( 'Password reset links sent to %s user.', 'Password reset links sent to %s users.', $reset_count );
567
-					}
568
-					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $reset_count ) ) . '</p></div>';
569
-					break;
570
-				case 'promote':
571
-					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Changed roles.' ) . '</p></div>';
572
-					break;
573
-				case 'err_admin_role':
574
-					$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'The current user&#8217;s role must have user editing capabilities.' ) . '</p></div>';
575
-					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Other user roles have been changed.' ) . '</p></div>';
576
-					break;
577
-				case 'err_admin_del':
578
-					$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'You cannot delete the current user.' ) . '</p></div>';
579
-					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Other users have been deleted.' ) . '</p></div>';
580
-					break;
581
-				case 'remove':
582
-					$messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __( 'User removed from this site.' ) . '</p></div>';
583
-					break;
584
-				case 'err_admin_remove':
585
-					$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'You cannot remove the current user.' ) . '</p></div>';
586
-					$messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __( 'Other users have been removed.' ) . '</p></div>';
587
-					break;
588
-			}
589
-		endif;
590
-		?>
497
+        break;
498
+
499
+    default:
500
+        if ( ! empty( $_GET['_wp_http_referer'] ) ) {
501
+            wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
502
+            exit;
503
+        }
504
+
505
+        if ( $wp_list_table->current_action() && ! empty( $_REQUEST['users'] ) ) {
506
+            $screen   = get_current_screen()->id;
507
+            $sendback = wp_get_referer();
508
+            $userids  = $_REQUEST['users'];
509
+
510
+            /** This action is documented in wp-admin/edit.php */
511
+            $sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback, $wp_list_table->current_action(), $userids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
512
+
513
+            wp_safe_redirect( $sendback );
514
+            exit;
515
+        }
516
+
517
+        $wp_list_table->prepare_items();
518
+        $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
519
+        if ( $pagenum > $total_pages && $total_pages > 0 ) {
520
+            wp_redirect( add_query_arg( 'paged', $total_pages ) );
521
+            exit;
522
+        }
523
+
524
+        require_once ABSPATH . 'wp-admin/admin-header.php';
525
+
526
+        $messages = array();
527
+        if ( isset( $_GET['update'] ) ) :
528
+            switch ( $_GET['update'] ) {
529
+                case 'del':
530
+                case 'del_many':
531
+                    $delete_count = isset( $_GET['delete_count'] ) ? (int) $_GET['delete_count'] : 0;
532
+                    if ( 1 == $delete_count ) {
533
+                        $message = __( 'User deleted.' );
534
+                    } else {
535
+                        /* translators: %s: Number of users. */
536
+                        $message = _n( '%s user deleted.', '%s users deleted.', $delete_count );
537
+                    }
538
+                    $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $delete_count ) ) . '</p></div>';
539
+                    break;
540
+                case 'add':
541
+                    $message = __( 'New user created.' );
542
+
543
+                    $user_id = isset( $_GET['id'] ) ? $_GET['id'] : false;
544
+                    if ( $user_id && current_user_can( 'edit_user', $user_id ) ) {
545
+                        $message .= sprintf(
546
+                            ' <a href="%s">%s</a>',
547
+                            esc_url(
548
+                                add_query_arg(
549
+                                    'wp_http_referer',
550
+                                    urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
551
+                                    self_admin_url( 'user-edit.php?user_id=' . $user_id )
552
+                                )
553
+                            ),
554
+                            __( 'Edit user' )
555
+                        );
556
+                    }
557
+
558
+                    $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . $message . '</p></div>';
559
+                    break;
560
+                case 'resetpassword':
561
+                    $reset_count = isset( $_GET['reset_count'] ) ? (int) $_GET['reset_count'] : 0;
562
+                    if ( 1 === $reset_count ) {
563
+                        $message = __( 'Password reset link sent.' );
564
+                    } else {
565
+                        /* translators: %s: Number of users. */
566
+                        $message = _n( 'Password reset links sent to %s user.', 'Password reset links sent to %s users.', $reset_count );
567
+                    }
568
+                    $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $reset_count ) ) . '</p></div>';
569
+                    break;
570
+                case 'promote':
571
+                    $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Changed roles.' ) . '</p></div>';
572
+                    break;
573
+                case 'err_admin_role':
574
+                    $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'The current user&#8217;s role must have user editing capabilities.' ) . '</p></div>';
575
+                    $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Other user roles have been changed.' ) . '</p></div>';
576
+                    break;
577
+                case 'err_admin_del':
578
+                    $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'You cannot delete the current user.' ) . '</p></div>';
579
+                    $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Other users have been deleted.' ) . '</p></div>';
580
+                    break;
581
+                case 'remove':
582
+                    $messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __( 'User removed from this site.' ) . '</p></div>';
583
+                    break;
584
+                case 'err_admin_remove':
585
+                    $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'You cannot remove the current user.' ) . '</p></div>';
586
+                    $messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __( 'Other users have been removed.' ) . '</p></div>';
587
+                    break;
588
+            }
589
+        endif;
590
+        ?>
591 591
 
592 592
 		<?php if ( isset( $errors ) && is_wp_error( $errors ) ) : ?>
593 593
 		<div class="error">
594 594
 			<ul>
595 595
 			<?php
596
-			foreach ( $errors->get_error_messages() as $err ) {
597
-				echo "<li>$err</li>\n";
598
-			}
599
-			?>
596
+            foreach ( $errors->get_error_messages() as $err ) {
597
+                echo "<li>$err</li>\n";
598
+            }
599
+            ?>
600 600
 			</ul>
601 601
 		</div>
602 602
 			<?php
603
-	endif;
603
+    endif;
604 604
 
605
-		if ( ! empty( $messages ) ) {
606
-			foreach ( $messages as $msg ) {
607
-				echo $msg;
608
-			}
609
-		}
610
-		?>
605
+        if ( ! empty( $messages ) ) {
606
+            foreach ( $messages as $msg ) {
607
+                echo $msg;
608
+            }
609
+        }
610
+        ?>
611 611
 
612 612
 	<div class="wrap">
613 613
 	<h1 class="wp-heading-inline">
614 614
 		<?php
615
-		echo esc_html( $title );
616
-		?>
615
+        echo esc_html( $title );
616
+        ?>
617 617
 </h1>
618 618
 
619 619
 		<?php
620
-		if ( current_user_can( 'create_users' ) ) {
621
-			?>
620
+        if ( current_user_can( 'create_users' ) ) {
621
+            ?>
622 622
 	<a href="<?php echo esc_url( admin_url( 'user-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
623 623
 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
624 624
 	<a href="<?php echo esc_url( admin_url( 'user-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a>
@@ -626,13 +626,13 @@  discard block
 block discarded – undo
626 626
 }
627 627
 
628 628
 if ( strlen( $usersearch ) ) {
629
-	echo '<span class="subtitle">';
630
-	printf(
631
-		/* translators: %s: Search query. */
632
-		__( 'Search results for: %s' ),
633
-		'<strong>' . esc_html( $usersearch ) . '</strong>'
634
-	);
635
-	echo '</span>';
629
+    echo '<span class="subtitle">';
630
+    printf(
631
+        /* translators: %s: Search query. */
632
+        __( 'Search results for: %s' ),
633
+        '<strong>' . esc_html( $usersearch ) . '</strong>'
634
+    );
635
+    echo '</span>';
636 636
 }
637 637
 ?>
638 638
 
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 <div class="clear"></div>
655 655
 </div>
656 656
 		<?php
657
-		break;
657
+        break;
658 658
 
659 659
 } // End of the $doaction switch.
660 660
 
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-ftp.php 1 patch
Indentation   +803 added lines, -803 removed lines patch added patch discarded remove patch
@@ -81,833 +81,833 @@
 block discarded – undo
81 81
  *
82 82
  */
83 83
 class ftp_base {
84
-	/* Public variables */
85
-	var $LocalEcho;
86
-	var $Verbose;
87
-	var $OS_local;
88
-	var $OS_remote;
89
-
90
-	/* Private variables */
91
-	var $_lastaction;
92
-	var $_errors;
93
-	var $_type;
94
-	var $_umask;
95
-	var $_timeout;
96
-	var $_passive;
97
-	var $_host;
98
-	var $_fullhost;
99
-	var $_port;
100
-	var $_datahost;
101
-	var $_dataport;
102
-	var $_ftp_control_sock;
103
-	var $_ftp_data_sock;
104
-	var $_ftp_temp_sock;
105
-	var $_ftp_buff_size;
106
-	var $_login;
107
-	var $_password;
108
-	var $_connected;
109
-	var $_ready;
110
-	var $_code;
111
-	var $_message;
112
-	var $_can_restore;
113
-	var $_port_available;
114
-	var $_curtype;
115
-	var $_features;
116
-
117
-	var $_error_array;
118
-	var $AuthorizedTransferMode;
119
-	var $OS_FullName;
120
-	var $_eol_code;
121
-	var $AutoAsciiExt;
122
-
123
-	/* Constructor */
124
-	function __construct($port_mode=FALSE, $verb=FALSE, $le=FALSE) {
125
-		$this->LocalEcho=$le;
126
-		$this->Verbose=$verb;
127
-		$this->_lastaction=NULL;
128
-		$this->_error_array=array();
129
-		$this->_eol_code=array(FTP_OS_Unix=>"\n", FTP_OS_Mac=>"\r", FTP_OS_Windows=>"\r\n");
130
-		$this->AuthorizedTransferMode=array(FTP_AUTOASCII, FTP_ASCII, FTP_BINARY);
131
-		$this->OS_FullName=array(FTP_OS_Unix => 'UNIX', FTP_OS_Windows => 'WINDOWS', FTP_OS_Mac => 'MACOS');
132
-		$this->AutoAsciiExt=array("ASP","BAT","C","CPP","CSS","CSV","JS","H","HTM","HTML","SHTML","INI","LOG","PHP3","PHTML","PL","PERL","SH","SQL","TXT");
133
-		$this->_port_available=($port_mode==TRUE);
134
-		$this->SendMSG("Staring FTP client class".($this->_port_available?"":" without PORT mode support"));
135
-		$this->_connected=FALSE;
136
-		$this->_ready=FALSE;
137
-		$this->_can_restore=FALSE;
138
-		$this->_code=0;
139
-		$this->_message="";
140
-		$this->_ftp_buff_size=4096;
141
-		$this->_curtype=NULL;
142
-		$this->SetUmask(0022);
143
-		$this->SetType(FTP_AUTOASCII);
144
-		$this->SetTimeout(30);
145
-		$this->Passive(!$this->_port_available);
146
-		$this->_login="anonymous";
147
-		$this->_password="[email protected]";
148
-		$this->_features=array();
149
-	    $this->OS_local=FTP_OS_Unix;
150
-		$this->OS_remote=FTP_OS_Unix;
151
-		$this->features=array();
152
-		if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows;
153
-		elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
154
-	}
155
-
156
-	function ftp_base($port_mode=FALSE) {
157
-		$this->__construct($port_mode);
158
-	}
84
+    /* Public variables */
85
+    var $LocalEcho;
86
+    var $Verbose;
87
+    var $OS_local;
88
+    var $OS_remote;
89
+
90
+    /* Private variables */
91
+    var $_lastaction;
92
+    var $_errors;
93
+    var $_type;
94
+    var $_umask;
95
+    var $_timeout;
96
+    var $_passive;
97
+    var $_host;
98
+    var $_fullhost;
99
+    var $_port;
100
+    var $_datahost;
101
+    var $_dataport;
102
+    var $_ftp_control_sock;
103
+    var $_ftp_data_sock;
104
+    var $_ftp_temp_sock;
105
+    var $_ftp_buff_size;
106
+    var $_login;
107
+    var $_password;
108
+    var $_connected;
109
+    var $_ready;
110
+    var $_code;
111
+    var $_message;
112
+    var $_can_restore;
113
+    var $_port_available;
114
+    var $_curtype;
115
+    var $_features;
116
+
117
+    var $_error_array;
118
+    var $AuthorizedTransferMode;
119
+    var $OS_FullName;
120
+    var $_eol_code;
121
+    var $AutoAsciiExt;
122
+
123
+    /* Constructor */
124
+    function __construct($port_mode=FALSE, $verb=FALSE, $le=FALSE) {
125
+        $this->LocalEcho=$le;
126
+        $this->Verbose=$verb;
127
+        $this->_lastaction=NULL;
128
+        $this->_error_array=array();
129
+        $this->_eol_code=array(FTP_OS_Unix=>"\n", FTP_OS_Mac=>"\r", FTP_OS_Windows=>"\r\n");
130
+        $this->AuthorizedTransferMode=array(FTP_AUTOASCII, FTP_ASCII, FTP_BINARY);
131
+        $this->OS_FullName=array(FTP_OS_Unix => 'UNIX', FTP_OS_Windows => 'WINDOWS', FTP_OS_Mac => 'MACOS');
132
+        $this->AutoAsciiExt=array("ASP","BAT","C","CPP","CSS","CSV","JS","H","HTM","HTML","SHTML","INI","LOG","PHP3","PHTML","PL","PERL","SH","SQL","TXT");
133
+        $this->_port_available=($port_mode==TRUE);
134
+        $this->SendMSG("Staring FTP client class".($this->_port_available?"":" without PORT mode support"));
135
+        $this->_connected=FALSE;
136
+        $this->_ready=FALSE;
137
+        $this->_can_restore=FALSE;
138
+        $this->_code=0;
139
+        $this->_message="";
140
+        $this->_ftp_buff_size=4096;
141
+        $this->_curtype=NULL;
142
+        $this->SetUmask(0022);
143
+        $this->SetType(FTP_AUTOASCII);
144
+        $this->SetTimeout(30);
145
+        $this->Passive(!$this->_port_available);
146
+        $this->_login="anonymous";
147
+        $this->_password="[email protected]";
148
+        $this->_features=array();
149
+        $this->OS_local=FTP_OS_Unix;
150
+        $this->OS_remote=FTP_OS_Unix;
151
+        $this->features=array();
152
+        if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows;
153
+        elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
154
+    }
155
+
156
+    function ftp_base($port_mode=FALSE) {
157
+        $this->__construct($port_mode);
158
+    }
159 159
 
160 160
 // <!-- --------------------------------------------------------------------------------------- -->
161 161
 // <!--       Public functions                                                                  -->
162 162
 // <!-- --------------------------------------------------------------------------------------- -->
163 163
 
164
-	function parselisting($line) {
165
-		$is_windows = ($this->OS_remote == FTP_OS_Windows);
166
-		if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/",$line,$lucifer)) {
167
-			$b = array();
168
-			if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
169
-			$b['isdir'] = ($lucifer[7]=="<DIR>");
170
-			if ( $b['isdir'] )
171
-				$b['type'] = 'd';
172
-			else
173
-				$b['type'] = 'f';
174
-			$b['size'] = $lucifer[7];
175
-			$b['month'] = $lucifer[1];
176
-			$b['day'] = $lucifer[2];
177
-			$b['year'] = $lucifer[3];
178
-			$b['hour'] = $lucifer[4];
179
-			$b['minute'] = $lucifer[5];
180
-			$b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
181
-			$b['am/pm'] = $lucifer[6];
182
-			$b['name'] = $lucifer[8];
183
-		} else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
184
-			//echo $line."\n";
185
-			$lcount=count($lucifer);
186
-			if ($lcount<8) return '';
187
-			$b = array();
188
-			$b['isdir'] = $lucifer[0][0] === "d";
189
-			$b['islink'] = $lucifer[0][0] === "l";
190
-			if ( $b['isdir'] )
191
-				$b['type'] = 'd';
192
-			elseif ( $b['islink'] )
193
-				$b['type'] = 'l';
194
-			else
195
-				$b['type'] = 'f';
196
-			$b['perms'] = $lucifer[0];
197
-			$b['number'] = $lucifer[1];
198
-			$b['owner'] = $lucifer[2];
199
-			$b['group'] = $lucifer[3];
200
-			$b['size'] = $lucifer[4];
201
-			if ($lcount==8) {
202
-				sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
203
-				sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
204
-				$b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
205
-				$b['name'] = $lucifer[7];
206
-			} else {
207
-				$b['month'] = $lucifer[5];
208
-				$b['day'] = $lucifer[6];
209
-				if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {
210
-					$b['year'] = gmdate("Y");
211
-					$b['hour'] = $l2[1];
212
-					$b['minute'] = $l2[2];
213
-				} else {
214
-					$b['year'] = $lucifer[7];
215
-					$b['hour'] = 0;
216
-					$b['minute'] = 0;
217
-				}
218
-				$b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));
219
-				$b['name'] = $lucifer[8];
220
-			}
221
-		}
222
-
223
-		return $b;
224
-	}
225
-
226
-	function SendMSG($message = "", $crlf=true) {
227
-		if ($this->Verbose) {
228
-			echo $message.($crlf?CRLF:"");
229
-			flush();
230
-		}
231
-		return TRUE;
232
-	}
233
-
234
-	function SetType($mode=FTP_AUTOASCII) {
235
-		if(!in_array($mode, $this->AuthorizedTransferMode)) {
236
-			$this->SendMSG("Wrong type");
237
-			return FALSE;
238
-		}
239
-		$this->_type=$mode;
240
-		$this->SendMSG("Transfer type: ".($this->_type==FTP_BINARY?"binary":($this->_type==FTP_ASCII?"ASCII":"auto ASCII") ) );
241
-		return TRUE;
242
-	}
243
-
244
-	function _settype($mode=FTP_ASCII) {
245
-		if($this->_ready) {
246
-			if($mode==FTP_BINARY) {
247
-				if($this->_curtype!=FTP_BINARY) {
248
-					if(!$this->_exec("TYPE I", "SetType")) return FALSE;
249
-					$this->_curtype=FTP_BINARY;
250
-				}
251
-			} elseif($this->_curtype!=FTP_ASCII) {
252
-				if(!$this->_exec("TYPE A", "SetType")) return FALSE;
253
-				$this->_curtype=FTP_ASCII;
254
-			}
255
-		} else return FALSE;
256
-		return TRUE;
257
-	}
258
-
259
-	function Passive($pasv=NULL) {
260
-		if(is_null($pasv)) $this->_passive=!$this->_passive;
261
-		else $this->_passive=$pasv;
262
-		if(!$this->_port_available and !$this->_passive) {
263
-			$this->SendMSG("Only passive connections available!");
264
-			$this->_passive=TRUE;
265
-			return FALSE;
266
-		}
267
-		$this->SendMSG("Passive mode ".($this->_passive?"on":"off"));
268
-		return TRUE;
269
-	}
270
-
271
-	function SetServer($host, $port=21, $reconnect=true) {
272
-		if(!is_long($port)) {
273
-	        $this->verbose=true;
274
-    	    $this->SendMSG("Incorrect port syntax");
275
-			return FALSE;
276
-		} else {
277
-			$ip=@gethostbyname($host);
278
-	        $dns=@gethostbyaddr($host);
279
-	        if(!$ip) $ip=$host;
280
-	        if(!$dns) $dns=$host;
281
-	        // Validate the IPAddress PHP4 returns -1 for invalid, PHP5 false
282
-	        // -1 === "255.255.255.255" which is the broadcast address which is also going to be invalid
283
-	        $ipaslong = ip2long($ip);
284
-			if ( ($ipaslong == false) || ($ipaslong === -1) ) {
285
-				$this->SendMSG("Wrong host name/address \"".$host."\"");
286
-				return FALSE;
287
-			}
288
-	        $this->_host=$ip;
289
-	        $this->_fullhost=$dns;
290
-	        $this->_port=$port;
291
-	        $this->_dataport=$port-1;
292
-		}
293
-		$this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\"");
294
-		if($reconnect){
295
-			if($this->_connected) {
296
-				$this->SendMSG("Reconnecting");
297
-				if(!$this->quit(FTP_FORCE)) return FALSE;
298
-				if(!$this->connect()) return FALSE;
299
-			}
300
-		}
301
-		return TRUE;
302
-	}
303
-
304
-	function SetUmask($umask=0022) {
305
-		$this->_umask=$umask;
306
-		umask($this->_umask);
307
-		$this->SendMSG("UMASK 0".decoct($this->_umask));
308
-		return TRUE;
309
-	}
310
-
311
-	function SetTimeout($timeout=30) {
312
-		$this->_timeout=$timeout;
313
-		$this->SendMSG("Timeout ".$this->_timeout);
314
-		if($this->_connected)
315
-			if(!$this->_settimeout($this->_ftp_control_sock)) return FALSE;
316
-		return TRUE;
317
-	}
318
-
319
-	function connect($server=NULL) {
320
-		if(!empty($server)) {
321
-			if(!$this->SetServer($server)) return false;
322
-		}
323
-		if($this->_ready) return true;
324
-	    $this->SendMsg('Local OS : '.$this->OS_FullName[$this->OS_local]);
325
-		if(!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) {
326
-			$this->SendMSG("Error : Cannot connect to remote host \"".$this->_fullhost." :".$this->_port."\"");
327
-			return FALSE;
328
-		}
329
-		$this->SendMSG("Connected to remote host \"".$this->_fullhost.":".$this->_port."\". Waiting for greeting.");
330
-		do {
331
-			if(!$this->_readmsg()) return FALSE;
332
-			if(!$this->_checkCode()) return FALSE;
333
-			$this->_lastaction=time();
334
-		} while($this->_code<200);
335
-		$this->_ready=true;
336
-		$syst=$this->systype();
337
-		if(!$syst) $this->SendMSG("Cannot detect remote OS");
338
-		else {
339
-			if(preg_match("/win|dos|novell/i", $syst[0])) $this->OS_remote=FTP_OS_Windows;
340
-			elseif(preg_match("/os/i", $syst[0])) $this->OS_remote=FTP_OS_Mac;
341
-			elseif(preg_match("/(li|u)nix/i", $syst[0])) $this->OS_remote=FTP_OS_Unix;
342
-			else $this->OS_remote=FTP_OS_Mac;
343
-			$this->SendMSG("Remote OS: ".$this->OS_FullName[$this->OS_remote]);
344
-		}
345
-		if(!$this->features()) $this->SendMSG("Cannot get features list. All supported - disabled");
346
-		else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
347
-		return TRUE;
348
-	}
349
-
350
-	function quit($force=false) {
351
-		if($this->_ready) {
352
-			if(!$this->_exec("QUIT") and !$force) return FALSE;
353
-			if(!$this->_checkCode() and !$force) return FALSE;
354
-			$this->_ready=false;
355
-			$this->SendMSG("Session finished");
356
-		}
357
-		$this->_quit();
358
-		return TRUE;
359
-	}
360
-
361
-	function login($user=NULL, $pass=NULL) {
362
-		if(!is_null($user)) $this->_login=$user;
363
-		else $this->_login="anonymous";
364
-		if(!is_null($pass)) $this->_password=$pass;
365
-		else $this->_password="[email protected]";
366
-		if(!$this->_exec("USER ".$this->_login, "login")) return FALSE;
367
-		if(!$this->_checkCode()) return FALSE;
368
-		if($this->_code!=230) {
369
-			if(!$this->_exec((($this->_code==331)?"PASS ":"ACCT ").$this->_password, "login")) return FALSE;
370
-			if(!$this->_checkCode()) return FALSE;
371
-		}
372
-		$this->SendMSG("Authentication succeeded");
373
-		if(empty($this->_features)) {
374
-			if(!$this->features()) $this->SendMSG("Cannot get features list. All supported - disabled");
375
-			else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
376
-		}
377
-		return TRUE;
378
-	}
379
-
380
-	function pwd() {
381
-		if(!$this->_exec("PWD", "pwd")) return FALSE;
382
-		if(!$this->_checkCode()) return FALSE;
383
-		return preg_replace("/^[0-9]{3} \"(.+)\".*$/s", "\\1", $this->_message);
384
-	}
385
-
386
-	function cdup() {
387
-		if(!$this->_exec("CDUP", "cdup")) return FALSE;
388
-		if(!$this->_checkCode()) return FALSE;
389
-		return true;
390
-	}
391
-
392
-	function chdir($pathname) {
393
-		if(!$this->_exec("CWD ".$pathname, "chdir")) return FALSE;
394
-		if(!$this->_checkCode()) return FALSE;
395
-		return TRUE;
396
-	}
397
-
398
-	function rmdir($pathname) {
399
-		if(!$this->_exec("RMD ".$pathname, "rmdir")) return FALSE;
400
-		if(!$this->_checkCode()) return FALSE;
401
-		return TRUE;
402
-	}
403
-
404
-	function mkdir($pathname) {
405
-		if(!$this->_exec("MKD ".$pathname, "mkdir")) return FALSE;
406
-		if(!$this->_checkCode()) return FALSE;
407
-		return TRUE;
408
-	}
409
-
410
-	function rename($from, $to) {
411
-		if(!$this->_exec("RNFR ".$from, "rename")) return FALSE;
412
-		if(!$this->_checkCode()) return FALSE;
413
-		if($this->_code==350) {
414
-			if(!$this->_exec("RNTO ".$to, "rename")) return FALSE;
415
-			if(!$this->_checkCode()) return FALSE;
416
-		} else return FALSE;
417
-		return TRUE;
418
-	}
419
-
420
-	function filesize($pathname) {
421
-		if(!isset($this->_features["SIZE"])) {
422
-			$this->PushError("filesize", "not supported by server");
423
-			return FALSE;
424
-		}
425
-		if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE;
426
-		if(!$this->_checkCode()) return FALSE;
427
-		return preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
428
-	}
429
-
430
-	function abort() {
431
-		if(!$this->_exec("ABOR", "abort")) return FALSE;
432
-		if(!$this->_checkCode()) {
433
-			if($this->_code!=426) return FALSE;
434
-			if(!$this->_readmsg("abort")) return FALSE;
435
-			if(!$this->_checkCode()) return FALSE;
436
-		}
437
-		return true;
438
-	}
439
-
440
-	function mdtm($pathname) {
441
-		if(!isset($this->_features["MDTM"])) {
442
-			$this->PushError("mdtm", "not supported by server");
443
-			return FALSE;
444
-		}
445
-		if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE;
446
-		if(!$this->_checkCode()) return FALSE;
447
-		$mdtm = preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
448
-		$date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
449
-		$timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
450
-		return $timestamp;
451
-	}
452
-
453
-	function systype() {
454
-		if(!$this->_exec("SYST", "systype")) return FALSE;
455
-		if(!$this->_checkCode()) return FALSE;
456
-		$DATA = explode(" ", $this->_message);
457
-		return array($DATA[1], $DATA[3]);
458
-	}
459
-
460
-	function delete($pathname) {
461
-		if(!$this->_exec("DELE ".$pathname, "delete")) return FALSE;
462
-		if(!$this->_checkCode()) return FALSE;
463
-		return TRUE;
464
-	}
465
-
466
-	function site($command, $fnction="site") {
467
-		if(!$this->_exec("SITE ".$command, $fnction)) return FALSE;
468
-		if(!$this->_checkCode()) return FALSE;
469
-		return TRUE;
470
-	}
471
-
472
-	function chmod($pathname, $mode) {
473
-		if(!$this->site( sprintf('CHMOD %o %s', $mode, $pathname), "chmod")) return FALSE;
474
-		return TRUE;
475
-	}
476
-
477
-	function restore($from) {
478
-		if(!isset($this->_features["REST"])) {
479
-			$this->PushError("restore", "not supported by server");
480
-			return FALSE;
481
-		}
482
-		if($this->_curtype!=FTP_BINARY) {
483
-			$this->PushError("restore", "cannot restore in ASCII mode");
484
-			return FALSE;
485
-		}
486
-		if(!$this->_exec("REST ".$from, "resore")) return FALSE;
487
-		if(!$this->_checkCode()) return FALSE;
488
-		return TRUE;
489
-	}
490
-
491
-	function features() {
492
-		if(!$this->_exec("FEAT", "features")) return FALSE;
493
-		if(!$this->_checkCode()) return FALSE;
494
-		$f=preg_split("/[".CRLF."]+/", preg_replace("/[0-9]{3}[ -].*[".CRLF."]+/", "", $this->_message), -1, PREG_SPLIT_NO_EMPTY);
495
-		$this->_features=array();
496
-		foreach($f as $k=>$v) {
497
-			$v=explode(" ", trim($v));
498
-			$this->_features[array_shift($v)]=$v;
499
-		}
500
-		return true;
501
-	}
502
-
503
-	function rawlist($pathname="", $arg="") {
504
-		return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist");
505
-	}
506
-
507
-	function nlist($pathname="", $arg="") {
508
-		return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
509
-	}
510
-
511
-	function is_exists($pathname) {
512
-		return $this->file_exists($pathname);
513
-	}
514
-
515
-	function file_exists($pathname) {
516
-		$exists=true;
517
-		if(!$this->_exec("RNFR ".$pathname, "rename")) $exists=FALSE;
518
-		else {
519
-			if(!$this->_checkCode()) $exists=FALSE;
520
-			$this->abort();
521
-		}
522
-		if($exists) $this->SendMSG("Remote file ".$pathname." exists");
523
-		else $this->SendMSG("Remote file ".$pathname." does not exist");
524
-		return $exists;
525
-	}
526
-
527
-	function fget($fp, $remotefile, $rest=0) {
528
-		if($this->_can_restore and $rest!=0) fseek($fp, $rest);
529
-		$pi=pathinfo($remotefile);
530
-		if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
531
-		else $mode=FTP_BINARY;
532
-		if(!$this->_data_prepare($mode)) {
533
-			return FALSE;
534
-		}
535
-		if($this->_can_restore and $rest!=0) $this->restore($rest);
536
-		if(!$this->_exec("RETR ".$remotefile, "get")) {
537
-			$this->_data_close();
538
-			return FALSE;
539
-		}
540
-		if(!$this->_checkCode()) {
541
-			$this->_data_close();
542
-			return FALSE;
543
-		}
544
-		$out=$this->_data_read($mode, $fp);
545
-		$this->_data_close();
546
-		if(!$this->_readmsg()) return FALSE;
547
-		if(!$this->_checkCode()) return FALSE;
548
-		return $out;
549
-	}
550
-
551
-	function get($remotefile, $localfile=NULL, $rest=0) {
552
-		if(is_null($localfile)) $localfile=$remotefile;
553
-		if (@file_exists($localfile)) $this->SendMSG("Warning : local file will be overwritten");
554
-		$fp = @fopen($localfile, "w");
555
-		if (!$fp) {
556
-			$this->PushError("get","cannot open local file", "Cannot create \"".$localfile."\"");
557
-			return FALSE;
558
-		}
559
-		if($this->_can_restore and $rest!=0) fseek($fp, $rest);
560
-		$pi=pathinfo($remotefile);
561
-		if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
562
-		else $mode=FTP_BINARY;
563
-		if(!$this->_data_prepare($mode)) {
564
-			fclose($fp);
565
-			return FALSE;
566
-		}
567
-		if($this->_can_restore and $rest!=0) $this->restore($rest);
568
-		if(!$this->_exec("RETR ".$remotefile, "get")) {
569
-			$this->_data_close();
570
-			fclose($fp);
571
-			return FALSE;
572
-		}
573
-		if(!$this->_checkCode()) {
574
-			$this->_data_close();
575
-			fclose($fp);
576
-			return FALSE;
577
-		}
578
-		$out=$this->_data_read($mode, $fp);
579
-		fclose($fp);
580
-		$this->_data_close();
581
-		if(!$this->_readmsg()) return FALSE;
582
-		if(!$this->_checkCode()) return FALSE;
583
-		return $out;
584
-	}
585
-
586
-	function fput($remotefile, $fp, $rest=0) {
587
-		if($this->_can_restore and $rest!=0) fseek($fp, $rest);
588
-		$pi=pathinfo($remotefile);
589
-		if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
590
-		else $mode=FTP_BINARY;
591
-		if(!$this->_data_prepare($mode)) {
592
-			return FALSE;
593
-		}
594
-		if($this->_can_restore and $rest!=0) $this->restore($rest);
595
-		if(!$this->_exec("STOR ".$remotefile, "put")) {
596
-			$this->_data_close();
597
-			return FALSE;
598
-		}
599
-		if(!$this->_checkCode()) {
600
-			$this->_data_close();
601
-			return FALSE;
602
-		}
603
-		$ret=$this->_data_write($mode, $fp);
604
-		$this->_data_close();
605
-		if(!$this->_readmsg()) return FALSE;
606
-		if(!$this->_checkCode()) return FALSE;
607
-		return $ret;
608
-	}
609
-
610
-	function put($localfile, $remotefile=NULL, $rest=0) {
611
-		if(is_null($remotefile)) $remotefile=$localfile;
612
-		if (!file_exists($localfile)) {
613
-			$this->PushError("put","cannot open local file", "No such file or directory \"".$localfile."\"");
614
-			return FALSE;
615
-		}
616
-		$fp = @fopen($localfile, "r");
617
-
618
-		if (!$fp) {
619
-			$this->PushError("put","cannot open local file", "Cannot read file \"".$localfile."\"");
620
-			return FALSE;
621
-		}
622
-		if($this->_can_restore and $rest!=0) fseek($fp, $rest);
623
-		$pi=pathinfo($localfile);
624
-		if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
625
-		else $mode=FTP_BINARY;
626
-		if(!$this->_data_prepare($mode)) {
627
-			fclose($fp);
628
-			return FALSE;
629
-		}
630
-		if($this->_can_restore and $rest!=0) $this->restore($rest);
631
-		if(!$this->_exec("STOR ".$remotefile, "put")) {
632
-			$this->_data_close();
633
-			fclose($fp);
634
-			return FALSE;
635
-		}
636
-		if(!$this->_checkCode()) {
637
-			$this->_data_close();
638
-			fclose($fp);
639
-			return FALSE;
640
-		}
641
-		$ret=$this->_data_write($mode, $fp);
642
-		fclose($fp);
643
-		$this->_data_close();
644
-		if(!$this->_readmsg()) return FALSE;
645
-		if(!$this->_checkCode()) return FALSE;
646
-		return $ret;
647
-	}
648
-
649
-	function mput($local=".", $remote=NULL, $continious=false) {
650
-		$local=realpath($local);
651
-		if(!@file_exists($local)) {
652
-			$this->PushError("mput","cannot open local folder", "Cannot stat folder \"".$local."\"");
653
-			return FALSE;
654
-		}
655
-		if(!is_dir($local)) return $this->put($local, $remote);
656
-		if(empty($remote)) $remote=".";
657
-		elseif(!$this->file_exists($remote) and !$this->mkdir($remote)) return FALSE;
658
-		if($handle = opendir($local)) {
659
-			$list=array();
660
-			while (false !== ($file = readdir($handle))) {
661
-				if ($file != "." && $file != "..") $list[]=$file;
662
-			}
663
-			closedir($handle);
664
-		} else {
665
-			$this->PushError("mput","cannot open local folder", "Cannot read folder \"".$local."\"");
666
-			return FALSE;
667
-		}
668
-		if(empty($list)) return TRUE;
669
-		$ret=true;
670
-		foreach($list as $el) {
671
-			if(is_dir($local."/".$el)) $t=$this->mput($local."/".$el, $remote."/".$el);
672
-			else $t=$this->put($local."/".$el, $remote."/".$el);
673
-			if(!$t) {
674
-				$ret=FALSE;
675
-				if(!$continious) break;
676
-			}
677
-		}
678
-		return $ret;
679
-
680
-	}
681
-
682
-	function mget($remote, $local=".", $continious=false) {
683
-		$list=$this->rawlist($remote, "-lA");
684
-		if($list===false) {
685
-			$this->PushError("mget","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents");
686
-			return FALSE;
687
-		}
688
-		if(empty($list)) return true;
689
-		if(!@file_exists($local)) {
690
-			if(!@mkdir($local)) {
691
-				$this->PushError("mget","cannot create local folder", "Cannot create folder \"".$local."\"");
692
-				return FALSE;
693
-			}
694
-		}
695
-		foreach($list as $k=>$v) {
696
-			$list[$k]=$this->parselisting($v);
697
-			if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
698
-		}
699
-		$ret=true;
700
-		foreach($list as $el) {
701
-			if($el["type"]=="d") {
702
-				if(!$this->mget($remote."/".$el["name"], $local."/".$el["name"], $continious)) {
703
-					$this->PushError("mget", "cannot copy folder", "Cannot copy remote folder \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
704
-					$ret=false;
705
-					if(!$continious) break;
706
-				}
707
-			} else {
708
-				if(!$this->get($remote."/".$el["name"], $local."/".$el["name"])) {
709
-					$this->PushError("mget", "cannot copy file", "Cannot copy remote file \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
710
-					$ret=false;
711
-					if(!$continious) break;
712
-				}
713
-			}
714
-			@chmod($local."/".$el["name"], $el["perms"]);
715
-			$t=strtotime($el["date"]);
716
-			if($t!==-1 and $t!==false) @touch($local."/".$el["name"], $t);
717
-		}
718
-		return $ret;
719
-	}
720
-
721
-	function mdel($remote, $continious=false) {
722
-		$list=$this->rawlist($remote, "-la");
723
-		if($list===false) {
724
-			$this->PushError("mdel","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents");
725
-			return false;
726
-		}
727
-
728
-		foreach($list as $k=>$v) {
729
-			$list[$k]=$this->parselisting($v);
730
-			if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
731
-		}
732
-		$ret=true;
733
-
734
-		foreach($list as $el) {
735
-			if ( empty($el) )
736
-				continue;
737
-
738
-			if($el["type"]=="d") {
739
-				if(!$this->mdel($remote."/".$el["name"], $continious)) {
740
-					$ret=false;
741
-					if(!$continious) break;
742
-				}
743
-			} else {
744
-				if (!$this->delete($remote."/".$el["name"])) {
745
-					$this->PushError("mdel", "cannot delete file", "Cannot delete remote file \"".$remote."/".$el["name"]."\"");
746
-					$ret=false;
747
-					if(!$continious) break;
748
-				}
749
-			}
750
-		}
751
-
752
-		if(!$this->rmdir($remote)) {
753
-			$this->PushError("mdel", "cannot delete folder", "Cannot delete remote folder \"".$remote."/".$el["name"]."\"");
754
-			$ret=false;
755
-		}
756
-		return $ret;
757
-	}
758
-
759
-	function mmkdir($dir, $mode = 0777) {
760
-		if(empty($dir)) return FALSE;
761
-		if($this->is_exists($dir) or $dir == "/" ) return TRUE;
762
-		if(!$this->mmkdir(dirname($dir), $mode)) return false;
763
-		$r=$this->mkdir($dir, $mode);
764
-		$this->chmod($dir,$mode);
765
-		return $r;
766
-	}
767
-
768
-	function glob($pattern, $handle=NULL) {
769
-		$path=$output=null;
770
-		if(PHP_OS=='WIN32') $slash='\\';
771
-		else $slash='/';
772
-		$lastpos=strrpos($pattern,$slash);
773
-		if(!($lastpos===false)) {
774
-			$path=substr($pattern,0,-$lastpos-1);
775
-			$pattern=substr($pattern,$lastpos);
776
-		} else $path=getcwd();
777
-		if(is_array($handle) and !empty($handle)) {
778
-			foreach($handle as $dir) {
779
-				if($this->glob_pattern_match($pattern,$dir))
780
-				$output[]=$dir;
781
-			}
782
-		} else {
783
-			$handle=@opendir($path);
784
-			if($handle===false) return false;
785
-			while($dir=readdir($handle)) {
786
-				if($this->glob_pattern_match($pattern,$dir))
787
-				$output[]=$dir;
788
-			}
789
-			closedir($handle);
790
-		}
791
-		if(is_array($output)) return $output;
792
-		return false;
793
-	}
794
-
795
-	function glob_pattern_match($pattern,$subject) {
796
-		$out=null;
797
-		$chunks=explode(';',$pattern);
798
-		foreach($chunks as $pattern) {
799
-			$escape=array('$','^','.','{','}','(',')','[',']','|');
800
-			while(strpos($pattern,'**')!==false)
801
-				$pattern=str_replace('**','*',$pattern);
802
-			foreach($escape as $probe)
803
-				$pattern=str_replace($probe,"\\$probe",$pattern);
804
-			$pattern=str_replace('?*','*',
805
-				str_replace('*?','*',
806
-					str_replace('*',".*",
807
-						str_replace('?','.{1,1}',$pattern))));
808
-			$out[]=$pattern;
809
-		}
810
-		if(count($out)==1) return($this->glob_regexp("^$out[0]$",$subject));
811
-		else {
812
-			foreach($out as $tester)
813
-				// TODO: This should probably be glob_regexp(), but needs tests.
814
-				if($this->my_regexp("^$tester$",$subject)) return true;
815
-		}
816
-		return false;
817
-	}
818
-
819
-	function glob_regexp($pattern,$subject) {
820
-		$sensitive=(PHP_OS!='WIN32');
821
-		return ($sensitive?
822
-			preg_match( '/' . preg_quote( $pattern, '/' ) . '/', $subject ) :
823
-			preg_match( '/' . preg_quote( $pattern, '/' ) . '/i', $subject )
824
-		);
825
-	}
826
-
827
-	function dirlist($remote) {
828
-		$list=$this->rawlist($remote, "-la");
829
-		if($list===false) {
830
-			$this->PushError("dirlist","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents");
831
-			return false;
832
-		}
833
-
834
-		$dirlist = array();
835
-		foreach($list as $k=>$v) {
836
-			$entry=$this->parselisting($v);
837
-			if ( empty($entry) )
838
-				continue;
839
-
840
-			if($entry["name"]=="." or $entry["name"]=="..")
841
-				continue;
842
-
843
-			$dirlist[$entry['name']] = $entry;
844
-		}
845
-
846
-		return $dirlist;
847
-	}
164
+    function parselisting($line) {
165
+        $is_windows = ($this->OS_remote == FTP_OS_Windows);
166
+        if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/",$line,$lucifer)) {
167
+            $b = array();
168
+            if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
169
+            $b['isdir'] = ($lucifer[7]=="<DIR>");
170
+            if ( $b['isdir'] )
171
+                $b['type'] = 'd';
172
+            else
173
+                $b['type'] = 'f';
174
+            $b['size'] = $lucifer[7];
175
+            $b['month'] = $lucifer[1];
176
+            $b['day'] = $lucifer[2];
177
+            $b['year'] = $lucifer[3];
178
+            $b['hour'] = $lucifer[4];
179
+            $b['minute'] = $lucifer[5];
180
+            $b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
181
+            $b['am/pm'] = $lucifer[6];
182
+            $b['name'] = $lucifer[8];
183
+        } else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
184
+            //echo $line."\n";
185
+            $lcount=count($lucifer);
186
+            if ($lcount<8) return '';
187
+            $b = array();
188
+            $b['isdir'] = $lucifer[0][0] === "d";
189
+            $b['islink'] = $lucifer[0][0] === "l";
190
+            if ( $b['isdir'] )
191
+                $b['type'] = 'd';
192
+            elseif ( $b['islink'] )
193
+                $b['type'] = 'l';
194
+            else
195
+                $b['type'] = 'f';
196
+            $b['perms'] = $lucifer[0];
197
+            $b['number'] = $lucifer[1];
198
+            $b['owner'] = $lucifer[2];
199
+            $b['group'] = $lucifer[3];
200
+            $b['size'] = $lucifer[4];
201
+            if ($lcount==8) {
202
+                sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
203
+                sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
204
+                $b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
205
+                $b['name'] = $lucifer[7];
206
+            } else {
207
+                $b['month'] = $lucifer[5];
208
+                $b['day'] = $lucifer[6];
209
+                if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {
210
+                    $b['year'] = gmdate("Y");
211
+                    $b['hour'] = $l2[1];
212
+                    $b['minute'] = $l2[2];
213
+                } else {
214
+                    $b['year'] = $lucifer[7];
215
+                    $b['hour'] = 0;
216
+                    $b['minute'] = 0;
217
+                }
218
+                $b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));
219
+                $b['name'] = $lucifer[8];
220
+            }
221
+        }
222
+
223
+        return $b;
224
+    }
225
+
226
+    function SendMSG($message = "", $crlf=true) {
227
+        if ($this->Verbose) {
228
+            echo $message.($crlf?CRLF:"");
229
+            flush();
230
+        }
231
+        return TRUE;
232
+    }
233
+
234
+    function SetType($mode=FTP_AUTOASCII) {
235
+        if(!in_array($mode, $this->AuthorizedTransferMode)) {
236
+            $this->SendMSG("Wrong type");
237
+            return FALSE;
238
+        }
239
+        $this->_type=$mode;
240
+        $this->SendMSG("Transfer type: ".($this->_type==FTP_BINARY?"binary":($this->_type==FTP_ASCII?"ASCII":"auto ASCII") ) );
241
+        return TRUE;
242
+    }
243
+
244
+    function _settype($mode=FTP_ASCII) {
245
+        if($this->_ready) {
246
+            if($mode==FTP_BINARY) {
247
+                if($this->_curtype!=FTP_BINARY) {
248
+                    if(!$this->_exec("TYPE I", "SetType")) return FALSE;
249
+                    $this->_curtype=FTP_BINARY;
250
+                }
251
+            } elseif($this->_curtype!=FTP_ASCII) {
252
+                if(!$this->_exec("TYPE A", "SetType")) return FALSE;
253
+                $this->_curtype=FTP_ASCII;
254
+            }
255
+        } else return FALSE;
256
+        return TRUE;
257
+    }
258
+
259
+    function Passive($pasv=NULL) {
260
+        if(is_null($pasv)) $this->_passive=!$this->_passive;
261
+        else $this->_passive=$pasv;
262
+        if(!$this->_port_available and !$this->_passive) {
263
+            $this->SendMSG("Only passive connections available!");
264
+            $this->_passive=TRUE;
265
+            return FALSE;
266
+        }
267
+        $this->SendMSG("Passive mode ".($this->_passive?"on":"off"));
268
+        return TRUE;
269
+    }
270
+
271
+    function SetServer($host, $port=21, $reconnect=true) {
272
+        if(!is_long($port)) {
273
+            $this->verbose=true;
274
+            $this->SendMSG("Incorrect port syntax");
275
+            return FALSE;
276
+        } else {
277
+            $ip=@gethostbyname($host);
278
+            $dns=@gethostbyaddr($host);
279
+            if(!$ip) $ip=$host;
280
+            if(!$dns) $dns=$host;
281
+            // Validate the IPAddress PHP4 returns -1 for invalid, PHP5 false
282
+            // -1 === "255.255.255.255" which is the broadcast address which is also going to be invalid
283
+            $ipaslong = ip2long($ip);
284
+            if ( ($ipaslong == false) || ($ipaslong === -1) ) {
285
+                $this->SendMSG("Wrong host name/address \"".$host."\"");
286
+                return FALSE;
287
+            }
288
+            $this->_host=$ip;
289
+            $this->_fullhost=$dns;
290
+            $this->_port=$port;
291
+            $this->_dataport=$port-1;
292
+        }
293
+        $this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\"");
294
+        if($reconnect){
295
+            if($this->_connected) {
296
+                $this->SendMSG("Reconnecting");
297
+                if(!$this->quit(FTP_FORCE)) return FALSE;
298
+                if(!$this->connect()) return FALSE;
299
+            }
300
+        }
301
+        return TRUE;
302
+    }
303
+
304
+    function SetUmask($umask=0022) {
305
+        $this->_umask=$umask;
306
+        umask($this->_umask);
307
+        $this->SendMSG("UMASK 0".decoct($this->_umask));
308
+        return TRUE;
309
+    }
310
+
311
+    function SetTimeout($timeout=30) {
312
+        $this->_timeout=$timeout;
313
+        $this->SendMSG("Timeout ".$this->_timeout);
314
+        if($this->_connected)
315
+            if(!$this->_settimeout($this->_ftp_control_sock)) return FALSE;
316
+        return TRUE;
317
+    }
318
+
319
+    function connect($server=NULL) {
320
+        if(!empty($server)) {
321
+            if(!$this->SetServer($server)) return false;
322
+        }
323
+        if($this->_ready) return true;
324
+        $this->SendMsg('Local OS : '.$this->OS_FullName[$this->OS_local]);
325
+        if(!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) {
326
+            $this->SendMSG("Error : Cannot connect to remote host \"".$this->_fullhost." :".$this->_port."\"");
327
+            return FALSE;
328
+        }
329
+        $this->SendMSG("Connected to remote host \"".$this->_fullhost.":".$this->_port."\". Waiting for greeting.");
330
+        do {
331
+            if(!$this->_readmsg()) return FALSE;
332
+            if(!$this->_checkCode()) return FALSE;
333
+            $this->_lastaction=time();
334
+        } while($this->_code<200);
335
+        $this->_ready=true;
336
+        $syst=$this->systype();
337
+        if(!$syst) $this->SendMSG("Cannot detect remote OS");
338
+        else {
339
+            if(preg_match("/win|dos|novell/i", $syst[0])) $this->OS_remote=FTP_OS_Windows;
340
+            elseif(preg_match("/os/i", $syst[0])) $this->OS_remote=FTP_OS_Mac;
341
+            elseif(preg_match("/(li|u)nix/i", $syst[0])) $this->OS_remote=FTP_OS_Unix;
342
+            else $this->OS_remote=FTP_OS_Mac;
343
+            $this->SendMSG("Remote OS: ".$this->OS_FullName[$this->OS_remote]);
344
+        }
345
+        if(!$this->features()) $this->SendMSG("Cannot get features list. All supported - disabled");
346
+        else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
347
+        return TRUE;
348
+    }
349
+
350
+    function quit($force=false) {
351
+        if($this->_ready) {
352
+            if(!$this->_exec("QUIT") and !$force) return FALSE;
353
+            if(!$this->_checkCode() and !$force) return FALSE;
354
+            $this->_ready=false;
355
+            $this->SendMSG("Session finished");
356
+        }
357
+        $this->_quit();
358
+        return TRUE;
359
+    }
360
+
361
+    function login($user=NULL, $pass=NULL) {
362
+        if(!is_null($user)) $this->_login=$user;
363
+        else $this->_login="anonymous";
364
+        if(!is_null($pass)) $this->_password=$pass;
365
+        else $this->_password="[email protected]";
366
+        if(!$this->_exec("USER ".$this->_login, "login")) return FALSE;
367
+        if(!$this->_checkCode()) return FALSE;
368
+        if($this->_code!=230) {
369
+            if(!$this->_exec((($this->_code==331)?"PASS ":"ACCT ").$this->_password, "login")) return FALSE;
370
+            if(!$this->_checkCode()) return FALSE;
371
+        }
372
+        $this->SendMSG("Authentication succeeded");
373
+        if(empty($this->_features)) {
374
+            if(!$this->features()) $this->SendMSG("Cannot get features list. All supported - disabled");
375
+            else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
376
+        }
377
+        return TRUE;
378
+    }
379
+
380
+    function pwd() {
381
+        if(!$this->_exec("PWD", "pwd")) return FALSE;
382
+        if(!$this->_checkCode()) return FALSE;
383
+        return preg_replace("/^[0-9]{3} \"(.+)\".*$/s", "\\1", $this->_message);
384
+    }
385
+
386
+    function cdup() {
387
+        if(!$this->_exec("CDUP", "cdup")) return FALSE;
388
+        if(!$this->_checkCode()) return FALSE;
389
+        return true;
390
+    }
391
+
392
+    function chdir($pathname) {
393
+        if(!$this->_exec("CWD ".$pathname, "chdir")) return FALSE;
394
+        if(!$this->_checkCode()) return FALSE;
395
+        return TRUE;
396
+    }
397
+
398
+    function rmdir($pathname) {
399
+        if(!$this->_exec("RMD ".$pathname, "rmdir")) return FALSE;
400
+        if(!$this->_checkCode()) return FALSE;
401
+        return TRUE;
402
+    }
403
+
404
+    function mkdir($pathname) {
405
+        if(!$this->_exec("MKD ".$pathname, "mkdir")) return FALSE;
406
+        if(!$this->_checkCode()) return FALSE;
407
+        return TRUE;
408
+    }
409
+
410
+    function rename($from, $to) {
411
+        if(!$this->_exec("RNFR ".$from, "rename")) return FALSE;
412
+        if(!$this->_checkCode()) return FALSE;
413
+        if($this->_code==350) {
414
+            if(!$this->_exec("RNTO ".$to, "rename")) return FALSE;
415
+            if(!$this->_checkCode()) return FALSE;
416
+        } else return FALSE;
417
+        return TRUE;
418
+    }
419
+
420
+    function filesize($pathname) {
421
+        if(!isset($this->_features["SIZE"])) {
422
+            $this->PushError("filesize", "not supported by server");
423
+            return FALSE;
424
+        }
425
+        if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE;
426
+        if(!$this->_checkCode()) return FALSE;
427
+        return preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
428
+    }
429
+
430
+    function abort() {
431
+        if(!$this->_exec("ABOR", "abort")) return FALSE;
432
+        if(!$this->_checkCode()) {
433
+            if($this->_code!=426) return FALSE;
434
+            if(!$this->_readmsg("abort")) return FALSE;
435
+            if(!$this->_checkCode()) return FALSE;
436
+        }
437
+        return true;
438
+    }
439
+
440
+    function mdtm($pathname) {
441
+        if(!isset($this->_features["MDTM"])) {
442
+            $this->PushError("mdtm", "not supported by server");
443
+            return FALSE;
444
+        }
445
+        if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE;
446
+        if(!$this->_checkCode()) return FALSE;
447
+        $mdtm = preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
448
+        $date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
449
+        $timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
450
+        return $timestamp;
451
+    }
452
+
453
+    function systype() {
454
+        if(!$this->_exec("SYST", "systype")) return FALSE;
455
+        if(!$this->_checkCode()) return FALSE;
456
+        $DATA = explode(" ", $this->_message);
457
+        return array($DATA[1], $DATA[3]);
458
+    }
459
+
460
+    function delete($pathname) {
461
+        if(!$this->_exec("DELE ".$pathname, "delete")) return FALSE;
462
+        if(!$this->_checkCode()) return FALSE;
463
+        return TRUE;
464
+    }
465
+
466
+    function site($command, $fnction="site") {
467
+        if(!$this->_exec("SITE ".$command, $fnction)) return FALSE;
468
+        if(!$this->_checkCode()) return FALSE;
469
+        return TRUE;
470
+    }
471
+
472
+    function chmod($pathname, $mode) {
473
+        if(!$this->site( sprintf('CHMOD %o %s', $mode, $pathname), "chmod")) return FALSE;
474
+        return TRUE;
475
+    }
476
+
477
+    function restore($from) {
478
+        if(!isset($this->_features["REST"])) {
479
+            $this->PushError("restore", "not supported by server");
480
+            return FALSE;
481
+        }
482
+        if($this->_curtype!=FTP_BINARY) {
483
+            $this->PushError("restore", "cannot restore in ASCII mode");
484
+            return FALSE;
485
+        }
486
+        if(!$this->_exec("REST ".$from, "resore")) return FALSE;
487
+        if(!$this->_checkCode()) return FALSE;
488
+        return TRUE;
489
+    }
490
+
491
+    function features() {
492
+        if(!$this->_exec("FEAT", "features")) return FALSE;
493
+        if(!$this->_checkCode()) return FALSE;
494
+        $f=preg_split("/[".CRLF."]+/", preg_replace("/[0-9]{3}[ -].*[".CRLF."]+/", "", $this->_message), -1, PREG_SPLIT_NO_EMPTY);
495
+        $this->_features=array();
496
+        foreach($f as $k=>$v) {
497
+            $v=explode(" ", trim($v));
498
+            $this->_features[array_shift($v)]=$v;
499
+        }
500
+        return true;
501
+    }
502
+
503
+    function rawlist($pathname="", $arg="") {
504
+        return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist");
505
+    }
506
+
507
+    function nlist($pathname="", $arg="") {
508
+        return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
509
+    }
510
+
511
+    function is_exists($pathname) {
512
+        return $this->file_exists($pathname);
513
+    }
514
+
515
+    function file_exists($pathname) {
516
+        $exists=true;
517
+        if(!$this->_exec("RNFR ".$pathname, "rename")) $exists=FALSE;
518
+        else {
519
+            if(!$this->_checkCode()) $exists=FALSE;
520
+            $this->abort();
521
+        }
522
+        if($exists) $this->SendMSG("Remote file ".$pathname." exists");
523
+        else $this->SendMSG("Remote file ".$pathname." does not exist");
524
+        return $exists;
525
+    }
526
+
527
+    function fget($fp, $remotefile, $rest=0) {
528
+        if($this->_can_restore and $rest!=0) fseek($fp, $rest);
529
+        $pi=pathinfo($remotefile);
530
+        if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
531
+        else $mode=FTP_BINARY;
532
+        if(!$this->_data_prepare($mode)) {
533
+            return FALSE;
534
+        }
535
+        if($this->_can_restore and $rest!=0) $this->restore($rest);
536
+        if(!$this->_exec("RETR ".$remotefile, "get")) {
537
+            $this->_data_close();
538
+            return FALSE;
539
+        }
540
+        if(!$this->_checkCode()) {
541
+            $this->_data_close();
542
+            return FALSE;
543
+        }
544
+        $out=$this->_data_read($mode, $fp);
545
+        $this->_data_close();
546
+        if(!$this->_readmsg()) return FALSE;
547
+        if(!$this->_checkCode()) return FALSE;
548
+        return $out;
549
+    }
550
+
551
+    function get($remotefile, $localfile=NULL, $rest=0) {
552
+        if(is_null($localfile)) $localfile=$remotefile;
553
+        if (@file_exists($localfile)) $this->SendMSG("Warning : local file will be overwritten");
554
+        $fp = @fopen($localfile, "w");
555
+        if (!$fp) {
556
+            $this->PushError("get","cannot open local file", "Cannot create \"".$localfile."\"");
557
+            return FALSE;
558
+        }
559
+        if($this->_can_restore and $rest!=0) fseek($fp, $rest);
560
+        $pi=pathinfo($remotefile);
561
+        if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
562
+        else $mode=FTP_BINARY;
563
+        if(!$this->_data_prepare($mode)) {
564
+            fclose($fp);
565
+            return FALSE;
566
+        }
567
+        if($this->_can_restore and $rest!=0) $this->restore($rest);
568
+        if(!$this->_exec("RETR ".$remotefile, "get")) {
569
+            $this->_data_close();
570
+            fclose($fp);
571
+            return FALSE;
572
+        }
573
+        if(!$this->_checkCode()) {
574
+            $this->_data_close();
575
+            fclose($fp);
576
+            return FALSE;
577
+        }
578
+        $out=$this->_data_read($mode, $fp);
579
+        fclose($fp);
580
+        $this->_data_close();
581
+        if(!$this->_readmsg()) return FALSE;
582
+        if(!$this->_checkCode()) return FALSE;
583
+        return $out;
584
+    }
585
+
586
+    function fput($remotefile, $fp, $rest=0) {
587
+        if($this->_can_restore and $rest!=0) fseek($fp, $rest);
588
+        $pi=pathinfo($remotefile);
589
+        if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
590
+        else $mode=FTP_BINARY;
591
+        if(!$this->_data_prepare($mode)) {
592
+            return FALSE;
593
+        }
594
+        if($this->_can_restore and $rest!=0) $this->restore($rest);
595
+        if(!$this->_exec("STOR ".$remotefile, "put")) {
596
+            $this->_data_close();
597
+            return FALSE;
598
+        }
599
+        if(!$this->_checkCode()) {
600
+            $this->_data_close();
601
+            return FALSE;
602
+        }
603
+        $ret=$this->_data_write($mode, $fp);
604
+        $this->_data_close();
605
+        if(!$this->_readmsg()) return FALSE;
606
+        if(!$this->_checkCode()) return FALSE;
607
+        return $ret;
608
+    }
609
+
610
+    function put($localfile, $remotefile=NULL, $rest=0) {
611
+        if(is_null($remotefile)) $remotefile=$localfile;
612
+        if (!file_exists($localfile)) {
613
+            $this->PushError("put","cannot open local file", "No such file or directory \"".$localfile."\"");
614
+            return FALSE;
615
+        }
616
+        $fp = @fopen($localfile, "r");
617
+
618
+        if (!$fp) {
619
+            $this->PushError("put","cannot open local file", "Cannot read file \"".$localfile."\"");
620
+            return FALSE;
621
+        }
622
+        if($this->_can_restore and $rest!=0) fseek($fp, $rest);
623
+        $pi=pathinfo($localfile);
624
+        if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
625
+        else $mode=FTP_BINARY;
626
+        if(!$this->_data_prepare($mode)) {
627
+            fclose($fp);
628
+            return FALSE;
629
+        }
630
+        if($this->_can_restore and $rest!=0) $this->restore($rest);
631
+        if(!$this->_exec("STOR ".$remotefile, "put")) {
632
+            $this->_data_close();
633
+            fclose($fp);
634
+            return FALSE;
635
+        }
636
+        if(!$this->_checkCode()) {
637
+            $this->_data_close();
638
+            fclose($fp);
639
+            return FALSE;
640
+        }
641
+        $ret=$this->_data_write($mode, $fp);
642
+        fclose($fp);
643
+        $this->_data_close();
644
+        if(!$this->_readmsg()) return FALSE;
645
+        if(!$this->_checkCode()) return FALSE;
646
+        return $ret;
647
+    }
648
+
649
+    function mput($local=".", $remote=NULL, $continious=false) {
650
+        $local=realpath($local);
651
+        if(!@file_exists($local)) {
652
+            $this->PushError("mput","cannot open local folder", "Cannot stat folder \"".$local."\"");
653
+            return FALSE;
654
+        }
655
+        if(!is_dir($local)) return $this->put($local, $remote);
656
+        if(empty($remote)) $remote=".";
657
+        elseif(!$this->file_exists($remote) and !$this->mkdir($remote)) return FALSE;
658
+        if($handle = opendir($local)) {
659
+            $list=array();
660
+            while (false !== ($file = readdir($handle))) {
661
+                if ($file != "." && $file != "..") $list[]=$file;
662
+            }
663
+            closedir($handle);
664
+        } else {
665
+            $this->PushError("mput","cannot open local folder", "Cannot read folder \"".$local."\"");
666
+            return FALSE;
667
+        }
668
+        if(empty($list)) return TRUE;
669
+        $ret=true;
670
+        foreach($list as $el) {
671
+            if(is_dir($local."/".$el)) $t=$this->mput($local."/".$el, $remote."/".$el);
672
+            else $t=$this->put($local."/".$el, $remote."/".$el);
673
+            if(!$t) {
674
+                $ret=FALSE;
675
+                if(!$continious) break;
676
+            }
677
+        }
678
+        return $ret;
679
+
680
+    }
681
+
682
+    function mget($remote, $local=".", $continious=false) {
683
+        $list=$this->rawlist($remote, "-lA");
684
+        if($list===false) {
685
+            $this->PushError("mget","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents");
686
+            return FALSE;
687
+        }
688
+        if(empty($list)) return true;
689
+        if(!@file_exists($local)) {
690
+            if(!@mkdir($local)) {
691
+                $this->PushError("mget","cannot create local folder", "Cannot create folder \"".$local."\"");
692
+                return FALSE;
693
+            }
694
+        }
695
+        foreach($list as $k=>$v) {
696
+            $list[$k]=$this->parselisting($v);
697
+            if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
698
+        }
699
+        $ret=true;
700
+        foreach($list as $el) {
701
+            if($el["type"]=="d") {
702
+                if(!$this->mget($remote."/".$el["name"], $local."/".$el["name"], $continious)) {
703
+                    $this->PushError("mget", "cannot copy folder", "Cannot copy remote folder \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
704
+                    $ret=false;
705
+                    if(!$continious) break;
706
+                }
707
+            } else {
708
+                if(!$this->get($remote."/".$el["name"], $local."/".$el["name"])) {
709
+                    $this->PushError("mget", "cannot copy file", "Cannot copy remote file \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
710
+                    $ret=false;
711
+                    if(!$continious) break;
712
+                }
713
+            }
714
+            @chmod($local."/".$el["name"], $el["perms"]);
715
+            $t=strtotime($el["date"]);
716
+            if($t!==-1 and $t!==false) @touch($local."/".$el["name"], $t);
717
+        }
718
+        return $ret;
719
+    }
720
+
721
+    function mdel($remote, $continious=false) {
722
+        $list=$this->rawlist($remote, "-la");
723
+        if($list===false) {
724
+            $this->PushError("mdel","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents");
725
+            return false;
726
+        }
727
+
728
+        foreach($list as $k=>$v) {
729
+            $list[$k]=$this->parselisting($v);
730
+            if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
731
+        }
732
+        $ret=true;
733
+
734
+        foreach($list as $el) {
735
+            if ( empty($el) )
736
+                continue;
737
+
738
+            if($el["type"]=="d") {
739
+                if(!$this->mdel($remote."/".$el["name"], $continious)) {
740
+                    $ret=false;
741
+                    if(!$continious) break;
742
+                }
743
+            } else {
744
+                if (!$this->delete($remote."/".$el["name"])) {
745
+                    $this->PushError("mdel", "cannot delete file", "Cannot delete remote file \"".$remote."/".$el["name"]."\"");
746
+                    $ret=false;
747
+                    if(!$continious) break;
748
+                }
749
+            }
750
+        }
751
+
752
+        if(!$this->rmdir($remote)) {
753
+            $this->PushError("mdel", "cannot delete folder", "Cannot delete remote folder \"".$remote."/".$el["name"]."\"");
754
+            $ret=false;
755
+        }
756
+        return $ret;
757
+    }
758
+
759
+    function mmkdir($dir, $mode = 0777) {
760
+        if(empty($dir)) return FALSE;
761
+        if($this->is_exists($dir) or $dir == "/" ) return TRUE;
762
+        if(!$this->mmkdir(dirname($dir), $mode)) return false;
763
+        $r=$this->mkdir($dir, $mode);
764
+        $this->chmod($dir,$mode);
765
+        return $r;
766
+    }
767
+
768
+    function glob($pattern, $handle=NULL) {
769
+        $path=$output=null;
770
+        if(PHP_OS=='WIN32') $slash='\\';
771
+        else $slash='/';
772
+        $lastpos=strrpos($pattern,$slash);
773
+        if(!($lastpos===false)) {
774
+            $path=substr($pattern,0,-$lastpos-1);
775
+            $pattern=substr($pattern,$lastpos);
776
+        } else $path=getcwd();
777
+        if(is_array($handle) and !empty($handle)) {
778
+            foreach($handle as $dir) {
779
+                if($this->glob_pattern_match($pattern,$dir))
780
+                $output[]=$dir;
781
+            }
782
+        } else {
783
+            $handle=@opendir($path);
784
+            if($handle===false) return false;
785
+            while($dir=readdir($handle)) {
786
+                if($this->glob_pattern_match($pattern,$dir))
787
+                $output[]=$dir;
788
+            }
789
+            closedir($handle);
790
+        }
791
+        if(is_array($output)) return $output;
792
+        return false;
793
+    }
794
+
795
+    function glob_pattern_match($pattern,$subject) {
796
+        $out=null;
797
+        $chunks=explode(';',$pattern);
798
+        foreach($chunks as $pattern) {
799
+            $escape=array('$','^','.','{','}','(',')','[',']','|');
800
+            while(strpos($pattern,'**')!==false)
801
+                $pattern=str_replace('**','*',$pattern);
802
+            foreach($escape as $probe)
803
+                $pattern=str_replace($probe,"\\$probe",$pattern);
804
+            $pattern=str_replace('?*','*',
805
+                str_replace('*?','*',
806
+                    str_replace('*',".*",
807
+                        str_replace('?','.{1,1}',$pattern))));
808
+            $out[]=$pattern;
809
+        }
810
+        if(count($out)==1) return($this->glob_regexp("^$out[0]$",$subject));
811
+        else {
812
+            foreach($out as $tester)
813
+                // TODO: This should probably be glob_regexp(), but needs tests.
814
+                if($this->my_regexp("^$tester$",$subject)) return true;
815
+        }
816
+        return false;
817
+    }
818
+
819
+    function glob_regexp($pattern,$subject) {
820
+        $sensitive=(PHP_OS!='WIN32');
821
+        return ($sensitive?
822
+            preg_match( '/' . preg_quote( $pattern, '/' ) . '/', $subject ) :
823
+            preg_match( '/' . preg_quote( $pattern, '/' ) . '/i', $subject )
824
+        );
825
+    }
826
+
827
+    function dirlist($remote) {
828
+        $list=$this->rawlist($remote, "-la");
829
+        if($list===false) {
830
+            $this->PushError("dirlist","cannot read remote folder list", "Cannot read remote folder \"".$remote."\" contents");
831
+            return false;
832
+        }
833
+
834
+        $dirlist = array();
835
+        foreach($list as $k=>$v) {
836
+            $entry=$this->parselisting($v);
837
+            if ( empty($entry) )
838
+                continue;
839
+
840
+            if($entry["name"]=="." or $entry["name"]=="..")
841
+                continue;
842
+
843
+            $dirlist[$entry['name']] = $entry;
844
+        }
845
+
846
+        return $dirlist;
847
+    }
848 848
 // <!-- --------------------------------------------------------------------------------------- -->
849 849
 // <!--       Private functions                                                                 -->
850 850
 // <!-- --------------------------------------------------------------------------------------- -->
851
-	function _checkCode() {
852
-		return ($this->_code<400 and $this->_code>0);
853
-	}
854
-
855
-	function _list($arg="", $cmd="LIST", $fnction="_list") {
856
-		if(!$this->_data_prepare()) return false;
857
-		if(!$this->_exec($cmd.$arg, $fnction)) {
858
-			$this->_data_close();
859
-			return FALSE;
860
-		}
861
-		if(!$this->_checkCode()) {
862
-			$this->_data_close();
863
-			return FALSE;
864
-		}
865
-		$out="";
866
-		if($this->_code<200) {
867
-			$out=$this->_data_read();
868
-			$this->_data_close();
869
-			if(!$this->_readmsg()) return FALSE;
870
-			if(!$this->_checkCode()) return FALSE;
871
-			if($out === FALSE ) return FALSE;
872
-			$out=preg_split("/[".CRLF."]+/", $out, -1, PREG_SPLIT_NO_EMPTY);
851
+    function _checkCode() {
852
+        return ($this->_code<400 and $this->_code>0);
853
+    }
854
+
855
+    function _list($arg="", $cmd="LIST", $fnction="_list") {
856
+        if(!$this->_data_prepare()) return false;
857
+        if(!$this->_exec($cmd.$arg, $fnction)) {
858
+            $this->_data_close();
859
+            return FALSE;
860
+        }
861
+        if(!$this->_checkCode()) {
862
+            $this->_data_close();
863
+            return FALSE;
864
+        }
865
+        $out="";
866
+        if($this->_code<200) {
867
+            $out=$this->_data_read();
868
+            $this->_data_close();
869
+            if(!$this->_readmsg()) return FALSE;
870
+            if(!$this->_checkCode()) return FALSE;
871
+            if($out === FALSE ) return FALSE;
872
+            $out=preg_split("/[".CRLF."]+/", $out, -1, PREG_SPLIT_NO_EMPTY);
873 873
 //			$this->SendMSG(implode($this->_eol_code[$this->OS_local], $out));
874
-		}
875
-		return $out;
876
-	}
874
+        }
875
+        return $out;
876
+    }
877 877
 
878 878
 // <!-- --------------------------------------------------------------------------------------- -->
879 879
 // <!-- Partie : gestion des erreurs                                                            -->
880 880
 // <!-- --------------------------------------------------------------------------------------- -->
881 881
 // Gnre une erreur pour traitement externe  la classe
882
-	function PushError($fctname,$msg,$desc=false){
883
-		$error=array();
884
-		$error['time']=time();
885
-		$error['fctname']=$fctname;
886
-		$error['msg']=$msg;
887
-		$error['desc']=$desc;
888
-		if($desc) $tmp=' ('.$desc.')'; else $tmp='';
889
-		$this->SendMSG($fctname.': '.$msg.$tmp);
890
-		return(array_push($this->_error_array,$error));
891
-	}
882
+    function PushError($fctname,$msg,$desc=false){
883
+        $error=array();
884
+        $error['time']=time();
885
+        $error['fctname']=$fctname;
886
+        $error['msg']=$msg;
887
+        $error['desc']=$desc;
888
+        if($desc) $tmp=' ('.$desc.')'; else $tmp='';
889
+        $this->SendMSG($fctname.': '.$msg.$tmp);
890
+        return(array_push($this->_error_array,$error));
891
+    }
892 892
 
893 893
 // Rcupre une erreur externe
894
-	function PopError(){
895
-		if(count($this->_error_array)) return(array_pop($this->_error_array));
896
-			else return(false);
897
-	}
894
+    function PopError(){
895
+        if(count($this->_error_array)) return(array_pop($this->_error_array));
896
+            else return(false);
897
+    }
898 898
 }
899 899
 
900 900
 $mod_sockets = extension_loaded( 'sockets' );
901 901
 if ( ! $mod_sockets && function_exists( 'dl' ) && is_callable( 'dl' ) ) {
902
-	$prefix = ( PHP_SHLIB_SUFFIX == 'dll' ) ? 'php_' : '';
903
-	@dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX ); // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.dlDeprecated
904
-	$mod_sockets = extension_loaded( 'sockets' );
902
+    $prefix = ( PHP_SHLIB_SUFFIX == 'dll' ) ? 'php_' : '';
903
+    @dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX ); // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.dlDeprecated
904
+    $mod_sockets = extension_loaded( 'sockets' );
905 905
 }
906 906
 
907 907
 require_once __DIR__ . "/class-ftp-" . ( $mod_sockets ? "sockets" : "pure" ) . ".php";
908 908
 
909 909
 if ( $mod_sockets ) {
910
-	class ftp extends ftp_sockets {}
910
+    class ftp extends ftp_sockets {}
911 911
 } else {
912
-	class ftp extends ftp_pure {}
912
+    class ftp extends ftp_pure {}
913 913
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/post.php 1 patch
Indentation   +1836 added lines, -1836 removed lines patch added patch discarded remove patch
@@ -20,188 +20,188 @@  discard block
 block discarded – undo
20 20
  */
21 21
 function _wp_translate_postdata( $update = false, $post_data = null ) {
22 22
 
23
-	if ( empty( $post_data ) ) {
24
-		$post_data = &$_POST;
25
-	}
26
-
27
-	if ( $update ) {
28
-		$post_data['ID'] = (int) $post_data['post_ID'];
29
-	}
30
-
31
-	$ptype = get_post_type_object( $post_data['post_type'] );
32
-
33
-	if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
34
-		if ( 'page' === $post_data['post_type'] ) {
35
-			return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
36
-		} else {
37
-			return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
38
-		}
39
-	} elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) {
40
-		if ( 'page' === $post_data['post_type'] ) {
41
-			return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
42
-		} else {
43
-			return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
44
-		}
45
-	}
46
-
47
-	if ( isset( $post_data['content'] ) ) {
48
-		$post_data['post_content'] = $post_data['content'];
49
-	}
50
-
51
-	if ( isset( $post_data['excerpt'] ) ) {
52
-		$post_data['post_excerpt'] = $post_data['excerpt'];
53
-	}
54
-
55
-	if ( isset( $post_data['parent_id'] ) ) {
56
-		$post_data['post_parent'] = (int) $post_data['parent_id'];
57
-	}
58
-
59
-	if ( isset( $post_data['trackback_url'] ) ) {
60
-		$post_data['to_ping'] = $post_data['trackback_url'];
61
-	}
62
-
63
-	$post_data['user_ID'] = get_current_user_id();
64
-
65
-	if ( ! empty( $post_data['post_author_override'] ) ) {
66
-		$post_data['post_author'] = (int) $post_data['post_author_override'];
67
-	} else {
68
-		if ( ! empty( $post_data['post_author'] ) ) {
69
-			$post_data['post_author'] = (int) $post_data['post_author'];
70
-		} else {
71
-			$post_data['post_author'] = (int) $post_data['user_ID'];
72
-		}
73
-	}
74
-
75
-	if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] != $post_data['user_ID'] )
76
-		&& ! current_user_can( $ptype->cap->edit_others_posts ) ) {
77
-
78
-		if ( $update ) {
79
-			if ( 'page' === $post_data['post_type'] ) {
80
-				return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
81
-			} else {
82
-				return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
83
-			}
84
-		} else {
85
-			if ( 'page' === $post_data['post_type'] ) {
86
-				return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
87
-			} else {
88
-				return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
89
-			}
90
-		}
91
-	}
92
-
93
-	if ( ! empty( $post_data['post_status'] ) ) {
94
-		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
95
-
96
-		// No longer an auto-draft.
97
-		if ( 'auto-draft' === $post_data['post_status'] ) {
98
-			$post_data['post_status'] = 'draft';
99
-		}
100
-
101
-		if ( ! get_post_status_object( $post_data['post_status'] ) ) {
102
-			unset( $post_data['post_status'] );
103
-		}
104
-	}
105
-
106
-	// What to do based on which button they pressed.
107
-	if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) {
108
-		$post_data['post_status'] = 'draft';
109
-	}
110
-	if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) {
111
-		$post_data['post_status'] = 'private';
112
-	}
113
-	if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] )
114
-		&& ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] )
115
-	) {
116
-		$post_data['post_status'] = 'publish';
117
-	}
118
-	if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) {
119
-		$post_data['post_status'] = 'draft';
120
-	}
121
-	if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) {
122
-		$post_data['post_status'] = 'pending';
123
-	}
124
-
125
-	if ( isset( $post_data['ID'] ) ) {
126
-		$post_id = $post_data['ID'];
127
-	} else {
128
-		$post_id = false;
129
-	}
130
-	$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
131
-
132
-	if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
133
-		$post_data['post_status'] = $previous_status ? $previous_status : 'pending';
134
-	}
135
-
136
-	$published_statuses = array( 'publish', 'future' );
137
-
138
-	// Posts 'submitted for approval' are submitted to $_POST the same as if they were being published.
139
-	// Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
140
-	if ( isset( $post_data['post_status'] )
141
-		&& ( in_array( $post_data['post_status'], $published_statuses, true )
142
-		&& ! current_user_can( $ptype->cap->publish_posts ) )
143
-	) {
144
-		if ( ! in_array( $previous_status, $published_statuses, true ) || ! current_user_can( 'edit_post', $post_id ) ) {
145
-			$post_data['post_status'] = 'pending';
146
-		}
147
-	}
148
-
149
-	if ( ! isset( $post_data['post_status'] ) ) {
150
-		$post_data['post_status'] = 'auto-draft' === $previous_status ? 'draft' : $previous_status;
151
-	}
152
-
153
-	if ( isset( $post_data['post_password'] ) && ! current_user_can( $ptype->cap->publish_posts ) ) {
154
-		unset( $post_data['post_password'] );
155
-	}
156
-
157
-	if ( ! isset( $post_data['comment_status'] ) ) {
158
-		$post_data['comment_status'] = 'closed';
159
-	}
160
-
161
-	if ( ! isset( $post_data['ping_status'] ) ) {
162
-		$post_data['ping_status'] = 'closed';
163
-	}
164
-
165
-	foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
166
-		if ( ! empty( $post_data[ 'hidden_' . $timeunit ] ) && $post_data[ 'hidden_' . $timeunit ] != $post_data[ $timeunit ] ) {
167
-			$post_data['edit_date'] = '1';
168
-			break;
169
-		}
170
-	}
171
-
172
-	if ( ! empty( $post_data['edit_date'] ) ) {
173
-		$aa = $post_data['aa'];
174
-		$mm = $post_data['mm'];
175
-		$jj = $post_data['jj'];
176
-		$hh = $post_data['hh'];
177
-		$mn = $post_data['mn'];
178
-		$ss = $post_data['ss'];
179
-		$aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa;
180
-		$mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm;
181
-		$jj = ( $jj > 31 ) ? 31 : $jj;
182
-		$jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj;
183
-		$hh = ( $hh > 23 ) ? $hh - 24 : $hh;
184
-		$mn = ( $mn > 59 ) ? $mn - 60 : $mn;
185
-		$ss = ( $ss > 59 ) ? $ss - 60 : $ss;
186
-
187
-		$post_data['post_date'] = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss );
188
-
189
-		$valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
190
-		if ( ! $valid_date ) {
191
-			return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
192
-		}
193
-
194
-		$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
195
-	}
196
-
197
-	if ( isset( $post_data['post_category'] ) ) {
198
-		$category_object = get_taxonomy( 'category' );
199
-		if ( ! current_user_can( $category_object->cap->assign_terms ) ) {
200
-			unset( $post_data['post_category'] );
201
-		}
202
-	}
203
-
204
-	return $post_data;
23
+    if ( empty( $post_data ) ) {
24
+        $post_data = &$_POST;
25
+    }
26
+
27
+    if ( $update ) {
28
+        $post_data['ID'] = (int) $post_data['post_ID'];
29
+    }
30
+
31
+    $ptype = get_post_type_object( $post_data['post_type'] );
32
+
33
+    if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
34
+        if ( 'page' === $post_data['post_type'] ) {
35
+            return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
36
+        } else {
37
+            return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
38
+        }
39
+    } elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) {
40
+        if ( 'page' === $post_data['post_type'] ) {
41
+            return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
42
+        } else {
43
+            return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
44
+        }
45
+    }
46
+
47
+    if ( isset( $post_data['content'] ) ) {
48
+        $post_data['post_content'] = $post_data['content'];
49
+    }
50
+
51
+    if ( isset( $post_data['excerpt'] ) ) {
52
+        $post_data['post_excerpt'] = $post_data['excerpt'];
53
+    }
54
+
55
+    if ( isset( $post_data['parent_id'] ) ) {
56
+        $post_data['post_parent'] = (int) $post_data['parent_id'];
57
+    }
58
+
59
+    if ( isset( $post_data['trackback_url'] ) ) {
60
+        $post_data['to_ping'] = $post_data['trackback_url'];
61
+    }
62
+
63
+    $post_data['user_ID'] = get_current_user_id();
64
+
65
+    if ( ! empty( $post_data['post_author_override'] ) ) {
66
+        $post_data['post_author'] = (int) $post_data['post_author_override'];
67
+    } else {
68
+        if ( ! empty( $post_data['post_author'] ) ) {
69
+            $post_data['post_author'] = (int) $post_data['post_author'];
70
+        } else {
71
+            $post_data['post_author'] = (int) $post_data['user_ID'];
72
+        }
73
+    }
74
+
75
+    if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] != $post_data['user_ID'] )
76
+        && ! current_user_can( $ptype->cap->edit_others_posts ) ) {
77
+
78
+        if ( $update ) {
79
+            if ( 'page' === $post_data['post_type'] ) {
80
+                return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
81
+            } else {
82
+                return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
83
+            }
84
+        } else {
85
+            if ( 'page' === $post_data['post_type'] ) {
86
+                return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
87
+            } else {
88
+                return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
89
+            }
90
+        }
91
+    }
92
+
93
+    if ( ! empty( $post_data['post_status'] ) ) {
94
+        $post_data['post_status'] = sanitize_key( $post_data['post_status'] );
95
+
96
+        // No longer an auto-draft.
97
+        if ( 'auto-draft' === $post_data['post_status'] ) {
98
+            $post_data['post_status'] = 'draft';
99
+        }
100
+
101
+        if ( ! get_post_status_object( $post_data['post_status'] ) ) {
102
+            unset( $post_data['post_status'] );
103
+        }
104
+    }
105
+
106
+    // What to do based on which button they pressed.
107
+    if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) {
108
+        $post_data['post_status'] = 'draft';
109
+    }
110
+    if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) {
111
+        $post_data['post_status'] = 'private';
112
+    }
113
+    if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] )
114
+        && ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] )
115
+    ) {
116
+        $post_data['post_status'] = 'publish';
117
+    }
118
+    if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) {
119
+        $post_data['post_status'] = 'draft';
120
+    }
121
+    if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) {
122
+        $post_data['post_status'] = 'pending';
123
+    }
124
+
125
+    if ( isset( $post_data['ID'] ) ) {
126
+        $post_id = $post_data['ID'];
127
+    } else {
128
+        $post_id = false;
129
+    }
130
+    $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
131
+
132
+    if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
133
+        $post_data['post_status'] = $previous_status ? $previous_status : 'pending';
134
+    }
135
+
136
+    $published_statuses = array( 'publish', 'future' );
137
+
138
+    // Posts 'submitted for approval' are submitted to $_POST the same as if they were being published.
139
+    // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
140
+    if ( isset( $post_data['post_status'] )
141
+        && ( in_array( $post_data['post_status'], $published_statuses, true )
142
+        && ! current_user_can( $ptype->cap->publish_posts ) )
143
+    ) {
144
+        if ( ! in_array( $previous_status, $published_statuses, true ) || ! current_user_can( 'edit_post', $post_id ) ) {
145
+            $post_data['post_status'] = 'pending';
146
+        }
147
+    }
148
+
149
+    if ( ! isset( $post_data['post_status'] ) ) {
150
+        $post_data['post_status'] = 'auto-draft' === $previous_status ? 'draft' : $previous_status;
151
+    }
152
+
153
+    if ( isset( $post_data['post_password'] ) && ! current_user_can( $ptype->cap->publish_posts ) ) {
154
+        unset( $post_data['post_password'] );
155
+    }
156
+
157
+    if ( ! isset( $post_data['comment_status'] ) ) {
158
+        $post_data['comment_status'] = 'closed';
159
+    }
160
+
161
+    if ( ! isset( $post_data['ping_status'] ) ) {
162
+        $post_data['ping_status'] = 'closed';
163
+    }
164
+
165
+    foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
166
+        if ( ! empty( $post_data[ 'hidden_' . $timeunit ] ) && $post_data[ 'hidden_' . $timeunit ] != $post_data[ $timeunit ] ) {
167
+            $post_data['edit_date'] = '1';
168
+            break;
169
+        }
170
+    }
171
+
172
+    if ( ! empty( $post_data['edit_date'] ) ) {
173
+        $aa = $post_data['aa'];
174
+        $mm = $post_data['mm'];
175
+        $jj = $post_data['jj'];
176
+        $hh = $post_data['hh'];
177
+        $mn = $post_data['mn'];
178
+        $ss = $post_data['ss'];
179
+        $aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa;
180
+        $mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm;
181
+        $jj = ( $jj > 31 ) ? 31 : $jj;
182
+        $jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj;
183
+        $hh = ( $hh > 23 ) ? $hh - 24 : $hh;
184
+        $mn = ( $mn > 59 ) ? $mn - 60 : $mn;
185
+        $ss = ( $ss > 59 ) ? $ss - 60 : $ss;
186
+
187
+        $post_data['post_date'] = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss );
188
+
189
+        $valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
190
+        if ( ! $valid_date ) {
191
+            return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
192
+        }
193
+
194
+        $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
195
+    }
196
+
197
+    if ( isset( $post_data['post_category'] ) ) {
198
+        $category_object = get_taxonomy( 'category' );
199
+        if ( ! current_user_can( $category_object->cap->assign_terms ) ) {
200
+            unset( $post_data['post_category'] );
201
+        }
202
+    }
203
+
204
+    return $post_data;
205 205
 }
206 206
 
207 207
 /**
@@ -214,16 +214,16 @@  discard block
 block discarded – undo
214 214
  * @return array|WP_Error Array of post data on success, WP_Error on failure.
215 215
  */
216 216
 function _wp_get_allowed_postdata( $post_data = null ) {
217
-	if ( empty( $post_data ) ) {
218
-		$post_data = $_POST;
219
-	}
217
+    if ( empty( $post_data ) ) {
218
+        $post_data = $_POST;
219
+    }
220 220
 
221
-	// Pass through errors.
222
-	if ( is_wp_error( $post_data ) ) {
223
-		return $post_data;
224
-	}
221
+    // Pass through errors.
222
+    if ( is_wp_error( $post_data ) ) {
223
+        return $post_data;
224
+    }
225 225
 
226
-	return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
226
+    return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
227 227
 }
228 228
 
229 229
 /**
@@ -243,215 +243,215 @@  discard block
 block discarded – undo
243 243
  * @return int Post ID.
244 244
  */
245 245
 function edit_post( $post_data = null ) {
246
-	global $wpdb;
247
-
248
-	if ( empty( $post_data ) ) {
249
-		$post_data = &$_POST;
250
-	}
251
-
252
-	// Clear out any data in internal vars.
253
-	unset( $post_data['filter'] );
254
-
255
-	$post_ID = (int) $post_data['post_ID'];
256
-	$post    = get_post( $post_ID );
257
-
258
-	$post_data['post_type']      = $post->post_type;
259
-	$post_data['post_mime_type'] = $post->post_mime_type;
260
-
261
-	if ( ! empty( $post_data['post_status'] ) ) {
262
-		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
263
-
264
-		if ( 'inherit' === $post_data['post_status'] ) {
265
-			unset( $post_data['post_status'] );
266
-		}
267
-	}
268
-
269
-	$ptype = get_post_type_object( $post_data['post_type'] );
270
-	if ( ! current_user_can( 'edit_post', $post_ID ) ) {
271
-		if ( 'page' === $post_data['post_type'] ) {
272
-			wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
273
-		} else {
274
-			wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
275
-		}
276
-	}
277
-
278
-	if ( post_type_supports( $ptype->name, 'revisions' ) ) {
279
-		$revisions = wp_get_post_revisions(
280
-			$post_ID,
281
-			array(
282
-				'order'          => 'ASC',
283
-				'posts_per_page' => 1,
284
-			)
285
-		);
286
-		$revision  = current( $revisions );
287
-
288
-		// Check if the revisions have been upgraded.
289
-		if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) {
290
-			_wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) );
291
-		}
292
-	}
293
-
294
-	if ( isset( $post_data['visibility'] ) ) {
295
-		switch ( $post_data['visibility'] ) {
296
-			case 'public':
297
-				$post_data['post_password'] = '';
298
-				break;
299
-			case 'password':
300
-				unset( $post_data['sticky'] );
301
-				break;
302
-			case 'private':
303
-				$post_data['post_status']   = 'private';
304
-				$post_data['post_password'] = '';
305
-				unset( $post_data['sticky'] );
306
-				break;
307
-		}
308
-	}
309
-
310
-	$post_data = _wp_translate_postdata( true, $post_data );
311
-	if ( is_wp_error( $post_data ) ) {
312
-		wp_die( $post_data->get_error_message() );
313
-	}
314
-	$translated = _wp_get_allowed_postdata( $post_data );
315
-
316
-	// Post formats.
317
-	if ( isset( $post_data['post_format'] ) ) {
318
-		set_post_format( $post_ID, $post_data['post_format'] );
319
-	}
320
-
321
-	$format_meta_urls = array( 'url', 'link_url', 'quote_source_url' );
322
-	foreach ( $format_meta_urls as $format_meta_url ) {
323
-		$keyed = '_format_' . $format_meta_url;
324
-		if ( isset( $post_data[ $keyed ] ) ) {
325
-			update_post_meta( $post_ID, $keyed, wp_slash( esc_url_raw( wp_unslash( $post_data[ $keyed ] ) ) ) );
326
-		}
327
-	}
328
-
329
-	$format_keys = array( 'quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed' );
330
-
331
-	foreach ( $format_keys as $key ) {
332
-		$keyed = '_format_' . $key;
333
-		if ( isset( $post_data[ $keyed ] ) ) {
334
-			if ( current_user_can( 'unfiltered_html' ) ) {
335
-				update_post_meta( $post_ID, $keyed, $post_data[ $keyed ] );
336
-			} else {
337
-				update_post_meta( $post_ID, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) );
338
-			}
339
-		}
340
-	}
341
-
342
-	if ( 'attachment' === $post_data['post_type'] && preg_match( '#^(audio|video)/#', $post_data['post_mime_type'] ) ) {
343
-		$id3data = wp_get_attachment_metadata( $post_ID );
344
-		if ( ! is_array( $id3data ) ) {
345
-			$id3data = array();
346
-		}
347
-
348
-		foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) {
349
-			if ( isset( $post_data[ 'id3_' . $key ] ) ) {
350
-				$id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) );
351
-			}
352
-		}
353
-		wp_update_attachment_metadata( $post_ID, $id3data );
354
-	}
355
-
356
-	// Meta stuff.
357
-	if ( isset( $post_data['meta'] ) && $post_data['meta'] ) {
358
-		foreach ( $post_data['meta'] as $key => $value ) {
359
-			$meta = get_post_meta_by_id( $key );
360
-			if ( ! $meta ) {
361
-				continue;
362
-			}
363
-			if ( $meta->post_id != $post_ID ) {
364
-				continue;
365
-			}
366
-			if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $meta->meta_key ) ) {
367
-				continue;
368
-			}
369
-			if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) ) {
370
-				continue;
371
-			}
372
-			update_meta( $key, $value['key'], $value['value'] );
373
-		}
374
-	}
375
-
376
-	if ( isset( $post_data['deletemeta'] ) && $post_data['deletemeta'] ) {
377
-		foreach ( $post_data['deletemeta'] as $key => $value ) {
378
-			$meta = get_post_meta_by_id( $key );
379
-			if ( ! $meta ) {
380
-				continue;
381
-			}
382
-			if ( $meta->post_id != $post_ID ) {
383
-				continue;
384
-			}
385
-			if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_ID, $meta->meta_key ) ) {
386
-				continue;
387
-			}
388
-			delete_meta( $key );
389
-		}
390
-	}
391
-
392
-	// Attachment stuff.
393
-	if ( 'attachment' === $post_data['post_type'] ) {
394
-		if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
395
-			$image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
396
-
397
-			if ( get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) !== $image_alt ) {
398
-				$image_alt = wp_strip_all_tags( $image_alt, true );
399
-
400
-				// update_post_meta() expects slashed.
401
-				update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
402
-			}
403
-		}
404
-
405
-		$attachment_data = isset( $post_data['attachments'][ $post_ID ] ) ? $post_data['attachments'][ $post_ID ] : array();
406
-
407
-		/** This filter is documented in wp-admin/includes/media.php */
408
-		$translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data );
409
-	}
410
-
411
-	// Convert taxonomy input to term IDs, to avoid ambiguity.
412
-	if ( isset( $post_data['tax_input'] ) ) {
413
-		foreach ( (array) $post_data['tax_input'] as $taxonomy => $terms ) {
414
-			$tax_object = get_taxonomy( $taxonomy );
415
-
416
-			if ( $tax_object && isset( $tax_object->meta_box_sanitize_cb ) ) {
417
-				$translated['tax_input'][ $taxonomy ] = call_user_func_array( $tax_object->meta_box_sanitize_cb, array( $taxonomy, $terms ) );
418
-			}
419
-		}
420
-	}
421
-
422
-	add_meta( $post_ID );
423
-
424
-	update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
425
-
426
-	$success = wp_update_post( $translated );
427
-
428
-	// If the save failed, see if we can sanity check the main fields and try again.
429
-	if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
430
-		$fields = array( 'post_title', 'post_content', 'post_excerpt' );
431
-
432
-		foreach ( $fields as $field ) {
433
-			if ( isset( $translated[ $field ] ) ) {
434
-				$translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] );
435
-			}
436
-		}
437
-
438
-		wp_update_post( $translated );
439
-	}
440
-
441
-	// Now that we have an ID we can fix any attachment anchor hrefs.
442
-	_fix_attachment_links( $post_ID );
443
-
444
-	wp_set_post_lock( $post_ID );
445
-
446
-	if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) {
447
-		if ( ! empty( $post_data['sticky'] ) ) {
448
-			stick_post( $post_ID );
449
-		} else {
450
-			unstick_post( $post_ID );
451
-		}
452
-	}
453
-
454
-	return $post_ID;
246
+    global $wpdb;
247
+
248
+    if ( empty( $post_data ) ) {
249
+        $post_data = &$_POST;
250
+    }
251
+
252
+    // Clear out any data in internal vars.
253
+    unset( $post_data['filter'] );
254
+
255
+    $post_ID = (int) $post_data['post_ID'];
256
+    $post    = get_post( $post_ID );
257
+
258
+    $post_data['post_type']      = $post->post_type;
259
+    $post_data['post_mime_type'] = $post->post_mime_type;
260
+
261
+    if ( ! empty( $post_data['post_status'] ) ) {
262
+        $post_data['post_status'] = sanitize_key( $post_data['post_status'] );
263
+
264
+        if ( 'inherit' === $post_data['post_status'] ) {
265
+            unset( $post_data['post_status'] );
266
+        }
267
+    }
268
+
269
+    $ptype = get_post_type_object( $post_data['post_type'] );
270
+    if ( ! current_user_can( 'edit_post', $post_ID ) ) {
271
+        if ( 'page' === $post_data['post_type'] ) {
272
+            wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
273
+        } else {
274
+            wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
275
+        }
276
+    }
277
+
278
+    if ( post_type_supports( $ptype->name, 'revisions' ) ) {
279
+        $revisions = wp_get_post_revisions(
280
+            $post_ID,
281
+            array(
282
+                'order'          => 'ASC',
283
+                'posts_per_page' => 1,
284
+            )
285
+        );
286
+        $revision  = current( $revisions );
287
+
288
+        // Check if the revisions have been upgraded.
289
+        if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) {
290
+            _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) );
291
+        }
292
+    }
293
+
294
+    if ( isset( $post_data['visibility'] ) ) {
295
+        switch ( $post_data['visibility'] ) {
296
+            case 'public':
297
+                $post_data['post_password'] = '';
298
+                break;
299
+            case 'password':
300
+                unset( $post_data['sticky'] );
301
+                break;
302
+            case 'private':
303
+                $post_data['post_status']   = 'private';
304
+                $post_data['post_password'] = '';
305
+                unset( $post_data['sticky'] );
306
+                break;
307
+        }
308
+    }
309
+
310
+    $post_data = _wp_translate_postdata( true, $post_data );
311
+    if ( is_wp_error( $post_data ) ) {
312
+        wp_die( $post_data->get_error_message() );
313
+    }
314
+    $translated = _wp_get_allowed_postdata( $post_data );
315
+
316
+    // Post formats.
317
+    if ( isset( $post_data['post_format'] ) ) {
318
+        set_post_format( $post_ID, $post_data['post_format'] );
319
+    }
320
+
321
+    $format_meta_urls = array( 'url', 'link_url', 'quote_source_url' );
322
+    foreach ( $format_meta_urls as $format_meta_url ) {
323
+        $keyed = '_format_' . $format_meta_url;
324
+        if ( isset( $post_data[ $keyed ] ) ) {
325
+            update_post_meta( $post_ID, $keyed, wp_slash( esc_url_raw( wp_unslash( $post_data[ $keyed ] ) ) ) );
326
+        }
327
+    }
328
+
329
+    $format_keys = array( 'quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed' );
330
+
331
+    foreach ( $format_keys as $key ) {
332
+        $keyed = '_format_' . $key;
333
+        if ( isset( $post_data[ $keyed ] ) ) {
334
+            if ( current_user_can( 'unfiltered_html' ) ) {
335
+                update_post_meta( $post_ID, $keyed, $post_data[ $keyed ] );
336
+            } else {
337
+                update_post_meta( $post_ID, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) );
338
+            }
339
+        }
340
+    }
341
+
342
+    if ( 'attachment' === $post_data['post_type'] && preg_match( '#^(audio|video)/#', $post_data['post_mime_type'] ) ) {
343
+        $id3data = wp_get_attachment_metadata( $post_ID );
344
+        if ( ! is_array( $id3data ) ) {
345
+            $id3data = array();
346
+        }
347
+
348
+        foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) {
349
+            if ( isset( $post_data[ 'id3_' . $key ] ) ) {
350
+                $id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) );
351
+            }
352
+        }
353
+        wp_update_attachment_metadata( $post_ID, $id3data );
354
+    }
355
+
356
+    // Meta stuff.
357
+    if ( isset( $post_data['meta'] ) && $post_data['meta'] ) {
358
+        foreach ( $post_data['meta'] as $key => $value ) {
359
+            $meta = get_post_meta_by_id( $key );
360
+            if ( ! $meta ) {
361
+                continue;
362
+            }
363
+            if ( $meta->post_id != $post_ID ) {
364
+                continue;
365
+            }
366
+            if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $meta->meta_key ) ) {
367
+                continue;
368
+            }
369
+            if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) ) {
370
+                continue;
371
+            }
372
+            update_meta( $key, $value['key'], $value['value'] );
373
+        }
374
+    }
375
+
376
+    if ( isset( $post_data['deletemeta'] ) && $post_data['deletemeta'] ) {
377
+        foreach ( $post_data['deletemeta'] as $key => $value ) {
378
+            $meta = get_post_meta_by_id( $key );
379
+            if ( ! $meta ) {
380
+                continue;
381
+            }
382
+            if ( $meta->post_id != $post_ID ) {
383
+                continue;
384
+            }
385
+            if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_ID, $meta->meta_key ) ) {
386
+                continue;
387
+            }
388
+            delete_meta( $key );
389
+        }
390
+    }
391
+
392
+    // Attachment stuff.
393
+    if ( 'attachment' === $post_data['post_type'] ) {
394
+        if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
395
+            $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
396
+
397
+            if ( get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) !== $image_alt ) {
398
+                $image_alt = wp_strip_all_tags( $image_alt, true );
399
+
400
+                // update_post_meta() expects slashed.
401
+                update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
402
+            }
403
+        }
404
+
405
+        $attachment_data = isset( $post_data['attachments'][ $post_ID ] ) ? $post_data['attachments'][ $post_ID ] : array();
406
+
407
+        /** This filter is documented in wp-admin/includes/media.php */
408
+        $translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data );
409
+    }
410
+
411
+    // Convert taxonomy input to term IDs, to avoid ambiguity.
412
+    if ( isset( $post_data['tax_input'] ) ) {
413
+        foreach ( (array) $post_data['tax_input'] as $taxonomy => $terms ) {
414
+            $tax_object = get_taxonomy( $taxonomy );
415
+
416
+            if ( $tax_object && isset( $tax_object->meta_box_sanitize_cb ) ) {
417
+                $translated['tax_input'][ $taxonomy ] = call_user_func_array( $tax_object->meta_box_sanitize_cb, array( $taxonomy, $terms ) );
418
+            }
419
+        }
420
+    }
421
+
422
+    add_meta( $post_ID );
423
+
424
+    update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
425
+
426
+    $success = wp_update_post( $translated );
427
+
428
+    // If the save failed, see if we can sanity check the main fields and try again.
429
+    if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
430
+        $fields = array( 'post_title', 'post_content', 'post_excerpt' );
431
+
432
+        foreach ( $fields as $field ) {
433
+            if ( isset( $translated[ $field ] ) ) {
434
+                $translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] );
435
+            }
436
+        }
437
+
438
+        wp_update_post( $translated );
439
+    }
440
+
441
+    // Now that we have an ID we can fix any attachment anchor hrefs.
442
+    _fix_attachment_links( $post_ID );
443
+
444
+    wp_set_post_lock( $post_ID );
445
+
446
+    if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) {
447
+        if ( ! empty( $post_data['sticky'] ) ) {
448
+            stick_post( $post_ID );
449
+        } else {
450
+            unstick_post( $post_ID );
451
+        }
452
+    }
453
+
454
+    return $post_ID;
455 455
 }
456 456
 
457 457
 /**
@@ -469,199 +469,199 @@  discard block
 block discarded – undo
469 469
  * @return array
470 470
  */
471 471
 function bulk_edit_posts( $post_data = null ) {
472
-	global $wpdb;
473
-
474
-	if ( empty( $post_data ) ) {
475
-		$post_data = &$_POST;
476
-	}
477
-
478
-	if ( isset( $post_data['post_type'] ) ) {
479
-		$ptype = get_post_type_object( $post_data['post_type'] );
480
-	} else {
481
-		$ptype = get_post_type_object( 'post' );
482
-	}
483
-
484
-	if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
485
-		if ( 'page' === $ptype->name ) {
486
-			wp_die( __( 'Sorry, you are not allowed to edit pages.' ) );
487
-		} else {
488
-			wp_die( __( 'Sorry, you are not allowed to edit posts.' ) );
489
-		}
490
-	}
491
-
492
-	if ( -1 == $post_data['_status'] ) {
493
-		$post_data['post_status'] = null;
494
-		unset( $post_data['post_status'] );
495
-	} else {
496
-		$post_data['post_status'] = $post_data['_status'];
497
-	}
498
-	unset( $post_data['_status'] );
499
-
500
-	if ( ! empty( $post_data['post_status'] ) ) {
501
-		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
502
-
503
-		if ( 'inherit' === $post_data['post_status'] ) {
504
-			unset( $post_data['post_status'] );
505
-		}
506
-	}
507
-
508
-	$post_IDs = array_map( 'intval', (array) $post_data['post'] );
509
-
510
-	$reset = array(
511
-		'post_author',
512
-		'post_status',
513
-		'post_password',
514
-		'post_parent',
515
-		'page_template',
516
-		'comment_status',
517
-		'ping_status',
518
-		'keep_private',
519
-		'tax_input',
520
-		'post_category',
521
-		'sticky',
522
-		'post_format',
523
-	);
524
-
525
-	foreach ( $reset as $field ) {
526
-		if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
527
-			unset( $post_data[ $field ] );
528
-		}
529
-	}
530
-
531
-	if ( isset( $post_data['post_category'] ) ) {
532
-		if ( is_array( $post_data['post_category'] ) && ! empty( $post_data['post_category'] ) ) {
533
-			$new_cats = array_map( 'absint', $post_data['post_category'] );
534
-		} else {
535
-			unset( $post_data['post_category'] );
536
-		}
537
-	}
538
-
539
-	$tax_input = array();
540
-	if ( isset( $post_data['tax_input'] ) ) {
541
-		foreach ( $post_data['tax_input'] as $tax_name => $terms ) {
542
-			if ( empty( $terms ) ) {
543
-				continue;
544
-			}
545
-			if ( is_taxonomy_hierarchical( $tax_name ) ) {
546
-				$tax_input[ $tax_name ] = array_map( 'absint', $terms );
547
-			} else {
548
-				$comma = _x( ',', 'tag delimiter' );
549
-				if ( ',' !== $comma ) {
550
-					$terms = str_replace( $comma, ',', $terms );
551
-				}
552
-				$tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
553
-			}
554
-		}
555
-	}
556
-
557
-	if ( isset( $post_data['post_parent'] ) && (int) $post_data['post_parent'] ) {
558
-		$parent   = (int) $post_data['post_parent'];
559
-		$pages    = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'" );
560
-		$children = array();
561
-
562
-		for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
563
-			$children[] = $parent;
564
-
565
-			foreach ( $pages as $page ) {
566
-				if ( (int) $page->ID === $parent ) {
567
-					$parent = (int) $page->post_parent;
568
-					break;
569
-				}
570
-			}
571
-		}
572
-	}
573
-
574
-	$updated          = array();
575
-	$skipped          = array();
576
-	$locked           = array();
577
-	$shared_post_data = $post_data;
578
-
579
-	foreach ( $post_IDs as $post_ID ) {
580
-		// Start with fresh post data with each iteration.
581
-		$post_data = $shared_post_data;
582
-
583
-		$post_type_object = get_post_type_object( get_post_type( $post_ID ) );
584
-
585
-		if ( ! isset( $post_type_object )
586
-			|| ( isset( $children ) && in_array( $post_ID, $children, true ) )
587
-			|| ! current_user_can( 'edit_post', $post_ID )
588
-		) {
589
-			$skipped[] = $post_ID;
590
-			continue;
591
-		}
592
-
593
-		if ( wp_check_post_lock( $post_ID ) ) {
594
-			$locked[] = $post_ID;
595
-			continue;
596
-		}
597
-
598
-		$post      = get_post( $post_ID );
599
-		$tax_names = get_object_taxonomies( $post );
600
-		foreach ( $tax_names as $tax_name ) {
601
-			$taxonomy_obj = get_taxonomy( $tax_name );
602
-			if ( isset( $tax_input[ $tax_name ] ) && current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
603
-				$new_terms = $tax_input[ $tax_name ];
604
-			} else {
605
-				$new_terms = array();
606
-			}
607
-
608
-			if ( $taxonomy_obj->hierarchical ) {
609
-				$current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array( 'fields' => 'ids' ) );
610
-			} else {
611
-				$current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array( 'fields' => 'names' ) );
612
-			}
613
-
614
-			$post_data['tax_input'][ $tax_name ] = array_merge( $current_terms, $new_terms );
615
-		}
616
-
617
-		if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
618
-			$cats                       = (array) wp_get_post_categories( $post_ID );
619
-			$post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) );
620
-			unset( $post_data['tax_input']['category'] );
621
-		}
622
-
623
-		$post_data['post_ID']        = $post_ID;
624
-		$post_data['post_type']      = $post->post_type;
625
-		$post_data['post_mime_type'] = $post->post_mime_type;
626
-
627
-		foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) {
628
-			if ( ! isset( $post_data[ $field ] ) ) {
629
-				$post_data[ $field ] = $post->$field;
630
-			}
631
-		}
632
-
633
-		$post_data = _wp_translate_postdata( true, $post_data );
634
-		if ( is_wp_error( $post_data ) ) {
635
-			$skipped[] = $post_ID;
636
-			continue;
637
-		}
638
-		$post_data = _wp_get_allowed_postdata( $post_data );
639
-
640
-		if ( isset( $shared_post_data['post_format'] ) ) {
641
-			set_post_format( $post_ID, $shared_post_data['post_format'] );
642
-		}
643
-
644
-		// Prevent wp_insert_post() from overwriting post format with the old data.
645
-		unset( $post_data['tax_input']['post_format'] );
646
-
647
-		$post_id = wp_update_post( $post_data );
648
-		update_post_meta( $post_id, '_edit_last', get_current_user_id() );
649
-		$updated[] = $post_id;
650
-
651
-		if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
652
-			if ( 'sticky' === $post_data['sticky'] ) {
653
-				stick_post( $post_ID );
654
-			} else {
655
-				unstick_post( $post_ID );
656
-			}
657
-		}
658
-	}
659
-
660
-	return array(
661
-		'updated' => $updated,
662
-		'skipped' => $skipped,
663
-		'locked'  => $locked,
664
-	);
472
+    global $wpdb;
473
+
474
+    if ( empty( $post_data ) ) {
475
+        $post_data = &$_POST;
476
+    }
477
+
478
+    if ( isset( $post_data['post_type'] ) ) {
479
+        $ptype = get_post_type_object( $post_data['post_type'] );
480
+    } else {
481
+        $ptype = get_post_type_object( 'post' );
482
+    }
483
+
484
+    if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
485
+        if ( 'page' === $ptype->name ) {
486
+            wp_die( __( 'Sorry, you are not allowed to edit pages.' ) );
487
+        } else {
488
+            wp_die( __( 'Sorry, you are not allowed to edit posts.' ) );
489
+        }
490
+    }
491
+
492
+    if ( -1 == $post_data['_status'] ) {
493
+        $post_data['post_status'] = null;
494
+        unset( $post_data['post_status'] );
495
+    } else {
496
+        $post_data['post_status'] = $post_data['_status'];
497
+    }
498
+    unset( $post_data['_status'] );
499
+
500
+    if ( ! empty( $post_data['post_status'] ) ) {
501
+        $post_data['post_status'] = sanitize_key( $post_data['post_status'] );
502
+
503
+        if ( 'inherit' === $post_data['post_status'] ) {
504
+            unset( $post_data['post_status'] );
505
+        }
506
+    }
507
+
508
+    $post_IDs = array_map( 'intval', (array) $post_data['post'] );
509
+
510
+    $reset = array(
511
+        'post_author',
512
+        'post_status',
513
+        'post_password',
514
+        'post_parent',
515
+        'page_template',
516
+        'comment_status',
517
+        'ping_status',
518
+        'keep_private',
519
+        'tax_input',
520
+        'post_category',
521
+        'sticky',
522
+        'post_format',
523
+    );
524
+
525
+    foreach ( $reset as $field ) {
526
+        if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
527
+            unset( $post_data[ $field ] );
528
+        }
529
+    }
530
+
531
+    if ( isset( $post_data['post_category'] ) ) {
532
+        if ( is_array( $post_data['post_category'] ) && ! empty( $post_data['post_category'] ) ) {
533
+            $new_cats = array_map( 'absint', $post_data['post_category'] );
534
+        } else {
535
+            unset( $post_data['post_category'] );
536
+        }
537
+    }
538
+
539
+    $tax_input = array();
540
+    if ( isset( $post_data['tax_input'] ) ) {
541
+        foreach ( $post_data['tax_input'] as $tax_name => $terms ) {
542
+            if ( empty( $terms ) ) {
543
+                continue;
544
+            }
545
+            if ( is_taxonomy_hierarchical( $tax_name ) ) {
546
+                $tax_input[ $tax_name ] = array_map( 'absint', $terms );
547
+            } else {
548
+                $comma = _x( ',', 'tag delimiter' );
549
+                if ( ',' !== $comma ) {
550
+                    $terms = str_replace( $comma, ',', $terms );
551
+                }
552
+                $tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
553
+            }
554
+        }
555
+    }
556
+
557
+    if ( isset( $post_data['post_parent'] ) && (int) $post_data['post_parent'] ) {
558
+        $parent   = (int) $post_data['post_parent'];
559
+        $pages    = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'" );
560
+        $children = array();
561
+
562
+        for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
563
+            $children[] = $parent;
564
+
565
+            foreach ( $pages as $page ) {
566
+                if ( (int) $page->ID === $parent ) {
567
+                    $parent = (int) $page->post_parent;
568
+                    break;
569
+                }
570
+            }
571
+        }
572
+    }
573
+
574
+    $updated          = array();
575
+    $skipped          = array();
576
+    $locked           = array();
577
+    $shared_post_data = $post_data;
578
+
579
+    foreach ( $post_IDs as $post_ID ) {
580
+        // Start with fresh post data with each iteration.
581
+        $post_data = $shared_post_data;
582
+
583
+        $post_type_object = get_post_type_object( get_post_type( $post_ID ) );
584
+
585
+        if ( ! isset( $post_type_object )
586
+            || ( isset( $children ) && in_array( $post_ID, $children, true ) )
587
+            || ! current_user_can( 'edit_post', $post_ID )
588
+        ) {
589
+            $skipped[] = $post_ID;
590
+            continue;
591
+        }
592
+
593
+        if ( wp_check_post_lock( $post_ID ) ) {
594
+            $locked[] = $post_ID;
595
+            continue;
596
+        }
597
+
598
+        $post      = get_post( $post_ID );
599
+        $tax_names = get_object_taxonomies( $post );
600
+        foreach ( $tax_names as $tax_name ) {
601
+            $taxonomy_obj = get_taxonomy( $tax_name );
602
+            if ( isset( $tax_input[ $tax_name ] ) && current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
603
+                $new_terms = $tax_input[ $tax_name ];
604
+            } else {
605
+                $new_terms = array();
606
+            }
607
+
608
+            if ( $taxonomy_obj->hierarchical ) {
609
+                $current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array( 'fields' => 'ids' ) );
610
+            } else {
611
+                $current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array( 'fields' => 'names' ) );
612
+            }
613
+
614
+            $post_data['tax_input'][ $tax_name ] = array_merge( $current_terms, $new_terms );
615
+        }
616
+
617
+        if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
618
+            $cats                       = (array) wp_get_post_categories( $post_ID );
619
+            $post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) );
620
+            unset( $post_data['tax_input']['category'] );
621
+        }
622
+
623
+        $post_data['post_ID']        = $post_ID;
624
+        $post_data['post_type']      = $post->post_type;
625
+        $post_data['post_mime_type'] = $post->post_mime_type;
626
+
627
+        foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) {
628
+            if ( ! isset( $post_data[ $field ] ) ) {
629
+                $post_data[ $field ] = $post->$field;
630
+            }
631
+        }
632
+
633
+        $post_data = _wp_translate_postdata( true, $post_data );
634
+        if ( is_wp_error( $post_data ) ) {
635
+            $skipped[] = $post_ID;
636
+            continue;
637
+        }
638
+        $post_data = _wp_get_allowed_postdata( $post_data );
639
+
640
+        if ( isset( $shared_post_data['post_format'] ) ) {
641
+            set_post_format( $post_ID, $shared_post_data['post_format'] );
642
+        }
643
+
644
+        // Prevent wp_insert_post() from overwriting post format with the old data.
645
+        unset( $post_data['tax_input']['post_format'] );
646
+
647
+        $post_id = wp_update_post( $post_data );
648
+        update_post_meta( $post_id, '_edit_last', get_current_user_id() );
649
+        $updated[] = $post_id;
650
+
651
+        if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
652
+            if ( 'sticky' === $post_data['sticky'] ) {
653
+                stick_post( $post_ID );
654
+            } else {
655
+                unstick_post( $post_ID );
656
+            }
657
+        }
658
+    }
659
+
660
+    return array(
661
+        'updated' => $updated,
662
+        'skipped' => $skipped,
663
+        'locked'  => $locked,
664
+    );
665 665
 }
666 666
 
667 667
 /**
@@ -674,94 +674,94 @@  discard block
 block discarded – undo
674 674
  * @return WP_Post Post object containing all the default post data as attributes
675 675
  */
676 676
 function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
677
-	$post_title = '';
678
-	if ( ! empty( $_REQUEST['post_title'] ) ) {
679
-		$post_title = esc_html( wp_unslash( $_REQUEST['post_title'] ) );
680
-	}
681
-
682
-	$post_content = '';
683
-	if ( ! empty( $_REQUEST['content'] ) ) {
684
-		$post_content = esc_html( wp_unslash( $_REQUEST['content'] ) );
685
-	}
686
-
687
-	$post_excerpt = '';
688
-	if ( ! empty( $_REQUEST['excerpt'] ) ) {
689
-		$post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] ) );
690
-	}
691
-
692
-	if ( $create_in_db ) {
693
-		$post_id = wp_insert_post(
694
-			array(
695
-				'post_title'  => __( 'Auto Draft' ),
696
-				'post_type'   => $post_type,
697
-				'post_status' => 'auto-draft',
698
-			),
699
-			false,
700
-			false
701
-		);
702
-		$post    = get_post( $post_id );
703
-		if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
704
-			set_post_format( $post, get_option( 'default_post_format' ) );
705
-		}
706
-		wp_after_insert_post( $post, false, null );
707
-
708
-		// Schedule auto-draft cleanup.
709
-		if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
710
-			wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
711
-		}
712
-	} else {
713
-		$post                 = new stdClass;
714
-		$post->ID             = 0;
715
-		$post->post_author    = '';
716
-		$post->post_date      = '';
717
-		$post->post_date_gmt  = '';
718
-		$post->post_password  = '';
719
-		$post->post_name      = '';
720
-		$post->post_type      = $post_type;
721
-		$post->post_status    = 'draft';
722
-		$post->to_ping        = '';
723
-		$post->pinged         = '';
724
-		$post->comment_status = get_default_comment_status( $post_type );
725
-		$post->ping_status    = get_default_comment_status( $post_type, 'pingback' );
726
-		$post->post_pingback  = get_option( 'default_pingback_flag' );
727
-		$post->post_category  = get_option( 'default_category' );
728
-		$post->page_template  = 'default';
729
-		$post->post_parent    = 0;
730
-		$post->menu_order     = 0;
731
-		$post                 = new WP_Post( $post );
732
-	}
733
-
734
-	/**
735
-	 * Filters the default post content initially used in the "Write Post" form.
736
-	 *
737
-	 * @since 1.5.0
738
-	 *
739
-	 * @param string  $post_content Default post content.
740
-	 * @param WP_Post $post         Post object.
741
-	 */
742
-	$post->post_content = (string) apply_filters( 'default_content', $post_content, $post );
743
-
744
-	/**
745
-	 * Filters the default post title initially used in the "Write Post" form.
746
-	 *
747
-	 * @since 1.5.0
748
-	 *
749
-	 * @param string  $post_title Default post title.
750
-	 * @param WP_Post $post       Post object.
751
-	 */
752
-	$post->post_title = (string) apply_filters( 'default_title', $post_title, $post );
753
-
754
-	/**
755
-	 * Filters the default post excerpt initially used in the "Write Post" form.
756
-	 *
757
-	 * @since 1.5.0
758
-	 *
759
-	 * @param string  $post_excerpt Default post excerpt.
760
-	 * @param WP_Post $post         Post object.
761
-	 */
762
-	$post->post_excerpt = (string) apply_filters( 'default_excerpt', $post_excerpt, $post );
763
-
764
-	return $post;
677
+    $post_title = '';
678
+    if ( ! empty( $_REQUEST['post_title'] ) ) {
679
+        $post_title = esc_html( wp_unslash( $_REQUEST['post_title'] ) );
680
+    }
681
+
682
+    $post_content = '';
683
+    if ( ! empty( $_REQUEST['content'] ) ) {
684
+        $post_content = esc_html( wp_unslash( $_REQUEST['content'] ) );
685
+    }
686
+
687
+    $post_excerpt = '';
688
+    if ( ! empty( $_REQUEST['excerpt'] ) ) {
689
+        $post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] ) );
690
+    }
691
+
692
+    if ( $create_in_db ) {
693
+        $post_id = wp_insert_post(
694
+            array(
695
+                'post_title'  => __( 'Auto Draft' ),
696
+                'post_type'   => $post_type,
697
+                'post_status' => 'auto-draft',
698
+            ),
699
+            false,
700
+            false
701
+        );
702
+        $post    = get_post( $post_id );
703
+        if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
704
+            set_post_format( $post, get_option( 'default_post_format' ) );
705
+        }
706
+        wp_after_insert_post( $post, false, null );
707
+
708
+        // Schedule auto-draft cleanup.
709
+        if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
710
+            wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
711
+        }
712
+    } else {
713
+        $post                 = new stdClass;
714
+        $post->ID             = 0;
715
+        $post->post_author    = '';
716
+        $post->post_date      = '';
717
+        $post->post_date_gmt  = '';
718
+        $post->post_password  = '';
719
+        $post->post_name      = '';
720
+        $post->post_type      = $post_type;
721
+        $post->post_status    = 'draft';
722
+        $post->to_ping        = '';
723
+        $post->pinged         = '';
724
+        $post->comment_status = get_default_comment_status( $post_type );
725
+        $post->ping_status    = get_default_comment_status( $post_type, 'pingback' );
726
+        $post->post_pingback  = get_option( 'default_pingback_flag' );
727
+        $post->post_category  = get_option( 'default_category' );
728
+        $post->page_template  = 'default';
729
+        $post->post_parent    = 0;
730
+        $post->menu_order     = 0;
731
+        $post                 = new WP_Post( $post );
732
+    }
733
+
734
+    /**
735
+     * Filters the default post content initially used in the "Write Post" form.
736
+     *
737
+     * @since 1.5.0
738
+     *
739
+     * @param string  $post_content Default post content.
740
+     * @param WP_Post $post         Post object.
741
+     */
742
+    $post->post_content = (string) apply_filters( 'default_content', $post_content, $post );
743
+
744
+    /**
745
+     * Filters the default post title initially used in the "Write Post" form.
746
+     *
747
+     * @since 1.5.0
748
+     *
749
+     * @param string  $post_title Default post title.
750
+     * @param WP_Post $post       Post object.
751
+     */
752
+    $post->post_title = (string) apply_filters( 'default_title', $post_title, $post );
753
+
754
+    /**
755
+     * Filters the default post excerpt initially used in the "Write Post" form.
756
+     *
757
+     * @since 1.5.0
758
+     *
759
+     * @param string  $post_excerpt Default post excerpt.
760
+     * @param WP_Post $post         Post object.
761
+     */
762
+    $post->post_excerpt = (string) apply_filters( 'default_excerpt', $post_excerpt, $post );
763
+
764
+    return $post;
765 765
 }
766 766
 
767 767
 /**
@@ -781,47 +781,47 @@  discard block
 block discarded – undo
781 781
  * @return int Post ID if post exists, 0 otherwise.
782 782
  */
783 783
 function post_exists( $title, $content = '', $date = '', $type = '', $status = '' ) {
784
-	global $wpdb;
785
-
786
-	$post_title   = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
787
-	$post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) );
788
-	$post_date    = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) );
789
-	$post_type    = wp_unslash( sanitize_post_field( 'post_type', $type, 0, 'db' ) );
790
-	$post_status  = wp_unslash( sanitize_post_field( 'post_status', $status, 0, 'db' ) );
791
-
792
-	$query = "SELECT ID FROM $wpdb->posts WHERE 1=1";
793
-	$args  = array();
794
-
795
-	if ( ! empty( $date ) ) {
796
-		$query .= ' AND post_date = %s';
797
-		$args[] = $post_date;
798
-	}
799
-
800
-	if ( ! empty( $title ) ) {
801
-		$query .= ' AND post_title = %s';
802
-		$args[] = $post_title;
803
-	}
804
-
805
-	if ( ! empty( $content ) ) {
806
-		$query .= ' AND post_content = %s';
807
-		$args[] = $post_content;
808
-	}
809
-
810
-	if ( ! empty( $type ) ) {
811
-		$query .= ' AND post_type = %s';
812
-		$args[] = $post_type;
813
-	}
814
-
815
-	if ( ! empty( $status ) ) {
816
-		$query .= ' AND post_status = %s';
817
-		$args[] = $post_status;
818
-	}
819
-
820
-	if ( ! empty( $args ) ) {
821
-		return (int) $wpdb->get_var( $wpdb->prepare( $query, $args ) );
822
-	}
823
-
824
-	return 0;
784
+    global $wpdb;
785
+
786
+    $post_title   = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
787
+    $post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) );
788
+    $post_date    = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) );
789
+    $post_type    = wp_unslash( sanitize_post_field( 'post_type', $type, 0, 'db' ) );
790
+    $post_status  = wp_unslash( sanitize_post_field( 'post_status', $status, 0, 'db' ) );
791
+
792
+    $query = "SELECT ID FROM $wpdb->posts WHERE 1=1";
793
+    $args  = array();
794
+
795
+    if ( ! empty( $date ) ) {
796
+        $query .= ' AND post_date = %s';
797
+        $args[] = $post_date;
798
+    }
799
+
800
+    if ( ! empty( $title ) ) {
801
+        $query .= ' AND post_title = %s';
802
+        $args[] = $post_title;
803
+    }
804
+
805
+    if ( ! empty( $content ) ) {
806
+        $query .= ' AND post_content = %s';
807
+        $args[] = $post_content;
808
+    }
809
+
810
+    if ( ! empty( $type ) ) {
811
+        $query .= ' AND post_type = %s';
812
+        $args[] = $post_type;
813
+    }
814
+
815
+    if ( ! empty( $status ) ) {
816
+        $query .= ' AND post_status = %s';
817
+        $args[] = $post_status;
818
+    }
819
+
820
+    if ( ! empty( $args ) ) {
821
+        return (int) $wpdb->get_var( $wpdb->prepare( $query, $args ) );
822
+    }
823
+
824
+    return 0;
825 825
 }
826 826
 
827 827
 /**
@@ -834,72 +834,72 @@  discard block
 block discarded – undo
834 834
  * @return int|WP_Error Post ID on success, WP_Error on failure.
835 835
  */
836 836
 function wp_write_post() {
837
-	if ( isset( $_POST['post_type'] ) ) {
838
-		$ptype = get_post_type_object( $_POST['post_type'] );
839
-	} else {
840
-		$ptype = get_post_type_object( 'post' );
841
-	}
842
-
843
-	if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
844
-		if ( 'page' === $ptype->name ) {
845
-			return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) );
846
-		} else {
847
-			return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) );
848
-		}
849
-	}
850
-
851
-	$_POST['post_mime_type'] = '';
852
-
853
-	// Clear out any data in internal vars.
854
-	unset( $_POST['filter'] );
855
-
856
-	// Edit, don't write, if we have a post ID.
857
-	if ( isset( $_POST['post_ID'] ) ) {
858
-		return edit_post();
859
-	}
860
-
861
-	if ( isset( $_POST['visibility'] ) ) {
862
-		switch ( $_POST['visibility'] ) {
863
-			case 'public':
864
-				$_POST['post_password'] = '';
865
-				break;
866
-			case 'password':
867
-				unset( $_POST['sticky'] );
868
-				break;
869
-			case 'private':
870
-				$_POST['post_status']   = 'private';
871
-				$_POST['post_password'] = '';
872
-				unset( $_POST['sticky'] );
873
-				break;
874
-		}
875
-	}
876
-
877
-	$translated = _wp_translate_postdata( false );
878
-	if ( is_wp_error( $translated ) ) {
879
-		return $translated;
880
-	}
881
-	$translated = _wp_get_allowed_postdata( $translated );
882
-
883
-	// Create the post.
884
-	$post_ID = wp_insert_post( $translated );
885
-	if ( is_wp_error( $post_ID ) ) {
886
-		return $post_ID;
887
-	}
888
-
889
-	if ( empty( $post_ID ) ) {
890
-		return 0;
891
-	}
892
-
893
-	add_meta( $post_ID );
894
-
895
-	add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
896
-
897
-	// Now that we have an ID we can fix any attachment anchor hrefs.
898
-	_fix_attachment_links( $post_ID );
899
-
900
-	wp_set_post_lock( $post_ID );
901
-
902
-	return $post_ID;
837
+    if ( isset( $_POST['post_type'] ) ) {
838
+        $ptype = get_post_type_object( $_POST['post_type'] );
839
+    } else {
840
+        $ptype = get_post_type_object( 'post' );
841
+    }
842
+
843
+    if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
844
+        if ( 'page' === $ptype->name ) {
845
+            return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) );
846
+        } else {
847
+            return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) );
848
+        }
849
+    }
850
+
851
+    $_POST['post_mime_type'] = '';
852
+
853
+    // Clear out any data in internal vars.
854
+    unset( $_POST['filter'] );
855
+
856
+    // Edit, don't write, if we have a post ID.
857
+    if ( isset( $_POST['post_ID'] ) ) {
858
+        return edit_post();
859
+    }
860
+
861
+    if ( isset( $_POST['visibility'] ) ) {
862
+        switch ( $_POST['visibility'] ) {
863
+            case 'public':
864
+                $_POST['post_password'] = '';
865
+                break;
866
+            case 'password':
867
+                unset( $_POST['sticky'] );
868
+                break;
869
+            case 'private':
870
+                $_POST['post_status']   = 'private';
871
+                $_POST['post_password'] = '';
872
+                unset( $_POST['sticky'] );
873
+                break;
874
+        }
875
+    }
876
+
877
+    $translated = _wp_translate_postdata( false );
878
+    if ( is_wp_error( $translated ) ) {
879
+        return $translated;
880
+    }
881
+    $translated = _wp_get_allowed_postdata( $translated );
882
+
883
+    // Create the post.
884
+    $post_ID = wp_insert_post( $translated );
885
+    if ( is_wp_error( $post_ID ) ) {
886
+        return $post_ID;
887
+    }
888
+
889
+    if ( empty( $post_ID ) ) {
890
+        return 0;
891
+    }
892
+
893
+    add_meta( $post_ID );
894
+
895
+    add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
896
+
897
+    // Now that we have an ID we can fix any attachment anchor hrefs.
898
+    _fix_attachment_links( $post_ID );
899
+
900
+    wp_set_post_lock( $post_ID );
901
+
902
+    return $post_ID;
903 903
 }
904 904
 
905 905
 /**
@@ -910,12 +910,12 @@  discard block
 block discarded – undo
910 910
  * @return int|void Post ID on success, void on failure.
911 911
  */
912 912
 function write_post() {
913
-	$result = wp_write_post();
914
-	if ( is_wp_error( $result ) ) {
915
-		wp_die( $result->get_error_message() );
916
-	} else {
917
-		return $result;
918
-	}
913
+    $result = wp_write_post();
914
+    if ( is_wp_error( $result ) ) {
915
+        wp_die( $result->get_error_message() );
916
+    } else {
917
+        return $result;
918
+    }
919 919
 }
920 920
 
921 921
 //
@@ -931,38 +931,38 @@  discard block
 block discarded – undo
931 931
  * @return int|bool
932 932
  */
933 933
 function add_meta( $post_ID ) {
934
-	$post_ID = (int) $post_ID;
934
+    $post_ID = (int) $post_ID;
935 935
 
936
-	$metakeyselect = isset( $_POST['metakeyselect'] ) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : '';
937
-	$metakeyinput  = isset( $_POST['metakeyinput'] ) ? wp_unslash( trim( $_POST['metakeyinput'] ) ) : '';
938
-	$metavalue     = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : '';
939
-	if ( is_string( $metavalue ) ) {
940
-		$metavalue = trim( $metavalue );
941
-	}
936
+    $metakeyselect = isset( $_POST['metakeyselect'] ) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : '';
937
+    $metakeyinput  = isset( $_POST['metakeyinput'] ) ? wp_unslash( trim( $_POST['metakeyinput'] ) ) : '';
938
+    $metavalue     = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : '';
939
+    if ( is_string( $metavalue ) ) {
940
+        $metavalue = trim( $metavalue );
941
+    }
942 942
 
943
-	if ( ( ( '#NONE#' !== $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
944
-		/*
943
+    if ( ( ( '#NONE#' !== $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
944
+        /*
945 945
 		 * We have a key/value pair. If both the select and the input
946 946
 		 * for the key have data, the input takes precedence.
947 947
 		 */
948
-		if ( '#NONE#' !== $metakeyselect ) {
949
-			$metakey = $metakeyselect;
950
-		}
948
+        if ( '#NONE#' !== $metakeyselect ) {
949
+            $metakey = $metakeyselect;
950
+        }
951 951
 
952
-		if ( $metakeyinput ) {
953
-			$metakey = $metakeyinput; // Default.
954
-		}
952
+        if ( $metakeyinput ) {
953
+            $metakey = $metakeyinput; // Default.
954
+        }
955 955
 
956
-		if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) ) {
957
-			return false;
958
-		}
956
+        if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) ) {
957
+            return false;
958
+        }
959 959
 
960
-		$metakey = wp_slash( $metakey );
960
+        $metakey = wp_slash( $metakey );
961 961
 
962
-		return add_post_meta( $post_ID, $metakey, $metavalue );
963
-	}
962
+        return add_post_meta( $post_ID, $metakey, $metavalue );
963
+    }
964 964
 
965
-	return false;
965
+    return false;
966 966
 }
967 967
 
968 968
 /**
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
  * @return bool
975 975
  */
976 976
 function delete_meta( $mid ) {
977
-	return delete_metadata_by_mid( 'post', $mid );
977
+    return delete_metadata_by_mid( 'post', $mid );
978 978
 }
979 979
 
980 980
 /**
@@ -987,17 +987,17 @@  discard block
 block discarded – undo
987 987
  * @return string[] Array of meta key names.
988 988
  */
989 989
 function get_meta_keys() {
990
-	global $wpdb;
990
+    global $wpdb;
991 991
 
992
-	$keys = $wpdb->get_col(
993
-		"
992
+    $keys = $wpdb->get_col(
993
+        "
994 994
 			SELECT meta_key
995 995
 			FROM $wpdb->postmeta
996 996
 			GROUP BY meta_key
997 997
 			ORDER BY meta_key"
998
-	);
998
+    );
999 999
 
1000
-	return $keys;
1000
+    return $keys;
1001 1001
 }
1002 1002
 
1003 1003
 /**
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
  * @return object|bool
1010 1010
  */
1011 1011
 function get_post_meta_by_id( $mid ) {
1012
-	return get_metadata_by_mid( 'post', $mid );
1012
+    return get_metadata_by_mid( 'post', $mid );
1013 1013
 }
1014 1014
 
1015 1015
 /**
@@ -1034,17 +1034,17 @@  discard block
 block discarded – undo
1034 1034
  * }
1035 1035
  */
1036 1036
 function has_meta( $postid ) {
1037
-	global $wpdb;
1037
+    global $wpdb;
1038 1038
 
1039
-	return $wpdb->get_results(
1040
-		$wpdb->prepare(
1041
-			"SELECT meta_key, meta_value, meta_id, post_id
1039
+    return $wpdb->get_results(
1040
+        $wpdb->prepare(
1041
+            "SELECT meta_key, meta_value, meta_id, post_id
1042 1042
 			FROM $wpdb->postmeta WHERE post_id = %d
1043 1043
 			ORDER BY meta_key,meta_id",
1044
-			$postid
1045
-		),
1046
-		ARRAY_A
1047
-	);
1044
+            $postid
1045
+        ),
1046
+        ARRAY_A
1047
+    );
1048 1048
 }
1049 1049
 
1050 1050
 /**
@@ -1058,10 +1058,10 @@  discard block
 block discarded – undo
1058 1058
  * @return bool
1059 1059
  */
1060 1060
 function update_meta( $meta_id, $meta_key, $meta_value ) {
1061
-	$meta_key   = wp_unslash( $meta_key );
1062
-	$meta_value = wp_unslash( $meta_value );
1061
+    $meta_key   = wp_unslash( $meta_key );
1062
+    $meta_value = wp_unslash( $meta_value );
1063 1063
 
1064
-	return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key );
1064
+    return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key );
1065 1065
 }
1066 1066
 
1067 1067
 //
@@ -1078,51 +1078,51 @@  discard block
 block discarded – undo
1078 1078
  * @return void|int|WP_Error Void if nothing fixed. 0 or WP_Error on update failure. The post ID on update success.
1079 1079
  */
1080 1080
 function _fix_attachment_links( $post ) {
1081
-	$post    = get_post( $post, ARRAY_A );
1082
-	$content = $post['post_content'];
1083
-
1084
-	// Don't run if no pretty permalinks or post is not published, scheduled, or privately published.
1085
-	if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ), true ) ) {
1086
-		return;
1087
-	}
1088
-
1089
-	// Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero).
1090
-	if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) {
1091
-		return;
1092
-	}
1093
-
1094
-	$site_url = get_bloginfo( 'url' );
1095
-	$site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // Remove the http(s).
1096
-	$replace  = '';
1097
-
1098
-	foreach ( $link_matches[1] as $key => $value ) {
1099
-		if ( ! strpos( $value, '?attachment_id=' ) || ! strpos( $value, 'wp-att-' )
1100
-			|| ! preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match )
1101
-			|| ! preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) ) {
1102
-				continue;
1103
-		}
1104
-
1105
-		$quote  = $url_match[1]; // The quote (single or double).
1106
-		$url_id = (int) $url_match[2];
1107
-		$rel_id = (int) $rel_match[1];
1108
-
1109
-		if ( ! $url_id || ! $rel_id || $url_id != $rel_id || strpos( $url_match[0], $site_url ) === false ) {
1110
-			continue;
1111
-		}
1112
-
1113
-		$link    = $link_matches[0][ $key ];
1114
-		$replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link );
1115
-
1116
-		$content = str_replace( $link, $replace, $content );
1117
-	}
1118
-
1119
-	if ( $replace ) {
1120
-		$post['post_content'] = $content;
1121
-		// Escape data pulled from DB.
1122
-		$post = add_magic_quotes( $post );
1123
-
1124
-		return wp_update_post( $post );
1125
-	}
1081
+    $post    = get_post( $post, ARRAY_A );
1082
+    $content = $post['post_content'];
1083
+
1084
+    // Don't run if no pretty permalinks or post is not published, scheduled, or privately published.
1085
+    if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ), true ) ) {
1086
+        return;
1087
+    }
1088
+
1089
+    // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero).
1090
+    if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) {
1091
+        return;
1092
+    }
1093
+
1094
+    $site_url = get_bloginfo( 'url' );
1095
+    $site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // Remove the http(s).
1096
+    $replace  = '';
1097
+
1098
+    foreach ( $link_matches[1] as $key => $value ) {
1099
+        if ( ! strpos( $value, '?attachment_id=' ) || ! strpos( $value, 'wp-att-' )
1100
+            || ! preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match )
1101
+            || ! preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) ) {
1102
+                continue;
1103
+        }
1104
+
1105
+        $quote  = $url_match[1]; // The quote (single or double).
1106
+        $url_id = (int) $url_match[2];
1107
+        $rel_id = (int) $rel_match[1];
1108
+
1109
+        if ( ! $url_id || ! $rel_id || $url_id != $rel_id || strpos( $url_match[0], $site_url ) === false ) {
1110
+            continue;
1111
+        }
1112
+
1113
+        $link    = $link_matches[0][ $key ];
1114
+        $replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link );
1115
+
1116
+        $content = str_replace( $link, $replace, $content );
1117
+    }
1118
+
1119
+    if ( $replace ) {
1120
+        $post['post_content'] = $content;
1121
+        // Escape data pulled from DB.
1122
+        $post = add_magic_quotes( $post );
1123
+
1124
+        return wp_update_post( $post );
1125
+    }
1126 1126
 }
1127 1127
 
1128 1128
 /**
@@ -1134,9 +1134,9 @@  discard block
 block discarded – undo
1134 1134
  * @return string[] An array of all the statuses for the supplied post type.
1135 1135
  */
1136 1136
 function get_available_post_statuses( $type = 'post' ) {
1137
-	$stati = wp_count_posts( $type );
1137
+    $stati = wp_count_posts( $type );
1138 1138
 
1139
-	return array_keys( get_object_vars( $stati ) );
1139
+    return array_keys( get_object_vars( $stati ) );
1140 1140
 }
1141 1141
 
1142 1142
 /**
@@ -1149,96 +1149,96 @@  discard block
 block discarded – undo
1149 1149
  * @return array
1150 1150
  */
1151 1151
 function wp_edit_posts_query( $q = false ) {
1152
-	if ( false === $q ) {
1153
-		$q = $_GET;
1154
-	}
1155
-	$q['m']     = isset( $q['m'] ) ? (int) $q['m'] : 0;
1156
-	$q['cat']   = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
1157
-	$post_stati = get_post_stati();
1158
-
1159
-	if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types(), true ) ) {
1160
-		$post_type = $q['post_type'];
1161
-	} else {
1162
-		$post_type = 'post';
1163
-	}
1164
-
1165
-	$avail_post_stati = get_available_post_statuses( $post_type );
1166
-	$post_status      = '';
1167
-	$perm             = '';
1168
-
1169
-	if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_stati, true ) ) {
1170
-		$post_status = $q['post_status'];
1171
-		$perm        = 'readable';
1172
-	}
1173
-
1174
-	$orderby = '';
1175
-
1176
-	if ( isset( $q['orderby'] ) ) {
1177
-		$orderby = $q['orderby'];
1178
-	} elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ), true ) ) {
1179
-		$orderby = 'modified';
1180
-	}
1181
-
1182
-	$order = '';
1183
-
1184
-	if ( isset( $q['order'] ) ) {
1185
-		$order = $q['order'];
1186
-	} elseif ( isset( $q['post_status'] ) && 'pending' === $q['post_status'] ) {
1187
-		$order = 'ASC';
1188
-	}
1189
-
1190
-	$per_page       = "edit_{$post_type}_per_page";
1191
-	$posts_per_page = (int) get_user_option( $per_page );
1192
-	if ( empty( $posts_per_page ) || $posts_per_page < 1 ) {
1193
-		$posts_per_page = 20;
1194
-	}
1195
-
1196
-	/**
1197
-	 * Filters the number of items per page to show for a specific 'per_page' type.
1198
-	 *
1199
-	 * The dynamic portion of the hook name, `$post_type`, refers to the post type.
1200
-	 *
1201
-	 * Possible hook names include:
1202
-	 *
1203
-	 *  - `edit_post_per_page`
1204
-	 *  - `edit_page_per_page`
1205
-	 *  - `edit_attachment_per_page`
1206
-	 *
1207
-	 * @since 3.0.0
1208
-	 *
1209
-	 * @param int $posts_per_page Number of posts to display per page for the given post
1210
-	 *                            type. Default 20.
1211
-	 */
1212
-	$posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page );
1213
-
1214
-	/**
1215
-	 * Filters the number of posts displayed per page when specifically listing "posts".
1216
-	 *
1217
-	 * @since 2.8.0
1218
-	 *
1219
-	 * @param int    $posts_per_page Number of posts to be displayed. Default 20.
1220
-	 * @param string $post_type      The post type.
1221
-	 */
1222
-	$posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type );
1223
-
1224
-	$query = compact( 'post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page' );
1225
-
1226
-	// Hierarchical types require special args.
1227
-	if ( is_post_type_hierarchical( $post_type ) && empty( $orderby ) ) {
1228
-		$query['orderby']                = 'menu_order title';
1229
-		$query['order']                  = 'asc';
1230
-		$query['posts_per_page']         = -1;
1231
-		$query['posts_per_archive_page'] = -1;
1232
-		$query['fields']                 = 'id=>parent';
1233
-	}
1234
-
1235
-	if ( ! empty( $q['show_sticky'] ) ) {
1236
-		$query['post__in'] = (array) get_option( 'sticky_posts' );
1237
-	}
1238
-
1239
-	wp( $query );
1240
-
1241
-	return $avail_post_stati;
1152
+    if ( false === $q ) {
1153
+        $q = $_GET;
1154
+    }
1155
+    $q['m']     = isset( $q['m'] ) ? (int) $q['m'] : 0;
1156
+    $q['cat']   = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
1157
+    $post_stati = get_post_stati();
1158
+
1159
+    if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types(), true ) ) {
1160
+        $post_type = $q['post_type'];
1161
+    } else {
1162
+        $post_type = 'post';
1163
+    }
1164
+
1165
+    $avail_post_stati = get_available_post_statuses( $post_type );
1166
+    $post_status      = '';
1167
+    $perm             = '';
1168
+
1169
+    if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_stati, true ) ) {
1170
+        $post_status = $q['post_status'];
1171
+        $perm        = 'readable';
1172
+    }
1173
+
1174
+    $orderby = '';
1175
+
1176
+    if ( isset( $q['orderby'] ) ) {
1177
+        $orderby = $q['orderby'];
1178
+    } elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ), true ) ) {
1179
+        $orderby = 'modified';
1180
+    }
1181
+
1182
+    $order = '';
1183
+
1184
+    if ( isset( $q['order'] ) ) {
1185
+        $order = $q['order'];
1186
+    } elseif ( isset( $q['post_status'] ) && 'pending' === $q['post_status'] ) {
1187
+        $order = 'ASC';
1188
+    }
1189
+
1190
+    $per_page       = "edit_{$post_type}_per_page";
1191
+    $posts_per_page = (int) get_user_option( $per_page );
1192
+    if ( empty( $posts_per_page ) || $posts_per_page < 1 ) {
1193
+        $posts_per_page = 20;
1194
+    }
1195
+
1196
+    /**
1197
+     * Filters the number of items per page to show for a specific 'per_page' type.
1198
+     *
1199
+     * The dynamic portion of the hook name, `$post_type`, refers to the post type.
1200
+     *
1201
+     * Possible hook names include:
1202
+     *
1203
+     *  - `edit_post_per_page`
1204
+     *  - `edit_page_per_page`
1205
+     *  - `edit_attachment_per_page`
1206
+     *
1207
+     * @since 3.0.0
1208
+     *
1209
+     * @param int $posts_per_page Number of posts to display per page for the given post
1210
+     *                            type. Default 20.
1211
+     */
1212
+    $posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page );
1213
+
1214
+    /**
1215
+     * Filters the number of posts displayed per page when specifically listing "posts".
1216
+     *
1217
+     * @since 2.8.0
1218
+     *
1219
+     * @param int    $posts_per_page Number of posts to be displayed. Default 20.
1220
+     * @param string $post_type      The post type.
1221
+     */
1222
+    $posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type );
1223
+
1224
+    $query = compact( 'post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page' );
1225
+
1226
+    // Hierarchical types require special args.
1227
+    if ( is_post_type_hierarchical( $post_type ) && empty( $orderby ) ) {
1228
+        $query['orderby']                = 'menu_order title';
1229
+        $query['order']                  = 'asc';
1230
+        $query['posts_per_page']         = -1;
1231
+        $query['posts_per_archive_page'] = -1;
1232
+        $query['fields']                 = 'id=>parent';
1233
+    }
1234
+
1235
+    if ( ! empty( $q['show_sticky'] ) ) {
1236
+        $query['post__in'] = (array) get_option( 'sticky_posts' );
1237
+    }
1238
+
1239
+    wp( $query );
1240
+
1241
+    return $avail_post_stati;
1242 1242
 }
1243 1243
 
1244 1244
 /**
@@ -1251,61 +1251,61 @@  discard block
 block discarded – undo
1251 1251
  * @return array The parsed query vars.
1252 1252
  */
1253 1253
 function wp_edit_attachments_query_vars( $q = false ) {
1254
-	if ( false === $q ) {
1255
-		$q = $_GET;
1256
-	}
1257
-	$q['m']         = isset( $q['m'] ) ? (int) $q['m'] : 0;
1258
-	$q['cat']       = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
1259
-	$q['post_type'] = 'attachment';
1260
-	$post_type      = get_post_type_object( 'attachment' );
1261
-	$states         = 'inherit';
1262
-	if ( current_user_can( $post_type->cap->read_private_posts ) ) {
1263
-		$states .= ',private';
1264
-	}
1265
-
1266
-	$q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states;
1267
-	$q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states;
1268
-
1269
-	$media_per_page = (int) get_user_option( 'upload_per_page' );
1270
-	if ( empty( $media_per_page ) || $media_per_page < 1 ) {
1271
-		$media_per_page = 20;
1272
-	}
1273
-
1274
-	/**
1275
-	 * Filters the number of items to list per page when listing media items.
1276
-	 *
1277
-	 * @since 2.9.0
1278
-	 *
1279
-	 * @param int $media_per_page Number of media to list. Default 20.
1280
-	 */
1281
-	$q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page );
1282
-
1283
-	$post_mime_types = get_post_mime_types();
1284
-	if ( isset( $q['post_mime_type'] ) && ! array_intersect( (array) $q['post_mime_type'], array_keys( $post_mime_types ) ) ) {
1285
-		unset( $q['post_mime_type'] );
1286
-	}
1287
-
1288
-	foreach ( array_keys( $post_mime_types ) as $type ) {
1289
-		if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) {
1290
-			$q['post_mime_type'] = $type;
1291
-			break;
1292
-		}
1293
-	}
1294
-
1295
-	if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) {
1296
-		$q['post_parent'] = 0;
1297
-	}
1298
-
1299
-	if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) {
1300
-		$q['author'] = get_current_user_id();
1301
-	}
1302
-
1303
-	// Filter query clauses to include filenames.
1304
-	if ( isset( $q['s'] ) ) {
1305
-		add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
1306
-	}
1307
-
1308
-	return $q;
1254
+    if ( false === $q ) {
1255
+        $q = $_GET;
1256
+    }
1257
+    $q['m']         = isset( $q['m'] ) ? (int) $q['m'] : 0;
1258
+    $q['cat']       = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
1259
+    $q['post_type'] = 'attachment';
1260
+    $post_type      = get_post_type_object( 'attachment' );
1261
+    $states         = 'inherit';
1262
+    if ( current_user_can( $post_type->cap->read_private_posts ) ) {
1263
+        $states .= ',private';
1264
+    }
1265
+
1266
+    $q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states;
1267
+    $q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states;
1268
+
1269
+    $media_per_page = (int) get_user_option( 'upload_per_page' );
1270
+    if ( empty( $media_per_page ) || $media_per_page < 1 ) {
1271
+        $media_per_page = 20;
1272
+    }
1273
+
1274
+    /**
1275
+     * Filters the number of items to list per page when listing media items.
1276
+     *
1277
+     * @since 2.9.0
1278
+     *
1279
+     * @param int $media_per_page Number of media to list. Default 20.
1280
+     */
1281
+    $q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page );
1282
+
1283
+    $post_mime_types = get_post_mime_types();
1284
+    if ( isset( $q['post_mime_type'] ) && ! array_intersect( (array) $q['post_mime_type'], array_keys( $post_mime_types ) ) ) {
1285
+        unset( $q['post_mime_type'] );
1286
+    }
1287
+
1288
+    foreach ( array_keys( $post_mime_types ) as $type ) {
1289
+        if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) {
1290
+            $q['post_mime_type'] = $type;
1291
+            break;
1292
+        }
1293
+    }
1294
+
1295
+    if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) {
1296
+        $q['post_parent'] = 0;
1297
+    }
1298
+
1299
+    if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) {
1300
+        $q['author'] = get_current_user_id();
1301
+    }
1302
+
1303
+    // Filter query clauses to include filenames.
1304
+    if ( isset( $q['s'] ) ) {
1305
+        add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
1306
+    }
1307
+
1308
+    return $q;
1309 1309
 }
1310 1310
 
1311 1311
 /**
@@ -1319,12 +1319,12 @@  discard block
 block discarded – undo
1319 1319
  * @return array
1320 1320
  */
1321 1321
 function wp_edit_attachments_query( $q = false ) {
1322
-	wp( wp_edit_attachments_query_vars( $q ) );
1322
+    wp( wp_edit_attachments_query_vars( $q ) );
1323 1323
 
1324
-	$post_mime_types       = get_post_mime_types();
1325
-	$avail_post_mime_types = get_available_post_mime_types( 'attachment' );
1324
+    $post_mime_types       = get_post_mime_types();
1325
+    $avail_post_mime_types = get_available_post_mime_types( 'attachment' );
1326 1326
 
1327
-	return array( $post_mime_types, $avail_post_mime_types );
1327
+    return array( $post_mime_types, $avail_post_mime_types );
1328 1328
 }
1329 1329
 
1330 1330
 /**
@@ -1337,32 +1337,32 @@  discard block
 block discarded – undo
1337 1337
  * @return string Space-separated string of class names.
1338 1338
  */
1339 1339
 function postbox_classes( $box_id, $screen_id ) {
1340
-	if ( isset( $_GET['edit'] ) && $_GET['edit'] == $box_id ) {
1341
-		$classes = array( '' );
1342
-	} elseif ( get_user_option( 'closedpostboxes_' . $screen_id ) ) {
1343
-		$closed = get_user_option( 'closedpostboxes_' . $screen_id );
1344
-		if ( ! is_array( $closed ) ) {
1345
-			$classes = array( '' );
1346
-		} else {
1347
-			$classes = in_array( $box_id, $closed, true ) ? array( 'closed' ) : array( '' );
1348
-		}
1349
-	} else {
1350
-		$classes = array( '' );
1351
-	}
1352
-
1353
-	/**
1354
-	 * Filters the postbox classes for a specific screen and box ID combo.
1355
-	 *
1356
-	 * The dynamic portions of the hook name, `$screen_id` and `$box_id`, refer to
1357
-	 * the screen ID and meta box ID, respectively.
1358
-	 *
1359
-	 * @since 3.2.0
1360
-	 *
1361
-	 * @param string[] $classes An array of postbox classes.
1362
-	 */
1363
-	$classes = apply_filters( "postbox_classes_{$screen_id}_{$box_id}", $classes );
1364
-
1365
-	return implode( ' ', $classes );
1340
+    if ( isset( $_GET['edit'] ) && $_GET['edit'] == $box_id ) {
1341
+        $classes = array( '' );
1342
+    } elseif ( get_user_option( 'closedpostboxes_' . $screen_id ) ) {
1343
+        $closed = get_user_option( 'closedpostboxes_' . $screen_id );
1344
+        if ( ! is_array( $closed ) ) {
1345
+            $classes = array( '' );
1346
+        } else {
1347
+            $classes = in_array( $box_id, $closed, true ) ? array( 'closed' ) : array( '' );
1348
+        }
1349
+    } else {
1350
+        $classes = array( '' );
1351
+    }
1352
+
1353
+    /**
1354
+     * Filters the postbox classes for a specific screen and box ID combo.
1355
+     *
1356
+     * The dynamic portions of the hook name, `$screen_id` and `$box_id`, refer to
1357
+     * the screen ID and meta box ID, respectively.
1358
+     *
1359
+     * @since 3.2.0
1360
+     *
1361
+     * @param string[] $classes An array of postbox classes.
1362
+     */
1363
+    $classes = apply_filters( "postbox_classes_{$screen_id}_{$box_id}", $classes );
1364
+
1365
+    return implode( ' ', $classes );
1366 1366
 }
1367 1367
 
1368 1368
 /**
@@ -1382,79 +1382,79 @@  discard block
 block discarded – undo
1382 1382
  * }
1383 1383
  */
1384 1384
 function get_sample_permalink( $id, $title = null, $name = null ) {
1385
-	$post = get_post( $id );
1386
-	if ( ! $post ) {
1387
-		return array( '', '' );
1388
-	}
1389
-
1390
-	$ptype = get_post_type_object( $post->post_type );
1391
-
1392
-	$original_status = $post->post_status;
1393
-	$original_date   = $post->post_date;
1394
-	$original_name   = $post->post_name;
1395
-
1396
-	// Hack: get_permalink() would return plain permalink for drafts, so we will fake that our post is published.
1397
-	if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ), true ) ) {
1398
-		$post->post_status = 'publish';
1399
-		$post->post_name   = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
1400
-	}
1401
-
1402
-	// If the user wants to set a new name -- override the current one.
1403
-	// Note: if empty name is supplied -- use the title instead, see #6072.
1404
-	if ( ! is_null( $name ) ) {
1405
-		$post->post_name = sanitize_title( $name ? $name : $title, $post->ID );
1406
-	}
1407
-
1408
-	$post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent );
1409
-
1410
-	$post->filter = 'sample';
1411
-
1412
-	$permalink = get_permalink( $post, true );
1413
-
1414
-	// Replace custom post_type token with generic pagename token for ease of use.
1415
-	$permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink );
1416
-
1417
-	// Handle page hierarchy.
1418
-	if ( $ptype->hierarchical ) {
1419
-		$uri = get_page_uri( $post );
1420
-		if ( $uri ) {
1421
-			$uri = untrailingslashit( $uri );
1422
-			$uri = strrev( stristr( strrev( $uri ), '/' ) );
1423
-			$uri = untrailingslashit( $uri );
1424
-		}
1425
-
1426
-		/** This filter is documented in wp-admin/edit-tag-form.php */
1427
-		$uri = apply_filters( 'editable_slug', $uri, $post );
1428
-		if ( ! empty( $uri ) ) {
1429
-			$uri .= '/';
1430
-		}
1431
-		$permalink = str_replace( '%pagename%', "{$uri}%pagename%", $permalink );
1432
-	}
1433
-
1434
-	/** This filter is documented in wp-admin/edit-tag-form.php */
1435
-	$permalink         = array( $permalink, apply_filters( 'editable_slug', $post->post_name, $post ) );
1436
-	$post->post_status = $original_status;
1437
-	$post->post_date   = $original_date;
1438
-	$post->post_name   = $original_name;
1439
-	unset( $post->filter );
1440
-
1441
-	/**
1442
-	 * Filters the sample permalink.
1443
-	 *
1444
-	 * @since 4.4.0
1445
-	 *
1446
-	 * @param array   $permalink {
1447
-	 *     Array containing the sample permalink with placeholder for the post name, and the post name.
1448
-	 *
1449
-	 *     @type string $0 The permalink with placeholder for the post name.
1450
-	 *     @type string $1 The post name.
1451
-	 * }
1452
-	 * @param int     $post_id Post ID.
1453
-	 * @param string  $title   Post title.
1454
-	 * @param string  $name    Post name (slug).
1455
-	 * @param WP_Post $post    Post object.
1456
-	 */
1457
-	return apply_filters( 'get_sample_permalink', $permalink, $post->ID, $title, $name, $post );
1385
+    $post = get_post( $id );
1386
+    if ( ! $post ) {
1387
+        return array( '', '' );
1388
+    }
1389
+
1390
+    $ptype = get_post_type_object( $post->post_type );
1391
+
1392
+    $original_status = $post->post_status;
1393
+    $original_date   = $post->post_date;
1394
+    $original_name   = $post->post_name;
1395
+
1396
+    // Hack: get_permalink() would return plain permalink for drafts, so we will fake that our post is published.
1397
+    if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ), true ) ) {
1398
+        $post->post_status = 'publish';
1399
+        $post->post_name   = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
1400
+    }
1401
+
1402
+    // If the user wants to set a new name -- override the current one.
1403
+    // Note: if empty name is supplied -- use the title instead, see #6072.
1404
+    if ( ! is_null( $name ) ) {
1405
+        $post->post_name = sanitize_title( $name ? $name : $title, $post->ID );
1406
+    }
1407
+
1408
+    $post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent );
1409
+
1410
+    $post->filter = 'sample';
1411
+
1412
+    $permalink = get_permalink( $post, true );
1413
+
1414
+    // Replace custom post_type token with generic pagename token for ease of use.
1415
+    $permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink );
1416
+
1417
+    // Handle page hierarchy.
1418
+    if ( $ptype->hierarchical ) {
1419
+        $uri = get_page_uri( $post );
1420
+        if ( $uri ) {
1421
+            $uri = untrailingslashit( $uri );
1422
+            $uri = strrev( stristr( strrev( $uri ), '/' ) );
1423
+            $uri = untrailingslashit( $uri );
1424
+        }
1425
+
1426
+        /** This filter is documented in wp-admin/edit-tag-form.php */
1427
+        $uri = apply_filters( 'editable_slug', $uri, $post );
1428
+        if ( ! empty( $uri ) ) {
1429
+            $uri .= '/';
1430
+        }
1431
+        $permalink = str_replace( '%pagename%', "{$uri}%pagename%", $permalink );
1432
+    }
1433
+
1434
+    /** This filter is documented in wp-admin/edit-tag-form.php */
1435
+    $permalink         = array( $permalink, apply_filters( 'editable_slug', $post->post_name, $post ) );
1436
+    $post->post_status = $original_status;
1437
+    $post->post_date   = $original_date;
1438
+    $post->post_name   = $original_name;
1439
+    unset( $post->filter );
1440
+
1441
+    /**
1442
+     * Filters the sample permalink.
1443
+     *
1444
+     * @since 4.4.0
1445
+     *
1446
+     * @param array   $permalink {
1447
+     *     Array containing the sample permalink with placeholder for the post name, and the post name.
1448
+     *
1449
+     *     @type string $0 The permalink with placeholder for the post name.
1450
+     *     @type string $1 The post name.
1451
+     * }
1452
+     * @param int     $post_id Post ID.
1453
+     * @param string  $title   Post title.
1454
+     * @param string  $name    Post name (slug).
1455
+     * @param WP_Post $post    Post object.
1456
+     */
1457
+    return apply_filters( 'get_sample_permalink', $permalink, $post->ID, $title, $name, $post );
1458 1458
 }
1459 1459
 
1460 1460
 /**
@@ -1468,79 +1468,79 @@  discard block
 block discarded – undo
1468 1468
  * @return string The HTML of the sample permalink slug editor.
1469 1469
  */
1470 1470
 function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
1471
-	$post = get_post( $id );
1472
-	if ( ! $post ) {
1473
-		return '';
1474
-	}
1475
-
1476
-	list($permalink, $post_name) = get_sample_permalink( $post->ID, $new_title, $new_slug );
1477
-
1478
-	$view_link      = false;
1479
-	$preview_target = '';
1480
-
1481
-	if ( current_user_can( 'read_post', $post->ID ) ) {
1482
-		if ( 'draft' === $post->post_status || empty( $post->post_name ) ) {
1483
-			$view_link      = get_preview_post_link( $post );
1484
-			$preview_target = " target='wp-preview-{$post->ID}'";
1485
-		} else {
1486
-			if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
1487
-				$view_link = get_permalink( $post );
1488
-			} else {
1489
-				// Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set.
1490
-				$view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
1491
-			}
1492
-		}
1493
-	}
1494
-
1495
-	// Permalinks without a post/page name placeholder don't have anything to edit.
1496
-	if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
1497
-		$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
1498
-
1499
-		if ( false !== $view_link ) {
1500
-			$display_link = urldecode( $view_link );
1501
-			$return      .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . esc_html( $display_link ) . "</a>\n";
1502
-		} else {
1503
-			$return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
1504
-		}
1505
-
1506
-		// Encourage a pretty permalink setting.
1507
-		if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' )
1508
-			&& ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $id )
1509
-		) {
1510
-			$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small">' . __( 'Change Permalink Structure' ) . "</a></span>\n";
1511
-		}
1512
-	} else {
1513
-		if ( mb_strlen( $post_name ) > 34 ) {
1514
-			$post_name_abridged = mb_substr( $post_name, 0, 16 ) . '&hellip;' . mb_substr( $post_name, -16 );
1515
-		} else {
1516
-			$post_name_abridged = $post_name;
1517
-		}
1518
-
1519
-		$post_name_html = '<span id="editable-post-name">' . esc_html( $post_name_abridged ) . '</span>';
1520
-		$display_link   = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, esc_html( urldecode( $permalink ) ) );
1521
-
1522
-		$return  = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
1523
-		$return .= '<span id="sample-permalink"><a href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $display_link . "</a></span>\n";
1524
-		$return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
1525
-		$return .= '<span id="edit-slug-buttons"><button type="button" class="edit-slug button button-small hide-if-no-js" aria-label="' . __( 'Edit permalink' ) . '">' . __( 'Edit' ) . "</button></span>\n";
1526
-		$return .= '<span id="editable-post-name-full">' . esc_html( $post_name ) . "</span>\n";
1527
-	}
1528
-
1529
-	/**
1530
-	 * Filters the sample permalink HTML markup.
1531
-	 *
1532
-	 * @since 2.9.0
1533
-	 * @since 4.4.0 Added `$post` parameter.
1534
-	 *
1535
-	 * @param string  $return    Sample permalink HTML markup.
1536
-	 * @param int     $post_id   Post ID.
1537
-	 * @param string  $new_title New sample permalink title.
1538
-	 * @param string  $new_slug  New sample permalink slug.
1539
-	 * @param WP_Post $post      Post object.
1540
-	 */
1541
-	$return = apply_filters( 'get_sample_permalink_html', $return, $post->ID, $new_title, $new_slug, $post );
1542
-
1543
-	return $return;
1471
+    $post = get_post( $id );
1472
+    if ( ! $post ) {
1473
+        return '';
1474
+    }
1475
+
1476
+    list($permalink, $post_name) = get_sample_permalink( $post->ID, $new_title, $new_slug );
1477
+
1478
+    $view_link      = false;
1479
+    $preview_target = '';
1480
+
1481
+    if ( current_user_can( 'read_post', $post->ID ) ) {
1482
+        if ( 'draft' === $post->post_status || empty( $post->post_name ) ) {
1483
+            $view_link      = get_preview_post_link( $post );
1484
+            $preview_target = " target='wp-preview-{$post->ID}'";
1485
+        } else {
1486
+            if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
1487
+                $view_link = get_permalink( $post );
1488
+            } else {
1489
+                // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set.
1490
+                $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
1491
+            }
1492
+        }
1493
+    }
1494
+
1495
+    // Permalinks without a post/page name placeholder don't have anything to edit.
1496
+    if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
1497
+        $return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
1498
+
1499
+        if ( false !== $view_link ) {
1500
+            $display_link = urldecode( $view_link );
1501
+            $return      .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . esc_html( $display_link ) . "</a>\n";
1502
+        } else {
1503
+            $return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
1504
+        }
1505
+
1506
+        // Encourage a pretty permalink setting.
1507
+        if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' )
1508
+            && ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $id )
1509
+        ) {
1510
+            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small">' . __( 'Change Permalink Structure' ) . "</a></span>\n";
1511
+        }
1512
+    } else {
1513
+        if ( mb_strlen( $post_name ) > 34 ) {
1514
+            $post_name_abridged = mb_substr( $post_name, 0, 16 ) . '&hellip;' . mb_substr( $post_name, -16 );
1515
+        } else {
1516
+            $post_name_abridged = $post_name;
1517
+        }
1518
+
1519
+        $post_name_html = '<span id="editable-post-name">' . esc_html( $post_name_abridged ) . '</span>';
1520
+        $display_link   = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, esc_html( urldecode( $permalink ) ) );
1521
+
1522
+        $return  = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
1523
+        $return .= '<span id="sample-permalink"><a href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $display_link . "</a></span>\n";
1524
+        $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
1525
+        $return .= '<span id="edit-slug-buttons"><button type="button" class="edit-slug button button-small hide-if-no-js" aria-label="' . __( 'Edit permalink' ) . '">' . __( 'Edit' ) . "</button></span>\n";
1526
+        $return .= '<span id="editable-post-name-full">' . esc_html( $post_name ) . "</span>\n";
1527
+    }
1528
+
1529
+    /**
1530
+     * Filters the sample permalink HTML markup.
1531
+     *
1532
+     * @since 2.9.0
1533
+     * @since 4.4.0 Added `$post` parameter.
1534
+     *
1535
+     * @param string  $return    Sample permalink HTML markup.
1536
+     * @param int     $post_id   Post ID.
1537
+     * @param string  $new_title New sample permalink title.
1538
+     * @param string  $new_slug  New sample permalink slug.
1539
+     * @param WP_Post $post      Post object.
1540
+     */
1541
+    $return = apply_filters( 'get_sample_permalink_html', $return, $post->ID, $new_title, $new_slug, $post );
1542
+
1543
+    return $return;
1544 1544
 }
1545 1545
 
1546 1546
 /**
@@ -1554,67 +1554,67 @@  discard block
 block discarded – undo
1554 1554
  * @return string The post thumbnail HTML.
1555 1555
  */
1556 1556
 function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
1557
-	$_wp_additional_image_sizes = wp_get_additional_image_sizes();
1558
-
1559
-	$post               = get_post( $post );
1560
-	$post_type_object   = get_post_type_object( $post->post_type );
1561
-	$set_thumbnail_link = '<p class="hide-if-no-js"><a href="%s" id="set-post-thumbnail"%s class="thickbox">%s</a></p>';
1562
-	$upload_iframe_src  = get_upload_iframe_src( 'image', $post->ID );
1563
-
1564
-	$content = sprintf(
1565
-		$set_thumbnail_link,
1566
-		esc_url( $upload_iframe_src ),
1567
-		'', // Empty when there's no featured image set, `aria-describedby` attribute otherwise.
1568
-		esc_html( $post_type_object->labels->set_featured_image )
1569
-	);
1570
-
1571
-	if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
1572
-		$size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 );
1573
-
1574
-		/**
1575
-		 * Filters the size used to display the post thumbnail image in the 'Featured image' meta box.
1576
-		 *
1577
-		 * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail'
1578
-		 * image size is registered, which differs from the 'thumbnail' image size
1579
-		 * managed via the Settings > Media screen.
1580
-		 *
1581
-		 * @since 4.4.0
1582
-		 *
1583
-		 * @param string|int[] $size         Requested image size. Can be any registered image size name, or
1584
-		 *                                   an array of width and height values in pixels (in that order).
1585
-		 * @param int          $thumbnail_id Post thumbnail attachment ID.
1586
-		 * @param WP_Post      $post         The post object associated with the thumbnail.
1587
-		 */
1588
-		$size = apply_filters( 'admin_post_thumbnail_size', $size, $thumbnail_id, $post );
1589
-
1590
-		$thumbnail_html = wp_get_attachment_image( $thumbnail_id, $size );
1591
-
1592
-		if ( ! empty( $thumbnail_html ) ) {
1593
-			$content  = sprintf(
1594
-				$set_thumbnail_link,
1595
-				esc_url( $upload_iframe_src ),
1596
-				' aria-describedby="set-post-thumbnail-desc"',
1597
-				$thumbnail_html
1598
-			);
1599
-			$content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . __( 'Click the image to edit or update' ) . '</p>';
1600
-			$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
1601
-		}
1602
-	}
1603
-
1604
-	$content .= '<input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />';
1605
-
1606
-	/**
1607
-	 * Filters the admin post thumbnail HTML markup to return.
1608
-	 *
1609
-	 * @since 2.9.0
1610
-	 * @since 3.5.0 Added the `$post_id` parameter.
1611
-	 * @since 4.6.0 Added the `$thumbnail_id` parameter.
1612
-	 *
1613
-	 * @param string   $content      Admin post thumbnail HTML markup.
1614
-	 * @param int      $post_id      Post ID.
1615
-	 * @param int|null $thumbnail_id Thumbnail attachment ID, or null if there isn't one.
1616
-	 */
1617
-	return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID, $thumbnail_id );
1557
+    $_wp_additional_image_sizes = wp_get_additional_image_sizes();
1558
+
1559
+    $post               = get_post( $post );
1560
+    $post_type_object   = get_post_type_object( $post->post_type );
1561
+    $set_thumbnail_link = '<p class="hide-if-no-js"><a href="%s" id="set-post-thumbnail"%s class="thickbox">%s</a></p>';
1562
+    $upload_iframe_src  = get_upload_iframe_src( 'image', $post->ID );
1563
+
1564
+    $content = sprintf(
1565
+        $set_thumbnail_link,
1566
+        esc_url( $upload_iframe_src ),
1567
+        '', // Empty when there's no featured image set, `aria-describedby` attribute otherwise.
1568
+        esc_html( $post_type_object->labels->set_featured_image )
1569
+    );
1570
+
1571
+    if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
1572
+        $size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 );
1573
+
1574
+        /**
1575
+         * Filters the size used to display the post thumbnail image in the 'Featured image' meta box.
1576
+         *
1577
+         * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail'
1578
+         * image size is registered, which differs from the 'thumbnail' image size
1579
+         * managed via the Settings > Media screen.
1580
+         *
1581
+         * @since 4.4.0
1582
+         *
1583
+         * @param string|int[] $size         Requested image size. Can be any registered image size name, or
1584
+         *                                   an array of width and height values in pixels (in that order).
1585
+         * @param int          $thumbnail_id Post thumbnail attachment ID.
1586
+         * @param WP_Post      $post         The post object associated with the thumbnail.
1587
+         */
1588
+        $size = apply_filters( 'admin_post_thumbnail_size', $size, $thumbnail_id, $post );
1589
+
1590
+        $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $size );
1591
+
1592
+        if ( ! empty( $thumbnail_html ) ) {
1593
+            $content  = sprintf(
1594
+                $set_thumbnail_link,
1595
+                esc_url( $upload_iframe_src ),
1596
+                ' aria-describedby="set-post-thumbnail-desc"',
1597
+                $thumbnail_html
1598
+            );
1599
+            $content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . __( 'Click the image to edit or update' ) . '</p>';
1600
+            $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
1601
+        }
1602
+    }
1603
+
1604
+    $content .= '<input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />';
1605
+
1606
+    /**
1607
+     * Filters the admin post thumbnail HTML markup to return.
1608
+     *
1609
+     * @since 2.9.0
1610
+     * @since 3.5.0 Added the `$post_id` parameter.
1611
+     * @since 4.6.0 Added the `$thumbnail_id` parameter.
1612
+     *
1613
+     * @param string   $content      Admin post thumbnail HTML markup.
1614
+     * @param int      $post_id      Post ID.
1615
+     * @param int|null $thumbnail_id Thumbnail attachment ID, or null if there isn't one.
1616
+     */
1617
+    return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID, $thumbnail_id );
1618 1618
 }
1619 1619
 
1620 1620
 /**
@@ -1627,32 +1627,32 @@  discard block
 block discarded – undo
1627 1627
  *                   the user with lock does not exist, or the post is locked by current user.
1628 1628
  */
1629 1629
 function wp_check_post_lock( $post_id ) {
1630
-	$post = get_post( $post_id );
1631
-	if ( ! $post ) {
1632
-		return false;
1633
-	}
1630
+    $post = get_post( $post_id );
1631
+    if ( ! $post ) {
1632
+        return false;
1633
+    }
1634 1634
 
1635
-	$lock = get_post_meta( $post->ID, '_edit_lock', true );
1636
-	if ( ! $lock ) {
1637
-		return false;
1638
-	}
1635
+    $lock = get_post_meta( $post->ID, '_edit_lock', true );
1636
+    if ( ! $lock ) {
1637
+        return false;
1638
+    }
1639 1639
 
1640
-	$lock = explode( ':', $lock );
1641
-	$time = $lock[0];
1642
-	$user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
1640
+    $lock = explode( ':', $lock );
1641
+    $time = $lock[0];
1642
+    $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
1643 1643
 
1644
-	if ( ! get_userdata( $user ) ) {
1645
-		return false;
1646
-	}
1644
+    if ( ! get_userdata( $user ) ) {
1645
+        return false;
1646
+    }
1647 1647
 
1648
-	/** This filter is documented in wp-admin/includes/ajax-actions.php */
1649
-	$time_window = apply_filters( 'wp_check_post_lock_window', 150 );
1648
+    /** This filter is documented in wp-admin/includes/ajax-actions.php */
1649
+    $time_window = apply_filters( 'wp_check_post_lock_window', 150 );
1650 1650
 
1651
-	if ( $time && $time > time() - $time_window && get_current_user_id() != $user ) {
1652
-		return $user;
1653
-	}
1651
+    if ( $time && $time > time() - $time_window && get_current_user_id() != $user ) {
1652
+        return $user;
1653
+    }
1654 1654
 
1655
-	return false;
1655
+    return false;
1656 1656
 }
1657 1657
 
1658 1658
 /**
@@ -1670,22 +1670,22 @@  discard block
 block discarded – undo
1670 1670
  * }
1671 1671
  */
1672 1672
 function wp_set_post_lock( $post_id ) {
1673
-	$post = get_post( $post_id );
1674
-	if ( ! $post ) {
1675
-		return false;
1676
-	}
1673
+    $post = get_post( $post_id );
1674
+    if ( ! $post ) {
1675
+        return false;
1676
+    }
1677 1677
 
1678
-	$user_id = get_current_user_id();
1679
-	if ( 0 == $user_id ) {
1680
-		return false;
1681
-	}
1678
+    $user_id = get_current_user_id();
1679
+    if ( 0 == $user_id ) {
1680
+        return false;
1681
+    }
1682 1682
 
1683
-	$now  = time();
1684
-	$lock = "$now:$user_id";
1683
+    $now  = time();
1684
+    $lock = "$now:$user_id";
1685 1685
 
1686
-	update_post_meta( $post->ID, '_edit_lock', $lock );
1686
+    update_post_meta( $post->ID, '_edit_lock', $lock );
1687 1687
 
1688
-	return array( $now, $user_id );
1688
+    return array( $now, $user_id );
1689 1689
 }
1690 1690
 
1691 1691
 /**
@@ -1694,134 +1694,134 @@  discard block
 block discarded – undo
1694 1694
  * @since 2.8.5
1695 1695
  */
1696 1696
 function _admin_notice_post_locked() {
1697
-	$post = get_post();
1698
-	if ( ! $post ) {
1699
-		return;
1700
-	}
1701
-
1702
-	$user    = null;
1703
-	$user_id = wp_check_post_lock( $post->ID );
1704
-	if ( $user_id ) {
1705
-		$user = get_userdata( $user_id );
1706
-	}
1707
-
1708
-	if ( $user ) {
1709
-		/**
1710
-		 * Filters whether to show the post locked dialog.
1711
-		 *
1712
-		 * Returning false from the filter will prevent the dialog from being displayed.
1713
-		 *
1714
-		 * @since 3.6.0
1715
-		 *
1716
-		 * @param bool    $display Whether to display the dialog. Default true.
1717
-		 * @param WP_Post $post    Post object.
1718
-		 * @param WP_User $user    The user with the lock for the post.
1719
-		 */
1720
-		if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) {
1721
-			return;
1722
-		}
1723
-
1724
-		$locked = true;
1725
-	} else {
1726
-		$locked = false;
1727
-	}
1728
-
1729
-	$sendback = wp_get_referer();
1730
-	if ( $locked && $sendback && false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) {
1731
-
1732
-		$sendback_text = __( 'Go back' );
1733
-	} else {
1734
-		$sendback = admin_url( 'edit.php' );
1735
-
1736
-		if ( 'post' !== $post->post_type ) {
1737
-			$sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
1738
-		}
1739
-
1740
-		$sendback_text = get_post_type_object( $post->post_type )->labels->all_items;
1741
-	}
1742
-
1743
-	$hidden = $locked ? '' : ' hidden';
1744
-
1745
-	?>
1697
+    $post = get_post();
1698
+    if ( ! $post ) {
1699
+        return;
1700
+    }
1701
+
1702
+    $user    = null;
1703
+    $user_id = wp_check_post_lock( $post->ID );
1704
+    if ( $user_id ) {
1705
+        $user = get_userdata( $user_id );
1706
+    }
1707
+
1708
+    if ( $user ) {
1709
+        /**
1710
+         * Filters whether to show the post locked dialog.
1711
+         *
1712
+         * Returning false from the filter will prevent the dialog from being displayed.
1713
+         *
1714
+         * @since 3.6.0
1715
+         *
1716
+         * @param bool    $display Whether to display the dialog. Default true.
1717
+         * @param WP_Post $post    Post object.
1718
+         * @param WP_User $user    The user with the lock for the post.
1719
+         */
1720
+        if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) {
1721
+            return;
1722
+        }
1723
+
1724
+        $locked = true;
1725
+    } else {
1726
+        $locked = false;
1727
+    }
1728
+
1729
+    $sendback = wp_get_referer();
1730
+    if ( $locked && $sendback && false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) {
1731
+
1732
+        $sendback_text = __( 'Go back' );
1733
+    } else {
1734
+        $sendback = admin_url( 'edit.php' );
1735
+
1736
+        if ( 'post' !== $post->post_type ) {
1737
+            $sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
1738
+        }
1739
+
1740
+        $sendback_text = get_post_type_object( $post->post_type )->labels->all_items;
1741
+    }
1742
+
1743
+    $hidden = $locked ? '' : ' hidden';
1744
+
1745
+    ?>
1746 1746
 	<div id="post-lock-dialog" class="notification-dialog-wrap<?php echo $hidden; ?>">
1747 1747
 	<div class="notification-dialog-background"></div>
1748 1748
 	<div class="notification-dialog">
1749 1749
 	<?php
1750 1750
 
1751
-	if ( $locked ) {
1752
-		$query_args = array();
1753
-		if ( get_post_type_object( $post->post_type )->public ) {
1754
-			if ( 'publish' === $post->post_status || $user->ID != $post->post_author ) {
1755
-				// Latest content is in autosave.
1756
-				$nonce                       = wp_create_nonce( 'post_preview_' . $post->ID );
1757
-				$query_args['preview_id']    = $post->ID;
1758
-				$query_args['preview_nonce'] = $nonce;
1759
-			}
1760
-		}
1761
-
1762
-		$preview_link = get_preview_post_link( $post->ID, $query_args );
1763
-
1764
-		/**
1765
-		 * Filters whether to allow the post lock to be overridden.
1766
-		 *
1767
-		 * Returning false from the filter will disable the ability
1768
-		 * to override the post lock.
1769
-		 *
1770
-		 * @since 3.6.0
1771
-		 *
1772
-		 * @param bool    $override Whether to allow the post lock to be overridden. Default true.
1773
-		 * @param WP_Post $post     Post object.
1774
-		 * @param WP_User $user     The user with the lock for the post.
1775
-		 */
1776
-		$override = apply_filters( 'override_post_lock', true, $post, $user );
1777
-		$tab_last = $override ? '' : ' wp-tab-last';
1778
-
1779
-		?>
1751
+    if ( $locked ) {
1752
+        $query_args = array();
1753
+        if ( get_post_type_object( $post->post_type )->public ) {
1754
+            if ( 'publish' === $post->post_status || $user->ID != $post->post_author ) {
1755
+                // Latest content is in autosave.
1756
+                $nonce                       = wp_create_nonce( 'post_preview_' . $post->ID );
1757
+                $query_args['preview_id']    = $post->ID;
1758
+                $query_args['preview_nonce'] = $nonce;
1759
+            }
1760
+        }
1761
+
1762
+        $preview_link = get_preview_post_link( $post->ID, $query_args );
1763
+
1764
+        /**
1765
+         * Filters whether to allow the post lock to be overridden.
1766
+         *
1767
+         * Returning false from the filter will disable the ability
1768
+         * to override the post lock.
1769
+         *
1770
+         * @since 3.6.0
1771
+         *
1772
+         * @param bool    $override Whether to allow the post lock to be overridden. Default true.
1773
+         * @param WP_Post $post     Post object.
1774
+         * @param WP_User $user     The user with the lock for the post.
1775
+         */
1776
+        $override = apply_filters( 'override_post_lock', true, $post, $user );
1777
+        $tab_last = $override ? '' : ' wp-tab-last';
1778
+
1779
+        ?>
1780 1780
 		<div class="post-locked-message">
1781 1781
 		<div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div>
1782 1782
 		<p class="currently-editing wp-tab-first" tabindex="0">
1783 1783
 		<?php
1784
-		if ( $override ) {
1785
-			/* translators: %s: User's display name. */
1786
-			printf( __( '%s is currently editing this post. Do you want to take over?' ), esc_html( $user->display_name ) );
1787
-		} else {
1788
-			/* translators: %s: User's display name. */
1789
-			printf( __( '%s is currently editing this post.' ), esc_html( $user->display_name ) );
1790
-		}
1791
-		?>
1784
+        if ( $override ) {
1785
+            /* translators: %s: User's display name. */
1786
+            printf( __( '%s is currently editing this post. Do you want to take over?' ), esc_html( $user->display_name ) );
1787
+        } else {
1788
+            /* translators: %s: User's display name. */
1789
+            printf( __( '%s is currently editing this post.' ), esc_html( $user->display_name ) );
1790
+        }
1791
+        ?>
1792 1792
 		</p>
1793 1793
 		<?php
1794
-		/**
1795
-		 * Fires inside the post locked dialog before the buttons are displayed.
1796
-		 *
1797
-		 * @since 3.6.0
1798
-		 * @since 5.4.0 The $user parameter was added.
1799
-		 *
1800
-		 * @param WP_Post $post Post object.
1801
-		 * @param WP_User $user The user with the lock for the post.
1802
-		 */
1803
-		do_action( 'post_locked_dialog', $post, $user );
1804
-		?>
1794
+        /**
1795
+         * Fires inside the post locked dialog before the buttons are displayed.
1796
+         *
1797
+         * @since 3.6.0
1798
+         * @since 5.4.0 The $user parameter was added.
1799
+         *
1800
+         * @param WP_Post $post Post object.
1801
+         * @param WP_User $user The user with the lock for the post.
1802
+         */
1803
+        do_action( 'post_locked_dialog', $post, $user );
1804
+        ?>
1805 1805
 		<p>
1806 1806
 		<a class="button" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a>
1807 1807
 		<?php if ( $preview_link ) { ?>
1808 1808
 		<a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e( 'Preview' ); ?></a>
1809 1809
 			<?php
1810
-		}
1810
+        }
1811 1811
 
1812
-		// Allow plugins to prevent some users overriding the post lock.
1813
-		if ( $override ) {
1814
-			?>
1812
+        // Allow plugins to prevent some users overriding the post lock.
1813
+        if ( $override ) {
1814
+            ?>
1815 1815
 	<a class="button button-primary wp-tab-last" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', wp_nonce_url( get_edit_post_link( $post->ID, 'url' ), 'lock-post_' . $post->ID ) ) ); ?>"><?php _e( 'Take over' ); ?></a>
1816 1816
 			<?php
1817
-		}
1817
+        }
1818 1818
 
1819
-		?>
1819
+        ?>
1820 1820
 		</p>
1821 1821
 		</div>
1822 1822
 		<?php
1823
-	} else {
1824
-		?>
1823
+    } else {
1824
+        ?>
1825 1825
 		<div class="post-taken-over">
1826 1826
 			<div class="post-locked-avatar"></div>
1827 1827
 			<p class="wp-tab-first" tabindex="0">
@@ -1830,21 +1830,21 @@  discard block
 block discarded – undo
1830 1830
 			<span class="locked-saved hidden"><?php _e( 'Your latest changes were saved as a revision.' ); ?></span>
1831 1831
 			</p>
1832 1832
 			<?php
1833
-			/**
1834
-			 * Fires inside the dialog displayed when a user has lost the post lock.
1835
-			 *
1836
-			 * @since 3.6.0
1837
-			 *
1838
-			 * @param WP_Post $post Post object.
1839
-			 */
1840
-			do_action( 'post_lock_lost_dialog', $post );
1841
-			?>
1833
+            /**
1834
+             * Fires inside the dialog displayed when a user has lost the post lock.
1835
+             *
1836
+             * @since 3.6.0
1837
+             *
1838
+             * @param WP_Post $post Post object.
1839
+             */
1840
+            do_action( 'post_lock_lost_dialog', $post );
1841
+            ?>
1842 1842
 			<p><a class="button button-primary wp-tab-last" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a></p>
1843 1843
 		</div>
1844 1844
 		<?php
1845
-	}
1845
+    }
1846 1846
 
1847
-	?>
1847
+    ?>
1848 1848
 	</div>
1849 1849
 	</div>
1850 1850
 	<?php
@@ -1860,61 +1860,61 @@  discard block
 block discarded – undo
1860 1860
  * @return int|WP_Error The autosave revision ID. WP_Error or 0 on error.
1861 1861
  */
1862 1862
 function wp_create_post_autosave( $post_data ) {
1863
-	if ( is_numeric( $post_data ) ) {
1864
-		$post_id   = $post_data;
1865
-		$post_data = $_POST;
1866
-	} else {
1867
-		$post_id = (int) $post_data['post_ID'];
1868
-	}
1869
-
1870
-	$post_data = _wp_translate_postdata( true, $post_data );
1871
-	if ( is_wp_error( $post_data ) ) {
1872
-		return $post_data;
1873
-	}
1874
-	$post_data = _wp_get_allowed_postdata( $post_data );
1875
-
1876
-	$post_author = get_current_user_id();
1877
-
1878
-	// Store one autosave per author. If there is already an autosave, overwrite it.
1879
-	$old_autosave = wp_get_post_autosave( $post_id, $post_author );
1880
-	if ( $old_autosave ) {
1881
-		$new_autosave                = _wp_post_revision_data( $post_data, true );
1882
-		$new_autosave['ID']          = $old_autosave->ID;
1883
-		$new_autosave['post_author'] = $post_author;
1884
-
1885
-		$post = get_post( $post_id );
1886
-
1887
-		// If the new autosave has the same content as the post, delete the autosave.
1888
-		$autosave_is_different = false;
1889
-		foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
1890
-			if ( normalize_whitespace( $new_autosave[ $field ] ) !== normalize_whitespace( $post->$field ) ) {
1891
-				$autosave_is_different = true;
1892
-				break;
1893
-			}
1894
-		}
1895
-
1896
-		if ( ! $autosave_is_different ) {
1897
-			wp_delete_post_revision( $old_autosave->ID );
1898
-			return 0;
1899
-		}
1900
-
1901
-		/**
1902
-		 * Fires before an autosave is stored.
1903
-		 *
1904
-		 * @since 4.1.0
1905
-		 *
1906
-		 * @param array $new_autosave Post array - the autosave that is about to be saved.
1907
-		 */
1908
-		do_action( 'wp_creating_autosave', $new_autosave );
1909
-
1910
-		return wp_update_post( $new_autosave );
1911
-	}
1912
-
1913
-	// _wp_put_post_revision() expects unescaped.
1914
-	$post_data = wp_unslash( $post_data );
1915
-
1916
-	// Otherwise create the new autosave as a special post revision.
1917
-	return _wp_put_post_revision( $post_data, true );
1863
+    if ( is_numeric( $post_data ) ) {
1864
+        $post_id   = $post_data;
1865
+        $post_data = $_POST;
1866
+    } else {
1867
+        $post_id = (int) $post_data['post_ID'];
1868
+    }
1869
+
1870
+    $post_data = _wp_translate_postdata( true, $post_data );
1871
+    if ( is_wp_error( $post_data ) ) {
1872
+        return $post_data;
1873
+    }
1874
+    $post_data = _wp_get_allowed_postdata( $post_data );
1875
+
1876
+    $post_author = get_current_user_id();
1877
+
1878
+    // Store one autosave per author. If there is already an autosave, overwrite it.
1879
+    $old_autosave = wp_get_post_autosave( $post_id, $post_author );
1880
+    if ( $old_autosave ) {
1881
+        $new_autosave                = _wp_post_revision_data( $post_data, true );
1882
+        $new_autosave['ID']          = $old_autosave->ID;
1883
+        $new_autosave['post_author'] = $post_author;
1884
+
1885
+        $post = get_post( $post_id );
1886
+
1887
+        // If the new autosave has the same content as the post, delete the autosave.
1888
+        $autosave_is_different = false;
1889
+        foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
1890
+            if ( normalize_whitespace( $new_autosave[ $field ] ) !== normalize_whitespace( $post->$field ) ) {
1891
+                $autosave_is_different = true;
1892
+                break;
1893
+            }
1894
+        }
1895
+
1896
+        if ( ! $autosave_is_different ) {
1897
+            wp_delete_post_revision( $old_autosave->ID );
1898
+            return 0;
1899
+        }
1900
+
1901
+        /**
1902
+         * Fires before an autosave is stored.
1903
+         *
1904
+         * @since 4.1.0
1905
+         *
1906
+         * @param array $new_autosave Post array - the autosave that is about to be saved.
1907
+         */
1908
+        do_action( 'wp_creating_autosave', $new_autosave );
1909
+
1910
+        return wp_update_post( $new_autosave );
1911
+    }
1912
+
1913
+    // _wp_put_post_revision() expects unescaped.
1914
+    $post_data = wp_unslash( $post_data );
1915
+
1916
+    // Otherwise create the new autosave as a special post revision.
1917
+    return _wp_put_post_revision( $post_data, true );
1918 1918
 }
1919 1919
 
1920 1920
 /**
@@ -1926,54 +1926,54 @@  discard block
 block discarded – undo
1926 1926
  */
1927 1927
 function post_preview() {
1928 1928
 
1929
-	$post_ID     = (int) $_POST['post_ID'];
1930
-	$_POST['ID'] = $post_ID;
1929
+    $post_ID     = (int) $_POST['post_ID'];
1930
+    $_POST['ID'] = $post_ID;
1931 1931
 
1932
-	$post = get_post( $post_ID );
1933
-	if ( ! $post ) {
1934
-		wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
1935
-	}
1932
+    $post = get_post( $post_ID );
1933
+    if ( ! $post ) {
1934
+        wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
1935
+    }
1936 1936
 
1937
-	if ( ! current_user_can( 'edit_post', $post->ID ) ) {
1938
-		wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
1939
-	}
1937
+    if ( ! current_user_can( 'edit_post', $post->ID ) ) {
1938
+        wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
1939
+    }
1940 1940
 
1941
-	$is_autosave = false;
1941
+    $is_autosave = false;
1942 1942
 
1943
-	if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
1944
-		&& ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status )
1945
-	) {
1946
-		$saved_post_id = edit_post();
1947
-	} else {
1948
-		$is_autosave = true;
1943
+    if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
1944
+        && ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status )
1945
+    ) {
1946
+        $saved_post_id = edit_post();
1947
+    } else {
1948
+        $is_autosave = true;
1949 1949
 
1950
-		if ( isset( $_POST['post_status'] ) && 'auto-draft' === $_POST['post_status'] ) {
1951
-			$_POST['post_status'] = 'draft';
1952
-		}
1950
+        if ( isset( $_POST['post_status'] ) && 'auto-draft' === $_POST['post_status'] ) {
1951
+            $_POST['post_status'] = 'draft';
1952
+        }
1953 1953
 
1954
-		$saved_post_id = wp_create_post_autosave( $post->ID );
1955
-	}
1954
+        $saved_post_id = wp_create_post_autosave( $post->ID );
1955
+    }
1956 1956
 
1957
-	if ( is_wp_error( $saved_post_id ) ) {
1958
-		wp_die( $saved_post_id->get_error_message() );
1959
-	}
1957
+    if ( is_wp_error( $saved_post_id ) ) {
1958
+        wp_die( $saved_post_id->get_error_message() );
1959
+    }
1960 1960
 
1961
-	$query_args = array();
1961
+    $query_args = array();
1962 1962
 
1963
-	if ( $is_autosave && $saved_post_id ) {
1964
-		$query_args['preview_id']    = $post->ID;
1965
-		$query_args['preview_nonce'] = wp_create_nonce( 'post_preview_' . $post->ID );
1963
+    if ( $is_autosave && $saved_post_id ) {
1964
+        $query_args['preview_id']    = $post->ID;
1965
+        $query_args['preview_nonce'] = wp_create_nonce( 'post_preview_' . $post->ID );
1966 1966
 
1967
-		if ( isset( $_POST['post_format'] ) ) {
1968
-			$query_args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] );
1969
-		}
1967
+        if ( isset( $_POST['post_format'] ) ) {
1968
+            $query_args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] );
1969
+        }
1970 1970
 
1971
-		if ( isset( $_POST['_thumbnail_id'] ) ) {
1972
-			$query_args['_thumbnail_id'] = ( (int) $_POST['_thumbnail_id'] <= 0 ) ? '-1' : (int) $_POST['_thumbnail_id'];
1973
-		}
1974
-	}
1971
+        if ( isset( $_POST['_thumbnail_id'] ) ) {
1972
+            $query_args['_thumbnail_id'] = ( (int) $_POST['_thumbnail_id'] <= 0 ) ? '-1' : (int) $_POST['_thumbnail_id'];
1973
+        }
1974
+    }
1975 1975
 
1976
-	return get_preview_post_link( $post, $query_args );
1976
+    return get_preview_post_link( $post, $query_args );
1977 1977
 }
1978 1978
 
1979 1979
 /**
@@ -1988,43 +1988,43 @@  discard block
 block discarded – undo
1988 1988
  *               The ID can be the draft post_id or the autosave revision post_id.
1989 1989
  */
1990 1990
 function wp_autosave( $post_data ) {
1991
-	// Back-compat.
1992
-	if ( ! defined( 'DOING_AUTOSAVE' ) ) {
1993
-		define( 'DOING_AUTOSAVE', true );
1994
-	}
1995
-
1996
-	$post_id              = (int) $post_data['post_id'];
1997
-	$post_data['ID']      = $post_id;
1998
-	$post_data['post_ID'] = $post_id;
1999
-
2000
-	if ( false === wp_verify_nonce( $post_data['_wpnonce'], 'update-post_' . $post_id ) ) {
2001
-		return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ) );
2002
-	}
2003
-
2004
-	$post = get_post( $post_id );
2005
-
2006
-	if ( ! current_user_can( 'edit_post', $post->ID ) ) {
2007
-		return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to edit this item.' ) );
2008
-	}
2009
-
2010
-	if ( 'auto-draft' === $post->post_status ) {
2011
-		$post_data['post_status'] = 'draft';
2012
-	}
2013
-
2014
-	if ( 'page' !== $post_data['post_type'] && ! empty( $post_data['catslist'] ) ) {
2015
-		$post_data['post_category'] = explode( ',', $post_data['catslist'] );
2016
-	}
2017
-
2018
-	if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
2019
-		&& ( 'auto-draft' === $post->post_status || 'draft' === $post->post_status )
2020
-	) {
2021
-		// Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked.
2022
-		return edit_post( wp_slash( $post_data ) );
2023
-	} else {
2024
-		// Non-drafts or other users' drafts are not overwritten.
2025
-		// The autosave is stored in a special post revision for each user.
2026
-		return wp_create_post_autosave( wp_slash( $post_data ) );
2027
-	}
1991
+    // Back-compat.
1992
+    if ( ! defined( 'DOING_AUTOSAVE' ) ) {
1993
+        define( 'DOING_AUTOSAVE', true );
1994
+    }
1995
+
1996
+    $post_id              = (int) $post_data['post_id'];
1997
+    $post_data['ID']      = $post_id;
1998
+    $post_data['post_ID'] = $post_id;
1999
+
2000
+    if ( false === wp_verify_nonce( $post_data['_wpnonce'], 'update-post_' . $post_id ) ) {
2001
+        return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ) );
2002
+    }
2003
+
2004
+    $post = get_post( $post_id );
2005
+
2006
+    if ( ! current_user_can( 'edit_post', $post->ID ) ) {
2007
+        return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to edit this item.' ) );
2008
+    }
2009
+
2010
+    if ( 'auto-draft' === $post->post_status ) {
2011
+        $post_data['post_status'] = 'draft';
2012
+    }
2013
+
2014
+    if ( 'page' !== $post_data['post_type'] && ! empty( $post_data['catslist'] ) ) {
2015
+        $post_data['post_category'] = explode( ',', $post_data['catslist'] );
2016
+    }
2017
+
2018
+    if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
2019
+        && ( 'auto-draft' === $post->post_status || 'draft' === $post->post_status )
2020
+    ) {
2021
+        // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked.
2022
+        return edit_post( wp_slash( $post_data ) );
2023
+    } else {
2024
+        // Non-drafts or other users' drafts are not overwritten.
2025
+        // The autosave is stored in a special post revision for each user.
2026
+        return wp_create_post_autosave( wp_slash( $post_data ) );
2027
+    }
2028 2028
 }
2029 2029
 
2030 2030
 /**
@@ -2035,47 +2035,47 @@  discard block
 block discarded – undo
2035 2035
  * @param int $post_id Optional. Post ID.
2036 2036
  */
2037 2037
 function redirect_post( $post_id = '' ) {
2038
-	if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) {
2039
-		$status = get_post_status( $post_id );
2040
-
2041
-		if ( isset( $_POST['publish'] ) ) {
2042
-			switch ( $status ) {
2043
-				case 'pending':
2044
-					$message = 8;
2045
-					break;
2046
-				case 'future':
2047
-					$message = 9;
2048
-					break;
2049
-				default:
2050
-					$message = 6;
2051
-			}
2052
-		} else {
2053
-			$message = 'draft' === $status ? 10 : 1;
2054
-		}
2055
-
2056
-		$location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
2057
-	} elseif ( isset( $_POST['addmeta'] ) && $_POST['addmeta'] ) {
2058
-		$location = add_query_arg( 'message', 2, wp_get_referer() );
2059
-		$location = explode( '#', $location );
2060
-		$location = $location[0] . '#postcustom';
2061
-	} elseif ( isset( $_POST['deletemeta'] ) && $_POST['deletemeta'] ) {
2062
-		$location = add_query_arg( 'message', 3, wp_get_referer() );
2063
-		$location = explode( '#', $location );
2064
-		$location = $location[0] . '#postcustom';
2065
-	} else {
2066
-		$location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
2067
-	}
2068
-
2069
-	/**
2070
-	 * Filters the post redirect destination URL.
2071
-	 *
2072
-	 * @since 2.9.0
2073
-	 *
2074
-	 * @param string $location The destination URL.
2075
-	 * @param int    $post_id  The post ID.
2076
-	 */
2077
-	wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
2078
-	exit;
2038
+    if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) {
2039
+        $status = get_post_status( $post_id );
2040
+
2041
+        if ( isset( $_POST['publish'] ) ) {
2042
+            switch ( $status ) {
2043
+                case 'pending':
2044
+                    $message = 8;
2045
+                    break;
2046
+                case 'future':
2047
+                    $message = 9;
2048
+                    break;
2049
+                default:
2050
+                    $message = 6;
2051
+            }
2052
+        } else {
2053
+            $message = 'draft' === $status ? 10 : 1;
2054
+        }
2055
+
2056
+        $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
2057
+    } elseif ( isset( $_POST['addmeta'] ) && $_POST['addmeta'] ) {
2058
+        $location = add_query_arg( 'message', 2, wp_get_referer() );
2059
+        $location = explode( '#', $location );
2060
+        $location = $location[0] . '#postcustom';
2061
+    } elseif ( isset( $_POST['deletemeta'] ) && $_POST['deletemeta'] ) {
2062
+        $location = add_query_arg( 'message', 3, wp_get_referer() );
2063
+        $location = explode( '#', $location );
2064
+        $location = $location[0] . '#postcustom';
2065
+    } else {
2066
+        $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
2067
+    }
2068
+
2069
+    /**
2070
+     * Filters the post redirect destination URL.
2071
+     *
2072
+     * @since 2.9.0
2073
+     *
2074
+     * @param string $location The destination URL.
2075
+     * @param int    $post_id  The post ID.
2076
+     */
2077
+    wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
2078
+    exit;
2079 2079
 }
2080 2080
 
2081 2081
 /**
@@ -2088,7 +2088,7 @@  discard block
 block discarded – undo
2088 2088
  * @return int[] Array of sanitized term IDs.
2089 2089
  */
2090 2090
 function taxonomy_meta_box_sanitize_cb_checkboxes( $taxonomy, $terms ) {
2091
-	return array_map( 'intval', $terms );
2091
+    return array_map( 'intval', $terms );
2092 2092
 }
2093 2093
 
2094 2094
 /**
@@ -2101,44 +2101,44 @@  discard block
 block discarded – undo
2101 2101
  * @return array
2102 2102
  */
2103 2103
 function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
2104
-	/*
2104
+    /*
2105 2105
 	 * Assume that a 'tax_input' string is a comma-separated list of term names.
2106 2106
 	 * Some languages may use a character other than a comma as a delimiter, so we standardize on
2107 2107
 	 * commas before parsing the list.
2108 2108
 	 */
2109
-	if ( ! is_array( $terms ) ) {
2110
-		$comma = _x( ',', 'tag delimiter' );
2111
-		if ( ',' !== $comma ) {
2112
-			$terms = str_replace( $comma, ',', $terms );
2113
-		}
2114
-		$terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
2115
-	}
2116
-
2117
-	$clean_terms = array();
2118
-	foreach ( $terms as $term ) {
2119
-		// Empty terms are invalid input.
2120
-		if ( empty( $term ) ) {
2121
-			continue;
2122
-		}
2123
-
2124
-		$_term = get_terms(
2125
-			array(
2126
-				'taxonomy'   => $taxonomy,
2127
-				'name'       => $term,
2128
-				'fields'     => 'ids',
2129
-				'hide_empty' => false,
2130
-			)
2131
-		);
2132
-
2133
-		if ( ! empty( $_term ) ) {
2134
-			$clean_terms[] = (int) $_term[0];
2135
-		} else {
2136
-			// No existing term was found, so pass the string. A new term will be created.
2137
-			$clean_terms[] = $term;
2138
-		}
2139
-	}
2140
-
2141
-	return $clean_terms;
2109
+    if ( ! is_array( $terms ) ) {
2110
+        $comma = _x( ',', 'tag delimiter' );
2111
+        if ( ',' !== $comma ) {
2112
+            $terms = str_replace( $comma, ',', $terms );
2113
+        }
2114
+        $terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
2115
+    }
2116
+
2117
+    $clean_terms = array();
2118
+    foreach ( $terms as $term ) {
2119
+        // Empty terms are invalid input.
2120
+        if ( empty( $term ) ) {
2121
+            continue;
2122
+        }
2123
+
2124
+        $_term = get_terms(
2125
+            array(
2126
+                'taxonomy'   => $taxonomy,
2127
+                'name'       => $term,
2128
+                'fields'     => 'ids',
2129
+                'hide_empty' => false,
2130
+            )
2131
+        );
2132
+
2133
+        if ( ! empty( $_term ) ) {
2134
+            $clean_terms[] = (int) $_term[0];
2135
+        } else {
2136
+            // No existing term was found, so pass the string. A new term will be created.
2137
+            $clean_terms[] = $term;
2138
+        }
2139
+    }
2140
+
2141
+    return $clean_terms;
2142 2142
 }
2143 2143
 
2144 2144
 /**
@@ -2150,29 +2150,29 @@  discard block
 block discarded – undo
2150 2150
  * @return bool Whether the post can be edited in the block editor.
2151 2151
  */
2152 2152
 function use_block_editor_for_post( $post ) {
2153
-	$post = get_post( $post );
2154
-
2155
-	if ( ! $post ) {
2156
-		return false;
2157
-	}
2158
-
2159
-	// We're in the meta box loader, so don't use the block editor.
2160
-	if ( isset( $_GET['meta-box-loader'] ) ) {
2161
-		check_admin_referer( 'meta-box-loader', 'meta-box-loader-nonce' );
2162
-		return false;
2163
-	}
2164
-
2165
-	$use_block_editor = use_block_editor_for_post_type( $post->post_type );
2166
-
2167
-	/**
2168
-	 * Filters whether a post is able to be edited in the block editor.
2169
-	 *
2170
-	 * @since 5.0.0
2171
-	 *
2172
-	 * @param bool    $use_block_editor Whether the post can be edited or not.
2173
-	 * @param WP_Post $post             The post being checked.
2174
-	 */
2175
-	return apply_filters( 'use_block_editor_for_post', $use_block_editor, $post );
2153
+    $post = get_post( $post );
2154
+
2155
+    if ( ! $post ) {
2156
+        return false;
2157
+    }
2158
+
2159
+    // We're in the meta box loader, so don't use the block editor.
2160
+    if ( isset( $_GET['meta-box-loader'] ) ) {
2161
+        check_admin_referer( 'meta-box-loader', 'meta-box-loader-nonce' );
2162
+        return false;
2163
+    }
2164
+
2165
+    $use_block_editor = use_block_editor_for_post_type( $post->post_type );
2166
+
2167
+    /**
2168
+     * Filters whether a post is able to be edited in the block editor.
2169
+     *
2170
+     * @since 5.0.0
2171
+     *
2172
+     * @param bool    $use_block_editor Whether the post can be edited or not.
2173
+     * @param WP_Post $post             The post being checked.
2174
+     */
2175
+    return apply_filters( 'use_block_editor_for_post', $use_block_editor, $post );
2176 2176
 }
2177 2177
 
2178 2178
 /**
@@ -2187,28 +2187,28 @@  discard block
 block discarded – undo
2187 2187
  * @return bool Whether the post type can be edited with the block editor.
2188 2188
  */
2189 2189
 function use_block_editor_for_post_type( $post_type ) {
2190
-	if ( ! post_type_exists( $post_type ) ) {
2191
-		return false;
2192
-	}
2193
-
2194
-	if ( ! post_type_supports( $post_type, 'editor' ) ) {
2195
-		return false;
2196
-	}
2197
-
2198
-	$post_type_object = get_post_type_object( $post_type );
2199
-	if ( $post_type_object && ! $post_type_object->show_in_rest ) {
2200
-		return false;
2201
-	}
2202
-
2203
-	/**
2204
-	 * Filters whether a post is able to be edited in the block editor.
2205
-	 *
2206
-	 * @since 5.0.0
2207
-	 *
2208
-	 * @param bool   $use_block_editor  Whether the post type can be edited or not. Default true.
2209
-	 * @param string $post_type         The post type being checked.
2210
-	 */
2211
-	return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
2190
+    if ( ! post_type_exists( $post_type ) ) {
2191
+        return false;
2192
+    }
2193
+
2194
+    if ( ! post_type_supports( $post_type, 'editor' ) ) {
2195
+        return false;
2196
+    }
2197
+
2198
+    $post_type_object = get_post_type_object( $post_type );
2199
+    if ( $post_type_object && ! $post_type_object->show_in_rest ) {
2200
+        return false;
2201
+    }
2202
+
2203
+    /**
2204
+     * Filters whether a post is able to be edited in the block editor.
2205
+     *
2206
+     * @since 5.0.0
2207
+     *
2208
+     * @param bool   $use_block_editor  Whether the post type can be edited or not. Default true.
2209
+     * @param string $post_type         The post type being checked.
2210
+     */
2211
+    return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
2212 2212
 }
2213 2213
 
2214 2214
 /**
@@ -2222,42 +2222,42 @@  discard block
 block discarded – undo
2222 2222
  * @return array An associative array of registered block data.
2223 2223
  */
2224 2224
 function get_block_editor_server_block_settings() {
2225
-	$block_registry = WP_Block_Type_Registry::get_instance();
2226
-	$blocks         = array();
2227
-	$fields_to_pick = array(
2228
-		'api_version'      => 'apiVersion',
2229
-		'title'            => 'title',
2230
-		'description'      => 'description',
2231
-		'icon'             => 'icon',
2232
-		'attributes'       => 'attributes',
2233
-		'provides_context' => 'providesContext',
2234
-		'uses_context'     => 'usesContext',
2235
-		'supports'         => 'supports',
2236
-		'category'         => 'category',
2237
-		'styles'           => 'styles',
2238
-		'textdomain'       => 'textdomain',
2239
-		'parent'           => 'parent',
2240
-		'ancestor'         => 'ancestor',
2241
-		'keywords'         => 'keywords',
2242
-		'example'          => 'example',
2243
-		'variations'       => 'variations',
2244
-	);
2245
-
2246
-	foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
2247
-		foreach ( $fields_to_pick as $field => $key ) {
2248
-			if ( ! isset( $block_type->{ $field } ) ) {
2249
-				continue;
2250
-			}
2251
-
2252
-			if ( ! isset( $blocks[ $block_name ] ) ) {
2253
-				$blocks[ $block_name ] = array();
2254
-			}
2255
-
2256
-			$blocks[ $block_name ][ $key ] = $block_type->{ $field };
2257
-		}
2258
-	}
2259
-
2260
-	return $blocks;
2225
+    $block_registry = WP_Block_Type_Registry::get_instance();
2226
+    $blocks         = array();
2227
+    $fields_to_pick = array(
2228
+        'api_version'      => 'apiVersion',
2229
+        'title'            => 'title',
2230
+        'description'      => 'description',
2231
+        'icon'             => 'icon',
2232
+        'attributes'       => 'attributes',
2233
+        'provides_context' => 'providesContext',
2234
+        'uses_context'     => 'usesContext',
2235
+        'supports'         => 'supports',
2236
+        'category'         => 'category',
2237
+        'styles'           => 'styles',
2238
+        'textdomain'       => 'textdomain',
2239
+        'parent'           => 'parent',
2240
+        'ancestor'         => 'ancestor',
2241
+        'keywords'         => 'keywords',
2242
+        'example'          => 'example',
2243
+        'variations'       => 'variations',
2244
+    );
2245
+
2246
+    foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
2247
+        foreach ( $fields_to_pick as $field => $key ) {
2248
+            if ( ! isset( $block_type->{ $field } ) ) {
2249
+                continue;
2250
+            }
2251
+
2252
+            if ( ! isset( $blocks[ $block_name ] ) ) {
2253
+                $blocks[ $block_name ] = array();
2254
+            }
2255
+
2256
+            $blocks[ $block_name ][ $key ] = $block_type->{ $field };
2257
+        }
2258
+    }
2259
+
2260
+    return $blocks;
2261 2261
 }
2262 2262
 
2263 2263
 /**
@@ -2266,27 +2266,27 @@  discard block
 block discarded – undo
2266 2266
  * @since 5.0.0
2267 2267
  */
2268 2268
 function the_block_editor_meta_boxes() {
2269
-	global $post, $current_screen, $wp_meta_boxes;
2270
-
2271
-	// Handle meta box state.
2272
-	$_original_meta_boxes = $wp_meta_boxes;
2273
-
2274
-	/**
2275
-	 * Fires right before the meta boxes are rendered.
2276
-	 *
2277
-	 * This allows for the filtering of meta box data, that should already be
2278
-	 * present by this point. Do not use as a means of adding meta box data.
2279
-	 *
2280
-	 * @since 5.0.0
2281
-	 *
2282
-	 * @param array $wp_meta_boxes Global meta box state.
2283
-	 */
2284
-	$wp_meta_boxes = apply_filters( 'filter_block_editor_meta_boxes', $wp_meta_boxes );
2285
-	$locations     = array( 'side', 'normal', 'advanced' );
2286
-	$priorities    = array( 'high', 'sorted', 'core', 'default', 'low' );
2287
-
2288
-	// Render meta boxes.
2289
-	?>
2269
+    global $post, $current_screen, $wp_meta_boxes;
2270
+
2271
+    // Handle meta box state.
2272
+    $_original_meta_boxes = $wp_meta_boxes;
2273
+
2274
+    /**
2275
+     * Fires right before the meta boxes are rendered.
2276
+     *
2277
+     * This allows for the filtering of meta box data, that should already be
2278
+     * present by this point. Do not use as a means of adding meta box data.
2279
+     *
2280
+     * @since 5.0.0
2281
+     *
2282
+     * @param array $wp_meta_boxes Global meta box state.
2283
+     */
2284
+    $wp_meta_boxes = apply_filters( 'filter_block_editor_meta_boxes', $wp_meta_boxes );
2285
+    $locations     = array( 'side', 'normal', 'advanced' );
2286
+    $priorities    = array( 'high', 'sorted', 'core', 'default', 'low' );
2287
+
2288
+    // Render meta boxes.
2289
+    ?>
2290 2290
 	<form class="metabox-base-form">
2291 2291
 	<?php the_block_editor_meta_box_post_form_hidden_fields( $post ); ?>
2292 2292
 	</form>
@@ -2299,80 +2299,80 @@  discard block
 block discarded – undo
2299 2299
 			<div id="poststuff" class="sidebar-open">
2300 2300
 				<div id="postbox-container-2" class="postbox-container">
2301 2301
 					<?php
2302
-					do_meta_boxes(
2303
-						$current_screen,
2304
-						$location,
2305
-						$post
2306
-					);
2307
-					?>
2302
+                    do_meta_boxes(
2303
+                        $current_screen,
2304
+                        $location,
2305
+                        $post
2306
+                    );
2307
+                    ?>
2308 2308
 				</div>
2309 2309
 			</div>
2310 2310
 		</form>
2311 2311
 	<?php endforeach; ?>
2312 2312
 	<?php
2313 2313
 
2314
-	$meta_boxes_per_location = array();
2315
-	foreach ( $locations as $location ) {
2316
-		$meta_boxes_per_location[ $location ] = array();
2317
-
2318
-		if ( ! isset( $wp_meta_boxes[ $current_screen->id ][ $location ] ) ) {
2319
-			continue;
2320
-		}
2321
-
2322
-		foreach ( $priorities as $priority ) {
2323
-			if ( ! isset( $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ] ) ) {
2324
-				continue;
2325
-			}
2326
-
2327
-			$meta_boxes = (array) $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ];
2328
-			foreach ( $meta_boxes as $meta_box ) {
2329
-				if ( false == $meta_box || ! $meta_box['title'] ) {
2330
-					continue;
2331
-				}
2332
-
2333
-				// If a meta box is just here for back compat, don't show it in the block editor.
2334
-				if ( isset( $meta_box['args']['__back_compat_meta_box'] ) && $meta_box['args']['__back_compat_meta_box'] ) {
2335
-					continue;
2336
-				}
2337
-
2338
-				$meta_boxes_per_location[ $location ][] = array(
2339
-					'id'    => $meta_box['id'],
2340
-					'title' => $meta_box['title'],
2341
-				);
2342
-			}
2343
-		}
2344
-	}
2345
-
2346
-	/*
2314
+    $meta_boxes_per_location = array();
2315
+    foreach ( $locations as $location ) {
2316
+        $meta_boxes_per_location[ $location ] = array();
2317
+
2318
+        if ( ! isset( $wp_meta_boxes[ $current_screen->id ][ $location ] ) ) {
2319
+            continue;
2320
+        }
2321
+
2322
+        foreach ( $priorities as $priority ) {
2323
+            if ( ! isset( $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ] ) ) {
2324
+                continue;
2325
+            }
2326
+
2327
+            $meta_boxes = (array) $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ];
2328
+            foreach ( $meta_boxes as $meta_box ) {
2329
+                if ( false == $meta_box || ! $meta_box['title'] ) {
2330
+                    continue;
2331
+                }
2332
+
2333
+                // If a meta box is just here for back compat, don't show it in the block editor.
2334
+                if ( isset( $meta_box['args']['__back_compat_meta_box'] ) && $meta_box['args']['__back_compat_meta_box'] ) {
2335
+                    continue;
2336
+                }
2337
+
2338
+                $meta_boxes_per_location[ $location ][] = array(
2339
+                    'id'    => $meta_box['id'],
2340
+                    'title' => $meta_box['title'],
2341
+                );
2342
+            }
2343
+        }
2344
+    }
2345
+
2346
+    /*
2347 2347
 	 * Sadly we probably cannot add this data directly into editor settings.
2348 2348
 	 *
2349 2349
 	 * Some meta boxes need `admin_head` to fire for meta box registry.
2350 2350
 	 * `admin_head` fires after `admin_enqueue_scripts`, which is where we create
2351 2351
 	 * our editor instance.
2352 2352
 	 */
2353
-	$script = 'window._wpLoadBlockEditor.then( function() {
2353
+    $script = 'window._wpLoadBlockEditor.then( function() {
2354 2354
 		wp.data.dispatch( \'core/edit-post\' ).setAvailableMetaBoxesPerLocation( ' . wp_json_encode( $meta_boxes_per_location ) . ' );
2355 2355
 	} );';
2356 2356
 
2357
-	wp_add_inline_script( 'wp-edit-post', $script );
2357
+    wp_add_inline_script( 'wp-edit-post', $script );
2358 2358
 
2359
-	/*
2359
+    /*
2360 2360
 	 * When `wp-edit-post` is output in the `<head>`, the inline script needs to be manually printed.
2361 2361
 	 * Otherwise, meta boxes will not display because inline scripts for `wp-edit-post`
2362 2362
 	 * will not be printed again after this point.
2363 2363
 	 */
2364
-	if ( wp_script_is( 'wp-edit-post', 'done' ) ) {
2365
-		printf( "<script type='text/javascript'>\n%s\n</script>\n", trim( $script ) );
2366
-	}
2364
+    if ( wp_script_is( 'wp-edit-post', 'done' ) ) {
2365
+        printf( "<script type='text/javascript'>\n%s\n</script>\n", trim( $script ) );
2366
+    }
2367 2367
 
2368
-	/*
2368
+    /*
2369 2369
 	 * If the 'postcustom' meta box is enabled, then we need to perform
2370 2370
 	 * some extra initialization on it.
2371 2371
 	 */
2372
-	$enable_custom_fields = (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true );
2372
+    $enable_custom_fields = (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true );
2373 2373
 
2374
-	if ( $enable_custom_fields ) {
2375
-		$script = "( function( $ ) {
2374
+    if ( $enable_custom_fields ) {
2375
+        $script = "( function( $ ) {
2376 2376
 			if ( $('#postcustom').length ) {
2377 2377
 				$( '#the-list' ).wpList( {
2378 2378
 					addBefore: function( s ) {
@@ -2385,12 +2385,12 @@  discard block
 block discarded – undo
2385 2385
 				});
2386 2386
 			}
2387 2387
 		} )( jQuery );";
2388
-		wp_enqueue_script( 'wp-lists' );
2389
-		wp_add_inline_script( 'wp-lists', $script );
2390
-	}
2388
+        wp_enqueue_script( 'wp-lists' );
2389
+        wp_add_inline_script( 'wp-lists', $script );
2390
+    }
2391 2391
 
2392
-	// Reset meta box data.
2393
-	$wp_meta_boxes = $_original_meta_boxes;
2392
+    // Reset meta box data.
2393
+    $wp_meta_boxes = $_original_meta_boxes;
2394 2394
 }
2395 2395
 
2396 2396
 /**
@@ -2401,42 +2401,42 @@  discard block
 block discarded – undo
2401 2401
  * @param WP_Post $post Current post object.
2402 2402
  */
2403 2403
 function the_block_editor_meta_box_post_form_hidden_fields( $post ) {
2404
-	$form_extra = '';
2405
-	if ( 'auto-draft' === $post->post_status ) {
2406
-		$form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
2407
-	}
2408
-	$form_action  = 'editpost';
2409
-	$nonce_action = 'update-post_' . $post->ID;
2410
-	$form_extra  .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post->ID ) . "' />";
2411
-	$referer      = wp_get_referer();
2412
-	$current_user = wp_get_current_user();
2413
-	$user_id      = $current_user->ID;
2414
-	wp_nonce_field( $nonce_action );
2415
-
2416
-	/*
2404
+    $form_extra = '';
2405
+    if ( 'auto-draft' === $post->post_status ) {
2406
+        $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
2407
+    }
2408
+    $form_action  = 'editpost';
2409
+    $nonce_action = 'update-post_' . $post->ID;
2410
+    $form_extra  .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post->ID ) . "' />";
2411
+    $referer      = wp_get_referer();
2412
+    $current_user = wp_get_current_user();
2413
+    $user_id      = $current_user->ID;
2414
+    wp_nonce_field( $nonce_action );
2415
+
2416
+    /*
2417 2417
 	 * Some meta boxes hook into these actions to add hidden input fields in the classic post form.
2418 2418
 	 * For backward compatibility, we can capture the output from these actions,
2419 2419
 	 * and extract the hidden input fields.
2420 2420
 	 */
2421
-	ob_start();
2422
-	/** This filter is documented in wp-admin/edit-form-advanced.php */
2423
-	do_action( 'edit_form_after_title', $post );
2424
-	/** This filter is documented in wp-admin/edit-form-advanced.php */
2425
-	do_action( 'edit_form_advanced', $post );
2426
-	$classic_output = ob_get_clean();
2427
-
2428
-	$classic_elements = wp_html_split( $classic_output );
2429
-	$hidden_inputs    = '';
2430
-	foreach ( $classic_elements as $element ) {
2431
-		if ( 0 !== strpos( $element, '<input ' ) ) {
2432
-			continue;
2433
-		}
2434
-
2435
-		if ( preg_match( '/\stype=[\'"]hidden[\'"]\s/', $element ) ) {
2436
-			echo $element;
2437
-		}
2438
-	}
2439
-	?>
2421
+    ob_start();
2422
+    /** This filter is documented in wp-admin/edit-form-advanced.php */
2423
+    do_action( 'edit_form_after_title', $post );
2424
+    /** This filter is documented in wp-admin/edit-form-advanced.php */
2425
+    do_action( 'edit_form_advanced', $post );
2426
+    $classic_output = ob_get_clean();
2427
+
2428
+    $classic_elements = wp_html_split( $classic_output );
2429
+    $hidden_inputs    = '';
2430
+    foreach ( $classic_elements as $element ) {
2431
+        if ( 0 !== strpos( $element, '<input ' ) ) {
2432
+            continue;
2433
+        }
2434
+
2435
+        if ( preg_match( '/\stype=[\'"]hidden[\'"]\s/', $element ) ) {
2436
+            echo $element;
2437
+        }
2438
+    }
2439
+    ?>
2440 2440
 	<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_id; ?>" />
2441 2441
 	<input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" />
2442 2442
 	<input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" />
@@ -2445,26 +2445,26 @@  discard block
 block discarded – undo
2445 2445
 	<input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" />
2446 2446
 
2447 2447
 	<?php
2448
-	if ( 'draft' !== get_post_status( $post ) ) {
2449
-		wp_original_referer_field( true, 'previous' );
2450
-	}
2451
-	echo $form_extra;
2452
-	wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
2453
-	wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
2454
-	// Permalink title nonce.
2455
-	wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
2456
-
2457
-	/**
2458
-	 * Adds hidden input fields to the meta box save form.
2459
-	 *
2460
-	 * Hook into this action to print `<input type="hidden" ... />` fields, which will be POSTed back to
2461
-	 * the server when meta boxes are saved.
2462
-	 *
2463
-	 * @since 5.0.0
2464
-	 *
2465
-	 * @param WP_Post $post The post that is being edited.
2466
-	 */
2467
-	do_action( 'block_editor_meta_box_hidden_fields', $post );
2448
+    if ( 'draft' !== get_post_status( $post ) ) {
2449
+        wp_original_referer_field( true, 'previous' );
2450
+    }
2451
+    echo $form_extra;
2452
+    wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
2453
+    wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
2454
+    // Permalink title nonce.
2455
+    wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
2456
+
2457
+    /**
2458
+     * Adds hidden input fields to the meta box save form.
2459
+     *
2460
+     * Hook into this action to print `<input type="hidden" ... />` fields, which will be POSTed back to
2461
+     * the server when meta boxes are saved.
2462
+     *
2463
+     * @since 5.0.0
2464
+     *
2465
+     * @param WP_Post $post The post that is being edited.
2466
+     */
2467
+    do_action( 'block_editor_meta_box_hidden_fields', $post );
2468 2468
 }
2469 2469
 
2470 2470
 /**
@@ -2478,11 +2478,11 @@  discard block
 block discarded – undo
2478 2478
  * @return bool Whether the block editor should be disabled or not.
2479 2479
  */
2480 2480
 function _disable_block_editor_for_navigation_post_type( $value, $post_type ) {
2481
-	if ( 'wp_navigation' === $post_type ) {
2482
-		return false;
2483
-	}
2481
+    if ( 'wp_navigation' === $post_type ) {
2482
+        return false;
2483
+    }
2484 2484
 
2485
-	return $value;
2485
+    return $value;
2486 2486
 }
2487 2487
 
2488 2488
 /**
@@ -2497,12 +2497,12 @@  discard block
 block discarded – undo
2497 2497
  * @param WP_Post $post An instance of WP_Post class.
2498 2498
  */
2499 2499
 function _disable_content_editor_for_navigation_post_type( $post ) {
2500
-	$post_type = get_post_type( $post );
2501
-	if ( 'wp_navigation' !== $post_type ) {
2502
-		return;
2503
-	}
2500
+    $post_type = get_post_type( $post );
2501
+    if ( 'wp_navigation' !== $post_type ) {
2502
+        return;
2503
+    }
2504 2504
 
2505
-	remove_post_type_support( $post_type, 'editor' );
2505
+    remove_post_type_support( $post_type, 'editor' );
2506 2506
 }
2507 2507
 
2508 2508
 /**
@@ -2518,10 +2518,10 @@  discard block
 block discarded – undo
2518 2518
  * @param WP_Post $post An instance of WP_Post class.
2519 2519
  */
2520 2520
 function _enable_content_editor_for_navigation_post_type( $post ) {
2521
-	$post_type = get_post_type( $post );
2522
-	if ( 'wp_navigation' !== $post_type ) {
2523
-		return;
2524
-	}
2521
+    $post_type = get_post_type( $post );
2522
+    if ( 'wp_navigation' !== $post_type ) {
2523
+        return;
2524
+    }
2525 2525
 
2526
-	add_post_type_support( $post_type, 'editor' );
2526
+    add_post_type_support( $post_type, 'editor' );
2527 2527
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-wp-media-list-table.php 1 patch
Indentation   +797 added lines, -797 removed lines patch added patch discarded remove patch
@@ -16,261 +16,261 @@  discard block
 block discarded – undo
16 16
  * @see WP_List_Table
17 17
  */
18 18
 class WP_Media_List_Table extends WP_List_Table {
19
-	/**
20
-	 * Holds the number of pending comments for each post.
21
-	 *
22
-	 * @since 4.4.0
23
-	 * @var array
24
-	 */
25
-	protected $comment_pending_count = array();
26
-
27
-	private $detached;
28
-
29
-	private $is_trash;
30
-
31
-	/**
32
-	 * Constructor.
33
-	 *
34
-	 * @since 3.1.0
35
-	 *
36
-	 * @see WP_List_Table::__construct() for more information on default arguments.
37
-	 *
38
-	 * @param array $args An associative array of arguments.
39
-	 */
40
-	public function __construct( $args = array() ) {
41
-		$this->detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] );
42
-
43
-		$this->modes = array(
44
-			'list' => __( 'List view' ),
45
-			'grid' => __( 'Grid view' ),
46
-		);
47
-
48
-		parent::__construct(
49
-			array(
50
-				'plural' => 'media',
51
-				'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
52
-			)
53
-		);
54
-	}
55
-
56
-	/**
57
-	 * @return bool
58
-	 */
59
-	public function ajax_user_can() {
60
-		return current_user_can( 'upload_files' );
61
-	}
62
-
63
-	/**
64
-	 * @global string   $mode                  List table view mode.
65
-	 * @global WP_Query $wp_query              WordPress Query object.
66
-	 * @global array    $post_mime_types
67
-	 * @global array    $avail_post_mime_types
68
-	 */
69
-	public function prepare_items() {
70
-		global $mode, $wp_query, $post_mime_types, $avail_post_mime_types;
71
-
72
-		$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
73
-
74
-		/*
19
+    /**
20
+     * Holds the number of pending comments for each post.
21
+     *
22
+     * @since 4.4.0
23
+     * @var array
24
+     */
25
+    protected $comment_pending_count = array();
26
+
27
+    private $detached;
28
+
29
+    private $is_trash;
30
+
31
+    /**
32
+     * Constructor.
33
+     *
34
+     * @since 3.1.0
35
+     *
36
+     * @see WP_List_Table::__construct() for more information on default arguments.
37
+     *
38
+     * @param array $args An associative array of arguments.
39
+     */
40
+    public function __construct( $args = array() ) {
41
+        $this->detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] );
42
+
43
+        $this->modes = array(
44
+            'list' => __( 'List view' ),
45
+            'grid' => __( 'Grid view' ),
46
+        );
47
+
48
+        parent::__construct(
49
+            array(
50
+                'plural' => 'media',
51
+                'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
52
+            )
53
+        );
54
+    }
55
+
56
+    /**
57
+     * @return bool
58
+     */
59
+    public function ajax_user_can() {
60
+        return current_user_can( 'upload_files' );
61
+    }
62
+
63
+    /**
64
+     * @global string   $mode                  List table view mode.
65
+     * @global WP_Query $wp_query              WordPress Query object.
66
+     * @global array    $post_mime_types
67
+     * @global array    $avail_post_mime_types
68
+     */
69
+    public function prepare_items() {
70
+        global $mode, $wp_query, $post_mime_types, $avail_post_mime_types;
71
+
72
+        $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
73
+
74
+        /*
75 75
 		 * Exclude attachments scheduled for deletion in the next two hours
76 76
 		 * if they are for zip packages for interrupted or failed updates.
77 77
 		 * See File_Upload_Upgrader class.
78 78
 		 */
79
-		$not_in = array();
80
-
81
-		$crons = _get_cron_array();
82
-
83
-		if ( is_array( $crons ) ) {
84
-			foreach ( $crons as $cron ) {
85
-				if ( isset( $cron['upgrader_scheduled_cleanup'] ) ) {
86
-					$details = reset( $cron['upgrader_scheduled_cleanup'] );
87
-
88
-					if ( ! empty( $details['args'][0] ) ) {
89
-						$not_in[] = (int) $details['args'][0];
90
-					}
91
-				}
92
-			}
93
-		}
94
-
95
-		if ( ! empty( $_REQUEST['post__not_in'] ) && is_array( $_REQUEST['post__not_in'] ) ) {
96
-			$not_in = array_merge( array_values( $_REQUEST['post__not_in'] ), $not_in );
97
-		}
98
-
99
-		if ( ! empty( $not_in ) ) {
100
-			$_REQUEST['post__not_in'] = $not_in;
101
-		}
102
-
103
-		list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST );
104
-
105
-		$this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
106
-
107
-		$this->set_pagination_args(
108
-			array(
109
-				'total_items' => $wp_query->found_posts,
110
-				'total_pages' => $wp_query->max_num_pages,
111
-				'per_page'    => $wp_query->query_vars['posts_per_page'],
112
-			)
113
-		);
114
-	}
115
-
116
-	/**
117
-	 * @global array $post_mime_types
118
-	 * @global array $avail_post_mime_types
119
-	 * @return array
120
-	 */
121
-	protected function get_views() {
122
-		global $post_mime_types, $avail_post_mime_types;
123
-
124
-		$type_links = array();
125
-
126
-		$filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter'];
127
-
128
-		$type_links['all'] = sprintf(
129
-			'<option value=""%s>%s</option>',
130
-			selected( $filter, true, false ),
131
-			__( 'All media items' )
132
-		);
133
-
134
-		foreach ( $post_mime_types as $mime_type => $label ) {
135
-			if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
136
-				continue;
137
-			}
138
-
139
-			$selected = selected(
140
-				$filter && 0 === strpos( $filter, 'post_mime_type:' ) &&
141
-					wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ),
142
-				true,
143
-				false
144
-			);
145
-
146
-			$type_links[ $mime_type ] = sprintf(
147
-				'<option value="post_mime_type:%s"%s>%s</option>',
148
-				esc_attr( $mime_type ),
149
-				$selected,
150
-				$label[0]
151
-			);
152
-		}
153
-
154
-		$type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . _x( 'Unattached', 'media items' ) . '</option>';
155
-
156
-		$type_links['mine'] = sprintf(
157
-			'<option value="mine"%s>%s</option>',
158
-			selected( 'mine' === $filter, true, false ),
159
-			_x( 'Mine', 'media items' )
160
-		);
161
-
162
-		if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) {
163
-			$type_links['trash'] = sprintf(
164
-				'<option value="trash"%s>%s</option>',
165
-				selected( 'trash' === $filter, true, false ),
166
-				_x( 'Trash', 'attachment filter' )
167
-			);
168
-		}
169
-
170
-		return $type_links;
171
-	}
172
-
173
-	/**
174
-	 * @return array
175
-	 */
176
-	protected function get_bulk_actions() {
177
-		$actions = array();
178
-
179
-		if ( MEDIA_TRASH ) {
180
-			if ( $this->is_trash ) {
181
-				$actions['untrash'] = __( 'Restore' );
182
-				$actions['delete']  = __( 'Delete permanently' );
183
-			} else {
184
-				$actions['trash'] = __( 'Move to Trash' );
185
-			}
186
-		} else {
187
-			$actions['delete'] = __( 'Delete permanently' );
188
-		}
189
-
190
-		if ( $this->detached ) {
191
-			$actions['attach'] = __( 'Attach' );
192
-		}
193
-
194
-		return $actions;
195
-	}
196
-
197
-	/**
198
-	 * @param string $which
199
-	 */
200
-	protected function extra_tablenav( $which ) {
201
-		if ( 'bar' !== $which ) {
202
-			return;
203
-		}
204
-		?>
79
+        $not_in = array();
80
+
81
+        $crons = _get_cron_array();
82
+
83
+        if ( is_array( $crons ) ) {
84
+            foreach ( $crons as $cron ) {
85
+                if ( isset( $cron['upgrader_scheduled_cleanup'] ) ) {
86
+                    $details = reset( $cron['upgrader_scheduled_cleanup'] );
87
+
88
+                    if ( ! empty( $details['args'][0] ) ) {
89
+                        $not_in[] = (int) $details['args'][0];
90
+                    }
91
+                }
92
+            }
93
+        }
94
+
95
+        if ( ! empty( $_REQUEST['post__not_in'] ) && is_array( $_REQUEST['post__not_in'] ) ) {
96
+            $not_in = array_merge( array_values( $_REQUEST['post__not_in'] ), $not_in );
97
+        }
98
+
99
+        if ( ! empty( $not_in ) ) {
100
+            $_REQUEST['post__not_in'] = $not_in;
101
+        }
102
+
103
+        list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST );
104
+
105
+        $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
106
+
107
+        $this->set_pagination_args(
108
+            array(
109
+                'total_items' => $wp_query->found_posts,
110
+                'total_pages' => $wp_query->max_num_pages,
111
+                'per_page'    => $wp_query->query_vars['posts_per_page'],
112
+            )
113
+        );
114
+    }
115
+
116
+    /**
117
+     * @global array $post_mime_types
118
+     * @global array $avail_post_mime_types
119
+     * @return array
120
+     */
121
+    protected function get_views() {
122
+        global $post_mime_types, $avail_post_mime_types;
123
+
124
+        $type_links = array();
125
+
126
+        $filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter'];
127
+
128
+        $type_links['all'] = sprintf(
129
+            '<option value=""%s>%s</option>',
130
+            selected( $filter, true, false ),
131
+            __( 'All media items' )
132
+        );
133
+
134
+        foreach ( $post_mime_types as $mime_type => $label ) {
135
+            if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
136
+                continue;
137
+            }
138
+
139
+            $selected = selected(
140
+                $filter && 0 === strpos( $filter, 'post_mime_type:' ) &&
141
+                    wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ),
142
+                true,
143
+                false
144
+            );
145
+
146
+            $type_links[ $mime_type ] = sprintf(
147
+                '<option value="post_mime_type:%s"%s>%s</option>',
148
+                esc_attr( $mime_type ),
149
+                $selected,
150
+                $label[0]
151
+            );
152
+        }
153
+
154
+        $type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . _x( 'Unattached', 'media items' ) . '</option>';
155
+
156
+        $type_links['mine'] = sprintf(
157
+            '<option value="mine"%s>%s</option>',
158
+            selected( 'mine' === $filter, true, false ),
159
+            _x( 'Mine', 'media items' )
160
+        );
161
+
162
+        if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) {
163
+            $type_links['trash'] = sprintf(
164
+                '<option value="trash"%s>%s</option>',
165
+                selected( 'trash' === $filter, true, false ),
166
+                _x( 'Trash', 'attachment filter' )
167
+            );
168
+        }
169
+
170
+        return $type_links;
171
+    }
172
+
173
+    /**
174
+     * @return array
175
+     */
176
+    protected function get_bulk_actions() {
177
+        $actions = array();
178
+
179
+        if ( MEDIA_TRASH ) {
180
+            if ( $this->is_trash ) {
181
+                $actions['untrash'] = __( 'Restore' );
182
+                $actions['delete']  = __( 'Delete permanently' );
183
+            } else {
184
+                $actions['trash'] = __( 'Move to Trash' );
185
+            }
186
+        } else {
187
+            $actions['delete'] = __( 'Delete permanently' );
188
+        }
189
+
190
+        if ( $this->detached ) {
191
+            $actions['attach'] = __( 'Attach' );
192
+        }
193
+
194
+        return $actions;
195
+    }
196
+
197
+    /**
198
+     * @param string $which
199
+     */
200
+    protected function extra_tablenav( $which ) {
201
+        if ( 'bar' !== $which ) {
202
+            return;
203
+        }
204
+        ?>
205 205
 		<div class="actions">
206 206
 			<?php
207
-			if ( ! $this->is_trash ) {
208
-				$this->months_dropdown( 'attachment' );
209
-			}
207
+            if ( ! $this->is_trash ) {
208
+                $this->months_dropdown( 'attachment' );
209
+            }
210 210
 
211
-			/** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
212
-			do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
211
+            /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
212
+            do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
213 213
 
214
-			submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
214
+            submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
215 215
 
216
-			if ( $this->is_trash && $this->has_items()
217
-				&& current_user_can( 'edit_others_posts' )
218
-			) {
219
-				submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
220
-			}
221
-			?>
216
+            if ( $this->is_trash && $this->has_items()
217
+                && current_user_can( 'edit_others_posts' )
218
+            ) {
219
+                submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
220
+            }
221
+            ?>
222 222
 		</div>
223 223
 		<?php
224
-	}
225
-
226
-	/**
227
-	 * @return string
228
-	 */
229
-	public function current_action() {
230
-		if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) {
231
-			return 'attach';
232
-		}
233
-
234
-		if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) ) {
235
-			return 'detach';
236
-		}
237
-
238
-		if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
239
-			return 'delete_all';
240
-		}
241
-
242
-		return parent::current_action();
243
-	}
244
-
245
-	/**
246
-	 * @return bool
247
-	 */
248
-	public function has_items() {
249
-		return have_posts();
250
-	}
251
-
252
-	/**
253
-	 */
254
-	public function no_items() {
255
-		if ( $this->is_trash ) {
256
-			_e( 'No media files found in Trash.' );
257
-		} else {
258
-			_e( 'No media files found.' );
259
-		}
260
-	}
261
-
262
-	/**
263
-	 * Override parent views so we can use the filter bar display.
264
-	 *
265
-	 * @global string $mode List table view mode.
266
-	 */
267
-	public function views() {
268
-		global $mode;
269
-
270
-		$views = $this->get_views();
271
-
272
-		$this->screen->render_screen_reader_content( 'heading_views' );
273
-		?>
224
+    }
225
+
226
+    /**
227
+     * @return string
228
+     */
229
+    public function current_action() {
230
+        if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) {
231
+            return 'attach';
232
+        }
233
+
234
+        if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) ) {
235
+            return 'detach';
236
+        }
237
+
238
+        if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
239
+            return 'delete_all';
240
+        }
241
+
242
+        return parent::current_action();
243
+    }
244
+
245
+    /**
246
+     * @return bool
247
+     */
248
+    public function has_items() {
249
+        return have_posts();
250
+    }
251
+
252
+    /**
253
+     */
254
+    public function no_items() {
255
+        if ( $this->is_trash ) {
256
+            _e( 'No media files found in Trash.' );
257
+        } else {
258
+            _e( 'No media files found.' );
259
+        }
260
+    }
261
+
262
+    /**
263
+     * Override parent views so we can use the filter bar display.
264
+     *
265
+     * @global string $mode List table view mode.
266
+     */
267
+    public function views() {
268
+        global $mode;
269
+
270
+        $views = $this->get_views();
271
+
272
+        $this->screen->render_screen_reader_content( 'heading_views' );
273
+        ?>
274 274
 		<div class="wp-filter">
275 275
 			<div class="filter-items">
276 276
 				<?php $this->view_switcher( $mode ); ?>
@@ -278,29 +278,29 @@  discard block
 block discarded – undo
278 278
 				<label for="attachment-filter" class="screen-reader-text"><?php _e( 'Filter by type' ); ?></label>
279 279
 				<select class="attachment-filters" name="attachment-filter" id="attachment-filter">
280 280
 					<?php
281
-					if ( ! empty( $views ) ) {
282
-						foreach ( $views as $class => $view ) {
283
-							echo "\t$view\n";
284
-						}
285
-					}
286
-					?>
281
+                    if ( ! empty( $views ) ) {
282
+                        foreach ( $views as $class => $view ) {
283
+                            echo "\t$view\n";
284
+                        }
285
+                    }
286
+                    ?>
287 287
 				</select>
288 288
 
289 289
 				<?php
290
-				$this->extra_tablenav( 'bar' );
291
-
292
-				/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
293
-				$views = apply_filters( "views_{$this->screen->id}", array() );
294
-
295
-				// Back compat for pre-4.0 view links.
296
-				if ( ! empty( $views ) ) {
297
-					echo '<ul class="filter-links">';
298
-					foreach ( $views as $class => $view ) {
299
-						echo "<li class='$class'>$view</li>";
300
-					}
301
-					echo '</ul>';
302
-				}
303
-				?>
290
+                $this->extra_tablenav( 'bar' );
291
+
292
+                /** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
293
+                $views = apply_filters( "views_{$this->screen->id}", array() );
294
+
295
+                // Back compat for pre-4.0 view links.
296
+                if ( ! empty( $views ) ) {
297
+                    echo '<ul class="filter-links">';
298
+                    foreach ( $views as $class => $view ) {
299
+                        echo "<li class='$class'>$view</li>";
300
+                    }
301
+                    echo '</ul>';
302
+                }
303
+                ?>
304 304
 			</div>
305 305
 
306 306
 			<div class="search-form">
@@ -309,560 +309,560 @@  discard block
 block discarded – undo
309 309
 			</div>
310 310
 		</div>
311 311
 		<?php
312
-	}
313
-
314
-	/**
315
-	 * @return array
316
-	 */
317
-	public function get_columns() {
318
-		$posts_columns       = array();
319
-		$posts_columns['cb'] = '<input type="checkbox" />';
320
-		/* translators: Column name. */
321
-		$posts_columns['title']  = _x( 'File', 'column name' );
322
-		$posts_columns['author'] = __( 'Author' );
323
-
324
-		$taxonomies = get_taxonomies_for_attachments( 'objects' );
325
-		$taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
326
-
327
-		/**
328
-		 * Filters the taxonomy columns for attachments in the Media list table.
329
-		 *
330
-		 * @since 3.5.0
331
-		 *
332
-		 * @param string[] $taxonomies An array of registered taxonomy names to show for attachments.
333
-		 * @param string   $post_type  The post type. Default 'attachment'.
334
-		 */
335
-		$taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' );
336
-		$taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
337
-
338
-		foreach ( $taxonomies as $taxonomy ) {
339
-			if ( 'category' === $taxonomy ) {
340
-				$column_key = 'categories';
341
-			} elseif ( 'post_tag' === $taxonomy ) {
342
-				$column_key = 'tags';
343
-			} else {
344
-				$column_key = 'taxonomy-' . $taxonomy;
345
-			}
346
-
347
-			$posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
348
-		}
349
-
350
-		/* translators: Column name. */
351
-		if ( ! $this->detached ) {
352
-			$posts_columns['parent'] = _x( 'Uploaded to', 'column name' );
353
-			if ( post_type_supports( 'attachment', 'comments' ) ) {
354
-				$posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
355
-			}
356
-		}
357
-
358
-		/* translators: Column name. */
359
-		$posts_columns['date'] = _x( 'Date', 'column name' );
360
-
361
-		/**
362
-		 * Filters the Media list table columns.
363
-		 *
364
-		 * @since 2.5.0
365
-		 *
366
-		 * @param string[] $posts_columns An array of columns displayed in the Media list table.
367
-		 * @param bool     $detached      Whether the list table contains media not attached
368
-		 *                                to any posts. Default true.
369
-		 */
370
-		return apply_filters( 'manage_media_columns', $posts_columns, $this->detached );
371
-	}
372
-
373
-	/**
374
-	 * @return array
375
-	 */
376
-	protected function get_sortable_columns() {
377
-		return array(
378
-			'title'    => 'title',
379
-			'author'   => 'author',
380
-			'parent'   => 'parent',
381
-			'comments' => 'comment_count',
382
-			'date'     => array( 'date', true ),
383
-		);
384
-	}
385
-
386
-	/**
387
-	 * Handles the checkbox column output.
388
-	 *
389
-	 * @since 4.3.0
390
-	 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
391
-	 *
392
-	 * @param WP_Post $item The current WP_Post object.
393
-	 */
394
-	public function column_cb( $item ) {
395
-		// Restores the more descriptive, specific name for use within this method.
396
-		$post = $item;
397
-
398
-		if ( current_user_can( 'edit_post', $post->ID ) ) {
399
-			?>
312
+    }
313
+
314
+    /**
315
+     * @return array
316
+     */
317
+    public function get_columns() {
318
+        $posts_columns       = array();
319
+        $posts_columns['cb'] = '<input type="checkbox" />';
320
+        /* translators: Column name. */
321
+        $posts_columns['title']  = _x( 'File', 'column name' );
322
+        $posts_columns['author'] = __( 'Author' );
323
+
324
+        $taxonomies = get_taxonomies_for_attachments( 'objects' );
325
+        $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
326
+
327
+        /**
328
+         * Filters the taxonomy columns for attachments in the Media list table.
329
+         *
330
+         * @since 3.5.0
331
+         *
332
+         * @param string[] $taxonomies An array of registered taxonomy names to show for attachments.
333
+         * @param string   $post_type  The post type. Default 'attachment'.
334
+         */
335
+        $taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' );
336
+        $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
337
+
338
+        foreach ( $taxonomies as $taxonomy ) {
339
+            if ( 'category' === $taxonomy ) {
340
+                $column_key = 'categories';
341
+            } elseif ( 'post_tag' === $taxonomy ) {
342
+                $column_key = 'tags';
343
+            } else {
344
+                $column_key = 'taxonomy-' . $taxonomy;
345
+            }
346
+
347
+            $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
348
+        }
349
+
350
+        /* translators: Column name. */
351
+        if ( ! $this->detached ) {
352
+            $posts_columns['parent'] = _x( 'Uploaded to', 'column name' );
353
+            if ( post_type_supports( 'attachment', 'comments' ) ) {
354
+                $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
355
+            }
356
+        }
357
+
358
+        /* translators: Column name. */
359
+        $posts_columns['date'] = _x( 'Date', 'column name' );
360
+
361
+        /**
362
+         * Filters the Media list table columns.
363
+         *
364
+         * @since 2.5.0
365
+         *
366
+         * @param string[] $posts_columns An array of columns displayed in the Media list table.
367
+         * @param bool     $detached      Whether the list table contains media not attached
368
+         *                                to any posts. Default true.
369
+         */
370
+        return apply_filters( 'manage_media_columns', $posts_columns, $this->detached );
371
+    }
372
+
373
+    /**
374
+     * @return array
375
+     */
376
+    protected function get_sortable_columns() {
377
+        return array(
378
+            'title'    => 'title',
379
+            'author'   => 'author',
380
+            'parent'   => 'parent',
381
+            'comments' => 'comment_count',
382
+            'date'     => array( 'date', true ),
383
+        );
384
+    }
385
+
386
+    /**
387
+     * Handles the checkbox column output.
388
+     *
389
+     * @since 4.3.0
390
+     * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
391
+     *
392
+     * @param WP_Post $item The current WP_Post object.
393
+     */
394
+    public function column_cb( $item ) {
395
+        // Restores the more descriptive, specific name for use within this method.
396
+        $post = $item;
397
+
398
+        if ( current_user_can( 'edit_post', $post->ID ) ) {
399
+            ?>
400 400
 			<label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>">
401 401
 				<?php
402
-				/* translators: %s: Attachment title. */
403
-				printf( __( 'Select %s' ), _draft_or_post_title() );
404
-				?>
402
+                /* translators: %s: Attachment title. */
403
+                printf( __( 'Select %s' ), _draft_or_post_title() );
404
+                ?>
405 405
 			</label>
406 406
 			<input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" />
407 407
 			<?php
408
-		}
409
-	}
410
-
411
-	/**
412
-	 * Handles the title column output.
413
-	 *
414
-	 * @since 4.3.0
415
-	 *
416
-	 * @param WP_Post $post The current WP_Post object.
417
-	 */
418
-	public function column_title( $post ) {
419
-		list( $mime ) = explode( '/', $post->post_mime_type );
420
-
421
-		$title      = _draft_or_post_title();
422
-		$thumb      = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
423
-		$link_start = '';
424
-		$link_end   = '';
425
-
426
-		if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
427
-			$link_start = sprintf(
428
-				'<a href="%s" aria-label="%s">',
429
-				get_edit_post_link( $post->ID ),
430
-				/* translators: %s: Attachment title. */
431
-				esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) )
432
-			);
433
-			$link_end = '</a>';
434
-		}
435
-
436
-		$class = $thumb ? ' class="has-media-icon"' : '';
437
-		?>
408
+        }
409
+    }
410
+
411
+    /**
412
+     * Handles the title column output.
413
+     *
414
+     * @since 4.3.0
415
+     *
416
+     * @param WP_Post $post The current WP_Post object.
417
+     */
418
+    public function column_title( $post ) {
419
+        list( $mime ) = explode( '/', $post->post_mime_type );
420
+
421
+        $title      = _draft_or_post_title();
422
+        $thumb      = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
423
+        $link_start = '';
424
+        $link_end   = '';
425
+
426
+        if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
427
+            $link_start = sprintf(
428
+                '<a href="%s" aria-label="%s">',
429
+                get_edit_post_link( $post->ID ),
430
+                /* translators: %s: Attachment title. */
431
+                esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) )
432
+            );
433
+            $link_end = '</a>';
434
+        }
435
+
436
+        $class = $thumb ? ' class="has-media-icon"' : '';
437
+        ?>
438 438
 		<strong<?php echo $class; ?>>
439 439
 			<?php
440
-			echo $link_start;
440
+            echo $link_start;
441 441
 
442
-			if ( $thumb ) :
443
-				?>
442
+            if ( $thumb ) :
443
+                ?>
444 444
 				<span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?>"><?php echo $thumb; ?></span>
445 445
 				<?php
446
-			endif;
446
+            endif;
447 447
 
448
-			echo $title . $link_end;
448
+            echo $title . $link_end;
449 449
 
450
-			_media_states( $post );
451
-			?>
450
+            _media_states( $post );
451
+            ?>
452 452
 		</strong>
453 453
 		<p class="filename">
454 454
 			<span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span>
455 455
 			<?php
456
-			$file = get_attached_file( $post->ID );
457
-			echo esc_html( wp_basename( $file ) );
458
-			?>
456
+            $file = get_attached_file( $post->ID );
457
+            echo esc_html( wp_basename( $file ) );
458
+            ?>
459 459
 		</p>
460 460
 		<?php
461
-	}
462
-
463
-	/**
464
-	 * Handles the author column output.
465
-	 *
466
-	 * @since 4.3.0
467
-	 *
468
-	 * @param WP_Post $post The current WP_Post object.
469
-	 */
470
-	public function column_author( $post ) {
471
-		printf(
472
-			'<a href="%s">%s</a>',
473
-			esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
474
-			get_the_author()
475
-		);
476
-	}
477
-
478
-	/**
479
-	 * Handles the description column output.
480
-	 *
481
-	 * @since 4.3.0
482
-	 *
483
-	 * @param WP_Post $post The current WP_Post object.
484
-	 */
485
-	public function column_desc( $post ) {
486
-		echo has_excerpt() ? $post->post_excerpt : '';
487
-	}
488
-
489
-	/**
490
-	 * Handles the date column output.
491
-	 *
492
-	 * @since 4.3.0
493
-	 *
494
-	 * @param WP_Post $post The current WP_Post object.
495
-	 */
496
-	public function column_date( $post ) {
497
-		if ( '0000-00-00 00:00:00' === $post->post_date ) {
498
-			$h_time = __( 'Unpublished' );
499
-		} else {
500
-			$time      = get_post_timestamp( $post );
501
-			$time_diff = time() - $time;
502
-
503
-			if ( $time && $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
504
-				/* translators: %s: Human-readable time difference. */
505
-				$h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
506
-			} else {
507
-				$h_time = get_the_time( __( 'Y/m/d' ), $post );
508
-			}
509
-		}
510
-
511
-		/**
512
-		 * Filters the published time of an attachment displayed in the Media list table.
513
-		 *
514
-		 * @since 6.0.0
515
-		 *
516
-		 * @param string  $h_time      The published time.
517
-		 * @param WP_Post $post        Attachment object.
518
-		 * @param string  $column_name The column name.
519
-		 */
520
-		echo apply_filters( 'media_date_column_time', $h_time, $post, 'date' );
521
-	}
522
-
523
-	/**
524
-	 * Handles the parent column output.
525
-	 *
526
-	 * @since 4.3.0
527
-	 *
528
-	 * @param WP_Post $post The current WP_Post object.
529
-	 */
530
-	public function column_parent( $post ) {
531
-		$user_can_edit = current_user_can( 'edit_post', $post->ID );
532
-
533
-		if ( $post->post_parent > 0 ) {
534
-			$parent = get_post( $post->post_parent );
535
-		} else {
536
-			$parent = false;
537
-		}
538
-
539
-		if ( $parent ) {
540
-			$title       = _draft_or_post_title( $post->post_parent );
541
-			$parent_type = get_post_type_object( $parent->post_type );
542
-
543
-			if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) {
544
-				printf( '<strong><a href="%s">%s</a></strong>', get_edit_post_link( $post->post_parent ), $title );
545
-			} elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) {
546
-				printf( '<strong>%s</strong>', $title );
547
-			} else {
548
-				_e( '(Private post)' );
549
-			}
550
-
551
-			if ( $user_can_edit ) :
552
-				$detach_url = add_query_arg(
553
-					array(
554
-						'parent_post_id' => $post->post_parent,
555
-						'media[]'        => $post->ID,
556
-						'_wpnonce'       => wp_create_nonce( 'bulk-' . $this->_args['plural'] ),
557
-					),
558
-					'upload.php'
559
-				);
560
-				printf(
561
-					'<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>',
562
-					$detach_url,
563
-					/* translators: %s: Title of the post the attachment is attached to. */
564
-					esc_attr( sprintf( __( 'Detach from &#8220;%s&#8221;' ), $title ) ),
565
-					__( 'Detach' )
566
-				);
567
-			endif;
568
-		} else {
569
-			_e( '(Unattached)' );
570
-			?>
461
+    }
462
+
463
+    /**
464
+     * Handles the author column output.
465
+     *
466
+     * @since 4.3.0
467
+     *
468
+     * @param WP_Post $post The current WP_Post object.
469
+     */
470
+    public function column_author( $post ) {
471
+        printf(
472
+            '<a href="%s">%s</a>',
473
+            esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
474
+            get_the_author()
475
+        );
476
+    }
477
+
478
+    /**
479
+     * Handles the description column output.
480
+     *
481
+     * @since 4.3.0
482
+     *
483
+     * @param WP_Post $post The current WP_Post object.
484
+     */
485
+    public function column_desc( $post ) {
486
+        echo has_excerpt() ? $post->post_excerpt : '';
487
+    }
488
+
489
+    /**
490
+     * Handles the date column output.
491
+     *
492
+     * @since 4.3.0
493
+     *
494
+     * @param WP_Post $post The current WP_Post object.
495
+     */
496
+    public function column_date( $post ) {
497
+        if ( '0000-00-00 00:00:00' === $post->post_date ) {
498
+            $h_time = __( 'Unpublished' );
499
+        } else {
500
+            $time      = get_post_timestamp( $post );
501
+            $time_diff = time() - $time;
502
+
503
+            if ( $time && $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
504
+                /* translators: %s: Human-readable time difference. */
505
+                $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
506
+            } else {
507
+                $h_time = get_the_time( __( 'Y/m/d' ), $post );
508
+            }
509
+        }
510
+
511
+        /**
512
+         * Filters the published time of an attachment displayed in the Media list table.
513
+         *
514
+         * @since 6.0.0
515
+         *
516
+         * @param string  $h_time      The published time.
517
+         * @param WP_Post $post        Attachment object.
518
+         * @param string  $column_name The column name.
519
+         */
520
+        echo apply_filters( 'media_date_column_time', $h_time, $post, 'date' );
521
+    }
522
+
523
+    /**
524
+     * Handles the parent column output.
525
+     *
526
+     * @since 4.3.0
527
+     *
528
+     * @param WP_Post $post The current WP_Post object.
529
+     */
530
+    public function column_parent( $post ) {
531
+        $user_can_edit = current_user_can( 'edit_post', $post->ID );
532
+
533
+        if ( $post->post_parent > 0 ) {
534
+            $parent = get_post( $post->post_parent );
535
+        } else {
536
+            $parent = false;
537
+        }
538
+
539
+        if ( $parent ) {
540
+            $title       = _draft_or_post_title( $post->post_parent );
541
+            $parent_type = get_post_type_object( $parent->post_type );
542
+
543
+            if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) {
544
+                printf( '<strong><a href="%s">%s</a></strong>', get_edit_post_link( $post->post_parent ), $title );
545
+            } elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) {
546
+                printf( '<strong>%s</strong>', $title );
547
+            } else {
548
+                _e( '(Private post)' );
549
+            }
550
+
551
+            if ( $user_can_edit ) :
552
+                $detach_url = add_query_arg(
553
+                    array(
554
+                        'parent_post_id' => $post->post_parent,
555
+                        'media[]'        => $post->ID,
556
+                        '_wpnonce'       => wp_create_nonce( 'bulk-' . $this->_args['plural'] ),
557
+                    ),
558
+                    'upload.php'
559
+                );
560
+                printf(
561
+                    '<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>',
562
+                    $detach_url,
563
+                    /* translators: %s: Title of the post the attachment is attached to. */
564
+                    esc_attr( sprintf( __( 'Detach from &#8220;%s&#8221;' ), $title ) ),
565
+                    __( 'Detach' )
566
+                );
567
+            endif;
568
+        } else {
569
+            _e( '(Unattached)' );
570
+            ?>
571 571
 			<?php
572
-			if ( $user_can_edit ) {
573
-				$title = _draft_or_post_title( $post->post_parent );
574
-				printf(
575
-					'<br /><a href="#the-list" onclick="findPosts.open( \'media[]\', \'%s\' ); return false;" class="hide-if-no-js aria-button-if-js" aria-label="%s">%s</a>',
576
-					$post->ID,
577
-					/* translators: %s: Attachment title. */
578
-					esc_attr( sprintf( __( 'Attach &#8220;%s&#8221; to existing content' ), $title ) ),
579
-					__( 'Attach' )
580
-				);
581
-			}
582
-		}
583
-	}
584
-
585
-	/**
586
-	 * Handles the comments column output.
587
-	 *
588
-	 * @since 4.3.0
589
-	 *
590
-	 * @param WP_Post $post The current WP_Post object.
591
-	 */
592
-	public function column_comments( $post ) {
593
-		echo '<div class="post-com-count-wrapper">';
594
-
595
-		if ( isset( $this->comment_pending_count[ $post->ID ] ) ) {
596
-			$pending_comments = $this->comment_pending_count[ $post->ID ];
597
-		} else {
598
-			$pending_comments = get_pending_comments_num( $post->ID );
599
-		}
600
-
601
-		$this->comments_bubble( $post->ID, $pending_comments );
602
-
603
-		echo '</div>';
604
-	}
605
-
606
-	/**
607
-	 * Handles output for the default column.
608
-	 *
609
-	 * @since 4.3.0
610
-	 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
611
-	 *
612
-	 * @param WP_Post $item        The current WP_Post object.
613
-	 * @param string  $column_name Current column name.
614
-	 */
615
-	public function column_default( $item, $column_name ) {
616
-		// Restores the more descriptive, specific name for use within this method.
617
-		$post = $item;
618
-
619
-		if ( 'categories' === $column_name ) {
620
-			$taxonomy = 'category';
621
-		} elseif ( 'tags' === $column_name ) {
622
-			$taxonomy = 'post_tag';
623
-		} elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
624
-			$taxonomy = substr( $column_name, 9 );
625
-		} else {
626
-			$taxonomy = false;
627
-		}
628
-
629
-		if ( $taxonomy ) {
630
-			$terms = get_the_terms( $post->ID, $taxonomy );
631
-
632
-			if ( is_array( $terms ) ) {
633
-				$out = array();
634
-				foreach ( $terms as $t ) {
635
-					$posts_in_term_qv             = array();
636
-					$posts_in_term_qv['taxonomy'] = $taxonomy;
637
-					$posts_in_term_qv['term']     = $t->slug;
638
-
639
-					$out[] = sprintf(
640
-						'<a href="%s">%s</a>',
641
-						esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
642
-						esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
643
-					);
644
-				}
645
-				echo implode( wp_get_list_item_separator(), $out );
646
-			} else {
647
-				echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>';
648
-			}
649
-
650
-			return;
651
-		}
652
-
653
-		/**
654
-		 * Fires for each custom column in the Media list table.
655
-		 *
656
-		 * Custom columns are registered using the {@see 'manage_media_columns'} filter.
657
-		 *
658
-		 * @since 2.5.0
659
-		 *
660
-		 * @param string $column_name Name of the custom column.
661
-		 * @param int    $post_id     Attachment ID.
662
-		 */
663
-		do_action( 'manage_media_custom_column', $column_name, $post->ID );
664
-	}
665
-
666
-	/**
667
-	 * @global WP_Post $post Global post object.
668
-	 */
669
-	public function display_rows() {
670
-		global $post, $wp_query;
671
-
672
-		$post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
673
-		reset( $wp_query->posts );
674
-
675
-		$this->comment_pending_count = get_pending_comments_num( $post_ids );
676
-
677
-		add_filter( 'the_title', 'esc_html' );
678
-
679
-		while ( have_posts() ) :
680
-			the_post();
681
-
682
-			if ( $this->is_trash && 'trash' !== $post->post_status
683
-				|| ! $this->is_trash && 'trash' === $post->post_status
684
-			) {
685
-				continue;
686
-			}
687
-
688
-			$post_owner = ( get_current_user_id() === (int) $post->post_author ) ? 'self' : 'other';
689
-			?>
572
+            if ( $user_can_edit ) {
573
+                $title = _draft_or_post_title( $post->post_parent );
574
+                printf(
575
+                    '<br /><a href="#the-list" onclick="findPosts.open( \'media[]\', \'%s\' ); return false;" class="hide-if-no-js aria-button-if-js" aria-label="%s">%s</a>',
576
+                    $post->ID,
577
+                    /* translators: %s: Attachment title. */
578
+                    esc_attr( sprintf( __( 'Attach &#8220;%s&#8221; to existing content' ), $title ) ),
579
+                    __( 'Attach' )
580
+                );
581
+            }
582
+        }
583
+    }
584
+
585
+    /**
586
+     * Handles the comments column output.
587
+     *
588
+     * @since 4.3.0
589
+     *
590
+     * @param WP_Post $post The current WP_Post object.
591
+     */
592
+    public function column_comments( $post ) {
593
+        echo '<div class="post-com-count-wrapper">';
594
+
595
+        if ( isset( $this->comment_pending_count[ $post->ID ] ) ) {
596
+            $pending_comments = $this->comment_pending_count[ $post->ID ];
597
+        } else {
598
+            $pending_comments = get_pending_comments_num( $post->ID );
599
+        }
600
+
601
+        $this->comments_bubble( $post->ID, $pending_comments );
602
+
603
+        echo '</div>';
604
+    }
605
+
606
+    /**
607
+     * Handles output for the default column.
608
+     *
609
+     * @since 4.3.0
610
+     * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
611
+     *
612
+     * @param WP_Post $item        The current WP_Post object.
613
+     * @param string  $column_name Current column name.
614
+     */
615
+    public function column_default( $item, $column_name ) {
616
+        // Restores the more descriptive, specific name for use within this method.
617
+        $post = $item;
618
+
619
+        if ( 'categories' === $column_name ) {
620
+            $taxonomy = 'category';
621
+        } elseif ( 'tags' === $column_name ) {
622
+            $taxonomy = 'post_tag';
623
+        } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
624
+            $taxonomy = substr( $column_name, 9 );
625
+        } else {
626
+            $taxonomy = false;
627
+        }
628
+
629
+        if ( $taxonomy ) {
630
+            $terms = get_the_terms( $post->ID, $taxonomy );
631
+
632
+            if ( is_array( $terms ) ) {
633
+                $out = array();
634
+                foreach ( $terms as $t ) {
635
+                    $posts_in_term_qv             = array();
636
+                    $posts_in_term_qv['taxonomy'] = $taxonomy;
637
+                    $posts_in_term_qv['term']     = $t->slug;
638
+
639
+                    $out[] = sprintf(
640
+                        '<a href="%s">%s</a>',
641
+                        esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
642
+                        esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
643
+                    );
644
+                }
645
+                echo implode( wp_get_list_item_separator(), $out );
646
+            } else {
647
+                echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>';
648
+            }
649
+
650
+            return;
651
+        }
652
+
653
+        /**
654
+         * Fires for each custom column in the Media list table.
655
+         *
656
+         * Custom columns are registered using the {@see 'manage_media_columns'} filter.
657
+         *
658
+         * @since 2.5.0
659
+         *
660
+         * @param string $column_name Name of the custom column.
661
+         * @param int    $post_id     Attachment ID.
662
+         */
663
+        do_action( 'manage_media_custom_column', $column_name, $post->ID );
664
+    }
665
+
666
+    /**
667
+     * @global WP_Post $post Global post object.
668
+     */
669
+    public function display_rows() {
670
+        global $post, $wp_query;
671
+
672
+        $post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
673
+        reset( $wp_query->posts );
674
+
675
+        $this->comment_pending_count = get_pending_comments_num( $post_ids );
676
+
677
+        add_filter( 'the_title', 'esc_html' );
678
+
679
+        while ( have_posts() ) :
680
+            the_post();
681
+
682
+            if ( $this->is_trash && 'trash' !== $post->post_status
683
+                || ! $this->is_trash && 'trash' === $post->post_status
684
+            ) {
685
+                continue;
686
+            }
687
+
688
+            $post_owner = ( get_current_user_id() === (int) $post->post_author ) ? 'self' : 'other';
689
+            ?>
690 690
 			<tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>">
691 691
 				<?php $this->single_row_columns( $post ); ?>
692 692
 			</tr>
693 693
 			<?php
694
-		endwhile;
695
-	}
696
-
697
-	/**
698
-	 * Gets the name of the default primary column.
699
-	 *
700
-	 * @since 4.3.0
701
-	 *
702
-	 * @return string Name of the default primary column, in this case, 'title'.
703
-	 */
704
-	protected function get_default_primary_column_name() {
705
-		return 'title';
706
-	}
707
-
708
-	/**
709
-	 * @param WP_Post $post
710
-	 * @param string  $att_title
711
-	 * @return array
712
-	 */
713
-	private function _get_row_actions( $post, $att_title ) {
714
-		$actions = array();
715
-
716
-		if ( $this->detached ) {
717
-			if ( current_user_can( 'edit_post', $post->ID ) ) {
718
-				$actions['edit'] = sprintf(
719
-					'<a href="%s" aria-label="%s">%s</a>',
720
-					get_edit_post_link( $post->ID ),
721
-					/* translators: %s: Attachment title. */
722
-					esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ),
723
-					__( 'Edit' )
724
-				);
725
-			}
726
-
727
-			if ( current_user_can( 'delete_post', $post->ID ) ) {
728
-				if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
729
-					$actions['trash'] = sprintf(
730
-						'<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
731
-						wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ),
732
-						/* translators: %s: Attachment title. */
733
-						esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $att_title ) ),
734
-						_x( 'Trash', 'verb' )
735
-					);
736
-				} else {
737
-					$delete_ays        = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
738
-					$actions['delete'] = sprintf(
739
-						'<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
740
-						wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
741
-						$delete_ays,
742
-						/* translators: %s: Attachment title. */
743
-						esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $att_title ) ),
744
-						__( 'Delete Permanently' )
745
-					);
746
-				}
747
-			}
748
-
749
-			$actions['view'] = sprintf(
750
-				'<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
751
-				get_permalink( $post->ID ),
752
-				/* translators: %s: Attachment title. */
753
-				esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
754
-				__( 'View' )
755
-			);
756
-
757
-			if ( current_user_can( 'edit_post', $post->ID ) ) {
758
-				$actions['attach'] = sprintf(
759
-					'<a href="#the-list" onclick="findPosts.open( \'media[]\', \'%s\' ); return false;" class="hide-if-no-js aria-button-if-js" aria-label="%s">%s</a>',
760
-					$post->ID,
761
-					/* translators: %s: Attachment title. */
762
-					esc_attr( sprintf( __( 'Attach &#8220;%s&#8221; to existing content' ), $att_title ) ),
763
-					__( 'Attach' )
764
-				);
765
-			}
766
-		} else {
767
-			if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
768
-				$actions['edit'] = sprintf(
769
-					'<a href="%s" aria-label="%s">%s</a>',
770
-					get_edit_post_link( $post->ID ),
771
-					/* translators: %s: Attachment title. */
772
-					esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ),
773
-					__( 'Edit' )
774
-				);
775
-			}
776
-
777
-			if ( current_user_can( 'delete_post', $post->ID ) ) {
778
-				if ( $this->is_trash ) {
779
-					$actions['untrash'] = sprintf(
780
-						'<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
781
-						wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID ),
782
-						/* translators: %s: Attachment title. */
783
-						esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $att_title ) ),
784
-						__( 'Restore' )
785
-					);
786
-				} elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
787
-					$actions['trash'] = sprintf(
788
-						'<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
789
-						wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ),
790
-						/* translators: %s: Attachment title. */
791
-						esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $att_title ) ),
792
-						_x( 'Trash', 'verb' )
793
-					);
794
-				}
795
-
796
-				if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) {
797
-					$delete_ays        = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
798
-					$actions['delete'] = sprintf(
799
-						'<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
800
-						wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
801
-						$delete_ays,
802
-						/* translators: %s: Attachment title. */
803
-						esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $att_title ) ),
804
-						__( 'Delete Permanently' )
805
-					);
806
-				}
807
-			}
808
-
809
-			if ( ! $this->is_trash ) {
810
-				$actions['view'] = sprintf(
811
-					'<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
812
-					get_permalink( $post->ID ),
813
-					/* translators: %s: Attachment title. */
814
-					esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
815
-					__( 'View' )
816
-				);
817
-
818
-				$actions['copy'] = sprintf(
819
-					'<span class="copy-to-clipboard-container"><button type="button" class="button-link copy-attachment-url media-library" data-clipboard-text="%s" aria-label="%s">%s</button><span class="success hidden" aria-hidden="true">%s</span></span>',
820
-					esc_url( wp_get_attachment_url( $post->ID ) ),
821
-					/* translators: %s: Attachment title. */
822
-					esc_attr( sprintf( __( 'Copy &#8220;%s&#8221; URL to clipboard' ), $att_title ) ),
823
-					__( 'Copy URL to clipboard' ),
824
-					__( 'Copied!' )
825
-				);
826
-			}
827
-		}
828
-
829
-		/**
830
-		 * Filters the action links for each attachment in the Media list table.
831
-		 *
832
-		 * @since 2.8.0
833
-		 *
834
-		 * @param string[] $actions  An array of action links for each attachment.
835
-		 *                           Default 'Edit', 'Delete Permanently', 'View'.
836
-		 * @param WP_Post  $post     WP_Post object for the current attachment.
837
-		 * @param bool     $detached Whether the list table contains media not attached
838
-		 *                           to any posts. Default true.
839
-		 */
840
-		return apply_filters( 'media_row_actions', $actions, $post, $this->detached );
841
-	}
842
-
843
-	/**
844
-	 * Generates and displays row action links.
845
-	 *
846
-	 * @since 4.3.0
847
-	 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
848
-	 *
849
-	 * @param WP_Post $item        Attachment being acted upon.
850
-	 * @param string  $column_name Current column name.
851
-	 * @param string  $primary     Primary column name.
852
-	 * @return string Row actions output for media attachments, or an empty string
853
-	 *                if the current column is not the primary column.
854
-	 */
855
-	protected function handle_row_actions( $item, $column_name, $primary ) {
856
-		if ( $primary !== $column_name ) {
857
-			return '';
858
-		}
859
-
860
-		$att_title = _draft_or_post_title();
861
-		$actions   = $this->_get_row_actions(
862
-			$item, // WP_Post object for an attachment.
863
-			$att_title
864
-		);
865
-
866
-		return $this->row_actions( $actions );
867
-	}
694
+        endwhile;
695
+    }
696
+
697
+    /**
698
+     * Gets the name of the default primary column.
699
+     *
700
+     * @since 4.3.0
701
+     *
702
+     * @return string Name of the default primary column, in this case, 'title'.
703
+     */
704
+    protected function get_default_primary_column_name() {
705
+        return 'title';
706
+    }
707
+
708
+    /**
709
+     * @param WP_Post $post
710
+     * @param string  $att_title
711
+     * @return array
712
+     */
713
+    private function _get_row_actions( $post, $att_title ) {
714
+        $actions = array();
715
+
716
+        if ( $this->detached ) {
717
+            if ( current_user_can( 'edit_post', $post->ID ) ) {
718
+                $actions['edit'] = sprintf(
719
+                    '<a href="%s" aria-label="%s">%s</a>',
720
+                    get_edit_post_link( $post->ID ),
721
+                    /* translators: %s: Attachment title. */
722
+                    esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ),
723
+                    __( 'Edit' )
724
+                );
725
+            }
726
+
727
+            if ( current_user_can( 'delete_post', $post->ID ) ) {
728
+                if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
729
+                    $actions['trash'] = sprintf(
730
+                        '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
731
+                        wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ),
732
+                        /* translators: %s: Attachment title. */
733
+                        esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $att_title ) ),
734
+                        _x( 'Trash', 'verb' )
735
+                    );
736
+                } else {
737
+                    $delete_ays        = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
738
+                    $actions['delete'] = sprintf(
739
+                        '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
740
+                        wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
741
+                        $delete_ays,
742
+                        /* translators: %s: Attachment title. */
743
+                        esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $att_title ) ),
744
+                        __( 'Delete Permanently' )
745
+                    );
746
+                }
747
+            }
748
+
749
+            $actions['view'] = sprintf(
750
+                '<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
751
+                get_permalink( $post->ID ),
752
+                /* translators: %s: Attachment title. */
753
+                esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
754
+                __( 'View' )
755
+            );
756
+
757
+            if ( current_user_can( 'edit_post', $post->ID ) ) {
758
+                $actions['attach'] = sprintf(
759
+                    '<a href="#the-list" onclick="findPosts.open( \'media[]\', \'%s\' ); return false;" class="hide-if-no-js aria-button-if-js" aria-label="%s">%s</a>',
760
+                    $post->ID,
761
+                    /* translators: %s: Attachment title. */
762
+                    esc_attr( sprintf( __( 'Attach &#8220;%s&#8221; to existing content' ), $att_title ) ),
763
+                    __( 'Attach' )
764
+                );
765
+            }
766
+        } else {
767
+            if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
768
+                $actions['edit'] = sprintf(
769
+                    '<a href="%s" aria-label="%s">%s</a>',
770
+                    get_edit_post_link( $post->ID ),
771
+                    /* translators: %s: Attachment title. */
772
+                    esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ),
773
+                    __( 'Edit' )
774
+                );
775
+            }
776
+
777
+            if ( current_user_can( 'delete_post', $post->ID ) ) {
778
+                if ( $this->is_trash ) {
779
+                    $actions['untrash'] = sprintf(
780
+                        '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
781
+                        wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID ),
782
+                        /* translators: %s: Attachment title. */
783
+                        esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $att_title ) ),
784
+                        __( 'Restore' )
785
+                    );
786
+                } elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
787
+                    $actions['trash'] = sprintf(
788
+                        '<a href="%s" class="submitdelete aria-button-if-js" aria-label="%s">%s</a>',
789
+                        wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ),
790
+                        /* translators: %s: Attachment title. */
791
+                        esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $att_title ) ),
792
+                        _x( 'Trash', 'verb' )
793
+                    );
794
+                }
795
+
796
+                if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) {
797
+                    $delete_ays        = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
798
+                    $actions['delete'] = sprintf(
799
+                        '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
800
+                        wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID ),
801
+                        $delete_ays,
802
+                        /* translators: %s: Attachment title. */
803
+                        esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $att_title ) ),
804
+                        __( 'Delete Permanently' )
805
+                    );
806
+                }
807
+            }
808
+
809
+            if ( ! $this->is_trash ) {
810
+                $actions['view'] = sprintf(
811
+                    '<a href="%s" aria-label="%s" rel="bookmark">%s</a>',
812
+                    get_permalink( $post->ID ),
813
+                    /* translators: %s: Attachment title. */
814
+                    esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ),
815
+                    __( 'View' )
816
+                );
817
+
818
+                $actions['copy'] = sprintf(
819
+                    '<span class="copy-to-clipboard-container"><button type="button" class="button-link copy-attachment-url media-library" data-clipboard-text="%s" aria-label="%s">%s</button><span class="success hidden" aria-hidden="true">%s</span></span>',
820
+                    esc_url( wp_get_attachment_url( $post->ID ) ),
821
+                    /* translators: %s: Attachment title. */
822
+                    esc_attr( sprintf( __( 'Copy &#8220;%s&#8221; URL to clipboard' ), $att_title ) ),
823
+                    __( 'Copy URL to clipboard' ),
824
+                    __( 'Copied!' )
825
+                );
826
+            }
827
+        }
828
+
829
+        /**
830
+         * Filters the action links for each attachment in the Media list table.
831
+         *
832
+         * @since 2.8.0
833
+         *
834
+         * @param string[] $actions  An array of action links for each attachment.
835
+         *                           Default 'Edit', 'Delete Permanently', 'View'.
836
+         * @param WP_Post  $post     WP_Post object for the current attachment.
837
+         * @param bool     $detached Whether the list table contains media not attached
838
+         *                           to any posts. Default true.
839
+         */
840
+        return apply_filters( 'media_row_actions', $actions, $post, $this->detached );
841
+    }
842
+
843
+    /**
844
+     * Generates and displays row action links.
845
+     *
846
+     * @since 4.3.0
847
+     * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
848
+     *
849
+     * @param WP_Post $item        Attachment being acted upon.
850
+     * @param string  $column_name Current column name.
851
+     * @param string  $primary     Primary column name.
852
+     * @return string Row actions output for media attachments, or an empty string
853
+     *                if the current column is not the primary column.
854
+     */
855
+    protected function handle_row_actions( $item, $column_name, $primary ) {
856
+        if ( $primary !== $column_name ) {
857
+            return '';
858
+        }
859
+
860
+        $att_title = _draft_or_post_title();
861
+        $actions   = $this->_get_row_actions(
862
+            $item, // WP_Post object for an attachment.
863
+            $att_title
864
+        );
865
+
866
+        return $this->row_actions( $actions );
867
+    }
868 868
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-wp-importer.php 1 patch
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -3,265 +3,265 @@  discard block
 block discarded – undo
3 3
  * WP_Importer base class
4 4
  */
5 5
 class WP_Importer {
6
-	/**
7
-	 * Class Constructor
8
-	 */
9
-	public function __construct() {}
10
-
11
-	/**
12
-	 * Returns array with imported permalinks from WordPress database
13
-	 *
14
-	 * @global wpdb $wpdb WordPress database abstraction object.
15
-	 *
16
-	 * @param string $importer_name
17
-	 * @param string $blog_id
18
-	 * @return array
19
-	 */
20
-	public function get_imported_posts( $importer_name, $blog_id ) {
21
-		global $wpdb;
22
-
23
-		$hashtable = array();
24
-
25
-		$limit  = 100;
26
-		$offset = 0;
27
-
28
-		// Grab all posts in chunks.
29
-		do {
30
-			$meta_key = $importer_name . '_' . $blog_id . '_permalink';
31
-			$sql      = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );
32
-			$results  = $wpdb->get_results( $sql );
33
-
34
-			// Increment offset.
35
-			$offset = ( $limit + $offset );
36
-
37
-			if ( ! empty( $results ) ) {
38
-				foreach ( $results as $r ) {
39
-					// Set permalinks into array.
40
-					$hashtable[ $r->meta_value ] = (int) $r->post_id;
41
-				}
42
-			}
43
-		} while ( count( $results ) == $limit );
44
-
45
-		return $hashtable;
46
-	}
47
-
48
-	/**
49
-	 * Return count of imported permalinks from WordPress database
50
-	 *
51
-	 * @global wpdb $wpdb WordPress database abstraction object.
52
-	 *
53
-	 * @param string $importer_name
54
-	 * @param string $blog_id
55
-	 * @return int
56
-	 */
57
-	public function count_imported_posts( $importer_name, $blog_id ) {
58
-		global $wpdb;
59
-
60
-		$count = 0;
61
-
62
-		// Get count of permalinks.
63
-		$meta_key = $importer_name . '_' . $blog_id . '_permalink';
64
-		$sql      = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key );
65
-
66
-		$result = $wpdb->get_results( $sql );
67
-
68
-		if ( ! empty( $result ) ) {
69
-			$count = (int) $result[0]->cnt;
70
-		}
71
-
72
-		return $count;
73
-	}
74
-
75
-	/**
76
-	 * Set array with imported comments from WordPress database
77
-	 *
78
-	 * @global wpdb $wpdb WordPress database abstraction object.
79
-	 *
80
-	 * @param string $blog_id
81
-	 * @return array
82
-	 */
83
-	public function get_imported_comments( $blog_id ) {
84
-		global $wpdb;
85
-
86
-		$hashtable = array();
87
-
88
-		$limit  = 100;
89
-		$offset = 0;
90
-
91
-		// Grab all comments in chunks.
92
-		do {
93
-			$sql     = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit );
94
-			$results = $wpdb->get_results( $sql );
95
-
96
-			// Increment offset.
97
-			$offset = ( $limit + $offset );
98
-
99
-			if ( ! empty( $results ) ) {
100
-				foreach ( $results as $r ) {
101
-					// Explode comment_agent key.
102
-					list ( $comment_agent_blog_id, $source_comment_id ) = explode( '-', $r->comment_agent );
103
-
104
-					$source_comment_id = (int) $source_comment_id;
105
-
106
-					// Check if this comment came from this blog.
107
-					if ( $blog_id == $comment_agent_blog_id ) {
108
-						$hashtable[ $source_comment_id ] = (int) $r->comment_ID;
109
-					}
110
-				}
111
-			}
112
-		} while ( count( $results ) == $limit );
113
-
114
-		return $hashtable;
115
-	}
116
-
117
-	/**
118
-	 * @param int $blog_id
119
-	 * @return int|void
120
-	 */
121
-	public function set_blog( $blog_id ) {
122
-		if ( is_numeric( $blog_id ) ) {
123
-			$blog_id = (int) $blog_id;
124
-		} else {
125
-			$blog   = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
126
-			$parsed = parse_url( $blog );
127
-			if ( ! $parsed || empty( $parsed['host'] ) ) {
128
-				fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
129
-				exit;
130
-			}
131
-			if ( empty( $parsed['path'] ) ) {
132
-				$parsed['path'] = '/';
133
-			}
134
-			$blogs = get_sites(
135
-				array(
136
-					'domain' => $parsed['host'],
137
-					'number' => 1,
138
-					'path'   => $parsed['path'],
139
-				)
140
-			);
141
-			if ( ! $blogs ) {
142
-				fwrite( STDERR, "Error: Could not find blog\n" );
143
-				exit;
144
-			}
145
-			$blog    = array_shift( $blogs );
146
-			$blog_id = (int) $blog->blog_id;
147
-		}
148
-
149
-		if ( function_exists( 'is_multisite' ) ) {
150
-			if ( is_multisite() ) {
151
-				switch_to_blog( $blog_id );
152
-			}
153
-		}
154
-
155
-		return $blog_id;
156
-	}
157
-
158
-	/**
159
-	 * @param int $user_id
160
-	 * @return int|void
161
-	 */
162
-	public function set_user( $user_id ) {
163
-		if ( is_numeric( $user_id ) ) {
164
-			$user_id = (int) $user_id;
165
-		} else {
166
-			$user_id = (int) username_exists( $user_id );
167
-		}
168
-
169
-		if ( ! $user_id || ! wp_set_current_user( $user_id ) ) {
170
-			fwrite( STDERR, "Error: can not find user\n" );
171
-			exit;
172
-		}
173
-
174
-		return $user_id;
175
-	}
176
-
177
-	/**
178
-	 * Sort by strlen, longest string first
179
-	 *
180
-	 * @param string $a
181
-	 * @param string $b
182
-	 * @return int
183
-	 */
184
-	public function cmpr_strlen( $a, $b ) {
185
-		return strlen( $b ) - strlen( $a );
186
-	}
187
-
188
-	/**
189
-	 * GET URL
190
-	 *
191
-	 * @param string $url
192
-	 * @param string $username
193
-	 * @param string $password
194
-	 * @param bool   $head
195
-	 * @return array
196
-	 */
197
-	public function get_page( $url, $username = '', $password = '', $head = false ) {
198
-		// Increase the timeout.
199
-		add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
200
-
201
-		$headers = array();
202
-		$args    = array();
203
-		if ( true === $head ) {
204
-			$args['method'] = 'HEAD';
205
-		}
206
-		if ( ! empty( $username ) && ! empty( $password ) ) {
207
-			$headers['Authorization'] = 'Basic ' . base64_encode( "$username:$password" );
208
-		}
209
-
210
-		$args['headers'] = $headers;
211
-
212
-		return wp_safe_remote_request( $url, $args );
213
-	}
214
-
215
-	/**
216
-	 * Bump up the request timeout for http requests
217
-	 *
218
-	 * @param int $val
219
-	 * @return int
220
-	 */
221
-	public function bump_request_timeout( $val ) {
222
-		return 60;
223
-	}
224
-
225
-	/**
226
-	 * Check if user has exceeded disk quota
227
-	 *
228
-	 * @return bool
229
-	 */
230
-	public function is_user_over_quota() {
231
-		if ( function_exists( 'upload_is_user_over_quota' ) ) {
232
-			if ( upload_is_user_over_quota() ) {
233
-				return true;
234
-			}
235
-		}
236
-
237
-		return false;
238
-	}
239
-
240
-	/**
241
-	 * Replace newlines, tabs, and multiple spaces with a single space.
242
-	 *
243
-	 * @param string $text
244
-	 * @return string
245
-	 */
246
-	public function min_whitespace( $text ) {
247
-		return preg_replace( '|[\r\n\t ]+|', ' ', $text );
248
-	}
249
-
250
-	/**
251
-	 * Resets global variables that grow out of control during imports.
252
-	 *
253
-	 * @since 3.0.0
254
-	 *
255
-	 * @global wpdb  $wpdb       WordPress database abstraction object.
256
-	 * @global int[] $wp_actions
257
-	 */
258
-	public function stop_the_insanity() {
259
-		global $wpdb, $wp_actions;
260
-		// Or define( 'WP_IMPORTING', true );
261
-		$wpdb->queries = array();
262
-		// Reset $wp_actions to keep it from growing out of control.
263
-		$wp_actions = array();
264
-	}
6
+    /**
7
+     * Class Constructor
8
+     */
9
+    public function __construct() {}
10
+
11
+    /**
12
+     * Returns array with imported permalinks from WordPress database
13
+     *
14
+     * @global wpdb $wpdb WordPress database abstraction object.
15
+     *
16
+     * @param string $importer_name
17
+     * @param string $blog_id
18
+     * @return array
19
+     */
20
+    public function get_imported_posts( $importer_name, $blog_id ) {
21
+        global $wpdb;
22
+
23
+        $hashtable = array();
24
+
25
+        $limit  = 100;
26
+        $offset = 0;
27
+
28
+        // Grab all posts in chunks.
29
+        do {
30
+            $meta_key = $importer_name . '_' . $blog_id . '_permalink';
31
+            $sql      = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );
32
+            $results  = $wpdb->get_results( $sql );
33
+
34
+            // Increment offset.
35
+            $offset = ( $limit + $offset );
36
+
37
+            if ( ! empty( $results ) ) {
38
+                foreach ( $results as $r ) {
39
+                    // Set permalinks into array.
40
+                    $hashtable[ $r->meta_value ] = (int) $r->post_id;
41
+                }
42
+            }
43
+        } while ( count( $results ) == $limit );
44
+
45
+        return $hashtable;
46
+    }
47
+
48
+    /**
49
+     * Return count of imported permalinks from WordPress database
50
+     *
51
+     * @global wpdb $wpdb WordPress database abstraction object.
52
+     *
53
+     * @param string $importer_name
54
+     * @param string $blog_id
55
+     * @return int
56
+     */
57
+    public function count_imported_posts( $importer_name, $blog_id ) {
58
+        global $wpdb;
59
+
60
+        $count = 0;
61
+
62
+        // Get count of permalinks.
63
+        $meta_key = $importer_name . '_' . $blog_id . '_permalink';
64
+        $sql      = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key );
65
+
66
+        $result = $wpdb->get_results( $sql );
67
+
68
+        if ( ! empty( $result ) ) {
69
+            $count = (int) $result[0]->cnt;
70
+        }
71
+
72
+        return $count;
73
+    }
74
+
75
+    /**
76
+     * Set array with imported comments from WordPress database
77
+     *
78
+     * @global wpdb $wpdb WordPress database abstraction object.
79
+     *
80
+     * @param string $blog_id
81
+     * @return array
82
+     */
83
+    public function get_imported_comments( $blog_id ) {
84
+        global $wpdb;
85
+
86
+        $hashtable = array();
87
+
88
+        $limit  = 100;
89
+        $offset = 0;
90
+
91
+        // Grab all comments in chunks.
92
+        do {
93
+            $sql     = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit );
94
+            $results = $wpdb->get_results( $sql );
95
+
96
+            // Increment offset.
97
+            $offset = ( $limit + $offset );
98
+
99
+            if ( ! empty( $results ) ) {
100
+                foreach ( $results as $r ) {
101
+                    // Explode comment_agent key.
102
+                    list ( $comment_agent_blog_id, $source_comment_id ) = explode( '-', $r->comment_agent );
103
+
104
+                    $source_comment_id = (int) $source_comment_id;
105
+
106
+                    // Check if this comment came from this blog.
107
+                    if ( $blog_id == $comment_agent_blog_id ) {
108
+                        $hashtable[ $source_comment_id ] = (int) $r->comment_ID;
109
+                    }
110
+                }
111
+            }
112
+        } while ( count( $results ) == $limit );
113
+
114
+        return $hashtable;
115
+    }
116
+
117
+    /**
118
+     * @param int $blog_id
119
+     * @return int|void
120
+     */
121
+    public function set_blog( $blog_id ) {
122
+        if ( is_numeric( $blog_id ) ) {
123
+            $blog_id = (int) $blog_id;
124
+        } else {
125
+            $blog   = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
126
+            $parsed = parse_url( $blog );
127
+            if ( ! $parsed || empty( $parsed['host'] ) ) {
128
+                fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
129
+                exit;
130
+            }
131
+            if ( empty( $parsed['path'] ) ) {
132
+                $parsed['path'] = '/';
133
+            }
134
+            $blogs = get_sites(
135
+                array(
136
+                    'domain' => $parsed['host'],
137
+                    'number' => 1,
138
+                    'path'   => $parsed['path'],
139
+                )
140
+            );
141
+            if ( ! $blogs ) {
142
+                fwrite( STDERR, "Error: Could not find blog\n" );
143
+                exit;
144
+            }
145
+            $blog    = array_shift( $blogs );
146
+            $blog_id = (int) $blog->blog_id;
147
+        }
148
+
149
+        if ( function_exists( 'is_multisite' ) ) {
150
+            if ( is_multisite() ) {
151
+                switch_to_blog( $blog_id );
152
+            }
153
+        }
154
+
155
+        return $blog_id;
156
+    }
157
+
158
+    /**
159
+     * @param int $user_id
160
+     * @return int|void
161
+     */
162
+    public function set_user( $user_id ) {
163
+        if ( is_numeric( $user_id ) ) {
164
+            $user_id = (int) $user_id;
165
+        } else {
166
+            $user_id = (int) username_exists( $user_id );
167
+        }
168
+
169
+        if ( ! $user_id || ! wp_set_current_user( $user_id ) ) {
170
+            fwrite( STDERR, "Error: can not find user\n" );
171
+            exit;
172
+        }
173
+
174
+        return $user_id;
175
+    }
176
+
177
+    /**
178
+     * Sort by strlen, longest string first
179
+     *
180
+     * @param string $a
181
+     * @param string $b
182
+     * @return int
183
+     */
184
+    public function cmpr_strlen( $a, $b ) {
185
+        return strlen( $b ) - strlen( $a );
186
+    }
187
+
188
+    /**
189
+     * GET URL
190
+     *
191
+     * @param string $url
192
+     * @param string $username
193
+     * @param string $password
194
+     * @param bool   $head
195
+     * @return array
196
+     */
197
+    public function get_page( $url, $username = '', $password = '', $head = false ) {
198
+        // Increase the timeout.
199
+        add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
200
+
201
+        $headers = array();
202
+        $args    = array();
203
+        if ( true === $head ) {
204
+            $args['method'] = 'HEAD';
205
+        }
206
+        if ( ! empty( $username ) && ! empty( $password ) ) {
207
+            $headers['Authorization'] = 'Basic ' . base64_encode( "$username:$password" );
208
+        }
209
+
210
+        $args['headers'] = $headers;
211
+
212
+        return wp_safe_remote_request( $url, $args );
213
+    }
214
+
215
+    /**
216
+     * Bump up the request timeout for http requests
217
+     *
218
+     * @param int $val
219
+     * @return int
220
+     */
221
+    public function bump_request_timeout( $val ) {
222
+        return 60;
223
+    }
224
+
225
+    /**
226
+     * Check if user has exceeded disk quota
227
+     *
228
+     * @return bool
229
+     */
230
+    public function is_user_over_quota() {
231
+        if ( function_exists( 'upload_is_user_over_quota' ) ) {
232
+            if ( upload_is_user_over_quota() ) {
233
+                return true;
234
+            }
235
+        }
236
+
237
+        return false;
238
+    }
239
+
240
+    /**
241
+     * Replace newlines, tabs, and multiple spaces with a single space.
242
+     *
243
+     * @param string $text
244
+     * @return string
245
+     */
246
+    public function min_whitespace( $text ) {
247
+        return preg_replace( '|[\r\n\t ]+|', ' ', $text );
248
+    }
249
+
250
+    /**
251
+     * Resets global variables that grow out of control during imports.
252
+     *
253
+     * @since 3.0.0
254
+     *
255
+     * @global wpdb  $wpdb       WordPress database abstraction object.
256
+     * @global int[] $wp_actions
257
+     */
258
+    public function stop_the_insanity() {
259
+        global $wpdb, $wp_actions;
260
+        // Or define( 'WP_IMPORTING', true );
261
+        $wpdb->queries = array();
262
+        // Reset $wp_actions to keep it from growing out of control.
263
+        $wp_actions = array();
264
+    }
265 265
 }
266 266
 
267 267
 /**
@@ -273,54 +273,54 @@  discard block
 block discarded – undo
273 273
  * @return mixed
274 274
  */
275 275
 function get_cli_args( $param, $required = false ) {
276
-	$args = $_SERVER['argv'];
277
-	if ( ! is_array( $args ) ) {
278
-		$args = array();
279
-	}
280
-
281
-	$out = array();
282
-
283
-	$last_arg = null;
284
-	$return   = null;
285
-
286
-	$il = count( $args );
287
-
288
-	for ( $i = 1, $il; $i < $il; $i++ ) {
289
-		if ( (bool) preg_match( '/^--(.+)/', $args[ $i ], $match ) ) {
290
-			$parts = explode( '=', $match[1] );
291
-			$key   = preg_replace( '/[^a-z0-9]+/', '', $parts[0] );
292
-
293
-			if ( isset( $parts[1] ) ) {
294
-				$out[ $key ] = $parts[1];
295
-			} else {
296
-				$out[ $key ] = true;
297
-			}
298
-
299
-			$last_arg = $key;
300
-		} elseif ( (bool) preg_match( '/^-([a-zA-Z0-9]+)/', $args[ $i ], $match ) ) {
301
-			for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) {
302
-				$key         = $match[1][ $j ];
303
-				$out[ $key ] = true;
304
-			}
305
-
306
-			$last_arg = $key;
307
-		} elseif ( null !== $last_arg ) {
308
-			$out[ $last_arg ] = $args[ $i ];
309
-		}
310
-	}
311
-
312
-	// Check array for specified param.
313
-	if ( isset( $out[ $param ] ) ) {
314
-		// Set return value.
315
-		$return = $out[ $param ];
316
-	}
317
-
318
-	// Check for missing required param.
319
-	if ( ! isset( $out[ $param ] ) && $required ) {
320
-		// Display message and exit.
321
-		echo "\"$param\" parameter is required but was not specified\n";
322
-		exit;
323
-	}
324
-
325
-	return $return;
276
+    $args = $_SERVER['argv'];
277
+    if ( ! is_array( $args ) ) {
278
+        $args = array();
279
+    }
280
+
281
+    $out = array();
282
+
283
+    $last_arg = null;
284
+    $return   = null;
285
+
286
+    $il = count( $args );
287
+
288
+    for ( $i = 1, $il; $i < $il; $i++ ) {
289
+        if ( (bool) preg_match( '/^--(.+)/', $args[ $i ], $match ) ) {
290
+            $parts = explode( '=', $match[1] );
291
+            $key   = preg_replace( '/[^a-z0-9]+/', '', $parts[0] );
292
+
293
+            if ( isset( $parts[1] ) ) {
294
+                $out[ $key ] = $parts[1];
295
+            } else {
296
+                $out[ $key ] = true;
297
+            }
298
+
299
+            $last_arg = $key;
300
+        } elseif ( (bool) preg_match( '/^-([a-zA-Z0-9]+)/', $args[ $i ], $match ) ) {
301
+            for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) {
302
+                $key         = $match[1][ $j ];
303
+                $out[ $key ] = true;
304
+            }
305
+
306
+            $last_arg = $key;
307
+        } elseif ( null !== $last_arg ) {
308
+            $out[ $last_arg ] = $args[ $i ];
309
+        }
310
+    }
311
+
312
+    // Check array for specified param.
313
+    if ( isset( $out[ $param ] ) ) {
314
+        // Set return value.
315
+        $return = $out[ $param ];
316
+    }
317
+
318
+    // Check for missing required param.
319
+    if ( ! isset( $out[ $param ] ) && $required ) {
320
+        // Display message and exit.
321
+        echo "\"$param\" parameter is required but was not specified\n";
322
+        exit;
323
+    }
324
+
325
+    return $return;
326 326
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-plugin-upgrader.php 1 patch
Indentation   +630 added lines, -630 removed lines patch added patch discarded remove patch
@@ -20,639 +20,639 @@
 block discarded – undo
20 20
  */
21 21
 class Plugin_Upgrader extends WP_Upgrader {
22 22
 
23
-	/**
24
-	 * Plugin upgrade result.
25
-	 *
26
-	 * @since 2.8.0
27
-	 * @var array|WP_Error $result
28
-	 *
29
-	 * @see WP_Upgrader::$result
30
-	 */
31
-	public $result;
32
-
33
-	/**
34
-	 * Whether a bulk upgrade/installation is being performed.
35
-	 *
36
-	 * @since 2.9.0
37
-	 * @var bool $bulk
38
-	 */
39
-	public $bulk = false;
40
-
41
-	/**
42
-	 * New plugin info.
43
-	 *
44
-	 * @since 5.5.0
45
-	 * @var array $new_plugin_data
46
-	 *
47
-	 * @see check_package()
48
-	 */
49
-	public $new_plugin_data = array();
50
-
51
-	/**
52
-	 * Initialize the upgrade strings.
53
-	 *
54
-	 * @since 2.8.0
55
-	 */
56
-	public function upgrade_strings() {
57
-		$this->strings['up_to_date'] = __( 'The plugin is at the latest version.' );
58
-		$this->strings['no_package'] = __( 'Update package not available.' );
59
-		/* translators: %s: Package URL. */
60
-		$this->strings['downloading_package']  = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
61
-		$this->strings['unpack_package']       = __( 'Unpacking the update&#8230;' );
62
-		$this->strings['remove_old']           = __( 'Removing the old version of the plugin&#8230;' );
63
-		$this->strings['remove_old_failed']    = __( 'Could not remove the old plugin.' );
64
-		$this->strings['process_failed']       = __( 'Plugin update failed.' );
65
-		$this->strings['process_success']      = __( 'Plugin updated successfully.' );
66
-		$this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' );
67
-	}
68
-
69
-	/**
70
-	 * Initialize the installation strings.
71
-	 *
72
-	 * @since 2.8.0
73
-	 */
74
-	public function install_strings() {
75
-		$this->strings['no_package'] = __( 'Installation package not available.' );
76
-		/* translators: %s: Package URL. */
77
-		$this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s&#8230;' ), '<span class="code">%s</span>' );
78
-		$this->strings['unpack_package']      = __( 'Unpacking the package&#8230;' );
79
-		$this->strings['installing_package']  = __( 'Installing the plugin&#8230;' );
80
-		$this->strings['remove_old']          = __( 'Removing the current plugin&#8230;' );
81
-		$this->strings['remove_old_failed']   = __( 'Could not remove the current plugin.' );
82
-		$this->strings['no_files']            = __( 'The plugin contains no files.' );
83
-		$this->strings['process_failed']      = __( 'Plugin installation failed.' );
84
-		$this->strings['process_success']     = __( 'Plugin installed successfully.' );
85
-		/* translators: 1: Plugin name, 2: Plugin version. */
86
-		$this->strings['process_success_specific'] = __( 'Successfully installed the plugin <strong>%1$s %2$s</strong>.' );
87
-
88
-		if ( ! empty( $this->skin->overwrite ) ) {
89
-			if ( 'update-plugin' === $this->skin->overwrite ) {
90
-				$this->strings['installing_package'] = __( 'Updating the plugin&#8230;' );
91
-				$this->strings['process_failed']     = __( 'Plugin update failed.' );
92
-				$this->strings['process_success']    = __( 'Plugin updated successfully.' );
93
-			}
94
-
95
-			if ( 'downgrade-plugin' === $this->skin->overwrite ) {
96
-				$this->strings['installing_package'] = __( 'Downgrading the plugin&#8230;' );
97
-				$this->strings['process_failed']     = __( 'Plugin downgrade failed.' );
98
-				$this->strings['process_success']    = __( 'Plugin downgraded successfully.' );
99
-			}
100
-		}
101
-	}
102
-
103
-	/**
104
-	 * Install a plugin package.
105
-	 *
106
-	 * @since 2.8.0
107
-	 * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
108
-	 *
109
-	 * @param string $package The full local path or URI of the package.
110
-	 * @param array  $args {
111
-	 *     Optional. Other arguments for installing a plugin package. Default empty array.
112
-	 *
113
-	 *     @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
114
-	 *                                    Default true.
115
-	 * }
116
-	 * @return bool|WP_Error True if the installation was successful, false or a WP_Error otherwise.
117
-	 */
118
-	public function install( $package, $args = array() ) {
119
-		$defaults    = array(
120
-			'clear_update_cache' => true,
121
-			'overwrite_package'  => false, // Do not overwrite files.
122
-		);
123
-		$parsed_args = wp_parse_args( $args, $defaults );
124
-
125
-		$this->init();
126
-		$this->install_strings();
127
-
128
-		add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
129
-
130
-		if ( $parsed_args['clear_update_cache'] ) {
131
-			// Clear cache so wp_update_plugins() knows about the new plugin.
132
-			add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
133
-		}
134
-
135
-		$this->run(
136
-			array(
137
-				'package'           => $package,
138
-				'destination'       => WP_PLUGIN_DIR,
139
-				'clear_destination' => $parsed_args['overwrite_package'],
140
-				'clear_working'     => true,
141
-				'hook_extra'        => array(
142
-					'type'   => 'plugin',
143
-					'action' => 'install',
144
-				),
145
-			)
146
-		);
147
-
148
-		remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
149
-		remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
150
-
151
-		if ( ! $this->result || is_wp_error( $this->result ) ) {
152
-			return $this->result;
153
-		}
154
-
155
-		// Force refresh of plugin update information.
156
-		wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
157
-
158
-		if ( $parsed_args['overwrite_package'] ) {
159
-			/**
160
-			 * Fires when the upgrader has successfully overwritten a currently installed
161
-			 * plugin or theme with an uploaded zip package.
162
-			 *
163
-			 * @since 5.5.0
164
-			 *
165
-			 * @param string  $package      The package file.
166
-			 * @param array   $data         The new plugin or theme data.
167
-			 * @param string  $package_type The package type ('plugin' or 'theme').
168
-			 */
169
-			do_action( 'upgrader_overwrote_package', $package, $this->new_plugin_data, 'plugin' );
170
-		}
171
-
172
-		return true;
173
-	}
174
-
175
-	/**
176
-	 * Upgrade a plugin.
177
-	 *
178
-	 * @since 2.8.0
179
-	 * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
180
-	 *
181
-	 * @param string $plugin Path to the plugin file relative to the plugins directory.
182
-	 * @param array  $args {
183
-	 *     Optional. Other arguments for upgrading a plugin package. Default empty array.
184
-	 *
185
-	 *     @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
186
-	 *                                    Default true.
187
-	 * }
188
-	 * @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise.
189
-	 */
190
-	public function upgrade( $plugin, $args = array() ) {
191
-		$defaults    = array(
192
-			'clear_update_cache' => true,
193
-		);
194
-		$parsed_args = wp_parse_args( $args, $defaults );
195
-
196
-		$this->init();
197
-		$this->upgrade_strings();
198
-
199
-		$current = get_site_transient( 'update_plugins' );
200
-		if ( ! isset( $current->response[ $plugin ] ) ) {
201
-			$this->skin->before();
202
-			$this->skin->set_result( false );
203
-			$this->skin->error( 'up_to_date' );
204
-			$this->skin->after();
205
-			return false;
206
-		}
207
-
208
-		// Get the URL to the zip file.
209
-		$r = $current->response[ $plugin ];
210
-
211
-		add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
212
-		add_filter( 'upgrader_pre_install', array( $this, 'active_before' ), 10, 2 );
213
-		add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
214
-		add_filter( 'upgrader_post_install', array( $this, 'active_after' ), 10, 2 );
215
-		// There's a Trac ticket to move up the directory for zips which are made a bit differently, useful for non-.org plugins.
216
-		// 'source_selection' => array( $this, 'source_selection' ),
217
-		if ( $parsed_args['clear_update_cache'] ) {
218
-			// Clear cache so wp_update_plugins() knows about the new plugin.
219
-			add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
220
-		}
221
-
222
-		$this->run(
223
-			array(
224
-				'package'           => $r->package,
225
-				'destination'       => WP_PLUGIN_DIR,
226
-				'clear_destination' => true,
227
-				'clear_working'     => true,
228
-				'hook_extra'        => array(
229
-					'plugin' => $plugin,
230
-					'type'   => 'plugin',
231
-					'action' => 'update',
232
-				),
233
-			)
234
-		);
235
-
236
-		// Cleanup our hooks, in case something else does a upgrade on this connection.
237
-		remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
238
-		remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
239
-		remove_filter( 'upgrader_pre_install', array( $this, 'active_before' ) );
240
-		remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
241
-		remove_filter( 'upgrader_post_install', array( $this, 'active_after' ) );
242
-
243
-		if ( ! $this->result || is_wp_error( $this->result ) ) {
244
-			return $this->result;
245
-		}
246
-
247
-		// Force refresh of plugin update information.
248
-		wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
249
-
250
-		// Ensure any future auto-update failures trigger a failure email by removing
251
-		// the last failure notification from the list when plugins update successfully.
252
-		$past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() );
253
-
254
-		if ( isset( $past_failure_emails[ $plugin ] ) ) {
255
-			unset( $past_failure_emails[ $plugin ] );
256
-			update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
257
-		}
258
-
259
-		return true;
260
-	}
261
-
262
-	/**
263
-	 * Bulk upgrade several plugins at once.
264
-	 *
265
-	 * @since 2.8.0
266
-	 * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
267
-	 *
268
-	 * @param string[] $plugins Array of paths to plugin files relative to the plugins directory.
269
-	 * @param array    $args {
270
-	 *     Optional. Other arguments for upgrading several plugins at once.
271
-	 *
272
-	 *     @type bool $clear_update_cache Whether to clear the plugin updates cache if successful. Default true.
273
-	 * }
274
-	 * @return array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem.
275
-	 */
276
-	public function bulk_upgrade( $plugins, $args = array() ) {
277
-		$defaults    = array(
278
-			'clear_update_cache' => true,
279
-		);
280
-		$parsed_args = wp_parse_args( $args, $defaults );
281
-
282
-		$this->init();
283
-		$this->bulk = true;
284
-		$this->upgrade_strings();
285
-
286
-		$current = get_site_transient( 'update_plugins' );
287
-
288
-		add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
289
-
290
-		$this->skin->header();
291
-
292
-		// Connect to the filesystem first.
293
-		$res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
294
-		if ( ! $res ) {
295
-			$this->skin->footer();
296
-			return false;
297
-		}
298
-
299
-		$this->skin->bulk_header();
300
-
301
-		/*
23
+    /**
24
+     * Plugin upgrade result.
25
+     *
26
+     * @since 2.8.0
27
+     * @var array|WP_Error $result
28
+     *
29
+     * @see WP_Upgrader::$result
30
+     */
31
+    public $result;
32
+
33
+    /**
34
+     * Whether a bulk upgrade/installation is being performed.
35
+     *
36
+     * @since 2.9.0
37
+     * @var bool $bulk
38
+     */
39
+    public $bulk = false;
40
+
41
+    /**
42
+     * New plugin info.
43
+     *
44
+     * @since 5.5.0
45
+     * @var array $new_plugin_data
46
+     *
47
+     * @see check_package()
48
+     */
49
+    public $new_plugin_data = array();
50
+
51
+    /**
52
+     * Initialize the upgrade strings.
53
+     *
54
+     * @since 2.8.0
55
+     */
56
+    public function upgrade_strings() {
57
+        $this->strings['up_to_date'] = __( 'The plugin is at the latest version.' );
58
+        $this->strings['no_package'] = __( 'Update package not available.' );
59
+        /* translators: %s: Package URL. */
60
+        $this->strings['downloading_package']  = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
61
+        $this->strings['unpack_package']       = __( 'Unpacking the update&#8230;' );
62
+        $this->strings['remove_old']           = __( 'Removing the old version of the plugin&#8230;' );
63
+        $this->strings['remove_old_failed']    = __( 'Could not remove the old plugin.' );
64
+        $this->strings['process_failed']       = __( 'Plugin update failed.' );
65
+        $this->strings['process_success']      = __( 'Plugin updated successfully.' );
66
+        $this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' );
67
+    }
68
+
69
+    /**
70
+     * Initialize the installation strings.
71
+     *
72
+     * @since 2.8.0
73
+     */
74
+    public function install_strings() {
75
+        $this->strings['no_package'] = __( 'Installation package not available.' );
76
+        /* translators: %s: Package URL. */
77
+        $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s&#8230;' ), '<span class="code">%s</span>' );
78
+        $this->strings['unpack_package']      = __( 'Unpacking the package&#8230;' );
79
+        $this->strings['installing_package']  = __( 'Installing the plugin&#8230;' );
80
+        $this->strings['remove_old']          = __( 'Removing the current plugin&#8230;' );
81
+        $this->strings['remove_old_failed']   = __( 'Could not remove the current plugin.' );
82
+        $this->strings['no_files']            = __( 'The plugin contains no files.' );
83
+        $this->strings['process_failed']      = __( 'Plugin installation failed.' );
84
+        $this->strings['process_success']     = __( 'Plugin installed successfully.' );
85
+        /* translators: 1: Plugin name, 2: Plugin version. */
86
+        $this->strings['process_success_specific'] = __( 'Successfully installed the plugin <strong>%1$s %2$s</strong>.' );
87
+
88
+        if ( ! empty( $this->skin->overwrite ) ) {
89
+            if ( 'update-plugin' === $this->skin->overwrite ) {
90
+                $this->strings['installing_package'] = __( 'Updating the plugin&#8230;' );
91
+                $this->strings['process_failed']     = __( 'Plugin update failed.' );
92
+                $this->strings['process_success']    = __( 'Plugin updated successfully.' );
93
+            }
94
+
95
+            if ( 'downgrade-plugin' === $this->skin->overwrite ) {
96
+                $this->strings['installing_package'] = __( 'Downgrading the plugin&#8230;' );
97
+                $this->strings['process_failed']     = __( 'Plugin downgrade failed.' );
98
+                $this->strings['process_success']    = __( 'Plugin downgraded successfully.' );
99
+            }
100
+        }
101
+    }
102
+
103
+    /**
104
+     * Install a plugin package.
105
+     *
106
+     * @since 2.8.0
107
+     * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
108
+     *
109
+     * @param string $package The full local path or URI of the package.
110
+     * @param array  $args {
111
+     *     Optional. Other arguments for installing a plugin package. Default empty array.
112
+     *
113
+     *     @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
114
+     *                                    Default true.
115
+     * }
116
+     * @return bool|WP_Error True if the installation was successful, false or a WP_Error otherwise.
117
+     */
118
+    public function install( $package, $args = array() ) {
119
+        $defaults    = array(
120
+            'clear_update_cache' => true,
121
+            'overwrite_package'  => false, // Do not overwrite files.
122
+        );
123
+        $parsed_args = wp_parse_args( $args, $defaults );
124
+
125
+        $this->init();
126
+        $this->install_strings();
127
+
128
+        add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
129
+
130
+        if ( $parsed_args['clear_update_cache'] ) {
131
+            // Clear cache so wp_update_plugins() knows about the new plugin.
132
+            add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
133
+        }
134
+
135
+        $this->run(
136
+            array(
137
+                'package'           => $package,
138
+                'destination'       => WP_PLUGIN_DIR,
139
+                'clear_destination' => $parsed_args['overwrite_package'],
140
+                'clear_working'     => true,
141
+                'hook_extra'        => array(
142
+                    'type'   => 'plugin',
143
+                    'action' => 'install',
144
+                ),
145
+            )
146
+        );
147
+
148
+        remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
149
+        remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
150
+
151
+        if ( ! $this->result || is_wp_error( $this->result ) ) {
152
+            return $this->result;
153
+        }
154
+
155
+        // Force refresh of plugin update information.
156
+        wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
157
+
158
+        if ( $parsed_args['overwrite_package'] ) {
159
+            /**
160
+             * Fires when the upgrader has successfully overwritten a currently installed
161
+             * plugin or theme with an uploaded zip package.
162
+             *
163
+             * @since 5.5.0
164
+             *
165
+             * @param string  $package      The package file.
166
+             * @param array   $data         The new plugin or theme data.
167
+             * @param string  $package_type The package type ('plugin' or 'theme').
168
+             */
169
+            do_action( 'upgrader_overwrote_package', $package, $this->new_plugin_data, 'plugin' );
170
+        }
171
+
172
+        return true;
173
+    }
174
+
175
+    /**
176
+     * Upgrade a plugin.
177
+     *
178
+     * @since 2.8.0
179
+     * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
180
+     *
181
+     * @param string $plugin Path to the plugin file relative to the plugins directory.
182
+     * @param array  $args {
183
+     *     Optional. Other arguments for upgrading a plugin package. Default empty array.
184
+     *
185
+     *     @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
186
+     *                                    Default true.
187
+     * }
188
+     * @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise.
189
+     */
190
+    public function upgrade( $plugin, $args = array() ) {
191
+        $defaults    = array(
192
+            'clear_update_cache' => true,
193
+        );
194
+        $parsed_args = wp_parse_args( $args, $defaults );
195
+
196
+        $this->init();
197
+        $this->upgrade_strings();
198
+
199
+        $current = get_site_transient( 'update_plugins' );
200
+        if ( ! isset( $current->response[ $plugin ] ) ) {
201
+            $this->skin->before();
202
+            $this->skin->set_result( false );
203
+            $this->skin->error( 'up_to_date' );
204
+            $this->skin->after();
205
+            return false;
206
+        }
207
+
208
+        // Get the URL to the zip file.
209
+        $r = $current->response[ $plugin ];
210
+
211
+        add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
212
+        add_filter( 'upgrader_pre_install', array( $this, 'active_before' ), 10, 2 );
213
+        add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
214
+        add_filter( 'upgrader_post_install', array( $this, 'active_after' ), 10, 2 );
215
+        // There's a Trac ticket to move up the directory for zips which are made a bit differently, useful for non-.org plugins.
216
+        // 'source_selection' => array( $this, 'source_selection' ),
217
+        if ( $parsed_args['clear_update_cache'] ) {
218
+            // Clear cache so wp_update_plugins() knows about the new plugin.
219
+            add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
220
+        }
221
+
222
+        $this->run(
223
+            array(
224
+                'package'           => $r->package,
225
+                'destination'       => WP_PLUGIN_DIR,
226
+                'clear_destination' => true,
227
+                'clear_working'     => true,
228
+                'hook_extra'        => array(
229
+                    'plugin' => $plugin,
230
+                    'type'   => 'plugin',
231
+                    'action' => 'update',
232
+                ),
233
+            )
234
+        );
235
+
236
+        // Cleanup our hooks, in case something else does a upgrade on this connection.
237
+        remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
238
+        remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
239
+        remove_filter( 'upgrader_pre_install', array( $this, 'active_before' ) );
240
+        remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
241
+        remove_filter( 'upgrader_post_install', array( $this, 'active_after' ) );
242
+
243
+        if ( ! $this->result || is_wp_error( $this->result ) ) {
244
+            return $this->result;
245
+        }
246
+
247
+        // Force refresh of plugin update information.
248
+        wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
249
+
250
+        // Ensure any future auto-update failures trigger a failure email by removing
251
+        // the last failure notification from the list when plugins update successfully.
252
+        $past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() );
253
+
254
+        if ( isset( $past_failure_emails[ $plugin ] ) ) {
255
+            unset( $past_failure_emails[ $plugin ] );
256
+            update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
257
+        }
258
+
259
+        return true;
260
+    }
261
+
262
+    /**
263
+     * Bulk upgrade several plugins at once.
264
+     *
265
+     * @since 2.8.0
266
+     * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
267
+     *
268
+     * @param string[] $plugins Array of paths to plugin files relative to the plugins directory.
269
+     * @param array    $args {
270
+     *     Optional. Other arguments for upgrading several plugins at once.
271
+     *
272
+     *     @type bool $clear_update_cache Whether to clear the plugin updates cache if successful. Default true.
273
+     * }
274
+     * @return array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem.
275
+     */
276
+    public function bulk_upgrade( $plugins, $args = array() ) {
277
+        $defaults    = array(
278
+            'clear_update_cache' => true,
279
+        );
280
+        $parsed_args = wp_parse_args( $args, $defaults );
281
+
282
+        $this->init();
283
+        $this->bulk = true;
284
+        $this->upgrade_strings();
285
+
286
+        $current = get_site_transient( 'update_plugins' );
287
+
288
+        add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
289
+
290
+        $this->skin->header();
291
+
292
+        // Connect to the filesystem first.
293
+        $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
294
+        if ( ! $res ) {
295
+            $this->skin->footer();
296
+            return false;
297
+        }
298
+
299
+        $this->skin->bulk_header();
300
+
301
+        /*
302 302
 		 * Only start maintenance mode if:
303 303
 		 * - running Multisite and there are one or more plugins specified, OR
304 304
 		 * - a plugin with an update available is currently active.
305 305
 		 * @todo For multisite, maintenance mode should only kick in for individual sites if at all possible.
306 306
 		 */
307
-		$maintenance = ( is_multisite() && ! empty( $plugins ) );
308
-		foreach ( $plugins as $plugin ) {
309
-			$maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) );
310
-		}
311
-		if ( $maintenance ) {
312
-			$this->maintenance_mode( true );
313
-		}
314
-
315
-		$results = array();
316
-
317
-		$this->update_count   = count( $plugins );
318
-		$this->update_current = 0;
319
-		foreach ( $plugins as $plugin ) {
320
-			$this->update_current++;
321
-			$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true );
322
-
323
-			if ( ! isset( $current->response[ $plugin ] ) ) {
324
-				$this->skin->set_result( 'up_to_date' );
325
-				$this->skin->before();
326
-				$this->skin->feedback( 'up_to_date' );
327
-				$this->skin->after();
328
-				$results[ $plugin ] = true;
329
-				continue;
330
-			}
331
-
332
-			// Get the URL to the zip file.
333
-			$r = $current->response[ $plugin ];
334
-
335
-			$this->skin->plugin_active = is_plugin_active( $plugin );
336
-
337
-			$result = $this->run(
338
-				array(
339
-					'package'           => $r->package,
340
-					'destination'       => WP_PLUGIN_DIR,
341
-					'clear_destination' => true,
342
-					'clear_working'     => true,
343
-					'is_multi'          => true,
344
-					'hook_extra'        => array(
345
-						'plugin' => $plugin,
346
-					),
347
-				)
348
-			);
349
-
350
-			$results[ $plugin ] = $result;
351
-
352
-			// Prevent credentials auth screen from displaying multiple times.
353
-			if ( false === $result ) {
354
-				break;
355
-			}
356
-		} // End foreach $plugins.
357
-
358
-		$this->maintenance_mode( false );
359
-
360
-		// Force refresh of plugin update information.
361
-		wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
362
-
363
-		/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
364
-		do_action(
365
-			'upgrader_process_complete',
366
-			$this,
367
-			array(
368
-				'action'  => 'update',
369
-				'type'    => 'plugin',
370
-				'bulk'    => true,
371
-				'plugins' => $plugins,
372
-			)
373
-		);
374
-
375
-		$this->skin->bulk_footer();
376
-
377
-		$this->skin->footer();
378
-
379
-		// Cleanup our hooks, in case something else does a upgrade on this connection.
380
-		remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
381
-
382
-		// Ensure any future auto-update failures trigger a failure email by removing
383
-		// the last failure notification from the list when plugins update successfully.
384
-		$past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() );
385
-
386
-		foreach ( $results as $plugin => $result ) {
387
-			// Maintain last failure notification when plugins failed to update manually.
388
-			if ( ! $result || is_wp_error( $result ) || ! isset( $past_failure_emails[ $plugin ] ) ) {
389
-				continue;
390
-			}
391
-
392
-			unset( $past_failure_emails[ $plugin ] );
393
-		}
394
-
395
-		update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
396
-
397
-		return $results;
398
-	}
399
-
400
-	/**
401
-	 * Checks that the source package contains a valid plugin.
402
-	 *
403
-	 * Hooked to the {@see 'upgrader_source_selection'} filter by Plugin_Upgrader::install().
404
-	 *
405
-	 * @since 3.3.0
406
-	 *
407
-	 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
408
-	 * @global string             $wp_version    The WordPress version string.
409
-	 *
410
-	 * @param string $source The path to the downloaded package source.
411
-	 * @return string|WP_Error The source as passed, or a WP_Error object on failure.
412
-	 */
413
-	public function check_package( $source ) {
414
-		global $wp_filesystem, $wp_version;
415
-
416
-		$this->new_plugin_data = array();
417
-
418
-		if ( is_wp_error( $source ) ) {
419
-			return $source;
420
-		}
421
-
422
-		$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
423
-		if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.
424
-			return $source;
425
-		}
426
-
427
-		// Check that the folder contains at least 1 valid plugin.
428
-		$files = glob( $working_directory . '*.php' );
429
-		if ( $files ) {
430
-			foreach ( $files as $file ) {
431
-				$info = get_plugin_data( $file, false, false );
432
-				if ( ! empty( $info['Name'] ) ) {
433
-					$this->new_plugin_data = $info;
434
-					break;
435
-				}
436
-			}
437
-		}
438
-
439
-		if ( empty( $this->new_plugin_data ) ) {
440
-			return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
441
-		}
442
-
443
-		$requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
444
-		$requires_wp  = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null;
445
-
446
-		if ( ! is_php_version_compatible( $requires_php ) ) {
447
-			$error = sprintf(
448
-				/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
449
-				__( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
450
-				phpversion(),
451
-				$requires_php
452
-			);
453
-
454
-			return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error );
455
-		}
456
-
457
-		if ( ! is_wp_version_compatible( $requires_wp ) ) {
458
-			$error = sprintf(
459
-				/* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
460
-				__( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
461
-				$wp_version,
462
-				$requires_wp
463
-			);
464
-
465
-			return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error );
466
-		}
467
-
468
-		return $source;
469
-	}
470
-
471
-	/**
472
-	 * Retrieve the path to the file that contains the plugin info.
473
-	 *
474
-	 * This isn't used internally in the class, but is called by the skins.
475
-	 *
476
-	 * @since 2.8.0
477
-	 *
478
-	 * @return string|false The full path to the main plugin file, or false.
479
-	 */
480
-	public function plugin_info() {
481
-		if ( ! is_array( $this->result ) ) {
482
-			return false;
483
-		}
484
-		if ( empty( $this->result['destination_name'] ) ) {
485
-			return false;
486
-		}
487
-
488
-		// Ensure to pass with leading slash.
489
-		$plugin = get_plugins( '/' . $this->result['destination_name'] );
490
-		if ( empty( $plugin ) ) {
491
-			return false;
492
-		}
493
-
494
-		// Assume the requested plugin is the first in the list.
495
-		$pluginfiles = array_keys( $plugin );
496
-
497
-		return $this->result['destination_name'] . '/' . $pluginfiles[0];
498
-	}
499
-
500
-	/**
501
-	 * Deactivates a plugin before it is upgraded.
502
-	 *
503
-	 * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
504
-	 *
505
-	 * @since 2.8.0
506
-	 * @since 4.1.0 Added a return value.
507
-	 *
508
-	 * @param bool|WP_Error $response The installation response before the installation has started.
509
-	 * @param array         $plugin   Plugin package arguments.
510
-	 * @return bool|WP_Error The original `$response` parameter or WP_Error.
511
-	 */
512
-	public function deactivate_plugin_before_upgrade( $response, $plugin ) {
513
-
514
-		if ( is_wp_error( $response ) ) { // Bypass.
515
-			return $response;
516
-		}
517
-
518
-		// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it.
519
-		if ( wp_doing_cron() ) {
520
-			return $response;
521
-		}
522
-
523
-		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
524
-		if ( empty( $plugin ) ) {
525
-			return new WP_Error( 'bad_request', $this->strings['bad_request'] );
526
-		}
527
-
528
-		if ( is_plugin_active( $plugin ) ) {
529
-			// Deactivate the plugin silently, Prevent deactivation hooks from running.
530
-			deactivate_plugins( $plugin, true );
531
-		}
532
-
533
-		return $response;
534
-	}
535
-
536
-	/**
537
-	 * Turns on maintenance mode before attempting to background update an active plugin.
538
-	 *
539
-	 * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
540
-	 *
541
-	 * @since 5.4.0
542
-	 *
543
-	 * @param bool|WP_Error $response The installation response before the installation has started.
544
-	 * @param array         $plugin   Plugin package arguments.
545
-	 * @return bool|WP_Error The original `$response` parameter or WP_Error.
546
-	 */
547
-	public function active_before( $response, $plugin ) {
548
-		if ( is_wp_error( $response ) ) {
549
-			return $response;
550
-		}
551
-
552
-		// Only enable maintenance mode when in cron (background update).
553
-		if ( ! wp_doing_cron() ) {
554
-			return $response;
555
-		}
556
-
557
-		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
558
-
559
-		// Only run if plugin is active.
560
-		if ( ! is_plugin_active( $plugin ) ) {
561
-			return $response;
562
-		}
563
-
564
-		// Change to maintenance mode. Bulk edit handles this separately.
565
-		if ( ! $this->bulk ) {
566
-			$this->maintenance_mode( true );
567
-		}
568
-
569
-		return $response;
570
-	}
571
-
572
-	/**
573
-	 * Turns off maintenance mode after upgrading an active plugin.
574
-	 *
575
-	 * Hooked to the {@see 'upgrader_post_install'} filter by Plugin_Upgrader::upgrade().
576
-	 *
577
-	 * @since 5.4.0
578
-	 *
579
-	 * @param bool|WP_Error $response The installation response after the installation has finished.
580
-	 * @param array         $plugin   Plugin package arguments.
581
-	 * @return bool|WP_Error The original `$response` parameter or WP_Error.
582
-	 */
583
-	public function active_after( $response, $plugin ) {
584
-		if ( is_wp_error( $response ) ) {
585
-			return $response;
586
-		}
587
-
588
-		// Only disable maintenance mode when in cron (background update).
589
-		if ( ! wp_doing_cron() ) {
590
-			return $response;
591
-		}
592
-
593
-		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
594
-
595
-		// Only run if plugin is active.
596
-		if ( ! is_plugin_active( $plugin ) ) {
597
-			return $response;
598
-		}
599
-
600
-		// Time to remove maintenance mode. Bulk edit handles this separately.
601
-		if ( ! $this->bulk ) {
602
-			$this->maintenance_mode( false );
603
-		}
604
-
605
-		return $response;
606
-	}
607
-
608
-	/**
609
-	 * Deletes the old plugin during an upgrade.
610
-	 *
611
-	 * Hooked to the {@see 'upgrader_clear_destination'} filter by
612
-	 * Plugin_Upgrader::upgrade() and Plugin_Upgrader::bulk_upgrade().
613
-	 *
614
-	 * @since 2.8.0
615
-	 *
616
-	 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
617
-	 *
618
-	 * @param bool|WP_Error $removed            Whether the destination was cleared.
619
-	 *                                          True on success, WP_Error on failure.
620
-	 * @param string        $local_destination  The local package destination.
621
-	 * @param string        $remote_destination The remote package destination.
622
-	 * @param array         $plugin             Extra arguments passed to hooked filters.
623
-	 * @return bool|WP_Error
624
-	 */
625
-	public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) {
626
-		global $wp_filesystem;
627
-
628
-		if ( is_wp_error( $removed ) ) {
629
-			return $removed; // Pass errors through.
630
-		}
631
-
632
-		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
633
-		if ( empty( $plugin ) ) {
634
-			return new WP_Error( 'bad_request', $this->strings['bad_request'] );
635
-		}
636
-
637
-		$plugins_dir     = $wp_filesystem->wp_plugins_dir();
638
-		$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) );
639
-
640
-		if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { // If it's already vanished.
641
-			return $removed;
642
-		}
643
-
644
-		// If plugin is in its own directory, recursively delete the directory.
645
-		// Base check on if plugin includes directory separator AND that it's not the root plugin folder.
646
-		if ( strpos( $plugin, '/' ) && $this_plugin_dir !== $plugins_dir ) {
647
-			$deleted = $wp_filesystem->delete( $this_plugin_dir, true );
648
-		} else {
649
-			$deleted = $wp_filesystem->delete( $plugins_dir . $plugin );
650
-		}
651
-
652
-		if ( ! $deleted ) {
653
-			return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
654
-		}
655
-
656
-		return true;
657
-	}
307
+        $maintenance = ( is_multisite() && ! empty( $plugins ) );
308
+        foreach ( $plugins as $plugin ) {
309
+            $maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) );
310
+        }
311
+        if ( $maintenance ) {
312
+            $this->maintenance_mode( true );
313
+        }
314
+
315
+        $results = array();
316
+
317
+        $this->update_count   = count( $plugins );
318
+        $this->update_current = 0;
319
+        foreach ( $plugins as $plugin ) {
320
+            $this->update_current++;
321
+            $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true );
322
+
323
+            if ( ! isset( $current->response[ $plugin ] ) ) {
324
+                $this->skin->set_result( 'up_to_date' );
325
+                $this->skin->before();
326
+                $this->skin->feedback( 'up_to_date' );
327
+                $this->skin->after();
328
+                $results[ $plugin ] = true;
329
+                continue;
330
+            }
331
+
332
+            // Get the URL to the zip file.
333
+            $r = $current->response[ $plugin ];
334
+
335
+            $this->skin->plugin_active = is_plugin_active( $plugin );
336
+
337
+            $result = $this->run(
338
+                array(
339
+                    'package'           => $r->package,
340
+                    'destination'       => WP_PLUGIN_DIR,
341
+                    'clear_destination' => true,
342
+                    'clear_working'     => true,
343
+                    'is_multi'          => true,
344
+                    'hook_extra'        => array(
345
+                        'plugin' => $plugin,
346
+                    ),
347
+                )
348
+            );
349
+
350
+            $results[ $plugin ] = $result;
351
+
352
+            // Prevent credentials auth screen from displaying multiple times.
353
+            if ( false === $result ) {
354
+                break;
355
+            }
356
+        } // End foreach $plugins.
357
+
358
+        $this->maintenance_mode( false );
359
+
360
+        // Force refresh of plugin update information.
361
+        wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
362
+
363
+        /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
364
+        do_action(
365
+            'upgrader_process_complete',
366
+            $this,
367
+            array(
368
+                'action'  => 'update',
369
+                'type'    => 'plugin',
370
+                'bulk'    => true,
371
+                'plugins' => $plugins,
372
+            )
373
+        );
374
+
375
+        $this->skin->bulk_footer();
376
+
377
+        $this->skin->footer();
378
+
379
+        // Cleanup our hooks, in case something else does a upgrade on this connection.
380
+        remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
381
+
382
+        // Ensure any future auto-update failures trigger a failure email by removing
383
+        // the last failure notification from the list when plugins update successfully.
384
+        $past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() );
385
+
386
+        foreach ( $results as $plugin => $result ) {
387
+            // Maintain last failure notification when plugins failed to update manually.
388
+            if ( ! $result || is_wp_error( $result ) || ! isset( $past_failure_emails[ $plugin ] ) ) {
389
+                continue;
390
+            }
391
+
392
+            unset( $past_failure_emails[ $plugin ] );
393
+        }
394
+
395
+        update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
396
+
397
+        return $results;
398
+    }
399
+
400
+    /**
401
+     * Checks that the source package contains a valid plugin.
402
+     *
403
+     * Hooked to the {@see 'upgrader_source_selection'} filter by Plugin_Upgrader::install().
404
+     *
405
+     * @since 3.3.0
406
+     *
407
+     * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
408
+     * @global string             $wp_version    The WordPress version string.
409
+     *
410
+     * @param string $source The path to the downloaded package source.
411
+     * @return string|WP_Error The source as passed, or a WP_Error object on failure.
412
+     */
413
+    public function check_package( $source ) {
414
+        global $wp_filesystem, $wp_version;
415
+
416
+        $this->new_plugin_data = array();
417
+
418
+        if ( is_wp_error( $source ) ) {
419
+            return $source;
420
+        }
421
+
422
+        $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
423
+        if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.
424
+            return $source;
425
+        }
426
+
427
+        // Check that the folder contains at least 1 valid plugin.
428
+        $files = glob( $working_directory . '*.php' );
429
+        if ( $files ) {
430
+            foreach ( $files as $file ) {
431
+                $info = get_plugin_data( $file, false, false );
432
+                if ( ! empty( $info['Name'] ) ) {
433
+                    $this->new_plugin_data = $info;
434
+                    break;
435
+                }
436
+            }
437
+        }
438
+
439
+        if ( empty( $this->new_plugin_data ) ) {
440
+            return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
441
+        }
442
+
443
+        $requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
444
+        $requires_wp  = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null;
445
+
446
+        if ( ! is_php_version_compatible( $requires_php ) ) {
447
+            $error = sprintf(
448
+                /* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
449
+                __( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
450
+                phpversion(),
451
+                $requires_php
452
+            );
453
+
454
+            return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error );
455
+        }
456
+
457
+        if ( ! is_wp_version_compatible( $requires_wp ) ) {
458
+            $error = sprintf(
459
+                /* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
460
+                __( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
461
+                $wp_version,
462
+                $requires_wp
463
+            );
464
+
465
+            return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error );
466
+        }
467
+
468
+        return $source;
469
+    }
470
+
471
+    /**
472
+     * Retrieve the path to the file that contains the plugin info.
473
+     *
474
+     * This isn't used internally in the class, but is called by the skins.
475
+     *
476
+     * @since 2.8.0
477
+     *
478
+     * @return string|false The full path to the main plugin file, or false.
479
+     */
480
+    public function plugin_info() {
481
+        if ( ! is_array( $this->result ) ) {
482
+            return false;
483
+        }
484
+        if ( empty( $this->result['destination_name'] ) ) {
485
+            return false;
486
+        }
487
+
488
+        // Ensure to pass with leading slash.
489
+        $plugin = get_plugins( '/' . $this->result['destination_name'] );
490
+        if ( empty( $plugin ) ) {
491
+            return false;
492
+        }
493
+
494
+        // Assume the requested plugin is the first in the list.
495
+        $pluginfiles = array_keys( $plugin );
496
+
497
+        return $this->result['destination_name'] . '/' . $pluginfiles[0];
498
+    }
499
+
500
+    /**
501
+     * Deactivates a plugin before it is upgraded.
502
+     *
503
+     * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
504
+     *
505
+     * @since 2.8.0
506
+     * @since 4.1.0 Added a return value.
507
+     *
508
+     * @param bool|WP_Error $response The installation response before the installation has started.
509
+     * @param array         $plugin   Plugin package arguments.
510
+     * @return bool|WP_Error The original `$response` parameter or WP_Error.
511
+     */
512
+    public function deactivate_plugin_before_upgrade( $response, $plugin ) {
513
+
514
+        if ( is_wp_error( $response ) ) { // Bypass.
515
+            return $response;
516
+        }
517
+
518
+        // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it.
519
+        if ( wp_doing_cron() ) {
520
+            return $response;
521
+        }
522
+
523
+        $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
524
+        if ( empty( $plugin ) ) {
525
+            return new WP_Error( 'bad_request', $this->strings['bad_request'] );
526
+        }
527
+
528
+        if ( is_plugin_active( $plugin ) ) {
529
+            // Deactivate the plugin silently, Prevent deactivation hooks from running.
530
+            deactivate_plugins( $plugin, true );
531
+        }
532
+
533
+        return $response;
534
+    }
535
+
536
+    /**
537
+     * Turns on maintenance mode before attempting to background update an active plugin.
538
+     *
539
+     * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
540
+     *
541
+     * @since 5.4.0
542
+     *
543
+     * @param bool|WP_Error $response The installation response before the installation has started.
544
+     * @param array         $plugin   Plugin package arguments.
545
+     * @return bool|WP_Error The original `$response` parameter or WP_Error.
546
+     */
547
+    public function active_before( $response, $plugin ) {
548
+        if ( is_wp_error( $response ) ) {
549
+            return $response;
550
+        }
551
+
552
+        // Only enable maintenance mode when in cron (background update).
553
+        if ( ! wp_doing_cron() ) {
554
+            return $response;
555
+        }
556
+
557
+        $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
558
+
559
+        // Only run if plugin is active.
560
+        if ( ! is_plugin_active( $plugin ) ) {
561
+            return $response;
562
+        }
563
+
564
+        // Change to maintenance mode. Bulk edit handles this separately.
565
+        if ( ! $this->bulk ) {
566
+            $this->maintenance_mode( true );
567
+        }
568
+
569
+        return $response;
570
+    }
571
+
572
+    /**
573
+     * Turns off maintenance mode after upgrading an active plugin.
574
+     *
575
+     * Hooked to the {@see 'upgrader_post_install'} filter by Plugin_Upgrader::upgrade().
576
+     *
577
+     * @since 5.4.0
578
+     *
579
+     * @param bool|WP_Error $response The installation response after the installation has finished.
580
+     * @param array         $plugin   Plugin package arguments.
581
+     * @return bool|WP_Error The original `$response` parameter or WP_Error.
582
+     */
583
+    public function active_after( $response, $plugin ) {
584
+        if ( is_wp_error( $response ) ) {
585
+            return $response;
586
+        }
587
+
588
+        // Only disable maintenance mode when in cron (background update).
589
+        if ( ! wp_doing_cron() ) {
590
+            return $response;
591
+        }
592
+
593
+        $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
594
+
595
+        // Only run if plugin is active.
596
+        if ( ! is_plugin_active( $plugin ) ) {
597
+            return $response;
598
+        }
599
+
600
+        // Time to remove maintenance mode. Bulk edit handles this separately.
601
+        if ( ! $this->bulk ) {
602
+            $this->maintenance_mode( false );
603
+        }
604
+
605
+        return $response;
606
+    }
607
+
608
+    /**
609
+     * Deletes the old plugin during an upgrade.
610
+     *
611
+     * Hooked to the {@see 'upgrader_clear_destination'} filter by
612
+     * Plugin_Upgrader::upgrade() and Plugin_Upgrader::bulk_upgrade().
613
+     *
614
+     * @since 2.8.0
615
+     *
616
+     * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
617
+     *
618
+     * @param bool|WP_Error $removed            Whether the destination was cleared.
619
+     *                                          True on success, WP_Error on failure.
620
+     * @param string        $local_destination  The local package destination.
621
+     * @param string        $remote_destination The remote package destination.
622
+     * @param array         $plugin             Extra arguments passed to hooked filters.
623
+     * @return bool|WP_Error
624
+     */
625
+    public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) {
626
+        global $wp_filesystem;
627
+
628
+        if ( is_wp_error( $removed ) ) {
629
+            return $removed; // Pass errors through.
630
+        }
631
+
632
+        $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
633
+        if ( empty( $plugin ) ) {
634
+            return new WP_Error( 'bad_request', $this->strings['bad_request'] );
635
+        }
636
+
637
+        $plugins_dir     = $wp_filesystem->wp_plugins_dir();
638
+        $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) );
639
+
640
+        if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { // If it's already vanished.
641
+            return $removed;
642
+        }
643
+
644
+        // If plugin is in its own directory, recursively delete the directory.
645
+        // Base check on if plugin includes directory separator AND that it's not the root plugin folder.
646
+        if ( strpos( $plugin, '/' ) && $this_plugin_dir !== $plugins_dir ) {
647
+            $deleted = $wp_filesystem->delete( $this_plugin_dir, true );
648
+        } else {
649
+            $deleted = $wp_filesystem->delete( $plugins_dir . $plugin );
650
+        }
651
+
652
+        if ( ! $deleted ) {
653
+            return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
654
+        }
655
+
656
+        return true;
657
+    }
658 658
 }
Please login to merge, or discard this patch.