author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Administration API: Core Ajax handlers |
0 | 4 |
* |
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 2.1.0 |
0 | 8 |
*/ |
9 |
||
5 | 10 |
// |
11 |
// No-privilege Ajax handlers. |
|
12 |
// |
|
0 | 13 |
|
14 |
/** |
|
18 | 15 |
* Ajax handler for the Heartbeat API in the no-privilege context. |
0 | 16 |
* |
17 |
* Runs when the user is not logged in. |
|
5 | 18 |
* |
19 |
* @since 3.6.0 |
|
0 | 20 |
*/ |
21 |
function wp_ajax_nopriv_heartbeat() { |
|
22 |
$response = array(); |
|
23 |
||
16 | 24 |
// 'screen_id' is the same as $current_screen->id and the JS global 'pagenow'. |
9 | 25 |
if ( ! empty( $_POST['screen_id'] ) ) { |
26 |
$screen_id = sanitize_key( $_POST['screen_id'] ); |
|
27 |
} else { |
|
0 | 28 |
$screen_id = 'front'; |
9 | 29 |
} |
30 |
||
31 |
if ( ! empty( $_POST['data'] ) ) { |
|
0 | 32 |
$data = wp_unslash( (array) $_POST['data'] ); |
33 |
||
34 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* Filters Heartbeat Ajax response in no-privilege environments. |
0 | 36 |
* |
37 |
* @since 3.6.0 |
|
38 |
* |
|
9 | 39 |
* @param array $response The no-priv Heartbeat response. |
40 |
* @param array $data The $_POST data sent. |
|
16 | 41 |
* @param string $screen_id The screen ID. |
0 | 42 |
*/ |
43 |
$response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id ); |
|
44 |
} |
|
45 |
||
46 |
/** |
|
9 | 47 |
* Filters Heartbeat Ajax response in no-privilege environments when no data is passed. |
0 | 48 |
* |
49 |
* @since 3.6.0 |
|
50 |
* |
|
9 | 51 |
* @param array $response The no-priv Heartbeat response. |
16 | 52 |
* @param string $screen_id The screen ID. |
0 | 53 |
*/ |
54 |
$response = apply_filters( 'heartbeat_nopriv_send', $response, $screen_id ); |
|
55 |
||
56 |
/** |
|
57 |
* Fires when Heartbeat ticks in no-privilege environments. |
|
58 |
* |
|
59 |
* Allows the transport to be easily replaced with long-polling. |
|
60 |
* |
|
61 |
* @since 3.6.0 |
|
62 |
* |
|
9 | 63 |
* @param array $response The no-priv Heartbeat response. |
16 | 64 |
* @param string $screen_id The screen ID. |
0 | 65 |
*/ |
66 |
do_action( 'heartbeat_nopriv_tick', $response, $screen_id ); |
|
67 |
||
5 | 68 |
// Send the current time according to the server. |
0 | 69 |
$response['server_time'] = time(); |
70 |
||
9 | 71 |
wp_send_json( $response ); |
0 | 72 |
} |
73 |
||
5 | 74 |
// |
75 |
// GET-based Ajax handlers. |
|
76 |
// |
|
77 |
||
78 |
/** |
|
79 |
* Ajax handler for fetching a list table. |
|
80 |
* |
|
81 |
* @since 3.1.0 |
|
0 | 82 |
*/ |
83 |
function wp_ajax_fetch_list() { |
|
84 |
$list_class = $_GET['list_args']['class']; |
|
85 |
check_ajax_referer( "fetch-list-$list_class", '_ajax_fetch_list_nonce' ); |
|
86 |
||
87 |
$wp_list_table = _get_list_table( $list_class, array( 'screen' => $_GET['list_args']['screen']['id'] ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
if ( ! $wp_list_table ) { |
0 | 89 |
wp_die( 0 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
if ( ! $wp_list_table->ajax_user_can() ) { |
0 | 93 |
wp_die( -1 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
} |
0 | 95 |
|
96 |
$wp_list_table->ajax_response(); |
|
97 |
||
98 |
wp_die( 0 ); |
|
99 |
} |
|
5 | 100 |
|
101 |
/** |
|
102 |
* Ajax handler for tag search. |
|
103 |
* |
|
104 |
* @since 3.1.0 |
|
105 |
*/ |
|
0 | 106 |
function wp_ajax_ajax_tag_search() { |
5 | 107 |
if ( ! isset( $_GET['tax'] ) ) { |
0 | 108 |
wp_die( 0 ); |
109 |
} |
|
110 |
||
5 | 111 |
$taxonomy = sanitize_key( $_GET['tax'] ); |
9 | 112 |
$tax = get_taxonomy( $taxonomy ); |
16 | 113 |
|
5 | 114 |
if ( ! $tax ) { |
115 |
wp_die( 0 ); |
|
116 |
} |
|
117 |
||
118 |
if ( ! current_user_can( $tax->cap->assign_terms ) ) { |
|
119 |
wp_die( -1 ); |
|
120 |
} |
|
121 |
||
0 | 122 |
$s = wp_unslash( $_GET['q'] ); |
123 |
||
124 |
$comma = _x( ',', 'tag delimiter' ); |
|
9 | 125 |
if ( ',' !== $comma ) { |
0 | 126 |
$s = str_replace( $comma, ',', $s ); |
9 | 127 |
} |
16 | 128 |
|
0 | 129 |
if ( false !== strpos( $s, ',' ) ) { |
130 |
$s = explode( ',', $s ); |
|
9 | 131 |
$s = $s[ count( $s ) - 1 ]; |
0 | 132 |
} |
16 | 133 |
|
0 | 134 |
$s = trim( $s ); |
5 | 135 |
|
136 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
* Filters the minimum number of characters required to fire a tag search via Ajax. |
5 | 138 |
* |
139 |
* @since 4.0.0 |
|
140 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* @param int $characters The minimum number of characters required. Default 2. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
* @param WP_Taxonomy $tax The taxonomy object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
* @param string $s The search term. |
5 | 144 |
*/ |
145 |
$term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s ); |
|
146 |
||
147 |
/* |
|
148 |
* Require $term_search_min_chars chars for matching (default: 2) |
|
149 |
* ensure it's a non-negative, non-zero integer. |
|
150 |
*/ |
|
16 | 151 |
if ( ( 0 == $term_search_min_chars ) || ( strlen( $s ) < $term_search_min_chars ) ) { |
5 | 152 |
wp_die(); |
153 |
} |
|
0 | 154 |
|
9 | 155 |
$results = get_terms( |
156 |
array( |
|
16 | 157 |
'taxonomy' => $taxonomy, |
9 | 158 |
'name__like' => $s, |
159 |
'fields' => 'names', |
|
160 |
'hide_empty' => false, |
|
161 |
) |
|
162 |
); |
|
0 | 163 |
|
18 | 164 |
echo implode( "\n", $results ); |
0 | 165 |
wp_die(); |
166 |
} |
|
167 |
||
5 | 168 |
/** |
169 |
* Ajax handler for compression testing. |
|
170 |
* |
|
171 |
* @since 3.1.0 |
|
172 |
*/ |
|
0 | 173 |
function wp_ajax_wp_compression_test() { |
9 | 174 |
if ( ! current_user_can( 'manage_options' ) ) { |
0 | 175 |
wp_die( -1 ); |
9 | 176 |
} |
177 |
||
16 | 178 |
if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) ) { |
9 | 179 |
update_site_option( 'can_compress_scripts', 0 ); |
0 | 180 |
wp_die( 0 ); |
181 |
} |
|
182 |
||
9 | 183 |
if ( isset( $_GET['test'] ) ) { |
0 | 184 |
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' ); |
185 |
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); |
|
186 |
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' ); |
|
9 | 187 |
header( 'Content-Type: application/javascript; charset=UTF-8' ); |
188 |
$force_gzip = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ); |
|
189 |
$test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."'; |
|
190 |
||
191 |
if ( 1 == $_GET['test'] ) { |
|
192 |
echo $test_str; |
|
193 |
wp_die(); |
|
194 |
} elseif ( 2 == $_GET['test'] ) { |
|
195 |
if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) { |
|
0 | 196 |
wp_die( -1 ); |
9 | 197 |
} |
16 | 198 |
|
9 | 199 |
if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) { |
200 |
header( 'Content-Encoding: deflate' ); |
|
0 | 201 |
$out = gzdeflate( $test_str, 1 ); |
9 | 202 |
} elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && function_exists( 'gzencode' ) ) { |
203 |
header( 'Content-Encoding: gzip' ); |
|
0 | 204 |
$out = gzencode( $test_str, 1 ); |
205 |
} else { |
|
206 |
wp_die( -1 ); |
|
207 |
} |
|
16 | 208 |
|
0 | 209 |
echo $out; |
210 |
wp_die(); |
|
16 | 211 |
} elseif ( 'no' === $_GET['test'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
check_ajax_referer( 'update_can_compress_scripts' ); |
9 | 213 |
update_site_option( 'can_compress_scripts', 0 ); |
16 | 214 |
} elseif ( 'yes' === $_GET['test'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
check_ajax_referer( 'update_can_compress_scripts' ); |
9 | 216 |
update_site_option( 'can_compress_scripts', 1 ); |
0 | 217 |
} |
218 |
} |
|
219 |
||
220 |
wp_die( 0 ); |
|
221 |
} |
|
222 |
||
5 | 223 |
/** |
224 |
* Ajax handler for image editor previews. |
|
225 |
* |
|
226 |
* @since 3.1.0 |
|
227 |
*/ |
|
0 | 228 |
function wp_ajax_imgedit_preview() { |
18 | 229 |
$post_id = (int) $_GET['postid']; |
9 | 230 |
if ( empty( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) { |
0 | 231 |
wp_die( -1 ); |
9 | 232 |
} |
0 | 233 |
|
234 |
check_ajax_referer( "image_editor-$post_id" ); |
|
235 |
||
16 | 236 |
include_once ABSPATH . 'wp-admin/includes/image-edit.php'; |
237 |
||
9 | 238 |
if ( ! stream_preview_image( $post_id ) ) { |
0 | 239 |
wp_die( -1 ); |
9 | 240 |
} |
0 | 241 |
|
242 |
wp_die(); |
|
243 |
} |
|
244 |
||
5 | 245 |
/** |
246 |
* Ajax handler for oEmbed caching. |
|
247 |
* |
|
248 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* @global WP_Embed $wp_embed |
5 | 251 |
*/ |
0 | 252 |
function wp_ajax_oembed_cache() { |
5 | 253 |
$GLOBALS['wp_embed']->cache_oembed( $_GET['post'] ); |
254 |
wp_die( 0 ); |
|
0 | 255 |
} |
256 |
||
5 | 257 |
/** |
258 |
* Ajax handler for user autocomplete. |
|
259 |
* |
|
260 |
* @since 3.4.0 |
|
261 |
*/ |
|
0 | 262 |
function wp_ajax_autocomplete_user() { |
9 | 263 |
if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) ) { |
0 | 264 |
wp_die( -1 ); |
9 | 265 |
} |
0 | 266 |
|
267 |
/** This filter is documented in wp-admin/user-new.php */ |
|
9 | 268 |
if ( ! current_user_can( 'manage_network_users' ) && ! apply_filters( 'autocomplete_users_for_site_admins', false ) ) { |
0 | 269 |
wp_die( -1 ); |
9 | 270 |
} |
0 | 271 |
|
272 |
$return = array(); |
|
273 |
||
16 | 274 |
// Check the type of request. |
275 |
// Current allowed values are `add` and `search`. |
|
5 | 276 |
if ( isset( $_REQUEST['autocomplete_type'] ) && 'search' === $_REQUEST['autocomplete_type'] ) { |
0 | 277 |
$type = $_REQUEST['autocomplete_type']; |
5 | 278 |
} else { |
0 | 279 |
$type = 'add'; |
5 | 280 |
} |
281 |
||
16 | 282 |
// Check the desired field for value. |
283 |
// Current allowed values are `user_email` and `user_login`. |
|
5 | 284 |
if ( isset( $_REQUEST['autocomplete_field'] ) && 'user_email' === $_REQUEST['autocomplete_field'] ) { |
285 |
$field = $_REQUEST['autocomplete_field']; |
|
286 |
} else { |
|
287 |
$field = 'user_login'; |
|
288 |
} |
|
0 | 289 |
|
16 | 290 |
// Exclude current users of this blog. |
5 | 291 |
if ( isset( $_REQUEST['site_id'] ) ) { |
0 | 292 |
$id = absint( $_REQUEST['site_id'] ); |
5 | 293 |
} else { |
0 | 294 |
$id = get_current_blog_id(); |
5 | 295 |
} |
0 | 296 |
|
16 | 297 |
$include_blog_users = ( 'search' === $type ? get_users( |
9 | 298 |
array( |
299 |
'blog_id' => $id, |
|
300 |
'fields' => 'ID', |
|
301 |
) |
|
302 |
) : array() ); |
|
16 | 303 |
|
304 |
$exclude_blog_users = ( 'add' === $type ? get_users( |
|
9 | 305 |
array( |
306 |
'blog_id' => $id, |
|
307 |
'fields' => 'ID', |
|
308 |
) |
|
309 |
) : array() ); |
|
310 |
||
311 |
$users = get_users( |
|
312 |
array( |
|
313 |
'blog_id' => false, |
|
314 |
'search' => '*' . $_REQUEST['term'] . '*', |
|
315 |
'include' => $include_blog_users, |
|
316 |
'exclude' => $exclude_blog_users, |
|
317 |
'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ), |
|
318 |
) |
|
319 |
); |
|
0 | 320 |
|
321 |
foreach ( $users as $user ) { |
|
322 |
$return[] = array( |
|
16 | 323 |
/* translators: 1: User login, 2: User email address. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
'label' => sprintf( _x( '%1$s (%2$s)', 'user autocomplete result' ), $user->user_login, $user->user_email ), |
5 | 325 |
'value' => $user->$field, |
0 | 326 |
); |
327 |
} |
|
328 |
||
5 | 329 |
wp_die( wp_json_encode( $return ) ); |
0 | 330 |
} |
331 |
||
5 | 332 |
/** |
16 | 333 |
* Handles Ajax requests for community events |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
function wp_ajax_get_community_events() { |
16 | 338 |
require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
check_ajax_referer( 'community_events' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
$search = isset( $_POST['location'] ) ? wp_unslash( $_POST['location'] ) : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
$timezone = isset( $_POST['timezone'] ) ? wp_unslash( $_POST['timezone'] ) : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
$user_id = get_current_user_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
$saved_location = get_user_option( 'community-events-location', $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
$events_client = new WP_Community_Events( $user_id, $saved_location ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
$events = $events_client->get_events( $search, $timezone ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
$ip_changed = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
if ( is_wp_error( $events ) ) { |
9 | 351 |
wp_send_json_error( |
352 |
array( |
|
353 |
'error' => $events->get_error_message(), |
|
354 |
) |
|
355 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
if ( empty( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
$ip_changed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
} elseif ( isset( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) && $saved_location['ip'] !== $events['location']['ip'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
$ip_changed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
* The location should only be updated when it changes. The API doesn't always return |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
* a full location; sometimes it's missing the description or country. The location |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
* that was saved during the initial request is known to be good and complete, though. |
9 | 367 |
* It should be left intact until the user explicitly changes it (either by manually |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
* searching for a new location, or by changing their IP address). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
* |
9 | 370 |
* If the location was updated with an incomplete response from the API, then it could |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
* break assumptions that the UI makes (e.g., that there will always be a description |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
* that corresponds to a latitude/longitude location). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* The location is stored network-wide, so that the user doesn't have to set it on each site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
if ( $ip_changed || $search ) { |
18 | 377 |
update_user_meta( $user_id, 'community-events-location', $events['location'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
wp_send_json_success( $events ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
/** |
5 | 385 |
* Ajax handler for dashboard widgets. |
386 |
* |
|
387 |
* @since 3.4.0 |
|
388 |
*/ |
|
0 | 389 |
function wp_ajax_dashboard_widgets() { |
390 |
require_once ABSPATH . 'wp-admin/includes/dashboard.php'; |
|
391 |
||
5 | 392 |
$pagenow = $_GET['pagenow']; |
16 | 393 |
if ( 'dashboard-user' === $pagenow || 'dashboard-network' === $pagenow || 'dashboard' === $pagenow ) { |
5 | 394 |
set_current_screen( $pagenow ); |
395 |
} |
|
396 |
||
0 | 397 |
switch ( $_GET['widget'] ) { |
9 | 398 |
case 'dashboard_primary': |
0 | 399 |
wp_dashboard_primary(); |
400 |
break; |
|
401 |
} |
|
402 |
wp_die(); |
|
403 |
} |
|
404 |
||
5 | 405 |
/** |
406 |
* Ajax handler for Customizer preview logged-in status. |
|
407 |
* |
|
408 |
* @since 3.4.0 |
|
409 |
*/ |
|
0 | 410 |
function wp_ajax_logged_in() { |
411 |
wp_die( 1 ); |
|
412 |
} |
|
413 |
||
5 | 414 |
// |
415 |
// Ajax helpers. |
|
416 |
// |
|
0 | 417 |
|
418 |
/** |
|
419 |
* Sends back current comment total and new page links if they need to be updated. |
|
420 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
* Contrary to normal success Ajax response ("1"), die with time() on success. |
0 | 422 |
* |
16 | 423 |
* @since 2.7.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
* @access private |
0 | 425 |
* |
426 |
* @param int $comment_id |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* @param int $delta |
0 | 428 |
*/ |
429 |
function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { |
|
9 | 430 |
$total = isset( $_POST['_total'] ) ? (int) $_POST['_total'] : 0; |
0 | 431 |
$per_page = isset( $_POST['_per_page'] ) ? (int) $_POST['_per_page'] : 0; |
9 | 432 |
$page = isset( $_POST['_page'] ) ? (int) $_POST['_page'] : 0; |
433 |
$url = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : ''; |
|
0 | 434 |
|
16 | 435 |
// JS didn't send us everything we need to know. Just die with success message. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
if ( ! $total || ! $per_page || ! $page || ! $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
$time = time(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
$comment = get_comment( $comment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
$comment_status = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
$comment_link = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
if ( $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
$comment_status = $comment->comment_approved; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
if ( 1 === (int) $comment_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
$comment_link = get_comment_link( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
$counts = wp_count_comments(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
|
9 | 452 |
$x = new WP_Ajax_Response( |
453 |
array( |
|
454 |
'what' => 'comment', |
|
455 |
// Here for completeness - not used. |
|
456 |
'id' => $comment_id, |
|
457 |
'supplemental' => array( |
|
458 |
'status' => $comment_status, |
|
459 |
'postId' => $comment ? $comment->comment_post_ID : '', |
|
460 |
'time' => $time, |
|
461 |
'in_moderation' => $counts->moderated, |
|
462 |
'i18n_comments_text' => sprintf( |
|
16 | 463 |
/* translators: %s: Number of comments. */ |
9 | 464 |
_n( '%s Comment', '%s Comments', $counts->approved ), |
465 |
number_format_i18n( $counts->approved ) |
|
466 |
), |
|
467 |
'i18n_moderation_text' => sprintf( |
|
16 | 468 |
/* translators: %s: Number of comments. */ |
9 | 469 |
_n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ), |
470 |
number_format_i18n( $counts->moderated ) |
|
471 |
), |
|
472 |
'comment_link' => $comment_link, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
) |
9 | 475 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
$x->send(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
} |
0 | 478 |
|
479 |
$total += $delta; |
|
9 | 480 |
if ( $total < 0 ) { |
0 | 481 |
$total = 0; |
9 | 482 |
} |
0 | 483 |
|
16 | 484 |
// Only do the expensive stuff on a page-break, and about 1 other time per page. |
0 | 485 |
if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) { |
486 |
$post_id = 0; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
// What type of comment count are we looking for? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
$status = 'all'; |
0 | 489 |
$parsed = parse_url( $url ); |
16 | 490 |
|
0 | 491 |
if ( isset( $parsed['query'] ) ) { |
492 |
parse_str( $parsed['query'], $query_vars ); |
|
16 | 493 |
|
9 | 494 |
if ( ! empty( $query_vars['comment_status'] ) ) { |
0 | 495 |
$status = $query_vars['comment_status']; |
9 | 496 |
} |
16 | 497 |
|
9 | 498 |
if ( ! empty( $query_vars['p'] ) ) { |
0 | 499 |
$post_id = (int) $query_vars['p']; |
9 | 500 |
} |
16 | 501 |
|
9 | 502 |
if ( ! empty( $query_vars['comment_type'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
$type = $query_vars['comment_type']; |
9 | 504 |
} |
0 | 505 |
} |
506 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
if ( empty( $type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
// Only use the comment count if not filtering by a comment_type. |
9 | 509 |
$comment_count = wp_count_comments( $post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
// We're looking for a known type of comment count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
if ( isset( $comment_count->$status ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
$total = $comment_count->$status; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
// Else use the decremented value from above. |
0 | 517 |
} |
518 |
||
5 | 519 |
// The time since the last comment count. |
9 | 520 |
$time = time(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
$comment = get_comment( $comment_id ); |
9 | 522 |
$counts = wp_count_comments(); |
523 |
||
524 |
$x = new WP_Ajax_Response( |
|
525 |
array( |
|
526 |
'what' => 'comment', |
|
527 |
'id' => $comment_id, |
|
528 |
'supplemental' => array( |
|
529 |
'status' => $comment ? $comment->comment_approved : '', |
|
530 |
'postId' => $comment ? $comment->comment_post_ID : '', |
|
16 | 531 |
/* translators: %s: Number of comments. */ |
9 | 532 |
'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ), |
533 |
'total_pages' => ceil( $total / $per_page ), |
|
534 |
'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ), |
|
535 |
'total' => $total, |
|
536 |
'time' => $time, |
|
537 |
'in_moderation' => $counts->moderated, |
|
538 |
'i18n_moderation_text' => sprintf( |
|
16 | 539 |
/* translators: %s: Number of comments. */ |
9 | 540 |
_n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ), |
541 |
number_format_i18n( $counts->moderated ) |
|
542 |
), |
|
543 |
), |
|
0 | 544 |
) |
9 | 545 |
); |
0 | 546 |
$x->send(); |
547 |
} |
|
548 |
||
5 | 549 |
// |
550 |
// POST-based Ajax handlers. |
|
551 |
// |
|
552 |
||
553 |
/** |
|
554 |
* Ajax handler for adding a hierarchical term. |
|
555 |
* |
|
16 | 556 |
* @since 3.1.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
* @access private |
0 | 558 |
*/ |
559 |
function _wp_ajax_add_hierarchical_term() { |
|
9 | 560 |
$action = $_POST['action']; |
561 |
$taxonomy = get_taxonomy( substr( $action, 4 ) ); |
|
0 | 562 |
check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name ); |
16 | 563 |
|
9 | 564 |
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { |
0 | 565 |
wp_die( -1 ); |
9 | 566 |
} |
16 | 567 |
|
9 | 568 |
$names = explode( ',', $_POST[ 'new' . $taxonomy->name ] ); |
569 |
$parent = isset( $_POST[ 'new' . $taxonomy->name . '_parent' ] ) ? (int) $_POST[ 'new' . $taxonomy->name . '_parent' ] : 0; |
|
16 | 570 |
|
9 | 571 |
if ( 0 > $parent ) { |
0 | 572 |
$parent = 0; |
9 | 573 |
} |
16 | 574 |
|
575 |
if ( 'category' === $taxonomy->name ) { |
|
9 | 576 |
$post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array(); |
577 |
} else { |
|
578 |
$post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][ $taxonomy->name ] ) ) ? (array) $_POST['tax_input'][ $taxonomy->name ] : array(); |
|
579 |
} |
|
16 | 580 |
|
0 | 581 |
$checked_categories = array_map( 'absint', (array) $post_category ); |
9 | 582 |
$popular_ids = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false ); |
0 | 583 |
|
584 |
foreach ( $names as $cat_name ) { |
|
9 | 585 |
$cat_name = trim( $cat_name ); |
586 |
$category_nicename = sanitize_title( $cat_name ); |
|
16 | 587 |
|
9 | 588 |
if ( '' === $category_nicename ) { |
0 | 589 |
continue; |
9 | 590 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
$cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); |
16 | 593 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
if ( ! $cat_id || is_wp_error( $cat_id ) ) { |
0 | 595 |
continue; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
} else { |
0 | 597 |
$cat_id = $cat_id['term_id']; |
5 | 598 |
} |
16 | 599 |
|
0 | 600 |
$checked_categories[] = $cat_id; |
16 | 601 |
|
602 |
if ( $parent ) { // Do these all at once in a second. |
|
0 | 603 |
continue; |
9 | 604 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
|
0 | 606 |
ob_start(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
|
9 | 608 |
wp_terms_checklist( |
609 |
0, |
|
610 |
array( |
|
611 |
'taxonomy' => $taxonomy->name, |
|
612 |
'descendants_and_self' => $cat_id, |
|
613 |
'selected_cats' => $checked_categories, |
|
614 |
'popular_cats' => $popular_ids, |
|
615 |
) |
|
616 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
$data = ob_get_clean(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
|
0 | 620 |
$add = array( |
9 | 621 |
'what' => $taxonomy->name, |
622 |
'id' => $cat_id, |
|
623 |
'data' => str_replace( array( "\n", "\t" ), '', $data ), |
|
624 |
'position' => -1, |
|
0 | 625 |
); |
626 |
} |
|
627 |
||
16 | 628 |
if ( $parent ) { // Foncy - replace the parent and all its children. |
9 | 629 |
$parent = get_term( $parent, $taxonomy->name ); |
0 | 630 |
$term_id = $parent->term_id; |
631 |
||
16 | 632 |
while ( $parent->parent ) { // Get the top parent. |
0 | 633 |
$parent = get_term( $parent->parent, $taxonomy->name ); |
9 | 634 |
if ( is_wp_error( $parent ) ) { |
0 | 635 |
break; |
9 | 636 |
} |
0 | 637 |
$term_id = $parent->term_id; |
638 |
} |
|
639 |
||
640 |
ob_start(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
|
9 | 642 |
wp_terms_checklist( |
643 |
0, |
|
644 |
array( |
|
645 |
'taxonomy' => $taxonomy->name, |
|
646 |
'descendants_and_self' => $term_id, |
|
647 |
'selected_cats' => $checked_categories, |
|
648 |
'popular_cats' => $popular_ids, |
|
649 |
) |
|
650 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
$data = ob_get_clean(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
|
0 | 654 |
$add = array( |
9 | 655 |
'what' => $taxonomy->name, |
656 |
'id' => $term_id, |
|
657 |
'data' => str_replace( array( "\n", "\t" ), '', $data ), |
|
658 |
'position' => -1, |
|
0 | 659 |
); |
660 |
} |
|
661 |
||
662 |
ob_start(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
|
9 | 664 |
wp_dropdown_categories( |
665 |
array( |
|
666 |
'taxonomy' => $taxonomy->name, |
|
667 |
'hide_empty' => 0, |
|
668 |
'name' => 'new' . $taxonomy->name . '_parent', |
|
669 |
'orderby' => 'name', |
|
670 |
'hierarchical' => 1, |
|
671 |
'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', |
|
672 |
) |
|
673 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
$sup = ob_get_clean(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
|
0 | 677 |
$add['supplemental'] = array( 'newcat_parent' => $sup ); |
678 |
||
679 |
$x = new WP_Ajax_Response( $add ); |
|
680 |
$x->send(); |
|
681 |
} |
|
682 |
||
5 | 683 |
/** |
684 |
* Ajax handler for deleting a comment. |
|
685 |
* |
|
686 |
* @since 3.1.0 |
|
687 |
*/ |
|
0 | 688 |
function wp_ajax_delete_comment() { |
689 |
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; |
|
690 |
||
16 | 691 |
$comment = get_comment( $id ); |
692 |
||
693 |
if ( ! $comment ) { |
|
0 | 694 |
wp_die( time() ); |
9 | 695 |
} |
16 | 696 |
|
9 | 697 |
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { |
0 | 698 |
wp_die( -1 ); |
9 | 699 |
} |
0 | 700 |
|
701 |
check_ajax_referer( "delete-comment_$id" ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
$status = wp_get_comment_status( $comment ); |
16 | 703 |
$delta = -1; |
704 |
||
9 | 705 |
if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) { |
16 | 706 |
if ( 'trash' === $status ) { |
0 | 707 |
wp_die( time() ); |
9 | 708 |
} |
16 | 709 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
$r = wp_trash_comment( $comment ); |
9 | 711 |
} elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) { |
16 | 712 |
if ( 'trash' !== $status ) { |
0 | 713 |
wp_die( time() ); |
9 | 714 |
} |
16 | 715 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
$r = wp_untrash_comment( $comment ); |
16 | 717 |
|
718 |
// Undo trash, not in Trash. |
|
719 |
if ( ! isset( $_POST['comment_status'] ) || 'trash' !== $_POST['comment_status'] ) { |
|
0 | 720 |
$delta = 1; |
9 | 721 |
} |
722 |
} elseif ( isset( $_POST['spam'] ) && 1 == $_POST['spam'] ) { |
|
16 | 723 |
if ( 'spam' === $status ) { |
0 | 724 |
wp_die( time() ); |
9 | 725 |
} |
16 | 726 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
$r = wp_spam_comment( $comment ); |
9 | 728 |
} elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) { |
16 | 729 |
if ( 'spam' !== $status ) { |
0 | 730 |
wp_die( time() ); |
9 | 731 |
} |
16 | 732 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
$r = wp_unspam_comment( $comment ); |
16 | 734 |
|
735 |
// Undo spam, not in spam. |
|
736 |
if ( ! isset( $_POST['comment_status'] ) || 'spam' !== $_POST['comment_status'] ) { |
|
0 | 737 |
$delta = 1; |
9 | 738 |
} |
739 |
} elseif ( isset( $_POST['delete'] ) && 1 == $_POST['delete'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
$r = wp_delete_comment( $comment ); |
0 | 741 |
} else { |
742 |
wp_die( -1 ); |
|
743 |
} |
|
744 |
||
16 | 745 |
if ( $r ) { |
746 |
// Decide if we need to send back '1' or a more complicated response including page links and comment counts. |
|
0 | 747 |
_wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); |
9 | 748 |
} |
16 | 749 |
|
0 | 750 |
wp_die( 0 ); |
751 |
} |
|
752 |
||
5 | 753 |
/** |
754 |
* Ajax handler for deleting a tag. |
|
755 |
* |
|
756 |
* @since 3.1.0 |
|
757 |
*/ |
|
0 | 758 |
function wp_ajax_delete_tag() { |
759 |
$tag_id = (int) $_POST['tag_ID']; |
|
760 |
check_ajax_referer( "delete-tag_$tag_id" ); |
|
761 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
if ( ! current_user_can( 'delete_term', $tag_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
wp_die( -1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
|
9 | 766 |
$taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag'; |
767 |
$tag = get_term( $tag_id, $taxonomy ); |
|
16 | 768 |
|
9 | 769 |
if ( ! $tag || is_wp_error( $tag ) ) { |
0 | 770 |
wp_die( 1 ); |
9 | 771 |
} |
772 |
||
773 |
if ( wp_delete_term( $tag_id, $taxonomy ) ) { |
|
0 | 774 |
wp_die( 1 ); |
9 | 775 |
} else { |
0 | 776 |
wp_die( 0 ); |
9 | 777 |
} |
0 | 778 |
} |
779 |
||
5 | 780 |
/** |
781 |
* Ajax handler for deleting a link. |
|
782 |
* |
|
783 |
* @since 3.1.0 |
|
784 |
*/ |
|
0 | 785 |
function wp_ajax_delete_link() { |
786 |
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; |
|
787 |
||
788 |
check_ajax_referer( "delete-bookmark_$id" ); |
|
16 | 789 |
|
9 | 790 |
if ( ! current_user_can( 'manage_links' ) ) { |
0 | 791 |
wp_die( -1 ); |
9 | 792 |
} |
0 | 793 |
|
794 |
$link = get_bookmark( $id ); |
|
9 | 795 |
if ( ! $link || is_wp_error( $link ) ) { |
0 | 796 |
wp_die( 1 ); |
9 | 797 |
} |
798 |
||
799 |
if ( wp_delete_link( $id ) ) { |
|
0 | 800 |
wp_die( 1 ); |
9 | 801 |
} else { |
0 | 802 |
wp_die( 0 ); |
9 | 803 |
} |
0 | 804 |
} |
805 |
||
5 | 806 |
/** |
807 |
* Ajax handler for deleting meta. |
|
808 |
* |
|
809 |
* @since 3.1.0 |
|
810 |
*/ |
|
0 | 811 |
function wp_ajax_delete_meta() { |
812 |
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; |
|
813 |
||
814 |
check_ajax_referer( "delete-meta_$id" ); |
|
16 | 815 |
$meta = get_metadata_by_mid( 'post', $id ); |
816 |
||
817 |
if ( ! $meta ) { |
|
0 | 818 |
wp_die( 1 ); |
9 | 819 |
} |
820 |
||
821 |
if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $meta->post_id, $meta->meta_key ) ) { |
|
0 | 822 |
wp_die( -1 ); |
9 | 823 |
} |
16 | 824 |
|
9 | 825 |
if ( delete_meta( $meta->meta_id ) ) { |
0 | 826 |
wp_die( 1 ); |
9 | 827 |
} |
16 | 828 |
|
0 | 829 |
wp_die( 0 ); |
830 |
} |
|
831 |
||
5 | 832 |
/** |
833 |
* Ajax handler for deleting a post. |
|
834 |
* |
|
835 |
* @since 3.1.0 |
|
836 |
* |
|
837 |
* @param string $action Action to perform. |
|
838 |
*/ |
|
0 | 839 |
function wp_ajax_delete_post( $action ) { |
9 | 840 |
if ( empty( $action ) ) { |
0 | 841 |
$action = 'delete-post'; |
9 | 842 |
} |
16 | 843 |
|
0 | 844 |
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; |
845 |
check_ajax_referer( "{$action}_$id" ); |
|
16 | 846 |
|
9 | 847 |
if ( ! current_user_can( 'delete_post', $id ) ) { |
0 | 848 |
wp_die( -1 ); |
9 | 849 |
} |
850 |
||
851 |
if ( ! get_post( $id ) ) { |
|
0 | 852 |
wp_die( 1 ); |
9 | 853 |
} |
854 |
||
855 |
if ( wp_delete_post( $id ) ) { |
|
0 | 856 |
wp_die( 1 ); |
9 | 857 |
} else { |
0 | 858 |
wp_die( 0 ); |
9 | 859 |
} |
0 | 860 |
} |
861 |
||
5 | 862 |
/** |
16 | 863 |
* Ajax handler for sending a post to the Trash. |
5 | 864 |
* |
865 |
* @since 3.1.0 |
|
866 |
* |
|
867 |
* @param string $action Action to perform. |
|
868 |
*/ |
|
0 | 869 |
function wp_ajax_trash_post( $action ) { |
9 | 870 |
if ( empty( $action ) ) { |
0 | 871 |
$action = 'trash-post'; |
9 | 872 |
} |
16 | 873 |
|
0 | 874 |
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; |
875 |
check_ajax_referer( "{$action}_$id" ); |
|
16 | 876 |
|
9 | 877 |
if ( ! current_user_can( 'delete_post', $id ) ) { |
0 | 878 |
wp_die( -1 ); |
9 | 879 |
} |
880 |
||
881 |
if ( ! get_post( $id ) ) { |
|
0 | 882 |
wp_die( 1 ); |
9 | 883 |
} |
884 |
||
16 | 885 |
if ( 'trash-post' === $action ) { |
0 | 886 |
$done = wp_trash_post( $id ); |
9 | 887 |
} else { |
0 | 888 |
$done = wp_untrash_post( $id ); |
9 | 889 |
} |
890 |
||
891 |
if ( $done ) { |
|
0 | 892 |
wp_die( 1 ); |
9 | 893 |
} |
0 | 894 |
|
895 |
wp_die( 0 ); |
|
896 |
} |
|
897 |
||
5 | 898 |
/** |
16 | 899 |
* Ajax handler to restore a post from the Trash. |
5 | 900 |
* |
901 |
* @since 3.1.0 |
|
902 |
* |
|
903 |
* @param string $action Action to perform. |
|
904 |
*/ |
|
0 | 905 |
function wp_ajax_untrash_post( $action ) { |
9 | 906 |
if ( empty( $action ) ) { |
0 | 907 |
$action = 'untrash-post'; |
9 | 908 |
} |
16 | 909 |
|
0 | 910 |
wp_ajax_trash_post( $action ); |
911 |
} |
|
912 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
/** |
9 | 914 |
* Ajax handler to delete a page. |
915 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
* |
9 | 918 |
* @param string $action Action to perform. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
*/ |
0 | 920 |
function wp_ajax_delete_page( $action ) { |
9 | 921 |
if ( empty( $action ) ) { |
0 | 922 |
$action = 'delete-page'; |
9 | 923 |
} |
16 | 924 |
|
0 | 925 |
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; |
926 |
check_ajax_referer( "{$action}_$id" ); |
|
16 | 927 |
|
9 | 928 |
if ( ! current_user_can( 'delete_page', $id ) ) { |
0 | 929 |
wp_die( -1 ); |
9 | 930 |
} |
931 |
||
932 |
if ( ! get_post( $id ) ) { |
|
0 | 933 |
wp_die( 1 ); |
9 | 934 |
} |
935 |
||
936 |
if ( wp_delete_post( $id ) ) { |
|
0 | 937 |
wp_die( 1 ); |
9 | 938 |
} else { |
0 | 939 |
wp_die( 0 ); |
9 | 940 |
} |
0 | 941 |
} |
942 |
||
5 | 943 |
/** |
944 |
* Ajax handler to dim a comment. |
|
945 |
* |
|
946 |
* @since 3.1.0 |
|
947 |
*/ |
|
0 | 948 |
function wp_ajax_dim_comment() { |
16 | 949 |
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; |
950 |
$comment = get_comment( $id ); |
|
951 |
||
952 |
if ( ! $comment ) { |
|
9 | 953 |
$x = new WP_Ajax_Response( |
954 |
array( |
|
955 |
'what' => 'comment', |
|
16 | 956 |
'id' => new WP_Error( |
957 |
'invalid_comment', |
|
958 |
/* translators: %d: Comment ID. */ |
|
959 |
sprintf( __( 'Comment %d does not exist' ), $id ) |
|
960 |
), |
|
9 | 961 |
) |
962 |
); |
|
0 | 963 |
$x->send(); |
964 |
} |
|
965 |
||
9 | 966 |
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) ) { |
0 | 967 |
wp_die( -1 ); |
9 | 968 |
} |
0 | 969 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
$current = wp_get_comment_status( $comment ); |
16 | 971 |
|
9 | 972 |
if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) { |
0 | 973 |
wp_die( time() ); |
9 | 974 |
} |
0 | 975 |
|
976 |
check_ajax_referer( "approve-comment_$id" ); |
|
16 | 977 |
|
978 |
if ( in_array( $current, array( 'unapproved', 'spam' ), true ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
$result = wp_set_comment_status( $comment, 'approve', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
$result = wp_set_comment_status( $comment, 'hold', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
} |
0 | 983 |
|
9 | 984 |
if ( is_wp_error( $result ) ) { |
985 |
$x = new WP_Ajax_Response( |
|
986 |
array( |
|
987 |
'what' => 'comment', |
|
988 |
'id' => $result, |
|
989 |
) |
|
990 |
); |
|
0 | 991 |
$x->send(); |
992 |
} |
|
993 |
||
16 | 994 |
// Decide if we need to send back '1' or a more complicated response including page links and comment counts. |
0 | 995 |
_wp_ajax_delete_comment_response( $comment->comment_ID ); |
996 |
wp_die( 0 ); |
|
997 |
} |
|
998 |
||
5 | 999 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
* Ajax handler for adding a link category. |
5 | 1001 |
* |
1002 |
* @since 3.1.0 |
|
1003 |
* |
|
1004 |
* @param string $action Action to perform. |
|
1005 |
*/ |
|
0 | 1006 |
function wp_ajax_add_link_category( $action ) { |
9 | 1007 |
if ( empty( $action ) ) { |
0 | 1008 |
$action = 'add-link-category'; |
9 | 1009 |
} |
16 | 1010 |
|
0 | 1011 |
check_ajax_referer( $action ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
$tax = get_taxonomy( 'link_category' ); |
16 | 1013 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1014 |
if ( ! current_user_can( $tax->cap->manage_terms ) ) { |
0 | 1015 |
wp_die( -1 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
} |
16 | 1017 |
|
9 | 1018 |
$names = explode( ',', wp_unslash( $_POST['newcat'] ) ); |
1019 |
$x = new WP_Ajax_Response(); |
|
16 | 1020 |
|
0 | 1021 |
foreach ( $names as $cat_name ) { |
9 | 1022 |
$cat_name = trim( $cat_name ); |
1023 |
$slug = sanitize_title( $cat_name ); |
|
16 | 1024 |
|
9 | 1025 |
if ( '' === $slug ) { |
0 | 1026 |
continue; |
9 | 1027 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
$cat_id = wp_insert_term( $cat_name, 'link_category' ); |
16 | 1030 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
if ( ! $cat_id || is_wp_error( $cat_id ) ) { |
0 | 1032 |
continue; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
} else { |
0 | 1034 |
$cat_id = $cat_id['term_id']; |
5 | 1035 |
} |
16 | 1036 |
|
0 | 1037 |
$cat_name = esc_html( $cat_name ); |
16 | 1038 |
|
9 | 1039 |
$x->add( |
1040 |
array( |
|
1041 |
'what' => 'link-category', |
|
1042 |
'id' => $cat_id, |
|
1043 |
'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='" . esc_attr( $cat_id ) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>", |
|
1044 |
'position' => -1, |
|
1045 |
) |
|
1046 |
); |
|
0 | 1047 |
} |
1048 |
$x->send(); |
|
1049 |
} |
|
1050 |
||
5 | 1051 |
/** |
1052 |
* Ajax handler to add a tag. |
|
1053 |
* |
|
1054 |
* @since 3.1.0 |
|
1055 |
*/ |
|
0 | 1056 |
function wp_ajax_add_tag() { |
1057 |
check_ajax_referer( 'add-tag', '_wpnonce_add-tag' ); |
|
9 | 1058 |
$taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag'; |
1059 |
$tax = get_taxonomy( $taxonomy ); |
|
1060 |
||
1061 |
if ( ! current_user_can( $tax->cap->edit_terms ) ) { |
|
0 | 1062 |
wp_die( -1 ); |
9 | 1063 |
} |
0 | 1064 |
|
1065 |
$x = new WP_Ajax_Response(); |
|
1066 |
||
9 | 1067 |
$tag = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST ); |
1068 |
||
16 | 1069 |
if ( $tag && ! is_wp_error( $tag ) ) { |
1070 |
$tag = get_term( $tag['term_id'], $taxonomy ); |
|
1071 |
} |
|
1072 |
||
1073 |
if ( ! $tag || is_wp_error( $tag ) ) { |
|
9 | 1074 |
$message = __( 'An error has occurred. Please reload the page and try again.' ); |
16 | 1075 |
|
9 | 1076 |
if ( is_wp_error( $tag ) && $tag->get_error_message() ) { |
0 | 1077 |
$message = $tag->get_error_message(); |
9 | 1078 |
} |
1079 |
||
1080 |
$x->add( |
|
1081 |
array( |
|
1082 |
'what' => 'taxonomy', |
|
1083 |
'data' => new WP_Error( 'error', $message ), |
|
1084 |
) |
|
1085 |
); |
|
0 | 1086 |
$x->send(); |
1087 |
} |
|
1088 |
||
1089 |
$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) ); |
|
1090 |
||
9 | 1091 |
$level = 0; |
1092 |
$noparents = ''; |
|
1093 |
||
1094 |
if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
5 | 1095 |
$level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) ); |
0 | 1096 |
ob_start(); |
1097 |
$wp_list_table->single_row( $tag, $level ); |
|
1098 |
$noparents = ob_get_clean(); |
|
1099 |
} |
|
1100 |
||
1101 |
ob_start(); |
|
1102 |
$wp_list_table->single_row( $tag ); |
|
1103 |
$parents = ob_get_clean(); |
|
1104 |
||
9 | 1105 |
$x->add( |
1106 |
array( |
|
1107 |
'what' => 'taxonomy', |
|
1108 |
'supplemental' => compact( 'parents', 'noparents' ), |
|
1109 |
) |
|
1110 |
); |
|
16 | 1111 |
|
9 | 1112 |
$x->add( |
1113 |
array( |
|
1114 |
'what' => 'term', |
|
1115 |
'position' => $level, |
|
1116 |
'supplemental' => (array) $tag, |
|
1117 |
) |
|
1118 |
); |
|
16 | 1119 |
|
0 | 1120 |
$x->send(); |
1121 |
} |
|
1122 |
||
5 | 1123 |
/** |
1124 |
* Ajax handler for getting a tagcloud. |
|
1125 |
* |
|
1126 |
* @since 3.1.0 |
|
1127 |
*/ |
|
0 | 1128 |
function wp_ajax_get_tagcloud() { |
5 | 1129 |
if ( ! isset( $_POST['tax'] ) ) { |
0 | 1130 |
wp_die( 0 ); |
1131 |
} |
|
1132 |
||
5 | 1133 |
$taxonomy = sanitize_key( $_POST['tax'] ); |
9 | 1134 |
$tax = get_taxonomy( $taxonomy ); |
16 | 1135 |
|
5 | 1136 |
if ( ! $tax ) { |
1137 |
wp_die( 0 ); |
|
1138 |
} |
|
1139 |
||
1140 |
if ( ! current_user_can( $tax->cap->assign_terms ) ) { |
|
1141 |
wp_die( -1 ); |
|
1142 |
} |
|
1143 |
||
9 | 1144 |
$tags = get_terms( |
1145 |
array( |
|
16 | 1146 |
'taxonomy' => $taxonomy, |
1147 |
'number' => 45, |
|
1148 |
'orderby' => 'count', |
|
1149 |
'order' => 'DESC', |
|
9 | 1150 |
) |
1151 |
); |
|
1152 |
||
1153 |
if ( empty( $tags ) ) { |
|
0 | 1154 |
wp_die( $tax->labels->not_found ); |
9 | 1155 |
} |
1156 |
||
1157 |
if ( is_wp_error( $tags ) ) { |
|
0 | 1158 |
wp_die( $tags->get_error_message() ); |
9 | 1159 |
} |
0 | 1160 |
|
1161 |
foreach ( $tags as $key => $tag ) { |
|
1162 |
$tags[ $key ]->link = '#'; |
|
9 | 1163 |
$tags[ $key ]->id = $tag->term_id; |
0 | 1164 |
} |
1165 |
||
16 | 1166 |
// We need raw tag names here, so don't filter the output. |
9 | 1167 |
$return = wp_generate_tag_cloud( |
1168 |
$tags, |
|
1169 |
array( |
|
1170 |
'filter' => 0, |
|
1171 |
'format' => 'list', |
|
1172 |
) |
|
1173 |
); |
|
1174 |
||
1175 |
if ( empty( $return ) ) { |
|
0 | 1176 |
wp_die( 0 ); |
9 | 1177 |
} |
0 | 1178 |
|
1179 |
echo $return; |
|
1180 |
wp_die(); |
|
1181 |
} |
|
1182 |
||
5 | 1183 |
/** |
1184 |
* Ajax handler for getting comments. |
|
1185 |
* |
|
1186 |
* @since 3.1.0 |
|
1187 |
* |
|
16 | 1188 |
* @global int $post_id |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
* |
5 | 1190 |
* @param string $action Action to perform. |
1191 |
*/ |
|
0 | 1192 |
function wp_ajax_get_comments( $action ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
global $post_id; |
16 | 1194 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
if ( empty( $action ) ) { |
0 | 1196 |
$action = 'get-comments'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
} |
16 | 1198 |
|
0 | 1199 |
check_ajax_referer( $action ); |
1200 |
||
1201 |
if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) { |
|
1202 |
$id = absint( $_REQUEST['p'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1203 |
if ( ! empty( $id ) ) { |
0 | 1204 |
$post_id = $id; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
} |
0 | 1206 |
} |
1207 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1208 |
if ( empty( $post_id ) ) { |
0 | 1209 |
wp_die( -1 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
} |
0 | 1211 |
|
1212 |
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); |
|
1213 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
0 | 1215 |
wp_die( -1 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
} |
0 | 1217 |
|
1218 |
$wp_list_table->prepare_items(); |
|
1219 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
if ( ! $wp_list_table->has_items() ) { |
0 | 1221 |
wp_die( 1 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
} |
0 | 1223 |
|
1224 |
$x = new WP_Ajax_Response(); |
|
16 | 1225 |
|
0 | 1226 |
ob_start(); |
1227 |
foreach ( $wp_list_table->items as $comment ) { |
|
9 | 1228 |
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) { |
0 | 1229 |
continue; |
9 | 1230 |
} |
0 | 1231 |
get_comment( $comment ); |
1232 |
$wp_list_table->single_row( $comment ); |
|
1233 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
$comment_list_item = ob_get_clean(); |
0 | 1235 |
|
9 | 1236 |
$x->add( |
1237 |
array( |
|
1238 |
'what' => 'comments', |
|
1239 |
'data' => $comment_list_item, |
|
1240 |
) |
|
1241 |
); |
|
16 | 1242 |
|
0 | 1243 |
$x->send(); |
1244 |
} |
|
1245 |
||
5 | 1246 |
/** |
1247 |
* Ajax handler for replying to a comment. |
|
1248 |
* |
|
1249 |
* @since 3.1.0 |
|
1250 |
* |
|
1251 |
* @param string $action Action to perform. |
|
1252 |
*/ |
|
0 | 1253 |
function wp_ajax_replyto_comment( $action ) { |
9 | 1254 |
if ( empty( $action ) ) { |
0 | 1255 |
$action = 'replyto-comment'; |
9 | 1256 |
} |
0 | 1257 |
|
1258 |
check_ajax_referer( $action, '_ajax_nonce-replyto-comment' ); |
|
1259 |
||
1260 |
$comment_post_ID = (int) $_POST['comment_post_ID']; |
|
9 | 1261 |
$post = get_post( $comment_post_ID ); |
16 | 1262 |
|
9 | 1263 |
if ( ! $post ) { |
0 | 1264 |
wp_die( -1 ); |
9 | 1265 |
} |
1266 |
||
1267 |
if ( ! current_user_can( 'edit_post', $comment_post_ID ) ) { |
|
0 | 1268 |
wp_die( -1 ); |
9 | 1269 |
} |
1270 |
||
1271 |
if ( empty( $post->post_status ) ) { |
|
0 | 1272 |
wp_die( 1 ); |
16 | 1273 |
} elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ), true ) ) { |
1274 |
wp_die( __( 'Error: You can’t reply to a comment on a draft post.' ) ); |
|
9 | 1275 |
} |
0 | 1276 |
|
1277 |
$user = wp_get_current_user(); |
|
16 | 1278 |
|
0 | 1279 |
if ( $user->exists() ) { |
9 | 1280 |
$user_ID = $user->ID; |
0 | 1281 |
$comment_author = wp_slash( $user->display_name ); |
1282 |
$comment_author_email = wp_slash( $user->user_email ); |
|
1283 |
$comment_author_url = wp_slash( $user->user_url ); |
|
5 | 1284 |
$comment_content = trim( $_POST['content'] ); |
16 | 1285 |
$comment_type = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : 'comment'; |
1286 |
||
0 | 1287 |
if ( current_user_can( 'unfiltered_html' ) ) { |
9 | 1288 |
if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) { |
0 | 1289 |
$_POST['_wp_unfiltered_html_comment'] = ''; |
9 | 1290 |
} |
0 | 1291 |
|
1292 |
if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) { |
|
16 | 1293 |
kses_remove_filters(); // Start with a clean slate. |
1294 |
kses_init_filters(); // Set up the filters. |
|
9 | 1295 |
remove_filter( 'pre_comment_content', 'wp_filter_post_kses' ); |
1296 |
add_filter( 'pre_comment_content', 'wp_filter_kses' ); |
|
0 | 1297 |
} |
1298 |
} |
|
1299 |
} else { |
|
1300 |
wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) ); |
|
1301 |
} |
|
1302 |
||
16 | 1303 |
if ( '' === $comment_content ) { |
1304 |
wp_die( __( 'Error: Please type your comment text.' ) ); |
|
9 | 1305 |
} |
0 | 1306 |
|
1307 |
$comment_parent = 0; |
|
16 | 1308 |
|
9 | 1309 |
if ( isset( $_POST['comment_ID'] ) ) { |
0 | 1310 |
$comment_parent = absint( $_POST['comment_ID'] ); |
9 | 1311 |
} |
16 | 1312 |
|
0 | 1313 |
$comment_auto_approved = false; |
9 | 1314 |
$commentdata = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID' ); |
0 | 1315 |
|
5 | 1316 |
// Automatically approve parent comment. |
9 | 1317 |
if ( ! empty( $_POST['approve_parent'] ) ) { |
0 | 1318 |
$parent = get_comment( $comment_parent ); |
1319 |
||
16 | 1320 |
if ( $parent && '0' === $parent->comment_approved && $parent->comment_post_ID == $comment_post_ID ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
wp_die( -1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
|
9 | 1325 |
if ( wp_set_comment_status( $parent, 'approve' ) ) { |
0 | 1326 |
$comment_auto_approved = true; |
9 | 1327 |
} |
0 | 1328 |
} |
1329 |
} |
|
1330 |
||
1331 |
$comment_id = wp_new_comment( $commentdata ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
if ( is_wp_error( $comment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
wp_die( $comment_id->get_error_message() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
|
9 | 1337 |
$comment = get_comment( $comment_id ); |
16 | 1338 |
|
9 | 1339 |
if ( ! $comment ) { |
1340 |
wp_die( 1 ); |
|
1341 |
} |
|
1342 |
||
1343 |
$position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; |
|
0 | 1344 |
|
1345 |
ob_start(); |
|
16 | 1346 |
if ( isset( $_REQUEST['mode'] ) && 'dashboard' === $_REQUEST['mode'] ) { |
1347 |
require_once ABSPATH . 'wp-admin/includes/dashboard.php'; |
|
0 | 1348 |
_wp_dashboard_recent_comments_row( $comment ); |
1349 |
} else { |
|
16 | 1350 |
if ( isset( $_REQUEST['mode'] ) && 'single' === $_REQUEST['mode'] ) { |
9 | 1351 |
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); |
0 | 1352 |
} else { |
9 | 1353 |
$wp_list_table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); |
0 | 1354 |
} |
1355 |
$wp_list_table->single_row( $comment ); |
|
1356 |
} |
|
1357 |
$comment_list_item = ob_get_clean(); |
|
1358 |
||
9 | 1359 |
$response = array( |
1360 |
'what' => 'comment', |
|
1361 |
'id' => $comment->comment_ID, |
|
1362 |
'data' => $comment_list_item, |
|
1363 |
'position' => $position, |
|
0 | 1364 |
); |
1365 |
||
9 | 1366 |
$counts = wp_count_comments(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
$response['supplemental'] = array( |
9 | 1368 |
'in_moderation' => $counts->moderated, |
1369 |
'i18n_comments_text' => sprintf( |
|
16 | 1370 |
/* translators: %s: Number of comments. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
_n( '%s Comment', '%s Comments', $counts->approved ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
number_format_i18n( $counts->approved ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
'i18n_moderation_text' => sprintf( |
16 | 1375 |
/* translators: %s: Number of comments. */ |
9 | 1376 |
_n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
number_format_i18n( $counts->moderated ) |
9 | 1378 |
), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
if ( $comment_auto_approved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
$response['supplemental']['parent_approved'] = $parent->comment_ID; |
9 | 1383 |
$response['supplemental']['parent_post_id'] = $parent->comment_post_ID; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
} |
0 | 1385 |
|
1386 |
$x = new WP_Ajax_Response(); |
|
1387 |
$x->add( $response ); |
|
1388 |
$x->send(); |
|
1389 |
} |
|
1390 |
||
5 | 1391 |
/** |
1392 |
* Ajax handler for editing a comment. |
|
1393 |
* |
|
1394 |
* @since 3.1.0 |
|
1395 |
*/ |
|
0 | 1396 |
function wp_ajax_edit_comment() { |
1397 |
check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ); |
|
1398 |
||
1399 |
$comment_id = (int) $_POST['comment_ID']; |
|
16 | 1400 |
|
9 | 1401 |
if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
0 | 1402 |
wp_die( -1 ); |
9 | 1403 |
} |
1404 |
||
16 | 1405 |
if ( '' === $_POST['content'] ) { |
1406 |
wp_die( __( 'Error: Please type your comment text.' ) ); |
|
9 | 1407 |
} |
1408 |
||
1409 |
if ( isset( $_POST['status'] ) ) { |
|
0 | 1410 |
$_POST['comment_status'] = $_POST['status']; |
9 | 1411 |
} |
16 | 1412 |
|
1413 |
$updated = edit_comment(); |
|
1414 |
if ( is_wp_error( $updated ) ) { |
|
1415 |
wp_die( $updated->get_error_message() ); |
|
1416 |
} |
|
0 | 1417 |
|
9 | 1418 |
$position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; |
1419 |
$checkbox = ( isset( $_POST['checkbox'] ) && true == $_POST['checkbox'] ) ? 1 : 0; |
|
0 | 1420 |
$wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); |
1421 |
||
1422 |
$comment = get_comment( $comment_id ); |
|
16 | 1423 |
|
9 | 1424 |
if ( empty( $comment->comment_ID ) ) { |
0 | 1425 |
wp_die( -1 ); |
9 | 1426 |
} |
0 | 1427 |
|
1428 |
ob_start(); |
|
1429 |
$wp_list_table->single_row( $comment ); |
|
1430 |
$comment_list_item = ob_get_clean(); |
|
1431 |
||
1432 |
$x = new WP_Ajax_Response(); |
|
1433 |
||
9 | 1434 |
$x->add( |
1435 |
array( |
|
1436 |
'what' => 'edit_comment', |
|
1437 |
'id' => $comment->comment_ID, |
|
1438 |
'data' => $comment_list_item, |
|
1439 |
'position' => $position, |
|
1440 |
) |
|
1441 |
); |
|
0 | 1442 |
|
1443 |
$x->send(); |
|
1444 |
} |
|
1445 |
||
5 | 1446 |
/** |
1447 |
* Ajax handler for adding a menu item. |
|
1448 |
* |
|
1449 |
* @since 3.1.0 |
|
1450 |
*/ |
|
0 | 1451 |
function wp_ajax_add_menu_item() { |
1452 |
check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' ); |
|
1453 |
||
9 | 1454 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
0 | 1455 |
wp_die( -1 ); |
9 | 1456 |
} |
0 | 1457 |
|
1458 |
require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; |
|
1459 |
||
1460 |
// For performance reasons, we omit some object properties from the checklist. |
|
1461 |
// The following is a hacky way to restore them when adding non-custom items. |
|
1462 |
$menu_items_data = array(); |
|
16 | 1463 |
|
0 | 1464 |
foreach ( (array) $_POST['menu-item'] as $menu_item_data ) { |
1465 |
if ( |
|
1466 |
! empty( $menu_item_data['menu-item-type'] ) && |
|
16 | 1467 |
'custom' !== $menu_item_data['menu-item-type'] && |
0 | 1468 |
! empty( $menu_item_data['menu-item-object-id'] ) |
1469 |
) { |
|
9 | 1470 |
switch ( $menu_item_data['menu-item-type'] ) { |
1471 |
case 'post_type': |
|
0 | 1472 |
$_object = get_post( $menu_item_data['menu-item-object-id'] ); |
9 | 1473 |
break; |
1474 |
||
1475 |
case 'post_type_archive': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
$_object = get_post_type_object( $menu_item_data['menu-item-object'] ); |
9 | 1477 |
break; |
1478 |
||
1479 |
case 'taxonomy': |
|
0 | 1480 |
$_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] ); |
9 | 1481 |
break; |
0 | 1482 |
} |
1483 |
||
1484 |
$_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) ); |
|
9 | 1485 |
$_menu_item = reset( $_menu_items ); |
0 | 1486 |
|
16 | 1487 |
// Restore the missing menu item properties. |
0 | 1488 |
$menu_item_data['menu-item-description'] = $_menu_item->description; |
1489 |
} |
|
1490 |
||
1491 |
$menu_items_data[] = $menu_item_data; |
|
1492 |
} |
|
1493 |
||
1494 |
$item_ids = wp_save_nav_menu_items( 0, $menu_items_data ); |
|
9 | 1495 |
if ( is_wp_error( $item_ids ) ) { |
0 | 1496 |
wp_die( 0 ); |
9 | 1497 |
} |
0 | 1498 |
|
1499 |
$menu_items = array(); |
|
1500 |
||
1501 |
foreach ( (array) $item_ids as $menu_item_id ) { |
|
1502 |
$menu_obj = get_post( $menu_item_id ); |
|
16 | 1503 |
|
0 | 1504 |
if ( ! empty( $menu_obj->ID ) ) { |
9 | 1505 |
$menu_obj = wp_setup_nav_menu_item( $menu_obj ); |
1506 |
$menu_obj->title = empty( $menu_obj->title ) ? __( 'Menu Item' ) : $menu_obj->title; |
|
16 | 1507 |
$menu_obj->label = $menu_obj->title; // Don't show "(pending)" in ajax-added items. |
9 | 1508 |
$menu_items[] = $menu_obj; |
0 | 1509 |
} |
1510 |
} |
|
1511 |
||
5 | 1512 |
/** This filter is documented in wp-admin/includes/nav-menu.php */ |
0 | 1513 |
$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu'] ); |
1514 |
||
9 | 1515 |
if ( ! class_exists( $walker_class_name ) ) { |
0 | 1516 |
wp_die( 0 ); |
9 | 1517 |
} |
0 | 1518 |
|
1519 |
if ( ! empty( $menu_items ) ) { |
|
1520 |
$args = array( |
|
9 | 1521 |
'after' => '', |
1522 |
'before' => '', |
|
1523 |
'link_after' => '', |
|
0 | 1524 |
'link_before' => '', |
9 | 1525 |
'walker' => new $walker_class_name, |
0 | 1526 |
); |
16 | 1527 |
|
0 | 1528 |
echo walk_nav_menu_tree( $menu_items, 0, (object) $args ); |
1529 |
} |
|
16 | 1530 |
|
0 | 1531 |
wp_die(); |
1532 |
} |
|
1533 |
||
5 | 1534 |
/** |
1535 |
* Ajax handler for adding meta. |
|
1536 |
* |
|
1537 |
* @since 3.1.0 |
|
1538 |
*/ |
|
0 | 1539 |
function wp_ajax_add_meta() { |
1540 |
check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' ); |
|
9 | 1541 |
$c = 0; |
1542 |
$pid = (int) $_POST['post_id']; |
|
0 | 1543 |
$post = get_post( $pid ); |
1544 |
||
9 | 1545 |
if ( isset( $_POST['metakeyselect'] ) || isset( $_POST['metakeyinput'] ) ) { |
1546 |
if ( ! current_user_can( 'edit_post', $pid ) ) { |
|
0 | 1547 |
wp_die( -1 ); |
9 | 1548 |
} |
16 | 1549 |
|
1550 |
if ( isset( $_POST['metakeyselect'] ) && '#NONE#' === $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) { |
|
0 | 1551 |
wp_die( 1 ); |
9 | 1552 |
} |
5 | 1553 |
|
1554 |
// If the post is an autodraft, save the post as a draft and then attempt to save the meta. |
|
16 | 1555 |
if ( 'auto-draft' === $post->post_status ) { |
9 | 1556 |
$post_data = array(); |
16 | 1557 |
$post_data['action'] = 'draft'; // Warning fix. |
9 | 1558 |
$post_data['post_ID'] = $pid; |
1559 |
$post_data['post_type'] = $post->post_type; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1560 |
$post_data['post_status'] = 'draft'; |
9 | 1561 |
$now = time(); |
16 | 1562 |
/* translators: 1: Post creation date, 2: Post creation time. */ |
1563 |
$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1564 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1565 |
$pid = edit_post( $post_data ); |
16 | 1566 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1567 |
if ( $pid ) { |
0 | 1568 |
if ( is_wp_error( $pid ) ) { |
9 | 1569 |
$x = new WP_Ajax_Response( |
1570 |
array( |
|
1571 |
'what' => 'meta', |
|
1572 |
'data' => $pid, |
|
1573 |
) |
|
1574 |
); |
|
0 | 1575 |
$x->send(); |
1576 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1577 |
|
16 | 1578 |
$mid = add_meta( $pid ); |
1579 |
if ( ! $mid ) { |
|
0 | 1580 |
wp_die( __( 'Please provide a custom field value.' ) ); |
9 | 1581 |
} |
0 | 1582 |
} else { |
1583 |
wp_die( 0 ); |
|
1584 |
} |
|
16 | 1585 |
} else { |
1586 |
$mid = add_meta( $pid ); |
|
1587 |
if ( ! $mid ) { |
|
1588 |
wp_die( __( 'Please provide a custom field value.' ) ); |
|
1589 |
} |
|
0 | 1590 |
} |
1591 |
||
1592 |
$meta = get_metadata_by_mid( 'post', $mid ); |
|
9 | 1593 |
$pid = (int) $meta->post_id; |
0 | 1594 |
$meta = get_object_vars( $meta ); |
16 | 1595 |
|
1596 |
$x = new WP_Ajax_Response( |
|
9 | 1597 |
array( |
1598 |
'what' => 'meta', |
|
1599 |
'id' => $mid, |
|
1600 |
'data' => _list_meta_row( $meta, $c ), |
|
1601 |
'position' => 1, |
|
1602 |
'supplemental' => array( 'postid' => $pid ), |
|
1603 |
) |
|
1604 |
); |
|
0 | 1605 |
} else { // Update? |
9 | 1606 |
$mid = (int) key( $_POST['meta'] ); |
1607 |
$key = wp_unslash( $_POST['meta'][ $mid ]['key'] ); |
|
1608 |
$value = wp_unslash( $_POST['meta'][ $mid ]['value'] ); |
|
16 | 1609 |
|
1610 |
if ( '' === trim( $key ) ) { |
|
0 | 1611 |
wp_die( __( 'Please provide a custom field name.' ) ); |
9 | 1612 |
} |
16 | 1613 |
|
1614 |
$meta = get_metadata_by_mid( 'post', $mid ); |
|
1615 |
||
1616 |
if ( ! $meta ) { |
|
1617 |
wp_die( 0 ); // If meta doesn't exist. |
|
9 | 1618 |
} |
16 | 1619 |
|
1620 |
if ( |
|
1621 |
is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) || |
|
0 | 1622 |
! current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) || |
16 | 1623 |
! current_user_can( 'edit_post_meta', $meta->post_id, $key ) |
1624 |
) { |
|
0 | 1625 |
wp_die( -1 ); |
9 | 1626 |
} |
16 | 1627 |
|
0 | 1628 |
if ( $meta->meta_value != $value || $meta->meta_key != $key ) { |
16 | 1629 |
$u = update_metadata_by_mid( 'post', $mid, $value, $key ); |
1630 |
if ( ! $u ) { |
|
0 | 1631 |
wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems). |
9 | 1632 |
} |
0 | 1633 |
} |
1634 |
||
9 | 1635 |
$x = new WP_Ajax_Response( |
1636 |
array( |
|
1637 |
'what' => 'meta', |
|
1638 |
'id' => $mid, |
|
1639 |
'old_id' => $mid, |
|
1640 |
'data' => _list_meta_row( |
|
1641 |
array( |
|
1642 |
'meta_key' => $key, |
|
1643 |
'meta_value' => $value, |
|
1644 |
'meta_id' => $mid, |
|
1645 |
), |
|
1646 |
$c |
|
1647 |
), |
|
1648 |
'position' => 0, |
|
1649 |
'supplemental' => array( 'postid' => $meta->post_id ), |
|
1650 |
) |
|
1651 |
); |
|
0 | 1652 |
} |
1653 |
$x->send(); |
|
1654 |
} |
|
1655 |
||
5 | 1656 |
/** |
1657 |
* Ajax handler for adding a user. |
|
1658 |
* |
|
1659 |
* @since 3.1.0 |
|
1660 |
* |
|
1661 |
* @param string $action Action to perform. |
|
1662 |
*/ |
|
0 | 1663 |
function wp_ajax_add_user( $action ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1664 |
if ( empty( $action ) ) { |
0 | 1665 |
$action = 'add-user'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1666 |
} |
0 | 1667 |
|
1668 |
check_ajax_referer( $action ); |
|
16 | 1669 |
|
9 | 1670 |
if ( ! current_user_can( 'create_users' ) ) { |
0 | 1671 |
wp_die( -1 ); |
9 | 1672 |
} |
16 | 1673 |
|
1674 |
$user_id = edit_user(); |
|
1675 |
||
1676 |
if ( ! $user_id ) { |
|
0 | 1677 |
wp_die( 0 ); |
1678 |
} elseif ( is_wp_error( $user_id ) ) { |
|
9 | 1679 |
$x = new WP_Ajax_Response( |
1680 |
array( |
|
1681 |
'what' => 'user', |
|
1682 |
'id' => $user_id, |
|
1683 |
) |
|
1684 |
); |
|
0 | 1685 |
$x->send(); |
1686 |
} |
|
16 | 1687 |
|
1688 |
$user_object = get_userdata( $user_id ); |
|
9 | 1689 |
$wp_list_table = _get_list_table( 'WP_Users_List_Table' ); |
0 | 1690 |
|
1691 |
$role = current( $user_object->roles ); |
|
1692 |
||
9 | 1693 |
$x = new WP_Ajax_Response( |
1694 |
array( |
|
1695 |
'what' => 'user', |
|
1696 |
'id' => $user_id, |
|
1697 |
'data' => $wp_list_table->single_row( $user_object, '', $role ), |
|
1698 |
'supplemental' => array( |
|
1699 |
'show-link' => sprintf( |
|
16 | 1700 |
/* translators: %s: The new user. */ |
9 | 1701 |
__( 'User %s added' ), |
1702 |
'<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>' |
|
1703 |
), |
|
1704 |
'role' => $role, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1705 |
), |
0 | 1706 |
) |
9 | 1707 |
); |
0 | 1708 |
$x->send(); |
1709 |
} |
|
1710 |
||
5 | 1711 |
/** |
1712 |
* Ajax handler for closed post boxes. |
|
1713 |
* |
|
1714 |
* @since 3.1.0 |
|
1715 |
*/ |
|
0 | 1716 |
function wp_ajax_closed_postboxes() { |
1717 |
check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' ); |
|
9 | 1718 |
$closed = isset( $_POST['closed'] ) ? explode( ',', $_POST['closed'] ) : array(); |
1719 |
$closed = array_filter( $closed ); |
|
1720 |
||
1721 |
$hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array(); |
|
1722 |
$hidden = array_filter( $hidden ); |
|
0 | 1723 |
|
1724 |
$page = isset( $_POST['page'] ) ? $_POST['page'] : ''; |
|
1725 |
||
16 | 1726 |
if ( sanitize_key( $page ) != $page ) { |
0 | 1727 |
wp_die( 0 ); |
9 | 1728 |
} |
1729 |
||
16 | 1730 |
$user = wp_get_current_user(); |
1731 |
if ( ! $user ) { |
|
0 | 1732 |
wp_die( -1 ); |
9 | 1733 |
} |
1734 |
||
1735 |
if ( is_array( $closed ) ) { |
|
18 | 1736 |
update_user_meta( $user->ID, "closedpostboxes_$page", $closed ); |
9 | 1737 |
} |
1738 |
||
1739 |
if ( is_array( $hidden ) ) { |
|
16 | 1740 |
// Postboxes that are always shown. |
1741 |
$hidden = array_diff( $hidden, array( 'submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu' ) ); |
|
18 | 1742 |
update_user_meta( $user->ID, "metaboxhidden_$page", $hidden ); |
0 | 1743 |
} |
1744 |
||
1745 |
wp_die( 1 ); |
|
1746 |
} |
|
1747 |
||
5 | 1748 |
/** |
1749 |
* Ajax handler for hidden columns. |
|
1750 |
* |
|
1751 |
* @since 3.1.0 |
|
1752 |
*/ |
|
0 | 1753 |
function wp_ajax_hidden_columns() { |
1754 |
check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' ); |
|
1755 |
$page = isset( $_POST['page'] ) ? $_POST['page'] : ''; |
|
1756 |
||
16 | 1757 |
if ( sanitize_key( $page ) != $page ) { |
0 | 1758 |
wp_die( 0 ); |
9 | 1759 |
} |
1760 |
||
16 | 1761 |
$user = wp_get_current_user(); |
1762 |
if ( ! $user ) { |
|
0 | 1763 |
wp_die( -1 ); |
9 | 1764 |
} |
0 | 1765 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
$hidden = ! empty( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array(); |
18 | 1767 |
update_user_meta( $user->ID, "manage{$page}columnshidden", $hidden ); |
0 | 1768 |
|
1769 |
wp_die( 1 ); |
|
1770 |
} |
|
1771 |
||
5 | 1772 |
/** |
1773 |
* Ajax handler for updating whether to display the welcome panel. |
|
1774 |
* |
|
1775 |
* @since 3.1.0 |
|
1776 |
*/ |
|
0 | 1777 |
function wp_ajax_update_welcome_panel() { |
1778 |
check_ajax_referer( 'welcome-panel-nonce', 'welcomepanelnonce' ); |
|
1779 |
||
9 | 1780 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
0 | 1781 |
wp_die( -1 ); |
9 | 1782 |
} |
0 | 1783 |
|
1784 |
update_user_meta( get_current_user_id(), 'show_welcome_panel', empty( $_POST['visible'] ) ? 0 : 1 ); |
|
1785 |
||
1786 |
wp_die( 1 ); |
|
1787 |
} |
|
1788 |
||
5 | 1789 |
/** |
1790 |
* Ajax handler for retrieving menu meta boxes. |
|
1791 |
* |
|
1792 |
* @since 3.1.0 |
|
1793 |
*/ |
|
0 | 1794 |
function wp_ajax_menu_get_metabox() { |
9 | 1795 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
0 | 1796 |
wp_die( -1 ); |
9 | 1797 |
} |
0 | 1798 |
|
1799 |
require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; |
|
1800 |
||
16 | 1801 |
if ( isset( $_POST['item-type'] ) && 'post_type' === $_POST['item-type'] ) { |
9 | 1802 |
$type = 'posttype'; |
0 | 1803 |
$callback = 'wp_nav_menu_item_post_type_meta_box'; |
9 | 1804 |
$items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); |
16 | 1805 |
} elseif ( isset( $_POST['item-type'] ) && 'taxonomy' === $_POST['item-type'] ) { |
9 | 1806 |
$type = 'taxonomy'; |
0 | 1807 |
$callback = 'wp_nav_menu_item_taxonomy_meta_box'; |
9 | 1808 |
$items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' ); |
1809 |
} |
|
1810 |
||
1811 |
if ( ! empty( $_POST['item-object'] ) && isset( $items[ $_POST['item-object'] ] ) ) { |
|
0 | 1812 |
$menus_meta_box_object = $items[ $_POST['item-object'] ]; |
5 | 1813 |
|
1814 |
/** This filter is documented in wp-admin/includes/nav-menu.php */ |
|
0 | 1815 |
$item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object ); |
16 | 1816 |
|
1817 |
$box_args = array( |
|
1818 |
'id' => 'add-' . $item->name, |
|
1819 |
'title' => $item->labels->name, |
|
1820 |
'callback' => $callback, |
|
1821 |
'args' => $item, |
|
1822 |
); |
|
1823 |
||
0 | 1824 |
ob_start(); |
16 | 1825 |
$callback( null, $box_args ); |
0 | 1826 |
|
1827 |
$markup = ob_get_clean(); |
|
1828 |
||
9 | 1829 |
echo wp_json_encode( |
1830 |
array( |
|
1831 |
'replace-id' => $type . '-' . $item->name, |
|
1832 |
'markup' => $markup, |
|
1833 |
) |
|
1834 |
); |
|
0 | 1835 |
} |
1836 |
||
1837 |
wp_die(); |
|
1838 |
} |
|
1839 |
||
5 | 1840 |
/** |
1841 |
* Ajax handler for internal linking. |
|
1842 |
* |
|
1843 |
* @since 3.1.0 |
|
1844 |
*/ |
|
0 | 1845 |
function wp_ajax_wp_link_ajax() { |
1846 |
check_ajax_referer( 'internal-linking', '_ajax_linking_nonce' ); |
|
1847 |
||
1848 |
$args = array(); |
|
1849 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1850 |
if ( isset( $_POST['search'] ) ) { |
0 | 1851 |
$args['s'] = wp_unslash( $_POST['search'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1852 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1853 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1854 |
if ( isset( $_POST['term'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1855 |
$args['s'] = wp_unslash( $_POST['term'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1856 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1857 |
|
0 | 1858 |
$args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1; |
1859 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1860 |
if ( ! class_exists( '_WP_Editors', false ) ) { |
16 | 1861 |
require ABSPATH . WPINC . '/class-wp-editor.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1862 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1863 |
|
0 | 1864 |
$results = _WP_Editors::wp_link_query( $args ); |
1865 |
||
9 | 1866 |
if ( ! isset( $results ) ) { |
0 | 1867 |
wp_die( 0 ); |
9 | 1868 |
} |
0 | 1869 |
|
5 | 1870 |
echo wp_json_encode( $results ); |
0 | 1871 |
echo "\n"; |
1872 |
||
1873 |
wp_die(); |
|
1874 |
} |
|
1875 |
||
5 | 1876 |
/** |
1877 |
* Ajax handler for menu locations save. |
|
1878 |
* |
|
1879 |
* @since 3.1.0 |
|
1880 |
*/ |
|
0 | 1881 |
function wp_ajax_menu_locations_save() { |
9 | 1882 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
0 | 1883 |
wp_die( -1 ); |
9 | 1884 |
} |
16 | 1885 |
|
0 | 1886 |
check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' ); |
16 | 1887 |
|
9 | 1888 |
if ( ! isset( $_POST['menu-locations'] ) ) { |
0 | 1889 |
wp_die( 0 ); |
9 | 1890 |
} |
16 | 1891 |
|
0 | 1892 |
set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) ); |
1893 |
wp_die( 1 ); |
|
1894 |
} |
|
1895 |
||
5 | 1896 |
/** |
1897 |
* Ajax handler for saving the meta box order. |
|
1898 |
* |
|
1899 |
* @since 3.1.0 |
|
1900 |
*/ |
|
0 | 1901 |
function wp_ajax_meta_box_order() { |
1902 |
check_ajax_referer( 'meta-box-order' ); |
|
9 | 1903 |
$order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false; |
0 | 1904 |
$page_columns = isset( $_POST['page_columns'] ) ? $_POST['page_columns'] : 'auto'; |
1905 |
||
16 | 1906 |
if ( 'auto' !== $page_columns ) { |
0 | 1907 |
$page_columns = (int) $page_columns; |
9 | 1908 |
} |
0 | 1909 |
|
1910 |
$page = isset( $_POST['page'] ) ? $_POST['page'] : ''; |
|
1911 |
||
16 | 1912 |
if ( sanitize_key( $page ) != $page ) { |
0 | 1913 |
wp_die( 0 ); |
9 | 1914 |
} |
1915 |
||
16 | 1916 |
$user = wp_get_current_user(); |
1917 |
if ( ! $user ) { |
|
0 | 1918 |
wp_die( -1 ); |
9 | 1919 |
} |
1920 |
||
1921 |
if ( $order ) { |
|
18 | 1922 |
update_user_meta( $user->ID, "meta-box-order_$page", $order ); |
9 | 1923 |
} |
1924 |
||
1925 |
if ( $page_columns ) { |
|
18 | 1926 |
update_user_meta( $user->ID, "screen_layout_$page", $page_columns ); |
9 | 1927 |
} |
0 | 1928 |
|
16 | 1929 |
wp_send_json_success(); |
0 | 1930 |
} |
1931 |
||
5 | 1932 |
/** |
1933 |
* Ajax handler for menu quick searching. |
|
1934 |
* |
|
1935 |
* @since 3.1.0 |
|
1936 |
*/ |
|
0 | 1937 |
function wp_ajax_menu_quick_search() { |
9 | 1938 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
0 | 1939 |
wp_die( -1 ); |
9 | 1940 |
} |
0 | 1941 |
|
1942 |
require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; |
|
1943 |
||
1944 |
_wp_ajax_menu_quick_search( $_POST ); |
|
1945 |
||
1946 |
wp_die(); |
|
1947 |
} |
|
1948 |
||
5 | 1949 |
/** |
1950 |
* Ajax handler to retrieve a permalink. |
|
1951 |
* |
|
1952 |
* @since 3.1.0 |
|
1953 |
*/ |
|
0 | 1954 |
function wp_ajax_get_permalink() { |
1955 |
check_ajax_referer( 'getpermalink', 'getpermalinknonce' ); |
|
18 | 1956 |
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1957 |
wp_die( get_preview_post_link( $post_id ) ); |
0 | 1958 |
} |
1959 |
||
5 | 1960 |
/** |
1961 |
* Ajax handler to retrieve a sample permalink. |
|
1962 |
* |
|
1963 |
* @since 3.1.0 |
|
1964 |
*/ |
|
0 | 1965 |
function wp_ajax_sample_permalink() { |
1966 |
check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' ); |
|
18 | 1967 |
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; |
9 | 1968 |
$title = isset( $_POST['new_title'] ) ? $_POST['new_title'] : ''; |
1969 |
$slug = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null; |
|
0 | 1970 |
wp_die( get_sample_permalink_html( $post_id, $title, $slug ) ); |
1971 |
} |
|
1972 |
||
5 | 1973 |
/** |
1974 |
* Ajax handler for Quick Edit saving a post from a list table. |
|
1975 |
* |
|
1976 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1977 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1978 |
* @global string $mode List table view mode. |
5 | 1979 |
*/ |
0 | 1980 |
function wp_ajax_inline_save() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
global $mode; |
0 | 1982 |
|
1983 |
check_ajax_referer( 'inlineeditnonce', '_inline_edit' ); |
|
1984 |
||
16 | 1985 |
if ( ! isset( $_POST['post_ID'] ) || ! (int) $_POST['post_ID'] ) { |
0 | 1986 |
wp_die(); |
9 | 1987 |
} |
0 | 1988 |
|
16 | 1989 |
$post_ID = (int) $_POST['post_ID']; |
1990 |
||
1991 |
if ( 'page' === $_POST['post_type'] ) { |
|
9 | 1992 |
if ( ! current_user_can( 'edit_page', $post_ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
wp_die( __( 'Sorry, you are not allowed to edit this page.' ) ); |
9 | 1994 |
} |
0 | 1995 |
} else { |
9 | 1996 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1997 |
wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 1998 |
} |
0 | 1999 |
} |
2000 |
||
16 | 2001 |
$last = wp_check_post_lock( $post_ID ); |
2002 |
if ( $last ) { |
|
9 | 2003 |
$last_user = get_userdata( $last ); |
0 | 2004 |
$last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); |
9 | 2005 |
|
16 | 2006 |
/* translators: %s: User's display name. */ |
9 | 2007 |
$msg_template = __( 'Saving is disabled: %s is currently editing this post.' ); |
16 | 2008 |
|
2009 |
if ( 'page' === $_POST['post_type'] ) { |
|
2010 |
/* translators: %s: User's display name. */ |
|
9 | 2011 |
$msg_template = __( 'Saving is disabled: %s is currently editing this page.' ); |
2012 |
} |
|
2013 |
||
2014 |
printf( $msg_template, esc_html( $last_user_name ) ); |
|
0 | 2015 |
wp_die(); |
2016 |
} |
|
2017 |
||
2018 |
$data = &$_POST; |
|
2019 |
||
2020 |
$post = get_post( $post_ID, ARRAY_A ); |
|
5 | 2021 |
|
2022 |
// Since it's coming from the database. |
|
9 | 2023 |
$post = wp_slash( $post ); |
0 | 2024 |
|
2025 |
$data['content'] = $post['post_content']; |
|
2026 |
$data['excerpt'] = $post['post_excerpt']; |
|
2027 |
||
5 | 2028 |
// Rename. |
0 | 2029 |
$data['user_ID'] = get_current_user_id(); |
2030 |
||
9 | 2031 |
if ( isset( $data['post_parent'] ) ) { |
0 | 2032 |
$data['parent_id'] = $data['post_parent']; |
9 | 2033 |
} |
0 | 2034 |
|
5 | 2035 |
// Status. |
16 | 2036 |
if ( isset( $data['keep_private'] ) && 'private' === $data['keep_private'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2037 |
$data['visibility'] = 'private'; |
0 | 2038 |
$data['post_status'] = 'private'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2039 |
} else { |
0 | 2040 |
$data['post_status'] = $data['_status']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2041 |
} |
0 | 2042 |
|
9 | 2043 |
if ( empty( $data['comment_status'] ) ) { |
0 | 2044 |
$data['comment_status'] = 'closed'; |
9 | 2045 |
} |
16 | 2046 |
|
9 | 2047 |
if ( empty( $data['ping_status'] ) ) { |
0 | 2048 |
$data['ping_status'] = 'closed'; |
9 | 2049 |
} |
0 | 2050 |
|
5 | 2051 |
// Exclude terms from taxonomies that are not supposed to appear in Quick Edit. |
2052 |
if ( ! empty( $data['tax_input'] ) ) { |
|
2053 |
foreach ( $data['tax_input'] as $taxonomy => $terms ) { |
|
2054 |
$tax_object = get_taxonomy( $taxonomy ); |
|
2055 |
/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */ |
|
2056 |
if ( ! apply_filters( 'quick_edit_show_taxonomy', $tax_object->show_in_quick_edit, $taxonomy, $post['post_type'] ) ) { |
|
2057 |
unset( $data['tax_input'][ $taxonomy ] ); |
|
2058 |
} |
|
2059 |
} |
|
2060 |
} |
|
2061 |
||
0 | 2062 |
// Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published. |
16 | 2063 |
if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ), true ) ) { |
0 | 2064 |
$post['post_status'] = 'publish'; |
9 | 2065 |
$data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] ); |
0 | 2066 |
} |
2067 |
||
5 | 2068 |
// Update the post. |
0 | 2069 |
edit_post(); |
2070 |
||
2071 |
$wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) ); |
|
2072 |
||
16 | 2073 |
$mode = 'excerpt' === $_POST['post_view'] ? 'excerpt' : 'list'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2074 |
|
0 | 2075 |
$level = 0; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
if ( is_post_type_hierarchical( $wp_list_table->screen->post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2077 |
$request_post = array( get_post( $_POST['post_ID'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2078 |
$parent = $request_post[0]->post_parent; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2079 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2080 |
while ( $parent > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2081 |
$parent_post = get_post( $parent ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
$parent = $parent_post->post_parent; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
$level++; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
} |
0 | 2085 |
} |
2086 |
||
2087 |
$wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ), $level ); |
|
2088 |
||
2089 |
wp_die(); |
|
2090 |
} |
|
2091 |
||
5 | 2092 |
/** |
2093 |
* Ajax handler for quick edit saving for a term. |
|
2094 |
* |
|
2095 |
* @since 3.1.0 |
|
2096 |
*/ |
|
0 | 2097 |
function wp_ajax_inline_save_tax() { |
2098 |
check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' ); |
|
2099 |
||
2100 |
$taxonomy = sanitize_key( $_POST['taxonomy'] ); |
|
9 | 2101 |
$tax = get_taxonomy( $taxonomy ); |
16 | 2102 |
|
9 | 2103 |
if ( ! $tax ) { |
0 | 2104 |
wp_die( 0 ); |
9 | 2105 |
} |
0 | 2106 |
|
16 | 2107 |
if ( ! isset( $_POST['tax_ID'] ) || ! (int) $_POST['tax_ID'] ) { |
0 | 2108 |
wp_die( -1 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2109 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
|
16 | 2111 |
$id = (int) $_POST['tax_ID']; |
2112 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
if ( ! current_user_can( 'edit_term', $id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2114 |
wp_die( -1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2115 |
} |
0 | 2116 |
|
2117 |
$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) ); |
|
2118 |
||
9 | 2119 |
$tag = get_term( $id, $taxonomy ); |
0 | 2120 |
$_POST['description'] = $tag->description; |
2121 |
||
9 | 2122 |
$updated = wp_update_term( $id, $taxonomy, $_POST ); |
16 | 2123 |
|
9 | 2124 |
if ( $updated && ! is_wp_error( $updated ) ) { |
0 | 2125 |
$tag = get_term( $updated['term_id'], $taxonomy ); |
9 | 2126 |
if ( ! $tag || is_wp_error( $tag ) ) { |
2127 |
if ( is_wp_error( $tag ) && $tag->get_error_message() ) { |
|
0 | 2128 |
wp_die( $tag->get_error_message() ); |
9 | 2129 |
} |
0 | 2130 |
wp_die( __( 'Item not updated.' ) ); |
2131 |
} |
|
2132 |
} else { |
|
9 | 2133 |
if ( is_wp_error( $updated ) && $updated->get_error_message() ) { |
0 | 2134 |
wp_die( $updated->get_error_message() ); |
9 | 2135 |
} |
0 | 2136 |
wp_die( __( 'Item not updated.' ) ); |
2137 |
} |
|
16 | 2138 |
|
9 | 2139 |
$level = 0; |
0 | 2140 |
$parent = $tag->parent; |
16 | 2141 |
|
0 | 2142 |
while ( $parent > 0 ) { |
2143 |
$parent_tag = get_term( $parent, $taxonomy ); |
|
9 | 2144 |
$parent = $parent_tag->parent; |
0 | 2145 |
$level++; |
2146 |
} |
|
16 | 2147 |
|
0 | 2148 |
$wp_list_table->single_row( $tag, $level ); |
2149 |
wp_die(); |
|
2150 |
} |
|
2151 |
||
5 | 2152 |
/** |
2153 |
* Ajax handler for querying posts for the Find Posts modal. |
|
2154 |
* |
|
2155 |
* @see window.findPosts |
|
2156 |
* |
|
2157 |
* @since 3.1.0 |
|
2158 |
*/ |
|
0 | 2159 |
function wp_ajax_find_posts() { |
2160 |
check_ajax_referer( 'find-posts' ); |
|
2161 |
||
2162 |
$post_types = get_post_types( array( 'public' => true ), 'objects' ); |
|
2163 |
unset( $post_types['attachment'] ); |
|
2164 |
||
9 | 2165 |
$s = wp_unslash( $_POST['ps'] ); |
0 | 2166 |
$args = array( |
9 | 2167 |
'post_type' => array_keys( $post_types ), |
2168 |
'post_status' => 'any', |
|
0 | 2169 |
'posts_per_page' => 50, |
2170 |
); |
|
16 | 2171 |
|
9 | 2172 |
if ( '' !== $s ) { |
0 | 2173 |
$args['s'] = $s; |
9 | 2174 |
} |
0 | 2175 |
|
2176 |
$posts = get_posts( $args ); |
|
2177 |
||
5 | 2178 |
if ( ! $posts ) { |
2179 |
wp_send_json_error( __( 'No items found.' ) ); |
|
2180 |
} |
|
2181 |
||
9 | 2182 |
$html = '<table class="widefat"><thead><tr><th class="found-radio"><br /></th><th>' . __( 'Title' ) . '</th><th class="no-break">' . __( 'Type' ) . '</th><th class="no-break">' . __( 'Date' ) . '</th><th class="no-break">' . __( 'Status' ) . '</th></tr></thead><tbody>'; |
2183 |
$alt = ''; |
|
0 | 2184 |
foreach ( $posts as $post ) { |
2185 |
$title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' ); |
|
16 | 2186 |
$alt = ( 'alternate' === $alt ) ? '' : 'alternate'; |
0 | 2187 |
|
2188 |
switch ( $post->post_status ) { |
|
9 | 2189 |
case 'publish': |
2190 |
case 'private': |
|
2191 |
$stat = __( 'Published' ); |
|
0 | 2192 |
break; |
9 | 2193 |
case 'future': |
2194 |
$stat = __( 'Scheduled' ); |
|
0 | 2195 |
break; |
9 | 2196 |
case 'pending': |
2197 |
$stat = __( 'Pending Review' ); |
|
0 | 2198 |
break; |
9 | 2199 |
case 'draft': |
2200 |
$stat = __( 'Draft' ); |
|
0 | 2201 |
break; |
2202 |
} |
|
2203 |
||
16 | 2204 |
if ( '0000-00-00 00:00:00' === $post->post_date ) { |
0 | 2205 |
$time = ''; |
2206 |
} else { |
|
18 | 2207 |
/* translators: Date format in table columns, see https://www.php.net/manual/datetime.format.php */ |
9 | 2208 |
$time = mysql2date( __( 'Y/m/d' ), $post->post_date ); |
0 | 2209 |
} |
2210 |
||
9 | 2211 |
$html .= '<tr class="' . trim( 'found-posts ' . $alt ) . '"><td class="found-radio"><input type="radio" id="found-' . $post->ID . '" name="found_post_id" value="' . esc_attr( $post->ID ) . '"></td>'; |
2212 |
$html .= '<td><label for="found-' . $post->ID . '">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[ $post->post_type ]->labels->singular_name ) . '</td><td class="no-break">' . esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ) . ' </td></tr>' . "\n\n"; |
|
0 | 2213 |
} |
2214 |
||
2215 |
$html .= '</tbody></table>'; |
|
2216 |
||
5 | 2217 |
wp_send_json_success( $html ); |
0 | 2218 |
} |
2219 |
||
5 | 2220 |
/** |
2221 |
* Ajax handler for saving the widgets order. |
|
2222 |
* |
|
2223 |
* @since 3.1.0 |
|
2224 |
*/ |
|
0 | 2225 |
function wp_ajax_widgets_order() { |
2226 |
check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' ); |
|
2227 |
||
9 | 2228 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
0 | 2229 |
wp_die( -1 ); |
9 | 2230 |
} |
0 | 2231 |
|
2232 |
unset( $_POST['savewidgets'], $_POST['action'] ); |
|
2233 |
||
5 | 2234 |
// Save widgets order for all sidebars. |
9 | 2235 |
if ( is_array( $_POST['sidebars'] ) ) { |
0 | 2236 |
$sidebars = array(); |
16 | 2237 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) { |
0 | 2239 |
$sb = array(); |
16 | 2240 |
|
9 | 2241 |
if ( ! empty( $val ) ) { |
2242 |
$val = explode( ',', $val ); |
|
16 | 2243 |
|
0 | 2244 |
foreach ( $val as $k => $v ) { |
9 | 2245 |
if ( strpos( $v, 'widget-' ) === false ) { |
0 | 2246 |
continue; |
9 | 2247 |
} |
2248 |
||
2249 |
$sb[ $k ] = substr( $v, strpos( $v, '_' ) + 1 ); |
|
0 | 2250 |
} |
2251 |
} |
|
9 | 2252 |
$sidebars[ $key ] = $sb; |
0 | 2253 |
} |
16 | 2254 |
|
9 | 2255 |
wp_set_sidebars_widgets( $sidebars ); |
0 | 2256 |
wp_die( 1 ); |
2257 |
} |
|
2258 |
||
2259 |
wp_die( -1 ); |
|
2260 |
} |
|
2261 |
||
5 | 2262 |
/** |
2263 |
* Ajax handler for saving a widget. |
|
2264 |
* |
|
2265 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2266 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2267 |
* @global array $wp_registered_widgets |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2268 |
* @global array $wp_registered_widget_controls |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2269 |
* @global array $wp_registered_widget_updates |
5 | 2270 |
*/ |
0 | 2271 |
function wp_ajax_save_widget() { |
2272 |
global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates; |
|
2273 |
||
2274 |
check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' ); |
|
2275 |
||
9 | 2276 |
if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['id_base'] ) ) { |
0 | 2277 |
wp_die( -1 ); |
9 | 2278 |
} |
0 | 2279 |
|
2280 |
unset( $_POST['savewidgets'], $_POST['action'] ); |
|
2281 |
||
2282 |
/** |
|
2283 |
* Fires early when editing the widgets displayed in sidebars. |
|
2284 |
* |
|
2285 |
* @since 2.8.0 |
|
2286 |
*/ |
|
16 | 2287 |
do_action( 'load-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
0 | 2288 |
|
2289 |
/** |
|
2290 |
* Fires early when editing the widgets displayed in sidebars. |
|
2291 |
* |
|
2292 |
* @since 2.8.0 |
|
2293 |
*/ |
|
16 | 2294 |
do_action( 'widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
0 | 2295 |
|
5 | 2296 |
/** This action is documented in wp-admin/widgets.php */ |
0 | 2297 |
do_action( 'sidebar_admin_setup' ); |
2298 |
||
9 | 2299 |
$id_base = wp_unslash( $_POST['id_base'] ); |
2300 |
$widget_id = wp_unslash( $_POST['widget-id'] ); |
|
2301 |
$sidebar_id = $_POST['sidebar']; |
|
2302 |
$multi_number = ! empty( $_POST['multi_number'] ) ? (int) $_POST['multi_number'] : 0; |
|
2303 |
$settings = isset( $_POST[ 'widget-' . $id_base ] ) && is_array( $_POST[ 'widget-' . $id_base ] ) ? $_POST[ 'widget-' . $id_base ] : false; |
|
2304 |
$error = '<p>' . __( 'An error has occurred. Please reload the page and try again.' ) . '</p>'; |
|
0 | 2305 |
|
2306 |
$sidebars = wp_get_sidebars_widgets(); |
|
9 | 2307 |
$sidebar = isset( $sidebars[ $sidebar_id ] ) ? $sidebars[ $sidebar_id ] : array(); |
0 | 2308 |
|
5 | 2309 |
// Delete. |
9 | 2310 |
if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { |
2311 |
||
2312 |
if ( ! isset( $wp_registered_widgets[ $widget_id ] ) ) { |
|
0 | 2313 |
wp_die( $error ); |
9 | 2314 |
} |
2315 |
||
2316 |
$sidebar = array_diff( $sidebar, array( $widget_id ) ); |
|
2317 |
$_POST = array( |
|
2318 |
'sidebar' => $sidebar_id, |
|
2319 |
'widget-' . $id_base => array(), |
|
2320 |
'the-widget-id' => $widget_id, |
|
2321 |
'delete_widget' => '1', |
|
2322 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2323 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2324 |
/** This action is documented in wp-admin/widgets.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2325 |
do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2326 |
|
9 | 2327 |
} elseif ( $settings && preg_match( '/__i__|%i%/', key( $settings ) ) ) { |
2328 |
if ( ! $multi_number ) { |
|
0 | 2329 |
wp_die( $error ); |
9 | 2330 |
} |
0 | 2331 |
|
5 | 2332 |
$_POST[ 'widget-' . $id_base ] = array( $multi_number => reset( $settings ) ); |
9 | 2333 |
$widget_id = $id_base . '-' . $multi_number; |
2334 |
$sidebar[] = $widget_id; |
|
0 | 2335 |
} |
2336 |
$_POST['widget-id'] = $sidebar; |
|
2337 |
||
2338 |
foreach ( (array) $wp_registered_widget_updates as $name => $control ) { |
|
2339 |
||
2340 |
if ( $name == $id_base ) { |
|
9 | 2341 |
if ( ! is_callable( $control['callback'] ) ) { |
0 | 2342 |
continue; |
9 | 2343 |
} |
0 | 2344 |
|
2345 |
ob_start(); |
|
2346 |
call_user_func_array( $control['callback'], $control['params'] ); |
|
2347 |
ob_end_clean(); |
|
2348 |
break; |
|
2349 |
} |
|
2350 |
} |
|
2351 |
||
9 | 2352 |
if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { |
2353 |
$sidebars[ $sidebar_id ] = $sidebar; |
|
2354 |
wp_set_sidebars_widgets( $sidebars ); |
|
0 | 2355 |
echo "deleted:$widget_id"; |
2356 |
wp_die(); |
|
2357 |
} |
|
2358 |
||
9 | 2359 |
if ( ! empty( $_POST['add_new'] ) ) { |
0 | 2360 |
wp_die(); |
9 | 2361 |
} |
2362 |
||
16 | 2363 |
$form = $wp_registered_widget_controls[ $widget_id ]; |
2364 |
if ( $form ) { |
|
0 | 2365 |
call_user_func_array( $form['callback'], $form['params'] ); |
9 | 2366 |
} |
0 | 2367 |
|
2368 |
wp_die(); |
|
2369 |
} |
|
2370 |
||
5 | 2371 |
/** |
18 | 2372 |
* Ajax handler for updating a widget. |
5 | 2373 |
* |
2374 |
* @since 3.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2375 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2376 |
* @global WP_Customize_Manager $wp_customize |
5 | 2377 |
*/ |
2378 |
function wp_ajax_update_widget() { |
|
2379 |
global $wp_customize; |
|
2380 |
$wp_customize->widgets->wp_ajax_update_widget(); |
|
2381 |
} |
|
2382 |
||
2383 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2384 |
* Ajax handler for removing inactive widgets. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2385 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2386 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2387 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2388 |
function wp_ajax_delete_inactive_widgets() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2389 |
check_ajax_referer( 'remove-inactive-widgets', 'removeinactivewidgets' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2391 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2392 |
wp_die( -1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2393 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2394 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2395 |
unset( $_POST['removeinactivewidgets'], $_POST['action'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2396 |
/** This action is documented in wp-admin/includes/ajax-actions.php */ |
16 | 2397 |
do_action( 'load-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2398 |
/** This action is documented in wp-admin/includes/ajax-actions.php */ |
16 | 2399 |
do_action( 'widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2400 |
/** This action is documented in wp-admin/widgets.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2401 |
do_action( 'sidebar_admin_setup' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2402 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2403 |
$sidebars_widgets = wp_get_sidebars_widgets(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2404 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2405 |
foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) { |
9 | 2406 |
$pieces = explode( '-', $widget_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2407 |
$multi_number = array_pop( $pieces ); |
9 | 2408 |
$id_base = implode( '-', $pieces ); |
2409 |
$widget = get_option( 'widget_' . $id_base ); |
|
2410 |
unset( $widget[ $multi_number ] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2411 |
update_option( 'widget_' . $id_base, $widget ); |
9 | 2412 |
unset( $sidebars_widgets['wp_inactive_widgets'][ $key ] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2413 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2414 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2415 |
wp_set_sidebars_widgets( $sidebars_widgets ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2416 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2417 |
wp_die(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2418 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2419 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2420 |
/** |
16 | 2421 |
* Ajax handler for creating missing image sub-sizes for just uploaded images. |
2422 |
* |
|
2423 |
* @since 5.3.0 |
|
2424 |
*/ |
|
2425 |
function wp_ajax_media_create_image_subsizes() { |
|
2426 |
check_ajax_referer( 'media-form' ); |
|
2427 |
||
2428 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
2429 |
wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to upload files.' ) ) ); |
|
2430 |
} |
|
2431 |
||
2432 |
if ( empty( $_POST['attachment_id'] ) ) { |
|
2433 |
wp_send_json_error( array( 'message' => __( 'Upload failed. Please reload and try again.' ) ) ); |
|
2434 |
} |
|
2435 |
||
2436 |
$attachment_id = (int) $_POST['attachment_id']; |
|
2437 |
||
2438 |
if ( ! empty( $_POST['_wp_upload_failed_cleanup'] ) ) { |
|
2439 |
// Upload failed. Cleanup. |
|
2440 |
if ( wp_attachment_is_image( $attachment_id ) && current_user_can( 'delete_post', $attachment_id ) ) { |
|
2441 |
$attachment = get_post( $attachment_id ); |
|
2442 |
||
2443 |
// Created at most 10 min ago. |
|
2444 |
if ( $attachment && ( time() - strtotime( $attachment->post_date_gmt ) < 600 ) ) { |
|
2445 |
wp_delete_attachment( $attachment_id, true ); |
|
2446 |
wp_send_json_success(); |
|
2447 |
} |
|
2448 |
} |
|
2449 |
} |
|
2450 |
||
2451 |
// Set a custom header with the attachment_id. |
|
2452 |
// Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. |
|
2453 |
if ( ! headers_sent() ) { |
|
2454 |
header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id ); |
|
2455 |
} |
|
2456 |
||
2457 |
// This can still be pretty slow and cause timeout or out of memory errors. |
|
2458 |
// The js that handles the response would need to also handle HTTP 500 errors. |
|
2459 |
wp_update_image_subsizes( $attachment_id ); |
|
2460 |
||
2461 |
if ( ! empty( $_POST['_legacy_support'] ) ) { |
|
2462 |
// The old (inline) uploader. Only needs the attachment_id. |
|
2463 |
$response = array( 'id' => $attachment_id ); |
|
2464 |
} else { |
|
2465 |
// Media modal and Media Library grid view. |
|
2466 |
$response = wp_prepare_attachment_for_js( $attachment_id ); |
|
2467 |
||
2468 |
if ( ! $response ) { |
|
2469 |
wp_send_json_error( array( 'message' => __( 'Upload failed.' ) ) ); |
|
2470 |
} |
|
2471 |
} |
|
2472 |
||
2473 |
// At this point the image has been uploaded successfully. |
|
2474 |
wp_send_json_success( $response ); |
|
2475 |
} |
|
2476 |
||
2477 |
/** |
|
5 | 2478 |
* Ajax handler for uploading attachments |
2479 |
* |
|
2480 |
* @since 3.3.0 |
|
2481 |
*/ |
|
0 | 2482 |
function wp_ajax_upload_attachment() { |
2483 |
check_ajax_referer( 'media-form' ); |
|
5 | 2484 |
/* |
2485 |
* This function does not use wp_send_json_success() / wp_send_json_error() |
|
2486 |
* as the html4 Plupload handler requires a text/html content-type for older IE. |
|
2487 |
* See https://core.trac.wordpress.org/ticket/31037 |
|
2488 |
*/ |
|
2489 |
||
2490 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
9 | 2491 |
echo wp_json_encode( |
2492 |
array( |
|
2493 |
'success' => false, |
|
2494 |
'data' => array( |
|
2495 |
'message' => __( 'Sorry, you are not allowed to upload files.' ), |
|
2496 |
'filename' => esc_html( $_FILES['async-upload']['name'] ), |
|
2497 |
), |
|
5 | 2498 |
) |
9 | 2499 |
); |
5 | 2500 |
|
0 | 2501 |
wp_die(); |
5 | 2502 |
} |
0 | 2503 |
|
2504 |
if ( isset( $_REQUEST['post_id'] ) ) { |
|
2505 |
$post_id = $_REQUEST['post_id']; |
|
16 | 2506 |
|
5 | 2507 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
9 | 2508 |
echo wp_json_encode( |
2509 |
array( |
|
2510 |
'success' => false, |
|
2511 |
'data' => array( |
|
2512 |
'message' => __( 'Sorry, you are not allowed to attach files to this post.' ), |
|
2513 |
'filename' => esc_html( $_FILES['async-upload']['name'] ), |
|
2514 |
), |
|
5 | 2515 |
) |
9 | 2516 |
); |
5 | 2517 |
|
0 | 2518 |
wp_die(); |
5 | 2519 |
} |
0 | 2520 |
} else { |
2521 |
$post_id = null; |
|
2522 |
} |
|
2523 |
||
9 | 2524 |
$post_data = ! empty( $_REQUEST['post_data'] ) ? _wp_get_allowed_postdata( _wp_translate_postdata( false, (array) $_REQUEST['post_data'] ) ) : array(); |
2525 |
||
2526 |
if ( is_wp_error( $post_data ) ) { |
|
2527 |
wp_die( $post_data->get_error_message() ); |
|
2528 |
} |
|
0 | 2529 |
|
2530 |
// If the context is custom header or background, make sure the uploaded file is an image. |
|
16 | 2531 |
if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ), true ) ) { |
5 | 2532 |
$wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] ); |
16 | 2533 |
|
0 | 2534 |
if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { |
9 | 2535 |
echo wp_json_encode( |
2536 |
array( |
|
2537 |
'success' => false, |
|
2538 |
'data' => array( |
|
2539 |
'message' => __( 'The uploaded file is not a valid image. Please try again.' ), |
|
2540 |
'filename' => esc_html( $_FILES['async-upload']['name'] ), |
|
2541 |
), |
|
0 | 2542 |
) |
9 | 2543 |
); |
0 | 2544 |
|
2545 |
wp_die(); |
|
2546 |
} |
|
2547 |
} |
|
2548 |
||
2549 |
$attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data ); |
|
2550 |
||
2551 |
if ( is_wp_error( $attachment_id ) ) { |
|
9 | 2552 |
echo wp_json_encode( |
2553 |
array( |
|
2554 |
'success' => false, |
|
2555 |
'data' => array( |
|
2556 |
'message' => $attachment_id->get_error_message(), |
|
2557 |
'filename' => esc_html( $_FILES['async-upload']['name'] ), |
|
2558 |
), |
|
0 | 2559 |
) |
9 | 2560 |
); |
0 | 2561 |
|
2562 |
wp_die(); |
|
2563 |
} |
|
2564 |
||
2565 |
if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) { |
|
9 | 2566 |
if ( 'custom-background' === $post_data['context'] ) { |
0 | 2567 |
update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', $post_data['theme'] ); |
9 | 2568 |
} |
2569 |
||
2570 |
if ( 'custom-header' === $post_data['context'] ) { |
|
0 | 2571 |
update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] ); |
9 | 2572 |
} |
2573 |
} |
|
2574 |
||
16 | 2575 |
$attachment = wp_prepare_attachment_for_js( $attachment_id ); |
2576 |
if ( ! $attachment ) { |
|
0 | 2577 |
wp_die(); |
9 | 2578 |
} |
2579 |
||
2580 |
echo wp_json_encode( |
|
2581 |
array( |
|
2582 |
'success' => true, |
|
2583 |
'data' => $attachment, |
|
2584 |
) |
|
2585 |
); |
|
0 | 2586 |
|
2587 |
wp_die(); |
|
2588 |
} |
|
2589 |
||
5 | 2590 |
/** |
2591 |
* Ajax handler for image editing. |
|
2592 |
* |
|
2593 |
* @since 3.1.0 |
|
2594 |
*/ |
|
0 | 2595 |
function wp_ajax_image_editor() { |
18 | 2596 |
$attachment_id = (int) $_POST['postid']; |
16 | 2597 |
|
9 | 2598 |
if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { |
0 | 2599 |
wp_die( -1 ); |
9 | 2600 |
} |
0 | 2601 |
|
2602 |
check_ajax_referer( "image_editor-$attachment_id" ); |
|
16 | 2603 |
include_once ABSPATH . 'wp-admin/includes/image-edit.php'; |
0 | 2604 |
|
2605 |
$msg = false; |
|
18 | 2606 |
|
0 | 2607 |
switch ( $_POST['do'] ) { |
9 | 2608 |
case 'save': |
2609 |
$msg = wp_save_image( $attachment_id ); |
|
18 | 2610 |
if ( ! empty( $msg->error ) ) { |
16 | 2611 |
wp_send_json_error( $msg ); |
2612 |
} |
|
2613 |
||
2614 |
wp_send_json_success( $msg ); |
|
0 | 2615 |
break; |
9 | 2616 |
case 'scale': |
2617 |
$msg = wp_save_image( $attachment_id ); |
|
0 | 2618 |
break; |
9 | 2619 |
case 'restore': |
2620 |
$msg = wp_restore_image( $attachment_id ); |
|
0 | 2621 |
break; |
2622 |
} |
|
2623 |
||
16 | 2624 |
ob_start(); |
9 | 2625 |
wp_image_editor( $attachment_id, $msg ); |
16 | 2626 |
$html = ob_get_clean(); |
2627 |
||
18 | 2628 |
if ( ! empty( $msg->error ) ) { |
16 | 2629 |
wp_send_json_error( |
2630 |
array( |
|
2631 |
'message' => $msg, |
|
2632 |
'html' => $html, |
|
2633 |
) |
|
2634 |
); |
|
2635 |
} |
|
2636 |
||
2637 |
wp_send_json_success( |
|
2638 |
array( |
|
2639 |
'message' => $msg, |
|
2640 |
'html' => $html, |
|
2641 |
) |
|
2642 |
); |
|
0 | 2643 |
} |
2644 |
||
5 | 2645 |
/** |
2646 |
* Ajax handler for setting the featured image. |
|
2647 |
* |
|
2648 |
* @since 3.1.0 |
|
2649 |
*/ |
|
0 | 2650 |
function wp_ajax_set_post_thumbnail() { |
16 | 2651 |
$json = ! empty( $_REQUEST['json'] ); // New-style request. |
0 | 2652 |
|
18 | 2653 |
$post_ID = (int) $_POST['post_id']; |
9 | 2654 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
0 | 2655 |
wp_die( -1 ); |
9 | 2656 |
} |
0 | 2657 |
|
18 | 2658 |
$thumbnail_id = (int) $_POST['thumbnail_id']; |
0 | 2659 |
|
9 | 2660 |
if ( $json ) { |
0 | 2661 |
check_ajax_referer( "update-post_$post_ID" ); |
9 | 2662 |
} else { |
0 | 2663 |
check_ajax_referer( "set_post_thumbnail-$post_ID" ); |
9 | 2664 |
} |
0 | 2665 |
|
16 | 2666 |
if ( '-1' == $thumbnail_id ) { |
0 | 2667 |
if ( delete_post_thumbnail( $post_ID ) ) { |
2668 |
$return = _wp_post_thumbnail_html( null, $post_ID ); |
|
2669 |
$json ? wp_send_json_success( $return ) : wp_die( $return ); |
|
2670 |
} else { |
|
2671 |
wp_die( 0 ); |
|
2672 |
} |
|
2673 |
} |
|
2674 |
||
2675 |
if ( set_post_thumbnail( $post_ID, $thumbnail_id ) ) { |
|
2676 |
$return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID ); |
|
2677 |
$json ? wp_send_json_success( $return ) : wp_die( $return ); |
|
2678 |
} |
|
2679 |
||
2680 |
wp_die( 0 ); |
|
2681 |
} |
|
2682 |
||
5 | 2683 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2684 |
* Ajax handler for retrieving HTML for the featured image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2685 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2686 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2687 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2688 |
function wp_ajax_get_post_thumbnail_html() { |
18 | 2689 |
$post_ID = (int) $_POST['post_id']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2690 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2691 |
check_ajax_referer( "update-post_$post_ID" ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2692 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2693 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2694 |
wp_die( -1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2695 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2696 |
|
18 | 2697 |
$thumbnail_id = (int) $_POST['thumbnail_id']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2698 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2699 |
// For backward compatibility, -1 refers to no featured image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2700 |
if ( -1 === $thumbnail_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2701 |
$thumbnail_id = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2702 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2703 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2704 |
$return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2705 |
wp_send_json_success( $return ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2706 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2707 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2708 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2709 |
* Ajax handler for setting the featured image for an attachment. |
5 | 2710 |
* |
2711 |
* @since 4.0.0 |
|
2712 |
* |
|
2713 |
* @see set_post_thumbnail() |
|
2714 |
*/ |
|
2715 |
function wp_ajax_set_attachment_thumbnail() { |
|
2716 |
if ( empty( $_POST['urls'] ) || ! is_array( $_POST['urls'] ) ) { |
|
2717 |
wp_send_json_error(); |
|
2718 |
} |
|
2719 |
||
2720 |
$thumbnail_id = (int) $_POST['thumbnail_id']; |
|
2721 |
if ( empty( $thumbnail_id ) ) { |
|
2722 |
wp_send_json_error(); |
|
2723 |
} |
|
2724 |
||
2725 |
$post_ids = array(); |
|
2726 |
// For each URL, try to find its corresponding post ID. |
|
2727 |
foreach ( $_POST['urls'] as $url ) { |
|
2728 |
$post_id = attachment_url_to_postid( $url ); |
|
2729 |
if ( ! empty( $post_id ) ) { |
|
2730 |
$post_ids[] = $post_id; |
|
2731 |
} |
|
2732 |
} |
|
2733 |
||
2734 |
if ( empty( $post_ids ) ) { |
|
2735 |
wp_send_json_error(); |
|
2736 |
} |
|
2737 |
||
2738 |
$success = 0; |
|
2739 |
// For each found attachment, set its thumbnail. |
|
2740 |
foreach ( $post_ids as $post_id ) { |
|
2741 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
2742 |
continue; |
|
2743 |
} |
|
2744 |
||
2745 |
if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) { |
|
2746 |
$success++; |
|
2747 |
} |
|
2748 |
} |
|
2749 |
||
2750 |
if ( 0 === $success ) { |
|
2751 |
wp_send_json_error(); |
|
2752 |
} else { |
|
2753 |
wp_send_json_success(); |
|
2754 |
} |
|
2755 |
||
2756 |
wp_send_json_error(); |
|
0 | 2757 |
} |
2758 |
||
5 | 2759 |
/** |
2760 |
* Ajax handler for date formatting. |
|
2761 |
* |
|
2762 |
* @since 3.1.0 |
|
2763 |
*/ |
|
2764 |
function wp_ajax_date_format() { |
|
2765 |
wp_die( date_i18n( sanitize_option( 'date_format', wp_unslash( $_POST['date'] ) ) ) ); |
|
2766 |
} |
|
2767 |
||
2768 |
/** |
|
2769 |
* Ajax handler for time formatting. |
|
2770 |
* |
|
2771 |
* @since 3.1.0 |
|
2772 |
*/ |
|
0 | 2773 |
function wp_ajax_time_format() { |
5 | 2774 |
wp_die( date_i18n( sanitize_option( 'time_format', wp_unslash( $_POST['date'] ) ) ) ); |
0 | 2775 |
} |
2776 |
||
5 | 2777 |
/** |
2778 |
* Ajax handler for saving posts from the fullscreen editor. |
|
2779 |
* |
|
2780 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2781 |
* @deprecated 4.3.0 |
5 | 2782 |
*/ |
0 | 2783 |
function wp_ajax_wp_fullscreen_save_post() { |
2784 |
$post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0; |
|
2785 |
||
5 | 2786 |
$post = null; |
0 | 2787 |
|
9 | 2788 |
if ( $post_id ) { |
0 | 2789 |
$post = get_post( $post_id ); |
9 | 2790 |
} |
2791 |
||
2792 |
check_ajax_referer( 'update-post_' . $post_id, '_wpnonce' ); |
|
0 | 2793 |
|
2794 |
$post_id = edit_post(); |
|
2795 |
||
5 | 2796 |
if ( is_wp_error( $post_id ) ) { |
2797 |
wp_send_json_error(); |
|
0 | 2798 |
} |
2799 |
||
2800 |
if ( $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2801 |
$last_date = mysql2date( __( 'F j, Y' ), $post->post_modified ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2802 |
$last_time = mysql2date( __( 'g:i a' ), $post->post_modified ); |
0 | 2803 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2804 |
$last_date = date_i18n( __( 'F j, Y' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2805 |
$last_time = date_i18n( __( 'g:i a' ) ); |
0 | 2806 |
} |
2807 |
||
16 | 2808 |
$last_id = get_post_meta( $post_id, '_edit_last', true ); |
2809 |
if ( $last_id ) { |
|
5 | 2810 |
$last_user = get_userdata( $last_id ); |
16 | 2811 |
/* translators: 1: User's display name, 2: Date of last edit, 3: Time of last edit. */ |
9 | 2812 |
$last_edited = sprintf( __( 'Last edited by %1$s on %2$s at %3$s' ), esc_html( $last_user->display_name ), $last_date, $last_time ); |
0 | 2813 |
} else { |
16 | 2814 |
/* translators: 1: Date of last edit, 2: Time of last edit. */ |
9 | 2815 |
$last_edited = sprintf( __( 'Last edited on %1$s at %2$s' ), $last_date, $last_time ); |
0 | 2816 |
} |
2817 |
||
5 | 2818 |
wp_send_json_success( array( 'last_edited' => $last_edited ) ); |
0 | 2819 |
} |
2820 |
||
5 | 2821 |
/** |
2822 |
* Ajax handler for removing a post lock. |
|
2823 |
* |
|
2824 |
* @since 3.1.0 |
|
2825 |
*/ |
|
0 | 2826 |
function wp_ajax_wp_remove_post_lock() { |
9 | 2827 |
if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) ) { |
0 | 2828 |
wp_die( 0 ); |
9 | 2829 |
} |
16 | 2830 |
|
0 | 2831 |
$post_id = (int) $_POST['post_ID']; |
16 | 2832 |
$post = get_post( $post_id ); |
2833 |
||
2834 |
if ( ! $post ) { |
|
0 | 2835 |
wp_die( 0 ); |
9 | 2836 |
} |
0 | 2837 |
|
2838 |
check_ajax_referer( 'update-post_' . $post_id ); |
|
2839 |
||
9 | 2840 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
0 | 2841 |
wp_die( -1 ); |
9 | 2842 |
} |
0 | 2843 |
|
2844 |
$active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) ); |
|
16 | 2845 |
|
2846 |
if ( get_current_user_id() != $active_lock[1] ) { |
|
0 | 2847 |
wp_die( 0 ); |
9 | 2848 |
} |
0 | 2849 |
|
2850 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2851 |
* Filters the post lock window duration. |
0 | 2852 |
* |
2853 |
* @since 3.3.0 |
|
2854 |
* |
|
5 | 2855 |
* @param int $interval The interval in seconds the post lock duration |
2856 |
* should last, plus 5 seconds. Default 150. |
|
0 | 2857 |
*/ |
5 | 2858 |
$new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', 150 ) + 5 ) . ':' . $active_lock[1]; |
0 | 2859 |
update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) ); |
2860 |
wp_die( 1 ); |
|
2861 |
} |
|
2862 |
||
5 | 2863 |
/** |
2864 |
* Ajax handler for dismissing a WordPress pointer. |
|
2865 |
* |
|
2866 |
* @since 3.1.0 |
|
2867 |
*/ |
|
0 | 2868 |
function wp_ajax_dismiss_wp_pointer() { |
2869 |
$pointer = $_POST['pointer']; |
|
16 | 2870 |
|
2871 |
if ( sanitize_key( $pointer ) != $pointer ) { |
|
0 | 2872 |
wp_die( 0 ); |
9 | 2873 |
} |
2874 |
||
2875 |
// check_ajax_referer( 'dismiss-pointer_' . $pointer ); |
|
0 | 2876 |
|
2877 |
$dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ); |
|
2878 |
||
16 | 2879 |
if ( in_array( $pointer, $dismissed, true ) ) { |
0 | 2880 |
wp_die( 0 ); |
9 | 2881 |
} |
0 | 2882 |
|
2883 |
$dismissed[] = $pointer; |
|
9 | 2884 |
$dismissed = implode( ',', $dismissed ); |
0 | 2885 |
|
2886 |
update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed ); |
|
2887 |
wp_die( 1 ); |
|
2888 |
} |
|
2889 |
||
2890 |
/** |
|
5 | 2891 |
* Ajax handler for getting an attachment. |
0 | 2892 |
* |
2893 |
* @since 3.5.0 |
|
2894 |
*/ |
|
2895 |
function wp_ajax_get_attachment() { |
|
9 | 2896 |
if ( ! isset( $_REQUEST['id'] ) ) { |
0 | 2897 |
wp_send_json_error(); |
9 | 2898 |
} |
2899 |
||
16 | 2900 |
$id = absint( $_REQUEST['id'] ); |
2901 |
if ( ! $id ) { |
|
0 | 2902 |
wp_send_json_error(); |
9 | 2903 |
} |
2904 |
||
16 | 2905 |
$post = get_post( $id ); |
2906 |
if ( ! $post ) { |
|
0 | 2907 |
wp_send_json_error(); |
9 | 2908 |
} |
2909 |
||
16 | 2910 |
if ( 'attachment' !== $post->post_type ) { |
0 | 2911 |
wp_send_json_error(); |
9 | 2912 |
} |
2913 |
||
2914 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
0 | 2915 |
wp_send_json_error(); |
9 | 2916 |
} |
2917 |
||
16 | 2918 |
$attachment = wp_prepare_attachment_for_js( $id ); |
2919 |
if ( ! $attachment ) { |
|
0 | 2920 |
wp_send_json_error(); |
9 | 2921 |
} |
0 | 2922 |
|
2923 |
wp_send_json_success( $attachment ); |
|
2924 |
} |
|
2925 |
||
2926 |
/** |
|
5 | 2927 |
* Ajax handler for querying attachments. |
0 | 2928 |
* |
2929 |
* @since 3.5.0 |
|
2930 |
*/ |
|
2931 |
function wp_ajax_query_attachments() { |
|
9 | 2932 |
if ( ! current_user_can( 'upload_files' ) ) { |
0 | 2933 |
wp_send_json_error(); |
9 | 2934 |
} |
0 | 2935 |
|
2936 |
$query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array(); |
|
9 | 2937 |
$keys = array( |
2938 |
's', |
|
2939 |
'order', |
|
2940 |
'orderby', |
|
2941 |
'posts_per_page', |
|
2942 |
'paged', |
|
2943 |
'post_mime_type', |
|
2944 |
'post_parent', |
|
2945 |
'author', |
|
2946 |
'post__in', |
|
2947 |
'post__not_in', |
|
2948 |
'year', |
|
2949 |
'monthnum', |
|
5 | 2950 |
); |
16 | 2951 |
|
5 | 2952 |
foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) { |
2953 |
if ( $t->query_var && isset( $query[ $t->query_var ] ) ) { |
|
2954 |
$keys[] = $t->query_var; |
|
2955 |
} |
|
2956 |
} |
|
2957 |
||
9 | 2958 |
$query = array_intersect_key( $query, array_flip( $keys ) ); |
0 | 2959 |
$query['post_type'] = 'attachment'; |
16 | 2960 |
|
2961 |
if ( |
|
2962 |
MEDIA_TRASH && |
|
2963 |
! empty( $_REQUEST['query']['post_status'] ) && |
|
2964 |
'trash' === $_REQUEST['query']['post_status'] |
|
2965 |
) { |
|
5 | 2966 |
$query['post_status'] = 'trash'; |
2967 |
} else { |
|
2968 |
$query['post_status'] = 'inherit'; |
|
2969 |
} |
|
2970 |
||
9 | 2971 |
if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) { |
0 | 2972 |
$query['post_status'] .= ',private'; |
9 | 2973 |
} |
0 | 2974 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2975 |
// Filter query clauses to include filenames. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2976 |
if ( isset( $query['s'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2977 |
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2978 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2979 |
|
0 | 2980 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2981 |
* Filters the arguments passed to WP_Query during an Ajax |
5 | 2982 |
* call for querying attachments. |
0 | 2983 |
* |
2984 |
* @since 3.7.0 |
|
2985 |
* |
|
5 | 2986 |
* @see WP_Query::parse_query() |
2987 |
* |
|
2988 |
* @param array $query An array of query variables. |
|
0 | 2989 |
*/ |
18 | 2990 |
$query = apply_filters( 'ajax_query_attachments_args', $query ); |
2991 |
$attachments_query = new WP_Query( $query ); |
|
2992 |
||
2993 |
$posts = array_map( 'wp_prepare_attachment_for_js', $attachments_query->posts ); |
|
2994 |
$posts = array_filter( $posts ); |
|
2995 |
$total_posts = $attachments_query->found_posts; |
|
2996 |
||
2997 |
if ( $total_posts < 1 ) { |
|
2998 |
// Out-of-bounds, run the query again without LIMIT for total count. |
|
2999 |
unset( $query['paged'] ); |
|
3000 |
||
3001 |
$count_query = new WP_Query(); |
|
3002 |
$count_query->query( $query ); |
|
3003 |
$total_posts = $count_query->found_posts; |
|
3004 |
} |
|
3005 |
||
3006 |
$posts_per_page = (int) $attachments_query->query['posts_per_page']; |
|
3007 |
||
3008 |
$max_pages = $posts_per_page ? ceil( $total_posts / $posts_per_page ) : 0; |
|
3009 |
||
3010 |
header( 'X-WP-Total: ' . (int) $total_posts ); |
|
3011 |
header( 'X-WP-TotalPages: ' . (int) $max_pages ); |
|
0 | 3012 |
|
3013 |
wp_send_json_success( $posts ); |
|
3014 |
} |
|
3015 |
||
3016 |
/** |
|
5 | 3017 |
* Ajax handler for updating attachment attributes. |
0 | 3018 |
* |
3019 |
* @since 3.5.0 |
|
3020 |
*/ |
|
3021 |
function wp_ajax_save_attachment() { |
|
9 | 3022 |
if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) ) { |
0 | 3023 |
wp_send_json_error(); |
9 | 3024 |
} |
3025 |
||
16 | 3026 |
$id = absint( $_REQUEST['id'] ); |
3027 |
if ( ! $id ) { |
|
0 | 3028 |
wp_send_json_error(); |
9 | 3029 |
} |
0 | 3030 |
|
3031 |
check_ajax_referer( 'update-post_' . $id, 'nonce' ); |
|
3032 |
||
9 | 3033 |
if ( ! current_user_can( 'edit_post', $id ) ) { |
0 | 3034 |
wp_send_json_error(); |
9 | 3035 |
} |
0 | 3036 |
|
3037 |
$changes = $_REQUEST['changes']; |
|
3038 |
$post = get_post( $id, ARRAY_A ); |
|
3039 |
||
16 | 3040 |
if ( 'attachment' !== $post['post_type'] ) { |
0 | 3041 |
wp_send_json_error(); |
9 | 3042 |
} |
3043 |
||
3044 |
if ( isset( $changes['parent'] ) ) { |
|
5 | 3045 |
$post['post_parent'] = $changes['parent']; |
9 | 3046 |
} |
3047 |
||
3048 |
if ( isset( $changes['title'] ) ) { |
|
0 | 3049 |
$post['post_title'] = $changes['title']; |
9 | 3050 |
} |
3051 |
||
3052 |
if ( isset( $changes['caption'] ) ) { |
|
0 | 3053 |
$post['post_excerpt'] = $changes['caption']; |
9 | 3054 |
} |
3055 |
||
3056 |
if ( isset( $changes['description'] ) ) { |
|
0 | 3057 |
$post['post_content'] = $changes['description']; |
9 | 3058 |
} |
3059 |
||
3060 |
if ( MEDIA_TRASH && isset( $changes['status'] ) ) { |
|
5 | 3061 |
$post['post_status'] = $changes['status']; |
9 | 3062 |
} |
5 | 3063 |
|
0 | 3064 |
if ( isset( $changes['alt'] ) ) { |
3065 |
$alt = wp_unslash( $changes['alt'] ); |
|
16 | 3066 |
if ( get_post_meta( $id, '_wp_attachment_image_alt', true ) !== $alt ) { |
0 | 3067 |
$alt = wp_strip_all_tags( $alt, true ); |
3068 |
update_post_meta( $id, '_wp_attachment_image_alt', wp_slash( $alt ) ); |
|
3069 |
} |
|
3070 |
} |
|
3071 |
||
5 | 3072 |
if ( wp_attachment_is( 'audio', $post['ID'] ) ) { |
3073 |
$changed = false; |
|
3074 |
$id3data = wp_get_attachment_metadata( $post['ID'] ); |
|
16 | 3075 |
|
5 | 3076 |
if ( ! is_array( $id3data ) ) { |
3077 |
$changed = true; |
|
3078 |
$id3data = array(); |
|
3079 |
} |
|
16 | 3080 |
|
5 | 3081 |
foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) { |
3082 |
if ( isset( $changes[ $key ] ) ) { |
|
9 | 3083 |
$changed = true; |
5 | 3084 |
$id3data[ $key ] = sanitize_text_field( wp_unslash( $changes[ $key ] ) ); |
3085 |
} |
|
3086 |
} |
|
3087 |
||
3088 |
if ( $changed ) { |
|
3089 |
wp_update_attachment_metadata( $id, $id3data ); |
|
3090 |
} |
|
3091 |
} |
|
3092 |
||
3093 |
if ( MEDIA_TRASH && isset( $changes['status'] ) && 'trash' === $changes['status'] ) { |
|
3094 |
wp_delete_post( $id ); |
|
3095 |
} else { |
|
3096 |
wp_update_post( $post ); |
|
3097 |
} |
|
3098 |
||
0 | 3099 |
wp_send_json_success(); |
3100 |
} |
|
3101 |
||
3102 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
* Ajax handler for saving backward compatible attachment attributes. |
0 | 3104 |
* |
3105 |
* @since 3.5.0 |
|
3106 |
*/ |
|
3107 |
function wp_ajax_save_attachment_compat() { |
|
9 | 3108 |
if ( ! isset( $_REQUEST['id'] ) ) { |
3109 |
wp_send_json_error(); |
|
3110 |
} |
|
3111 |
||
16 | 3112 |
$id = absint( $_REQUEST['id'] ); |
3113 |
if ( ! $id ) { |
|
0 | 3114 |
wp_send_json_error(); |
9 | 3115 |
} |
3116 |
||
3117 |
if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) { |
|
0 | 3118 |
wp_send_json_error(); |
9 | 3119 |
} |
16 | 3120 |
|
0 | 3121 |
$attachment_data = $_REQUEST['attachments'][ $id ]; |
3122 |
||
3123 |
check_ajax_referer( 'update-post_' . $id, 'nonce' ); |
|
3124 |
||
9 | 3125 |
if ( ! current_user_can( 'edit_post', $id ) ) { |
0 | 3126 |
wp_send_json_error(); |
9 | 3127 |
} |
0 | 3128 |
|
3129 |
$post = get_post( $id, ARRAY_A ); |
|
3130 |
||
16 | 3131 |
if ( 'attachment' !== $post['post_type'] ) { |
0 | 3132 |
wp_send_json_error(); |
9 | 3133 |
} |
0 | 3134 |
|
3135 |
/** This filter is documented in wp-admin/includes/media.php */ |
|
3136 |
$post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data ); |
|
3137 |
||
3138 |
if ( isset( $post['errors'] ) ) { |
|
3139 |
$errors = $post['errors']; // @todo return me and display me! |
|
3140 |
unset( $post['errors'] ); |
|
3141 |
} |
|
3142 |
||
3143 |
wp_update_post( $post ); |
|
3144 |
||
3145 |
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { |
|
9 | 3146 |
if ( isset( $attachment_data[ $taxonomy ] ) ) { |
0 | 3147 |
wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false ); |
9 | 3148 |
} |
3149 |
} |
|
3150 |
||
16 | 3151 |
$attachment = wp_prepare_attachment_for_js( $id ); |
3152 |
||
3153 |
if ( ! $attachment ) { |
|
0 | 3154 |
wp_send_json_error(); |
9 | 3155 |
} |
0 | 3156 |
|
3157 |
wp_send_json_success( $attachment ); |
|
3158 |
} |
|
3159 |
||
5 | 3160 |
/** |
3161 |
* Ajax handler for saving the attachment order. |
|
3162 |
* |
|
3163 |
* @since 3.5.0 |
|
3164 |
*/ |
|
0 | 3165 |
function wp_ajax_save_attachment_order() { |
9 | 3166 |
if ( ! isset( $_REQUEST['post_id'] ) ) { |
3167 |
wp_send_json_error(); |
|
3168 |
} |
|
3169 |
||
16 | 3170 |
$post_id = absint( $_REQUEST['post_id'] ); |
3171 |
if ( ! $post_id ) { |
|
0 | 3172 |
wp_send_json_error(); |
9 | 3173 |
} |
3174 |
||
3175 |
if ( empty( $_REQUEST['attachments'] ) ) { |
|
0 | 3176 |
wp_send_json_error(); |
9 | 3177 |
} |
0 | 3178 |
|
3179 |
check_ajax_referer( 'update-post_' . $post_id, 'nonce' ); |
|
3180 |
||
3181 |
$attachments = $_REQUEST['attachments']; |
|
3182 |
||
9 | 3183 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
0 | 3184 |
wp_send_json_error(); |
9 | 3185 |
} |
0 | 3186 |
|
3187 |
foreach ( $attachments as $attachment_id => $menu_order ) { |
|
9 | 3188 |
if ( ! current_user_can( 'edit_post', $attachment_id ) ) { |
0 | 3189 |
continue; |
9 | 3190 |
} |
16 | 3191 |
|
3192 |
$attachment = get_post( $attachment_id ); |
|
3193 |
||
3194 |
if ( ! $attachment ) { |
|
9 | 3195 |
continue; |
3196 |
} |
|
16 | 3197 |
|
3198 |
if ( 'attachment' !== $attachment->post_type ) { |
|
0 | 3199 |
continue; |
9 | 3200 |
} |
3201 |
||
3202 |
wp_update_post( |
|
3203 |
array( |
|
3204 |
'ID' => $attachment_id, |
|
3205 |
'menu_order' => $menu_order, |
|
3206 |
) |
|
3207 |
); |
|
0 | 3208 |
} |
3209 |
||
3210 |
wp_send_json_success(); |
|
3211 |
} |
|
3212 |
||
3213 |
/** |
|
5 | 3214 |
* Ajax handler for sending an attachment to the editor. |
3215 |
* |
|
0 | 3216 |
* Generates the HTML to send an attachment to the editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3217 |
* Backward compatible with the {@see 'media_send_to_editor'} filter |
5 | 3218 |
* and the chain of filters that follow. |
0 | 3219 |
* |
3220 |
* @since 3.5.0 |
|
3221 |
*/ |
|
3222 |
function wp_ajax_send_attachment_to_editor() { |
|
3223 |
check_ajax_referer( 'media-send-to-editor', 'nonce' ); |
|
3224 |
||
3225 |
$attachment = wp_unslash( $_POST['attachment'] ); |
|
3226 |
||
18 | 3227 |
$id = (int) $attachment['id']; |
0 | 3228 |
|
16 | 3229 |
$post = get_post( $id ); |
3230 |
if ( ! $post ) { |
|
0 | 3231 |
wp_send_json_error(); |
9 | 3232 |
} |
3233 |
||
16 | 3234 |
if ( 'attachment' !== $post->post_type ) { |
0 | 3235 |
wp_send_json_error(); |
9 | 3236 |
} |
0 | 3237 |
|
3238 |
if ( current_user_can( 'edit_post', $id ) ) { |
|
3239 |
// If this attachment is unattached, attach it. Primarily a back compat thing. |
|
18 | 3240 |
$insert_into_post_id = (int) $_POST['post_id']; |
16 | 3241 |
|
3242 |
if ( 0 == $post->post_parent && $insert_into_post_id ) { |
|
9 | 3243 |
wp_update_post( |
3244 |
array( |
|
3245 |
'ID' => $id, |
|
3246 |
'post_parent' => $insert_into_post_id, |
|
3247 |
) |
|
3248 |
); |
|
0 | 3249 |
} |
3250 |
} |
|
3251 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3252 |
$url = empty( $attachment['url'] ) ? '' : $attachment['url']; |
9 | 3253 |
$rel = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $id ) == $url ); |
0 | 3254 |
|
3255 |
remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' ); |
|
3256 |
||
3257 |
if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) { |
|
3258 |
$align = isset( $attachment['align'] ) ? $attachment['align'] : 'none'; |
|
9 | 3259 |
$size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium'; |
3260 |
$alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : ''; |
|
5 | 3261 |
|
3262 |
// No whitespace-only captions. |
|
0 | 3263 |
$caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : ''; |
5 | 3264 |
if ( '' === trim( $caption ) ) { |
3265 |
$caption = ''; |
|
3266 |
} |
|
3267 |
||
0 | 3268 |
$title = ''; // We no longer insert title tags into <img> tags, as they are redundant. |
9 | 3269 |
$html = get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ); |
3270 |
} elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) { |
|
0 | 3271 |
$html = stripslashes_deep( $_POST['html'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3272 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3273 |
$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; |
16 | 3274 |
$rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3275 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3276 |
if ( ! empty( $url ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3277 |
$html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3278 |
} |
0 | 3279 |
} |
3280 |
||
3281 |
/** This filter is documented in wp-admin/includes/media.php */ |
|
3282 |
$html = apply_filters( 'media_send_to_editor', $html, $id, $attachment ); |
|
3283 |
||
3284 |
wp_send_json_success( $html ); |
|
3285 |
} |
|
3286 |
||
3287 |
/** |
|
5 | 3288 |
* Ajax handler for sending a link to the editor. |
3289 |
* |
|
0 | 3290 |
* Generates the HTML to send a non-image embed link to the editor. |
3291 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3292 |
* Backward compatible with the following filters: |
0 | 3293 |
* - file_send_to_editor_url |
3294 |
* - audio_send_to_editor_url |
|
3295 |
* - video_send_to_editor_url |
|
3296 |
* |
|
3297 |
* @since 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3298 |
* |
16 | 3299 |
* @global WP_Post $post Global post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3300 |
* @global WP_Embed $wp_embed |
0 | 3301 |
*/ |
3302 |
function wp_ajax_send_link_to_editor() { |
|
5 | 3303 |
global $post, $wp_embed; |
3304 |
||
0 | 3305 |
check_ajax_referer( 'media-send-to-editor', 'nonce' ); |
3306 |
||
16 | 3307 |
$src = wp_unslash( $_POST['src'] ); |
3308 |
if ( ! $src ) { |
|
0 | 3309 |
wp_send_json_error(); |
9 | 3310 |
} |
3311 |
||
3312 |
if ( ! strpos( $src, '://' ) ) { |
|
0 | 3313 |
$src = 'http://' . $src; |
9 | 3314 |
} |
3315 |
||
16 | 3316 |
$src = esc_url_raw( $src ); |
3317 |
if ( ! $src ) { |
|
0 | 3318 |
wp_send_json_error(); |
9 | 3319 |
} |
3320 |
||
16 | 3321 |
$link_text = trim( wp_unslash( $_POST['link_text'] ) ); |
3322 |
if ( ! $link_text ) { |
|
5 | 3323 |
$link_text = wp_basename( $src ); |
9 | 3324 |
} |
5 | 3325 |
|
3326 |
$post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 ); |
|
3327 |
||
3328 |
// Ping WordPress for an embed. |
|
9 | 3329 |
$check_embed = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' ); |
5 | 3330 |
|
3331 |
// Fallback that WordPress creates when no oEmbed was found. |
|
3332 |
$fallback = $wp_embed->maybe_make_link( $src ); |
|
3333 |
||
3334 |
if ( $check_embed !== $fallback ) { |
|
16 | 3335 |
// TinyMCE view for [embed] will parse this. |
5 | 3336 |
$html = '[embed]' . $src . '[/embed]'; |
3337 |
} elseif ( $link_text ) { |
|
3338 |
$html = '<a href="' . esc_url( $src ) . '">' . $link_text . '</a>'; |
|
3339 |
} else { |
|
3340 |
$html = ''; |
|
3341 |
} |
|
0 | 3342 |
|
3343 |
// Figure out what filter to run: |
|
3344 |
$type = 'file'; |
|
16 | 3345 |
$ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ); |
3346 |
if ( $ext ) { |
|
3347 |
$ext_type = wp_ext2type( $ext ); |
|
3348 |
if ( 'audio' === $ext_type || 'video' === $ext_type ) { |
|
0 | 3349 |
$type = $ext_type; |
16 | 3350 |
} |
9 | 3351 |
} |
0 | 3352 |
|
3353 |
/** This filter is documented in wp-admin/includes/media.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3354 |
$html = apply_filters( "{$type}_send_to_editor_url", $html, $src, $link_text ); |
0 | 3355 |
|
3356 |
wp_send_json_success( $html ); |
|
3357 |
} |
|
3358 |
||
3359 |
/** |
|
5 | 3360 |
* Ajax handler for the Heartbeat API. |
0 | 3361 |
* |
3362 |
* Runs when the user is logged in. |
|
5 | 3363 |
* |
3364 |
* @since 3.6.0 |
|
0 | 3365 |
*/ |
3366 |
function wp_ajax_heartbeat() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3367 |
if ( empty( $_POST['_nonce'] ) ) { |
0 | 3368 |
wp_send_json_error(); |
3369 |
} |
|
3370 |
||
16 | 3371 |
$response = array(); |
3372 |
$data = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3373 |
$nonce_state = wp_verify_nonce( $_POST['_nonce'], 'heartbeat-nonce' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3374 |
|
16 | 3375 |
// 'screen_id' is the same as $current_screen->id and the JS global 'pagenow'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
if ( ! empty( $_POST['screen_id'] ) ) { |
9 | 3377 |
$screen_id = sanitize_key( $_POST['screen_id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
} else { |
0 | 3379 |
$screen_id = 'front'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3381 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3382 |
if ( ! empty( $_POST['data'] ) ) { |
5 | 3383 |
$data = wp_unslash( (array) $_POST['data'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3384 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3385 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3386 |
if ( 1 !== $nonce_state ) { |
9 | 3387 |
/** |
3388 |
* Filters the nonces to send to the New/Edit Post screen. |
|
3389 |
* |
|
3390 |
* @since 4.3.0 |
|
3391 |
* |
|
3392 |
* @param array $response The Heartbeat response. |
|
3393 |
* @param array $data The $_POST data sent. |
|
16 | 3394 |
* @param string $screen_id The screen ID. |
9 | 3395 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3396 |
$response = apply_filters( 'wp_refresh_nonces', $response, $data, $screen_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3397 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3398 |
if ( false === $nonce_state ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3399 |
// User is logged in but nonces have expired. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3400 |
$response['nonces_expired'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3401 |
wp_send_json( $response ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3402 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3403 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3404 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3405 |
if ( ! empty( $data ) ) { |
0 | 3406 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3407 |
* Filters the Heartbeat response received. |
0 | 3408 |
* |
3409 |
* @since 3.6.0 |
|
3410 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3411 |
* @param array $response The Heartbeat response. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3412 |
* @param array $data The $_POST data sent. |
16 | 3413 |
* @param string $screen_id The screen ID. |
0 | 3414 |
*/ |
3415 |
$response = apply_filters( 'heartbeat_received', $response, $data, $screen_id ); |
|
3416 |
} |
|
3417 |
||
3418 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3419 |
* Filters the Heartbeat response sent. |
0 | 3420 |
* |
3421 |
* @since 3.6.0 |
|
3422 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3423 |
* @param array $response The Heartbeat response. |
16 | 3424 |
* @param string $screen_id The screen ID. |
0 | 3425 |
*/ |
3426 |
$response = apply_filters( 'heartbeat_send', $response, $screen_id ); |
|
3427 |
||
3428 |
/** |
|
3429 |
* Fires when Heartbeat ticks in logged-in environments. |
|
3430 |
* |
|
3431 |
* Allows the transport to be easily replaced with long-polling. |
|
3432 |
* |
|
3433 |
* @since 3.6.0 |
|
3434 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3435 |
* @param array $response The Heartbeat response. |
16 | 3436 |
* @param string $screen_id The screen ID. |
0 | 3437 |
*/ |
3438 |
do_action( 'heartbeat_tick', $response, $screen_id ); |
|
3439 |
||
16 | 3440 |
// Send the current time according to the server. |
0 | 3441 |
$response['server_time'] = time(); |
3442 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3443 |
wp_send_json( $response ); |
0 | 3444 |
} |
3445 |
||
5 | 3446 |
/** |
3447 |
* Ajax handler for getting revision diffs. |
|
3448 |
* |
|
3449 |
* @since 3.6.0 |
|
3450 |
*/ |
|
0 | 3451 |
function wp_ajax_get_revision_diffs() { |
3452 |
require ABSPATH . 'wp-admin/includes/revision.php'; |
|
3453 |
||
16 | 3454 |
$post = get_post( (int) $_REQUEST['post_id'] ); |
3455 |
if ( ! $post ) { |
|
0 | 3456 |
wp_send_json_error(); |
9 | 3457 |
} |
3458 |
||
3459 |
if ( ! current_user_can( 'edit_post', $post->ID ) ) { |
|
0 | 3460 |
wp_send_json_error(); |
9 | 3461 |
} |
0 | 3462 |
|
3463 |
// Really just pre-loading the cache here. |
|
16 | 3464 |
$revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) ); |
3465 |
if ( ! $revisions ) { |
|
0 | 3466 |
wp_send_json_error(); |
9 | 3467 |
} |
0 | 3468 |
|
3469 |
$return = array(); |
|
16 | 3470 |
set_time_limit( 0 ); |
0 | 3471 |
|
3472 |
foreach ( $_REQUEST['compare'] as $compare_key ) { |
|
3473 |
list( $compare_from, $compare_to ) = explode( ':', $compare_key ); // from:to |
|
3474 |
||
3475 |
$return[] = array( |
|
9 | 3476 |
'id' => $compare_key, |
0 | 3477 |
'fields' => wp_get_revision_ui_diff( $post, $compare_from, $compare_to ), |
3478 |
); |
|
3479 |
} |
|
3480 |
wp_send_json_success( $return ); |
|
3481 |
} |
|
5 | 3482 |
|
3483 |
/** |
|
3484 |
* Ajax handler for auto-saving the selected color scheme for |
|
3485 |
* a user's own profile. |
|
3486 |
* |
|
3487 |
* @since 3.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3488 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3489 |
* @global array $_wp_admin_css_colors |
5 | 3490 |
*/ |
3491 |
function wp_ajax_save_user_color_scheme() { |
|
3492 |
global $_wp_admin_css_colors; |
|
3493 |
||
3494 |
check_ajax_referer( 'save-color-scheme', 'nonce' ); |
|
3495 |
||
3496 |
$color_scheme = sanitize_key( $_POST['color_scheme'] ); |
|
3497 |
||
3498 |
if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) { |
|
3499 |
wp_send_json_error(); |
|
3500 |
} |
|
3501 |
||
3502 |
$previous_color_scheme = get_user_meta( get_current_user_id(), 'admin_color', true ); |
|
3503 |
update_user_meta( get_current_user_id(), 'admin_color', $color_scheme ); |
|
3504 |
||
9 | 3505 |
wp_send_json_success( |
3506 |
array( |
|
3507 |
'previousScheme' => 'admin-color-' . $previous_color_scheme, |
|
3508 |
'currentScheme' => 'admin-color-' . $color_scheme, |
|
3509 |
) |
|
3510 |
); |
|
5 | 3511 |
} |
3512 |
||
3513 |
/** |
|
3514 |
* Ajax handler for getting themes from themes_api(). |
|
3515 |
* |
|
3516 |
* @since 3.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3517 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3518 |
* @global array $themes_allowedtags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
* @global array $theme_field_defaults |
5 | 3520 |
*/ |
3521 |
function wp_ajax_query_themes() { |
|
3522 |
global $themes_allowedtags, $theme_field_defaults; |
|
3523 |
||
3524 |
if ( ! current_user_can( 'install_themes' ) ) { |
|
3525 |
wp_send_json_error(); |
|
3526 |
} |
|
3527 |
||
9 | 3528 |
$args = wp_parse_args( |
3529 |
wp_unslash( $_REQUEST['request'] ), |
|
3530 |
array( |
|
3531 |
'per_page' => 20, |
|
3532 |
'fields' => array_merge( |
|
3533 |
(array) $theme_field_defaults, |
|
3534 |
array( |
|
3535 |
'reviews_url' => true, // Explicitly request the reviews URL to be linked from the Add Themes screen. |
|
3536 |
) |
|
3537 |
), |
|
3538 |
) |
|
3539 |
); |
|
5 | 3540 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3541 |
if ( isset( $args['browse'] ) && 'favorites' === $args['browse'] && ! isset( $args['user'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3542 |
$user = get_user_option( 'wporg_favorites' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3543 |
if ( $user ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3544 |
$args['user'] = $user; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3545 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3546 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3547 |
|
5 | 3548 |
$old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search'; |
3549 |
||
3550 |
/** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */ |
|
3551 |
$args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args ); |
|
3552 |
||
3553 |
$api = themes_api( 'query_themes', $args ); |
|
3554 |
||
3555 |
if ( is_wp_error( $api ) ) { |
|
3556 |
wp_send_json_error(); |
|
3557 |
} |
|
3558 |
||
3559 |
$update_php = network_admin_url( 'update.php?action=install-theme' ); |
|
16 | 3560 |
|
5 | 3561 |
foreach ( $api->themes as &$theme ) { |
9 | 3562 |
$theme->install_url = add_query_arg( |
3563 |
array( |
|
3564 |
'theme' => $theme->slug, |
|
3565 |
'_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ), |
|
3566 |
), |
|
3567 |
$update_php |
|
3568 |
); |
|
5 | 3569 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3570 |
if ( current_user_can( 'switch_themes' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3571 |
if ( is_multisite() ) { |
9 | 3572 |
$theme->activate_url = add_query_arg( |
3573 |
array( |
|
3574 |
'action' => 'enable', |
|
3575 |
'_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ), |
|
3576 |
'theme' => $theme->slug, |
|
3577 |
), |
|
3578 |
network_admin_url( 'themes.php' ) |
|
3579 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
} else { |
9 | 3581 |
$theme->activate_url = add_query_arg( |
3582 |
array( |
|
3583 |
'action' => 'activate', |
|
3584 |
'_wpnonce' => wp_create_nonce( 'switch-theme_' . $theme->slug ), |
|
3585 |
'stylesheet' => $theme->slug, |
|
3586 |
), |
|
3587 |
admin_url( 'themes.php' ) |
|
3588 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3589 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3590 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3591 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3592 |
if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
9 | 3593 |
$theme->customize_url = add_query_arg( |
3594 |
array( |
|
3595 |
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ), |
|
3596 |
), |
|
3597 |
wp_customize_url( $theme->slug ) |
|
3598 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3599 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3600 |
|
5 | 3601 |
$theme->name = wp_kses( $theme->name, $themes_allowedtags ); |
9 | 3602 |
$theme->author = wp_kses( $theme->author['display_name'], $themes_allowedtags ); |
5 | 3603 |
$theme->version = wp_kses( $theme->version, $themes_allowedtags ); |
3604 |
$theme->description = wp_kses( $theme->description, $themes_allowedtags ); |
|
16 | 3605 |
|
3606 |
$theme->stars = wp_star_rating( |
|
9 | 3607 |
array( |
3608 |
'rating' => $theme->rating, |
|
3609 |
'type' => 'percent', |
|
3610 |
'number' => $theme->num_ratings, |
|
3611 |
'echo' => false, |
|
3612 |
) |
|
3613 |
); |
|
16 | 3614 |
|
3615 |
$theme->num_ratings = number_format_i18n( $theme->num_ratings ); |
|
3616 |
$theme->preview_url = set_url_scheme( $theme->preview_url ); |
|
3617 |
$theme->compatible_wp = is_wp_version_compatible( $theme->requires ); |
|
3618 |
$theme->compatible_php = is_php_version_compatible( $theme->requires_php ); |
|
5 | 3619 |
} |
3620 |
||
3621 |
wp_send_json_success( $api ); |
|
3622 |
} |
|
3623 |
||
3624 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3625 |
* Apply [embed] Ajax handlers to a string. |
5 | 3626 |
* |
3627 |
* @since 4.0.0 |
|
3628 |
* |
|
16 | 3629 |
* @global WP_Post $post Global post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3630 |
* @global WP_Embed $wp_embed Embed API instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3631 |
* @global WP_Scripts $wp_scripts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3632 |
* @global int $content_width |
5 | 3633 |
*/ |
3634 |
function wp_ajax_parse_embed() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3635 |
global $post, $wp_embed, $content_width; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3636 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3637 |
if ( empty( $_POST['shortcode'] ) ) { |
5 | 3638 |
wp_send_json_error(); |
3639 |
} |
|
16 | 3640 |
|
18 | 3641 |
$post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0; |
16 | 3642 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3643 |
if ( $post_id > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3644 |
$post = get_post( $post_id ); |
16 | 3645 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3646 |
if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3647 |
wp_send_json_error(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3648 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3649 |
setup_postdata( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3650 |
} elseif ( ! current_user_can( 'edit_posts' ) ) { // See WP_oEmbed_Controller::get_proxy_item_permissions_check(). |
5 | 3651 |
wp_send_json_error(); |
3652 |
} |
|
3653 |
||
3654 |
$shortcode = wp_unslash( $_POST['shortcode'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3655 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3656 |
preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3657 |
$atts = shortcode_parse_atts( $matches[3] ); |
16 | 3658 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
if ( ! empty( $matches[5] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3660 |
$url = $matches[5]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3661 |
} elseif ( ! empty( $atts['src'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
$url = $atts['src']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3663 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3664 |
$url = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3665 |
} |
5 | 3666 |
|
9 | 3667 |
$parsed = false; |
5 | 3668 |
$wp_embed->return_false_on_fail = true; |
3669 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3670 |
if ( 0 === $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3671 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
* Refresh oEmbeds cached outside of posts that are past their TTL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
* Posts are excluded because they have separate logic for refreshing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3674 |
* their post meta caches. See WP_Embed::cache_oembed(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3675 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3676 |
$wp_embed->usecache = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3677 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3678 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3679 |
if ( is_ssl() && 0 === strpos( $url, 'http://' ) ) { |
5 | 3680 |
// Admin is ssl and the user pasted non-ssl URL. |
3681 |
// Check if the provider supports ssl embeds and use that for the preview. |
|
3682 |
$ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode ); |
|
9 | 3683 |
$parsed = $wp_embed->run_shortcode( $ssl_shortcode ); |
5 | 3684 |
|
3685 |
if ( ! $parsed ) { |
|
3686 |
$no_ssl_support = true; |
|
3687 |
} |
|
3688 |
} |
|
3689 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3690 |
// Set $content_width so any embeds fit in the destination iframe. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3691 |
if ( isset( $_POST['maxwidth'] ) && is_numeric( $_POST['maxwidth'] ) && $_POST['maxwidth'] > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3692 |
if ( ! isset( $content_width ) ) { |
18 | 3693 |
$content_width = (int) $_POST['maxwidth']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3694 |
} else { |
18 | 3695 |
$content_width = min( $content_width, (int) $_POST['maxwidth'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3696 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3697 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3698 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3699 |
if ( $url && ! $parsed ) { |
5 | 3700 |
$parsed = $wp_embed->run_shortcode( $shortcode ); |
3701 |
} |
|
3702 |
||
3703 |
if ( ! $parsed ) { |
|
9 | 3704 |
wp_send_json_error( |
3705 |
array( |
|
3706 |
'type' => 'not-embeddable', |
|
16 | 3707 |
/* translators: %s: URL that could not be embedded. */ |
9 | 3708 |
'message' => sprintf( __( '%s failed to embed.' ), '<code>' . esc_html( $url ) . '</code>' ), |
3709 |
) |
|
3710 |
); |
|
5 | 3711 |
} |
3712 |
||
3713 |
if ( has_shortcode( $parsed, 'audio' ) || has_shortcode( $parsed, 'video' ) ) { |
|
9 | 3714 |
$styles = ''; |
5 | 3715 |
$mce_styles = wpview_media_sandbox_styles(); |
16 | 3716 |
|
5 | 3717 |
foreach ( $mce_styles as $style ) { |
18 | 3718 |
$styles .= sprintf( '<link rel="stylesheet" href="%s" />', $style ); |
5 | 3719 |
} |
3720 |
||
3721 |
$html = do_shortcode( $parsed ); |
|
3722 |
||
3723 |
global $wp_scripts; |
|
16 | 3724 |
|
5 | 3725 |
if ( ! empty( $wp_scripts ) ) { |
3726 |
$wp_scripts->done = array(); |
|
3727 |
} |
|
16 | 3728 |
|
5 | 3729 |
ob_start(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3730 |
wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) ); |
5 | 3731 |
$scripts = ob_get_clean(); |
3732 |
||
3733 |
$parsed = $styles . $html . $scripts; |
|
3734 |
} |
|
3735 |
||
3736 |
if ( ! empty( $no_ssl_support ) || ( is_ssl() && ( preg_match( '%<(iframe|script|embed) [^>]*src="http://%', $parsed ) || |
|
3737 |
preg_match( '%<link [^>]*href="http://%', $parsed ) ) ) ) { |
|
3738 |
// Admin is ssl and the embed is not. Iframes, scripts, and other "active content" will be blocked. |
|
9 | 3739 |
wp_send_json_error( |
3740 |
array( |
|
3741 |
'type' => 'not-ssl', |
|
3742 |
'message' => __( 'This preview is unavailable in the editor.' ), |
|
3743 |
) |
|
3744 |
); |
|
5 | 3745 |
} |
3746 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
$return = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
'body' => $parsed, |
9 | 3749 |
'attr' => $wp_embed->last_attr, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3750 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3751 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3752 |
if ( strpos( $parsed, 'class="wp-embedded-content' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3753 |
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3754 |
$script_src = includes_url( 'js/wp-embed.js' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3755 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3756 |
$script_src = includes_url( 'js/wp-embed.min.js' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3757 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3758 |
|
9 | 3759 |
$return['head'] = '<script src="' . $script_src . '"></script>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3760 |
$return['sandbox'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3761 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3762 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3763 |
wp_send_json_success( $return ); |
5 | 3764 |
} |
3765 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3766 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3767 |
* @since 4.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3768 |
* |
16 | 3769 |
* @global WP_Post $post Global post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3770 |
* @global WP_Scripts $wp_scripts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3771 |
*/ |
5 | 3772 |
function wp_ajax_parse_media_shortcode() { |
3773 |
global $post, $wp_scripts; |
|
3774 |
||
3775 |
if ( empty( $_POST['shortcode'] ) ) { |
|
3776 |
wp_send_json_error(); |
|
3777 |
} |
|
3778 |
||
3779 |
$shortcode = wp_unslash( $_POST['shortcode'] ); |
|
3780 |
||
3781 |
if ( ! empty( $_POST['post_ID'] ) ) { |
|
3782 |
$post = get_post( (int) $_POST['post_ID'] ); |
|
3783 |
} |
|
3784 |
||
16 | 3785 |
// The embed shortcode requires a post. |
5 | 3786 |
if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { |
3787 |
if ( 'embed' === $shortcode ) { |
|
3788 |
wp_send_json_error(); |
|
3789 |
} |
|
3790 |
} else { |
|
3791 |
setup_postdata( $post ); |
|
3792 |
} |
|
3793 |
||
9 | 3794 |
$parsed = do_shortcode( $shortcode ); |
5 | 3795 |
|
3796 |
if ( empty( $parsed ) ) { |
|
9 | 3797 |
wp_send_json_error( |
3798 |
array( |
|
3799 |
'type' => 'no-items', |
|
3800 |
'message' => __( 'No items found.' ), |
|
3801 |
) |
|
3802 |
); |
|
3803 |
} |
|
3804 |
||
3805 |
$head = ''; |
|
5 | 3806 |
$styles = wpview_media_sandbox_styles(); |
3807 |
||
3808 |
foreach ( $styles as $style ) { |
|
3809 |
$head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">'; |
|
3810 |
} |
|
3811 |
||
3812 |
if ( ! empty( $wp_scripts ) ) { |
|
3813 |
$wp_scripts->done = array(); |
|
3814 |
} |
|
3815 |
||
3816 |
ob_start(); |
|
3817 |
||
3818 |
echo $parsed; |
|
3819 |
||
3820 |
if ( 'playlist' === $_REQUEST['type'] ) { |
|
3821 |
wp_underscore_playlist_templates(); |
|
3822 |
||
3823 |
wp_print_scripts( 'wp-playlist' ); |
|
3824 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) ); |
5 | 3826 |
} |
3827 |
||
9 | 3828 |
wp_send_json_success( |
3829 |
array( |
|
3830 |
'head' => $head, |
|
3831 |
'body' => ob_get_clean(), |
|
3832 |
) |
|
3833 |
); |
|
5 | 3834 |
} |
3835 |
||
3836 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3837 |
* Ajax handler for destroying multiple open sessions for a user. |
5 | 3838 |
* |
3839 |
* @since 4.1.0 |
|
3840 |
*/ |
|
3841 |
function wp_ajax_destroy_sessions() { |
|
3842 |
$user = get_userdata( (int) $_POST['user_id'] ); |
|
16 | 3843 |
|
5 | 3844 |
if ( $user ) { |
3845 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
|
3846 |
$user = false; |
|
3847 |
} elseif ( ! wp_verify_nonce( $_POST['nonce'], 'update-user_' . $user->ID ) ) { |
|
3848 |
$user = false; |
|
3849 |
} |
|
3850 |
} |
|
3851 |
||
3852 |
if ( ! $user ) { |
|
9 | 3853 |
wp_send_json_error( |
3854 |
array( |
|
3855 |
'message' => __( 'Could not log out user sessions. Please try again.' ), |
|
3856 |
) |
|
3857 |
); |
|
5 | 3858 |
} |
3859 |
||
3860 |
$sessions = WP_Session_Tokens::get_instance( $user->ID ); |
|
3861 |
||
16 | 3862 |
if ( get_current_user_id() === $user->ID ) { |
5 | 3863 |
$sessions->destroy_others( wp_get_session_token() ); |
3864 |
$message = __( 'You are now logged out everywhere else.' ); |
|
3865 |
} else { |
|
3866 |
$sessions->destroy_all(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3867 |
/* translators: %s: User's display name. */ |
5 | 3868 |
$message = sprintf( __( '%s has been logged out.' ), $user->display_name ); |
3869 |
} |
|
3870 |
||
3871 |
wp_send_json_success( array( 'message' => $message ) ); |
|
3872 |
} |
|
3873 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3874 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3875 |
* Ajax handler for cropping an image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3876 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3877 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3878 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3879 |
function wp_ajax_crop_image() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3880 |
$attachment_id = absint( $_POST['id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3881 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3882 |
check_ajax_referer( 'image_editor-' . $attachment_id, 'nonce' ); |
16 | 3883 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3884 |
if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3885 |
wp_send_json_error(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3886 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3887 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3888 |
$context = str_replace( '_', '-', $_POST['context'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3889 |
$data = array_map( 'absint', $_POST['cropDetails'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3890 |
$cropped = wp_crop_image( $attachment_id, $data['x1'], $data['y1'], $data['width'], $data['height'], $data['dst_width'], $data['dst_height'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3891 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3892 |
if ( ! $cropped || is_wp_error( $cropped ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3893 |
wp_send_json_error( array( 'message' => __( 'Image could not be processed.' ) ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3894 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3895 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3896 |
switch ( $context ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3897 |
case 'site-icon': |
9 | 3898 |
require_once ABSPATH . 'wp-admin/includes/class-wp-site-icon.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3899 |
$wp_site_icon = new WP_Site_Icon(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3900 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3901 |
// Skip creating a new attachment if the attachment is a Site Icon. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3902 |
if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) == $context ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3903 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3904 |
// Delete the temporary cropped file, we don't need it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3905 |
wp_delete_file( $cropped ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3906 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3907 |
// Additional sizes in wp_prepare_attachment_for_js(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3908 |
add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3909 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3910 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3911 |
|
16 | 3912 |
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3913 |
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
$object = $wp_site_icon->create_attachment_object( $cropped, $attachment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3915 |
unset( $object['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3917 |
// Update the attachment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3918 |
add_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3919 |
$attachment_id = $wp_site_icon->insert_attachment( $object, $cropped ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3920 |
remove_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3921 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3922 |
// Additional sizes in wp_prepare_attachment_for_js(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3923 |
add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3924 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3925 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3926 |
default: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3927 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3928 |
* Fires before a cropped image is saved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3929 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3930 |
* Allows to add filters to modify the way a cropped image is saved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3931 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3932 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3933 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3934 |
* @param string $context The Customizer control requesting the cropped image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3935 |
* @param int $attachment_id The attachment ID of the original image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3936 |
* @param string $cropped Path to the cropped image file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3937 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3938 |
do_action( 'wp_ajax_crop_image_pre_save', $context, $attachment_id, $cropped ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3939 |
|
16 | 3940 |
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3941 |
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3942 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3943 |
$parent_url = wp_get_attachment_url( $attachment_id ); |
9 | 3944 |
$url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3945 |
|
18 | 3946 |
$size = wp_getimagesize( $cropped ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3947 |
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3948 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3949 |
$object = array( |
9 | 3950 |
'post_title' => wp_basename( $cropped ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3951 |
'post_content' => $url, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3952 |
'post_mime_type' => $image_type, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3953 |
'guid' => $url, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3954 |
'context' => $context, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3955 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3956 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3957 |
$attachment_id = wp_insert_attachment( $object, $cropped ); |
9 | 3958 |
$metadata = wp_generate_attachment_metadata( $attachment_id, $cropped ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3959 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3960 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3961 |
* Filters the cropped image attachment metadata. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3962 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3963 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3964 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3965 |
* @see wp_generate_attachment_metadata() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3966 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3967 |
* @param array $metadata Attachment metadata. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3968 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3969 |
$metadata = apply_filters( 'wp_ajax_cropped_attachment_metadata', $metadata ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3970 |
wp_update_attachment_metadata( $attachment_id, $metadata ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3971 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3972 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3973 |
* Filters the attachment ID for a cropped image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3974 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3975 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3976 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3977 |
* @param int $attachment_id The attachment ID of the cropped image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3978 |
* @param string $context The Customizer control requesting the cropped image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3979 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3980 |
$attachment_id = apply_filters( 'wp_ajax_cropped_attachment_id', $attachment_id, $context ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3981 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3982 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3983 |
wp_send_json_success( wp_prepare_attachment_for_js( $attachment_id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3984 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3985 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3986 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3987 |
* Ajax handler for generating a password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3988 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3989 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3990 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
function wp_ajax_generate_password() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3992 |
wp_send_json_success( wp_generate_password( 24 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3994 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3995 |
/** |
18 | 3996 |
* Ajax handler for generating a password in the no-privilege context. |
3997 |
* |
|
3998 |
* @since 5.7.0 |
|
3999 |
*/ |
|
4000 |
function wp_ajax_nopriv_generate_password() { |
|
4001 |
wp_send_json_success( wp_generate_password( 24 ) ); |
|
4002 |
} |
|
4003 |
||
4004 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4005 |
* Ajax handler for saving the user's WordPress.org username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4006 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4007 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4008 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4009 |
function wp_ajax_save_wporg_username() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4010 |
if ( ! current_user_can( 'install_themes' ) && ! current_user_can( 'install_plugins' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4011 |
wp_send_json_error(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4012 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4013 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4014 |
check_ajax_referer( 'save_wporg_username_' . get_current_user_id() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4015 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4016 |
$username = isset( $_REQUEST['username'] ) ? wp_unslash( $_REQUEST['username'] ) : false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4017 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4018 |
if ( ! $username ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4019 |
wp_send_json_error(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4020 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4021 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4022 |
wp_send_json_success( update_user_meta( get_current_user_id(), 'wporg_favorites', $username ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4023 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4024 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4025 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4026 |
* Ajax handler for installing a theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4027 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4028 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4029 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4030 |
* @see Theme_Upgrader |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4031 |
* |
9 | 4032 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4033 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4034 |
function wp_ajax_install_theme() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4035 |
check_ajax_referer( 'updates' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4036 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4037 |
if ( empty( $_POST['slug'] ) ) { |
9 | 4038 |
wp_send_json_error( |
4039 |
array( |
|
4040 |
'slug' => '', |
|
4041 |
'errorCode' => 'no_theme_specified', |
|
4042 |
'errorMessage' => __( 'No theme specified.' ), |
|
4043 |
) |
|
4044 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4045 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4046 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4047 |
$slug = sanitize_key( wp_unslash( $_POST['slug'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4048 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4049 |
$status = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4050 |
'install' => 'theme', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4051 |
'slug' => $slug, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4052 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4053 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4054 |
if ( ! current_user_can( 'install_themes' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4055 |
$status['errorMessage'] = __( 'Sorry, you are not allowed to install themes on this site.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4056 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4057 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4058 |
|
16 | 4059 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
4060 |
include_once ABSPATH . 'wp-admin/includes/theme.php'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4061 |
|
9 | 4062 |
$api = themes_api( |
4063 |
'theme_information', |
|
4064 |
array( |
|
4065 |
'slug' => $slug, |
|
4066 |
'fields' => array( 'sections' => false ), |
|
4067 |
) |
|
4068 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4069 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4070 |
if ( is_wp_error( $api ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4071 |
$status['errorMessage'] = $api->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4072 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4073 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4074 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4075 |
$skin = new WP_Ajax_Upgrader_Skin(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4076 |
$upgrader = new Theme_Upgrader( $skin ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4077 |
$result = $upgrader->install( $api->download_link ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4078 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4079 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4080 |
$status['debug'] = $skin->get_upgrade_messages(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4081 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4082 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4083 |
if ( is_wp_error( $result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4084 |
$status['errorCode'] = $result->get_error_code(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4085 |
$status['errorMessage'] = $result->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4086 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4087 |
} elseif ( is_wp_error( $skin->result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4088 |
$status['errorCode'] = $skin->result->get_error_code(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4089 |
$status['errorMessage'] = $skin->result->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4090 |
wp_send_json_error( $status ); |
9 | 4091 |
} elseif ( $skin->get_errors()->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4092 |
$status['errorMessage'] = $skin->get_error_messages(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4093 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4094 |
} elseif ( is_null( $result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4095 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4096 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4097 |
$status['errorCode'] = 'unable_to_connect_to_filesystem'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4098 |
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4099 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4100 |
// Pass through the error from WP_Filesystem if one was raised. |
9 | 4101 |
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4102 |
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4103 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4104 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4105 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4106 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4107 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4108 |
$status['themeName'] = wp_get_theme( $slug )->get( 'Name' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4109 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4110 |
if ( current_user_can( 'switch_themes' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4111 |
if ( is_multisite() ) { |
9 | 4112 |
$status['activateUrl'] = add_query_arg( |
4113 |
array( |
|
4114 |
'action' => 'enable', |
|
4115 |
'_wpnonce' => wp_create_nonce( 'enable-theme_' . $slug ), |
|
4116 |
'theme' => $slug, |
|
4117 |
), |
|
4118 |
network_admin_url( 'themes.php' ) |
|
4119 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4120 |
} else { |
9 | 4121 |
$status['activateUrl'] = add_query_arg( |
4122 |
array( |
|
4123 |
'action' => 'activate', |
|
4124 |
'_wpnonce' => wp_create_nonce( 'switch-theme_' . $slug ), |
|
4125 |
'stylesheet' => $slug, |
|
4126 |
), |
|
4127 |
admin_url( 'themes.php' ) |
|
4128 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4129 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4130 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4131 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4132 |
if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
9 | 4133 |
$status['customizeUrl'] = add_query_arg( |
4134 |
array( |
|
4135 |
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ), |
|
4136 |
), |
|
4137 |
wp_customize_url( $slug ) |
|
4138 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4139 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4140 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4141 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4142 |
* See WP_Theme_Install_List_Table::_get_theme_status() if we wanted to check |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4143 |
* on post-installation status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4144 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4145 |
wp_send_json_success( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4146 |
} |
5 | 4147 |
|
4148 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4149 |
* Ajax handler for updating a theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4150 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4151 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4152 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4153 |
* @see Theme_Upgrader |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4154 |
* |
9 | 4155 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4156 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4157 |
function wp_ajax_update_theme() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4158 |
check_ajax_referer( 'updates' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4159 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4160 |
if ( empty( $_POST['slug'] ) ) { |
9 | 4161 |
wp_send_json_error( |
4162 |
array( |
|
4163 |
'slug' => '', |
|
4164 |
'errorCode' => 'no_theme_specified', |
|
4165 |
'errorMessage' => __( 'No theme specified.' ), |
|
4166 |
) |
|
4167 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4168 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4169 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4170 |
$stylesheet = preg_replace( '/[^A-z0-9_\-]/', '', wp_unslash( $_POST['slug'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4171 |
$status = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4172 |
'update' => 'theme', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4173 |
'slug' => $stylesheet, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4174 |
'oldVersion' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4175 |
'newVersion' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4176 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4177 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4178 |
if ( ! current_user_can( 'update_themes' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4179 |
$status['errorMessage'] = __( 'Sorry, you are not allowed to update themes for this site.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4180 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4181 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4182 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4183 |
$theme = wp_get_theme( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4184 |
if ( $theme->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4185 |
$status['oldVersion'] = $theme->get( 'Version' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4186 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4187 |
|
16 | 4188 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4190 |
$current = get_site_transient( 'update_themes' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4191 |
if ( empty( $current ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4192 |
wp_update_themes(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4193 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4194 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4195 |
$skin = new WP_Ajax_Upgrader_Skin(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4196 |
$upgrader = new Theme_Upgrader( $skin ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4197 |
$result = $upgrader->bulk_upgrade( array( $stylesheet ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4198 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4199 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4200 |
$status['debug'] = $skin->get_upgrade_messages(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4201 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4202 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4203 |
if ( is_wp_error( $skin->result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4204 |
$status['errorCode'] = $skin->result->get_error_code(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4205 |
$status['errorMessage'] = $skin->result->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4206 |
wp_send_json_error( $status ); |
9 | 4207 |
} elseif ( $skin->get_errors()->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4208 |
$status['errorMessage'] = $skin->get_error_messages(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4209 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4210 |
} elseif ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4211 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4212 |
// Theme is already at the latest version. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4213 |
if ( true === $result[ $stylesheet ] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4214 |
$status['errorMessage'] = $upgrader->strings['up_to_date']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4215 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4216 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4217 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4218 |
$theme = wp_get_theme( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4219 |
if ( $theme->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4220 |
$status['newVersion'] = $theme->get( 'Version' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4221 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4222 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4223 |
wp_send_json_success( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4224 |
} elseif ( false === $result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4225 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4226 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4227 |
$status['errorCode'] = 'unable_to_connect_to_filesystem'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4228 |
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4229 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4230 |
// Pass through the error from WP_Filesystem if one was raised. |
9 | 4231 |
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4232 |
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4233 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4234 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4235 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4236 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4237 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4238 |
// An unhandled error occurred. |
16 | 4239 |
$status['errorMessage'] = __( 'Theme update failed.' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4240 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4241 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4242 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4243 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4244 |
* Ajax handler for deleting a theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4245 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4246 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4247 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4248 |
* @see delete_theme() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4249 |
* |
9 | 4250 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4251 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4252 |
function wp_ajax_delete_theme() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4253 |
check_ajax_referer( 'updates' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4254 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4255 |
if ( empty( $_POST['slug'] ) ) { |
9 | 4256 |
wp_send_json_error( |
4257 |
array( |
|
4258 |
'slug' => '', |
|
4259 |
'errorCode' => 'no_theme_specified', |
|
4260 |
'errorMessage' => __( 'No theme specified.' ), |
|
4261 |
) |
|
4262 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4263 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4264 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4265 |
$stylesheet = preg_replace( '/[^A-z0-9_\-]/', '', wp_unslash( $_POST['slug'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4266 |
$status = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4267 |
'delete' => 'theme', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4268 |
'slug' => $stylesheet, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4269 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4270 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4271 |
if ( ! current_user_can( 'delete_themes' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4272 |
$status['errorMessage'] = __( 'Sorry, you are not allowed to delete themes on this site.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4273 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4274 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4275 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4276 |
if ( ! wp_get_theme( $stylesheet )->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4277 |
$status['errorMessage'] = __( 'The requested theme does not exist.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4278 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4279 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4280 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4281 |
// Check filesystem credentials. `delete_theme()` will bail otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4282 |
$url = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ); |
16 | 4283 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4284 |
ob_start(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4285 |
$credentials = request_filesystem_credentials( $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4286 |
ob_end_clean(); |
16 | 4287 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4288 |
if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4289 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4290 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4291 |
$status['errorCode'] = 'unable_to_connect_to_filesystem'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4292 |
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4293 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4294 |
// Pass through the error from WP_Filesystem if one was raised. |
9 | 4295 |
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4296 |
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4297 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4298 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4299 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4300 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4301 |
|
16 | 4302 |
include_once ABSPATH . 'wp-admin/includes/theme.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4303 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4304 |
$result = delete_theme( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4305 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4306 |
if ( is_wp_error( $result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4307 |
$status['errorMessage'] = $result->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4308 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4309 |
} elseif ( false === $result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4310 |
$status['errorMessage'] = __( 'Theme could not be deleted.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4311 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4312 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4313 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4314 |
wp_send_json_success( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4315 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4316 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4317 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4318 |
* Ajax handler for installing a plugin. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4319 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4320 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4321 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4322 |
* @see Plugin_Upgrader |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4323 |
* |
9 | 4324 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4325 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4326 |
function wp_ajax_install_plugin() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4327 |
check_ajax_referer( 'updates' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4328 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4329 |
if ( empty( $_POST['slug'] ) ) { |
9 | 4330 |
wp_send_json_error( |
4331 |
array( |
|
4332 |
'slug' => '', |
|
4333 |
'errorCode' => 'no_plugin_specified', |
|
4334 |
'errorMessage' => __( 'No plugin specified.' ), |
|
4335 |
) |
|
4336 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4337 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4338 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4339 |
$status = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4340 |
'install' => 'plugin', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4341 |
'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4342 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4343 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4344 |
if ( ! current_user_can( 'install_plugins' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4345 |
$status['errorMessage'] = __( 'Sorry, you are not allowed to install plugins on this site.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4346 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4347 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4348 |
|
16 | 4349 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
4350 |
include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4351 |
|
9 | 4352 |
$api = plugins_api( |
4353 |
'plugin_information', |
|
4354 |
array( |
|
4355 |
'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ), |
|
4356 |
'fields' => array( |
|
4357 |
'sections' => false, |
|
4358 |
), |
|
4359 |
) |
|
4360 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4361 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4362 |
if ( is_wp_error( $api ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4363 |
$status['errorMessage'] = $api->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4364 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4365 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4366 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4367 |
$status['pluginName'] = $api->name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4368 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4369 |
$skin = new WP_Ajax_Upgrader_Skin(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4370 |
$upgrader = new Plugin_Upgrader( $skin ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4371 |
$result = $upgrader->install( $api->download_link ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4372 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4373 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4374 |
$status['debug'] = $skin->get_upgrade_messages(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4375 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4376 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4377 |
if ( is_wp_error( $result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4378 |
$status['errorCode'] = $result->get_error_code(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4379 |
$status['errorMessage'] = $result->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4380 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4381 |
} elseif ( is_wp_error( $skin->result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4382 |
$status['errorCode'] = $skin->result->get_error_code(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4383 |
$status['errorMessage'] = $skin->result->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4384 |
wp_send_json_error( $status ); |
9 | 4385 |
} elseif ( $skin->get_errors()->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4386 |
$status['errorMessage'] = $skin->get_error_messages(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4387 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4388 |
} elseif ( is_null( $result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4389 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4391 |
$status['errorCode'] = 'unable_to_connect_to_filesystem'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4392 |
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4393 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4394 |
// Pass through the error from WP_Filesystem if one was raised. |
9 | 4395 |
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4396 |
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4397 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4398 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4399 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4400 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4401 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4402 |
$install_status = install_plugin_install_status( $api ); |
9 | 4403 |
$pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4404 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4405 |
// If installation request is coming from import page, do not return network activation link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4406 |
$plugins_url = ( 'import' === $pagenow ) ? admin_url( 'plugins.php' ) : network_admin_url( 'plugins.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4407 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4408 |
if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) { |
9 | 4409 |
$status['activateUrl'] = add_query_arg( |
4410 |
array( |
|
4411 |
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ), |
|
4412 |
'action' => 'activate', |
|
4413 |
'plugin' => $install_status['file'], |
|
4414 |
), |
|
4415 |
$plugins_url |
|
4416 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4417 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4418 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4419 |
if ( is_multisite() && current_user_can( 'manage_network_plugins' ) && 'import' !== $pagenow ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4420 |
$status['activateUrl'] = add_query_arg( array( 'networkwide' => 1 ), $status['activateUrl'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4421 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4422 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4423 |
wp_send_json_success( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4424 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4425 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4426 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4427 |
* Ajax handler for updating a plugin. |
5 | 4428 |
* |
4429 |
* @since 4.2.0 |
|
4430 |
* |
|
4431 |
* @see Plugin_Upgrader |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4432 |
* |
9 | 4433 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
5 | 4434 |
*/ |
4435 |
function wp_ajax_update_plugin() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4436 |
check_ajax_referer( 'updates' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4437 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4438 |
if ( empty( $_POST['plugin'] ) || empty( $_POST['slug'] ) ) { |
9 | 4439 |
wp_send_json_error( |
4440 |
array( |
|
4441 |
'slug' => '', |
|
4442 |
'errorCode' => 'no_plugin_specified', |
|
4443 |
'errorMessage' => __( 'No plugin specified.' ), |
|
4444 |
) |
|
4445 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4446 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4447 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4448 |
$plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) ); |
5 | 4449 |
|
4450 |
$status = array( |
|
4451 |
'update' => 'plugin', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4452 |
'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ), |
5 | 4453 |
'oldVersion' => '', |
4454 |
'newVersion' => '', |
|
4455 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4456 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4457 |
if ( ! current_user_can( 'update_plugins' ) || 0 !== validate_file( $plugin ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4458 |
$status['errorMessage'] = __( 'Sorry, you are not allowed to update plugins for this site.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4459 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4460 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4461 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4462 |
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4463 |
$status['plugin'] = $plugin; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4464 |
$status['pluginName'] = $plugin_data['Name']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4465 |
|
5 | 4466 |
if ( $plugin_data['Version'] ) { |
16 | 4467 |
/* translators: %s: Plugin version. */ |
5 | 4468 |
$status['oldVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); |
4469 |
} |
|
4470 |
||
16 | 4471 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4472 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4473 |
wp_update_plugins(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4474 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4475 |
$skin = new WP_Ajax_Upgrader_Skin(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4476 |
$upgrader = new Plugin_Upgrader( $skin ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4477 |
$result = $upgrader->bulk_upgrade( array( $plugin ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4478 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4479 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4480 |
$status['debug'] = $skin->get_upgrade_messages(); |
5 | 4481 |
} |
4482 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4483 |
if ( is_wp_error( $skin->result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4484 |
$status['errorCode'] = $skin->result->get_error_code(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4485 |
$status['errorMessage'] = $skin->result->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4486 |
wp_send_json_error( $status ); |
9 | 4487 |
} elseif ( $skin->get_errors()->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4488 |
$status['errorMessage'] = $skin->get_error_messages(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4489 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4490 |
} elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) { |
5 | 4491 |
|
4492 |
/* |
|
16 | 4493 |
* Plugin is already at the latest version. |
4494 |
* |
|
4495 |
* This may also be the return value if the `update_plugins` site transient is empty, |
|
4496 |
* e.g. when you update two plugins in quick succession before the transient repopulates. |
|
5 | 4497 |
* |
4498 |
* Preferably something can be done to ensure `update_plugins` isn't empty. |
|
4499 |
* For now, surface some sort of error here. |
|
4500 |
*/ |
|
16 | 4501 |
if ( true === $result[ $plugin ] ) { |
4502 |
$status['errorMessage'] = $upgrader->strings['up_to_date']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4503 |
wp_send_json_error( $status ); |
5 | 4504 |
} |
4505 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4506 |
$plugin_data = get_plugins( '/' . $result[ $plugin ]['destination_name'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4507 |
$plugin_data = reset( $plugin_data ); |
5 | 4508 |
|
4509 |
if ( $plugin_data['Version'] ) { |
|
16 | 4510 |
/* translators: %s: Plugin version. */ |
5 | 4511 |
$status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); |
4512 |
} |
|
16 | 4513 |
|
5 | 4514 |
wp_send_json_success( $status ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4515 |
} elseif ( false === $result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4516 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4517 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4518 |
$status['errorCode'] = 'unable_to_connect_to_filesystem'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4519 |
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4520 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4521 |
// Pass through the error from WP_Filesystem if one was raised. |
9 | 4522 |
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4523 |
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4524 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4525 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4526 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4527 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4528 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4529 |
// An unhandled error occurred. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4530 |
$status['errorMessage'] = __( 'Plugin update failed.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4531 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4532 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4533 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4534 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4535 |
* Ajax handler for deleting a plugin. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4536 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4537 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4538 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4539 |
* @see delete_plugins() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4540 |
* |
9 | 4541 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4542 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4543 |
function wp_ajax_delete_plugin() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4544 |
check_ajax_referer( 'updates' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4545 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4546 |
if ( empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) { |
9 | 4547 |
wp_send_json_error( |
4548 |
array( |
|
4549 |
'slug' => '', |
|
4550 |
'errorCode' => 'no_plugin_specified', |
|
4551 |
'errorMessage' => __( 'No plugin specified.' ), |
|
4552 |
) |
|
4553 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4554 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4555 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4556 |
$plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4557 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4558 |
$status = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4559 |
'delete' => 'plugin', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4560 |
'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4561 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4562 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4563 |
if ( ! current_user_can( 'delete_plugins' ) || 0 !== validate_file( $plugin ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4564 |
$status['errorMessage'] = __( 'Sorry, you are not allowed to delete plugins for this site.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4565 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4566 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4567 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4568 |
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4569 |
$status['plugin'] = $plugin; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4570 |
$status['pluginName'] = $plugin_data['Name']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4571 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4572 |
if ( is_plugin_active( $plugin ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4573 |
$status['errorMessage'] = __( 'You cannot delete a plugin while it is active on the main site.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4574 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4575 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4576 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4577 |
// Check filesystem credentials. `delete_plugins()` will bail otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4578 |
$url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&checked[]=' . $plugin, 'bulk-plugins' ); |
16 | 4579 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4580 |
ob_start(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4581 |
$credentials = request_filesystem_credentials( $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4582 |
ob_end_clean(); |
16 | 4583 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4584 |
if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4585 |
global $wp_filesystem; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4586 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4587 |
$status['errorCode'] = 'unable_to_connect_to_filesystem'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4588 |
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4589 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4590 |
// Pass through the error from WP_Filesystem if one was raised. |
9 | 4591 |
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4592 |
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4593 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4594 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4595 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4596 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4597 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4598 |
$result = delete_plugins( array( $plugin ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4599 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4600 |
if ( is_wp_error( $result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4601 |
$status['errorMessage'] = $result->get_error_message(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4602 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4603 |
} elseif ( false === $result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4604 |
$status['errorMessage'] = __( 'Plugin could not be deleted.' ); |
5 | 4605 |
wp_send_json_error( $status ); |
4606 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4607 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4608 |
wp_send_json_success( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4609 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4610 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4611 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4612 |
* Ajax handler for searching plugins. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4613 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4614 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4615 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4616 |
* @global string $s Search term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4617 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4618 |
function wp_ajax_search_plugins() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4619 |
check_ajax_referer( 'updates' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4620 |
|
16 | 4621 |
// Ensure after_plugin_row_{$plugin_file} gets hooked. |
4622 |
wp_plugin_update_rows(); |
|
4623 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4624 |
$pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4625 |
if ( 'plugins-network' === $pagenow || 'plugins' === $pagenow ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4626 |
set_current_screen( $pagenow ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4627 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4628 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4629 |
/** @var WP_Plugins_List_Table $wp_list_table */ |
9 | 4630 |
$wp_list_table = _get_list_table( |
4631 |
'WP_Plugins_List_Table', |
|
4632 |
array( |
|
4633 |
'screen' => get_current_screen(), |
|
4634 |
) |
|
4635 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4636 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4637 |
$status = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4638 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4639 |
if ( ! $wp_list_table->ajax_user_can() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4640 |
$status['errorMessage'] = __( 'Sorry, you are not allowed to manage plugins for this site.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4641 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4642 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4643 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4644 |
// Set the correct requester, so pagination works. |
9 | 4645 |
$_SERVER['REQUEST_URI'] = add_query_arg( |
4646 |
array_diff_key( |
|
4647 |
$_POST, |
|
4648 |
array( |
|
4649 |
'_ajax_nonce' => null, |
|
4650 |
'action' => null, |
|
4651 |
) |
|
4652 |
), |
|
4653 |
network_admin_url( 'plugins.php', 'relative' ) |
|
4654 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4655 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4656 |
$GLOBALS['s'] = wp_unslash( $_POST['s'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4657 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4658 |
$wp_list_table->prepare_items(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4659 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4660 |
ob_start(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4661 |
$wp_list_table->display(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4662 |
$status['count'] = count( $wp_list_table->items ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4663 |
$status['items'] = ob_get_clean(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4664 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4665 |
wp_send_json_success( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4666 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4667 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4668 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4669 |
* Ajax handler for searching plugins to install. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4670 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4671 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4672 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4673 |
function wp_ajax_search_install_plugins() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4674 |
check_ajax_referer( 'updates' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4675 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4676 |
$pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4677 |
if ( 'plugin-install-network' === $pagenow || 'plugin-install' === $pagenow ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4678 |
set_current_screen( $pagenow ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4679 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4680 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4681 |
/** @var WP_Plugin_Install_List_Table $wp_list_table */ |
9 | 4682 |
$wp_list_table = _get_list_table( |
4683 |
'WP_Plugin_Install_List_Table', |
|
4684 |
array( |
|
4685 |
'screen' => get_current_screen(), |
|
4686 |
) |
|
4687 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4688 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4689 |
$status = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4690 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4691 |
if ( ! $wp_list_table->ajax_user_can() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4692 |
$status['errorMessage'] = __( 'Sorry, you are not allowed to manage plugins for this site.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4693 |
wp_send_json_error( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4694 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4695 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4696 |
// Set the correct requester, so pagination works. |
9 | 4697 |
$_SERVER['REQUEST_URI'] = add_query_arg( |
4698 |
array_diff_key( |
|
4699 |
$_POST, |
|
4700 |
array( |
|
4701 |
'_ajax_nonce' => null, |
|
4702 |
'action' => null, |
|
4703 |
) |
|
4704 |
), |
|
4705 |
network_admin_url( 'plugin-install.php', 'relative' ) |
|
4706 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4707 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4708 |
$wp_list_table->prepare_items(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4709 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4710 |
ob_start(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4711 |
$wp_list_table->display(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4712 |
$status['count'] = (int) $wp_list_table->get_pagination_arg( 'total_items' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4713 |
$status['items'] = ob_get_clean(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4714 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4715 |
wp_send_json_success( $status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4716 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4717 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4718 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4719 |
* Ajax handler for editing a theme or plugin file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4720 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4721 |
* @since 4.9.0 |
16 | 4722 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4723 |
* @see wp_edit_theme_plugin_file() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4724 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4725 |
function wp_ajax_edit_theme_plugin_file() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4726 |
$r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file(). |
16 | 4727 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4728 |
if ( is_wp_error( $r ) ) { |
9 | 4729 |
wp_send_json_error( |
4730 |
array_merge( |
|
4731 |
array( |
|
4732 |
'code' => $r->get_error_code(), |
|
4733 |
'message' => $r->get_error_message(), |
|
4734 |
), |
|
4735 |
(array) $r->get_error_data() |
|
4736 |
) |
|
4737 |
); |
|
4738 |
} else { |
|
4739 |
wp_send_json_success( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4740 |
array( |
9 | 4741 |
'message' => __( 'File edited successfully.' ), |
4742 |
) |
|
4743 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4744 |
} |
5 | 4745 |
} |
4746 |
||
4747 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4748 |
* Ajax handler for exporting a user's personal data. |
5 | 4749 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4750 |
* @since 4.9.6 |
5 | 4751 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4752 |
function wp_ajax_wp_privacy_export_personal_data() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4753 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4754 |
if ( empty( $_POST['id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4755 |
wp_send_json_error( __( 'Missing request ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4756 |
} |
16 | 4757 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4758 |
$request_id = (int) $_POST['id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4759 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4760 |
if ( $request_id < 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4761 |
wp_send_json_error( __( 'Invalid request ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4762 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4763 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4764 |
if ( ! current_user_can( 'export_others_personal_data' ) ) { |
9 | 4765 |
wp_send_json_error( __( 'Sorry, you are not allowed to perform this action.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4766 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4767 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4768 |
check_ajax_referer( 'wp-privacy-export-personal-data-' . $request_id, 'security' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4769 |
|
16 | 4770 |
// Get the request. |
4771 |
$request = wp_get_user_request( $request_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4772 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4773 |
if ( ! $request || 'export_personal_data' !== $request->action_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4774 |
wp_send_json_error( __( 'Invalid request type.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4775 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4776 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4777 |
$email_address = $request->email; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4778 |
if ( ! is_email( $email_address ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4779 |
wp_send_json_error( __( 'A valid email address must be given.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4780 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4781 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4782 |
if ( ! isset( $_POST['exporter'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4783 |
wp_send_json_error( __( 'Missing exporter index.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4784 |
} |
16 | 4785 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4786 |
$exporter_index = (int) $_POST['exporter']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4787 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4788 |
if ( ! isset( $_POST['page'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4789 |
wp_send_json_error( __( 'Missing page index.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4790 |
} |
16 | 4791 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4792 |
$page = (int) $_POST['page']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4793 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4794 |
$send_as_email = isset( $_POST['sendAsEmail'] ) ? ( 'true' === $_POST['sendAsEmail'] ) : false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4795 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4796 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4797 |
* Filters the array of exporter callbacks. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4798 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4799 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4800 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4801 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4802 |
* An array of callable exporters of personal data. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4803 |
* |
16 | 4804 |
* @type array ...$0 { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4805 |
* Array of personal data exporters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4806 |
* |
16 | 4807 |
* @type callable $callback Callable exporter function that accepts an |
4808 |
* email address and a page and returns an array |
|
4809 |
* of name => value pairs of personal data. |
|
4810 |
* @type string $exporter_friendly_name Translated user facing friendly name for the |
|
4811 |
* exporter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4812 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4813 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4814 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4815 |
$exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4816 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4817 |
if ( ! is_array( $exporters ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4818 |
wp_send_json_error( __( 'An exporter has improperly used the registration filter.' ) ); |
5 | 4819 |
} |
4820 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4821 |
// Do we have any registered exporters? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4822 |
if ( 0 < count( $exporters ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4823 |
if ( $exporter_index < 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4824 |
wp_send_json_error( __( 'Exporter index cannot be negative.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4825 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4826 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4827 |
if ( $exporter_index > count( $exporters ) ) { |
9 | 4828 |
wp_send_json_error( __( 'Exporter index is out of range.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4829 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4830 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4831 |
if ( $page < 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4832 |
wp_send_json_error( __( 'Page index cannot be less than one.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4833 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4834 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4835 |
$exporter_keys = array_keys( $exporters ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4836 |
$exporter_key = $exporter_keys[ $exporter_index - 1 ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4837 |
$exporter = $exporters[ $exporter_key ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4838 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4839 |
if ( ! is_array( $exporter ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4840 |
wp_send_json_error( |
16 | 4841 |
/* translators: %s: Exporter array index. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4842 |
sprintf( __( 'Expected an array describing the exporter at index %s.' ), $exporter_key ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4843 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4844 |
} |
16 | 4845 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4846 |
if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4847 |
wp_send_json_error( |
16 | 4848 |
/* translators: %s: Exporter array index. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4849 |
sprintf( __( 'Exporter array at index %s does not include a friendly name.' ), $exporter_key ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4850 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4851 |
} |
9 | 4852 |
|
4853 |
$exporter_friendly_name = $exporter['exporter_friendly_name']; |
|
4854 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4855 |
if ( ! array_key_exists( 'callback', $exporter ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4856 |
wp_send_json_error( |
16 | 4857 |
/* translators: %s: Exporter friendly name. */ |
9 | 4858 |
sprintf( __( 'Exporter does not include a callback: %s.' ), esc_html( $exporter_friendly_name ) ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4859 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4860 |
} |
16 | 4861 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4862 |
if ( ! is_callable( $exporter['callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4863 |
wp_send_json_error( |
16 | 4864 |
/* translators: %s: Exporter friendly name. */ |
9 | 4865 |
sprintf( __( 'Exporter callback is not a valid callback: %s.' ), esc_html( $exporter_friendly_name ) ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4866 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4867 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4868 |
|
9 | 4869 |
$callback = $exporter['callback']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4870 |
$response = call_user_func( $callback, $email_address, $page ); |
9 | 4871 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4872 |
if ( is_wp_error( $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4873 |
wp_send_json_error( $response ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4874 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4875 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4876 |
if ( ! is_array( $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4877 |
wp_send_json_error( |
16 | 4878 |
/* translators: %s: Exporter friendly name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4879 |
sprintf( __( 'Expected response as an array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4880 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4881 |
} |
16 | 4882 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4883 |
if ( ! array_key_exists( 'data', $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4884 |
wp_send_json_error( |
16 | 4885 |
/* translators: %s: Exporter friendly name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4886 |
sprintf( __( 'Expected data in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4887 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4888 |
} |
16 | 4889 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4890 |
if ( ! is_array( $response['data'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4891 |
wp_send_json_error( |
16 | 4892 |
/* translators: %s: Exporter friendly name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4893 |
sprintf( __( 'Expected data array in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4894 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4895 |
} |
16 | 4896 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4897 |
if ( ! array_key_exists( 'done', $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4898 |
wp_send_json_error( |
16 | 4899 |
/* translators: %s: Exporter friendly name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4900 |
sprintf( __( 'Expected done (boolean) in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4901 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4902 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4903 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4904 |
// No exporters, so we're done. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4905 |
$exporter_key = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4906 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4907 |
$response = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4908 |
'data' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4909 |
'done' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4910 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4911 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4912 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4913 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4914 |
* Filters a page of personal data exporter data. Used to build the export report. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4915 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4916 |
* Allows the export response to be consumed by destinations in addition to Ajax. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4917 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4918 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4919 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4920 |
* @param array $response The personal data for the given exporter and page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4921 |
* @param int $exporter_index The index of the exporter that provided this data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4922 |
* @param string $email_address The email address associated with this personal data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4923 |
* @param int $page The page for this response. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4924 |
* @param int $request_id The privacy request post ID associated with this request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4925 |
* @param bool $send_as_email Whether the final results of the export should be emailed to the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4926 |
* @param string $exporter_key The key (slug) of the exporter that provided this data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4927 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4928 |
$response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page, $request_id, $send_as_email, $exporter_key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4929 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4930 |
if ( is_wp_error( $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4931 |
wp_send_json_error( $response ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4932 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4933 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4934 |
wp_send_json_success( $response ); |
5 | 4935 |
} |
4936 |
||
4937 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4938 |
* Ajax handler for erasing personal data. |
5 | 4939 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4940 |
* @since 4.9.6 |
5 | 4941 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4942 |
function wp_ajax_wp_privacy_erase_personal_data() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4943 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4944 |
if ( empty( $_POST['id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4945 |
wp_send_json_error( __( 'Missing request ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4946 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4947 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4948 |
$request_id = (int) $_POST['id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4949 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4950 |
if ( $request_id < 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4951 |
wp_send_json_error( __( 'Invalid request ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4952 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4953 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4954 |
// Both capabilities are required to avoid confusion, see `_wp_personal_data_removal_page()`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4955 |
if ( ! current_user_can( 'erase_others_personal_data' ) || ! current_user_can( 'delete_users' ) ) { |
9 | 4956 |
wp_send_json_error( __( 'Sorry, you are not allowed to perform this action.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4957 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4958 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4959 |
check_ajax_referer( 'wp-privacy-erase-personal-data-' . $request_id, 'security' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4960 |
|
16 | 4961 |
// Get the request. |
4962 |
$request = wp_get_user_request( $request_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4963 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4964 |
if ( ! $request || 'remove_personal_data' !== $request->action_name ) { |
9 | 4965 |
wp_send_json_error( __( 'Invalid request type.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4966 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4967 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4968 |
$email_address = $request->email; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4969 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4970 |
if ( ! is_email( $email_address ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4971 |
wp_send_json_error( __( 'Invalid email address in request.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4972 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4973 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4974 |
if ( ! isset( $_POST['eraser'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4975 |
wp_send_json_error( __( 'Missing eraser index.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4976 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4977 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4978 |
$eraser_index = (int) $_POST['eraser']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4979 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4980 |
if ( ! isset( $_POST['page'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4981 |
wp_send_json_error( __( 'Missing page index.' ) ); |
5 | 4982 |
} |
4983 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4984 |
$page = (int) $_POST['page']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4985 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4986 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4987 |
* Filters the array of personal data eraser callbacks. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4988 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4989 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4990 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4991 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4992 |
* An array of callable erasers of personal data. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4993 |
* |
16 | 4994 |
* @type array ...$0 { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4995 |
* Array of personal data exporters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4996 |
* |
16 | 4997 |
* @type callable $callback Callable eraser that accepts an email address and |
4998 |
* a page and returns an array with boolean values for |
|
4999 |
* whether items were removed or retained and any messages |
|
5000 |
* from the eraser, as well as if additional pages are |
|
5001 |
* available. |
|
5002 |
* @type string $exporter_friendly_name Translated user facing friendly name for the eraser. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5003 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5004 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5005 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5006 |
$erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5007 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5008 |
// Do we have any registered erasers? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5009 |
if ( 0 < count( $erasers ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5010 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5011 |
if ( $eraser_index < 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5012 |
wp_send_json_error( __( 'Eraser index cannot be less than one.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5013 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5014 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5015 |
if ( $eraser_index > count( $erasers ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5016 |
wp_send_json_error( __( 'Eraser index is out of range.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5017 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5018 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5019 |
if ( $page < 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5020 |
wp_send_json_error( __( 'Page index cannot be less than one.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5021 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5022 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5023 |
$eraser_keys = array_keys( $erasers ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5024 |
$eraser_key = $eraser_keys[ $eraser_index - 1 ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5025 |
$eraser = $erasers[ $eraser_key ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5026 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5027 |
if ( ! is_array( $eraser ) ) { |
16 | 5028 |
/* translators: %d: Eraser array index. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5029 |
wp_send_json_error( sprintf( __( 'Expected an array describing the eraser at index %d.' ), $eraser_index ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5030 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5031 |
|
9 | 5032 |
if ( ! array_key_exists( 'eraser_friendly_name', $eraser ) ) { |
16 | 5033 |
/* translators: %d: Eraser array index. */ |
9 | 5034 |
wp_send_json_error( sprintf( __( 'Eraser array at index %d does not include a friendly name.' ), $eraser_index ) ); |
5035 |
} |
|
5036 |
||
5037 |
$eraser_friendly_name = $eraser['eraser_friendly_name']; |
|
5038 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5039 |
if ( ! array_key_exists( 'callback', $eraser ) ) { |
9 | 5040 |
wp_send_json_error( |
5041 |
sprintf( |
|
16 | 5042 |
/* translators: %s: Eraser friendly name. */ |
9 | 5043 |
__( 'Eraser does not include a callback: %s.' ), |
5044 |
esc_html( $eraser_friendly_name ) |
|
5045 |
) |
|
5046 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5047 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5048 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5049 |
if ( ! is_callable( $eraser['callback'] ) ) { |
9 | 5050 |
wp_send_json_error( |
5051 |
sprintf( |
|
16 | 5052 |
/* translators: %s: Eraser friendly name. */ |
9 | 5053 |
__( 'Eraser callback is not valid: %s.' ), |
5054 |
esc_html( $eraser_friendly_name ) |
|
5055 |
) |
|
5056 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5057 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5058 |
|
9 | 5059 |
$callback = $eraser['callback']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5060 |
$response = call_user_func( $callback, $email_address, $page ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5061 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5062 |
if ( is_wp_error( $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5063 |
wp_send_json_error( $response ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5064 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5065 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5066 |
if ( ! is_array( $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5067 |
wp_send_json_error( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5068 |
sprintf( |
16 | 5069 |
/* translators: 1: Eraser friendly name, 2: Eraser array index. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5070 |
__( 'Did not receive array from %1$s eraser (index %2$d).' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5071 |
esc_html( $eraser_friendly_name ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5072 |
$eraser_index |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5073 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5074 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5075 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5076 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5077 |
if ( ! array_key_exists( 'items_removed', $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5078 |
wp_send_json_error( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5079 |
sprintf( |
16 | 5080 |
/* translators: 1: Eraser friendly name, 2: Eraser array index. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5081 |
__( 'Expected items_removed key in response array from %1$s eraser (index %2$d).' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5082 |
esc_html( $eraser_friendly_name ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5083 |
$eraser_index |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5084 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5085 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5086 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5087 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5088 |
if ( ! array_key_exists( 'items_retained', $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5089 |
wp_send_json_error( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5090 |
sprintf( |
16 | 5091 |
/* translators: 1: Eraser friendly name, 2: Eraser array index. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5092 |
__( 'Expected items_retained key in response array from %1$s eraser (index %2$d).' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5093 |
esc_html( $eraser_friendly_name ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5094 |
$eraser_index |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5095 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5096 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5097 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5098 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5099 |
if ( ! array_key_exists( 'messages', $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5100 |
wp_send_json_error( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5101 |
sprintf( |
16 | 5102 |
/* translators: 1: Eraser friendly name, 2: Eraser array index. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5103 |
__( 'Expected messages key in response array from %1$s eraser (index %2$d).' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5104 |
esc_html( $eraser_friendly_name ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5105 |
$eraser_index |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5106 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5107 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5108 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5109 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5110 |
if ( ! is_array( $response['messages'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5111 |
wp_send_json_error( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5112 |
sprintf( |
16 | 5113 |
/* translators: 1: Eraser friendly name, 2: Eraser array index. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5114 |
__( 'Expected messages key to reference an array in response array from %1$s eraser (index %2$d).' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5115 |
esc_html( $eraser_friendly_name ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5116 |
$eraser_index |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5117 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5118 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5119 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5120 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5121 |
if ( ! array_key_exists( 'done', $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5122 |
wp_send_json_error( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5123 |
sprintf( |
16 | 5124 |
/* translators: 1: Eraser friendly name, 2: Eraser array index. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5125 |
__( 'Expected done flag in response array from %1$s eraser (index %2$d).' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5126 |
esc_html( $eraser_friendly_name ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5127 |
$eraser_index |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5128 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5129 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5130 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5131 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5132 |
// No erasers, so we're done. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5133 |
$eraser_key = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5134 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5135 |
$response = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5136 |
'items_removed' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5137 |
'items_retained' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5138 |
'messages' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5139 |
'done' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5140 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5141 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5142 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5143 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5144 |
* Filters a page of personal data eraser data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5145 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5146 |
* Allows the erasure response to be consumed by destinations in addition to Ajax. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5147 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5148 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5149 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5150 |
* @param array $response The personal data for the given exporter and page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5151 |
* @param int $eraser_index The index of the eraser that provided this data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5152 |
* @param string $email_address The email address associated with this personal data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5153 |
* @param int $page The page for this response. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5154 |
* @param int $request_id The privacy request post ID associated with this request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5155 |
* @param string $eraser_key The key (slug) of the eraser that provided this data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5156 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5157 |
$response = apply_filters( 'wp_privacy_personal_data_erasure_page', $response, $eraser_index, $email_address, $page, $request_id, $eraser_key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5158 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5159 |
if ( is_wp_error( $response ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5160 |
wp_send_json_error( $response ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5161 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5162 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5163 |
wp_send_json_success( $response ); |
5 | 5164 |
} |
9 | 5165 |
|
5166 |
/** |
|
5167 |
* Ajax handler for site health checks on server communication. |
|
5168 |
* |
|
5169 |
* @since 5.2.0 |
|
18 | 5170 |
* @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_dotorg_communication() |
5171 |
* @see WP_REST_Site_Health_Controller::test_dotorg_communication() |
|
9 | 5172 |
*/ |
5173 |
function wp_ajax_health_check_dotorg_communication() { |
|
18 | 5174 |
_doing_it_wrong( |
5175 |
'wp_ajax_health_check_dotorg_communication', |
|
5176 |
sprintf( |
|
5177 |
// translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it. |
|
5178 |
__( 'The Site Health check for %1$s has been replaced with %2$s.' ), |
|
5179 |
'wp_ajax_health_check_dotorg_communication', |
|
5180 |
'WP_REST_Site_Health_Controller::test_dotorg_communication' |
|
5181 |
), |
|
5182 |
'5.6.0' |
|
5183 |
); |
|
5184 |
||
9 | 5185 |
check_ajax_referer( 'health-check-site-status' ); |
5186 |
||
5187 |
if ( ! current_user_can( 'view_site_health_checks' ) ) { |
|
5188 |
wp_send_json_error(); |
|
5189 |
} |
|
5190 |
||
5191 |
if ( ! class_exists( 'WP_Site_Health' ) ) { |
|
16 | 5192 |
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php'; |
5193 |
} |
|
5194 |
||
5195 |
$site_health = WP_Site_Health::get_instance(); |
|
9 | 5196 |
wp_send_json_success( $site_health->get_test_dotorg_communication() ); |
5197 |
} |
|
5198 |
||
5199 |
/** |
|
5200 |
* Ajax handler for site health checks on background updates. |
|
5201 |
* |
|
5202 |
* @since 5.2.0 |
|
18 | 5203 |
* @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_background_updates() |
5204 |
* @see WP_REST_Site_Health_Controller::test_background_updates() |
|
9 | 5205 |
*/ |
5206 |
function wp_ajax_health_check_background_updates() { |
|
18 | 5207 |
_doing_it_wrong( |
5208 |
'wp_ajax_health_check_background_updates', |
|
5209 |
sprintf( |
|
5210 |
// translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it. |
|
5211 |
__( 'The Site Health check for %1$s has been replaced with %2$s.' ), |
|
5212 |
'wp_ajax_health_check_background_updates', |
|
5213 |
'WP_REST_Site_Health_Controller::test_background_updates' |
|
5214 |
), |
|
5215 |
'5.6.0' |
|
5216 |
); |
|
5217 |
||
9 | 5218 |
check_ajax_referer( 'health-check-site-status' ); |
5219 |
||
5220 |
if ( ! current_user_can( 'view_site_health_checks' ) ) { |
|
5221 |
wp_send_json_error(); |
|
5222 |
} |
|
5223 |
||
5224 |
if ( ! class_exists( 'WP_Site_Health' ) ) { |
|
16 | 5225 |
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php'; |
5226 |
} |
|
5227 |
||
5228 |
$site_health = WP_Site_Health::get_instance(); |
|
9 | 5229 |
wp_send_json_success( $site_health->get_test_background_updates() ); |
5230 |
} |
|
5231 |
||
5232 |
/** |
|
5233 |
* Ajax handler for site health checks on loopback requests. |
|
5234 |
* |
|
5235 |
* @since 5.2.0 |
|
18 | 5236 |
* @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_loopback_requests() |
5237 |
* @see WP_REST_Site_Health_Controller::test_loopback_requests() |
|
9 | 5238 |
*/ |
5239 |
function wp_ajax_health_check_loopback_requests() { |
|
18 | 5240 |
_doing_it_wrong( |
5241 |
'wp_ajax_health_check_loopback_requests', |
|
5242 |
sprintf( |
|
5243 |
// translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it. |
|
5244 |
__( 'The Site Health check for %1$s has been replaced with %2$s.' ), |
|
5245 |
'wp_ajax_health_check_loopback_requests', |
|
5246 |
'WP_REST_Site_Health_Controller::test_loopback_requests' |
|
5247 |
), |
|
5248 |
'5.6.0' |
|
5249 |
); |
|
5250 |
||
9 | 5251 |
check_ajax_referer( 'health-check-site-status' ); |
5252 |
||
5253 |
if ( ! current_user_can( 'view_site_health_checks' ) ) { |
|
5254 |
wp_send_json_error(); |
|
5255 |
} |
|
5256 |
||
5257 |
if ( ! class_exists( 'WP_Site_Health' ) ) { |
|
16 | 5258 |
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php'; |
5259 |
} |
|
5260 |
||
5261 |
$site_health = WP_Site_Health::get_instance(); |
|
9 | 5262 |
wp_send_json_success( $site_health->get_test_loopback_requests() ); |
5263 |
} |
|
5264 |
||
5265 |
/** |
|
5266 |
* Ajax handler for site health check to update the result status. |
|
5267 |
* |
|
5268 |
* @since 5.2.0 |
|
5269 |
*/ |
|
5270 |
function wp_ajax_health_check_site_status_result() { |
|
5271 |
check_ajax_referer( 'health-check-site-status-result' ); |
|
5272 |
||
5273 |
if ( ! current_user_can( 'view_site_health_checks' ) ) { |
|
5274 |
wp_send_json_error(); |
|
5275 |
} |
|
5276 |
||
5277 |
set_transient( 'health-check-site-status-result', wp_json_encode( $_POST['counts'] ) ); |
|
5278 |
||
5279 |
wp_send_json_success(); |
|
5280 |
} |
|
5281 |
||
5282 |
/** |
|
5283 |
* Ajax handler for site health check to get directories and database sizes. |
|
5284 |
* |
|
5285 |
* @since 5.2.0 |
|
18 | 5286 |
* @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::get_directory_sizes() |
5287 |
* @see WP_REST_Site_Health_Controller::get_directory_sizes() |
|
9 | 5288 |
*/ |
5289 |
function wp_ajax_health_check_get_sizes() { |
|
18 | 5290 |
_doing_it_wrong( |
5291 |
'wp_ajax_health_check_get_sizes', |
|
5292 |
sprintf( |
|
5293 |
// translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it. |
|
5294 |
__( 'The Site Health check for %1$s has been replaced with %2$s.' ), |
|
5295 |
'wp_ajax_health_check_get_sizes', |
|
5296 |
'WP_REST_Site_Health_Controller::get_directory_sizes' |
|
5297 |
), |
|
5298 |
'5.6.0' |
|
5299 |
); |
|
5300 |
||
9 | 5301 |
check_ajax_referer( 'health-check-site-status-result' ); |
5302 |
||
5303 |
if ( ! current_user_can( 'view_site_health_checks' ) || is_multisite() ) { |
|
5304 |
wp_send_json_error(); |
|
5305 |
} |
|
5306 |
||
5307 |
if ( ! class_exists( 'WP_Debug_Data' ) ) { |
|
16 | 5308 |
require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php'; |
9 | 5309 |
} |
5310 |
||
5311 |
$sizes_data = WP_Debug_Data::get_sizes(); |
|
5312 |
$all_sizes = array( 'raw' => 0 ); |
|
5313 |
||
5314 |
foreach ( $sizes_data as $name => $value ) { |
|
5315 |
$name = sanitize_text_field( $name ); |
|
5316 |
$data = array(); |
|
5317 |
||
5318 |
if ( isset( $value['size'] ) ) { |
|
5319 |
if ( is_string( $value['size'] ) ) { |
|
5320 |
$data['size'] = sanitize_text_field( $value['size'] ); |
|
5321 |
} else { |
|
5322 |
$data['size'] = (int) $value['size']; |
|
5323 |
} |
|
5324 |
} |
|
5325 |
||
5326 |
if ( isset( $value['debug'] ) ) { |
|
5327 |
if ( is_string( $value['debug'] ) ) { |
|
5328 |
$data['debug'] = sanitize_text_field( $value['debug'] ); |
|
5329 |
} else { |
|
5330 |
$data['debug'] = (int) $value['debug']; |
|
5331 |
} |
|
5332 |
} |
|
5333 |
||
5334 |
if ( ! empty( $value['raw'] ) ) { |
|
5335 |
$data['raw'] = (int) $value['raw']; |
|
5336 |
} |
|
5337 |
||
5338 |
$all_sizes[ $name ] = $data; |
|
5339 |
} |
|
5340 |
||
5341 |
if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) { |
|
5342 |
wp_send_json_error( $all_sizes ); |
|
5343 |
} |
|
5344 |
||
5345 |
wp_send_json_success( $all_sizes ); |
|
5346 |
} |
|
16 | 5347 |
|
5348 |
/** |
|
5349 |
* Ajax handler to renew the REST API nonce. |
|
5350 |
* |
|
5351 |
* @since 5.3.0 |
|
5352 |
*/ |
|
5353 |
function wp_ajax_rest_nonce() { |
|
5354 |
exit( wp_create_nonce( 'wp_rest' ) ); |
|
5355 |
} |
|
5356 |
||
5357 |
/** |
|
5358 |
* Ajax handler to enable or disable plugin and theme auto-updates. |
|
5359 |
* |
|
5360 |
* @since 5.5.0 |
|
5361 |
*/ |
|
5362 |
function wp_ajax_toggle_auto_updates() { |
|
5363 |
check_ajax_referer( 'updates' ); |
|
5364 |
||
5365 |
if ( empty( $_POST['type'] ) || empty( $_POST['asset'] ) || empty( $_POST['state'] ) ) { |
|
5366 |
wp_send_json_error( array( 'error' => __( 'Invalid data. No selected item.' ) ) ); |
|
5367 |
} |
|
5368 |
||
5369 |
$asset = sanitize_text_field( urldecode( $_POST['asset'] ) ); |
|
5370 |
||
5371 |
if ( 'enable' !== $_POST['state'] && 'disable' !== $_POST['state'] ) { |
|
5372 |
wp_send_json_error( array( 'error' => __( 'Invalid data. Unknown state.' ) ) ); |
|
5373 |
} |
|
5374 |
$state = $_POST['state']; |
|
5375 |
||
5376 |
if ( 'plugin' !== $_POST['type'] && 'theme' !== $_POST['type'] ) { |
|
5377 |
wp_send_json_error( array( 'error' => __( 'Invalid data. Unknown type.' ) ) ); |
|
5378 |
} |
|
5379 |
$type = $_POST['type']; |
|
5380 |
||
5381 |
switch ( $type ) { |
|
5382 |
case 'plugin': |
|
5383 |
if ( ! current_user_can( 'update_plugins' ) ) { |
|
5384 |
$error_message = __( 'Sorry, you are not allowed to modify plugins.' ); |
|
5385 |
wp_send_json_error( array( 'error' => $error_message ) ); |
|
5386 |
} |
|
5387 |
||
5388 |
$option = 'auto_update_plugins'; |
|
5389 |
/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ |
|
5390 |
$all_items = apply_filters( 'all_plugins', get_plugins() ); |
|
5391 |
break; |
|
5392 |
case 'theme': |
|
5393 |
if ( ! current_user_can( 'update_themes' ) ) { |
|
5394 |
$error_message = __( 'Sorry, you are not allowed to modify themes.' ); |
|
5395 |
wp_send_json_error( array( 'error' => $error_message ) ); |
|
5396 |
} |
|
5397 |
||
5398 |
$option = 'auto_update_themes'; |
|
5399 |
$all_items = wp_get_themes(); |
|
5400 |
break; |
|
5401 |
default: |
|
5402 |
wp_send_json_error( array( 'error' => __( 'Invalid data. Unknown type.' ) ) ); |
|
5403 |
} |
|
5404 |
||
5405 |
if ( ! array_key_exists( $asset, $all_items ) ) { |
|
5406 |
$error_message = __( 'Invalid data. The item does not exist.' ); |
|
5407 |
wp_send_json_error( array( 'error' => $error_message ) ); |
|
5408 |
} |
|
5409 |
||
5410 |
$auto_updates = (array) get_site_option( $option, array() ); |
|
5411 |
||
5412 |
if ( 'disable' === $state ) { |
|
5413 |
$auto_updates = array_diff( $auto_updates, array( $asset ) ); |
|
5414 |
} else { |
|
5415 |
$auto_updates[] = $asset; |
|
5416 |
$auto_updates = array_unique( $auto_updates ); |
|
5417 |
} |
|
5418 |
||
5419 |
// Remove items that have been deleted since the site option was last updated. |
|
5420 |
$auto_updates = array_intersect( $auto_updates, array_keys( $all_items ) ); |
|
5421 |
||
5422 |
update_site_option( $option, $auto_updates ); |
|
5423 |
||
5424 |
wp_send_json_success(); |
|
5425 |
} |
|
18 | 5426 |
|
5427 |
/** |
|
5428 |
* Ajax handler sends a password reset link. |
|
5429 |
* |
|
5430 |
* @since 5.7.0 |
|
5431 |
*/ |
|
5432 |
function wp_ajax_send_password_reset() { |
|
5433 |
||
5434 |
// Validate the nonce for this action. |
|
5435 |
$user_id = isset( $_POST['user_id'] ) ? (int) $_POST['user_id'] : 0; |
|
5436 |
check_ajax_referer( 'reset-password-for-' . $user_id, 'nonce' ); |
|
5437 |
||
5438 |
// Verify user capabilities. |
|
5439 |
if ( ! current_user_can( 'edit_user', $user_id ) ) { |
|
5440 |
wp_send_json_error( __( 'Cannot send password reset, permission denied.' ) ); |
|
5441 |
} |
|
5442 |
||
5443 |
// Send the password reset link. |
|
5444 |
$user = get_userdata( $user_id ); |
|
5445 |
$results = retrieve_password( $user->user_login ); |
|
5446 |
||
5447 |
if ( true === $results ) { |
|
5448 |
wp_send_json_success( |
|
5449 |
/* translators: %s: User's display name. */ |
|
5450 |
sprintf( __( 'A password reset link was emailed to %s.' ), $user->display_name ) |
|
5451 |
); |
|
5452 |
} else { |
|
5453 |
wp_send_json_error( $results->get_error_message() ); |
|
5454 |
} |
|
5455 |
} |