Passed
Push — main ( 16d49b...d78e29 )
by TARIQ
111:03
created
brighty/wp-admin/includes/class-wp-users-list-table.php 1 patch
Indentation   +642 added lines, -642 removed lines patch added patch discarded remove patch
@@ -17,292 +17,292 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class WP_Users_List_Table extends WP_List_Table {
19 19
 
20
-	/**
21
-	 * Site ID to generate the Users list table for.
22
-	 *
23
-	 * @since 3.1.0
24
-	 * @var int
25
-	 */
26
-	public $site_id;
27
-
28
-	/**
29
-	 * Whether or not the current Users list table is for Multisite.
30
-	 *
31
-	 * @since 3.1.0
32
-	 * @var bool
33
-	 */
34
-	public $is_site_users;
35
-
36
-	/**
37
-	 * Constructor.
38
-	 *
39
-	 * @since 3.1.0
40
-	 *
41
-	 * @see WP_List_Table::__construct() for more information on default arguments.
42
-	 *
43
-	 * @param array $args An associative array of arguments.
44
-	 */
45
-	public function __construct( $args = array() ) {
46
-		parent::__construct(
47
-			array(
48
-				'singular' => 'user',
49
-				'plural'   => 'users',
50
-				'screen'   => isset( $args['screen'] ) ? $args['screen'] : null,
51
-			)
52
-		);
53
-
54
-		$this->is_site_users = 'site-users-network' === $this->screen->id;
55
-
56
-		if ( $this->is_site_users ) {
57
-			$this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Check the current user's permissions.
63
-	 *
64
-	 * @since 3.1.0
65
-	 *
66
-	 * @return bool
67
-	 */
68
-	public function ajax_user_can() {
69
-		if ( $this->is_site_users ) {
70
-			return current_user_can( 'manage_sites' );
71
-		} else {
72
-			return current_user_can( 'list_users' );
73
-		}
74
-	}
75
-
76
-	/**
77
-	 * Prepare the users list for display.
78
-	 *
79
-	 * @since 3.1.0
80
-	 *
81
-	 * @global string $role
82
-	 * @global string $usersearch
83
-	 */
84
-	public function prepare_items() {
85
-		global $role, $usersearch;
86
-
87
-		$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
88
-
89
-		$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
90
-
91
-		$per_page       = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page';
92
-		$users_per_page = $this->get_items_per_page( $per_page );
93
-
94
-		$paged = $this->get_pagenum();
95
-
96
-		if ( 'none' === $role ) {
97
-			$args = array(
98
-				'number'  => $users_per_page,
99
-				'offset'  => ( $paged - 1 ) * $users_per_page,
100
-				'include' => wp_get_users_with_no_role( $this->site_id ),
101
-				'search'  => $usersearch,
102
-				'fields'  => 'all_with_meta',
103
-			);
104
-		} else {
105
-			$args = array(
106
-				'number' => $users_per_page,
107
-				'offset' => ( $paged - 1 ) * $users_per_page,
108
-				'role'   => $role,
109
-				'search' => $usersearch,
110
-				'fields' => 'all_with_meta',
111
-			);
112
-		}
113
-
114
-		if ( '' !== $args['search'] ) {
115
-			$args['search'] = '*' . $args['search'] . '*';
116
-		}
117
-
118
-		if ( $this->is_site_users ) {
119
-			$args['blog_id'] = $this->site_id;
120
-		}
121
-
122
-		if ( isset( $_REQUEST['orderby'] ) ) {
123
-			$args['orderby'] = $_REQUEST['orderby'];
124
-		}
125
-
126
-		if ( isset( $_REQUEST['order'] ) ) {
127
-			$args['order'] = $_REQUEST['order'];
128
-		}
129
-
130
-		/**
131
-		 * Filters the query arguments used to retrieve users for the current users list table.
132
-		 *
133
-		 * @since 4.4.0
134
-		 *
135
-		 * @param array $args Arguments passed to WP_User_Query to retrieve items for the current
136
-		 *                    users list table.
137
-		 */
138
-		$args = apply_filters( 'users_list_table_query_args', $args );
139
-
140
-		// Query the user IDs for this page.
141
-		$wp_user_search = new WP_User_Query( $args );
142
-
143
-		$this->items = $wp_user_search->get_results();
144
-
145
-		$this->set_pagination_args(
146
-			array(
147
-				'total_items' => $wp_user_search->get_total(),
148
-				'per_page'    => $users_per_page,
149
-			)
150
-		);
151
-	}
152
-
153
-	/**
154
-	 * Output 'no users' message.
155
-	 *
156
-	 * @since 3.1.0
157
-	 */
158
-	public function no_items() {
159
-		_e( 'No users found.' );
160
-	}
161
-
162
-	/**
163
-	 * Return an associative array listing all the views that can be used
164
-	 * with this table.
165
-	 *
166
-	 * Provides a list of roles and user count for that role for easy
167
-	 * Filtersing of the user table.
168
-	 *
169
-	 * @since 3.1.0
170
-	 *
171
-	 * @global string $role
172
-	 *
173
-	 * @return string[] An array of HTML links keyed by their view.
174
-	 */
175
-	protected function get_views() {
176
-		global $role;
177
-
178
-		$wp_roles = wp_roles();
179
-
180
-		$count_users = ! wp_is_large_user_count();
181
-
182
-		if ( $this->is_site_users ) {
183
-			$url = 'site-users.php?id=' . $this->site_id;
184
-		} else {
185
-			$url = 'users.php';
186
-		}
187
-
188
-		$role_links              = array();
189
-		$avail_roles             = array();
190
-		$all_text                = __( 'All' );
191
-		$current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
192
-
193
-		if ( $count_users ) {
194
-			if ( $this->is_site_users ) {
195
-				switch_to_blog( $this->site_id );
196
-				$users_of_blog = count_users( 'time', $this->site_id );
197
-				restore_current_blog();
198
-			} else {
199
-				$users_of_blog = count_users();
200
-			}
201
-
202
-			$total_users = $users_of_blog['total_users'];
203
-			$avail_roles =& $users_of_blog['avail_roles'];
204
-			unset( $users_of_blog );
205
-
206
-			$all_text = sprintf(
207
-				/* translators: %s: Number of users. */
208
-				_nx(
209
-					'All <span class="count">(%s)</span>',
210
-					'All <span class="count">(%s)</span>',
211
-					$total_users,
212
-					'users'
213
-				),
214
-				number_format_i18n( $total_users )
215
-			);
216
-		}
217
-
218
-		$role_links['all'] = sprintf( '<a href="%s"%s>%s</a>', $url, $current_link_attributes, $all_text );
219
-
220
-		foreach ( $wp_roles->get_names() as $this_role => $name ) {
221
-			if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) {
222
-				continue;
223
-			}
224
-
225
-			$current_link_attributes = '';
226
-
227
-			if ( $this_role === $role ) {
228
-				$current_link_attributes = ' class="current" aria-current="page"';
229
-			}
230
-
231
-			$name = translate_user_role( $name );
232
-			if ( $count_users ) {
233
-				$name = sprintf(
234
-					/* translators: 1: User role name, 2: Number of users. */
235
-					__( '%1$s <span class="count">(%2$s)</span>' ),
236
-					$name,
237
-					number_format_i18n( $avail_roles[ $this_role ] )
238
-				);
239
-			}
240
-
241
-			$role_links[ $this_role ] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$current_link_attributes>$name</a>";
242
-		}
243
-
244
-		if ( ! empty( $avail_roles['none'] ) ) {
245
-
246
-			$current_link_attributes = '';
247
-
248
-			if ( 'none' === $role ) {
249
-				$current_link_attributes = ' class="current" aria-current="page"';
250
-			}
251
-
252
-			$name = __( 'No role' );
253
-			$name = sprintf(
254
-				/* translators: 1: User role name, 2: Number of users. */
255
-				__( '%1$s <span class="count">(%2$s)</span>' ),
256
-				$name,
257
-				number_format_i18n( $avail_roles['none'] )
258
-			);
259
-
260
-			$role_links['none'] = "<a href='" . esc_url( add_query_arg( 'role', 'none', $url ) ) . "'$current_link_attributes>$name</a>";
261
-		}
262
-
263
-		return $role_links;
264
-	}
265
-
266
-	/**
267
-	 * Retrieve an associative array of bulk actions available on this table.
268
-	 *
269
-	 * @since 3.1.0
270
-	 *
271
-	 * @return array Array of bulk action labels keyed by their action.
272
-	 */
273
-	protected function get_bulk_actions() {
274
-		$actions = array();
275
-
276
-		if ( is_multisite() ) {
277
-			if ( current_user_can( 'remove_users' ) ) {
278
-				$actions['remove'] = __( 'Remove' );
279
-			}
280
-		} else {
281
-			if ( current_user_can( 'delete_users' ) ) {
282
-				$actions['delete'] = __( 'Delete' );
283
-			}
284
-		}
285
-
286
-		// Add a password reset link to the bulk actions dropdown.
287
-		if ( current_user_can( 'edit_users' ) ) {
288
-			$actions['resetpassword'] = __( 'Send password reset' );
289
-		}
290
-
291
-		return $actions;
292
-	}
293
-
294
-	/**
295
-	 * Output the controls to allow user roles to be changed in bulk.
296
-	 *
297
-	 * @since 3.1.0
298
-	 *
299
-	 * @param string $which Whether this is being invoked above ("top")
300
-	 *                      or below the table ("bottom").
301
-	 */
302
-	protected function extra_tablenav( $which ) {
303
-		$id        = 'bottom' === $which ? 'new_role2' : 'new_role';
304
-		$button_id = 'bottom' === $which ? 'changeit2' : 'changeit';
305
-		?>
20
+    /**
21
+     * Site ID to generate the Users list table for.
22
+     *
23
+     * @since 3.1.0
24
+     * @var int
25
+     */
26
+    public $site_id;
27
+
28
+    /**
29
+     * Whether or not the current Users list table is for Multisite.
30
+     *
31
+     * @since 3.1.0
32
+     * @var bool
33
+     */
34
+    public $is_site_users;
35
+
36
+    /**
37
+     * Constructor.
38
+     *
39
+     * @since 3.1.0
40
+     *
41
+     * @see WP_List_Table::__construct() for more information on default arguments.
42
+     *
43
+     * @param array $args An associative array of arguments.
44
+     */
45
+    public function __construct( $args = array() ) {
46
+        parent::__construct(
47
+            array(
48
+                'singular' => 'user',
49
+                'plural'   => 'users',
50
+                'screen'   => isset( $args['screen'] ) ? $args['screen'] : null,
51
+            )
52
+        );
53
+
54
+        $this->is_site_users = 'site-users-network' === $this->screen->id;
55
+
56
+        if ( $this->is_site_users ) {
57
+            $this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Check the current user's permissions.
63
+     *
64
+     * @since 3.1.0
65
+     *
66
+     * @return bool
67
+     */
68
+    public function ajax_user_can() {
69
+        if ( $this->is_site_users ) {
70
+            return current_user_can( 'manage_sites' );
71
+        } else {
72
+            return current_user_can( 'list_users' );
73
+        }
74
+    }
75
+
76
+    /**
77
+     * Prepare the users list for display.
78
+     *
79
+     * @since 3.1.0
80
+     *
81
+     * @global string $role
82
+     * @global string $usersearch
83
+     */
84
+    public function prepare_items() {
85
+        global $role, $usersearch;
86
+
87
+        $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
88
+
89
+        $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
90
+
91
+        $per_page       = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page';
92
+        $users_per_page = $this->get_items_per_page( $per_page );
93
+
94
+        $paged = $this->get_pagenum();
95
+
96
+        if ( 'none' === $role ) {
97
+            $args = array(
98
+                'number'  => $users_per_page,
99
+                'offset'  => ( $paged - 1 ) * $users_per_page,
100
+                'include' => wp_get_users_with_no_role( $this->site_id ),
101
+                'search'  => $usersearch,
102
+                'fields'  => 'all_with_meta',
103
+            );
104
+        } else {
105
+            $args = array(
106
+                'number' => $users_per_page,
107
+                'offset' => ( $paged - 1 ) * $users_per_page,
108
+                'role'   => $role,
109
+                'search' => $usersearch,
110
+                'fields' => 'all_with_meta',
111
+            );
112
+        }
113
+
114
+        if ( '' !== $args['search'] ) {
115
+            $args['search'] = '*' . $args['search'] . '*';
116
+        }
117
+
118
+        if ( $this->is_site_users ) {
119
+            $args['blog_id'] = $this->site_id;
120
+        }
121
+
122
+        if ( isset( $_REQUEST['orderby'] ) ) {
123
+            $args['orderby'] = $_REQUEST['orderby'];
124
+        }
125
+
126
+        if ( isset( $_REQUEST['order'] ) ) {
127
+            $args['order'] = $_REQUEST['order'];
128
+        }
129
+
130
+        /**
131
+         * Filters the query arguments used to retrieve users for the current users list table.
132
+         *
133
+         * @since 4.4.0
134
+         *
135
+         * @param array $args Arguments passed to WP_User_Query to retrieve items for the current
136
+         *                    users list table.
137
+         */
138
+        $args = apply_filters( 'users_list_table_query_args', $args );
139
+
140
+        // Query the user IDs for this page.
141
+        $wp_user_search = new WP_User_Query( $args );
142
+
143
+        $this->items = $wp_user_search->get_results();
144
+
145
+        $this->set_pagination_args(
146
+            array(
147
+                'total_items' => $wp_user_search->get_total(),
148
+                'per_page'    => $users_per_page,
149
+            )
150
+        );
151
+    }
152
+
153
+    /**
154
+     * Output 'no users' message.
155
+     *
156
+     * @since 3.1.0
157
+     */
158
+    public function no_items() {
159
+        _e( 'No users found.' );
160
+    }
161
+
162
+    /**
163
+     * Return an associative array listing all the views that can be used
164
+     * with this table.
165
+     *
166
+     * Provides a list of roles and user count for that role for easy
167
+     * Filtersing of the user table.
168
+     *
169
+     * @since 3.1.0
170
+     *
171
+     * @global string $role
172
+     *
173
+     * @return string[] An array of HTML links keyed by their view.
174
+     */
175
+    protected function get_views() {
176
+        global $role;
177
+
178
+        $wp_roles = wp_roles();
179
+
180
+        $count_users = ! wp_is_large_user_count();
181
+
182
+        if ( $this->is_site_users ) {
183
+            $url = 'site-users.php?id=' . $this->site_id;
184
+        } else {
185
+            $url = 'users.php';
186
+        }
187
+
188
+        $role_links              = array();
189
+        $avail_roles             = array();
190
+        $all_text                = __( 'All' );
191
+        $current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
192
+
193
+        if ( $count_users ) {
194
+            if ( $this->is_site_users ) {
195
+                switch_to_blog( $this->site_id );
196
+                $users_of_blog = count_users( 'time', $this->site_id );
197
+                restore_current_blog();
198
+            } else {
199
+                $users_of_blog = count_users();
200
+            }
201
+
202
+            $total_users = $users_of_blog['total_users'];
203
+            $avail_roles =& $users_of_blog['avail_roles'];
204
+            unset( $users_of_blog );
205
+
206
+            $all_text = sprintf(
207
+                /* translators: %s: Number of users. */
208
+                _nx(
209
+                    'All <span class="count">(%s)</span>',
210
+                    'All <span class="count">(%s)</span>',
211
+                    $total_users,
212
+                    'users'
213
+                ),
214
+                number_format_i18n( $total_users )
215
+            );
216
+        }
217
+
218
+        $role_links['all'] = sprintf( '<a href="%s"%s>%s</a>', $url, $current_link_attributes, $all_text );
219
+
220
+        foreach ( $wp_roles->get_names() as $this_role => $name ) {
221
+            if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) {
222
+                continue;
223
+            }
224
+
225
+            $current_link_attributes = '';
226
+
227
+            if ( $this_role === $role ) {
228
+                $current_link_attributes = ' class="current" aria-current="page"';
229
+            }
230
+
231
+            $name = translate_user_role( $name );
232
+            if ( $count_users ) {
233
+                $name = sprintf(
234
+                    /* translators: 1: User role name, 2: Number of users. */
235
+                    __( '%1$s <span class="count">(%2$s)</span>' ),
236
+                    $name,
237
+                    number_format_i18n( $avail_roles[ $this_role ] )
238
+                );
239
+            }
240
+
241
+            $role_links[ $this_role ] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$current_link_attributes>$name</a>";
242
+        }
243
+
244
+        if ( ! empty( $avail_roles['none'] ) ) {
245
+
246
+            $current_link_attributes = '';
247
+
248
+            if ( 'none' === $role ) {
249
+                $current_link_attributes = ' class="current" aria-current="page"';
250
+            }
251
+
252
+            $name = __( 'No role' );
253
+            $name = sprintf(
254
+                /* translators: 1: User role name, 2: Number of users. */
255
+                __( '%1$s <span class="count">(%2$s)</span>' ),
256
+                $name,
257
+                number_format_i18n( $avail_roles['none'] )
258
+            );
259
+
260
+            $role_links['none'] = "<a href='" . esc_url( add_query_arg( 'role', 'none', $url ) ) . "'$current_link_attributes>$name</a>";
261
+        }
262
+
263
+        return $role_links;
264
+    }
265
+
266
+    /**
267
+     * Retrieve an associative array of bulk actions available on this table.
268
+     *
269
+     * @since 3.1.0
270
+     *
271
+     * @return array Array of bulk action labels keyed by their action.
272
+     */
273
+    protected function get_bulk_actions() {
274
+        $actions = array();
275
+
276
+        if ( is_multisite() ) {
277
+            if ( current_user_can( 'remove_users' ) ) {
278
+                $actions['remove'] = __( 'Remove' );
279
+            }
280
+        } else {
281
+            if ( current_user_can( 'delete_users' ) ) {
282
+                $actions['delete'] = __( 'Delete' );
283
+            }
284
+        }
285
+
286
+        // Add a password reset link to the bulk actions dropdown.
287
+        if ( current_user_can( 'edit_users' ) ) {
288
+            $actions['resetpassword'] = __( 'Send password reset' );
289
+        }
290
+
291
+        return $actions;
292
+    }
293
+
294
+    /**
295
+     * Output the controls to allow user roles to be changed in bulk.
296
+     *
297
+     * @since 3.1.0
298
+     *
299
+     * @param string $which Whether this is being invoked above ("top")
300
+     *                      or below the table ("bottom").
301
+     */
302
+    protected function extra_tablenav( $which ) {
303
+        $id        = 'bottom' === $which ? 'new_role2' : 'new_role';
304
+        $button_id = 'bottom' === $which ? 'changeit2' : 'changeit';
305
+        ?>
306 306
 	<div class="alignleft actions">
307 307
 		<?php if ( current_user_can( 'promote_users' ) && $this->has_items() ) : ?>
308 308
 		<label class="screen-reader-text" for="<?php echo $id; ?>"><?php _e( 'Change role to&hellip;' ); ?></label>
@@ -312,363 +312,363 @@  discard block
 block discarded – undo
312 312
 			<option value="none"><?php _e( '&mdash; No role for this site &mdash;' ); ?></option>
313 313
 		</select>
314 314
 			<?php
315
-			submit_button( __( 'Change' ), '', $button_id, false );
316
-		endif;
317
-
318
-		/**
319
-		 * Fires just before the closing div containing the bulk role-change controls
320
-		 * in the Users list table.
321
-		 *
322
-		 * @since 3.5.0
323
-		 * @since 4.6.0 The `$which` parameter was added.
324
-		 *
325
-		 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
326
-		 */
327
-		do_action( 'restrict_manage_users', $which );
328
-		?>
315
+            submit_button( __( 'Change' ), '', $button_id, false );
316
+        endif;
317
+
318
+        /**
319
+         * Fires just before the closing div containing the bulk role-change controls
320
+         * in the Users list table.
321
+         *
322
+         * @since 3.5.0
323
+         * @since 4.6.0 The `$which` parameter was added.
324
+         *
325
+         * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
326
+         */
327
+        do_action( 'restrict_manage_users', $which );
328
+        ?>
329 329
 		</div>
330 330
 		<?php
331
-		/**
332
-		 * Fires immediately following the closing "actions" div in the tablenav for the users
333
-		 * list table.
334
-		 *
335
-		 * @since 4.9.0
336
-		 *
337
-		 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
338
-		 */
339
-		do_action( 'manage_users_extra_tablenav', $which );
340
-	}
341
-
342
-	/**
343
-	 * Capture the bulk action required, and return it.
344
-	 *
345
-	 * Overridden from the base class implementation to capture
346
-	 * the role change drop-down.
347
-	 *
348
-	 * @since 3.1.0
349
-	 *
350
-	 * @return string The bulk action required.
351
-	 */
352
-	public function current_action() {
353
-		if ( isset( $_REQUEST['changeit'] ) && ! empty( $_REQUEST['new_role'] ) ) {
354
-			return 'promote';
355
-		}
356
-
357
-		return parent::current_action();
358
-	}
359
-
360
-	/**
361
-	 * Get a list of columns for the list table.
362
-	 *
363
-	 * @since 3.1.0
364
-	 *
365
-	 * @return string[] Array of column titles keyed by their column name.
366
-	 */
367
-	public function get_columns() {
368
-		$c = array(
369
-			'cb'       => '<input type="checkbox" />',
370
-			'username' => __( 'Username' ),
371
-			'name'     => __( 'Name' ),
372
-			'email'    => __( 'Email' ),
373
-			'role'     => __( 'Role' ),
374
-			'posts'    => _x( 'Posts', 'post type general name' ),
375
-		);
376
-
377
-		if ( $this->is_site_users ) {
378
-			unset( $c['posts'] );
379
-		}
380
-
381
-		return $c;
382
-	}
383
-
384
-	/**
385
-	 * Get a list of sortable columns for the list table.
386
-	 *
387
-	 * @since 3.1.0
388
-	 *
389
-	 * @return array Array of sortable columns.
390
-	 */
391
-	protected function get_sortable_columns() {
392
-		$c = array(
393
-			'username' => 'login',
394
-			'email'    => 'email',
395
-		);
396
-
397
-		return $c;
398
-	}
399
-
400
-	/**
401
-	 * Generate the list table rows.
402
-	 *
403
-	 * @since 3.1.0
404
-	 */
405
-	public function display_rows() {
406
-		// Query the post counts for this page.
407
-		if ( ! $this->is_site_users ) {
408
-			$post_counts = count_many_users_posts( array_keys( $this->items ) );
409
-		}
410
-
411
-		foreach ( $this->items as $userid => $user_object ) {
412
-			echo "\n\t" . $this->single_row( $user_object, '', '', isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
413
-		}
414
-	}
415
-
416
-	/**
417
-	 * Generate HTML for a single row on the users.php admin panel.
418
-	 *
419
-	 * @since 3.1.0
420
-	 * @since 4.2.0 The `$style` parameter was deprecated.
421
-	 * @since 4.4.0 The `$role` parameter was deprecated.
422
-	 *
423
-	 * @param WP_User $user_object The current user object.
424
-	 * @param string  $style       Deprecated. Not used.
425
-	 * @param string  $role        Deprecated. Not used.
426
-	 * @param int     $numposts    Optional. Post count to display for this user. Defaults
427
-	 *                             to zero, as in, a new user has made zero posts.
428
-	 * @return string Output for a single row.
429
-	 */
430
-	public function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
431
-		if ( ! ( $user_object instanceof WP_User ) ) {
432
-			$user_object = get_userdata( (int) $user_object );
433
-		}
434
-		$user_object->filter = 'display';
435
-		$email               = $user_object->user_email;
436
-
437
-		if ( $this->is_site_users ) {
438
-			$url = "site-users.php?id={$this->site_id}&amp;";
439
-		} else {
440
-			$url = 'users.php?';
441
-		}
442
-
443
-		$user_roles = $this->get_role_list( $user_object );
444
-
445
-		// Set up the hover actions for this user.
446
-		$actions     = array();
447
-		$checkbox    = '';
448
-		$super_admin = '';
449
-
450
-		if ( is_multisite() && current_user_can( 'manage_network_users' ) ) {
451
-			if ( in_array( $user_object->user_login, get_super_admins(), true ) ) {
452
-				$super_admin = ' &mdash; ' . __( 'Super Admin' );
453
-			}
454
-		}
455
-
456
-		// Check if the user for this row is editable.
457
-		if ( current_user_can( 'list_users' ) ) {
458
-			// Set up the user editing link.
459
-			$edit_link = esc_url(
460
-				add_query_arg(
461
-					'wp_http_referer',
462
-					urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
463
-					get_edit_user_link( $user_object->ID )
464
-				)
465
-			);
466
-
467
-			if ( current_user_can( 'edit_user', $user_object->ID ) ) {
468
-				$edit            = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a>{$super_admin}</strong><br />";
469
-				$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
470
-			} else {
471
-				$edit = "<strong>{$user_object->user_login}{$super_admin}</strong><br />";
472
-			}
473
-
474
-			if ( ! is_multisite()
475
-				&& get_current_user_id() !== $user_object->ID
476
-				&& current_user_can( 'delete_user', $user_object->ID )
477
-			) {
478
-				$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . '</a>';
479
-			}
480
-
481
-			if ( is_multisite()
482
-				&& current_user_can( 'remove_user', $user_object->ID )
483
-			) {
484
-				$actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . '</a>';
485
-			}
486
-
487
-			// Add a link to the user's author archive, if not empty.
488
-			$author_posts_url = get_author_posts_url( $user_object->ID );
489
-			if ( $author_posts_url ) {
490
-				$actions['view'] = sprintf(
491
-					'<a href="%s" aria-label="%s">%s</a>',
492
-					esc_url( $author_posts_url ),
493
-					/* translators: %s: Author's display name. */
494
-					esc_attr( sprintf( __( 'View posts by %s' ), $user_object->display_name ) ),
495
-					__( 'View' )
496
-				);
497
-			}
498
-
499
-			// Add a link to send the user a reset password link by email.
500
-			if ( get_current_user_id() !== $user_object->ID
501
-				&& current_user_can( 'edit_user', $user_object->ID )
502
-			) {
503
-				$actions['resetpassword'] = "<a class='resetpassword' href='" . wp_nonce_url( "users.php?action=resetpassword&amp;users=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Send password reset' ) . '</a>';
504
-			}
505
-
506
-			/**
507
-			 * Filters the action links displayed under each user in the Users list table.
508
-			 *
509
-			 * @since 2.8.0
510
-			 *
511
-			 * @param string[] $actions     An array of action links to be displayed.
512
-			 *                              Default 'Edit', 'Delete' for single site, and
513
-			 *                              'Edit', 'Remove' for Multisite.
514
-			 * @param WP_User  $user_object WP_User object for the currently listed user.
515
-			 */
516
-			$actions = apply_filters( 'user_row_actions', $actions, $user_object );
517
-
518
-			// Role classes.
519
-			$role_classes = esc_attr( implode( ' ', array_keys( $user_roles ) ) );
520
-
521
-			// Set up the checkbox (because the user is editable, otherwise it's empty).
522
-			$checkbox = sprintf(
523
-				'<label class="screen-reader-text" for="user_%1$s">%2$s</label>' .
524
-				'<input type="checkbox" name="users[]" id="user_%1$s" class="%3$s" value="%1$s" />',
525
-				$user_object->ID,
526
-				/* translators: %s: User login. */
527
-				sprintf( __( 'Select %s' ), $user_object->user_login ),
528
-				$role_classes
529
-			);
530
-
531
-		} else {
532
-			$edit = "<strong>{$user_object->user_login}{$super_admin}</strong>";
533
-		}
534
-
535
-		$avatar = get_avatar( $user_object->ID, 32 );
536
-
537
-		// Comma-separated list of user roles.
538
-		$roles_list = implode( ', ', $user_roles );
539
-
540
-		$r = "<tr id='user-$user_object->ID'>";
541
-
542
-		list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
543
-
544
-		foreach ( $columns as $column_name => $column_display_name ) {
545
-			$classes = "$column_name column-$column_name";
546
-			if ( $primary === $column_name ) {
547
-				$classes .= ' has-row-actions column-primary';
548
-			}
549
-			if ( 'posts' === $column_name ) {
550
-				$classes .= ' num'; // Special case for that column.
551
-			}
552
-
553
-			if ( in_array( $column_name, $hidden, true ) ) {
554
-				$classes .= ' hidden';
555
-			}
556
-
557
-			$data = 'data-colname="' . esc_attr( wp_strip_all_tags( $column_display_name ) ) . '"';
558
-
559
-			$attributes = "class='$classes' $data";
560
-
561
-			if ( 'cb' === $column_name ) {
562
-				$r .= "<th scope='row' class='check-column'>$checkbox</th>";
563
-			} else {
564
-				$r .= "<td $attributes>";
565
-				switch ( $column_name ) {
566
-					case 'username':
567
-						$r .= "$avatar $edit";
568
-						break;
569
-					case 'name':
570
-						if ( $user_object->first_name && $user_object->last_name ) {
571
-							$r .= "$user_object->first_name $user_object->last_name";
572
-						} elseif ( $user_object->first_name ) {
573
-							$r .= $user_object->first_name;
574
-						} elseif ( $user_object->last_name ) {
575
-							$r .= $user_object->last_name;
576
-						} else {
577
-							$r .= sprintf(
578
-								'<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
579
-								_x( 'Unknown', 'name' )
580
-							);
581
-						}
582
-						break;
583
-					case 'email':
584
-						$r .= "<a href='" . esc_url( "mailto:$email" ) . "'>$email</a>";
585
-						break;
586
-					case 'role':
587
-						$r .= esc_html( $roles_list );
588
-						break;
589
-					case 'posts':
590
-						if ( $numposts > 0 ) {
591
-							$r .= sprintf(
592
-								'<a href="%s" class="edit"><span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
593
-								"edit.php?author={$user_object->ID}",
594
-								$numposts,
595
-								sprintf(
596
-									/* translators: %s: Number of posts. */
597
-									_n( '%s post by this author', '%s posts by this author', $numposts ),
598
-									number_format_i18n( $numposts )
599
-								)
600
-							);
601
-						} else {
602
-							$r .= 0;
603
-						}
604
-						break;
605
-					default:
606
-						/**
607
-						 * Filters the display output of custom columns in the Users list table.
608
-						 *
609
-						 * @since 2.8.0
610
-						 *
611
-						 * @param string $output      Custom column output. Default empty.
612
-						 * @param string $column_name Column name.
613
-						 * @param int    $user_id     ID of the currently-listed user.
614
-						 */
615
-						$r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
616
-				}
617
-
618
-				if ( $primary === $column_name ) {
619
-					$r .= $this->row_actions( $actions );
620
-				}
621
-				$r .= '</td>';
622
-			}
623
-		}
624
-		$r .= '</tr>';
625
-
626
-		return $r;
627
-	}
628
-
629
-	/**
630
-	 * Gets the name of the default primary column.
631
-	 *
632
-	 * @since 4.3.0
633
-	 *
634
-	 * @return string Name of the default primary column, in this case, 'username'.
635
-	 */
636
-	protected function get_default_primary_column_name() {
637
-		return 'username';
638
-	}
639
-
640
-	/**
641
-	 * Returns an array of translated user role names for a given user object.
642
-	 *
643
-	 * @since 4.4.0
644
-	 *
645
-	 * @param WP_User $user_object The WP_User object.
646
-	 * @return string[] An array of user role names keyed by role.
647
-	 */
648
-	protected function get_role_list( $user_object ) {
649
-		$wp_roles = wp_roles();
650
-
651
-		$role_list = array();
652
-
653
-		foreach ( $user_object->roles as $role ) {
654
-			if ( isset( $wp_roles->role_names[ $role ] ) ) {
655
-				$role_list[ $role ] = translate_user_role( $wp_roles->role_names[ $role ] );
656
-			}
657
-		}
658
-
659
-		if ( empty( $role_list ) ) {
660
-			$role_list['none'] = _x( 'None', 'no user roles' );
661
-		}
662
-
663
-		/**
664
-		 * Filters the returned array of translated role names for a user.
665
-		 *
666
-		 * @since 4.4.0
667
-		 *
668
-		 * @param string[] $role_list   An array of translated user role names keyed by role.
669
-		 * @param WP_User  $user_object A WP_User object.
670
-		 */
671
-		return apply_filters( 'get_role_list', $role_list, $user_object );
672
-	}
331
+        /**
332
+         * Fires immediately following the closing "actions" div in the tablenav for the users
333
+         * list table.
334
+         *
335
+         * @since 4.9.0
336
+         *
337
+         * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
338
+         */
339
+        do_action( 'manage_users_extra_tablenav', $which );
340
+    }
341
+
342
+    /**
343
+     * Capture the bulk action required, and return it.
344
+     *
345
+     * Overridden from the base class implementation to capture
346
+     * the role change drop-down.
347
+     *
348
+     * @since 3.1.0
349
+     *
350
+     * @return string The bulk action required.
351
+     */
352
+    public function current_action() {
353
+        if ( isset( $_REQUEST['changeit'] ) && ! empty( $_REQUEST['new_role'] ) ) {
354
+            return 'promote';
355
+        }
356
+
357
+        return parent::current_action();
358
+    }
359
+
360
+    /**
361
+     * Get a list of columns for the list table.
362
+     *
363
+     * @since 3.1.0
364
+     *
365
+     * @return string[] Array of column titles keyed by their column name.
366
+     */
367
+    public function get_columns() {
368
+        $c = array(
369
+            'cb'       => '<input type="checkbox" />',
370
+            'username' => __( 'Username' ),
371
+            'name'     => __( 'Name' ),
372
+            'email'    => __( 'Email' ),
373
+            'role'     => __( 'Role' ),
374
+            'posts'    => _x( 'Posts', 'post type general name' ),
375
+        );
376
+
377
+        if ( $this->is_site_users ) {
378
+            unset( $c['posts'] );
379
+        }
380
+
381
+        return $c;
382
+    }
383
+
384
+    /**
385
+     * Get a list of sortable columns for the list table.
386
+     *
387
+     * @since 3.1.0
388
+     *
389
+     * @return array Array of sortable columns.
390
+     */
391
+    protected function get_sortable_columns() {
392
+        $c = array(
393
+            'username' => 'login',
394
+            'email'    => 'email',
395
+        );
396
+
397
+        return $c;
398
+    }
399
+
400
+    /**
401
+     * Generate the list table rows.
402
+     *
403
+     * @since 3.1.0
404
+     */
405
+    public function display_rows() {
406
+        // Query the post counts for this page.
407
+        if ( ! $this->is_site_users ) {
408
+            $post_counts = count_many_users_posts( array_keys( $this->items ) );
409
+        }
410
+
411
+        foreach ( $this->items as $userid => $user_object ) {
412
+            echo "\n\t" . $this->single_row( $user_object, '', '', isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
413
+        }
414
+    }
415
+
416
+    /**
417
+     * Generate HTML for a single row on the users.php admin panel.
418
+     *
419
+     * @since 3.1.0
420
+     * @since 4.2.0 The `$style` parameter was deprecated.
421
+     * @since 4.4.0 The `$role` parameter was deprecated.
422
+     *
423
+     * @param WP_User $user_object The current user object.
424
+     * @param string  $style       Deprecated. Not used.
425
+     * @param string  $role        Deprecated. Not used.
426
+     * @param int     $numposts    Optional. Post count to display for this user. Defaults
427
+     *                             to zero, as in, a new user has made zero posts.
428
+     * @return string Output for a single row.
429
+     */
430
+    public function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
431
+        if ( ! ( $user_object instanceof WP_User ) ) {
432
+            $user_object = get_userdata( (int) $user_object );
433
+        }
434
+        $user_object->filter = 'display';
435
+        $email               = $user_object->user_email;
436
+
437
+        if ( $this->is_site_users ) {
438
+            $url = "site-users.php?id={$this->site_id}&amp;";
439
+        } else {
440
+            $url = 'users.php?';
441
+        }
442
+
443
+        $user_roles = $this->get_role_list( $user_object );
444
+
445
+        // Set up the hover actions for this user.
446
+        $actions     = array();
447
+        $checkbox    = '';
448
+        $super_admin = '';
449
+
450
+        if ( is_multisite() && current_user_can( 'manage_network_users' ) ) {
451
+            if ( in_array( $user_object->user_login, get_super_admins(), true ) ) {
452
+                $super_admin = ' &mdash; ' . __( 'Super Admin' );
453
+            }
454
+        }
455
+
456
+        // Check if the user for this row is editable.
457
+        if ( current_user_can( 'list_users' ) ) {
458
+            // Set up the user editing link.
459
+            $edit_link = esc_url(
460
+                add_query_arg(
461
+                    'wp_http_referer',
462
+                    urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
463
+                    get_edit_user_link( $user_object->ID )
464
+                )
465
+            );
466
+
467
+            if ( current_user_can( 'edit_user', $user_object->ID ) ) {
468
+                $edit            = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a>{$super_admin}</strong><br />";
469
+                $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
470
+            } else {
471
+                $edit = "<strong>{$user_object->user_login}{$super_admin}</strong><br />";
472
+            }
473
+
474
+            if ( ! is_multisite()
475
+                && get_current_user_id() !== $user_object->ID
476
+                && current_user_can( 'delete_user', $user_object->ID )
477
+            ) {
478
+                $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . '</a>';
479
+            }
480
+
481
+            if ( is_multisite()
482
+                && current_user_can( 'remove_user', $user_object->ID )
483
+            ) {
484
+                $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . '</a>';
485
+            }
486
+
487
+            // Add a link to the user's author archive, if not empty.
488
+            $author_posts_url = get_author_posts_url( $user_object->ID );
489
+            if ( $author_posts_url ) {
490
+                $actions['view'] = sprintf(
491
+                    '<a href="%s" aria-label="%s">%s</a>',
492
+                    esc_url( $author_posts_url ),
493
+                    /* translators: %s: Author's display name. */
494
+                    esc_attr( sprintf( __( 'View posts by %s' ), $user_object->display_name ) ),
495
+                    __( 'View' )
496
+                );
497
+            }
498
+
499
+            // Add a link to send the user a reset password link by email.
500
+            if ( get_current_user_id() !== $user_object->ID
501
+                && current_user_can( 'edit_user', $user_object->ID )
502
+            ) {
503
+                $actions['resetpassword'] = "<a class='resetpassword' href='" . wp_nonce_url( "users.php?action=resetpassword&amp;users=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Send password reset' ) . '</a>';
504
+            }
505
+
506
+            /**
507
+             * Filters the action links displayed under each user in the Users list table.
508
+             *
509
+             * @since 2.8.0
510
+             *
511
+             * @param string[] $actions     An array of action links to be displayed.
512
+             *                              Default 'Edit', 'Delete' for single site, and
513
+             *                              'Edit', 'Remove' for Multisite.
514
+             * @param WP_User  $user_object WP_User object for the currently listed user.
515
+             */
516
+            $actions = apply_filters( 'user_row_actions', $actions, $user_object );
517
+
518
+            // Role classes.
519
+            $role_classes = esc_attr( implode( ' ', array_keys( $user_roles ) ) );
520
+
521
+            // Set up the checkbox (because the user is editable, otherwise it's empty).
522
+            $checkbox = sprintf(
523
+                '<label class="screen-reader-text" for="user_%1$s">%2$s</label>' .
524
+                '<input type="checkbox" name="users[]" id="user_%1$s" class="%3$s" value="%1$s" />',
525
+                $user_object->ID,
526
+                /* translators: %s: User login. */
527
+                sprintf( __( 'Select %s' ), $user_object->user_login ),
528
+                $role_classes
529
+            );
530
+
531
+        } else {
532
+            $edit = "<strong>{$user_object->user_login}{$super_admin}</strong>";
533
+        }
534
+
535
+        $avatar = get_avatar( $user_object->ID, 32 );
536
+
537
+        // Comma-separated list of user roles.
538
+        $roles_list = implode( ', ', $user_roles );
539
+
540
+        $r = "<tr id='user-$user_object->ID'>";
541
+
542
+        list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
543
+
544
+        foreach ( $columns as $column_name => $column_display_name ) {
545
+            $classes = "$column_name column-$column_name";
546
+            if ( $primary === $column_name ) {
547
+                $classes .= ' has-row-actions column-primary';
548
+            }
549
+            if ( 'posts' === $column_name ) {
550
+                $classes .= ' num'; // Special case for that column.
551
+            }
552
+
553
+            if ( in_array( $column_name, $hidden, true ) ) {
554
+                $classes .= ' hidden';
555
+            }
556
+
557
+            $data = 'data-colname="' . esc_attr( wp_strip_all_tags( $column_display_name ) ) . '"';
558
+
559
+            $attributes = "class='$classes' $data";
560
+
561
+            if ( 'cb' === $column_name ) {
562
+                $r .= "<th scope='row' class='check-column'>$checkbox</th>";
563
+            } else {
564
+                $r .= "<td $attributes>";
565
+                switch ( $column_name ) {
566
+                    case 'username':
567
+                        $r .= "$avatar $edit";
568
+                        break;
569
+                    case 'name':
570
+                        if ( $user_object->first_name && $user_object->last_name ) {
571
+                            $r .= "$user_object->first_name $user_object->last_name";
572
+                        } elseif ( $user_object->first_name ) {
573
+                            $r .= $user_object->first_name;
574
+                        } elseif ( $user_object->last_name ) {
575
+                            $r .= $user_object->last_name;
576
+                        } else {
577
+                            $r .= sprintf(
578
+                                '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
579
+                                _x( 'Unknown', 'name' )
580
+                            );
581
+                        }
582
+                        break;
583
+                    case 'email':
584
+                        $r .= "<a href='" . esc_url( "mailto:$email" ) . "'>$email</a>";
585
+                        break;
586
+                    case 'role':
587
+                        $r .= esc_html( $roles_list );
588
+                        break;
589
+                    case 'posts':
590
+                        if ( $numposts > 0 ) {
591
+                            $r .= sprintf(
592
+                                '<a href="%s" class="edit"><span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
593
+                                "edit.php?author={$user_object->ID}",
594
+                                $numposts,
595
+                                sprintf(
596
+                                    /* translators: %s: Number of posts. */
597
+                                    _n( '%s post by this author', '%s posts by this author', $numposts ),
598
+                                    number_format_i18n( $numposts )
599
+                                )
600
+                            );
601
+                        } else {
602
+                            $r .= 0;
603
+                        }
604
+                        break;
605
+                    default:
606
+                        /**
607
+                         * Filters the display output of custom columns in the Users list table.
608
+                         *
609
+                         * @since 2.8.0
610
+                         *
611
+                         * @param string $output      Custom column output. Default empty.
612
+                         * @param string $column_name Column name.
613
+                         * @param int    $user_id     ID of the currently-listed user.
614
+                         */
615
+                        $r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
616
+                }
617
+
618
+                if ( $primary === $column_name ) {
619
+                    $r .= $this->row_actions( $actions );
620
+                }
621
+                $r .= '</td>';
622
+            }
623
+        }
624
+        $r .= '</tr>';
625
+
626
+        return $r;
627
+    }
628
+
629
+    /**
630
+     * Gets the name of the default primary column.
631
+     *
632
+     * @since 4.3.0
633
+     *
634
+     * @return string Name of the default primary column, in this case, 'username'.
635
+     */
636
+    protected function get_default_primary_column_name() {
637
+        return 'username';
638
+    }
639
+
640
+    /**
641
+     * Returns an array of translated user role names for a given user object.
642
+     *
643
+     * @since 4.4.0
644
+     *
645
+     * @param WP_User $user_object The WP_User object.
646
+     * @return string[] An array of user role names keyed by role.
647
+     */
648
+    protected function get_role_list( $user_object ) {
649
+        $wp_roles = wp_roles();
650
+
651
+        $role_list = array();
652
+
653
+        foreach ( $user_object->roles as $role ) {
654
+            if ( isset( $wp_roles->role_names[ $role ] ) ) {
655
+                $role_list[ $role ] = translate_user_role( $wp_roles->role_names[ $role ] );
656
+            }
657
+        }
658
+
659
+        if ( empty( $role_list ) ) {
660
+            $role_list['none'] = _x( 'None', 'no user roles' );
661
+        }
662
+
663
+        /**
664
+         * Filters the returned array of translated role names for a user.
665
+         *
666
+         * @since 4.4.0
667
+         *
668
+         * @param string[] $role_list   An array of translated user role names keyed by role.
669
+         * @param WP_User  $user_object A WP_User object.
670
+         */
671
+        return apply_filters( 'get_role_list', $role_list, $user_object );
672
+    }
673 673
 
674 674
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/credits.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@  discard block
 block discarded – undo
18 18
  * @return array|false A list of all of the contributors, or false on error.
19 19
  */
20 20
 function wp_credits( $version = '', $locale = '' ) {
21
-	if ( ! $version ) {
22
-		// Include an unmodified $wp_version.
23
-		require ABSPATH . WPINC . '/version.php';
21
+    if ( ! $version ) {
22
+        // Include an unmodified $wp_version.
23
+        require ABSPATH . WPINC . '/version.php';
24 24
 
25
-		$version = $wp_version;
26
-	}
25
+        $version = $wp_version;
26
+    }
27 27
 
28
-	if ( ! $locale ) {
29
-		$locale = get_user_locale();
30
-	}
28
+    if ( ! $locale ) {
29
+        $locale = get_user_locale();
30
+    }
31 31
 
32
-	$results = get_site_transient( 'wordpress_credits_' . $locale );
32
+    $results = get_site_transient( 'wordpress_credits_' . $locale );
33 33
 
34
-	if ( ! is_array( $results )
35
-		|| false !== strpos( $version, '-' )
36
-		|| ( isset( $results['data']['version'] ) && strpos( $version, $results['data']['version'] ) !== 0 )
37
-	) {
38
-		$url     = "http://api.wordpress.org/core/credits/1.1/?version={$version}&locale={$locale}";
39
-		$options = array( 'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' ) );
34
+    if ( ! is_array( $results )
35
+        || false !== strpos( $version, '-' )
36
+        || ( isset( $results['data']['version'] ) && strpos( $version, $results['data']['version'] ) !== 0 )
37
+    ) {
38
+        $url     = "http://api.wordpress.org/core/credits/1.1/?version={$version}&locale={$locale}";
39
+        $options = array( 'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' ) );
40 40
 
41
-		if ( wp_http_supports( array( 'ssl' ) ) ) {
42
-			$url = set_url_scheme( $url, 'https' );
43
-		}
41
+        if ( wp_http_supports( array( 'ssl' ) ) ) {
42
+            $url = set_url_scheme( $url, 'https' );
43
+        }
44 44
 
45
-		$response = wp_remote_get( $url, $options );
45
+        $response = wp_remote_get( $url, $options );
46 46
 
47
-		if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
48
-			return false;
49
-		}
47
+        if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
48
+            return false;
49
+        }
50 50
 
51
-		$results = json_decode( wp_remote_retrieve_body( $response ), true );
51
+        $results = json_decode( wp_remote_retrieve_body( $response ), true );
52 52
 
53
-		if ( ! is_array( $results ) ) {
54
-			return false;
55
-		}
53
+        if ( ! is_array( $results ) ) {
54
+            return false;
55
+        }
56 56
 
57
-		set_site_transient( 'wordpress_credits_' . $locale, $results, DAY_IN_SECONDS );
58
-	}
57
+        set_site_transient( 'wordpress_credits_' . $locale, $results, DAY_IN_SECONDS );
58
+    }
59 59
 
60
-	return $results;
60
+    return $results;
61 61
 }
62 62
 
63 63
 /**
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
  * @param string $profiles      URL to the contributor's WordPress.org profile page.
72 72
  */
73 73
 function _wp_credits_add_profile_link( &$display_name, $username, $profiles ) {
74
-	$display_name = '<a href="' . esc_url( sprintf( $profiles, $username ) ) . '">' . esc_html( $display_name ) . '</a>';
74
+    $display_name = '<a href="' . esc_url( sprintf( $profiles, $username ) ) . '">' . esc_html( $display_name ) . '</a>';
75 75
 }
76 76
 
77 77
 /**
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
  * @param string $data External library data (passed by reference).
84 84
  */
85 85
 function _wp_credits_build_object_link( &$data ) {
86
-	$data = '<a href="' . esc_url( $data[1] ) . '">' . esc_html( $data[0] ) . '</a>';
86
+    $data = '<a href="' . esc_url( $data[1] ) . '">' . esc_html( $data[0] ) . '</a>';
87 87
 }
88 88
 
89 89
 /**
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
  * @param array $group_data The current contributor group.
95 95
  */
96 96
 function wp_credits_section_title( $group_data = array() ) {
97
-	if ( ! count( $group_data ) ) {
98
-		return;
99
-	}
100
-
101
-	if ( $group_data['name'] ) {
102
-		if ( 'Translators' === $group_data['name'] ) {
103
-			// Considered a special slug in the API response. (Also, will never be returned for en_US.)
104
-			$title = _x( 'Translators', 'Translate this to be the equivalent of English Translators in your language for the credits page Translators section' );
105
-		} elseif ( isset( $group_data['placeholders'] ) ) {
106
-			// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
107
-			$title = vsprintf( translate( $group_data['name'] ), $group_data['placeholders'] );
108
-		} else {
109
-			// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
110
-			$title = translate( $group_data['name'] );
111
-		}
112
-
113
-		echo '<h2 class="wp-people-group-title">' . esc_html( $title ) . "</h2>\n";
114
-	}
97
+    if ( ! count( $group_data ) ) {
98
+        return;
99
+    }
100
+
101
+    if ( $group_data['name'] ) {
102
+        if ( 'Translators' === $group_data['name'] ) {
103
+            // Considered a special slug in the API response. (Also, will never be returned for en_US.)
104
+            $title = _x( 'Translators', 'Translate this to be the equivalent of English Translators in your language for the credits page Translators section' );
105
+        } elseif ( isset( $group_data['placeholders'] ) ) {
106
+            // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
107
+            $title = vsprintf( translate( $group_data['name'] ), $group_data['placeholders'] );
108
+        } else {
109
+            // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
110
+            $title = translate( $group_data['name'] );
111
+        }
112
+
113
+        echo '<h2 class="wp-people-group-title">' . esc_html( $title ) . "</h2>\n";
114
+    }
115 115
 }
116 116
 
117 117
 /**
@@ -123,44 +123,44 @@  discard block
 block discarded – undo
123 123
  * @param string $slug    The current group to display.
124 124
  */
125 125
 function wp_credits_section_list( $credits = array(), $slug = '' ) {
126
-	$group_data   = isset( $credits['groups'][ $slug ] ) ? $credits['groups'][ $slug ] : array();
127
-	$credits_data = $credits['data'];
128
-	if ( ! count( $group_data ) ) {
129
-		return;
130
-	}
131
-
132
-	if ( ! empty( $group_data['shuffle'] ) ) {
133
-		shuffle( $group_data['data'] ); // We were going to sort by ability to pronounce "hierarchical," but that wouldn't be fair to Matt.
134
-	}
135
-
136
-	switch ( $group_data['type'] ) {
137
-		case 'list':
138
-			array_walk( $group_data['data'], '_wp_credits_add_profile_link', $credits_data['profiles'] );
139
-			echo '<p class="wp-credits-list">' . wp_sprintf( '%l.', $group_data['data'] ) . "</p>\n\n";
140
-			break;
141
-		case 'libraries':
142
-			array_walk( $group_data['data'], '_wp_credits_build_object_link' );
143
-			echo '<p class="wp-credits-list">' . wp_sprintf( '%l.', $group_data['data'] ) . "</p>\n\n";
144
-			break;
145
-		default:
146
-			$compact = 'compact' === $group_data['type'];
147
-			$classes = 'wp-people-group ' . ( $compact ? 'compact' : '' );
148
-			echo '<ul class="' . $classes . '" id="wp-people-group-' . $slug . '">' . "\n";
149
-			foreach ( $group_data['data'] as $person_data ) {
150
-				echo '<li class="wp-person" id="wp-person-' . esc_attr( $person_data[2] ) . '">' . "\n\t";
151
-				echo '<a href="' . esc_url( sprintf( $credits_data['profiles'], $person_data[2] ) ) . '" class="web">';
152
-				$size   = $compact ? 80 : 160;
153
-				$data   = get_avatar_data( $person_data[1] . '@md5.gravatar.com', array( 'size' => $size ) );
154
-				$data2x = get_avatar_data( $person_data[1] . '@md5.gravatar.com', array( 'size' => $size * 2 ) );
155
-				echo '<span class="wp-person-avatar"><img src="' . esc_url( $data['url'] ) . '" srcset="' . esc_url( $data2x['url'] ) . ' 2x" class="gravatar" alt="" /></span>' . "\n";
156
-				echo esc_html( $person_data[0] ) . "</a>\n\t";
157
-				if ( ! $compact && ! empty( $person_data[3] ) ) {
158
-					// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
159
-					echo '<span class="title">' . translate( $person_data[3] ) . "</span>\n";
160
-				}
161
-				echo "</li>\n";
162
-			}
163
-			echo "</ul>\n";
164
-			break;
165
-	}
126
+    $group_data   = isset( $credits['groups'][ $slug ] ) ? $credits['groups'][ $slug ] : array();
127
+    $credits_data = $credits['data'];
128
+    if ( ! count( $group_data ) ) {
129
+        return;
130
+    }
131
+
132
+    if ( ! empty( $group_data['shuffle'] ) ) {
133
+        shuffle( $group_data['data'] ); // We were going to sort by ability to pronounce "hierarchical," but that wouldn't be fair to Matt.
134
+    }
135
+
136
+    switch ( $group_data['type'] ) {
137
+        case 'list':
138
+            array_walk( $group_data['data'], '_wp_credits_add_profile_link', $credits_data['profiles'] );
139
+            echo '<p class="wp-credits-list">' . wp_sprintf( '%l.', $group_data['data'] ) . "</p>\n\n";
140
+            break;
141
+        case 'libraries':
142
+            array_walk( $group_data['data'], '_wp_credits_build_object_link' );
143
+            echo '<p class="wp-credits-list">' . wp_sprintf( '%l.', $group_data['data'] ) . "</p>\n\n";
144
+            break;
145
+        default:
146
+            $compact = 'compact' === $group_data['type'];
147
+            $classes = 'wp-people-group ' . ( $compact ? 'compact' : '' );
148
+            echo '<ul class="' . $classes . '" id="wp-people-group-' . $slug . '">' . "\n";
149
+            foreach ( $group_data['data'] as $person_data ) {
150
+                echo '<li class="wp-person" id="wp-person-' . esc_attr( $person_data[2] ) . '">' . "\n\t";
151
+                echo '<a href="' . esc_url( sprintf( $credits_data['profiles'], $person_data[2] ) ) . '" class="web">';
152
+                $size   = $compact ? 80 : 160;
153
+                $data   = get_avatar_data( $person_data[1] . '@md5.gravatar.com', array( 'size' => $size ) );
154
+                $data2x = get_avatar_data( $person_data[1] . '@md5.gravatar.com', array( 'size' => $size * 2 ) );
155
+                echo '<span class="wp-person-avatar"><img src="' . esc_url( $data['url'] ) . '" srcset="' . esc_url( $data2x['url'] ) . ' 2x" class="gravatar" alt="" /></span>' . "\n";
156
+                echo esc_html( $person_data[0] ) . "</a>\n\t";
157
+                if ( ! $compact && ! empty( $person_data[3] ) ) {
158
+                    // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
159
+                    echo '<span class="title">' . translate( $person_data[3] ) . "</span>\n";
160
+                }
161
+                echo "</li>\n";
162
+            }
163
+            echo "</ul>\n";
164
+            break;
165
+    }
166 166
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-bulk-upgrader-skin.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -16,166 +16,166 @@
 block discarded – undo
16 16
  * @see WP_Upgrader_Skin
17 17
  */
18 18
 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
19
-	public $in_loop = false;
20
-	/**
21
-	 * @var string|false
22
-	 */
23
-	public $error = false;
24
-
25
-	/**
26
-	 * @param array $args
27
-	 */
28
-	public function __construct( $args = array() ) {
29
-		$defaults = array(
30
-			'url'   => '',
31
-			'nonce' => '',
32
-		);
33
-		$args     = wp_parse_args( $args, $defaults );
34
-
35
-		parent::__construct( $args );
36
-	}
37
-
38
-	/**
39
-	 */
40
-	public function add_strings() {
41
-		$this->upgrader->strings['skin_upgrade_start'] = __( 'The update process is starting. This process may take a while on some hosts, so please be patient.' );
42
-		/* translators: 1: Title of an update, 2: Error message. */
43
-		$this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while updating %1$s: %2$s' );
44
-		/* translators: %s: Title of an update. */
45
-		$this->upgrader->strings['skin_update_failed'] = __( 'The update of %s failed.' );
46
-		/* translators: %s: Title of an update. */
47
-		$this->upgrader->strings['skin_update_successful'] = __( '%s updated successfully.' );
48
-		$this->upgrader->strings['skin_upgrade_end']       = __( 'All updates have been completed.' );
49
-	}
50
-
51
-	/**
52
-	 * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
53
-	 *
54
-	 * @param string $feedback Message data.
55
-	 * @param mixed  ...$args  Optional text replacements.
56
-	 */
57
-	public function feedback( $feedback, ...$args ) {
58
-		if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
59
-			$feedback = $this->upgrader->strings[ $feedback ];
60
-		}
61
-
62
-		if ( strpos( $feedback, '%' ) !== false ) {
63
-			if ( $args ) {
64
-				$args     = array_map( 'strip_tags', $args );
65
-				$args     = array_map( 'esc_html', $args );
66
-				$feedback = vsprintf( $feedback, $args );
67
-			}
68
-		}
69
-		if ( empty( $feedback ) ) {
70
-			return;
71
-		}
72
-		if ( $this->in_loop ) {
73
-			echo "$feedback<br />\n";
74
-		} else {
75
-			echo "<p>$feedback</p>\n";
76
-		}
77
-	}
78
-
79
-	/**
80
-	 */
81
-	public function header() {
82
-		// Nothing, This will be displayed within a iframe.
83
-	}
84
-
85
-	/**
86
-	 */
87
-	public function footer() {
88
-		// Nothing, This will be displayed within a iframe.
89
-	}
90
-
91
-	/**
92
-	 * @since 5.9.0 Renamed `$error` to `$errors` for PHP 8 named parameter support.
93
-	 *
94
-	 * @param string|WP_Error $errors Errors.
95
-	 */
96
-	public function error( $errors ) {
97
-		if ( is_string( $errors ) && isset( $this->upgrader->strings[ $errors ] ) ) {
98
-			$this->error = $this->upgrader->strings[ $errors ];
99
-		}
100
-
101
-		if ( is_wp_error( $errors ) ) {
102
-			$messages = array();
103
-			foreach ( $errors->get_error_messages() as $emessage ) {
104
-				if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
105
-					$messages[] = $emessage . ' ' . esc_html( strip_tags( $errors->get_error_data() ) );
106
-				} else {
107
-					$messages[] = $emessage;
108
-				}
109
-			}
110
-			$this->error = implode( ', ', $messages );
111
-		}
112
-		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
113
-	}
114
-
115
-	/**
116
-	 */
117
-	public function bulk_header() {
118
-		$this->feedback( 'skin_upgrade_start' );
119
-	}
120
-
121
-	/**
122
-	 */
123
-	public function bulk_footer() {
124
-		$this->feedback( 'skin_upgrade_end' );
125
-	}
126
-
127
-	/**
128
-	 * @param string $title
129
-	 */
130
-	public function before( $title = '' ) {
131
-		$this->in_loop = true;
132
-		printf( '<h2>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h2>', $title, $this->upgrader->update_current, $this->upgrader->update_count );
133
-		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");</script>';
134
-		// This progress messages div gets moved via JavaScript when clicking on "Show details.".
135
-		echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>';
136
-		$this->flush_output();
137
-	}
138
-
139
-	/**
140
-	 * @param string $title
141
-	 */
142
-	public function after( $title = '' ) {
143
-		echo '</p></div>';
144
-		if ( $this->error || ! $this->result ) {
145
-			if ( $this->error ) {
146
-				echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
147
-			} else {
148
-				echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '</p></div>';
149
-			}
150
-
151
-			echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>';
152
-		}
153
-		if ( $this->result && ! is_wp_error( $this->result ) ) {
154
-			if ( ! $this->error ) {
155
-				echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' .
156
-					'<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) .
157
-					' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'Show details.' ) . '</button>' .
158
-					'</p></div>';
159
-			}
160
-
161
-			echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
162
-		}
163
-
164
-		$this->reset();
165
-		$this->flush_output();
166
-	}
167
-
168
-	/**
169
-	 */
170
-	public function reset() {
171
-		$this->in_loop = false;
172
-		$this->error   = false;
173
-	}
174
-
175
-	/**
176
-	 */
177
-	public function flush_output() {
178
-		wp_ob_end_flush_all();
179
-		flush();
180
-	}
19
+    public $in_loop = false;
20
+    /**
21
+     * @var string|false
22
+     */
23
+    public $error = false;
24
+
25
+    /**
26
+     * @param array $args
27
+     */
28
+    public function __construct( $args = array() ) {
29
+        $defaults = array(
30
+            'url'   => '',
31
+            'nonce' => '',
32
+        );
33
+        $args     = wp_parse_args( $args, $defaults );
34
+
35
+        parent::__construct( $args );
36
+    }
37
+
38
+    /**
39
+     */
40
+    public function add_strings() {
41
+        $this->upgrader->strings['skin_upgrade_start'] = __( 'The update process is starting. This process may take a while on some hosts, so please be patient.' );
42
+        /* translators: 1: Title of an update, 2: Error message. */
43
+        $this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while updating %1$s: %2$s' );
44
+        /* translators: %s: Title of an update. */
45
+        $this->upgrader->strings['skin_update_failed'] = __( 'The update of %s failed.' );
46
+        /* translators: %s: Title of an update. */
47
+        $this->upgrader->strings['skin_update_successful'] = __( '%s updated successfully.' );
48
+        $this->upgrader->strings['skin_upgrade_end']       = __( 'All updates have been completed.' );
49
+    }
50
+
51
+    /**
52
+     * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
53
+     *
54
+     * @param string $feedback Message data.
55
+     * @param mixed  ...$args  Optional text replacements.
56
+     */
57
+    public function feedback( $feedback, ...$args ) {
58
+        if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
59
+            $feedback = $this->upgrader->strings[ $feedback ];
60
+        }
61
+
62
+        if ( strpos( $feedback, '%' ) !== false ) {
63
+            if ( $args ) {
64
+                $args     = array_map( 'strip_tags', $args );
65
+                $args     = array_map( 'esc_html', $args );
66
+                $feedback = vsprintf( $feedback, $args );
67
+            }
68
+        }
69
+        if ( empty( $feedback ) ) {
70
+            return;
71
+        }
72
+        if ( $this->in_loop ) {
73
+            echo "$feedback<br />\n";
74
+        } else {
75
+            echo "<p>$feedback</p>\n";
76
+        }
77
+    }
78
+
79
+    /**
80
+     */
81
+    public function header() {
82
+        // Nothing, This will be displayed within a iframe.
83
+    }
84
+
85
+    /**
86
+     */
87
+    public function footer() {
88
+        // Nothing, This will be displayed within a iframe.
89
+    }
90
+
91
+    /**
92
+     * @since 5.9.0 Renamed `$error` to `$errors` for PHP 8 named parameter support.
93
+     *
94
+     * @param string|WP_Error $errors Errors.
95
+     */
96
+    public function error( $errors ) {
97
+        if ( is_string( $errors ) && isset( $this->upgrader->strings[ $errors ] ) ) {
98
+            $this->error = $this->upgrader->strings[ $errors ];
99
+        }
100
+
101
+        if ( is_wp_error( $errors ) ) {
102
+            $messages = array();
103
+            foreach ( $errors->get_error_messages() as $emessage ) {
104
+                if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
105
+                    $messages[] = $emessage . ' ' . esc_html( strip_tags( $errors->get_error_data() ) );
106
+                } else {
107
+                    $messages[] = $emessage;
108
+                }
109
+            }
110
+            $this->error = implode( ', ', $messages );
111
+        }
112
+        echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
113
+    }
114
+
115
+    /**
116
+     */
117
+    public function bulk_header() {
118
+        $this->feedback( 'skin_upgrade_start' );
119
+    }
120
+
121
+    /**
122
+     */
123
+    public function bulk_footer() {
124
+        $this->feedback( 'skin_upgrade_end' );
125
+    }
126
+
127
+    /**
128
+     * @param string $title
129
+     */
130
+    public function before( $title = '' ) {
131
+        $this->in_loop = true;
132
+        printf( '<h2>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h2>', $title, $this->upgrader->update_current, $this->upgrader->update_count );
133
+        echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");</script>';
134
+        // This progress messages div gets moved via JavaScript when clicking on "Show details.".
135
+        echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>';
136
+        $this->flush_output();
137
+    }
138
+
139
+    /**
140
+     * @param string $title
141
+     */
142
+    public function after( $title = '' ) {
143
+        echo '</p></div>';
144
+        if ( $this->error || ! $this->result ) {
145
+            if ( $this->error ) {
146
+                echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
147
+            } else {
148
+                echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '</p></div>';
149
+            }
150
+
151
+            echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>';
152
+        }
153
+        if ( $this->result && ! is_wp_error( $this->result ) ) {
154
+            if ( ! $this->error ) {
155
+                echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' .
156
+                    '<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) .
157
+                    ' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'Show details.' ) . '</button>' .
158
+                    '</p></div>';
159
+            }
160
+
161
+            echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
162
+        }
163
+
164
+        $this->reset();
165
+        $this->flush_output();
166
+    }
167
+
168
+    /**
169
+     */
170
+    public function reset() {
171
+        $this->in_loop = false;
172
+        $this->error   = false;
173
+    }
174
+
175
+    /**
176
+     */
177
+    public function flush_output() {
178
+        wp_ob_end_flush_all();
179
+        flush();
180
+    }
181 181
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-plugin-installer-skin.php 1 patch
Indentation   +330 added lines, -330 removed lines patch added patch discarded remove patch
@@ -16,334 +16,334 @@
 block discarded – undo
16 16
  * @see WP_Upgrader_Skin
17 17
  */
18 18
 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
19
-	public $api;
20
-	public $type;
21
-	public $url;
22
-	public $overwrite;
23
-
24
-	private $is_downgrading = false;
25
-
26
-	/**
27
-	 * @param array $args
28
-	 */
29
-	public function __construct( $args = array() ) {
30
-		$defaults = array(
31
-			'type'      => 'web',
32
-			'url'       => '',
33
-			'plugin'    => '',
34
-			'nonce'     => '',
35
-			'title'     => '',
36
-			'overwrite' => '',
37
-		);
38
-		$args     = wp_parse_args( $args, $defaults );
39
-
40
-		$this->type      = $args['type'];
41
-		$this->url       = $args['url'];
42
-		$this->api       = isset( $args['api'] ) ? $args['api'] : array();
43
-		$this->overwrite = $args['overwrite'];
44
-
45
-		parent::__construct( $args );
46
-	}
47
-
48
-	/**
49
-	 * Action to perform before installing a plugin.
50
-	 *
51
-	 * @since 2.8.0
52
-	 */
53
-	public function before() {
54
-		if ( ! empty( $this->api ) ) {
55
-			$this->upgrader->strings['process_success'] = sprintf(
56
-				$this->upgrader->strings['process_success_specific'],
57
-				$this->api->name,
58
-				$this->api->version
59
-			);
60
-		}
61
-	}
62
-
63
-	/**
64
-	 * Hides the `process_failed` error when updating a plugin by uploading a zip file.
65
-	 *
66
-	 * @since 5.5.0
67
-	 *
68
-	 * @param WP_Error $wp_error WP_Error object.
69
-	 * @return bool
70
-	 */
71
-	public function hide_process_failed( $wp_error ) {
72
-		if (
73
-			'upload' === $this->type &&
74
-			'' === $this->overwrite &&
75
-			$wp_error->get_error_code() === 'folder_exists'
76
-		) {
77
-			return true;
78
-		}
79
-
80
-		return false;
81
-	}
82
-
83
-	/**
84
-	 * Action to perform following a plugin install.
85
-	 *
86
-	 * @since 2.8.0
87
-	 */
88
-	public function after() {
89
-		// Check if the plugin can be overwritten and output the HTML.
90
-		if ( $this->do_overwrite() ) {
91
-			return;
92
-		}
93
-
94
-		$plugin_file = $this->upgrader->plugin_info();
95
-
96
-		$install_actions = array();
97
-
98
-		$from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'plugins';
99
-
100
-		if ( 'import' === $from ) {
101
-			$install_actions['activate_plugin'] = sprintf(
102
-				'<a class="button button-primary" href="%s" target="_parent">%s</a>',
103
-				wp_nonce_url( 'plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
104
-				__( 'Activate Plugin &amp; Run Importer' )
105
-			);
106
-		} elseif ( 'press-this' === $from ) {
107
-			$install_actions['activate_plugin'] = sprintf(
108
-				'<a class="button button-primary" href="%s" target="_parent">%s</a>',
109
-				wp_nonce_url( 'plugins.php?action=activate&amp;from=press-this&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
110
-				__( 'Activate Plugin &amp; Go to Press This' )
111
-			);
112
-		} else {
113
-			$install_actions['activate_plugin'] = sprintf(
114
-				'<a class="button button-primary" href="%s" target="_parent">%s</a>',
115
-				wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
116
-				__( 'Activate Plugin' )
117
-			);
118
-		}
119
-
120
-		if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
121
-			$install_actions['network_activate'] = sprintf(
122
-				'<a class="button button-primary" href="%s" target="_parent">%s</a>',
123
-				wp_nonce_url( 'plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
124
-				__( 'Network Activate' )
125
-			);
126
-			unset( $install_actions['activate_plugin'] );
127
-		}
128
-
129
-		if ( 'import' === $from ) {
130
-			$install_actions['importers_page'] = sprintf(
131
-				'<a href="%s" target="_parent">%s</a>',
132
-				admin_url( 'import.php' ),
133
-				__( 'Go to Importers' )
134
-			);
135
-		} elseif ( 'web' === $this->type ) {
136
-			$install_actions['plugins_page'] = sprintf(
137
-				'<a href="%s" target="_parent">%s</a>',
138
-				self_admin_url( 'plugin-install.php' ),
139
-				__( 'Go to Plugin Installer' )
140
-			);
141
-		} elseif ( 'upload' === $this->type && 'plugins' === $from ) {
142
-			$install_actions['plugins_page'] = sprintf(
143
-				'<a href="%s">%s</a>',
144
-				self_admin_url( 'plugin-install.php' ),
145
-				__( 'Go to Plugin Installer' )
146
-			);
147
-		} else {
148
-			$install_actions['plugins_page'] = sprintf(
149
-				'<a href="%s" target="_parent">%s</a>',
150
-				self_admin_url( 'plugins.php' ),
151
-				__( 'Go to Plugins page' )
152
-			);
153
-		}
154
-
155
-		if ( ! $this->result || is_wp_error( $this->result ) ) {
156
-			unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
157
-		} elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) || is_plugin_active( $plugin_file ) ) {
158
-			unset( $install_actions['activate_plugin'] );
159
-		}
160
-
161
-		/**
162
-		 * Filters the list of action links available following a single plugin installation.
163
-		 *
164
-		 * @since 2.7.0
165
-		 *
166
-		 * @param string[] $install_actions Array of plugin action links.
167
-		 * @param object   $api             Object containing WordPress.org API plugin data. Empty
168
-		 *                                  for non-API installs, such as when a plugin is installed
169
-		 *                                  via upload.
170
-		 * @param string   $plugin_file     Path to the plugin file relative to the plugins directory.
171
-		 */
172
-		$install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
173
-
174
-		if ( ! empty( $install_actions ) ) {
175
-			$this->feedback( implode( ' ', (array) $install_actions ) );
176
-		}
177
-	}
178
-
179
-	/**
180
-	 * Check if the plugin can be overwritten and output the HTML for overwriting a plugin on upload.
181
-	 *
182
-	 * @since 5.5.0
183
-	 *
184
-	 * @return bool Whether the plugin can be overwritten and HTML was outputted.
185
-	 */
186
-	private function do_overwrite() {
187
-		if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) {
188
-			return false;
189
-		}
190
-
191
-		$folder = $this->result->get_error_data( 'folder_exists' );
192
-		$folder = ltrim( substr( $folder, strlen( WP_PLUGIN_DIR ) ), '/' );
193
-
194
-		$current_plugin_data = false;
195
-		$all_plugins         = get_plugins();
196
-
197
-		foreach ( $all_plugins as $plugin => $plugin_data ) {
198
-			if ( strrpos( $plugin, $folder ) !== 0 ) {
199
-				continue;
200
-			}
201
-
202
-			$current_plugin_data = $plugin_data;
203
-		}
204
-
205
-		$new_plugin_data = $this->upgrader->new_plugin_data;
206
-
207
-		if ( ! $current_plugin_data || ! $new_plugin_data ) {
208
-			return false;
209
-		}
210
-
211
-		echo '<h2 class="update-from-upload-heading">' . esc_html__( 'This plugin is already installed.' ) . '</h2>';
212
-
213
-		$this->is_downgrading = version_compare( $current_plugin_data['Version'], $new_plugin_data['Version'], '>' );
214
-
215
-		$rows = array(
216
-			'Name'        => __( 'Plugin name' ),
217
-			'Version'     => __( 'Version' ),
218
-			'Author'      => __( 'Author' ),
219
-			'RequiresWP'  => __( 'Required WordPress version' ),
220
-			'RequiresPHP' => __( 'Required PHP version' ),
221
-		);
222
-
223
-		$table  = '<table class="update-from-upload-comparison"><tbody>';
224
-		$table .= '<tr><th></th><th>' . esc_html_x( 'Current', 'plugin' ) . '</th>';
225
-		$table .= '<th>' . esc_html_x( 'Uploaded', 'plugin' ) . '</th></tr>';
226
-
227
-		$is_same_plugin = true; // Let's consider only these rows.
228
-
229
-		foreach ( $rows as $field => $label ) {
230
-			$old_value = ! empty( $current_plugin_data[ $field ] ) ? (string) $current_plugin_data[ $field ] : '-';
231
-			$new_value = ! empty( $new_plugin_data[ $field ] ) ? (string) $new_plugin_data[ $field ] : '-';
232
-
233
-			$is_same_plugin = $is_same_plugin && ( $old_value === $new_value );
234
-
235
-			$diff_field   = ( 'Version' !== $field && $new_value !== $old_value );
236
-			$diff_version = ( 'Version' === $field && $this->is_downgrading );
237
-
238
-			$table .= '<tr><td class="name-label">' . $label . '</td><td>' . wp_strip_all_tags( $old_value ) . '</td>';
239
-			$table .= ( $diff_field || $diff_version ) ? '<td class="warning">' : '<td>';
240
-			$table .= wp_strip_all_tags( $new_value ) . '</td></tr>';
241
-		}
242
-
243
-		$table .= '</tbody></table>';
244
-
245
-		/**
246
-		 * Filters the compare table output for overwriting a plugin package on upload.
247
-		 *
248
-		 * @since 5.5.0
249
-		 *
250
-		 * @param string $table               The output table with Name, Version, Author, RequiresWP, and RequiresPHP info.
251
-		 * @param array  $current_plugin_data Array with current plugin data.
252
-		 * @param array  $new_plugin_data     Array with uploaded plugin data.
253
-		 */
254
-		echo apply_filters( 'install_plugin_overwrite_comparison', $table, $current_plugin_data, $new_plugin_data );
255
-
256
-		$install_actions = array();
257
-		$can_update      = true;
258
-
259
-		$blocked_message  = '<p>' . esc_html__( 'The plugin cannot be updated due to the following:' ) . '</p>';
260
-		$blocked_message .= '<ul class="ul-disc">';
261
-
262
-		$requires_php = isset( $new_plugin_data['RequiresPHP'] ) ? $new_plugin_data['RequiresPHP'] : null;
263
-		$requires_wp  = isset( $new_plugin_data['RequiresWP'] ) ? $new_plugin_data['RequiresWP'] : null;
264
-
265
-		if ( ! is_php_version_compatible( $requires_php ) ) {
266
-			$error = sprintf(
267
-				/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
268
-				__( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
269
-				phpversion(),
270
-				$requires_php
271
-			);
272
-
273
-			$blocked_message .= '<li>' . esc_html( $error ) . '</li>';
274
-			$can_update       = false;
275
-		}
276
-
277
-		if ( ! is_wp_version_compatible( $requires_wp ) ) {
278
-			$error = sprintf(
279
-				/* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
280
-				__( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
281
-				get_bloginfo( 'version' ),
282
-				$requires_wp
283
-			);
284
-
285
-			$blocked_message .= '<li>' . esc_html( $error ) . '</li>';
286
-			$can_update       = false;
287
-		}
288
-
289
-		$blocked_message .= '</ul>';
290
-
291
-		if ( $can_update ) {
292
-			if ( $this->is_downgrading ) {
293
-				$warning = sprintf(
294
-					/* translators: %s: Documentation URL. */
295
-					__( 'You are uploading an older version of a current plugin. You can continue to install the older version, but be sure to <a href="%s">back up your database and files</a> first.' ),
296
-					__( 'https://wordpress.org/support/article/wordpress-backups/' )
297
-				);
298
-			} else {
299
-				$warning = sprintf(
300
-					/* translators: %s: Documentation URL. */
301
-					__( 'You are updating a plugin. Be sure to <a href="%s">back up your database and files</a> first.' ),
302
-					__( 'https://wordpress.org/support/article/wordpress-backups/' )
303
-				);
304
-			}
305
-
306
-			echo '<p class="update-from-upload-notice">' . $warning . '</p>';
307
-
308
-			$overwrite = $this->is_downgrading ? 'downgrade-plugin' : 'update-plugin';
309
-
310
-			$install_actions['overwrite_plugin'] = sprintf(
311
-				'<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>',
312
-				wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'plugin-upload' ),
313
-				_x( 'Replace current with uploaded', 'plugin' )
314
-			);
315
-		} else {
316
-			echo $blocked_message;
317
-		}
318
-
319
-		$cancel_url = add_query_arg( 'action', 'upload-plugin-cancel-overwrite', $this->url );
320
-
321
-		$install_actions['plugins_page'] = sprintf(
322
-			'<a class="button" href="%s">%s</a>',
323
-			wp_nonce_url( $cancel_url, 'plugin-upload-cancel-overwrite' ),
324
-			__( 'Cancel and go back' )
325
-		);
326
-
327
-		/**
328
-		 * Filters the list of action links available following a single plugin installation failure
329
-		 * when overwriting is allowed.
330
-		 *
331
-		 * @since 5.5.0
332
-		 *
333
-		 * @param string[] $install_actions Array of plugin action links.
334
-		 * @param object   $api             Object containing WordPress.org API plugin data.
335
-		 * @param array    $new_plugin_data Array with uploaded plugin data.
336
-		 */
337
-		$install_actions = apply_filters( 'install_plugin_overwrite_actions', $install_actions, $this->api, $new_plugin_data );
338
-
339
-		if ( ! empty( $install_actions ) ) {
340
-			printf(
341
-				'<p class="update-from-upload-expired hidden">%s</p>',
342
-				__( 'The uploaded file has expired. Please go back and upload it again.' )
343
-			);
344
-			echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>';
345
-		}
346
-
347
-		return true;
348
-	}
19
+    public $api;
20
+    public $type;
21
+    public $url;
22
+    public $overwrite;
23
+
24
+    private $is_downgrading = false;
25
+
26
+    /**
27
+     * @param array $args
28
+     */
29
+    public function __construct( $args = array() ) {
30
+        $defaults = array(
31
+            'type'      => 'web',
32
+            'url'       => '',
33
+            'plugin'    => '',
34
+            'nonce'     => '',
35
+            'title'     => '',
36
+            'overwrite' => '',
37
+        );
38
+        $args     = wp_parse_args( $args, $defaults );
39
+
40
+        $this->type      = $args['type'];
41
+        $this->url       = $args['url'];
42
+        $this->api       = isset( $args['api'] ) ? $args['api'] : array();
43
+        $this->overwrite = $args['overwrite'];
44
+
45
+        parent::__construct( $args );
46
+    }
47
+
48
+    /**
49
+     * Action to perform before installing a plugin.
50
+     *
51
+     * @since 2.8.0
52
+     */
53
+    public function before() {
54
+        if ( ! empty( $this->api ) ) {
55
+            $this->upgrader->strings['process_success'] = sprintf(
56
+                $this->upgrader->strings['process_success_specific'],
57
+                $this->api->name,
58
+                $this->api->version
59
+            );
60
+        }
61
+    }
62
+
63
+    /**
64
+     * Hides the `process_failed` error when updating a plugin by uploading a zip file.
65
+     *
66
+     * @since 5.5.0
67
+     *
68
+     * @param WP_Error $wp_error WP_Error object.
69
+     * @return bool
70
+     */
71
+    public function hide_process_failed( $wp_error ) {
72
+        if (
73
+            'upload' === $this->type &&
74
+            '' === $this->overwrite &&
75
+            $wp_error->get_error_code() === 'folder_exists'
76
+        ) {
77
+            return true;
78
+        }
79
+
80
+        return false;
81
+    }
82
+
83
+    /**
84
+     * Action to perform following a plugin install.
85
+     *
86
+     * @since 2.8.0
87
+     */
88
+    public function after() {
89
+        // Check if the plugin can be overwritten and output the HTML.
90
+        if ( $this->do_overwrite() ) {
91
+            return;
92
+        }
93
+
94
+        $plugin_file = $this->upgrader->plugin_info();
95
+
96
+        $install_actions = array();
97
+
98
+        $from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'plugins';
99
+
100
+        if ( 'import' === $from ) {
101
+            $install_actions['activate_plugin'] = sprintf(
102
+                '<a class="button button-primary" href="%s" target="_parent">%s</a>',
103
+                wp_nonce_url( 'plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
104
+                __( 'Activate Plugin &amp; Run Importer' )
105
+            );
106
+        } elseif ( 'press-this' === $from ) {
107
+            $install_actions['activate_plugin'] = sprintf(
108
+                '<a class="button button-primary" href="%s" target="_parent">%s</a>',
109
+                wp_nonce_url( 'plugins.php?action=activate&amp;from=press-this&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
110
+                __( 'Activate Plugin &amp; Go to Press This' )
111
+            );
112
+        } else {
113
+            $install_actions['activate_plugin'] = sprintf(
114
+                '<a class="button button-primary" href="%s" target="_parent">%s</a>',
115
+                wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
116
+                __( 'Activate Plugin' )
117
+            );
118
+        }
119
+
120
+        if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
121
+            $install_actions['network_activate'] = sprintf(
122
+                '<a class="button button-primary" href="%s" target="_parent">%s</a>',
123
+                wp_nonce_url( 'plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
124
+                __( 'Network Activate' )
125
+            );
126
+            unset( $install_actions['activate_plugin'] );
127
+        }
128
+
129
+        if ( 'import' === $from ) {
130
+            $install_actions['importers_page'] = sprintf(
131
+                '<a href="%s" target="_parent">%s</a>',
132
+                admin_url( 'import.php' ),
133
+                __( 'Go to Importers' )
134
+            );
135
+        } elseif ( 'web' === $this->type ) {
136
+            $install_actions['plugins_page'] = sprintf(
137
+                '<a href="%s" target="_parent">%s</a>',
138
+                self_admin_url( 'plugin-install.php' ),
139
+                __( 'Go to Plugin Installer' )
140
+            );
141
+        } elseif ( 'upload' === $this->type && 'plugins' === $from ) {
142
+            $install_actions['plugins_page'] = sprintf(
143
+                '<a href="%s">%s</a>',
144
+                self_admin_url( 'plugin-install.php' ),
145
+                __( 'Go to Plugin Installer' )
146
+            );
147
+        } else {
148
+            $install_actions['plugins_page'] = sprintf(
149
+                '<a href="%s" target="_parent">%s</a>',
150
+                self_admin_url( 'plugins.php' ),
151
+                __( 'Go to Plugins page' )
152
+            );
153
+        }
154
+
155
+        if ( ! $this->result || is_wp_error( $this->result ) ) {
156
+            unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
157
+        } elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) || is_plugin_active( $plugin_file ) ) {
158
+            unset( $install_actions['activate_plugin'] );
159
+        }
160
+
161
+        /**
162
+         * Filters the list of action links available following a single plugin installation.
163
+         *
164
+         * @since 2.7.0
165
+         *
166
+         * @param string[] $install_actions Array of plugin action links.
167
+         * @param object   $api             Object containing WordPress.org API plugin data. Empty
168
+         *                                  for non-API installs, such as when a plugin is installed
169
+         *                                  via upload.
170
+         * @param string   $plugin_file     Path to the plugin file relative to the plugins directory.
171
+         */
172
+        $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
173
+
174
+        if ( ! empty( $install_actions ) ) {
175
+            $this->feedback( implode( ' ', (array) $install_actions ) );
176
+        }
177
+    }
178
+
179
+    /**
180
+     * Check if the plugin can be overwritten and output the HTML for overwriting a plugin on upload.
181
+     *
182
+     * @since 5.5.0
183
+     *
184
+     * @return bool Whether the plugin can be overwritten and HTML was outputted.
185
+     */
186
+    private function do_overwrite() {
187
+        if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) {
188
+            return false;
189
+        }
190
+
191
+        $folder = $this->result->get_error_data( 'folder_exists' );
192
+        $folder = ltrim( substr( $folder, strlen( WP_PLUGIN_DIR ) ), '/' );
193
+
194
+        $current_plugin_data = false;
195
+        $all_plugins         = get_plugins();
196
+
197
+        foreach ( $all_plugins as $plugin => $plugin_data ) {
198
+            if ( strrpos( $plugin, $folder ) !== 0 ) {
199
+                continue;
200
+            }
201
+
202
+            $current_plugin_data = $plugin_data;
203
+        }
204
+
205
+        $new_plugin_data = $this->upgrader->new_plugin_data;
206
+
207
+        if ( ! $current_plugin_data || ! $new_plugin_data ) {
208
+            return false;
209
+        }
210
+
211
+        echo '<h2 class="update-from-upload-heading">' . esc_html__( 'This plugin is already installed.' ) . '</h2>';
212
+
213
+        $this->is_downgrading = version_compare( $current_plugin_data['Version'], $new_plugin_data['Version'], '>' );
214
+
215
+        $rows = array(
216
+            'Name'        => __( 'Plugin name' ),
217
+            'Version'     => __( 'Version' ),
218
+            'Author'      => __( 'Author' ),
219
+            'RequiresWP'  => __( 'Required WordPress version' ),
220
+            'RequiresPHP' => __( 'Required PHP version' ),
221
+        );
222
+
223
+        $table  = '<table class="update-from-upload-comparison"><tbody>';
224
+        $table .= '<tr><th></th><th>' . esc_html_x( 'Current', 'plugin' ) . '</th>';
225
+        $table .= '<th>' . esc_html_x( 'Uploaded', 'plugin' ) . '</th></tr>';
226
+
227
+        $is_same_plugin = true; // Let's consider only these rows.
228
+
229
+        foreach ( $rows as $field => $label ) {
230
+            $old_value = ! empty( $current_plugin_data[ $field ] ) ? (string) $current_plugin_data[ $field ] : '-';
231
+            $new_value = ! empty( $new_plugin_data[ $field ] ) ? (string) $new_plugin_data[ $field ] : '-';
232
+
233
+            $is_same_plugin = $is_same_plugin && ( $old_value === $new_value );
234
+
235
+            $diff_field   = ( 'Version' !== $field && $new_value !== $old_value );
236
+            $diff_version = ( 'Version' === $field && $this->is_downgrading );
237
+
238
+            $table .= '<tr><td class="name-label">' . $label . '</td><td>' . wp_strip_all_tags( $old_value ) . '</td>';
239
+            $table .= ( $diff_field || $diff_version ) ? '<td class="warning">' : '<td>';
240
+            $table .= wp_strip_all_tags( $new_value ) . '</td></tr>';
241
+        }
242
+
243
+        $table .= '</tbody></table>';
244
+
245
+        /**
246
+         * Filters the compare table output for overwriting a plugin package on upload.
247
+         *
248
+         * @since 5.5.0
249
+         *
250
+         * @param string $table               The output table with Name, Version, Author, RequiresWP, and RequiresPHP info.
251
+         * @param array  $current_plugin_data Array with current plugin data.
252
+         * @param array  $new_plugin_data     Array with uploaded plugin data.
253
+         */
254
+        echo apply_filters( 'install_plugin_overwrite_comparison', $table, $current_plugin_data, $new_plugin_data );
255
+
256
+        $install_actions = array();
257
+        $can_update      = true;
258
+
259
+        $blocked_message  = '<p>' . esc_html__( 'The plugin cannot be updated due to the following:' ) . '</p>';
260
+        $blocked_message .= '<ul class="ul-disc">';
261
+
262
+        $requires_php = isset( $new_plugin_data['RequiresPHP'] ) ? $new_plugin_data['RequiresPHP'] : null;
263
+        $requires_wp  = isset( $new_plugin_data['RequiresWP'] ) ? $new_plugin_data['RequiresWP'] : null;
264
+
265
+        if ( ! is_php_version_compatible( $requires_php ) ) {
266
+            $error = sprintf(
267
+                /* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
268
+                __( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
269
+                phpversion(),
270
+                $requires_php
271
+            );
272
+
273
+            $blocked_message .= '<li>' . esc_html( $error ) . '</li>';
274
+            $can_update       = false;
275
+        }
276
+
277
+        if ( ! is_wp_version_compatible( $requires_wp ) ) {
278
+            $error = sprintf(
279
+                /* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
280
+                __( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
281
+                get_bloginfo( 'version' ),
282
+                $requires_wp
283
+            );
284
+
285
+            $blocked_message .= '<li>' . esc_html( $error ) . '</li>';
286
+            $can_update       = false;
287
+        }
288
+
289
+        $blocked_message .= '</ul>';
290
+
291
+        if ( $can_update ) {
292
+            if ( $this->is_downgrading ) {
293
+                $warning = sprintf(
294
+                    /* translators: %s: Documentation URL. */
295
+                    __( 'You are uploading an older version of a current plugin. You can continue to install the older version, but be sure to <a href="%s">back up your database and files</a> first.' ),
296
+                    __( 'https://wordpress.org/support/article/wordpress-backups/' )
297
+                );
298
+            } else {
299
+                $warning = sprintf(
300
+                    /* translators: %s: Documentation URL. */
301
+                    __( 'You are updating a plugin. Be sure to <a href="%s">back up your database and files</a> first.' ),
302
+                    __( 'https://wordpress.org/support/article/wordpress-backups/' )
303
+                );
304
+            }
305
+
306
+            echo '<p class="update-from-upload-notice">' . $warning . '</p>';
307
+
308
+            $overwrite = $this->is_downgrading ? 'downgrade-plugin' : 'update-plugin';
309
+
310
+            $install_actions['overwrite_plugin'] = sprintf(
311
+                '<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>',
312
+                wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'plugin-upload' ),
313
+                _x( 'Replace current with uploaded', 'plugin' )
314
+            );
315
+        } else {
316
+            echo $blocked_message;
317
+        }
318
+
319
+        $cancel_url = add_query_arg( 'action', 'upload-plugin-cancel-overwrite', $this->url );
320
+
321
+        $install_actions['plugins_page'] = sprintf(
322
+            '<a class="button" href="%s">%s</a>',
323
+            wp_nonce_url( $cancel_url, 'plugin-upload-cancel-overwrite' ),
324
+            __( 'Cancel and go back' )
325
+        );
326
+
327
+        /**
328
+         * Filters the list of action links available following a single plugin installation failure
329
+         * when overwriting is allowed.
330
+         *
331
+         * @since 5.5.0
332
+         *
333
+         * @param string[] $install_actions Array of plugin action links.
334
+         * @param object   $api             Object containing WordPress.org API plugin data.
335
+         * @param array    $new_plugin_data Array with uploaded plugin data.
336
+         */
337
+        $install_actions = apply_filters( 'install_plugin_overwrite_actions', $install_actions, $this->api, $new_plugin_data );
338
+
339
+        if ( ! empty( $install_actions ) ) {
340
+            printf(
341
+                '<p class="update-from-upload-expired hidden">%s</p>',
342
+                __( 'The uploaded file has expired. Please go back and upload it again.' )
343
+            );
344
+            echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>';
345
+        }
346
+
347
+        return true;
348
+    }
349 349
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/translation-install.php 1 patch
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -17,96 +17,96 @@  discard block
 block discarded – undo
17 17
  * @return array|WP_Error On success an associative array of translations, WP_Error on failure.
18 18
  */
19 19
 function translations_api( $type, $args = null ) {
20
-	// Include an unmodified $wp_version.
21
-	require ABSPATH . WPINC . '/version.php';
22
-
23
-	if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ), true ) ) {
24
-		return new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) );
25
-	}
26
-
27
-	/**
28
-	 * Allows a plugin to override the WordPress.org Translation Installation API entirely.
29
-	 *
30
-	 * @since 4.0.0
31
-	 *
32
-	 * @param false|array $result The result array. Default false.
33
-	 * @param string      $type   The type of translations being requested.
34
-	 * @param object      $args   Translation API arguments.
35
-	 */
36
-	$res = apply_filters( 'translations_api', false, $type, $args );
37
-
38
-	if ( false === $res ) {
39
-		$url      = 'http://api.wordpress.org/translations/' . $type . '/1.0/';
40
-		$http_url = $url;
41
-		$ssl      = wp_http_supports( array( 'ssl' ) );
42
-		if ( $ssl ) {
43
-			$url = set_url_scheme( $url, 'https' );
44
-		}
45
-
46
-		$options = array(
47
-			'timeout' => 3,
48
-			'body'    => array(
49
-				'wp_version' => $wp_version,
50
-				'locale'     => get_locale(),
51
-				'version'    => $args['version'], // Version of plugin, theme or core.
52
-			),
53
-		);
54
-
55
-		if ( 'core' !== $type ) {
56
-			$options['body']['slug'] = $args['slug']; // Plugin or theme slug.
57
-		}
58
-
59
-		$request = wp_remote_post( $url, $options );
60
-
61
-		if ( $ssl && is_wp_error( $request ) ) {
62
-			trigger_error(
63
-				sprintf(
64
-					/* translators: %s: Support forums URL. */
65
-					__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
66
-					__( 'https://wordpress.org/support/forums/' )
67
-				) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
68
-				headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
69
-			);
70
-
71
-			$request = wp_remote_post( $http_url, $options );
72
-		}
73
-
74
-		if ( is_wp_error( $request ) ) {
75
-			$res = new WP_Error(
76
-				'translations_api_failed',
77
-				sprintf(
78
-					/* translators: %s: Support forums URL. */
79
-					__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
80
-					__( 'https://wordpress.org/support/forums/' )
81
-				),
82
-				$request->get_error_message()
83
-			);
84
-		} else {
85
-			$res = json_decode( wp_remote_retrieve_body( $request ), true );
86
-			if ( ! is_object( $res ) && ! is_array( $res ) ) {
87
-				$res = new WP_Error(
88
-					'translations_api_failed',
89
-					sprintf(
90
-						/* translators: %s: Support forums URL. */
91
-						__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
92
-						__( 'https://wordpress.org/support/forums/' )
93
-					),
94
-					wp_remote_retrieve_body( $request )
95
-				);
96
-			}
97
-		}
98
-	}
99
-
100
-	/**
101
-	 * Filters the Translation Installation API response results.
102
-	 *
103
-	 * @since 4.0.0
104
-	 *
105
-	 * @param array|WP_Error $res  Response as an associative array or WP_Error.
106
-	 * @param string         $type The type of translations being requested.
107
-	 * @param object         $args Translation API arguments.
108
-	 */
109
-	return apply_filters( 'translations_api_result', $res, $type, $args );
20
+    // Include an unmodified $wp_version.
21
+    require ABSPATH . WPINC . '/version.php';
22
+
23
+    if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ), true ) ) {
24
+        return new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) );
25
+    }
26
+
27
+    /**
28
+     * Allows a plugin to override the WordPress.org Translation Installation API entirely.
29
+     *
30
+     * @since 4.0.0
31
+     *
32
+     * @param false|array $result The result array. Default false.
33
+     * @param string      $type   The type of translations being requested.
34
+     * @param object      $args   Translation API arguments.
35
+     */
36
+    $res = apply_filters( 'translations_api', false, $type, $args );
37
+
38
+    if ( false === $res ) {
39
+        $url      = 'http://api.wordpress.org/translations/' . $type . '/1.0/';
40
+        $http_url = $url;
41
+        $ssl      = wp_http_supports( array( 'ssl' ) );
42
+        if ( $ssl ) {
43
+            $url = set_url_scheme( $url, 'https' );
44
+        }
45
+
46
+        $options = array(
47
+            'timeout' => 3,
48
+            'body'    => array(
49
+                'wp_version' => $wp_version,
50
+                'locale'     => get_locale(),
51
+                'version'    => $args['version'], // Version of plugin, theme or core.
52
+            ),
53
+        );
54
+
55
+        if ( 'core' !== $type ) {
56
+            $options['body']['slug'] = $args['slug']; // Plugin or theme slug.
57
+        }
58
+
59
+        $request = wp_remote_post( $url, $options );
60
+
61
+        if ( $ssl && is_wp_error( $request ) ) {
62
+            trigger_error(
63
+                sprintf(
64
+                    /* translators: %s: Support forums URL. */
65
+                    __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
66
+                    __( 'https://wordpress.org/support/forums/' )
67
+                ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
68
+                headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
69
+            );
70
+
71
+            $request = wp_remote_post( $http_url, $options );
72
+        }
73
+
74
+        if ( is_wp_error( $request ) ) {
75
+            $res = new WP_Error(
76
+                'translations_api_failed',
77
+                sprintf(
78
+                    /* translators: %s: Support forums URL. */
79
+                    __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
80
+                    __( 'https://wordpress.org/support/forums/' )
81
+                ),
82
+                $request->get_error_message()
83
+            );
84
+        } else {
85
+            $res = json_decode( wp_remote_retrieve_body( $request ), true );
86
+            if ( ! is_object( $res ) && ! is_array( $res ) ) {
87
+                $res = new WP_Error(
88
+                    'translations_api_failed',
89
+                    sprintf(
90
+                        /* translators: %s: Support forums URL. */
91
+                        __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
92
+                        __( 'https://wordpress.org/support/forums/' )
93
+                    ),
94
+                    wp_remote_retrieve_body( $request )
95
+                );
96
+            }
97
+        }
98
+    }
99
+
100
+    /**
101
+     * Filters the Translation Installation API response results.
102
+     *
103
+     * @since 4.0.0
104
+     *
105
+     * @param array|WP_Error $res  Response as an associative array or WP_Error.
106
+     * @param string         $type The type of translations being requested.
107
+     * @param object         $args Translation API arguments.
108
+     */
109
+    return apply_filters( 'translations_api_result', $res, $type, $args );
110 110
 }
111 111
 
112 112
 /**
@@ -120,33 +120,33 @@  discard block
 block discarded – undo
120 120
  *                 in an error, an empty array will be returned.
121 121
  */
122 122
 function wp_get_available_translations() {
123
-	if ( ! wp_installing() ) {
124
-		$translations = get_site_transient( 'available_translations' );
125
-		if ( false !== $translations ) {
126
-			return $translations;
127
-		}
128
-	}
123
+    if ( ! wp_installing() ) {
124
+        $translations = get_site_transient( 'available_translations' );
125
+        if ( false !== $translations ) {
126
+            return $translations;
127
+        }
128
+    }
129 129
 
130
-	// Include an unmodified $wp_version.
131
-	require ABSPATH . WPINC . '/version.php';
130
+    // Include an unmodified $wp_version.
131
+    require ABSPATH . WPINC . '/version.php';
132 132
 
133
-	$api = translations_api( 'core', array( 'version' => $wp_version ) );
133
+    $api = translations_api( 'core', array( 'version' => $wp_version ) );
134 134
 
135
-	if ( is_wp_error( $api ) || empty( $api['translations'] ) ) {
136
-		return array();
137
-	}
135
+    if ( is_wp_error( $api ) || empty( $api['translations'] ) ) {
136
+        return array();
137
+    }
138 138
 
139
-	$translations = array();
140
-	// Key the array with the language code for now.
141
-	foreach ( $api['translations'] as $translation ) {
142
-		$translations[ $translation['language'] ] = $translation;
143
-	}
139
+    $translations = array();
140
+    // Key the array with the language code for now.
141
+    foreach ( $api['translations'] as $translation ) {
142
+        $translations[ $translation['language'] ] = $translation;
143
+    }
144 144
 
145
-	if ( ! defined( 'WP_INSTALLING' ) ) {
146
-		set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS );
147
-	}
145
+    if ( ! defined( 'WP_INSTALLING' ) ) {
146
+        set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS );
147
+    }
148 148
 
149
-	return $translations;
149
+    return $translations;
150 150
 }
151 151
 
152 152
 /**
@@ -159,43 +159,43 @@  discard block
 block discarded – undo
159 159
  * @param array[] $languages Array of available languages (populated via the Translation API).
160 160
  */
161 161
 function wp_install_language_form( $languages ) {
162
-	global $wp_local_package;
163
-
164
-	$installed_languages = get_available_languages();
165
-
166
-	echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n";
167
-	echo "<select size='14' name='language' id='language'>\n";
168
-	echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>';
169
-	echo "\n";
170
-
171
-	if ( ! empty( $wp_local_package ) && isset( $languages[ $wp_local_package ] ) ) {
172
-		if ( isset( $languages[ $wp_local_package ] ) ) {
173
-			$language = $languages[ $wp_local_package ];
174
-			printf(
175
-				'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
176
-				esc_attr( $language['language'] ),
177
-				esc_attr( current( $language['iso'] ) ),
178
-				esc_attr( $language['strings']['continue'] ? $language['strings']['continue'] : 'Continue' ),
179
-				in_array( $language['language'], $installed_languages, true ) ? ' data-installed="1"' : '',
180
-				esc_html( $language['native_name'] )
181
-			);
182
-
183
-			unset( $languages[ $wp_local_package ] );
184
-		}
185
-	}
186
-
187
-	foreach ( $languages as $language ) {
188
-		printf(
189
-			'<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
190
-			esc_attr( $language['language'] ),
191
-			esc_attr( current( $language['iso'] ) ),
192
-			esc_attr( $language['strings']['continue'] ? $language['strings']['continue'] : 'Continue' ),
193
-			in_array( $language['language'], $installed_languages, true ) ? ' data-installed="1"' : '',
194
-			esc_html( $language['native_name'] )
195
-		);
196
-	}
197
-	echo "</select>\n";
198
-	echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';
162
+    global $wp_local_package;
163
+
164
+    $installed_languages = get_available_languages();
165
+
166
+    echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n";
167
+    echo "<select size='14' name='language' id='language'>\n";
168
+    echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>';
169
+    echo "\n";
170
+
171
+    if ( ! empty( $wp_local_package ) && isset( $languages[ $wp_local_package ] ) ) {
172
+        if ( isset( $languages[ $wp_local_package ] ) ) {
173
+            $language = $languages[ $wp_local_package ];
174
+            printf(
175
+                '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
176
+                esc_attr( $language['language'] ),
177
+                esc_attr( current( $language['iso'] ) ),
178
+                esc_attr( $language['strings']['continue'] ? $language['strings']['continue'] : 'Continue' ),
179
+                in_array( $language['language'], $installed_languages, true ) ? ' data-installed="1"' : '',
180
+                esc_html( $language['native_name'] )
181
+            );
182
+
183
+            unset( $languages[ $wp_local_package ] );
184
+        }
185
+    }
186
+
187
+    foreach ( $languages as $language ) {
188
+        printf(
189
+            '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
190
+            esc_attr( $language['language'] ),
191
+            esc_attr( current( $language['iso'] ) ),
192
+            esc_attr( $language['strings']['continue'] ? $language['strings']['continue'] : 'Continue' ),
193
+            in_array( $language['language'], $installed_languages, true ) ? ' data-installed="1"' : '',
194
+            esc_html( $language['native_name'] )
195
+        );
196
+    }
197
+    echo "</select>\n";
198
+    echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';
199 199
 }
200 200
 
201 201
 /**
@@ -210,43 +210,43 @@  discard block
 block discarded – undo
210 210
  *                      (or already installed), or false on failure.
211 211
  */
212 212
 function wp_download_language_pack( $download ) {
213
-	// Check if the translation is already installed.
214
-	if ( in_array( $download, get_available_languages(), true ) ) {
215
-		return $download;
216
-	}
217
-
218
-	if ( ! wp_is_file_mod_allowed( 'download_language_pack' ) ) {
219
-		return false;
220
-	}
221
-
222
-	// Confirm the translation is one we can download.
223
-	$translations = wp_get_available_translations();
224
-	if ( ! $translations ) {
225
-		return false;
226
-	}
227
-	foreach ( $translations as $translation ) {
228
-		if ( $translation['language'] === $download ) {
229
-			$translation_to_load = true;
230
-			break;
231
-		}
232
-	}
233
-
234
-	if ( empty( $translation_to_load ) ) {
235
-		return false;
236
-	}
237
-	$translation = (object) $translation;
238
-
239
-	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
240
-	$skin              = new Automatic_Upgrader_Skin;
241
-	$upgrader          = new Language_Pack_Upgrader( $skin );
242
-	$translation->type = 'core';
243
-	$result            = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
244
-
245
-	if ( ! $result || is_wp_error( $result ) ) {
246
-		return false;
247
-	}
248
-
249
-	return $translation->language;
213
+    // Check if the translation is already installed.
214
+    if ( in_array( $download, get_available_languages(), true ) ) {
215
+        return $download;
216
+    }
217
+
218
+    if ( ! wp_is_file_mod_allowed( 'download_language_pack' ) ) {
219
+        return false;
220
+    }
221
+
222
+    // Confirm the translation is one we can download.
223
+    $translations = wp_get_available_translations();
224
+    if ( ! $translations ) {
225
+        return false;
226
+    }
227
+    foreach ( $translations as $translation ) {
228
+        if ( $translation['language'] === $download ) {
229
+            $translation_to_load = true;
230
+            break;
231
+        }
232
+    }
233
+
234
+    if ( empty( $translation_to_load ) ) {
235
+        return false;
236
+    }
237
+    $translation = (object) $translation;
238
+
239
+    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
240
+    $skin              = new Automatic_Upgrader_Skin;
241
+    $upgrader          = new Language_Pack_Upgrader( $skin );
242
+    $translation->type = 'core';
243
+    $result            = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
244
+
245
+    if ( ! $result || is_wp_error( $result ) ) {
246
+        return false;
247
+    }
248
+
249
+    return $translation->language;
250 250
 }
251 251
 
252 252
 /**
@@ -258,20 +258,20 @@  discard block
 block discarded – undo
258 258
  * @return bool Returns true on success, false on failure.
259 259
  */
260 260
 function wp_can_install_language_pack() {
261
-	if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) {
262
-		return false;
263
-	}
261
+    if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) {
262
+        return false;
263
+    }
264 264
 
265
-	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
266
-	$skin     = new Automatic_Upgrader_Skin;
267
-	$upgrader = new Language_Pack_Upgrader( $skin );
268
-	$upgrader->init();
265
+    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
266
+    $skin     = new Automatic_Upgrader_Skin;
267
+    $upgrader = new Language_Pack_Upgrader( $skin );
268
+    $upgrader->init();
269 269
 
270
-	$check = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );
270
+    $check = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );
271 271
 
272
-	if ( ! $check || is_wp_error( $check ) ) {
273
-		return false;
274
-	}
272
+    if ( ! $check || is_wp_error( $check ) ) {
273
+        return false;
274
+    }
275 275
 
276
-	return true;
276
+    return true;
277 277
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/theme.php 1 patch
Indentation   +797 added lines, -797 removed lines patch added patch discarded remove patch
@@ -19,116 +19,116 @@  discard block
 block discarded – undo
19 19
  *                            Null if filesystem credentials are required to proceed.
20 20
  */
21 21
 function delete_theme( $stylesheet, $redirect = '' ) {
22
-	global $wp_filesystem;
23
-
24
-	if ( empty( $stylesheet ) ) {
25
-		return false;
26
-	}
27
-
28
-	if ( empty( $redirect ) ) {
29
-		$redirect = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );
30
-	}
31
-
32
-	ob_start();
33
-	$credentials = request_filesystem_credentials( $redirect );
34
-	$data        = ob_get_clean();
35
-
36
-	if ( false === $credentials ) {
37
-		if ( ! empty( $data ) ) {
38
-			require_once ABSPATH . 'wp-admin/admin-header.php';
39
-			echo $data;
40
-			require_once ABSPATH . 'wp-admin/admin-footer.php';
41
-			exit;
42
-		}
43
-		return;
44
-	}
45
-
46
-	if ( ! WP_Filesystem( $credentials ) ) {
47
-		ob_start();
48
-		// Failed to connect. Error and request again.
49
-		request_filesystem_credentials( $redirect, '', true );
50
-		$data = ob_get_clean();
51
-
52
-		if ( ! empty( $data ) ) {
53
-			require_once ABSPATH . 'wp-admin/admin-header.php';
54
-			echo $data;
55
-			require_once ABSPATH . 'wp-admin/admin-footer.php';
56
-			exit;
57
-		}
58
-		return;
59
-	}
60
-
61
-	if ( ! is_object( $wp_filesystem ) ) {
62
-		return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
63
-	}
64
-
65
-	if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
66
-		return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors );
67
-	}
68
-
69
-	// Get the base plugin folder.
70
-	$themes_dir = $wp_filesystem->wp_themes_dir();
71
-	if ( empty( $themes_dir ) ) {
72
-		return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
73
-	}
74
-
75
-	/**
76
-	 * Fires immediately before a theme deletion attempt.
77
-	 *
78
-	 * @since 5.8.0
79
-	 *
80
-	 * @param string $stylesheet Stylesheet of the theme to delete.
81
-	 */
82
-	do_action( 'delete_theme', $stylesheet );
83
-
84
-	$themes_dir = trailingslashit( $themes_dir );
85
-	$theme_dir  = trailingslashit( $themes_dir . $stylesheet );
86
-	$deleted    = $wp_filesystem->delete( $theme_dir, true );
87
-
88
-	/**
89
-	 * Fires immediately after a theme deletion attempt.
90
-	 *
91
-	 * @since 5.8.0
92
-	 *
93
-	 * @param string $stylesheet Stylesheet of the theme to delete.
94
-	 * @param bool   $deleted    Whether the theme deletion was successful.
95
-	 */
96
-	do_action( 'deleted_theme', $stylesheet, $deleted );
97
-
98
-	if ( ! $deleted ) {
99
-		return new WP_Error(
100
-			'could_not_remove_theme',
101
-			/* translators: %s: Theme name. */
102
-			sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet )
103
-		);
104
-	}
105
-
106
-	$theme_translations = wp_get_installed_translations( 'themes' );
107
-
108
-	// Remove language files, silently.
109
-	if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
110
-		$translations = $theme_translations[ $stylesheet ];
111
-
112
-		foreach ( $translations as $translation => $data ) {
113
-			$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
114
-			$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
115
-
116
-			$json_translation_files = glob( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json' );
117
-			if ( $json_translation_files ) {
118
-				array_map( array( $wp_filesystem, 'delete' ), $json_translation_files );
119
-			}
120
-		}
121
-	}
122
-
123
-	// Remove the theme from allowed themes on the network.
124
-	if ( is_multisite() ) {
125
-		WP_Theme::network_disable_theme( $stylesheet );
126
-	}
127
-
128
-	// Force refresh of theme update information.
129
-	delete_site_transient( 'update_themes' );
130
-
131
-	return true;
22
+    global $wp_filesystem;
23
+
24
+    if ( empty( $stylesheet ) ) {
25
+        return false;
26
+    }
27
+
28
+    if ( empty( $redirect ) ) {
29
+        $redirect = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );
30
+    }
31
+
32
+    ob_start();
33
+    $credentials = request_filesystem_credentials( $redirect );
34
+    $data        = ob_get_clean();
35
+
36
+    if ( false === $credentials ) {
37
+        if ( ! empty( $data ) ) {
38
+            require_once ABSPATH . 'wp-admin/admin-header.php';
39
+            echo $data;
40
+            require_once ABSPATH . 'wp-admin/admin-footer.php';
41
+            exit;
42
+        }
43
+        return;
44
+    }
45
+
46
+    if ( ! WP_Filesystem( $credentials ) ) {
47
+        ob_start();
48
+        // Failed to connect. Error and request again.
49
+        request_filesystem_credentials( $redirect, '', true );
50
+        $data = ob_get_clean();
51
+
52
+        if ( ! empty( $data ) ) {
53
+            require_once ABSPATH . 'wp-admin/admin-header.php';
54
+            echo $data;
55
+            require_once ABSPATH . 'wp-admin/admin-footer.php';
56
+            exit;
57
+        }
58
+        return;
59
+    }
60
+
61
+    if ( ! is_object( $wp_filesystem ) ) {
62
+        return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
63
+    }
64
+
65
+    if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
66
+        return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors );
67
+    }
68
+
69
+    // Get the base plugin folder.
70
+    $themes_dir = $wp_filesystem->wp_themes_dir();
71
+    if ( empty( $themes_dir ) ) {
72
+        return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
73
+    }
74
+
75
+    /**
76
+     * Fires immediately before a theme deletion attempt.
77
+     *
78
+     * @since 5.8.0
79
+     *
80
+     * @param string $stylesheet Stylesheet of the theme to delete.
81
+     */
82
+    do_action( 'delete_theme', $stylesheet );
83
+
84
+    $themes_dir = trailingslashit( $themes_dir );
85
+    $theme_dir  = trailingslashit( $themes_dir . $stylesheet );
86
+    $deleted    = $wp_filesystem->delete( $theme_dir, true );
87
+
88
+    /**
89
+     * Fires immediately after a theme deletion attempt.
90
+     *
91
+     * @since 5.8.0
92
+     *
93
+     * @param string $stylesheet Stylesheet of the theme to delete.
94
+     * @param bool   $deleted    Whether the theme deletion was successful.
95
+     */
96
+    do_action( 'deleted_theme', $stylesheet, $deleted );
97
+
98
+    if ( ! $deleted ) {
99
+        return new WP_Error(
100
+            'could_not_remove_theme',
101
+            /* translators: %s: Theme name. */
102
+            sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet )
103
+        );
104
+    }
105
+
106
+    $theme_translations = wp_get_installed_translations( 'themes' );
107
+
108
+    // Remove language files, silently.
109
+    if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
110
+        $translations = $theme_translations[ $stylesheet ];
111
+
112
+        foreach ( $translations as $translation => $data ) {
113
+            $wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
114
+            $wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
115
+
116
+            $json_translation_files = glob( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json' );
117
+            if ( $json_translation_files ) {
118
+                array_map( array( $wp_filesystem, 'delete' ), $json_translation_files );
119
+            }
120
+        }
121
+    }
122
+
123
+    // Remove the theme from allowed themes on the network.
124
+    if ( is_multisite() ) {
125
+        WP_Theme::network_disable_theme( $stylesheet );
126
+    }
127
+
128
+    // Force refresh of theme update information.
129
+    delete_site_transient( 'update_themes' );
130
+
131
+    return true;
132 132
 }
133 133
 
134 134
 /**
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
  * @return string[] Array of template file names keyed by the template header name.
143 143
  */
144 144
 function get_page_templates( $post = null, $post_type = 'page' ) {
145
-	return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
145
+    return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
146 146
 }
147 147
 
148 148
 /**
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
  * @return string
157 157
  */
158 158
 function _get_template_edit_filename( $fullpath, $containingfolder ) {
159
-	return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath );
159
+    return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath );
160 160
 }
161 161
 
162 162
 /**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
  * @param WP_Theme $theme Theme data object.
172 172
  */
173 173
 function theme_update_available( $theme ) {
174
-	echo get_theme_update_available( $theme );
174
+    echo get_theme_update_available( $theme );
175 175
 }
176 176
 
177 177
 /**
@@ -185,89 +185,89 @@  discard block
 block discarded – undo
185 185
  * @return string|false HTML for the update link, or false if invalid info was passed.
186 186
  */
187 187
 function get_theme_update_available( $theme ) {
188
-	static $themes_update = null;
189
-
190
-	if ( ! current_user_can( 'update_themes' ) ) {
191
-		return false;
192
-	}
193
-
194
-	if ( ! isset( $themes_update ) ) {
195
-		$themes_update = get_site_transient( 'update_themes' );
196
-	}
197
-
198
-	if ( ! ( $theme instanceof WP_Theme ) ) {
199
-		return false;
200
-	}
201
-
202
-	$stylesheet = $theme->get_stylesheet();
203
-
204
-	$html = '';
205
-
206
-	if ( isset( $themes_update->response[ $stylesheet ] ) ) {
207
-		$update      = $themes_update->response[ $stylesheet ];
208
-		$theme_name  = $theme->display( 'Name' );
209
-		$details_url = add_query_arg(
210
-			array(
211
-				'TB_iframe' => 'true',
212
-				'width'     => 1024,
213
-				'height'    => 800,
214
-			),
215
-			$update['url']
216
-		); // Theme browser inside WP? Replace this. Also, theme preview JS will override this on the available list.
217
-		$update_url  = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&amp;theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet );
218
-
219
-		if ( ! is_multisite() ) {
220
-			if ( ! current_user_can( 'update_themes' ) ) {
221
-				$html = sprintf(
222
-					/* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */
223
-					'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>',
224
-					$theme_name,
225
-					esc_url( $details_url ),
226
-					sprintf(
227
-						'class="thickbox open-plugin-details-modal" aria-label="%s"',
228
-						/* translators: 1: Theme name, 2: Version number. */
229
-						esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
230
-					),
231
-					$update['new_version']
232
-				);
233
-			} elseif ( empty( $update['package'] ) ) {
234
-				$html = sprintf(
235
-					/* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */
236
-					'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>',
237
-					$theme_name,
238
-					esc_url( $details_url ),
239
-					sprintf(
240
-						'class="thickbox open-plugin-details-modal" aria-label="%s"',
241
-						/* translators: 1: Theme name, 2: Version number. */
242
-						esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
243
-					),
244
-					$update['new_version']
245
-				);
246
-			} else {
247
-				$html = sprintf(
248
-					/* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
249
-					'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>',
250
-					$theme_name,
251
-					esc_url( $details_url ),
252
-					sprintf(
253
-						'class="thickbox open-plugin-details-modal" aria-label="%s"',
254
-						/* translators: 1: Theme name, 2: Version number. */
255
-						esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
256
-					),
257
-					$update['new_version'],
258
-					$update_url,
259
-					sprintf(
260
-						'aria-label="%s" id="update-theme" data-slug="%s"',
261
-						/* translators: %s: Theme name. */
262
-						esc_attr( sprintf( _x( 'Update %s now', 'theme' ), $theme_name ) ),
263
-						$stylesheet
264
-					)
265
-				);
266
-			}
267
-		}
268
-	}
269
-
270
-	return $html;
188
+    static $themes_update = null;
189
+
190
+    if ( ! current_user_can( 'update_themes' ) ) {
191
+        return false;
192
+    }
193
+
194
+    if ( ! isset( $themes_update ) ) {
195
+        $themes_update = get_site_transient( 'update_themes' );
196
+    }
197
+
198
+    if ( ! ( $theme instanceof WP_Theme ) ) {
199
+        return false;
200
+    }
201
+
202
+    $stylesheet = $theme->get_stylesheet();
203
+
204
+    $html = '';
205
+
206
+    if ( isset( $themes_update->response[ $stylesheet ] ) ) {
207
+        $update      = $themes_update->response[ $stylesheet ];
208
+        $theme_name  = $theme->display( 'Name' );
209
+        $details_url = add_query_arg(
210
+            array(
211
+                'TB_iframe' => 'true',
212
+                'width'     => 1024,
213
+                'height'    => 800,
214
+            ),
215
+            $update['url']
216
+        ); // Theme browser inside WP? Replace this. Also, theme preview JS will override this on the available list.
217
+        $update_url  = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&amp;theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet );
218
+
219
+        if ( ! is_multisite() ) {
220
+            if ( ! current_user_can( 'update_themes' ) ) {
221
+                $html = sprintf(
222
+                    /* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */
223
+                    '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>',
224
+                    $theme_name,
225
+                    esc_url( $details_url ),
226
+                    sprintf(
227
+                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
228
+                        /* translators: 1: Theme name, 2: Version number. */
229
+                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
230
+                    ),
231
+                    $update['new_version']
232
+                );
233
+            } elseif ( empty( $update['package'] ) ) {
234
+                $html = sprintf(
235
+                    /* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */
236
+                    '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>',
237
+                    $theme_name,
238
+                    esc_url( $details_url ),
239
+                    sprintf(
240
+                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
241
+                        /* translators: 1: Theme name, 2: Version number. */
242
+                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
243
+                    ),
244
+                    $update['new_version']
245
+                );
246
+            } else {
247
+                $html = sprintf(
248
+                    /* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
249
+                    '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>',
250
+                    $theme_name,
251
+                    esc_url( $details_url ),
252
+                    sprintf(
253
+                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
254
+                        /* translators: 1: Theme name, 2: Version number. */
255
+                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
256
+                    ),
257
+                    $update['new_version'],
258
+                    $update_url,
259
+                    sprintf(
260
+                        'aria-label="%s" id="update-theme" data-slug="%s"',
261
+                        /* translators: %s: Theme name. */
262
+                        esc_attr( sprintf( _x( 'Update %s now', 'theme' ), $theme_name ) ),
263
+                        $stylesheet
264
+                    )
265
+                );
266
+            }
267
+        }
268
+    }
269
+
270
+    return $html;
271 271
 }
272 272
 
273 273
 /**
@@ -304,102 +304,102 @@  discard block
 block discarded – undo
304 304
  * @return array Array of features keyed by category with translations keyed by slug.
305 305
  */
306 306
 function get_theme_feature_list( $api = true ) {
307
-	// Hard-coded list is used if API is not accessible.
308
-	$features = array(
309
-
310
-		__( 'Subject' )  => array(
311
-			'blog'           => __( 'Blog' ),
312
-			'e-commerce'     => __( 'E-Commerce' ),
313
-			'education'      => __( 'Education' ),
314
-			'entertainment'  => __( 'Entertainment' ),
315
-			'food-and-drink' => __( 'Food & Drink' ),
316
-			'holiday'        => __( 'Holiday' ),
317
-			'news'           => __( 'News' ),
318
-			'photography'    => __( 'Photography' ),
319
-			'portfolio'      => __( 'Portfolio' ),
320
-		),
321
-
322
-		__( 'Features' ) => array(
323
-			'accessibility-ready'   => __( 'Accessibility Ready' ),
324
-			'block-patterns'        => __( 'Block Editor Patterns' ),
325
-			'block-styles'          => __( 'Block Editor Styles' ),
326
-			'custom-background'     => __( 'Custom Background' ),
327
-			'custom-colors'         => __( 'Custom Colors' ),
328
-			'custom-header'         => __( 'Custom Header' ),
329
-			'custom-logo'           => __( 'Custom Logo' ),
330
-			'editor-style'          => __( 'Editor Style' ),
331
-			'featured-image-header' => __( 'Featured Image Header' ),
332
-			'featured-images'       => __( 'Featured Images' ),
333
-			'footer-widgets'        => __( 'Footer Widgets' ),
334
-			'full-site-editing'     => __( 'Full Site Editing' ),
335
-			'full-width-template'   => __( 'Full Width Template' ),
336
-			'post-formats'          => __( 'Post Formats' ),
337
-			'sticky-post'           => __( 'Sticky Post' ),
338
-			'template-editing'      => __( 'Template Editing' ),
339
-			'theme-options'         => __( 'Theme Options' ),
340
-		),
341
-
342
-		__( 'Layout' )   => array(
343
-			'grid-layout'   => __( 'Grid Layout' ),
344
-			'one-column'    => __( 'One Column' ),
345
-			'two-columns'   => __( 'Two Columns' ),
346
-			'three-columns' => __( 'Three Columns' ),
347
-			'four-columns'  => __( 'Four Columns' ),
348
-			'left-sidebar'  => __( 'Left Sidebar' ),
349
-			'right-sidebar' => __( 'Right Sidebar' ),
350
-			'wide-blocks'   => __( 'Wide Blocks' ),
351
-		),
352
-
353
-	);
354
-
355
-	if ( ! $api || ! current_user_can( 'install_themes' ) ) {
356
-		return $features;
357
-	}
358
-
359
-	$feature_list = get_site_transient( 'wporg_theme_feature_list' );
360
-	if ( ! $feature_list ) {
361
-		set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
362
-	}
363
-
364
-	if ( ! $feature_list ) {
365
-		$feature_list = themes_api( 'feature_list', array() );
366
-		if ( is_wp_error( $feature_list ) ) {
367
-			return $features;
368
-		}
369
-	}
370
-
371
-	if ( ! $feature_list ) {
372
-		return $features;
373
-	}
374
-
375
-	set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
376
-
377
-	$category_translations = array(
378
-		'Layout'   => __( 'Layout' ),
379
-		'Features' => __( 'Features' ),
380
-		'Subject'  => __( 'Subject' ),
381
-	);
382
-
383
-	$wporg_features = array();
384
-
385
-	// Loop over the wp.org canonical list and apply translations.
386
-	foreach ( (array) $feature_list as $feature_category => $feature_items ) {
387
-		if ( isset( $category_translations[ $feature_category ] ) ) {
388
-			$feature_category = $category_translations[ $feature_category ];
389
-		}
390
-
391
-		$wporg_features[ $feature_category ] = array();
392
-
393
-		foreach ( $feature_items as $feature ) {
394
-			if ( isset( $features[ $feature_category ][ $feature ] ) ) {
395
-				$wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ];
396
-			} else {
397
-				$wporg_features[ $feature_category ][ $feature ] = $feature;
398
-			}
399
-		}
400
-	}
401
-
402
-	return $wporg_features;
307
+    // Hard-coded list is used if API is not accessible.
308
+    $features = array(
309
+
310
+        __( 'Subject' )  => array(
311
+            'blog'           => __( 'Blog' ),
312
+            'e-commerce'     => __( 'E-Commerce' ),
313
+            'education'      => __( 'Education' ),
314
+            'entertainment'  => __( 'Entertainment' ),
315
+            'food-and-drink' => __( 'Food & Drink' ),
316
+            'holiday'        => __( 'Holiday' ),
317
+            'news'           => __( 'News' ),
318
+            'photography'    => __( 'Photography' ),
319
+            'portfolio'      => __( 'Portfolio' ),
320
+        ),
321
+
322
+        __( 'Features' ) => array(
323
+            'accessibility-ready'   => __( 'Accessibility Ready' ),
324
+            'block-patterns'        => __( 'Block Editor Patterns' ),
325
+            'block-styles'          => __( 'Block Editor Styles' ),
326
+            'custom-background'     => __( 'Custom Background' ),
327
+            'custom-colors'         => __( 'Custom Colors' ),
328
+            'custom-header'         => __( 'Custom Header' ),
329
+            'custom-logo'           => __( 'Custom Logo' ),
330
+            'editor-style'          => __( 'Editor Style' ),
331
+            'featured-image-header' => __( 'Featured Image Header' ),
332
+            'featured-images'       => __( 'Featured Images' ),
333
+            'footer-widgets'        => __( 'Footer Widgets' ),
334
+            'full-site-editing'     => __( 'Full Site Editing' ),
335
+            'full-width-template'   => __( 'Full Width Template' ),
336
+            'post-formats'          => __( 'Post Formats' ),
337
+            'sticky-post'           => __( 'Sticky Post' ),
338
+            'template-editing'      => __( 'Template Editing' ),
339
+            'theme-options'         => __( 'Theme Options' ),
340
+        ),
341
+
342
+        __( 'Layout' )   => array(
343
+            'grid-layout'   => __( 'Grid Layout' ),
344
+            'one-column'    => __( 'One Column' ),
345
+            'two-columns'   => __( 'Two Columns' ),
346
+            'three-columns' => __( 'Three Columns' ),
347
+            'four-columns'  => __( 'Four Columns' ),
348
+            'left-sidebar'  => __( 'Left Sidebar' ),
349
+            'right-sidebar' => __( 'Right Sidebar' ),
350
+            'wide-blocks'   => __( 'Wide Blocks' ),
351
+        ),
352
+
353
+    );
354
+
355
+    if ( ! $api || ! current_user_can( 'install_themes' ) ) {
356
+        return $features;
357
+    }
358
+
359
+    $feature_list = get_site_transient( 'wporg_theme_feature_list' );
360
+    if ( ! $feature_list ) {
361
+        set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
362
+    }
363
+
364
+    if ( ! $feature_list ) {
365
+        $feature_list = themes_api( 'feature_list', array() );
366
+        if ( is_wp_error( $feature_list ) ) {
367
+            return $features;
368
+        }
369
+    }
370
+
371
+    if ( ! $feature_list ) {
372
+        return $features;
373
+    }
374
+
375
+    set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
376
+
377
+    $category_translations = array(
378
+        'Layout'   => __( 'Layout' ),
379
+        'Features' => __( 'Features' ),
380
+        'Subject'  => __( 'Subject' ),
381
+    );
382
+
383
+    $wporg_features = array();
384
+
385
+    // Loop over the wp.org canonical list and apply translations.
386
+    foreach ( (array) $feature_list as $feature_category => $feature_items ) {
387
+        if ( isset( $category_translations[ $feature_category ] ) ) {
388
+            $feature_category = $category_translations[ $feature_category ];
389
+        }
390
+
391
+        $wporg_features[ $feature_category ] = array();
392
+
393
+        foreach ( $feature_items as $feature ) {
394
+            if ( isset( $features[ $feature_category ][ $feature ] ) ) {
395
+                $wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ];
396
+            } else {
397
+                $wporg_features[ $feature_category ][ $feature ] = $feature;
398
+            }
399
+        }
400
+    }
401
+
402
+    return $wporg_features;
403 403
 }
404 404
 
405 405
 /**
@@ -484,150 +484,150 @@  discard block
 block discarded – undo
484 484
  *         for more information on the make-up of possible return objects depending on the value of `$action`.
485 485
  */
486 486
 function themes_api( $action, $args = array() ) {
487
-	// Include an unmodified $wp_version.
488
-	require ABSPATH . WPINC . '/version.php';
489
-
490
-	if ( is_array( $args ) ) {
491
-		$args = (object) $args;
492
-	}
493
-
494
-	if ( 'query_themes' === $action ) {
495
-		if ( ! isset( $args->per_page ) ) {
496
-			$args->per_page = 24;
497
-		}
498
-	}
499
-
500
-	if ( ! isset( $args->locale ) ) {
501
-		$args->locale = get_user_locale();
502
-	}
503
-
504
-	if ( ! isset( $args->wp_version ) ) {
505
-		$args->wp_version = substr( $wp_version, 0, 3 ); // x.y
506
-	}
507
-
508
-	/**
509
-	 * Filters arguments used to query for installer pages from the WordPress.org Themes API.
510
-	 *
511
-	 * Important: An object MUST be returned to this filter.
512
-	 *
513
-	 * @since 2.8.0
514
-	 *
515
-	 * @param object $args   Arguments used to query for installer pages from the WordPress.org Themes API.
516
-	 * @param string $action Requested action. Likely values are 'theme_information',
517
-	 *                       'feature_list', or 'query_themes'.
518
-	 */
519
-	$args = apply_filters( 'themes_api_args', $args, $action );
520
-
521
-	/**
522
-	 * Filters whether to override the WordPress.org Themes API.
523
-	 *
524
-	 * Returning a non-false value will effectively short-circuit the WordPress.org API request.
525
-	 *
526
-	 * If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST
527
-	 * be passed. If `$action` is 'hot_tags', an array should be passed.
528
-	 *
529
-	 * @since 2.8.0
530
-	 *
531
-	 * @param false|object|array $override Whether to override the WordPress.org Themes API. Default false.
532
-	 * @param string             $action   Requested action. Likely values are 'theme_information',
533
-	 *                                    'feature_list', or 'query_themes'.
534
-	 * @param object             $args     Arguments used to query for installer pages from the Themes API.
535
-	 */
536
-	$res = apply_filters( 'themes_api', false, $action, $args );
537
-
538
-	if ( ! $res ) {
539
-		$url = 'http://api.wordpress.org/themes/info/1.2/';
540
-		$url = add_query_arg(
541
-			array(
542
-				'action'  => $action,
543
-				'request' => $args,
544
-			),
545
-			$url
546
-		);
547
-
548
-		$http_url = $url;
549
-		$ssl      = wp_http_supports( array( 'ssl' ) );
550
-		if ( $ssl ) {
551
-			$url = set_url_scheme( $url, 'https' );
552
-		}
553
-
554
-		$http_args = array(
555
-			'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
556
-		);
557
-		$request   = wp_remote_get( $url, $http_args );
558
-
559
-		if ( $ssl && is_wp_error( $request ) ) {
560
-			if ( ! wp_doing_ajax() ) {
561
-				trigger_error(
562
-					sprintf(
563
-						/* translators: %s: Support forums URL. */
564
-						__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
565
-						__( 'https://wordpress.org/support/forums/' )
566
-					) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
567
-					headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
568
-				);
569
-			}
570
-			$request = wp_remote_get( $http_url, $http_args );
571
-		}
572
-
573
-		if ( is_wp_error( $request ) ) {
574
-			$res = new WP_Error(
575
-				'themes_api_failed',
576
-				sprintf(
577
-					/* translators: %s: Support forums URL. */
578
-					__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
579
-					__( 'https://wordpress.org/support/forums/' )
580
-				),
581
-				$request->get_error_message()
582
-			);
583
-		} else {
584
-			$res = json_decode( wp_remote_retrieve_body( $request ), true );
585
-			if ( is_array( $res ) ) {
586
-				// Object casting is required in order to match the info/1.0 format.
587
-				$res = (object) $res;
588
-			} elseif ( null === $res ) {
589
-				$res = new WP_Error(
590
-					'themes_api_failed',
591
-					sprintf(
592
-						/* translators: %s: Support forums URL. */
593
-						__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
594
-						__( 'https://wordpress.org/support/forums/' )
595
-					),
596
-					wp_remote_retrieve_body( $request )
597
-				);
598
-			}
599
-
600
-			if ( isset( $res->error ) ) {
601
-				$res = new WP_Error( 'themes_api_failed', $res->error );
602
-			}
603
-		}
604
-
605
-		if ( ! is_wp_error( $res ) ) {
606
-			// Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects.
607
-			if ( 'query_themes' === $action ) {
608
-				foreach ( $res->themes as $i => $theme ) {
609
-					$res->themes[ $i ] = (object) $theme;
610
-				}
611
-			}
612
-
613
-			// Back-compat for info/1.2 API, downgrade the feature_list result back to an array.
614
-			if ( 'feature_list' === $action ) {
615
-				$res = (array) $res;
616
-			}
617
-		}
618
-	}
619
-
620
-	/**
621
-	 * Filters the returned WordPress.org Themes API response.
622
-	 *
623
-	 * @since 2.8.0
624
-	 *
625
-	 * @param array|stdClass|WP_Error $res    WordPress.org Themes API response.
626
-	 * @param string                  $action Requested action. Likely values are 'theme_information',
627
-	 *                                        'feature_list', or 'query_themes'.
628
-	 * @param stdClass                $args   Arguments used to query for installer pages from the WordPress.org Themes API.
629
-	 */
630
-	return apply_filters( 'themes_api_result', $res, $action, $args );
487
+    // Include an unmodified $wp_version.
488
+    require ABSPATH . WPINC . '/version.php';
489
+
490
+    if ( is_array( $args ) ) {
491
+        $args = (object) $args;
492
+    }
493
+
494
+    if ( 'query_themes' === $action ) {
495
+        if ( ! isset( $args->per_page ) ) {
496
+            $args->per_page = 24;
497
+        }
498
+    }
499
+
500
+    if ( ! isset( $args->locale ) ) {
501
+        $args->locale = get_user_locale();
502
+    }
503
+
504
+    if ( ! isset( $args->wp_version ) ) {
505
+        $args->wp_version = substr( $wp_version, 0, 3 ); // x.y
506
+    }
507
+
508
+    /**
509
+     * Filters arguments used to query for installer pages from the WordPress.org Themes API.
510
+     *
511
+     * Important: An object MUST be returned to this filter.
512
+     *
513
+     * @since 2.8.0
514
+     *
515
+     * @param object $args   Arguments used to query for installer pages from the WordPress.org Themes API.
516
+     * @param string $action Requested action. Likely values are 'theme_information',
517
+     *                       'feature_list', or 'query_themes'.
518
+     */
519
+    $args = apply_filters( 'themes_api_args', $args, $action );
520
+
521
+    /**
522
+     * Filters whether to override the WordPress.org Themes API.
523
+     *
524
+     * Returning a non-false value will effectively short-circuit the WordPress.org API request.
525
+     *
526
+     * If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST
527
+     * be passed. If `$action` is 'hot_tags', an array should be passed.
528
+     *
529
+     * @since 2.8.0
530
+     *
531
+     * @param false|object|array $override Whether to override the WordPress.org Themes API. Default false.
532
+     * @param string             $action   Requested action. Likely values are 'theme_information',
533
+     *                                    'feature_list', or 'query_themes'.
534
+     * @param object             $args     Arguments used to query for installer pages from the Themes API.
535
+     */
536
+    $res = apply_filters( 'themes_api', false, $action, $args );
537
+
538
+    if ( ! $res ) {
539
+        $url = 'http://api.wordpress.org/themes/info/1.2/';
540
+        $url = add_query_arg(
541
+            array(
542
+                'action'  => $action,
543
+                'request' => $args,
544
+            ),
545
+            $url
546
+        );
547
+
548
+        $http_url = $url;
549
+        $ssl      = wp_http_supports( array( 'ssl' ) );
550
+        if ( $ssl ) {
551
+            $url = set_url_scheme( $url, 'https' );
552
+        }
553
+
554
+        $http_args = array(
555
+            'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
556
+        );
557
+        $request   = wp_remote_get( $url, $http_args );
558
+
559
+        if ( $ssl && is_wp_error( $request ) ) {
560
+            if ( ! wp_doing_ajax() ) {
561
+                trigger_error(
562
+                    sprintf(
563
+                        /* translators: %s: Support forums URL. */
564
+                        __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
565
+                        __( 'https://wordpress.org/support/forums/' )
566
+                    ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
567
+                    headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
568
+                );
569
+            }
570
+            $request = wp_remote_get( $http_url, $http_args );
571
+        }
572
+
573
+        if ( is_wp_error( $request ) ) {
574
+            $res = new WP_Error(
575
+                'themes_api_failed',
576
+                sprintf(
577
+                    /* translators: %s: Support forums URL. */
578
+                    __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
579
+                    __( 'https://wordpress.org/support/forums/' )
580
+                ),
581
+                $request->get_error_message()
582
+            );
583
+        } else {
584
+            $res = json_decode( wp_remote_retrieve_body( $request ), true );
585
+            if ( is_array( $res ) ) {
586
+                // Object casting is required in order to match the info/1.0 format.
587
+                $res = (object) $res;
588
+            } elseif ( null === $res ) {
589
+                $res = new WP_Error(
590
+                    'themes_api_failed',
591
+                    sprintf(
592
+                        /* translators: %s: Support forums URL. */
593
+                        __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
594
+                        __( 'https://wordpress.org/support/forums/' )
595
+                    ),
596
+                    wp_remote_retrieve_body( $request )
597
+                );
598
+            }
599
+
600
+            if ( isset( $res->error ) ) {
601
+                $res = new WP_Error( 'themes_api_failed', $res->error );
602
+            }
603
+        }
604
+
605
+        if ( ! is_wp_error( $res ) ) {
606
+            // Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects.
607
+            if ( 'query_themes' === $action ) {
608
+                foreach ( $res->themes as $i => $theme ) {
609
+                    $res->themes[ $i ] = (object) $theme;
610
+                }
611
+            }
612
+
613
+            // Back-compat for info/1.2 API, downgrade the feature_list result back to an array.
614
+            if ( 'feature_list' === $action ) {
615
+                $res = (array) $res;
616
+            }
617
+        }
618
+    }
619
+
620
+    /**
621
+     * Filters the returned WordPress.org Themes API response.
622
+     *
623
+     * @since 2.8.0
624
+     *
625
+     * @param array|stdClass|WP_Error $res    WordPress.org Themes API response.
626
+     * @param string                  $action Requested action. Likely values are 'theme_information',
627
+     *                                        'feature_list', or 'query_themes'.
628
+     * @param stdClass                $args   Arguments used to query for installer pages from the WordPress.org Themes API.
629
+     */
630
+    return apply_filters( 'themes_api_result', $res, $action, $args );
631 631
 }
632 632
 
633 633
 /**
@@ -641,168 +641,168 @@  discard block
 block discarded – undo
641 641
  * @return array An associative array of theme data, sorted by name.
642 642
  */
643 643
 function wp_prepare_themes_for_js( $themes = null ) {
644
-	$current_theme = get_stylesheet();
645
-
646
-	/**
647
-	 * Filters theme data before it is prepared for JavaScript.
648
-	 *
649
-	 * Passing a non-empty array will result in wp_prepare_themes_for_js() returning
650
-	 * early with that value instead.
651
-	 *
652
-	 * @since 4.2.0
653
-	 *
654
-	 * @param array           $prepared_themes An associative array of theme data. Default empty array.
655
-	 * @param WP_Theme[]|null $themes          An array of theme objects to prepare, if any.
656
-	 * @param string          $current_theme   The active theme slug.
657
-	 */
658
-	$prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme );
659
-
660
-	if ( ! empty( $prepared_themes ) ) {
661
-		return $prepared_themes;
662
-	}
663
-
664
-	// Make sure the active theme is listed first.
665
-	$prepared_themes[ $current_theme ] = array();
666
-
667
-	if ( null === $themes ) {
668
-		$themes = wp_get_themes( array( 'allowed' => true ) );
669
-		if ( ! isset( $themes[ $current_theme ] ) ) {
670
-			$themes[ $current_theme ] = wp_get_theme();
671
-		}
672
-	}
673
-
674
-	$updates    = array();
675
-	$no_updates = array();
676
-	if ( ! is_multisite() && current_user_can( 'update_themes' ) ) {
677
-		$updates_transient = get_site_transient( 'update_themes' );
678
-		if ( isset( $updates_transient->response ) ) {
679
-			$updates = $updates_transient->response;
680
-		}
681
-		if ( isset( $updates_transient->no_update ) ) {
682
-			$no_updates = $updates_transient->no_update;
683
-		}
684
-	}
685
-
686
-	WP_Theme::sort_by_name( $themes );
687
-
688
-	$parents = array();
689
-
690
-	$auto_updates = (array) get_site_option( 'auto_update_themes', array() );
691
-
692
-	foreach ( $themes as $theme ) {
693
-		$slug         = $theme->get_stylesheet();
694
-		$encoded_slug = urlencode( $slug );
695
-
696
-		$parent = false;
697
-		if ( $theme->parent() ) {
698
-			$parent           = $theme->parent();
699
-			$parents[ $slug ] = $parent->get_stylesheet();
700
-			$parent           = $parent->display( 'Name' );
701
-		}
702
-
703
-		$customize_action = null;
704
-
705
-		$can_edit_theme_options = current_user_can( 'edit_theme_options' );
706
-		$can_customize          = current_user_can( 'customize' );
707
-		$is_block_theme         = $theme->is_block_theme();
708
-
709
-		if ( $is_block_theme && $can_edit_theme_options ) {
710
-			$customize_action = esc_url( admin_url( 'site-editor.php' ) );
711
-		} elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) {
712
-			$customize_action = esc_url(
713
-				add_query_arg(
714
-					array(
715
-						'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ),
716
-					),
717
-					wp_customize_url( $slug )
718
-				)
719
-			);
720
-		}
721
-
722
-		$update_requires_wp  = isset( $updates[ $slug ]['requires'] ) ? $updates[ $slug ]['requires'] : null;
723
-		$update_requires_php = isset( $updates[ $slug ]['requires_php'] ) ? $updates[ $slug ]['requires_php'] : null;
724
-
725
-		$auto_update        = in_array( $slug, $auto_updates, true );
726
-		$auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update';
727
-
728
-		if ( isset( $updates[ $slug ] ) ) {
729
-			$auto_update_supported      = true;
730
-			$auto_update_filter_payload = (object) $updates[ $slug ];
731
-		} elseif ( isset( $no_updates[ $slug ] ) ) {
732
-			$auto_update_supported      = true;
733
-			$auto_update_filter_payload = (object) $no_updates[ $slug ];
734
-		} else {
735
-			$auto_update_supported = false;
736
-			/*
644
+    $current_theme = get_stylesheet();
645
+
646
+    /**
647
+     * Filters theme data before it is prepared for JavaScript.
648
+     *
649
+     * Passing a non-empty array will result in wp_prepare_themes_for_js() returning
650
+     * early with that value instead.
651
+     *
652
+     * @since 4.2.0
653
+     *
654
+     * @param array           $prepared_themes An associative array of theme data. Default empty array.
655
+     * @param WP_Theme[]|null $themes          An array of theme objects to prepare, if any.
656
+     * @param string          $current_theme   The active theme slug.
657
+     */
658
+    $prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme );
659
+
660
+    if ( ! empty( $prepared_themes ) ) {
661
+        return $prepared_themes;
662
+    }
663
+
664
+    // Make sure the active theme is listed first.
665
+    $prepared_themes[ $current_theme ] = array();
666
+
667
+    if ( null === $themes ) {
668
+        $themes = wp_get_themes( array( 'allowed' => true ) );
669
+        if ( ! isset( $themes[ $current_theme ] ) ) {
670
+            $themes[ $current_theme ] = wp_get_theme();
671
+        }
672
+    }
673
+
674
+    $updates    = array();
675
+    $no_updates = array();
676
+    if ( ! is_multisite() && current_user_can( 'update_themes' ) ) {
677
+        $updates_transient = get_site_transient( 'update_themes' );
678
+        if ( isset( $updates_transient->response ) ) {
679
+            $updates = $updates_transient->response;
680
+        }
681
+        if ( isset( $updates_transient->no_update ) ) {
682
+            $no_updates = $updates_transient->no_update;
683
+        }
684
+    }
685
+
686
+    WP_Theme::sort_by_name( $themes );
687
+
688
+    $parents = array();
689
+
690
+    $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
691
+
692
+    foreach ( $themes as $theme ) {
693
+        $slug         = $theme->get_stylesheet();
694
+        $encoded_slug = urlencode( $slug );
695
+
696
+        $parent = false;
697
+        if ( $theme->parent() ) {
698
+            $parent           = $theme->parent();
699
+            $parents[ $slug ] = $parent->get_stylesheet();
700
+            $parent           = $parent->display( 'Name' );
701
+        }
702
+
703
+        $customize_action = null;
704
+
705
+        $can_edit_theme_options = current_user_can( 'edit_theme_options' );
706
+        $can_customize          = current_user_can( 'customize' );
707
+        $is_block_theme         = $theme->is_block_theme();
708
+
709
+        if ( $is_block_theme && $can_edit_theme_options ) {
710
+            $customize_action = esc_url( admin_url( 'site-editor.php' ) );
711
+        } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) {
712
+            $customize_action = esc_url(
713
+                add_query_arg(
714
+                    array(
715
+                        'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ),
716
+                    ),
717
+                    wp_customize_url( $slug )
718
+                )
719
+            );
720
+        }
721
+
722
+        $update_requires_wp  = isset( $updates[ $slug ]['requires'] ) ? $updates[ $slug ]['requires'] : null;
723
+        $update_requires_php = isset( $updates[ $slug ]['requires_php'] ) ? $updates[ $slug ]['requires_php'] : null;
724
+
725
+        $auto_update        = in_array( $slug, $auto_updates, true );
726
+        $auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update';
727
+
728
+        if ( isset( $updates[ $slug ] ) ) {
729
+            $auto_update_supported      = true;
730
+            $auto_update_filter_payload = (object) $updates[ $slug ];
731
+        } elseif ( isset( $no_updates[ $slug ] ) ) {
732
+            $auto_update_supported      = true;
733
+            $auto_update_filter_payload = (object) $no_updates[ $slug ];
734
+        } else {
735
+            $auto_update_supported = false;
736
+            /*
737 737
 			 * Create the expected payload for the auto_update_theme filter, this is the same data
738 738
 			 * as contained within $updates or $no_updates but used when the Theme is not known.
739 739
 			 */
740
-			$auto_update_filter_payload = (object) array(
741
-				'theme'        => $slug,
742
-				'new_version'  => $theme->get( 'Version' ),
743
-				'url'          => '',
744
-				'package'      => '',
745
-				'requires'     => $theme->get( 'RequiresWP' ),
746
-				'requires_php' => $theme->get( 'RequiresPHP' ),
747
-			);
748
-		}
749
-
750
-		$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $auto_update_filter_payload );
751
-
752
-		$prepared_themes[ $slug ] = array(
753
-			'id'             => $slug,
754
-			'name'           => $theme->display( 'Name' ),
755
-			'screenshot'     => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
756
-			'description'    => $theme->display( 'Description' ),
757
-			'author'         => $theme->display( 'Author', false, true ),
758
-			'authorAndUri'   => $theme->display( 'Author' ),
759
-			'tags'           => $theme->display( 'Tags' ),
760
-			'version'        => $theme->get( 'Version' ),
761
-			'compatibleWP'   => is_wp_version_compatible( $theme->get( 'RequiresWP' ) ),
762
-			'compatiblePHP'  => is_php_version_compatible( $theme->get( 'RequiresPHP' ) ),
763
-			'updateResponse' => array(
764
-				'compatibleWP'  => is_wp_version_compatible( $update_requires_wp ),
765
-				'compatiblePHP' => is_php_version_compatible( $update_requires_php ),
766
-			),
767
-			'parent'         => $parent,
768
-			'active'         => $slug === $current_theme,
769
-			'hasUpdate'      => isset( $updates[ $slug ] ),
770
-			'hasPackage'     => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
771
-			'update'         => get_theme_update_available( $theme ),
772
-			'autoupdate'     => array(
773
-				'enabled'   => $auto_update || $auto_update_forced,
774
-				'supported' => $auto_update_supported,
775
-				'forced'    => $auto_update_forced,
776
-			),
777
-			'actions'        => array(
778
-				'activate'   => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
779
-				'customize'  => $customize_action,
780
-				'delete'     => ( ! is_multisite() && current_user_can( 'delete_themes' ) ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&amp;stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
781
-				'autoupdate' => wp_is_auto_update_enabled_for_type( 'theme' ) && ! is_multisite() && current_user_can( 'update_themes' )
782
-					? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&amp;stylesheet=' . $encoded_slug ), 'updates' )
783
-					: null,
784
-			),
785
-			'blockTheme'     => $theme->is_block_theme(),
786
-		);
787
-	}
788
-
789
-	// Remove 'delete' action if theme has an active child.
790
-	if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) {
791
-		unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] );
792
-	}
793
-
794
-	/**
795
-	 * Filters the themes prepared for JavaScript, for themes.php.
796
-	 *
797
-	 * Could be useful for changing the order, which is by name by default.
798
-	 *
799
-	 * @since 3.8.0
800
-	 *
801
-	 * @param array $prepared_themes Array of theme data.
802
-	 */
803
-	$prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
804
-	$prepared_themes = array_values( $prepared_themes );
805
-	return array_filter( $prepared_themes );
740
+            $auto_update_filter_payload = (object) array(
741
+                'theme'        => $slug,
742
+                'new_version'  => $theme->get( 'Version' ),
743
+                'url'          => '',
744
+                'package'      => '',
745
+                'requires'     => $theme->get( 'RequiresWP' ),
746
+                'requires_php' => $theme->get( 'RequiresPHP' ),
747
+            );
748
+        }
749
+
750
+        $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $auto_update_filter_payload );
751
+
752
+        $prepared_themes[ $slug ] = array(
753
+            'id'             => $slug,
754
+            'name'           => $theme->display( 'Name' ),
755
+            'screenshot'     => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
756
+            'description'    => $theme->display( 'Description' ),
757
+            'author'         => $theme->display( 'Author', false, true ),
758
+            'authorAndUri'   => $theme->display( 'Author' ),
759
+            'tags'           => $theme->display( 'Tags' ),
760
+            'version'        => $theme->get( 'Version' ),
761
+            'compatibleWP'   => is_wp_version_compatible( $theme->get( 'RequiresWP' ) ),
762
+            'compatiblePHP'  => is_php_version_compatible( $theme->get( 'RequiresPHP' ) ),
763
+            'updateResponse' => array(
764
+                'compatibleWP'  => is_wp_version_compatible( $update_requires_wp ),
765
+                'compatiblePHP' => is_php_version_compatible( $update_requires_php ),
766
+            ),
767
+            'parent'         => $parent,
768
+            'active'         => $slug === $current_theme,
769
+            'hasUpdate'      => isset( $updates[ $slug ] ),
770
+            'hasPackage'     => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
771
+            'update'         => get_theme_update_available( $theme ),
772
+            'autoupdate'     => array(
773
+                'enabled'   => $auto_update || $auto_update_forced,
774
+                'supported' => $auto_update_supported,
775
+                'forced'    => $auto_update_forced,
776
+            ),
777
+            'actions'        => array(
778
+                'activate'   => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
779
+                'customize'  => $customize_action,
780
+                'delete'     => ( ! is_multisite() && current_user_can( 'delete_themes' ) ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&amp;stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
781
+                'autoupdate' => wp_is_auto_update_enabled_for_type( 'theme' ) && ! is_multisite() && current_user_can( 'update_themes' )
782
+                    ? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&amp;stylesheet=' . $encoded_slug ), 'updates' )
783
+                    : null,
784
+            ),
785
+            'blockTheme'     => $theme->is_block_theme(),
786
+        );
787
+    }
788
+
789
+    // Remove 'delete' action if theme has an active child.
790
+    if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) {
791
+        unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] );
792
+    }
793
+
794
+    /**
795
+     * Filters the themes prepared for JavaScript, for themes.php.
796
+     *
797
+     * Could be useful for changing the order, which is by name by default.
798
+     *
799
+     * @since 3.8.0
800
+     *
801
+     * @param array $prepared_themes Array of theme data.
802
+     */
803
+    $prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
804
+    $prepared_themes = array_values( $prepared_themes );
805
+    return array_filter( $prepared_themes );
806 806
 }
807 807
 
808 808
 /**
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
  * @since 4.2.0
812 812
  */
813 813
 function customize_themes_print_templates() {
814
-	?>
814
+    ?>
815 815
 	<script type="text/html" id="tmpl-customize-themes-details-view">
816 816
 		<div class="theme-backdrop"></div>
817 817
 		<div class="theme-wrap wp-clearfix" role="document">
@@ -835,15 +835,15 @@  discard block
 block discarded – undo
835 835
 					<# } #>
836 836
 					<h2 class="theme-name">{{{ data.name }}}<span class="theme-version">
837 837
 						<?php
838
-						/* translators: %s: Theme version. */
839
-						printf( __( 'Version: %s' ), '{{ data.version }}' );
840
-						?>
838
+                        /* translators: %s: Theme version. */
839
+                        printf( __( 'Version: %s' ), '{{ data.version }}' );
840
+                        ?>
841 841
 					</span></h2>
842 842
 					<h3 class="theme-author">
843 843
 						<?php
844
-						/* translators: %s: Theme author link. */
845
-						printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' );
846
-						?>
844
+                        /* translators: %s: Theme author link. */
845
+                        printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' );
846
+                        ?>
847 847
 					</h3>
848 848
 
849 849
 					<# if ( data.stars && 0 != data.num_ratings ) { #>
@@ -851,14 +851,14 @@  discard block
 block discarded – undo
851 851
 							{{{ data.stars }}}
852 852
 							<a class="num-ratings" target="_blank" href="{{ data.reviews_url }}">
853 853
 								<?php
854
-								printf(
855
-									'%1$s <span class="screen-reader-text">%2$s</span>',
856
-									/* translators: %s: Number of ratings. */
857
-									sprintf( __( '(%s ratings)' ), '{{ data.num_ratings }}' ),
858
-									/* translators: Accessibility text. */
859
-									__( '(opens in a new tab)' )
860
-								);
861
-								?>
854
+                                printf(
855
+                                    '%1$s <span class="screen-reader-text">%2$s</span>',
856
+                                    /* translators: %s: Number of ratings. */
857
+                                    sprintf( __( '(%s ratings)' ), '{{ data.num_ratings }}' ),
858
+                                    /* translators: Accessibility text. */
859
+                                    __( '(opens in a new tab)' )
860
+                                );
861
+                                ?>
862 862
 							</a>
863 863
 						</div>
864 864
 					<# } #>
@@ -875,65 +875,65 @@  discard block
 block discarded – undo
875 875
 								<p>
876 876
 									<# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #>
877 877
 										<?php
878
-										printf(
879
-											/* translators: %s: Theme name. */
880
-											__( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ),
881
-											'{{{ data.name }}}'
882
-										);
883
-										if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
884
-											printf(
885
-												/* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
886
-												' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
887
-												self_admin_url( 'update-core.php' ),
888
-												esc_url( wp_get_update_php_url() )
889
-											);
890
-											wp_update_php_annotation( '</p><p><em>', '</em>' );
891
-										} elseif ( current_user_can( 'update_core' ) ) {
892
-											printf(
893
-												/* translators: %s: URL to WordPress Updates screen. */
894
-												' ' . __( '<a href="%s">Please update WordPress</a>.' ),
895
-												self_admin_url( 'update-core.php' )
896
-											);
897
-										} elseif ( current_user_can( 'update_php' ) ) {
898
-											printf(
899
-												/* translators: %s: URL to Update PHP page. */
900
-												' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
901
-												esc_url( wp_get_update_php_url() )
902
-											);
903
-											wp_update_php_annotation( '</p><p><em>', '</em>' );
904
-										}
905
-										?>
878
+                                        printf(
879
+                                            /* translators: %s: Theme name. */
880
+                                            __( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ),
881
+                                            '{{{ data.name }}}'
882
+                                        );
883
+                                        if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
884
+                                            printf(
885
+                                                /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
886
+                                                ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
887
+                                                self_admin_url( 'update-core.php' ),
888
+                                                esc_url( wp_get_update_php_url() )
889
+                                            );
890
+                                            wp_update_php_annotation( '</p><p><em>', '</em>' );
891
+                                        } elseif ( current_user_can( 'update_core' ) ) {
892
+                                            printf(
893
+                                                /* translators: %s: URL to WordPress Updates screen. */
894
+                                                ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
895
+                                                self_admin_url( 'update-core.php' )
896
+                                            );
897
+                                        } elseif ( current_user_can( 'update_php' ) ) {
898
+                                            printf(
899
+                                                /* translators: %s: URL to Update PHP page. */
900
+                                                ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
901
+                                                esc_url( wp_get_update_php_url() )
902
+                                            );
903
+                                            wp_update_php_annotation( '</p><p><em>', '</em>' );
904
+                                        }
905
+                                        ?>
906 906
 									<# } else if ( ! data.updateResponse.compatibleWP ) { #>
907 907
 										<?php
908
-										printf(
909
-											/* translators: %s: Theme name. */
910
-											__( 'There is a new version of %s available, but it does not work with your version of WordPress.' ),
911
-											'{{{ data.name }}}'
912
-										);
913
-										if ( current_user_can( 'update_core' ) ) {
914
-											printf(
915
-												/* translators: %s: URL to WordPress Updates screen. */
916
-												' ' . __( '<a href="%s">Please update WordPress</a>.' ),
917
-												self_admin_url( 'update-core.php' )
918
-											);
919
-										}
920
-										?>
908
+                                        printf(
909
+                                            /* translators: %s: Theme name. */
910
+                                            __( 'There is a new version of %s available, but it does not work with your version of WordPress.' ),
911
+                                            '{{{ data.name }}}'
912
+                                        );
913
+                                        if ( current_user_can( 'update_core' ) ) {
914
+                                            printf(
915
+                                                /* translators: %s: URL to WordPress Updates screen. */
916
+                                                ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
917
+                                                self_admin_url( 'update-core.php' )
918
+                                            );
919
+                                        }
920
+                                        ?>
921 921
 									<# } else if ( ! data.updateResponse.compatiblePHP ) { #>
922 922
 										<?php
923
-										printf(
924
-											/* translators: %s: Theme name. */
925
-											__( 'There is a new version of %s available, but it does not work with your version of PHP.' ),
926
-											'{{{ data.name }}}'
927
-										);
928
-										if ( current_user_can( 'update_php' ) ) {
929
-											printf(
930
-												/* translators: %s: URL to Update PHP page. */
931
-												' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
932
-												esc_url( wp_get_update_php_url() )
933
-											);
934
-											wp_update_php_annotation( '</p><p><em>', '</em>' );
935
-										}
936
-										?>
923
+                                        printf(
924
+                                            /* translators: %s: Theme name. */
925
+                                            __( 'There is a new version of %s available, but it does not work with your version of PHP.' ),
926
+                                            '{{{ data.name }}}'
927
+                                        );
928
+                                        if ( current_user_can( 'update_php' ) ) {
929
+                                            printf(
930
+                                                /* translators: %s: URL to Update PHP page. */
931
+                                                ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
932
+                                                esc_url( wp_get_update_php_url() )
933
+                                            );
934
+                                            wp_update_php_annotation( '</p><p><em>', '</em>' );
935
+                                        }
936
+                                        ?>
937 937
 									<# } #>
938 938
 								</p>
939 939
 							</div>
@@ -943,12 +943,12 @@  discard block
 block discarded – undo
943 943
 					<# if ( data.parent ) { #>
944 944
 						<p class="parent-theme">
945 945
 							<?php
946
-							printf(
947
-								/* translators: %s: Theme name. */
948
-								__( 'This is a child theme of %s.' ),
949
-								'<strong>{{{ data.parent }}}</strong>'
950
-							);
951
-							?>
946
+                            printf(
947
+                                /* translators: %s: Theme name. */
948
+                                __( 'This is a child theme of %s.' ),
949
+                                '<strong>{{{ data.parent }}}</strong>'
950
+                            );
951
+                            ?>
952 952
 						</p>
953 953
 					<# } #>
954 954
 
@@ -956,68 +956,68 @@  discard block
 block discarded – undo
956 956
 						<div class="notice notice-error notice-alt notice-large"><p>
957 957
 							<# if ( ! data.compatibleWP && ! data.compatiblePHP ) { #>
958 958
 								<?php
959
-								_e( 'This theme does not work with your versions of WordPress and PHP.' );
960
-								if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
961
-									printf(
962
-										/* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
963
-										' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
964
-										self_admin_url( 'update-core.php' ),
965
-										esc_url( wp_get_update_php_url() )
966
-									);
967
-									wp_update_php_annotation( '</p><p><em>', '</em>' );
968
-								} elseif ( current_user_can( 'update_core' ) ) {
969
-									printf(
970
-										/* translators: %s: URL to WordPress Updates screen. */
971
-										' ' . __( '<a href="%s">Please update WordPress</a>.' ),
972
-										self_admin_url( 'update-core.php' )
973
-									);
974
-								} elseif ( current_user_can( 'update_php' ) ) {
975
-									printf(
976
-										/* translators: %s: URL to Update PHP page. */
977
-										' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
978
-										esc_url( wp_get_update_php_url() )
979
-									);
980
-									wp_update_php_annotation( '</p><p><em>', '</em>' );
981
-								}
982
-								?>
959
+                                _e( 'This theme does not work with your versions of WordPress and PHP.' );
960
+                                if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
961
+                                    printf(
962
+                                        /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
963
+                                        ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
964
+                                        self_admin_url( 'update-core.php' ),
965
+                                        esc_url( wp_get_update_php_url() )
966
+                                    );
967
+                                    wp_update_php_annotation( '</p><p><em>', '</em>' );
968
+                                } elseif ( current_user_can( 'update_core' ) ) {
969
+                                    printf(
970
+                                        /* translators: %s: URL to WordPress Updates screen. */
971
+                                        ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
972
+                                        self_admin_url( 'update-core.php' )
973
+                                    );
974
+                                } elseif ( current_user_can( 'update_php' ) ) {
975
+                                    printf(
976
+                                        /* translators: %s: URL to Update PHP page. */
977
+                                        ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
978
+                                        esc_url( wp_get_update_php_url() )
979
+                                    );
980
+                                    wp_update_php_annotation( '</p><p><em>', '</em>' );
981
+                                }
982
+                                ?>
983 983
 							<# } else if ( ! data.compatibleWP ) { #>
984 984
 								<?php
985
-								_e( 'This theme does not work with your version of WordPress.' );
986
-								if ( current_user_can( 'update_core' ) ) {
987
-									printf(
988
-										/* translators: %s: URL to WordPress Updates screen. */
989
-										' ' . __( '<a href="%s">Please update WordPress</a>.' ),
990
-										self_admin_url( 'update-core.php' )
991
-									);
992
-								}
993
-								?>
985
+                                _e( 'This theme does not work with your version of WordPress.' );
986
+                                if ( current_user_can( 'update_core' ) ) {
987
+                                    printf(
988
+                                        /* translators: %s: URL to WordPress Updates screen. */
989
+                                        ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
990
+                                        self_admin_url( 'update-core.php' )
991
+                                    );
992
+                                }
993
+                                ?>
994 994
 							<# } else if ( ! data.compatiblePHP ) { #>
995 995
 								<?php
996
-								_e( 'This theme does not work with your version of PHP.' );
997
-								if ( current_user_can( 'update_php' ) ) {
998
-									printf(
999
-										/* translators: %s: URL to Update PHP page. */
1000
-										' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
1001
-										esc_url( wp_get_update_php_url() )
1002
-									);
1003
-									wp_update_php_annotation( '</p><p><em>', '</em>' );
1004
-								}
1005
-								?>
996
+                                _e( 'This theme does not work with your version of PHP.' );
997
+                                if ( current_user_can( 'update_php' ) ) {
998
+                                    printf(
999
+                                        /* translators: %s: URL to Update PHP page. */
1000
+                                        ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
1001
+                                        esc_url( wp_get_update_php_url() )
1002
+                                    );
1003
+                                    wp_update_php_annotation( '</p><p><em>', '</em>' );
1004
+                                }
1005
+                                ?>
1006 1006
 							<# } #>
1007 1007
 						</p></div>
1008 1008
 					<# } else if ( ! data.active && data.blockTheme ) { #>
1009 1009
 						<div class="notice notice-error notice-alt notice-large"><p>
1010 1010
 						<?php
1011
-							_e( 'This theme doesn\'t support Customizer.' );
1012
-						?>
1011
+                            _e( 'This theme doesn\'t support Customizer.' );
1012
+                        ?>
1013 1013
 						<# if ( data.actions.activate ) { #>
1014 1014
 							<?php
1015
-							printf(
1016
-								/* translators: %s: URL to the themes page (also it activates the theme). */
1017
-								' ' . __( 'However, you can still <a href="%s">activate this theme</a>, and use the Site Editor to customize it.' ),
1018
-								'{{{ data.actions.activate }}}'
1019
-							);
1020
-							?>
1015
+                            printf(
1016
+                                /* translators: %s: URL to the themes page (also it activates the theme). */
1017
+                                ' ' . __( 'However, you can still <a href="%s">activate this theme</a>, and use the Site Editor to customize it.' ),
1018
+                                '{{{ data.actions.activate }}}'
1019
+                            );
1020
+                            ?>
1021 1021
 						<# } #>
1022 1022
 						</p></div>
1023 1023
 					<# } #>
@@ -1042,9 +1042,9 @@  discard block
 block discarded – undo
1042 1042
 
1043 1043
 					<# if ( data.blockTheme ) { #>
1044 1044
 						<?php
1045
-							/* translators: %s: Theme name. */
1046
-							$aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
1047
-						?>
1045
+                            /* translators: %s: Theme name. */
1046
+                            $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
1047
+                        ?>
1048 1048
 						<# if ( data.compatibleWP && data.compatiblePHP && data.actions.activate ) { #>
1049 1049
 							<a href="{{{ data.actions.activate }}}" class="button button-primary activate" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
1050 1050
 						<# } #>
@@ -1084,15 +1084,15 @@  discard block
 block discarded – undo
1084 1084
  * @return bool True, if in the list of paused themes. False, not in the list.
1085 1085
  */
1086 1086
 function is_theme_paused( $theme ) {
1087
-	if ( ! isset( $GLOBALS['_paused_themes'] ) ) {
1088
-		return false;
1089
-	}
1087
+    if ( ! isset( $GLOBALS['_paused_themes'] ) ) {
1088
+        return false;
1089
+    }
1090 1090
 
1091
-	if ( get_stylesheet() !== $theme && get_template() !== $theme ) {
1092
-		return false;
1093
-	}
1091
+    if ( get_stylesheet() !== $theme && get_template() !== $theme ) {
1092
+        return false;
1093
+    }
1094 1094
 
1095
-	return array_key_exists( $theme, $GLOBALS['_paused_themes'] );
1095
+    return array_key_exists( $theme, $GLOBALS['_paused_themes'] );
1096 1096
 }
1097 1097
 
1098 1098
 /**
@@ -1106,15 +1106,15 @@  discard block
 block discarded – undo
1106 1106
  *                     `error_get_last()`, or false if none was recorded.
1107 1107
  */
1108 1108
 function wp_get_theme_error( $theme ) {
1109
-	if ( ! isset( $GLOBALS['_paused_themes'] ) ) {
1110
-		return false;
1111
-	}
1109
+    if ( ! isset( $GLOBALS['_paused_themes'] ) ) {
1110
+        return false;
1111
+    }
1112 1112
 
1113
-	if ( ! array_key_exists( $theme, $GLOBALS['_paused_themes'] ) ) {
1114
-		return false;
1115
-	}
1113
+    if ( ! array_key_exists( $theme, $GLOBALS['_paused_themes'] ) ) {
1114
+        return false;
1115
+    }
1116 1116
 
1117
-	return $GLOBALS['_paused_themes'][ $theme ];
1117
+    return $GLOBALS['_paused_themes'][ $theme ];
1118 1118
 }
1119 1119
 
1120 1120
 /**
@@ -1135,49 +1135,49 @@  discard block
 block discarded – undo
1135 1135
  *                       `WP_Error` on failure.
1136 1136
  */
1137 1137
 function resume_theme( $theme, $redirect = '' ) {
1138
-	list( $extension ) = explode( '/', $theme );
1138
+    list( $extension ) = explode( '/', $theme );
1139 1139
 
1140
-	/*
1140
+    /*
1141 1141
 	 * We'll override this later if the theme could be resumed without
1142 1142
 	 * creating a fatal error.
1143 1143
 	 */
1144
-	if ( ! empty( $redirect ) ) {
1145
-		$functions_path = '';
1146
-		if ( strpos( STYLESHEETPATH, $extension ) ) {
1147
-			$functions_path = STYLESHEETPATH . '/functions.php';
1148
-		} elseif ( strpos( TEMPLATEPATH, $extension ) ) {
1149
-			$functions_path = TEMPLATEPATH . '/functions.php';
1150
-		}
1151
-
1152
-		if ( ! empty( $functions_path ) ) {
1153
-			wp_redirect(
1154
-				add_query_arg(
1155
-					'_error_nonce',
1156
-					wp_create_nonce( 'theme-resume-error_' . $theme ),
1157
-					$redirect
1158
-				)
1159
-			);
1160
-
1161
-			// Load the theme's functions.php to test whether it throws a fatal error.
1162
-			ob_start();
1163
-			if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
1164
-				define( 'WP_SANDBOX_SCRAPING', true );
1165
-			}
1166
-			include $functions_path;
1167
-			ob_clean();
1168
-		}
1169
-	}
1170
-
1171
-	$result = wp_paused_themes()->delete( $extension );
1172
-
1173
-	if ( ! $result ) {
1174
-		return new WP_Error(
1175
-			'could_not_resume_theme',
1176
-			__( 'Could not resume the theme.' )
1177
-		);
1178
-	}
1179
-
1180
-	return true;
1144
+    if ( ! empty( $redirect ) ) {
1145
+        $functions_path = '';
1146
+        if ( strpos( STYLESHEETPATH, $extension ) ) {
1147
+            $functions_path = STYLESHEETPATH . '/functions.php';
1148
+        } elseif ( strpos( TEMPLATEPATH, $extension ) ) {
1149
+            $functions_path = TEMPLATEPATH . '/functions.php';
1150
+        }
1151
+
1152
+        if ( ! empty( $functions_path ) ) {
1153
+            wp_redirect(
1154
+                add_query_arg(
1155
+                    '_error_nonce',
1156
+                    wp_create_nonce( 'theme-resume-error_' . $theme ),
1157
+                    $redirect
1158
+                )
1159
+            );
1160
+
1161
+            // Load the theme's functions.php to test whether it throws a fatal error.
1162
+            ob_start();
1163
+            if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
1164
+                define( 'WP_SANDBOX_SCRAPING', true );
1165
+            }
1166
+            include $functions_path;
1167
+            ob_clean();
1168
+        }
1169
+    }
1170
+
1171
+    $result = wp_paused_themes()->delete( $extension );
1172
+
1173
+    if ( ! $result ) {
1174
+        return new WP_Error(
1175
+            'could_not_resume_theme',
1176
+            __( 'Could not resume the theme.' )
1177
+        );
1178
+    }
1179
+
1180
+    return true;
1181 1181
 }
1182 1182
 
1183 1183
 /**
@@ -1188,23 +1188,23 @@  discard block
 block discarded – undo
1188 1188
  * @global string $pagenow The filename of the current screen.
1189 1189
  */
1190 1190
 function paused_themes_notice() {
1191
-	if ( 'themes.php' === $GLOBALS['pagenow'] ) {
1192
-		return;
1193
-	}
1194
-
1195
-	if ( ! current_user_can( 'resume_themes' ) ) {
1196
-		return;
1197
-	}
1198
-
1199
-	if ( ! isset( $GLOBALS['_paused_themes'] ) || empty( $GLOBALS['_paused_themes'] ) ) {
1200
-		return;
1201
-	}
1202
-
1203
-	printf(
1204
-		'<div class="notice notice-error"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>',
1205
-		__( 'One or more themes failed to load properly.' ),
1206
-		__( 'You can find more details and make changes on the Themes screen.' ),
1207
-		esc_url( admin_url( 'themes.php' ) ),
1208
-		__( 'Go to the Themes screen' )
1209
-	);
1191
+    if ( 'themes.php' === $GLOBALS['pagenow'] ) {
1192
+        return;
1193
+    }
1194
+
1195
+    if ( ! current_user_can( 'resume_themes' ) ) {
1196
+        return;
1197
+    }
1198
+
1199
+    if ( ! isset( $GLOBALS['_paused_themes'] ) || empty( $GLOBALS['_paused_themes'] ) ) {
1200
+        return;
1201
+    }
1202
+
1203
+    printf(
1204
+        '<div class="notice notice-error"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>',
1205
+        __( 'One or more themes failed to load properly.' ),
1206
+        __( 'You can find more details and make changes on the Themes screen.' ),
1207
+        esc_url( admin_url( 'themes.php' ) ),
1208
+        __( 'Go to the Themes screen' )
1209
+    );
1210 1210
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/class-file-upload-upgrader.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -18,116 +18,116 @@
 block discarded – undo
18 18
  */
19 19
 class File_Upload_Upgrader {
20 20
 
21
-	/**
22
-	 * The full path to the file package.
23
-	 *
24
-	 * @since 2.8.0
25
-	 * @var string $package
26
-	 */
27
-	public $package;
28
-
29
-	/**
30
-	 * The name of the file.
31
-	 *
32
-	 * @since 2.8.0
33
-	 * @var string $filename
34
-	 */
35
-	public $filename;
36
-
37
-	/**
38
-	 * The ID of the attachment post for this file.
39
-	 *
40
-	 * @since 3.3.0
41
-	 * @var int $id
42
-	 */
43
-	public $id = 0;
44
-
45
-	/**
46
-	 * Construct the upgrader for a form.
47
-	 *
48
-	 * @since 2.8.0
49
-	 *
50
-	 * @param string $form      The name of the form the file was uploaded from.
51
-	 * @param string $urlholder The name of the `GET` parameter that holds the filename.
52
-	 */
53
-	public function __construct( $form, $urlholder ) {
54
-
55
-		if ( empty( $_FILES[ $form ]['name'] ) && empty( $_GET[ $urlholder ] ) ) {
56
-			wp_die( __( 'Please select a file' ) );
57
-		}
58
-
59
-		// Handle a newly uploaded file. Else, assume it's already been uploaded.
60
-		if ( ! empty( $_FILES ) ) {
61
-			$overrides = array(
62
-				'test_form' => false,
63
-				'test_type' => false,
64
-			);
65
-			$file      = wp_handle_upload( $_FILES[ $form ], $overrides );
66
-
67
-			if ( isset( $file['error'] ) ) {
68
-				wp_die( $file['error'] );
69
-			}
70
-
71
-			$this->filename = $_FILES[ $form ]['name'];
72
-			$this->package  = $file['file'];
73
-
74
-			// Construct the attachment array.
75
-			$attachment = array(
76
-				'post_title'     => $this->filename,
77
-				'post_content'   => $file['url'],
78
-				'post_mime_type' => $file['type'],
79
-				'guid'           => $file['url'],
80
-				'context'        => 'upgrader',
81
-				'post_status'    => 'private',
82
-			);
83
-
84
-			// Save the data.
85
-			$this->id = wp_insert_attachment( $attachment, $file['file'] );
86
-
87
-			// Schedule a cleanup for 2 hours from now in case of failed installation.
88
-			wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $this->id ) );
89
-
90
-		} elseif ( is_numeric( $_GET[ $urlholder ] ) ) {
91
-			// Numeric Package = previously uploaded file, see above.
92
-			$this->id   = (int) $_GET[ $urlholder ];
93
-			$attachment = get_post( $this->id );
94
-			if ( empty( $attachment ) ) {
95
-				wp_die( __( 'Please select a file' ) );
96
-			}
97
-
98
-			$this->filename = $attachment->post_title;
99
-			$this->package  = get_attached_file( $attachment->ID );
100
-		} else {
101
-			// Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.
102
-			$uploads = wp_upload_dir();
103
-			if ( ! ( $uploads && false === $uploads['error'] ) ) {
104
-				wp_die( $uploads['error'] );
105
-			}
106
-
107
-			$this->filename = sanitize_file_name( $_GET[ $urlholder ] );
108
-			$this->package  = $uploads['basedir'] . '/' . $this->filename;
109
-
110
-			if ( 0 !== strpos( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) {
111
-				wp_die( __( 'Please select a file' ) );
112
-			}
113
-		}
114
-	}
115
-
116
-	/**
117
-	 * Delete the attachment/uploaded file.
118
-	 *
119
-	 * @since 3.2.2
120
-	 *
121
-	 * @return bool Whether the cleanup was successful.
122
-	 */
123
-	public function cleanup() {
124
-		if ( $this->id ) {
125
-			wp_delete_attachment( $this->id );
126
-
127
-		} elseif ( file_exists( $this->package ) ) {
128
-			return @unlink( $this->package );
129
-		}
130
-
131
-		return true;
132
-	}
21
+    /**
22
+     * The full path to the file package.
23
+     *
24
+     * @since 2.8.0
25
+     * @var string $package
26
+     */
27
+    public $package;
28
+
29
+    /**
30
+     * The name of the file.
31
+     *
32
+     * @since 2.8.0
33
+     * @var string $filename
34
+     */
35
+    public $filename;
36
+
37
+    /**
38
+     * The ID of the attachment post for this file.
39
+     *
40
+     * @since 3.3.0
41
+     * @var int $id
42
+     */
43
+    public $id = 0;
44
+
45
+    /**
46
+     * Construct the upgrader for a form.
47
+     *
48
+     * @since 2.8.0
49
+     *
50
+     * @param string $form      The name of the form the file was uploaded from.
51
+     * @param string $urlholder The name of the `GET` parameter that holds the filename.
52
+     */
53
+    public function __construct( $form, $urlholder ) {
54
+
55
+        if ( empty( $_FILES[ $form ]['name'] ) && empty( $_GET[ $urlholder ] ) ) {
56
+            wp_die( __( 'Please select a file' ) );
57
+        }
58
+
59
+        // Handle a newly uploaded file. Else, assume it's already been uploaded.
60
+        if ( ! empty( $_FILES ) ) {
61
+            $overrides = array(
62
+                'test_form' => false,
63
+                'test_type' => false,
64
+            );
65
+            $file      = wp_handle_upload( $_FILES[ $form ], $overrides );
66
+
67
+            if ( isset( $file['error'] ) ) {
68
+                wp_die( $file['error'] );
69
+            }
70
+
71
+            $this->filename = $_FILES[ $form ]['name'];
72
+            $this->package  = $file['file'];
73
+
74
+            // Construct the attachment array.
75
+            $attachment = array(
76
+                'post_title'     => $this->filename,
77
+                'post_content'   => $file['url'],
78
+                'post_mime_type' => $file['type'],
79
+                'guid'           => $file['url'],
80
+                'context'        => 'upgrader',
81
+                'post_status'    => 'private',
82
+            );
83
+
84
+            // Save the data.
85
+            $this->id = wp_insert_attachment( $attachment, $file['file'] );
86
+
87
+            // Schedule a cleanup for 2 hours from now in case of failed installation.
88
+            wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $this->id ) );
89
+
90
+        } elseif ( is_numeric( $_GET[ $urlholder ] ) ) {
91
+            // Numeric Package = previously uploaded file, see above.
92
+            $this->id   = (int) $_GET[ $urlholder ];
93
+            $attachment = get_post( $this->id );
94
+            if ( empty( $attachment ) ) {
95
+                wp_die( __( 'Please select a file' ) );
96
+            }
97
+
98
+            $this->filename = $attachment->post_title;
99
+            $this->package  = get_attached_file( $attachment->ID );
100
+        } else {
101
+            // Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.
102
+            $uploads = wp_upload_dir();
103
+            if ( ! ( $uploads && false === $uploads['error'] ) ) {
104
+                wp_die( $uploads['error'] );
105
+            }
106
+
107
+            $this->filename = sanitize_file_name( $_GET[ $urlholder ] );
108
+            $this->package  = $uploads['basedir'] . '/' . $this->filename;
109
+
110
+            if ( 0 !== strpos( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) {
111
+                wp_die( __( 'Please select a file' ) );
112
+            }
113
+        }
114
+    }
115
+
116
+    /**
117
+     * Delete the attachment/uploaded file.
118
+     *
119
+     * @since 3.2.2
120
+     *
121
+     * @return bool Whether the cleanup was successful.
122
+     */
123
+    public function cleanup() {
124
+        if ( $this->id ) {
125
+            wp_delete_attachment( $this->id );
126
+
127
+        } elseif ( file_exists( $this->package ) ) {
128
+            return @unlink( $this->package );
129
+        }
130
+
131
+        return true;
132
+    }
133 133
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/privacy-tools.php 1 patch
Indentation   +775 added lines, -775 removed lines patch added patch discarded remove patch
@@ -16,22 +16,22 @@  discard block
 block discarded – undo
16 16
  * @return true|WP_Error Returns true if sending the email was successful, or a WP_Error object.
17 17
  */
18 18
 function _wp_privacy_resend_request( $request_id ) {
19
-	$request_id = absint( $request_id );
20
-	$request    = get_post( $request_id );
19
+    $request_id = absint( $request_id );
20
+    $request    = get_post( $request_id );
21 21
 
22
-	if ( ! $request || 'user_request' !== $request->post_type ) {
23
-		return new WP_Error( 'privacy_request_error', __( 'Invalid personal data request.' ) );
24
-	}
22
+    if ( ! $request || 'user_request' !== $request->post_type ) {
23
+        return new WP_Error( 'privacy_request_error', __( 'Invalid personal data request.' ) );
24
+    }
25 25
 
26
-	$result = wp_send_user_request( $request_id );
26
+    $result = wp_send_user_request( $request_id );
27 27
 
28
-	if ( is_wp_error( $result ) ) {
29
-		return $result;
30
-	} elseif ( ! $result ) {
31
-		return new WP_Error( 'privacy_request_error', __( 'Unable to initiate confirmation for personal data request.' ) );
32
-	}
28
+    if ( is_wp_error( $result ) ) {
29
+        return $result;
30
+    } elseif ( ! $result ) {
31
+        return new WP_Error( 'privacy_request_error', __( 'Unable to initiate confirmation for personal data request.' ) );
32
+    }
33 33
 
34
-	return true;
34
+    return true;
35 35
 }
36 36
 
37 37
 /**
@@ -44,24 +44,24 @@  discard block
 block discarded – undo
44 44
  * @return int|WP_Error Request ID on success, or a WP_Error on failure.
45 45
  */
46 46
 function _wp_privacy_completed_request( $request_id ) {
47
-	// Get the request.
48
-	$request_id = absint( $request_id );
49
-	$request    = wp_get_user_request( $request_id );
47
+    // Get the request.
48
+    $request_id = absint( $request_id );
49
+    $request    = wp_get_user_request( $request_id );
50 50
 
51
-	if ( ! $request ) {
52
-		return new WP_Error( 'privacy_request_error', __( 'Invalid personal data request.' ) );
53
-	}
51
+    if ( ! $request ) {
52
+        return new WP_Error( 'privacy_request_error', __( 'Invalid personal data request.' ) );
53
+    }
54 54
 
55
-	update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() );
55
+    update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() );
56 56
 
57
-	$result = wp_update_post(
58
-		array(
59
-			'ID'          => $request_id,
60
-			'post_status' => 'request-completed',
61
-		)
62
-	);
57
+    $result = wp_update_post(
58
+        array(
59
+            'ID'          => $request_id,
60
+            'post_status' => 'request-completed',
61
+        )
62
+    );
63 63
 
64
-	return $result;
64
+    return $result;
65 65
 }
66 66
 
67 67
 /**
@@ -71,119 +71,119 @@  discard block
 block discarded – undo
71 71
  * @access private
72 72
  */
73 73
 function _wp_personal_data_handle_actions() {
74
-	if ( isset( $_POST['privacy_action_email_retry'] ) ) {
75
-		check_admin_referer( 'bulk-privacy_requests' );
76
-
77
-		$request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) );
78
-		$result     = _wp_privacy_resend_request( $request_id );
79
-
80
-		if ( is_wp_error( $result ) ) {
81
-			add_settings_error(
82
-				'privacy_action_email_retry',
83
-				'privacy_action_email_retry',
84
-				$result->get_error_message(),
85
-				'error'
86
-			);
87
-		} else {
88
-			add_settings_error(
89
-				'privacy_action_email_retry',
90
-				'privacy_action_email_retry',
91
-				__( 'Confirmation request sent again successfully.' ),
92
-				'success'
93
-			);
94
-		}
95
-	} elseif ( isset( $_POST['action'] ) ) {
96
-		$action = ! empty( $_POST['action'] ) ? sanitize_key( wp_unslash( $_POST['action'] ) ) : '';
97
-
98
-		switch ( $action ) {
99
-			case 'add_export_personal_data_request':
100
-			case 'add_remove_personal_data_request':
101
-				check_admin_referer( 'personal-data-request' );
102
-
103
-				if ( ! isset( $_POST['type_of_action'], $_POST['username_or_email_for_privacy_request'] ) ) {
104
-					add_settings_error(
105
-						'action_type',
106
-						'action_type',
107
-						__( 'Invalid personal data action.' ),
108
-						'error'
109
-					);
110
-				}
111
-				$action_type               = sanitize_text_field( wp_unslash( $_POST['type_of_action'] ) );
112
-				$username_or_email_address = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) );
113
-				$email_address             = '';
114
-				$status                    = 'pending';
115
-
116
-				if ( ! isset( $_POST['send_confirmation_email'] ) ) {
117
-					$status = 'confirmed';
118
-				}
119
-
120
-				if ( ! in_array( $action_type, _wp_privacy_action_request_types(), true ) ) {
121
-					add_settings_error(
122
-						'action_type',
123
-						'action_type',
124
-						__( 'Invalid personal data action.' ),
125
-						'error'
126
-					);
127
-				}
128
-
129
-				if ( ! is_email( $username_or_email_address ) ) {
130
-					$user = get_user_by( 'login', $username_or_email_address );
131
-					if ( ! $user instanceof WP_User ) {
132
-						add_settings_error(
133
-							'username_or_email_for_privacy_request',
134
-							'username_or_email_for_privacy_request',
135
-							__( 'Unable to add this request. A valid email address or username must be supplied.' ),
136
-							'error'
137
-						);
138
-					} else {
139
-						$email_address = $user->user_email;
140
-					}
141
-				} else {
142
-					$email_address = $username_or_email_address;
143
-				}
144
-
145
-				if ( empty( $email_address ) ) {
146
-					break;
147
-				}
148
-
149
-				$request_id = wp_create_user_request( $email_address, $action_type, array(), $status );
150
-				$message    = '';
151
-
152
-				if ( is_wp_error( $request_id ) ) {
153
-					$message = $request_id->get_error_message();
154
-				} elseif ( ! $request_id ) {
155
-					$message = __( 'Unable to initiate confirmation request.' );
156
-				}
157
-
158
-				if ( $message ) {
159
-					add_settings_error(
160
-						'username_or_email_for_privacy_request',
161
-						'username_or_email_for_privacy_request',
162
-						$message,
163
-						'error'
164
-					);
165
-					break;
166
-				}
167
-
168
-				if ( 'pending' === $status ) {
169
-					wp_send_user_request( $request_id );
170
-
171
-					$message = __( 'Confirmation request initiated successfully.' );
172
-				} elseif ( 'confirmed' === $status ) {
173
-					$message = __( 'Request added successfully.' );
174
-				}
175
-
176
-				if ( $message ) {
177
-					add_settings_error(
178
-						'username_or_email_for_privacy_request',
179
-						'username_or_email_for_privacy_request',
180
-						$message,
181
-						'success'
182
-					);
183
-					break;
184
-				}
185
-		}
186
-	}
74
+    if ( isset( $_POST['privacy_action_email_retry'] ) ) {
75
+        check_admin_referer( 'bulk-privacy_requests' );
76
+
77
+        $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) );
78
+        $result     = _wp_privacy_resend_request( $request_id );
79
+
80
+        if ( is_wp_error( $result ) ) {
81
+            add_settings_error(
82
+                'privacy_action_email_retry',
83
+                'privacy_action_email_retry',
84
+                $result->get_error_message(),
85
+                'error'
86
+            );
87
+        } else {
88
+            add_settings_error(
89
+                'privacy_action_email_retry',
90
+                'privacy_action_email_retry',
91
+                __( 'Confirmation request sent again successfully.' ),
92
+                'success'
93
+            );
94
+        }
95
+    } elseif ( isset( $_POST['action'] ) ) {
96
+        $action = ! empty( $_POST['action'] ) ? sanitize_key( wp_unslash( $_POST['action'] ) ) : '';
97
+
98
+        switch ( $action ) {
99
+            case 'add_export_personal_data_request':
100
+            case 'add_remove_personal_data_request':
101
+                check_admin_referer( 'personal-data-request' );
102
+
103
+                if ( ! isset( $_POST['type_of_action'], $_POST['username_or_email_for_privacy_request'] ) ) {
104
+                    add_settings_error(
105
+                        'action_type',
106
+                        'action_type',
107
+                        __( 'Invalid personal data action.' ),
108
+                        'error'
109
+                    );
110
+                }
111
+                $action_type               = sanitize_text_field( wp_unslash( $_POST['type_of_action'] ) );
112
+                $username_or_email_address = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) );
113
+                $email_address             = '';
114
+                $status                    = 'pending';
115
+
116
+                if ( ! isset( $_POST['send_confirmation_email'] ) ) {
117
+                    $status = 'confirmed';
118
+                }
119
+
120
+                if ( ! in_array( $action_type, _wp_privacy_action_request_types(), true ) ) {
121
+                    add_settings_error(
122
+                        'action_type',
123
+                        'action_type',
124
+                        __( 'Invalid personal data action.' ),
125
+                        'error'
126
+                    );
127
+                }
128
+
129
+                if ( ! is_email( $username_or_email_address ) ) {
130
+                    $user = get_user_by( 'login', $username_or_email_address );
131
+                    if ( ! $user instanceof WP_User ) {
132
+                        add_settings_error(
133
+                            'username_or_email_for_privacy_request',
134
+                            'username_or_email_for_privacy_request',
135
+                            __( 'Unable to add this request. A valid email address or username must be supplied.' ),
136
+                            'error'
137
+                        );
138
+                    } else {
139
+                        $email_address = $user->user_email;
140
+                    }
141
+                } else {
142
+                    $email_address = $username_or_email_address;
143
+                }
144
+
145
+                if ( empty( $email_address ) ) {
146
+                    break;
147
+                }
148
+
149
+                $request_id = wp_create_user_request( $email_address, $action_type, array(), $status );
150
+                $message    = '';
151
+
152
+                if ( is_wp_error( $request_id ) ) {
153
+                    $message = $request_id->get_error_message();
154
+                } elseif ( ! $request_id ) {
155
+                    $message = __( 'Unable to initiate confirmation request.' );
156
+                }
157
+
158
+                if ( $message ) {
159
+                    add_settings_error(
160
+                        'username_or_email_for_privacy_request',
161
+                        'username_or_email_for_privacy_request',
162
+                        $message,
163
+                        'error'
164
+                    );
165
+                    break;
166
+                }
167
+
168
+                if ( 'pending' === $status ) {
169
+                    wp_send_user_request( $request_id );
170
+
171
+                    $message = __( 'Confirmation request initiated successfully.' );
172
+                } elseif ( 'confirmed' === $status ) {
173
+                    $message = __( 'Request added successfully.' );
174
+                }
175
+
176
+                if ( $message ) {
177
+                    add_settings_error(
178
+                        'username_or_email_for_privacy_request',
179
+                        'username_or_email_for_privacy_request',
180
+                        $message,
181
+                        'success'
182
+                    );
183
+                    break;
184
+                }
185
+        }
186
+    }
187 187
 }
188 188
 
189 189
 /**
@@ -193,35 +193,35 @@  discard block
 block discarded – undo
193 193
  * @access private
194 194
  */
195 195
 function _wp_personal_data_cleanup_requests() {
196
-	/** This filter is documented in wp-includes/user.php */
197
-	$expires = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS );
198
-
199
-	$requests_query = new WP_Query(
200
-		array(
201
-			'post_type'      => 'user_request',
202
-			'posts_per_page' => -1,
203
-			'post_status'    => 'request-pending',
204
-			'fields'         => 'ids',
205
-			'date_query'     => array(
206
-				array(
207
-					'column' => 'post_modified_gmt',
208
-					'before' => $expires . ' seconds ago',
209
-				),
210
-			),
211
-		)
212
-	);
213
-
214
-	$request_ids = $requests_query->posts;
215
-
216
-	foreach ( $request_ids as $request_id ) {
217
-		wp_update_post(
218
-			array(
219
-				'ID'            => $request_id,
220
-				'post_status'   => 'request-failed',
221
-				'post_password' => '',
222
-			)
223
-		);
224
-	}
196
+    /** This filter is documented in wp-includes/user.php */
197
+    $expires = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS );
198
+
199
+    $requests_query = new WP_Query(
200
+        array(
201
+            'post_type'      => 'user_request',
202
+            'posts_per_page' => -1,
203
+            'post_status'    => 'request-pending',
204
+            'fields'         => 'ids',
205
+            'date_query'     => array(
206
+                array(
207
+                    'column' => 'post_modified_gmt',
208
+                    'before' => $expires . ' seconds ago',
209
+                ),
210
+            ),
211
+        )
212
+    );
213
+
214
+    $request_ids = $requests_query->posts;
215
+
216
+    foreach ( $request_ids as $request_id ) {
217
+        wp_update_post(
218
+            array(
219
+                'ID'            => $request_id,
220
+                'post_status'   => 'request-failed',
221
+                'post_password' => '',
222
+            )
223
+        );
224
+    }
225 225
 }
226 226
 
227 227
 /**
@@ -250,54 +250,54 @@  discard block
 block discarded – undo
250 250
  * @return string The HTML for this group and its items.
251 251
  */
252 252
 function wp_privacy_generate_personal_data_export_group_html( $group_data, $group_id = '', $groups_count = 1 ) {
253
-	$group_id_attr = sanitize_title_with_dashes( $group_data['group_label'] . '-' . $group_id );
253
+    $group_id_attr = sanitize_title_with_dashes( $group_data['group_label'] . '-' . $group_id );
254 254
 
255
-	$group_html  = '<h2 id="' . esc_attr( $group_id_attr ) . '">';
256
-	$group_html .= esc_html( $group_data['group_label'] );
255
+    $group_html  = '<h2 id="' . esc_attr( $group_id_attr ) . '">';
256
+    $group_html .= esc_html( $group_data['group_label'] );
257 257
 
258
-	$items_count = count( (array) $group_data['items'] );
259
-	if ( $items_count > 1 ) {
260
-		$group_html .= sprintf( ' <span class="count">(%d)</span>', $items_count );
261
-	}
258
+    $items_count = count( (array) $group_data['items'] );
259
+    if ( $items_count > 1 ) {
260
+        $group_html .= sprintf( ' <span class="count">(%d)</span>', $items_count );
261
+    }
262 262
 
263
-	$group_html .= '</h2>';
263
+    $group_html .= '</h2>';
264 264
 
265
-	if ( ! empty( $group_data['group_description'] ) ) {
266
-		$group_html .= '<p>' . esc_html( $group_data['group_description'] ) . '</p>';
267
-	}
265
+    if ( ! empty( $group_data['group_description'] ) ) {
266
+        $group_html .= '<p>' . esc_html( $group_data['group_description'] ) . '</p>';
267
+    }
268 268
 
269
-	$group_html .= '<div>';
269
+    $group_html .= '<div>';
270 270
 
271
-	foreach ( (array) $group_data['items'] as $group_item_id => $group_item_data ) {
272
-		$group_html .= '<table>';
273
-		$group_html .= '<tbody>';
271
+    foreach ( (array) $group_data['items'] as $group_item_id => $group_item_data ) {
272
+        $group_html .= '<table>';
273
+        $group_html .= '<tbody>';
274 274
 
275
-		foreach ( (array) $group_item_data as $group_item_datum ) {
276
-			$value = $group_item_datum['value'];
277
-			// If it looks like a link, make it a link.
278
-			if ( false === strpos( $value, ' ' ) && ( 0 === strpos( $value, 'http://' ) || 0 === strpos( $value, 'https://' ) ) ) {
279
-				$value = '<a href="' . esc_url( $value ) . '">' . esc_html( $value ) . '</a>';
280
-			}
275
+        foreach ( (array) $group_item_data as $group_item_datum ) {
276
+            $value = $group_item_datum['value'];
277
+            // If it looks like a link, make it a link.
278
+            if ( false === strpos( $value, ' ' ) && ( 0 === strpos( $value, 'http://' ) || 0 === strpos( $value, 'https://' ) ) ) {
279
+                $value = '<a href="' . esc_url( $value ) . '">' . esc_html( $value ) . '</a>';
280
+            }
281 281
 
282
-			$group_html .= '<tr>';
283
-			$group_html .= '<th>' . esc_html( $group_item_datum['name'] ) . '</th>';
284
-			$group_html .= '<td>' . wp_kses( $value, 'personal_data_export' ) . '</td>';
285
-			$group_html .= '</tr>';
286
-		}
282
+            $group_html .= '<tr>';
283
+            $group_html .= '<th>' . esc_html( $group_item_datum['name'] ) . '</th>';
284
+            $group_html .= '<td>' . wp_kses( $value, 'personal_data_export' ) . '</td>';
285
+            $group_html .= '</tr>';
286
+        }
287 287
 
288
-		$group_html .= '</tbody>';
289
-		$group_html .= '</table>';
290
-	}
288
+        $group_html .= '</tbody>';
289
+        $group_html .= '</table>';
290
+    }
291 291
 
292
-	if ( $groups_count > 1 ) {
293
-		$group_html .= '<div class="return-to-top">';
294
-		$group_html .= '<a href="#top"><span aria-hidden="true">&uarr; </span> ' . esc_html__( 'Go to top' ) . '</a>';
295
-		$group_html .= '</div>';
296
-	}
292
+    if ( $groups_count > 1 ) {
293
+        $group_html .= '<div class="return-to-top">';
294
+        $group_html .= '<a href="#top"><span aria-hidden="true">&uarr; </span> ' . esc_html__( 'Go to top' ) . '</a>';
295
+        $group_html .= '</div>';
296
+    }
297 297
 
298
-	$group_html .= '</div>';
298
+    $group_html .= '</div>';
299 299
 
300
-	return $group_html;
300
+    return $group_html;
301 301
 }
302 302
 
303 303
 /**
@@ -308,273 +308,273 @@  discard block
 block discarded – undo
308 308
  * @param int $request_id The export request ID.
309 309
  */
310 310
 function wp_privacy_generate_personal_data_export_file( $request_id ) {
311
-	if ( ! class_exists( 'ZipArchive' ) ) {
312
-		wp_send_json_error( __( 'Unable to generate personal data export file. ZipArchive not available.' ) );
313
-	}
314
-
315
-	// Get the request.
316
-	$request = wp_get_user_request( $request_id );
317
-
318
-	if ( ! $request || 'export_personal_data' !== $request->action_name ) {
319
-		wp_send_json_error( __( 'Invalid request ID when generating personal data export file.' ) );
320
-	}
321
-
322
-	$email_address = $request->email;
323
-
324
-	if ( ! is_email( $email_address ) ) {
325
-		wp_send_json_error( __( 'Invalid email address when generating personal data export file.' ) );
326
-	}
327
-
328
-	// Create the exports folder if needed.
329
-	$exports_dir = wp_privacy_exports_dir();
330
-	$exports_url = wp_privacy_exports_url();
331
-
332
-	if ( ! wp_mkdir_p( $exports_dir ) ) {
333
-		wp_send_json_error( __( 'Unable to create personal data export folder.' ) );
334
-	}
335
-
336
-	// Protect export folder from browsing.
337
-	$index_pathname = $exports_dir . 'index.php';
338
-	if ( ! file_exists( $index_pathname ) ) {
339
-		$file = fopen( $index_pathname, 'w' );
340
-		if ( false === $file ) {
341
-			wp_send_json_error( __( 'Unable to protect personal data export folder from browsing.' ) );
342
-		}
343
-		fwrite( $file, "<?php\n// Silence is golden.\n" );
344
-		fclose( $file );
345
-	}
346
-
347
-	$obscura              = wp_generate_password( 32, false, false );
348
-	$file_basename        = 'wp-personal-data-file-' . $obscura;
349
-	$html_report_filename = wp_unique_filename( $exports_dir, $file_basename . '.html' );
350
-	$html_report_pathname = wp_normalize_path( $exports_dir . $html_report_filename );
351
-	$json_report_filename = $file_basename . '.json';
352
-	$json_report_pathname = wp_normalize_path( $exports_dir . $json_report_filename );
353
-
354
-	/*
311
+    if ( ! class_exists( 'ZipArchive' ) ) {
312
+        wp_send_json_error( __( 'Unable to generate personal data export file. ZipArchive not available.' ) );
313
+    }
314
+
315
+    // Get the request.
316
+    $request = wp_get_user_request( $request_id );
317
+
318
+    if ( ! $request || 'export_personal_data' !== $request->action_name ) {
319
+        wp_send_json_error( __( 'Invalid request ID when generating personal data export file.' ) );
320
+    }
321
+
322
+    $email_address = $request->email;
323
+
324
+    if ( ! is_email( $email_address ) ) {
325
+        wp_send_json_error( __( 'Invalid email address when generating personal data export file.' ) );
326
+    }
327
+
328
+    // Create the exports folder if needed.
329
+    $exports_dir = wp_privacy_exports_dir();
330
+    $exports_url = wp_privacy_exports_url();
331
+
332
+    if ( ! wp_mkdir_p( $exports_dir ) ) {
333
+        wp_send_json_error( __( 'Unable to create personal data export folder.' ) );
334
+    }
335
+
336
+    // Protect export folder from browsing.
337
+    $index_pathname = $exports_dir . 'index.php';
338
+    if ( ! file_exists( $index_pathname ) ) {
339
+        $file = fopen( $index_pathname, 'w' );
340
+        if ( false === $file ) {
341
+            wp_send_json_error( __( 'Unable to protect personal data export folder from browsing.' ) );
342
+        }
343
+        fwrite( $file, "<?php\n// Silence is golden.\n" );
344
+        fclose( $file );
345
+    }
346
+
347
+    $obscura              = wp_generate_password( 32, false, false );
348
+    $file_basename        = 'wp-personal-data-file-' . $obscura;
349
+    $html_report_filename = wp_unique_filename( $exports_dir, $file_basename . '.html' );
350
+    $html_report_pathname = wp_normalize_path( $exports_dir . $html_report_filename );
351
+    $json_report_filename = $file_basename . '.json';
352
+    $json_report_pathname = wp_normalize_path( $exports_dir . $json_report_filename );
353
+
354
+    /*
355 355
 	 * Gather general data needed.
356 356
 	 */
357 357
 
358
-	// Title.
359
-	$title = sprintf(
360
-		/* translators: %s: User's email address. */
361
-		__( 'Personal Data Export for %s' ),
362
-		$email_address
363
-	);
364
-
365
-	// First, build an "About" group on the fly for this report.
366
-	$about_group = array(
367
-		/* translators: Header for the About section in a personal data export. */
368
-		'group_label'       => _x( 'About', 'personal data group label' ),
369
-		/* translators: Description for the About section in a personal data export. */
370
-		'group_description' => _x( 'Overview of export report.', 'personal data group description' ),
371
-		'items'             => array(
372
-			'about-1' => array(
373
-				array(
374
-					'name'  => _x( 'Report generated for', 'email address' ),
375
-					'value' => $email_address,
376
-				),
377
-				array(
378
-					'name'  => _x( 'For site', 'website name' ),
379
-					'value' => get_bloginfo( 'name' ),
380
-				),
381
-				array(
382
-					'name'  => _x( 'At URL', 'website URL' ),
383
-					'value' => get_bloginfo( 'url' ),
384
-				),
385
-				array(
386
-					'name'  => _x( 'On', 'date/time' ),
387
-					'value' => current_time( 'mysql' ),
388
-				),
389
-			),
390
-		),
391
-	);
392
-
393
-	// And now, all the Groups.
394
-	$groups = get_post_meta( $request_id, '_export_data_grouped', true );
395
-	if ( is_array( $groups ) ) {
396
-		// Merge in the special "About" group.
397
-		$groups       = array_merge( array( 'about' => $about_group ), $groups );
398
-		$groups_count = count( $groups );
399
-	} else {
400
-		if ( false !== $groups ) {
401
-			_doing_it_wrong(
402
-				__FUNCTION__,
403
-				/* translators: %s: Post meta key. */
404
-				sprintf( __( 'The %s post meta must be an array.' ), '<code>_export_data_grouped</code>' ),
405
-				'5.8.0'
406
-			);
407
-		}
408
-
409
-		$groups       = null;
410
-		$groups_count = 0;
411
-	}
412
-
413
-	// Convert the groups to JSON format.
414
-	$groups_json = wp_json_encode( $groups );
415
-
416
-	if ( false === $groups_json ) {
417
-		$error_message = sprintf(
418
-			/* translators: %s: Error message. */
419
-			__( 'Unable to encode the personal data for export. Error: %s' ),
420
-			json_last_error_msg()
421
-		);
422
-
423
-		wp_send_json_error( $error_message );
424
-	}
425
-
426
-	/*
358
+    // Title.
359
+    $title = sprintf(
360
+        /* translators: %s: User's email address. */
361
+        __( 'Personal Data Export for %s' ),
362
+        $email_address
363
+    );
364
+
365
+    // First, build an "About" group on the fly for this report.
366
+    $about_group = array(
367
+        /* translators: Header for the About section in a personal data export. */
368
+        'group_label'       => _x( 'About', 'personal data group label' ),
369
+        /* translators: Description for the About section in a personal data export. */
370
+        'group_description' => _x( 'Overview of export report.', 'personal data group description' ),
371
+        'items'             => array(
372
+            'about-1' => array(
373
+                array(
374
+                    'name'  => _x( 'Report generated for', 'email address' ),
375
+                    'value' => $email_address,
376
+                ),
377
+                array(
378
+                    'name'  => _x( 'For site', 'website name' ),
379
+                    'value' => get_bloginfo( 'name' ),
380
+                ),
381
+                array(
382
+                    'name'  => _x( 'At URL', 'website URL' ),
383
+                    'value' => get_bloginfo( 'url' ),
384
+                ),
385
+                array(
386
+                    'name'  => _x( 'On', 'date/time' ),
387
+                    'value' => current_time( 'mysql' ),
388
+                ),
389
+            ),
390
+        ),
391
+    );
392
+
393
+    // And now, all the Groups.
394
+    $groups = get_post_meta( $request_id, '_export_data_grouped', true );
395
+    if ( is_array( $groups ) ) {
396
+        // Merge in the special "About" group.
397
+        $groups       = array_merge( array( 'about' => $about_group ), $groups );
398
+        $groups_count = count( $groups );
399
+    } else {
400
+        if ( false !== $groups ) {
401
+            _doing_it_wrong(
402
+                __FUNCTION__,
403
+                /* translators: %s: Post meta key. */
404
+                sprintf( __( 'The %s post meta must be an array.' ), '<code>_export_data_grouped</code>' ),
405
+                '5.8.0'
406
+            );
407
+        }
408
+
409
+        $groups       = null;
410
+        $groups_count = 0;
411
+    }
412
+
413
+    // Convert the groups to JSON format.
414
+    $groups_json = wp_json_encode( $groups );
415
+
416
+    if ( false === $groups_json ) {
417
+        $error_message = sprintf(
418
+            /* translators: %s: Error message. */
419
+            __( 'Unable to encode the personal data for export. Error: %s' ),
420
+            json_last_error_msg()
421
+        );
422
+
423
+        wp_send_json_error( $error_message );
424
+    }
425
+
426
+    /*
427 427
 	 * Handle the JSON export.
428 428
 	 */
429
-	$file = fopen( $json_report_pathname, 'w' );
429
+    $file = fopen( $json_report_pathname, 'w' );
430 430
 
431
-	if ( false === $file ) {
432
-		wp_send_json_error( __( 'Unable to open personal data export file (JSON report) for writing.' ) );
433
-	}
431
+    if ( false === $file ) {
432
+        wp_send_json_error( __( 'Unable to open personal data export file (JSON report) for writing.' ) );
433
+    }
434 434
 
435
-	fwrite( $file, '{' );
436
-	fwrite( $file, '"' . $title . '":' );
437
-	fwrite( $file, $groups_json );
438
-	fwrite( $file, '}' );
439
-	fclose( $file );
435
+    fwrite( $file, '{' );
436
+    fwrite( $file, '"' . $title . '":' );
437
+    fwrite( $file, $groups_json );
438
+    fwrite( $file, '}' );
439
+    fclose( $file );
440 440
 
441
-	/*
441
+    /*
442 442
 	 * Handle the HTML export.
443 443
 	 */
444
-	$file = fopen( $html_report_pathname, 'w' );
445
-
446
-	if ( false === $file ) {
447
-		wp_send_json_error( __( 'Unable to open personal data export (HTML report) for writing.' ) );
448
-	}
449
-
450
-	fwrite( $file, "<!DOCTYPE html>\n" );
451
-	fwrite( $file, "<html>\n" );
452
-	fwrite( $file, "<head>\n" );
453
-	fwrite( $file, "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n" );
454
-	fwrite( $file, "<style type='text/css'>" );
455
-	fwrite( $file, 'body { color: black; font-family: Arial, sans-serif; font-size: 11pt; margin: 15px auto; width: 860px; }' );
456
-	fwrite( $file, 'table { background: #f0f0f0; border: 1px solid #ddd; margin-bottom: 20px; width: 100%; }' );
457
-	fwrite( $file, 'th { padding: 5px; text-align: left; width: 20%; }' );
458
-	fwrite( $file, 'td { padding: 5px; }' );
459
-	fwrite( $file, 'tr:nth-child(odd) { background-color: #fafafa; }' );
460
-	fwrite( $file, '.return-to-top { text-align: right; }' );
461
-	fwrite( $file, '</style>' );
462
-	fwrite( $file, '<title>' );
463
-	fwrite( $file, esc_html( $title ) );
464
-	fwrite( $file, '</title>' );
465
-	fwrite( $file, "</head>\n" );
466
-	fwrite( $file, "<body>\n" );
467
-	fwrite( $file, '<h1 id="top">' . esc_html__( 'Personal Data Export' ) . '</h1>' );
468
-
469
-	// Create TOC.
470
-	if ( $groups_count > 1 ) {
471
-		fwrite( $file, '<div id="table_of_contents">' );
472
-		fwrite( $file, '<h2>' . esc_html__( 'Table of Contents' ) . '</h2>' );
473
-		fwrite( $file, '<ul>' );
474
-		foreach ( (array) $groups as $group_id => $group_data ) {
475
-			$group_label       = esc_html( $group_data['group_label'] );
476
-			$group_id_attr     = sanitize_title_with_dashes( $group_data['group_label'] . '-' . $group_id );
477
-			$group_items_count = count( (array) $group_data['items'] );
478
-			if ( $group_items_count > 1 ) {
479
-				$group_label .= sprintf( ' <span class="count">(%d)</span>', $group_items_count );
480
-			}
481
-			fwrite( $file, '<li>' );
482
-			fwrite( $file, '<a href="#' . esc_attr( $group_id_attr ) . '">' . $group_label . '</a>' );
483
-			fwrite( $file, '</li>' );
484
-		}
485
-		fwrite( $file, '</ul>' );
486
-		fwrite( $file, '</div>' );
487
-	}
488
-
489
-	// Now, iterate over every group in $groups and have the formatter render it in HTML.
490
-	foreach ( (array) $groups as $group_id => $group_data ) {
491
-		fwrite( $file, wp_privacy_generate_personal_data_export_group_html( $group_data, $group_id, $groups_count ) );
492
-	}
493
-
494
-	fwrite( $file, "</body>\n" );
495
-	fwrite( $file, "</html>\n" );
496
-	fclose( $file );
497
-
498
-	/*
444
+    $file = fopen( $html_report_pathname, 'w' );
445
+
446
+    if ( false === $file ) {
447
+        wp_send_json_error( __( 'Unable to open personal data export (HTML report) for writing.' ) );
448
+    }
449
+
450
+    fwrite( $file, "<!DOCTYPE html>\n" );
451
+    fwrite( $file, "<html>\n" );
452
+    fwrite( $file, "<head>\n" );
453
+    fwrite( $file, "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n" );
454
+    fwrite( $file, "<style type='text/css'>" );
455
+    fwrite( $file, 'body { color: black; font-family: Arial, sans-serif; font-size: 11pt; margin: 15px auto; width: 860px; }' );
456
+    fwrite( $file, 'table { background: #f0f0f0; border: 1px solid #ddd; margin-bottom: 20px; width: 100%; }' );
457
+    fwrite( $file, 'th { padding: 5px; text-align: left; width: 20%; }' );
458
+    fwrite( $file, 'td { padding: 5px; }' );
459
+    fwrite( $file, 'tr:nth-child(odd) { background-color: #fafafa; }' );
460
+    fwrite( $file, '.return-to-top { text-align: right; }' );
461
+    fwrite( $file, '</style>' );
462
+    fwrite( $file, '<title>' );
463
+    fwrite( $file, esc_html( $title ) );
464
+    fwrite( $file, '</title>' );
465
+    fwrite( $file, "</head>\n" );
466
+    fwrite( $file, "<body>\n" );
467
+    fwrite( $file, '<h1 id="top">' . esc_html__( 'Personal Data Export' ) . '</h1>' );
468
+
469
+    // Create TOC.
470
+    if ( $groups_count > 1 ) {
471
+        fwrite( $file, '<div id="table_of_contents">' );
472
+        fwrite( $file, '<h2>' . esc_html__( 'Table of Contents' ) . '</h2>' );
473
+        fwrite( $file, '<ul>' );
474
+        foreach ( (array) $groups as $group_id => $group_data ) {
475
+            $group_label       = esc_html( $group_data['group_label'] );
476
+            $group_id_attr     = sanitize_title_with_dashes( $group_data['group_label'] . '-' . $group_id );
477
+            $group_items_count = count( (array) $group_data['items'] );
478
+            if ( $group_items_count > 1 ) {
479
+                $group_label .= sprintf( ' <span class="count">(%d)</span>', $group_items_count );
480
+            }
481
+            fwrite( $file, '<li>' );
482
+            fwrite( $file, '<a href="#' . esc_attr( $group_id_attr ) . '">' . $group_label . '</a>' );
483
+            fwrite( $file, '</li>' );
484
+        }
485
+        fwrite( $file, '</ul>' );
486
+        fwrite( $file, '</div>' );
487
+    }
488
+
489
+    // Now, iterate over every group in $groups and have the formatter render it in HTML.
490
+    foreach ( (array) $groups as $group_id => $group_data ) {
491
+        fwrite( $file, wp_privacy_generate_personal_data_export_group_html( $group_data, $group_id, $groups_count ) );
492
+    }
493
+
494
+    fwrite( $file, "</body>\n" );
495
+    fwrite( $file, "</html>\n" );
496
+    fclose( $file );
497
+
498
+    /*
499 499
 	 * Now, generate the ZIP.
500 500
 	 *
501 501
 	 * If an archive has already been generated, then remove it and reuse the filename,
502 502
 	 * to avoid breaking any URLs that may have been previously sent via email.
503 503
 	 */
504
-	$error = false;
505
-
506
-	// This meta value is used from version 5.5.
507
-	$archive_filename = get_post_meta( $request_id, '_export_file_name', true );
508
-
509
-	// This one stored an absolute path and is used for backward compatibility.
510
-	$archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
511
-
512
-	// If a filename meta exists, use it.
513
-	if ( ! empty( $archive_filename ) ) {
514
-		$archive_pathname = $exports_dir . $archive_filename;
515
-	} elseif ( ! empty( $archive_pathname ) ) {
516
-		// If a full path meta exists, use it and create the new meta value.
517
-		$archive_filename = basename( $archive_pathname );
518
-
519
-		update_post_meta( $request_id, '_export_file_name', $archive_filename );
520
-
521
-		// Remove the back-compat meta values.
522
-		delete_post_meta( $request_id, '_export_file_url' );
523
-		delete_post_meta( $request_id, '_export_file_path' );
524
-	} else {
525
-		// If there's no filename or full path stored, create a new file.
526
-		$archive_filename = $file_basename . '.zip';
527
-		$archive_pathname = $exports_dir . $archive_filename;
528
-
529
-		update_post_meta( $request_id, '_export_file_name', $archive_filename );
530
-	}
531
-
532
-	$archive_url = $exports_url . $archive_filename;
533
-
534
-	if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
535
-		wp_delete_file( $archive_pathname );
536
-	}
537
-
538
-	$zip = new ZipArchive;
539
-	if ( true === $zip->open( $archive_pathname, ZipArchive::CREATE ) ) {
540
-		if ( ! $zip->addFile( $json_report_pathname, 'export.json' ) ) {
541
-			$error = __( 'Unable to archive the personal data export file (JSON format).' );
542
-		}
543
-
544
-		if ( ! $zip->addFile( $html_report_pathname, 'index.html' ) ) {
545
-			$error = __( 'Unable to archive the personal data export file (HTML format).' );
546
-		}
547
-
548
-		$zip->close();
549
-
550
-		if ( ! $error ) {
551
-			/**
552
-			 * Fires right after all personal data has been written to the export file.
553
-			 *
554
-			 * @since 4.9.6
555
-			 * @since 5.4.0 Added the `$json_report_pathname` parameter.
556
-			 *
557
-			 * @param string $archive_pathname     The full path to the export file on the filesystem.
558
-			 * @param string $archive_url          The URL of the archive file.
559
-			 * @param string $html_report_pathname The full path to the HTML personal data report on the filesystem.
560
-			 * @param int    $request_id           The export request ID.
561
-			 * @param string $json_report_pathname The full path to the JSON personal data report on the filesystem.
562
-			 */
563
-			do_action( 'wp_privacy_personal_data_export_file_created', $archive_pathname, $archive_url, $html_report_pathname, $request_id, $json_report_pathname );
564
-		}
565
-	} else {
566
-		$error = __( 'Unable to open personal data export file (archive) for writing.' );
567
-	}
568
-
569
-	// Remove the JSON file.
570
-	unlink( $json_report_pathname );
571
-
572
-	// Remove the HTML file.
573
-	unlink( $html_report_pathname );
574
-
575
-	if ( $error ) {
576
-		wp_send_json_error( $error );
577
-	}
504
+    $error = false;
505
+
506
+    // This meta value is used from version 5.5.
507
+    $archive_filename = get_post_meta( $request_id, '_export_file_name', true );
508
+
509
+    // This one stored an absolute path and is used for backward compatibility.
510
+    $archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
511
+
512
+    // If a filename meta exists, use it.
513
+    if ( ! empty( $archive_filename ) ) {
514
+        $archive_pathname = $exports_dir . $archive_filename;
515
+    } elseif ( ! empty( $archive_pathname ) ) {
516
+        // If a full path meta exists, use it and create the new meta value.
517
+        $archive_filename = basename( $archive_pathname );
518
+
519
+        update_post_meta( $request_id, '_export_file_name', $archive_filename );
520
+
521
+        // Remove the back-compat meta values.
522
+        delete_post_meta( $request_id, '_export_file_url' );
523
+        delete_post_meta( $request_id, '_export_file_path' );
524
+    } else {
525
+        // If there's no filename or full path stored, create a new file.
526
+        $archive_filename = $file_basename . '.zip';
527
+        $archive_pathname = $exports_dir . $archive_filename;
528
+
529
+        update_post_meta( $request_id, '_export_file_name', $archive_filename );
530
+    }
531
+
532
+    $archive_url = $exports_url . $archive_filename;
533
+
534
+    if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
535
+        wp_delete_file( $archive_pathname );
536
+    }
537
+
538
+    $zip = new ZipArchive;
539
+    if ( true === $zip->open( $archive_pathname, ZipArchive::CREATE ) ) {
540
+        if ( ! $zip->addFile( $json_report_pathname, 'export.json' ) ) {
541
+            $error = __( 'Unable to archive the personal data export file (JSON format).' );
542
+        }
543
+
544
+        if ( ! $zip->addFile( $html_report_pathname, 'index.html' ) ) {
545
+            $error = __( 'Unable to archive the personal data export file (HTML format).' );
546
+        }
547
+
548
+        $zip->close();
549
+
550
+        if ( ! $error ) {
551
+            /**
552
+             * Fires right after all personal data has been written to the export file.
553
+             *
554
+             * @since 4.9.6
555
+             * @since 5.4.0 Added the `$json_report_pathname` parameter.
556
+             *
557
+             * @param string $archive_pathname     The full path to the export file on the filesystem.
558
+             * @param string $archive_url          The URL of the archive file.
559
+             * @param string $html_report_pathname The full path to the HTML personal data report on the filesystem.
560
+             * @param int    $request_id           The export request ID.
561
+             * @param string $json_report_pathname The full path to the JSON personal data report on the filesystem.
562
+             */
563
+            do_action( 'wp_privacy_personal_data_export_file_created', $archive_pathname, $archive_url, $html_report_pathname, $request_id, $json_report_pathname );
564
+        }
565
+    } else {
566
+        $error = __( 'Unable to open personal data export file (archive) for writing.' );
567
+    }
568
+
569
+    // Remove the JSON file.
570
+    unlink( $json_report_pathname );
571
+
572
+    // Remove the HTML file.
573
+    unlink( $html_report_pathname );
574
+
575
+    if ( $error ) {
576
+        wp_send_json_error( $error );
577
+    }
578 578
 }
579 579
 
580 580
 /**
@@ -586,83 +586,83 @@  discard block
 block discarded – undo
586 586
  * @return true|WP_Error True on success or `WP_Error` on failure.
587 587
  */
588 588
 function wp_privacy_send_personal_data_export_email( $request_id ) {
589
-	// Get the request.
590
-	$request = wp_get_user_request( $request_id );
591
-
592
-	if ( ! $request || 'export_personal_data' !== $request->action_name ) {
593
-		return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) );
594
-	}
595
-
596
-	// Localize message content for user; fallback to site default for visitors.
597
-	if ( ! empty( $request->user_id ) ) {
598
-		$locale = get_user_locale( $request->user_id );
599
-	} else {
600
-		$locale = get_locale();
601
-	}
602
-
603
-	$switched_locale = switch_to_locale( $locale );
604
-
605
-	/** This filter is documented in wp-includes/functions.php */
606
-	$expiration      = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
607
-	$expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
608
-
609
-	$exports_url      = wp_privacy_exports_url();
610
-	$export_file_name = get_post_meta( $request_id, '_export_file_name', true );
611
-	$export_file_url  = $exports_url . $export_file_name;
612
-
613
-	$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
614
-	$site_url  = home_url();
615
-
616
-	/**
617
-	 * Filters the recipient of the personal data export email notification.
618
-	 * Should be used with great caution to avoid sending the data export link to wrong emails.
619
-	 *
620
-	 * @since 5.3.0
621
-	 *
622
-	 * @param string          $request_email The email address of the notification recipient.
623
-	 * @param WP_User_Request $request       The request that is initiating the notification.
624
-	 */
625
-	$request_email = apply_filters( 'wp_privacy_personal_data_email_to', $request->email, $request );
626
-
627
-	$email_data = array(
628
-		'request'           => $request,
629
-		'expiration'        => $expiration,
630
-		'expiration_date'   => $expiration_date,
631
-		'message_recipient' => $request_email,
632
-		'export_file_url'   => $export_file_url,
633
-		'sitename'          => $site_name,
634
-		'siteurl'           => $site_url,
635
-	);
636
-
637
-	/* translators: Personal data export notification email subject. %s: Site title. */
638
-	$subject = sprintf( __( '[%s] Personal Data Export' ), $site_name );
639
-
640
-	/**
641
-	 * Filters the subject of the email sent when an export request is completed.
642
-	 *
643
-	 * @since 5.3.0
644
-	 *
645
-	 * @param string $subject    The email subject.
646
-	 * @param string $sitename   The name of the site.
647
-	 * @param array  $email_data {
648
-	 *     Data relating to the account action email.
649
-	 *
650
-	 *     @type WP_User_Request $request           User request object.
651
-	 *     @type int             $expiration        The time in seconds until the export file expires.
652
-	 *     @type string          $expiration_date   The localized date and time when the export file expires.
653
-	 *     @type string          $message_recipient The address that the email will be sent to. Defaults
654
-	 *                                              to the value of `$request->email`, but can be changed
655
-	 *                                              by the `wp_privacy_personal_data_email_to` filter.
656
-	 *     @type string          $export_file_url   The export file URL.
657
-	 *     @type string          $sitename          The site name sending the mail.
658
-	 *     @type string          $siteurl           The site URL sending the mail.
659
-	 * }
660
-	 */
661
-	$subject = apply_filters( 'wp_privacy_personal_data_email_subject', $subject, $site_name, $email_data );
662
-
663
-	/* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
664
-	$email_text = __(
665
-		'Howdy,
589
+    // Get the request.
590
+    $request = wp_get_user_request( $request_id );
591
+
592
+    if ( ! $request || 'export_personal_data' !== $request->action_name ) {
593
+        return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) );
594
+    }
595
+
596
+    // Localize message content for user; fallback to site default for visitors.
597
+    if ( ! empty( $request->user_id ) ) {
598
+        $locale = get_user_locale( $request->user_id );
599
+    } else {
600
+        $locale = get_locale();
601
+    }
602
+
603
+    $switched_locale = switch_to_locale( $locale );
604
+
605
+    /** This filter is documented in wp-includes/functions.php */
606
+    $expiration      = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
607
+    $expiration_date = date_i18n( get_option( 'date_format' ), time() + $expiration );
608
+
609
+    $exports_url      = wp_privacy_exports_url();
610
+    $export_file_name = get_post_meta( $request_id, '_export_file_name', true );
611
+    $export_file_url  = $exports_url . $export_file_name;
612
+
613
+    $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
614
+    $site_url  = home_url();
615
+
616
+    /**
617
+     * Filters the recipient of the personal data export email notification.
618
+     * Should be used with great caution to avoid sending the data export link to wrong emails.
619
+     *
620
+     * @since 5.3.0
621
+     *
622
+     * @param string          $request_email The email address of the notification recipient.
623
+     * @param WP_User_Request $request       The request that is initiating the notification.
624
+     */
625
+    $request_email = apply_filters( 'wp_privacy_personal_data_email_to', $request->email, $request );
626
+
627
+    $email_data = array(
628
+        'request'           => $request,
629
+        'expiration'        => $expiration,
630
+        'expiration_date'   => $expiration_date,
631
+        'message_recipient' => $request_email,
632
+        'export_file_url'   => $export_file_url,
633
+        'sitename'          => $site_name,
634
+        'siteurl'           => $site_url,
635
+    );
636
+
637
+    /* translators: Personal data export notification email subject. %s: Site title. */
638
+    $subject = sprintf( __( '[%s] Personal Data Export' ), $site_name );
639
+
640
+    /**
641
+     * Filters the subject of the email sent when an export request is completed.
642
+     *
643
+     * @since 5.3.0
644
+     *
645
+     * @param string $subject    The email subject.
646
+     * @param string $sitename   The name of the site.
647
+     * @param array  $email_data {
648
+     *     Data relating to the account action email.
649
+     *
650
+     *     @type WP_User_Request $request           User request object.
651
+     *     @type int             $expiration        The time in seconds until the export file expires.
652
+     *     @type string          $expiration_date   The localized date and time when the export file expires.
653
+     *     @type string          $message_recipient The address that the email will be sent to. Defaults
654
+     *                                              to the value of `$request->email`, but can be changed
655
+     *                                              by the `wp_privacy_personal_data_email_to` filter.
656
+     *     @type string          $export_file_url   The export file URL.
657
+     *     @type string          $sitename          The site name sending the mail.
658
+     *     @type string          $siteurl           The site URL sending the mail.
659
+     * }
660
+     */
661
+    $subject = apply_filters( 'wp_privacy_personal_data_email_subject', $subject, $site_name, $email_data );
662
+
663
+    /* translators: Do not translate EXPIRATION, LINK, SITENAME, SITEURL: those are placeholders. */
664
+    $email_text = __(
665
+        'Howdy,
666 666
 
667 667
 Your request for an export of personal data has been completed. You may
668 668
 download your personal data by clicking on the link below. For privacy
@@ -674,81 +674,81 @@  discard block
 block discarded – undo
674 674
 Regards,
675 675
 All at ###SITENAME###
676 676
 ###SITEURL###'
677
-	);
678
-
679
-	/**
680
-	 * Filters the text of the email sent with a personal data export file.
681
-	 *
682
-	 * The following strings have a special meaning and will get replaced dynamically:
683
-	 * ###EXPIRATION###         The date when the URL will be automatically deleted.
684
-	 * ###LINK###               URL of the personal data export file for the user.
685
-	 * ###SITENAME###           The name of the site.
686
-	 * ###SITEURL###            The URL to the site.
687
-	 *
688
-	 * @since 4.9.6
689
-	 * @since 5.3.0 Introduced the `$email_data` array.
690
-	 *
691
-	 * @param string $email_text Text in the email.
692
-	 * @param int    $request_id The request ID for this personal data export.
693
-	 * @param array  $email_data {
694
-	 *     Data relating to the account action email.
695
-	 *
696
-	 *     @type WP_User_Request $request           User request object.
697
-	 *     @type int             $expiration        The time in seconds until the export file expires.
698
-	 *     @type string          $expiration_date   The localized date and time when the export file expires.
699
-	 *     @type string          $message_recipient The address that the email will be sent to. Defaults
700
-	 *                                              to the value of `$request->email`, but can be changed
701
-	 *                                              by the `wp_privacy_personal_data_email_to` filter.
702
-	 *     @type string          $export_file_url   The export file URL.
703
-	 *     @type string          $sitename          The site name sending the mail.
704
-	 *     @type string          $siteurl           The site URL sending the mail.
705
-	 */
706
-	$content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $email_data );
707
-
708
-	$content = str_replace( '###EXPIRATION###', $expiration_date, $content );
709
-	$content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
710
-	$content = str_replace( '###EMAIL###', $request_email, $content );
711
-	$content = str_replace( '###SITENAME###', $site_name, $content );
712
-	$content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
713
-
714
-	$headers = '';
715
-
716
-	/**
717
-	 * Filters the headers of the email sent with a personal data export file.
718
-	 *
719
-	 * @since 5.4.0
720
-	 *
721
-	 * @param string|array $headers    The email headers.
722
-	 * @param string       $subject    The email subject.
723
-	 * @param string       $content    The email content.
724
-	 * @param int          $request_id The request ID.
725
-	 * @param array        $email_data {
726
-	 *     Data relating to the account action email.
727
-	 *
728
-	 *     @type WP_User_Request $request           User request object.
729
-	 *     @type int             $expiration        The time in seconds until the export file expires.
730
-	 *     @type string          $expiration_date   The localized date and time when the export file expires.
731
-	 *     @type string          $message_recipient The address that the email will be sent to. Defaults
732
-	 *                                              to the value of `$request->email`, but can be changed
733
-	 *                                              by the `wp_privacy_personal_data_email_to` filter.
734
-	 *     @type string          $export_file_url   The export file URL.
735
-	 *     @type string          $sitename          The site name sending the mail.
736
-	 *     @type string          $siteurl           The site URL sending the mail.
737
-	 * }
738
-	 */
739
-	$headers = apply_filters( 'wp_privacy_personal_data_email_headers', $headers, $subject, $content, $request_id, $email_data );
740
-
741
-	$mail_success = wp_mail( $request_email, $subject, $content, $headers );
742
-
743
-	if ( $switched_locale ) {
744
-		restore_previous_locale();
745
-	}
746
-
747
-	if ( ! $mail_success ) {
748
-		return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export email.' ) );
749
-	}
750
-
751
-	return true;
677
+    );
678
+
679
+    /**
680
+     * Filters the text of the email sent with a personal data export file.
681
+     *
682
+     * The following strings have a special meaning and will get replaced dynamically:
683
+     * ###EXPIRATION###         The date when the URL will be automatically deleted.
684
+     * ###LINK###               URL of the personal data export file for the user.
685
+     * ###SITENAME###           The name of the site.
686
+     * ###SITEURL###            The URL to the site.
687
+     *
688
+     * @since 4.9.6
689
+     * @since 5.3.0 Introduced the `$email_data` array.
690
+     *
691
+     * @param string $email_text Text in the email.
692
+     * @param int    $request_id The request ID for this personal data export.
693
+     * @param array  $email_data {
694
+     *     Data relating to the account action email.
695
+     *
696
+     *     @type WP_User_Request $request           User request object.
697
+     *     @type int             $expiration        The time in seconds until the export file expires.
698
+     *     @type string          $expiration_date   The localized date and time when the export file expires.
699
+     *     @type string          $message_recipient The address that the email will be sent to. Defaults
700
+     *                                              to the value of `$request->email`, but can be changed
701
+     *                                              by the `wp_privacy_personal_data_email_to` filter.
702
+     *     @type string          $export_file_url   The export file URL.
703
+     *     @type string          $sitename          The site name sending the mail.
704
+     *     @type string          $siteurl           The site URL sending the mail.
705
+     */
706
+    $content = apply_filters( 'wp_privacy_personal_data_email_content', $email_text, $request_id, $email_data );
707
+
708
+    $content = str_replace( '###EXPIRATION###', $expiration_date, $content );
709
+    $content = str_replace( '###LINK###', esc_url_raw( $export_file_url ), $content );
710
+    $content = str_replace( '###EMAIL###', $request_email, $content );
711
+    $content = str_replace( '###SITENAME###', $site_name, $content );
712
+    $content = str_replace( '###SITEURL###', esc_url_raw( $site_url ), $content );
713
+
714
+    $headers = '';
715
+
716
+    /**
717
+     * Filters the headers of the email sent with a personal data export file.
718
+     *
719
+     * @since 5.4.0
720
+     *
721
+     * @param string|array $headers    The email headers.
722
+     * @param string       $subject    The email subject.
723
+     * @param string       $content    The email content.
724
+     * @param int          $request_id The request ID.
725
+     * @param array        $email_data {
726
+     *     Data relating to the account action email.
727
+     *
728
+     *     @type WP_User_Request $request           User request object.
729
+     *     @type int             $expiration        The time in seconds until the export file expires.
730
+     *     @type string          $expiration_date   The localized date and time when the export file expires.
731
+     *     @type string          $message_recipient The address that the email will be sent to. Defaults
732
+     *                                              to the value of `$request->email`, but can be changed
733
+     *                                              by the `wp_privacy_personal_data_email_to` filter.
734
+     *     @type string          $export_file_url   The export file URL.
735
+     *     @type string          $sitename          The site name sending the mail.
736
+     *     @type string          $siteurl           The site URL sending the mail.
737
+     * }
738
+     */
739
+    $headers = apply_filters( 'wp_privacy_personal_data_email_headers', $headers, $subject, $content, $request_id, $email_data );
740
+
741
+    $mail_success = wp_mail( $request_email, $subject, $content, $headers );
742
+
743
+    if ( $switched_locale ) {
744
+        restore_previous_locale();
745
+    }
746
+
747
+    if ( ! $mail_success ) {
748
+        return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export email.' ) );
749
+    }
750
+
751
+    return true;
752 752
 }
753 753
 
754 754
 /**
@@ -768,127 +768,127 @@  discard block
 block discarded – undo
768 768
  * @return array The filtered response.
769 769
  */
770 770
 function wp_privacy_process_personal_data_export_page( $response, $exporter_index, $email_address, $page, $request_id, $send_as_email, $exporter_key ) {
771
-	/* Do some simple checks on the shape of the response from the exporter.
771
+    /* Do some simple checks on the shape of the response from the exporter.
772 772
 	 * If the exporter response is malformed, don't attempt to consume it - let it
773 773
 	 * pass through to generate a warning to the user by default Ajax processing.
774 774
 	 */
775
-	if ( ! is_array( $response ) ) {
776
-		return $response;
777
-	}
778
-
779
-	if ( ! array_key_exists( 'done', $response ) ) {
780
-		return $response;
781
-	}
782
-
783
-	if ( ! array_key_exists( 'data', $response ) ) {
784
-		return $response;
785
-	}
786
-
787
-	if ( ! is_array( $response['data'] ) ) {
788
-		return $response;
789
-	}
790
-
791
-	// Get the request.
792
-	$request = wp_get_user_request( $request_id );
793
-
794
-	if ( ! $request || 'export_personal_data' !== $request->action_name ) {
795
-		wp_send_json_error( __( 'Invalid request ID when merging personal data to export.' ) );
796
-	}
797
-
798
-	$export_data = array();
799
-
800
-	// First exporter, first page? Reset the report data accumulation array.
801
-	if ( 1 === $exporter_index && 1 === $page ) {
802
-		update_post_meta( $request_id, '_export_data_raw', $export_data );
803
-	} else {
804
-		$accumulated_data = get_post_meta( $request_id, '_export_data_raw', true );
805
-
806
-		if ( $accumulated_data ) {
807
-			$export_data = $accumulated_data;
808
-		}
809
-	}
810
-
811
-	// Now, merge the data from the exporter response into the data we have accumulated already.
812
-	$export_data = array_merge( $export_data, $response['data'] );
813
-	update_post_meta( $request_id, '_export_data_raw', $export_data );
814
-
815
-	// If we are not yet on the last page of the last exporter, return now.
816
-	/** This filter is documented in wp-admin/includes/ajax-actions.php */
817
-	$exporters        = apply_filters( 'wp_privacy_personal_data_exporters', array() );
818
-	$is_last_exporter = count( $exporters ) === $exporter_index;
819
-	$exporter_done    = $response['done'];
820
-	if ( ! $is_last_exporter || ! $exporter_done ) {
821
-		return $response;
822
-	}
823
-
824
-	// Last exporter, last page - let's prepare the export file.
825
-
826
-	// First we need to re-organize the raw data hierarchically in groups and items.
827
-	$groups = array();
828
-	foreach ( (array) $export_data as $export_datum ) {
829
-		$group_id    = $export_datum['group_id'];
830
-		$group_label = $export_datum['group_label'];
831
-
832
-		$group_description = '';
833
-		if ( ! empty( $export_datum['group_description'] ) ) {
834
-			$group_description = $export_datum['group_description'];
835
-		}
836
-
837
-		if ( ! array_key_exists( $group_id, $groups ) ) {
838
-			$groups[ $group_id ] = array(
839
-				'group_label'       => $group_label,
840
-				'group_description' => $group_description,
841
-				'items'             => array(),
842
-			);
843
-		}
844
-
845
-		$item_id = $export_datum['item_id'];
846
-		if ( ! array_key_exists( $item_id, $groups[ $group_id ]['items'] ) ) {
847
-			$groups[ $group_id ]['items'][ $item_id ] = array();
848
-		}
849
-
850
-		$old_item_data                            = $groups[ $group_id ]['items'][ $item_id ];
851
-		$merged_item_data                         = array_merge( $export_datum['data'], $old_item_data );
852
-		$groups[ $group_id ]['items'][ $item_id ] = $merged_item_data;
853
-	}
854
-
855
-	// Then save the grouped data into the request.
856
-	delete_post_meta( $request_id, '_export_data_raw' );
857
-	update_post_meta( $request_id, '_export_data_grouped', $groups );
858
-
859
-	/**
860
-	 * Generate the export file from the collected, grouped personal data.
861
-	 *
862
-	 * @since 4.9.6
863
-	 *
864
-	 * @param int $request_id The export request ID.
865
-	 */
866
-	do_action( 'wp_privacy_personal_data_export_file', $request_id );
867
-
868
-	// Clear the grouped data now that it is no longer needed.
869
-	delete_post_meta( $request_id, '_export_data_grouped' );
870
-
871
-	// If the destination is email, send it now.
872
-	if ( $send_as_email ) {
873
-		$mail_success = wp_privacy_send_personal_data_export_email( $request_id );
874
-		if ( is_wp_error( $mail_success ) ) {
875
-			wp_send_json_error( $mail_success->get_error_message() );
876
-		}
877
-
878
-		// Update the request to completed state when the export email is sent.
879
-		_wp_privacy_completed_request( $request_id );
880
-	} else {
881
-		// Modify the response to include the URL of the export file so the browser can fetch it.
882
-		$exports_url      = wp_privacy_exports_url();
883
-		$export_file_name = get_post_meta( $request_id, '_export_file_name', true );
884
-		$export_file_url  = $exports_url . $export_file_name;
885
-
886
-		if ( ! empty( $export_file_url ) ) {
887
-			$response['url'] = $export_file_url;
888
-		}
889
-	}
890
-
891
-	return $response;
775
+    if ( ! is_array( $response ) ) {
776
+        return $response;
777
+    }
778
+
779
+    if ( ! array_key_exists( 'done', $response ) ) {
780
+        return $response;
781
+    }
782
+
783
+    if ( ! array_key_exists( 'data', $response ) ) {
784
+        return $response;
785
+    }
786
+
787
+    if ( ! is_array( $response['data'] ) ) {
788
+        return $response;
789
+    }
790
+
791
+    // Get the request.
792
+    $request = wp_get_user_request( $request_id );
793
+
794
+    if ( ! $request || 'export_personal_data' !== $request->action_name ) {
795
+        wp_send_json_error( __( 'Invalid request ID when merging personal data to export.' ) );
796
+    }
797
+
798
+    $export_data = array();
799
+
800
+    // First exporter, first page? Reset the report data accumulation array.
801
+    if ( 1 === $exporter_index && 1 === $page ) {
802
+        update_post_meta( $request_id, '_export_data_raw', $export_data );
803
+    } else {
804
+        $accumulated_data = get_post_meta( $request_id, '_export_data_raw', true );
805
+
806
+        if ( $accumulated_data ) {
807
+            $export_data = $accumulated_data;
808
+        }
809
+    }
810
+
811
+    // Now, merge the data from the exporter response into the data we have accumulated already.
812
+    $export_data = array_merge( $export_data, $response['data'] );
813
+    update_post_meta( $request_id, '_export_data_raw', $export_data );
814
+
815
+    // If we are not yet on the last page of the last exporter, return now.
816
+    /** This filter is documented in wp-admin/includes/ajax-actions.php */
817
+    $exporters        = apply_filters( 'wp_privacy_personal_data_exporters', array() );
818
+    $is_last_exporter = count( $exporters ) === $exporter_index;
819
+    $exporter_done    = $response['done'];
820
+    if ( ! $is_last_exporter || ! $exporter_done ) {
821
+        return $response;
822
+    }
823
+
824
+    // Last exporter, last page - let's prepare the export file.
825
+
826
+    // First we need to re-organize the raw data hierarchically in groups and items.
827
+    $groups = array();
828
+    foreach ( (array) $export_data as $export_datum ) {
829
+        $group_id    = $export_datum['group_id'];
830
+        $group_label = $export_datum['group_label'];
831
+
832
+        $group_description = '';
833
+        if ( ! empty( $export_datum['group_description'] ) ) {
834
+            $group_description = $export_datum['group_description'];
835
+        }
836
+
837
+        if ( ! array_key_exists( $group_id, $groups ) ) {
838
+            $groups[ $group_id ] = array(
839
+                'group_label'       => $group_label,
840
+                'group_description' => $group_description,
841
+                'items'             => array(),
842
+            );
843
+        }
844
+
845
+        $item_id = $export_datum['item_id'];
846
+        if ( ! array_key_exists( $item_id, $groups[ $group_id ]['items'] ) ) {
847
+            $groups[ $group_id ]['items'][ $item_id ] = array();
848
+        }
849
+
850
+        $old_item_data                            = $groups[ $group_id ]['items'][ $item_id ];
851
+        $merged_item_data                         = array_merge( $export_datum['data'], $old_item_data );
852
+        $groups[ $group_id ]['items'][ $item_id ] = $merged_item_data;
853
+    }
854
+
855
+    // Then save the grouped data into the request.
856
+    delete_post_meta( $request_id, '_export_data_raw' );
857
+    update_post_meta( $request_id, '_export_data_grouped', $groups );
858
+
859
+    /**
860
+     * Generate the export file from the collected, grouped personal data.
861
+     *
862
+     * @since 4.9.6
863
+     *
864
+     * @param int $request_id The export request ID.
865
+     */
866
+    do_action( 'wp_privacy_personal_data_export_file', $request_id );
867
+
868
+    // Clear the grouped data now that it is no longer needed.
869
+    delete_post_meta( $request_id, '_export_data_grouped' );
870
+
871
+    // If the destination is email, send it now.
872
+    if ( $send_as_email ) {
873
+        $mail_success = wp_privacy_send_personal_data_export_email( $request_id );
874
+        if ( is_wp_error( $mail_success ) ) {
875
+            wp_send_json_error( $mail_success->get_error_message() );
876
+        }
877
+
878
+        // Update the request to completed state when the export email is sent.
879
+        _wp_privacy_completed_request( $request_id );
880
+    } else {
881
+        // Modify the response to include the URL of the export file so the browser can fetch it.
882
+        $exports_url      = wp_privacy_exports_url();
883
+        $export_file_name = get_post_meta( $request_id, '_export_file_name', true );
884
+        $export_file_url  = $exports_url . $export_file_name;
885
+
886
+        if ( ! empty( $export_file_url ) ) {
887
+            $response['url'] = $export_file_url;
888
+        }
889
+    }
890
+
891
+    return $response;
892 892
 }
893 893
 
894 894
 /**
@@ -914,57 +914,57 @@  discard block
 block discarded – undo
914 914
  * @return array The filtered response.
915 915
  */
916 916
 function wp_privacy_process_personal_data_erasure_page( $response, $eraser_index, $email_address, $page, $request_id ) {
917
-	/*
917
+    /*
918 918
 	 * If the eraser response is malformed, don't attempt to consume it; let it
919 919
 	 * pass through, so that the default Ajax processing will generate a warning
920 920
 	 * to the user.
921 921
 	 */
922
-	if ( ! is_array( $response ) ) {
923
-		return $response;
924
-	}
925
-
926
-	if ( ! array_key_exists( 'done', $response ) ) {
927
-		return $response;
928
-	}
929
-
930
-	if ( ! array_key_exists( 'items_removed', $response ) ) {
931
-		return $response;
932
-	}
933
-
934
-	if ( ! array_key_exists( 'items_retained', $response ) ) {
935
-		return $response;
936
-	}
937
-
938
-	if ( ! array_key_exists( 'messages', $response ) ) {
939
-		return $response;
940
-	}
941
-
942
-	// Get the request.
943
-	$request = wp_get_user_request( $request_id );
944
-
945
-	if ( ! $request || 'remove_personal_data' !== $request->action_name ) {
946
-		wp_send_json_error( __( 'Invalid request ID when processing personal data to erase.' ) );
947
-	}
948
-
949
-	/** This filter is documented in wp-admin/includes/ajax-actions.php */
950
-	$erasers        = apply_filters( 'wp_privacy_personal_data_erasers', array() );
951
-	$is_last_eraser = count( $erasers ) === $eraser_index;
952
-	$eraser_done    = $response['done'];
953
-
954
-	if ( ! $is_last_eraser || ! $eraser_done ) {
955
-		return $response;
956
-	}
957
-
958
-	_wp_privacy_completed_request( $request_id );
959
-
960
-	/**
961
-	 * Fires immediately after a personal data erasure request has been marked completed.
962
-	 *
963
-	 * @since 4.9.6
964
-	 *
965
-	 * @param int $request_id The privacy request post ID associated with this request.
966
-	 */
967
-	do_action( 'wp_privacy_personal_data_erased', $request_id );
968
-
969
-	return $response;
922
+    if ( ! is_array( $response ) ) {
923
+        return $response;
924
+    }
925
+
926
+    if ( ! array_key_exists( 'done', $response ) ) {
927
+        return $response;
928
+    }
929
+
930
+    if ( ! array_key_exists( 'items_removed', $response ) ) {
931
+        return $response;
932
+    }
933
+
934
+    if ( ! array_key_exists( 'items_retained', $response ) ) {
935
+        return $response;
936
+    }
937
+
938
+    if ( ! array_key_exists( 'messages', $response ) ) {
939
+        return $response;
940
+    }
941
+
942
+    // Get the request.
943
+    $request = wp_get_user_request( $request_id );
944
+
945
+    if ( ! $request || 'remove_personal_data' !== $request->action_name ) {
946
+        wp_send_json_error( __( 'Invalid request ID when processing personal data to erase.' ) );
947
+    }
948
+
949
+    /** This filter is documented in wp-admin/includes/ajax-actions.php */
950
+    $erasers        = apply_filters( 'wp_privacy_personal_data_erasers', array() );
951
+    $is_last_eraser = count( $erasers ) === $eraser_index;
952
+    $eraser_done    = $response['done'];
953
+
954
+    if ( ! $is_last_eraser || ! $eraser_done ) {
955
+        return $response;
956
+    }
957
+
958
+    _wp_privacy_completed_request( $request_id );
959
+
960
+    /**
961
+     * Fires immediately after a personal data erasure request has been marked completed.
962
+     *
963
+     * @since 4.9.6
964
+     *
965
+     * @param int $request_id The privacy request post ID associated with this request.
966
+     */
967
+    do_action( 'wp_privacy_personal_data_erased', $request_id );
968
+
969
+    return $response;
970 970
 }
Please login to merge, or discard this patch.
brighty/wp-admin/includes/user.php 1 patch
Indentation   +463 added lines, -463 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  * @return int|WP_Error WP_Error or User ID.
15 15
  */
16 16
 function add_user() {
17
-	return edit_user();
17
+    return edit_user();
18 18
 }
19 19
 
20 20
 /**
@@ -28,219 +28,219 @@  discard block
 block discarded – undo
28 28
  * @return int|WP_Error User ID of the updated user or WP_Error on failure.
29 29
  */
30 30
 function edit_user( $user_id = 0 ) {
31
-	$wp_roles = wp_roles();
32
-	$user     = new stdClass;
33
-	$user_id  = (int) $user_id;
34
-	if ( $user_id ) {
35
-		$update           = true;
36
-		$user->ID         = $user_id;
37
-		$userdata         = get_userdata( $user_id );
38
-		$user->user_login = wp_slash( $userdata->user_login );
39
-	} else {
40
-		$update = false;
41
-	}
42
-
43
-	if ( ! $update && isset( $_POST['user_login'] ) ) {
44
-		$user->user_login = sanitize_user( wp_unslash( $_POST['user_login'] ), true );
45
-	}
46
-
47
-	$pass1 = '';
48
-	$pass2 = '';
49
-	if ( isset( $_POST['pass1'] ) ) {
50
-		$pass1 = trim( $_POST['pass1'] );
51
-	}
52
-	if ( isset( $_POST['pass2'] ) ) {
53
-		$pass2 = trim( $_POST['pass2'] );
54
-	}
55
-
56
-	if ( isset( $_POST['role'] ) && current_user_can( 'promote_users' ) && ( ! $user_id || current_user_can( 'promote_user', $user_id ) ) ) {
57
-		$new_role = sanitize_text_field( $_POST['role'] );
58
-
59
-		// If the new role isn't editable by the logged-in user die with error.
60
-		$editable_roles = get_editable_roles();
61
-		if ( ! empty( $new_role ) && empty( $editable_roles[ $new_role ] ) ) {
62
-			wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
63
-		}
64
-
65
-		$potential_role = isset( $wp_roles->role_objects[ $new_role ] ) ? $wp_roles->role_objects[ $new_role ] : false;
66
-
67
-		/*
31
+    $wp_roles = wp_roles();
32
+    $user     = new stdClass;
33
+    $user_id  = (int) $user_id;
34
+    if ( $user_id ) {
35
+        $update           = true;
36
+        $user->ID         = $user_id;
37
+        $userdata         = get_userdata( $user_id );
38
+        $user->user_login = wp_slash( $userdata->user_login );
39
+    } else {
40
+        $update = false;
41
+    }
42
+
43
+    if ( ! $update && isset( $_POST['user_login'] ) ) {
44
+        $user->user_login = sanitize_user( wp_unslash( $_POST['user_login'] ), true );
45
+    }
46
+
47
+    $pass1 = '';
48
+    $pass2 = '';
49
+    if ( isset( $_POST['pass1'] ) ) {
50
+        $pass1 = trim( $_POST['pass1'] );
51
+    }
52
+    if ( isset( $_POST['pass2'] ) ) {
53
+        $pass2 = trim( $_POST['pass2'] );
54
+    }
55
+
56
+    if ( isset( $_POST['role'] ) && current_user_can( 'promote_users' ) && ( ! $user_id || current_user_can( 'promote_user', $user_id ) ) ) {
57
+        $new_role = sanitize_text_field( $_POST['role'] );
58
+
59
+        // If the new role isn't editable by the logged-in user die with error.
60
+        $editable_roles = get_editable_roles();
61
+        if ( ! empty( $new_role ) && empty( $editable_roles[ $new_role ] ) ) {
62
+            wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
63
+        }
64
+
65
+        $potential_role = isset( $wp_roles->role_objects[ $new_role ] ) ? $wp_roles->role_objects[ $new_role ] : false;
66
+
67
+        /*
68 68
 		 * Don't let anyone with 'promote_users' edit their own role to something without it.
69 69
 		 * Multisite super admins can freely edit their roles, they possess all caps.
70 70
 		 */
71
-		if (
72
-			( is_multisite() && current_user_can( 'manage_network_users' ) ) ||
73
-			get_current_user_id() !== $user_id ||
74
-			( $potential_role && $potential_role->has_cap( 'promote_users' ) )
75
-		) {
76
-			$user->role = $new_role;
77
-		}
78
-	}
79
-
80
-	if ( isset( $_POST['email'] ) ) {
81
-		$user->user_email = sanitize_text_field( wp_unslash( $_POST['email'] ) );
82
-	}
83
-	if ( isset( $_POST['url'] ) ) {
84
-		if ( empty( $_POST['url'] ) || 'http://' === $_POST['url'] ) {
85
-			$user->user_url = '';
86
-		} else {
87
-			$user->user_url = esc_url_raw( $_POST['url'] );
88
-			$protocols      = implode( '|', array_map( 'preg_quote', wp_allowed_protocols() ) );
89
-			$user->user_url = preg_match( '/^(' . $protocols . '):/is', $user->user_url ) ? $user->user_url : 'http://' . $user->user_url;
90
-		}
91
-	}
92
-	if ( isset( $_POST['first_name'] ) ) {
93
-		$user->first_name = sanitize_text_field( $_POST['first_name'] );
94
-	}
95
-	if ( isset( $_POST['last_name'] ) ) {
96
-		$user->last_name = sanitize_text_field( $_POST['last_name'] );
97
-	}
98
-	if ( isset( $_POST['nickname'] ) ) {
99
-		$user->nickname = sanitize_text_field( $_POST['nickname'] );
100
-	}
101
-	if ( isset( $_POST['display_name'] ) ) {
102
-		$user->display_name = sanitize_text_field( $_POST['display_name'] );
103
-	}
104
-
105
-	if ( isset( $_POST['description'] ) ) {
106
-		$user->description = trim( $_POST['description'] );
107
-	}
108
-
109
-	foreach ( wp_get_user_contact_methods( $user ) as $method => $name ) {
110
-		if ( isset( $_POST[ $method ] ) ) {
111
-			$user->$method = sanitize_text_field( $_POST[ $method ] );
112
-		}
113
-	}
114
-
115
-	if ( isset( $_POST['locale'] ) ) {
116
-		$locale = sanitize_text_field( $_POST['locale'] );
117
-		if ( 'site-default' === $locale ) {
118
-			$locale = '';
119
-		} elseif ( '' === $locale ) {
120
-			$locale = 'en_US';
121
-		} elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
122
-			$locale = '';
123
-		}
124
-
125
-		$user->locale = $locale;
126
-	}
127
-
128
-	if ( $update ) {
129
-		$user->rich_editing         = isset( $_POST['rich_editing'] ) && 'false' === $_POST['rich_editing'] ? 'false' : 'true';
130
-		$user->syntax_highlighting  = isset( $_POST['syntax_highlighting'] ) && 'false' === $_POST['syntax_highlighting'] ? 'false' : 'true';
131
-		$user->admin_color          = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh';
132
-		$user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false';
133
-	}
134
-
135
-	$user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' === $_POST['comment_shortcuts'] ? 'true' : '';
136
-
137
-	$user->use_ssl = 0;
138
-	if ( ! empty( $_POST['use_ssl'] ) ) {
139
-		$user->use_ssl = 1;
140
-	}
141
-
142
-	$errors = new WP_Error();
143
-
144
-	/* checking that username has been typed */
145
-	if ( '' === $user->user_login ) {
146
-		$errors->add( 'user_login', __( '<strong>Error</strong>: Please enter a username.' ) );
147
-	}
148
-
149
-	/* checking that nickname has been typed */
150
-	if ( $update && empty( $user->nickname ) ) {
151
-		$errors->add( 'nickname', __( '<strong>Error</strong>: Please enter a nickname.' ) );
152
-	}
153
-
154
-	/**
155
-	 * Fires before the password and confirm password fields are checked for congruity.
156
-	 *
157
-	 * @since 1.5.1
158
-	 *
159
-	 * @param string $user_login The username.
160
-	 * @param string $pass1     The password (passed by reference).
161
-	 * @param string $pass2     The confirmed password (passed by reference).
162
-	 */
163
-	do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) );
164
-
165
-	// Check for blank password when adding a user.
166
-	if ( ! $update && empty( $pass1 ) ) {
167
-		$errors->add( 'pass', __( '<strong>Error</strong>: Please enter a password.' ), array( 'form-field' => 'pass1' ) );
168
-	}
169
-
170
-	// Check for "\" in password.
171
-	if ( false !== strpos( wp_unslash( $pass1 ), '\\' ) ) {
172
-		$errors->add( 'pass', __( '<strong>Error</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );
173
-	}
174
-
175
-	// Checking the password has been typed twice the same.
176
-	if ( ( $update || ! empty( $pass1 ) ) && $pass1 != $pass2 ) {
177
-		$errors->add( 'pass', __( '<strong>Error</strong>: Passwords do not match. Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) );
178
-	}
179
-
180
-	if ( ! empty( $pass1 ) ) {
181
-		$user->user_pass = $pass1;
182
-	}
183
-
184
-	if ( ! $update && isset( $_POST['user_login'] ) && ! validate_username( $_POST['user_login'] ) ) {
185
-		$errors->add( 'user_login', __( '<strong>Error</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
186
-	}
187
-
188
-	if ( ! $update && username_exists( $user->user_login ) ) {
189
-		$errors->add( 'user_login', __( '<strong>Error</strong>: This username is already registered. Please choose another one.' ) );
190
-	}
191
-
192
-	/** This filter is documented in wp-includes/user.php */
193
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
194
-
195
-	if ( in_array( strtolower( $user->user_login ), array_map( 'strtolower', $illegal_logins ), true ) ) {
196
-		$errors->add( 'invalid_username', __( '<strong>Error</strong>: Sorry, that username is not allowed.' ) );
197
-	}
198
-
199
-	/* checking email address */
200
-	if ( empty( $user->user_email ) ) {
201
-		$errors->add( 'empty_email', __( '<strong>Error</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) );
202
-	} elseif ( ! is_email( $user->user_email ) ) {
203
-		$errors->add( 'invalid_email', __( '<strong>Error</strong>: The email address is not correct.' ), array( 'form-field' => 'email' ) );
204
-	} else {
205
-		$owner_id = email_exists( $user->user_email );
206
-		if ( $owner_id && ( ! $update || ( $owner_id != $user->ID ) ) ) {
207
-			$errors->add( 'email_exists', __( '<strong>Error</strong>: This email is already registered. Please choose another one.' ), array( 'form-field' => 'email' ) );
208
-		}
209
-	}
210
-
211
-	/**
212
-	 * Fires before user profile update errors are returned.
213
-	 *
214
-	 * @since 2.8.0
215
-	 *
216
-	 * @param WP_Error $errors WP_Error object (passed by reference).
217
-	 * @param bool     $update Whether this is a user update.
218
-	 * @param stdClass $user   User object (passed by reference).
219
-	 */
220
-	do_action_ref_array( 'user_profile_update_errors', array( &$errors, $update, &$user ) );
221
-
222
-	if ( $errors->has_errors() ) {
223
-		return $errors;
224
-	}
225
-
226
-	if ( $update ) {
227
-		$user_id = wp_update_user( $user );
228
-	} else {
229
-		$user_id = wp_insert_user( $user );
230
-		$notify  = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin';
231
-
232
-		/**
233
-		 * Fires after a new user has been created.
234
-		 *
235
-		 * @since 4.4.0
236
-		 *
237
-		 * @param int|WP_Error $user_id ID of the newly created user or WP_Error on failure.
238
-		 * @param string       $notify  Type of notification that should happen. See
239
-		 *                              wp_send_new_user_notifications() for more information.
240
-		 */
241
-		do_action( 'edit_user_created_user', $user_id, $notify );
242
-	}
243
-	return $user_id;
71
+        if (
72
+            ( is_multisite() && current_user_can( 'manage_network_users' ) ) ||
73
+            get_current_user_id() !== $user_id ||
74
+            ( $potential_role && $potential_role->has_cap( 'promote_users' ) )
75
+        ) {
76
+            $user->role = $new_role;
77
+        }
78
+    }
79
+
80
+    if ( isset( $_POST['email'] ) ) {
81
+        $user->user_email = sanitize_text_field( wp_unslash( $_POST['email'] ) );
82
+    }
83
+    if ( isset( $_POST['url'] ) ) {
84
+        if ( empty( $_POST['url'] ) || 'http://' === $_POST['url'] ) {
85
+            $user->user_url = '';
86
+        } else {
87
+            $user->user_url = esc_url_raw( $_POST['url'] );
88
+            $protocols      = implode( '|', array_map( 'preg_quote', wp_allowed_protocols() ) );
89
+            $user->user_url = preg_match( '/^(' . $protocols . '):/is', $user->user_url ) ? $user->user_url : 'http://' . $user->user_url;
90
+        }
91
+    }
92
+    if ( isset( $_POST['first_name'] ) ) {
93
+        $user->first_name = sanitize_text_field( $_POST['first_name'] );
94
+    }
95
+    if ( isset( $_POST['last_name'] ) ) {
96
+        $user->last_name = sanitize_text_field( $_POST['last_name'] );
97
+    }
98
+    if ( isset( $_POST['nickname'] ) ) {
99
+        $user->nickname = sanitize_text_field( $_POST['nickname'] );
100
+    }
101
+    if ( isset( $_POST['display_name'] ) ) {
102
+        $user->display_name = sanitize_text_field( $_POST['display_name'] );
103
+    }
104
+
105
+    if ( isset( $_POST['description'] ) ) {
106
+        $user->description = trim( $_POST['description'] );
107
+    }
108
+
109
+    foreach ( wp_get_user_contact_methods( $user ) as $method => $name ) {
110
+        if ( isset( $_POST[ $method ] ) ) {
111
+            $user->$method = sanitize_text_field( $_POST[ $method ] );
112
+        }
113
+    }
114
+
115
+    if ( isset( $_POST['locale'] ) ) {
116
+        $locale = sanitize_text_field( $_POST['locale'] );
117
+        if ( 'site-default' === $locale ) {
118
+            $locale = '';
119
+        } elseif ( '' === $locale ) {
120
+            $locale = 'en_US';
121
+        } elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
122
+            $locale = '';
123
+        }
124
+
125
+        $user->locale = $locale;
126
+    }
127
+
128
+    if ( $update ) {
129
+        $user->rich_editing         = isset( $_POST['rich_editing'] ) && 'false' === $_POST['rich_editing'] ? 'false' : 'true';
130
+        $user->syntax_highlighting  = isset( $_POST['syntax_highlighting'] ) && 'false' === $_POST['syntax_highlighting'] ? 'false' : 'true';
131
+        $user->admin_color          = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh';
132
+        $user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false';
133
+    }
134
+
135
+    $user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' === $_POST['comment_shortcuts'] ? 'true' : '';
136
+
137
+    $user->use_ssl = 0;
138
+    if ( ! empty( $_POST['use_ssl'] ) ) {
139
+        $user->use_ssl = 1;
140
+    }
141
+
142
+    $errors = new WP_Error();
143
+
144
+    /* checking that username has been typed */
145
+    if ( '' === $user->user_login ) {
146
+        $errors->add( 'user_login', __( '<strong>Error</strong>: Please enter a username.' ) );
147
+    }
148
+
149
+    /* checking that nickname has been typed */
150
+    if ( $update && empty( $user->nickname ) ) {
151
+        $errors->add( 'nickname', __( '<strong>Error</strong>: Please enter a nickname.' ) );
152
+    }
153
+
154
+    /**
155
+     * Fires before the password and confirm password fields are checked for congruity.
156
+     *
157
+     * @since 1.5.1
158
+     *
159
+     * @param string $user_login The username.
160
+     * @param string $pass1     The password (passed by reference).
161
+     * @param string $pass2     The confirmed password (passed by reference).
162
+     */
163
+    do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) );
164
+
165
+    // Check for blank password when adding a user.
166
+    if ( ! $update && empty( $pass1 ) ) {
167
+        $errors->add( 'pass', __( '<strong>Error</strong>: Please enter a password.' ), array( 'form-field' => 'pass1' ) );
168
+    }
169
+
170
+    // Check for "\" in password.
171
+    if ( false !== strpos( wp_unslash( $pass1 ), '\\' ) ) {
172
+        $errors->add( 'pass', __( '<strong>Error</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );
173
+    }
174
+
175
+    // Checking the password has been typed twice the same.
176
+    if ( ( $update || ! empty( $pass1 ) ) && $pass1 != $pass2 ) {
177
+        $errors->add( 'pass', __( '<strong>Error</strong>: Passwords do not match. Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) );
178
+    }
179
+
180
+    if ( ! empty( $pass1 ) ) {
181
+        $user->user_pass = $pass1;
182
+    }
183
+
184
+    if ( ! $update && isset( $_POST['user_login'] ) && ! validate_username( $_POST['user_login'] ) ) {
185
+        $errors->add( 'user_login', __( '<strong>Error</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
186
+    }
187
+
188
+    if ( ! $update && username_exists( $user->user_login ) ) {
189
+        $errors->add( 'user_login', __( '<strong>Error</strong>: This username is already registered. Please choose another one.' ) );
190
+    }
191
+
192
+    /** This filter is documented in wp-includes/user.php */
193
+    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
194
+
195
+    if ( in_array( strtolower( $user->user_login ), array_map( 'strtolower', $illegal_logins ), true ) ) {
196
+        $errors->add( 'invalid_username', __( '<strong>Error</strong>: Sorry, that username is not allowed.' ) );
197
+    }
198
+
199
+    /* checking email address */
200
+    if ( empty( $user->user_email ) ) {
201
+        $errors->add( 'empty_email', __( '<strong>Error</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) );
202
+    } elseif ( ! is_email( $user->user_email ) ) {
203
+        $errors->add( 'invalid_email', __( '<strong>Error</strong>: The email address is not correct.' ), array( 'form-field' => 'email' ) );
204
+    } else {
205
+        $owner_id = email_exists( $user->user_email );
206
+        if ( $owner_id && ( ! $update || ( $owner_id != $user->ID ) ) ) {
207
+            $errors->add( 'email_exists', __( '<strong>Error</strong>: This email is already registered. Please choose another one.' ), array( 'form-field' => 'email' ) );
208
+        }
209
+    }
210
+
211
+    /**
212
+     * Fires before user profile update errors are returned.
213
+     *
214
+     * @since 2.8.0
215
+     *
216
+     * @param WP_Error $errors WP_Error object (passed by reference).
217
+     * @param bool     $update Whether this is a user update.
218
+     * @param stdClass $user   User object (passed by reference).
219
+     */
220
+    do_action_ref_array( 'user_profile_update_errors', array( &$errors, $update, &$user ) );
221
+
222
+    if ( $errors->has_errors() ) {
223
+        return $errors;
224
+    }
225
+
226
+    if ( $update ) {
227
+        $user_id = wp_update_user( $user );
228
+    } else {
229
+        $user_id = wp_insert_user( $user );
230
+        $notify  = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin';
231
+
232
+        /**
233
+         * Fires after a new user has been created.
234
+         *
235
+         * @since 4.4.0
236
+         *
237
+         * @param int|WP_Error $user_id ID of the newly created user or WP_Error on failure.
238
+         * @param string       $notify  Type of notification that should happen. See
239
+         *                              wp_send_new_user_notifications() for more information.
240
+         */
241
+        do_action( 'edit_user_created_user', $user_id, $notify );
242
+    }
243
+    return $user_id;
244 244
 }
245 245
 
246 246
 /**
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
  * @return array[] Array of arrays containing role information.
261 261
  */
262 262
 function get_editable_roles() {
263
-	$all_roles = wp_roles()->roles;
264
-
265
-	/**
266
-	 * Filters the list of editable roles.
267
-	 *
268
-	 * @since 2.8.0
269
-	 *
270
-	 * @param array[] $all_roles Array of arrays containing role information.
271
-	 */
272
-	$editable_roles = apply_filters( 'editable_roles', $all_roles );
273
-
274
-	return $editable_roles;
263
+    $all_roles = wp_roles()->roles;
264
+
265
+    /**
266
+     * Filters the list of editable roles.
267
+     *
268
+     * @since 2.8.0
269
+     *
270
+     * @param array[] $all_roles Array of arrays containing role information.
271
+     */
272
+    $editable_roles = apply_filters( 'editable_roles', $all_roles );
273
+
274
+    return $editable_roles;
275 275
 }
276 276
 
277 277
 /**
@@ -283,13 +283,13 @@  discard block
 block discarded – undo
283 283
  * @return WP_User|false WP_User object on success, false on failure.
284 284
  */
285 285
 function get_user_to_edit( $user_id ) {
286
-	$user = get_userdata( $user_id );
286
+    $user = get_userdata( $user_id );
287 287
 
288
-	if ( $user ) {
289
-		$user->filter = 'edit';
290
-	}
288
+    if ( $user ) {
289
+        $user->filter = 'edit';
290
+    }
291 291
 
292
-	return $user;
292
+    return $user;
293 293
 }
294 294
 
295 295
 /**
@@ -303,18 +303,18 @@  discard block
 block discarded – undo
303 303
  * @return array
304 304
  */
305 305
 function get_users_drafts( $user_id ) {
306
-	global $wpdb;
307
-	$query = $wpdb->prepare( "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = %d ORDER BY post_modified DESC", $user_id );
308
-
309
-	/**
310
-	 * Filters the user's drafts query string.
311
-	 *
312
-	 * @since 2.0.0
313
-	 *
314
-	 * @param string $query The user's drafts query string.
315
-	 */
316
-	$query = apply_filters( 'get_users_drafts', $query );
317
-	return $wpdb->get_results( $query );
306
+    global $wpdb;
307
+    $query = $wpdb->prepare( "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = %d ORDER BY post_modified DESC", $user_id );
308
+
309
+    /**
310
+     * Filters the user's drafts query string.
311
+     *
312
+     * @since 2.0.0
313
+     *
314
+     * @param string $query The user's drafts query string.
315
+     */
316
+    $query = apply_filters( 'get_users_drafts', $query );
317
+    return $wpdb->get_results( $query );
318 318
 }
319 319
 
320 320
 /**
@@ -334,119 +334,119 @@  discard block
 block discarded – undo
334 334
  * @return bool True when finished.
335 335
  */
336 336
 function wp_delete_user( $id, $reassign = null ) {
337
-	global $wpdb;
338
-
339
-	if ( ! is_numeric( $id ) ) {
340
-		return false;
341
-	}
342
-
343
-	$id   = (int) $id;
344
-	$user = new WP_User( $id );
345
-
346
-	if ( ! $user->exists() ) {
347
-		return false;
348
-	}
349
-
350
-	// Normalize $reassign to null or a user ID. 'novalue' was an older default.
351
-	if ( 'novalue' === $reassign ) {
352
-		$reassign = null;
353
-	} elseif ( null !== $reassign ) {
354
-		$reassign = (int) $reassign;
355
-	}
356
-
357
-	/**
358
-	 * Fires immediately before a user is deleted from the database.
359
-	 *
360
-	 * @since 2.0.0
361
-	 * @since 5.5.0 Added the `$user` parameter.
362
-	 *
363
-	 * @param int      $id       ID of the user to delete.
364
-	 * @param int|null $reassign ID of the user to reassign posts and links to.
365
-	 *                           Default null, for no reassignment.
366
-	 * @param WP_User  $user     WP_User object of the user to delete.
367
-	 */
368
-	do_action( 'delete_user', $id, $reassign, $user );
369
-
370
-	if ( null === $reassign ) {
371
-		$post_types_to_delete = array();
372
-		foreach ( get_post_types( array(), 'objects' ) as $post_type ) {
373
-			if ( $post_type->delete_with_user ) {
374
-				$post_types_to_delete[] = $post_type->name;
375
-			} elseif ( null === $post_type->delete_with_user && post_type_supports( $post_type->name, 'author' ) ) {
376
-				$post_types_to_delete[] = $post_type->name;
377
-			}
378
-		}
379
-
380
-		/**
381
-		 * Filters the list of post types to delete with a user.
382
-		 *
383
-		 * @since 3.4.0
384
-		 *
385
-		 * @param string[] $post_types_to_delete Array of post types to delete.
386
-		 * @param int      $id                   User ID.
387
-		 */
388
-		$post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id );
389
-		$post_types_to_delete = implode( "', '", $post_types_to_delete );
390
-		$post_ids             = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types_to_delete')", $id ) );
391
-		if ( $post_ids ) {
392
-			foreach ( $post_ids as $post_id ) {
393
-				wp_delete_post( $post_id );
394
-			}
395
-		}
396
-
397
-		// Clean links.
398
-		$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
399
-
400
-		if ( $link_ids ) {
401
-			foreach ( $link_ids as $link_id ) {
402
-				wp_delete_link( $link_id );
403
-			}
404
-		}
405
-	} else {
406
-		$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
407
-		$wpdb->update( $wpdb->posts, array( 'post_author' => $reassign ), array( 'post_author' => $id ) );
408
-		if ( ! empty( $post_ids ) ) {
409
-			foreach ( $post_ids as $post_id ) {
410
-				clean_post_cache( $post_id );
411
-			}
412
-		}
413
-		$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
414
-		$wpdb->update( $wpdb->links, array( 'link_owner' => $reassign ), array( 'link_owner' => $id ) );
415
-		if ( ! empty( $link_ids ) ) {
416
-			foreach ( $link_ids as $link_id ) {
417
-				clean_bookmark_cache( $link_id );
418
-			}
419
-		}
420
-	}
421
-
422
-	// FINALLY, delete user.
423
-	if ( is_multisite() ) {
424
-		remove_user_from_blog( $id, get_current_blog_id() );
425
-	} else {
426
-		$meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
427
-		foreach ( $meta as $mid ) {
428
-			delete_metadata_by_mid( 'user', $mid );
429
-		}
430
-
431
-		$wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
432
-	}
433
-
434
-	clean_user_cache( $user );
435
-
436
-	/**
437
-	 * Fires immediately after a user is deleted from the database.
438
-	 *
439
-	 * @since 2.9.0
440
-	 * @since 5.5.0 Added the `$user` parameter.
441
-	 *
442
-	 * @param int      $id       ID of the deleted user.
443
-	 * @param int|null $reassign ID of the user to reassign posts and links to.
444
-	 *                           Default null, for no reassignment.
445
-	 * @param WP_User  $user     WP_User object of the deleted user.
446
-	 */
447
-	do_action( 'deleted_user', $id, $reassign, $user );
448
-
449
-	return true;
337
+    global $wpdb;
338
+
339
+    if ( ! is_numeric( $id ) ) {
340
+        return false;
341
+    }
342
+
343
+    $id   = (int) $id;
344
+    $user = new WP_User( $id );
345
+
346
+    if ( ! $user->exists() ) {
347
+        return false;
348
+    }
349
+
350
+    // Normalize $reassign to null or a user ID. 'novalue' was an older default.
351
+    if ( 'novalue' === $reassign ) {
352
+        $reassign = null;
353
+    } elseif ( null !== $reassign ) {
354
+        $reassign = (int) $reassign;
355
+    }
356
+
357
+    /**
358
+     * Fires immediately before a user is deleted from the database.
359
+     *
360
+     * @since 2.0.0
361
+     * @since 5.5.0 Added the `$user` parameter.
362
+     *
363
+     * @param int      $id       ID of the user to delete.
364
+     * @param int|null $reassign ID of the user to reassign posts and links to.
365
+     *                           Default null, for no reassignment.
366
+     * @param WP_User  $user     WP_User object of the user to delete.
367
+     */
368
+    do_action( 'delete_user', $id, $reassign, $user );
369
+
370
+    if ( null === $reassign ) {
371
+        $post_types_to_delete = array();
372
+        foreach ( get_post_types( array(), 'objects' ) as $post_type ) {
373
+            if ( $post_type->delete_with_user ) {
374
+                $post_types_to_delete[] = $post_type->name;
375
+            } elseif ( null === $post_type->delete_with_user && post_type_supports( $post_type->name, 'author' ) ) {
376
+                $post_types_to_delete[] = $post_type->name;
377
+            }
378
+        }
379
+
380
+        /**
381
+         * Filters the list of post types to delete with a user.
382
+         *
383
+         * @since 3.4.0
384
+         *
385
+         * @param string[] $post_types_to_delete Array of post types to delete.
386
+         * @param int      $id                   User ID.
387
+         */
388
+        $post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id );
389
+        $post_types_to_delete = implode( "', '", $post_types_to_delete );
390
+        $post_ids             = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types_to_delete')", $id ) );
391
+        if ( $post_ids ) {
392
+            foreach ( $post_ids as $post_id ) {
393
+                wp_delete_post( $post_id );
394
+            }
395
+        }
396
+
397
+        // Clean links.
398
+        $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
399
+
400
+        if ( $link_ids ) {
401
+            foreach ( $link_ids as $link_id ) {
402
+                wp_delete_link( $link_id );
403
+            }
404
+        }
405
+    } else {
406
+        $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
407
+        $wpdb->update( $wpdb->posts, array( 'post_author' => $reassign ), array( 'post_author' => $id ) );
408
+        if ( ! empty( $post_ids ) ) {
409
+            foreach ( $post_ids as $post_id ) {
410
+                clean_post_cache( $post_id );
411
+            }
412
+        }
413
+        $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
414
+        $wpdb->update( $wpdb->links, array( 'link_owner' => $reassign ), array( 'link_owner' => $id ) );
415
+        if ( ! empty( $link_ids ) ) {
416
+            foreach ( $link_ids as $link_id ) {
417
+                clean_bookmark_cache( $link_id );
418
+            }
419
+        }
420
+    }
421
+
422
+    // FINALLY, delete user.
423
+    if ( is_multisite() ) {
424
+        remove_user_from_blog( $id, get_current_blog_id() );
425
+    } else {
426
+        $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
427
+        foreach ( $meta as $mid ) {
428
+            delete_metadata_by_mid( 'user', $mid );
429
+        }
430
+
431
+        $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
432
+    }
433
+
434
+    clean_user_cache( $user );
435
+
436
+    /**
437
+     * Fires immediately after a user is deleted from the database.
438
+     *
439
+     * @since 2.9.0
440
+     * @since 5.5.0 Added the `$user` parameter.
441
+     *
442
+     * @param int      $id       ID of the deleted user.
443
+     * @param int|null $reassign ID of the user to reassign posts and links to.
444
+     *                           Default null, for no reassignment.
445
+     * @param WP_User  $user     WP_User object of the deleted user.
446
+     */
447
+    do_action( 'deleted_user', $id, $reassign, $user );
448
+
449
+    return true;
450 450
 }
451 451
 
452 452
 /**
@@ -457,10 +457,10 @@  discard block
 block discarded – undo
457 457
  * @param int $id User ID.
458 458
  */
459 459
 function wp_revoke_user( $id ) {
460
-	$id = (int) $id;
460
+    $id = (int) $id;
461 461
 
462
-	$user = new WP_User( $id );
463
-	$user->remove_all_caps();
462
+    $user = new WP_User( $id );
463
+    $user->remove_all_caps();
464 464
 }
465 465
 
466 466
 /**
@@ -471,19 +471,19 @@  discard block
 block discarded – undo
471 471
  * @param false $errors Deprecated.
472 472
  */
473 473
 function default_password_nag_handler( $errors = false ) {
474
-	global $user_ID;
475
-	// Short-circuit it.
476
-	if ( ! get_user_option( 'default_password_nag' ) ) {
477
-		return;
478
-	}
479
-
480
-	// get_user_setting() = JS-saved UI setting. Else no-js-fallback code.
481
-	if ( 'hide' === get_user_setting( 'default_password_nag' )
482
-		|| isset( $_GET['default_password_nag'] ) && '0' == $_GET['default_password_nag']
483
-	) {
484
-		delete_user_setting( 'default_password_nag' );
485
-		update_user_meta( $user_ID, 'default_password_nag', false );
486
-	}
474
+    global $user_ID;
475
+    // Short-circuit it.
476
+    if ( ! get_user_option( 'default_password_nag' ) ) {
477
+        return;
478
+    }
479
+
480
+    // get_user_setting() = JS-saved UI setting. Else no-js-fallback code.
481
+    if ( 'hide' === get_user_setting( 'default_password_nag' )
482
+        || isset( $_GET['default_password_nag'] ) && '0' == $_GET['default_password_nag']
483
+    ) {
484
+        delete_user_setting( 'default_password_nag' );
485
+        update_user_meta( $user_ID, 'default_password_nag', false );
486
+    }
487 487
 }
488 488
 
489 489
 /**
@@ -493,18 +493,18 @@  discard block
 block discarded – undo
493 493
  * @param WP_User $old_data
494 494
  */
495 495
 function default_password_nag_edit_user( $user_ID, $old_data ) {
496
-	// Short-circuit it.
497
-	if ( ! get_user_option( 'default_password_nag', $user_ID ) ) {
498
-		return;
499
-	}
500
-
501
-	$new_data = get_userdata( $user_ID );
502
-
503
-	// Remove the nag if the password has been changed.
504
-	if ( $new_data->user_pass != $old_data->user_pass ) {
505
-		delete_user_setting( 'default_password_nag' );
506
-		update_user_meta( $user_ID, 'default_password_nag', false );
507
-	}
496
+    // Short-circuit it.
497
+    if ( ! get_user_option( 'default_password_nag', $user_ID ) ) {
498
+        return;
499
+    }
500
+
501
+    $new_data = get_userdata( $user_ID );
502
+
503
+    // Remove the nag if the password has been changed.
504
+    if ( $new_data->user_pass != $old_data->user_pass ) {
505
+        delete_user_setting( 'default_password_nag' );
506
+        update_user_meta( $user_ID, 'default_password_nag', false );
507
+    }
508 508
 }
509 509
 
510 510
 /**
@@ -513,21 +513,21 @@  discard block
 block discarded – undo
513 513
  * @global string $pagenow The filename of the current screen.
514 514
  */
515 515
 function default_password_nag() {
516
-	global $pagenow;
517
-
518
-	// Short-circuit it.
519
-	if ( 'profile.php' === $pagenow || ! get_user_option( 'default_password_nag' ) ) {
520
-		return;
521
-	}
522
-
523
-	echo '<div class="error default-password-nag">';
524
-	echo '<p>';
525
-	echo '<strong>' . __( 'Notice:' ) . '</strong> ';
526
-	_e( 'You&rsquo;re using the auto-generated password for your account. Would you like to change it?' );
527
-	echo '</p><p>';
528
-	printf( '<a href="%s">' . __( 'Yes, take me to my profile page' ) . '</a> | ', get_edit_profile_url() . '#password' );
529
-	printf( '<a href="%s" id="default-password-nag-no">' . __( 'No thanks, do not remind me again' ) . '</a>', '?default_password_nag=0' );
530
-	echo '</p></div>';
516
+    global $pagenow;
517
+
518
+    // Short-circuit it.
519
+    if ( 'profile.php' === $pagenow || ! get_user_option( 'default_password_nag' ) ) {
520
+        return;
521
+    }
522
+
523
+    echo '<div class="error default-password-nag">';
524
+    echo '<p>';
525
+    echo '<strong>' . __( 'Notice:' ) . '</strong> ';
526
+    _e( 'You&rsquo;re using the auto-generated password for your account. Would you like to change it?' );
527
+    echo '</p><p>';
528
+    printf( '<a href="%s">' . __( 'Yes, take me to my profile page' ) . '</a> | ', get_edit_profile_url() . '#password' );
529
+    printf( '<a href="%s" id="default-password-nag-no">' . __( 'No thanks, do not remind me again' ) . '</a>', '?default_password_nag=0' );
530
+    echo '</p></div>';
531 531
 }
532 532
 
533 533
 /**
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
  * @access private
536 536
  */
537 537
 function delete_users_add_js() {
538
-	?>
538
+    ?>
539 539
 <script>
540 540
 jQuery( function($) {
541 541
 	var submit = $('#submit').prop('disabled', true);
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
  * @param WP_User $user User data object.
561 561
  */
562 562
 function use_ssl_preference( $user ) {
563
-	?>
563
+    ?>
564 564
 	<tr class="user-use-ssl-wrap">
565 565
 		<th scope="row"><?php _e( 'Use https' ); ?></th>
566 566
 		<td><label for="use_ssl"><input name="use_ssl" type="checkbox" id="use_ssl" value="1" <?php checked( '1', $user->use_ssl ); ?> /> <?php _e( 'Always use https when visiting the admin' ); ?></label></td>
@@ -575,19 +575,19 @@  discard block
 block discarded – undo
575 575
  * @return string
576 576
  */
577 577
 function admin_created_user_email( $text ) {
578
-	$roles = get_editable_roles();
579
-	$role  = $roles[ $_REQUEST['role'] ];
580
-
581
-	if ( '' !== get_bloginfo( 'name' ) ) {
582
-		$site_title = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
583
-	} else {
584
-		$site_title = parse_url( home_url(), PHP_URL_HOST );
585
-	}
586
-
587
-	return sprintf(
588
-		/* translators: 1: Site title, 2: Site URL, 3: User role. */
589
-		__(
590
-			'Hi,
578
+    $roles = get_editable_roles();
579
+    $role  = $roles[ $_REQUEST['role'] ];
580
+
581
+    if ( '' !== get_bloginfo( 'name' ) ) {
582
+        $site_title = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
583
+    } else {
584
+        $site_title = parse_url( home_url(), PHP_URL_HOST );
585
+    }
586
+
587
+    return sprintf(
588
+        /* translators: 1: Site title, 2: Site URL, 3: User role. */
589
+        __(
590
+            'Hi,
591 591
 You\'ve been invited to join \'%1$s\' at
592 592
 %2$s with the role of %3$s.
593 593
 If you do not want to join this site please ignore
@@ -595,11 +595,11 @@  discard block
 block discarded – undo
595 595
 
596 596
 Please click the following link to activate your user account:
597 597
 %%s'
598
-		),
599
-		$site_title,
600
-		home_url(),
601
-		wp_specialchars_decode( translate_user_role( $role['name'] ) )
602
-	);
598
+        ),
599
+        $site_title,
600
+        home_url(),
601
+        wp_specialchars_decode( translate_user_role( $role['name'] ) )
602
+    );
603 603
 }
604 604
 
605 605
 /**
@@ -619,51 +619,51 @@  discard block
 block discarded – undo
619 619
  * @return true|WP_Error True if the request is valid, a WP_Error object contains errors if not.
620 620
  */
621 621
 function wp_is_authorize_application_password_request_valid( $request, $user ) {
622
-	$error = new WP_Error();
623
-
624
-	if ( ! empty( $request['success_url'] ) ) {
625
-		$scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME );
626
-
627
-		if ( 'http' === $scheme ) {
628
-			$error->add(
629
-				'invalid_redirect_scheme',
630
-				__( 'The success URL must be served over a secure connection.' )
631
-			);
632
-		}
633
-	}
634
-
635
-	if ( ! empty( $request['reject_url'] ) ) {
636
-		$scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME );
637
-
638
-		if ( 'http' === $scheme ) {
639
-			$error->add(
640
-				'invalid_redirect_scheme',
641
-				__( 'The rejection URL must be served over a secure connection.' )
642
-			);
643
-		}
644
-	}
645
-
646
-	if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) {
647
-		$error->add(
648
-			'invalid_app_id',
649
-			__( 'The application ID must be a UUID.' )
650
-		);
651
-	}
652
-
653
-	/**
654
-	 * Fires before application password errors are returned.
655
-	 *
656
-	 * @since 5.6.0
657
-	 *
658
-	 * @param WP_Error $error   The error object.
659
-	 * @param array    $request The array of request data.
660
-	 * @param WP_User  $user    The user authorizing the application.
661
-	 */
662
-	do_action( 'wp_authorize_application_password_request_errors', $error, $request, $user );
663
-
664
-	if ( $error->has_errors() ) {
665
-		return $error;
666
-	}
667
-
668
-	return true;
622
+    $error = new WP_Error();
623
+
624
+    if ( ! empty( $request['success_url'] ) ) {
625
+        $scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME );
626
+
627
+        if ( 'http' === $scheme ) {
628
+            $error->add(
629
+                'invalid_redirect_scheme',
630
+                __( 'The success URL must be served over a secure connection.' )
631
+            );
632
+        }
633
+    }
634
+
635
+    if ( ! empty( $request['reject_url'] ) ) {
636
+        $scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME );
637
+
638
+        if ( 'http' === $scheme ) {
639
+            $error->add(
640
+                'invalid_redirect_scheme',
641
+                __( 'The rejection URL must be served over a secure connection.' )
642
+            );
643
+        }
644
+    }
645
+
646
+    if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) {
647
+        $error->add(
648
+            'invalid_app_id',
649
+            __( 'The application ID must be a UUID.' )
650
+        );
651
+    }
652
+
653
+    /**
654
+     * Fires before application password errors are returned.
655
+     *
656
+     * @since 5.6.0
657
+     *
658
+     * @param WP_Error $error   The error object.
659
+     * @param array    $request The array of request data.
660
+     * @param WP_User  $user    The user authorizing the application.
661
+     */
662
+    do_action( 'wp_authorize_application_password_request_errors', $error, $request, $user );
663
+
664
+    if ( $error->has_errors() ) {
665
+        return $error;
666
+    }
667
+
668
+    return true;
669 669
 }
Please login to merge, or discard this patch.