| author | ymh <ymh.work@gmail.com> |
| Fri, 05 Sep 2025 18:40:08 +0200 | |
| changeset 21 | 48c4eec2b7e6 |
| parent 19 | 3d72ae0968f4 |
| child 22 | 8c2e4d02f4ef |
| permissions | -rw-r--r-- |
| 0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Post Administration API. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
| 19 | 10 |
* Renames `$_POST` data from form names to DB post columns. |
| 0 | 11 |
* |
| 19 | 12 |
* Manipulates `$_POST` directly. |
| 0 | 13 |
* |
14 |
* @since 2.6.0 |
|
15 |
* |
|
| 19 | 16 |
* @param bool $update Whether the post already exists. |
17 |
* @param array|null $post_data Optional. The array of post data to process. |
|
18 |
* Defaults to the `$_POST` superglobal. |
|
| 16 | 19 |
* @return array|WP_Error Array of post data on success, WP_Error on failure. |
| 0 | 20 |
*/ |
21 |
function _wp_translate_postdata( $update = false, $post_data = null ) { |
|
22 |
||
| 9 | 23 |
if ( empty( $post_data ) ) { |
| 0 | 24 |
$post_data = &$_POST; |
| 9 | 25 |
} |
| 0 | 26 |
|
| 9 | 27 |
if ( $update ) { |
| 0 | 28 |
$post_data['ID'] = (int) $post_data['post_ID']; |
| 9 | 29 |
} |
| 0 | 30 |
|
31 |
$ptype = get_post_type_object( $post_data['post_type'] ); |
|
32 |
||
33 |
if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) { |
|
| 16 | 34 |
if ( 'page' === $post_data['post_type'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) ); |
| 9 | 36 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) ); |
| 9 | 38 |
} |
| 0 | 39 |
} elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) { |
| 16 | 40 |
if ( 'page' === $post_data['post_type'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) ); |
| 9 | 42 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
| 9 | 44 |
} |
| 0 | 45 |
} |
46 |
||
| 9 | 47 |
if ( isset( $post_data['content'] ) ) { |
| 0 | 48 |
$post_data['post_content'] = $post_data['content']; |
| 9 | 49 |
} |
| 0 | 50 |
|
| 9 | 51 |
if ( isset( $post_data['excerpt'] ) ) { |
| 0 | 52 |
$post_data['post_excerpt'] = $post_data['excerpt']; |
| 9 | 53 |
} |
| 0 | 54 |
|
| 9 | 55 |
if ( isset( $post_data['parent_id'] ) ) { |
| 0 | 56 |
$post_data['post_parent'] = (int) $post_data['parent_id']; |
| 9 | 57 |
} |
| 0 | 58 |
|
| 9 | 59 |
if ( isset( $post_data['trackback_url'] ) ) { |
| 0 | 60 |
$post_data['to_ping'] = $post_data['trackback_url']; |
| 9 | 61 |
} |
| 0 | 62 |
|
63 |
$post_data['user_ID'] = get_current_user_id(); |
|
64 |
||
| 9 | 65 |
if ( ! empty( $post_data['post_author_override'] ) ) { |
| 0 | 66 |
$post_data['post_author'] = (int) $post_data['post_author_override']; |
67 |
} else { |
|
| 9 | 68 |
if ( ! empty( $post_data['post_author'] ) ) { |
| 0 | 69 |
$post_data['post_author'] = (int) $post_data['post_author']; |
70 |
} else { |
|
71 |
$post_data['post_author'] = (int) $post_data['user_ID']; |
|
72 |
} |
|
73 |
} |
|
74 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
75 |
if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] !== $post_data['user_ID'] ) |
| 9 | 76 |
&& ! current_user_can( $ptype->cap->edit_others_posts ) ) { |
77 |
||
| 0 | 78 |
if ( $update ) { |
| 16 | 79 |
if ( 'page' === $post_data['post_type'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) ); |
| 9 | 81 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) ); |
| 9 | 83 |
} |
| 0 | 84 |
} else { |
| 16 | 85 |
if ( 'page' === $post_data['post_type'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) ); |
| 9 | 87 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
| 9 | 89 |
} |
| 0 | 90 |
} |
91 |
} |
|
92 |
||
| 5 | 93 |
if ( ! empty( $post_data['post_status'] ) ) { |
| 0 | 94 |
$post_data['post_status'] = sanitize_key( $post_data['post_status'] ); |
95 |
||
| 16 | 96 |
// No longer an auto-draft. |
| 5 | 97 |
if ( 'auto-draft' === $post_data['post_status'] ) { |
98 |
$post_data['post_status'] = 'draft'; |
|
99 |
} |
|
100 |
||
101 |
if ( ! get_post_status_object( $post_data['post_status'] ) ) { |
|
102 |
unset( $post_data['post_status'] ); |
|
103 |
} |
|
104 |
} |
|
105 |
||
| 16 | 106 |
// What to do based on which button they pressed. |
107 |
if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) { |
|
| 0 | 108 |
$post_data['post_status'] = 'draft'; |
| 9 | 109 |
} |
| 16 | 110 |
if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) { |
| 0 | 111 |
$post_data['post_status'] = 'private'; |
| 9 | 112 |
} |
| 16 | 113 |
if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] ) |
114 |
&& ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] ) |
|
115 |
) { |
|
| 0 | 116 |
$post_data['post_status'] = 'publish'; |
| 9 | 117 |
} |
| 16 | 118 |
if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) { |
| 0 | 119 |
$post_data['post_status'] = 'draft'; |
| 9 | 120 |
} |
| 16 | 121 |
if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) { |
| 0 | 122 |
$post_data['post_status'] = 'pending'; |
| 9 | 123 |
} |
| 0 | 124 |
|
| 9 | 125 |
if ( isset( $post_data['ID'] ) ) { |
| 0 | 126 |
$post_id = $post_data['ID']; |
| 9 | 127 |
} else { |
| 0 | 128 |
$post_id = false; |
| 9 | 129 |
} |
| 0 | 130 |
$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false; |
131 |
||
| 16 | 132 |
if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) { |
| 5 | 133 |
$post_data['post_status'] = $previous_status ? $previous_status : 'pending'; |
134 |
} |
|
135 |
||
| 0 | 136 |
$published_statuses = array( 'publish', 'future' ); |
137 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
138 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
* Posts 'submitted for approval' are submitted to $_POST the same as if they were being published. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
* Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
*/ |
| 16 | 142 |
if ( isset( $post_data['post_status'] ) |
143 |
&& ( in_array( $post_data['post_status'], $published_statuses, true ) |
|
144 |
&& ! current_user_can( $ptype->cap->publish_posts ) ) |
|
145 |
) { |
|
146 |
if ( ! in_array( $previous_status, $published_statuses, true ) || ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 0 | 147 |
$post_data['post_status'] = 'pending'; |
| 9 | 148 |
} |
149 |
} |
|
| 0 | 150 |
|
| 5 | 151 |
if ( ! isset( $post_data['post_status'] ) ) { |
152 |
$post_data['post_status'] = 'auto-draft' === $previous_status ? 'draft' : $previous_status; |
|
153 |
} |
|
154 |
||
155 |
if ( isset( $post_data['post_password'] ) && ! current_user_can( $ptype->cap->publish_posts ) ) { |
|
156 |
unset( $post_data['post_password'] ); |
|
157 |
} |
|
| 0 | 158 |
|
| 9 | 159 |
if ( ! isset( $post_data['comment_status'] ) ) { |
| 0 | 160 |
$post_data['comment_status'] = 'closed'; |
| 9 | 161 |
} |
| 0 | 162 |
|
| 9 | 163 |
if ( ! isset( $post_data['ping_status'] ) ) { |
| 0 | 164 |
$post_data['ping_status'] = 'closed'; |
| 9 | 165 |
} |
| 0 | 166 |
|
| 9 | 167 |
foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
168 |
if ( ! empty( $post_data[ 'hidden_' . $timeunit ] ) && $post_data[ 'hidden_' . $timeunit ] !== $post_data[ $timeunit ] ) { |
| 0 | 169 |
$post_data['edit_date'] = '1'; |
170 |
break; |
|
171 |
} |
|
172 |
} |
|
173 |
||
| 9 | 174 |
if ( ! empty( $post_data['edit_date'] ) ) { |
| 18 | 175 |
$aa = $post_data['aa']; |
176 |
$mm = $post_data['mm']; |
|
177 |
$jj = $post_data['jj']; |
|
178 |
$hh = $post_data['hh']; |
|
179 |
$mn = $post_data['mn']; |
|
180 |
$ss = $post_data['ss']; |
|
181 |
$aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa; |
|
182 |
$mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm; |
|
183 |
$jj = ( $jj > 31 ) ? 31 : $jj; |
|
184 |
$jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj; |
|
185 |
$hh = ( $hh > 23 ) ? $hh - 24 : $hh; |
|
186 |
$mn = ( $mn > 59 ) ? $mn - 60 : $mn; |
|
187 |
$ss = ( $ss > 59 ) ? $ss - 60 : $ss; |
|
188 |
||
| 9 | 189 |
$post_data['post_date'] = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss ); |
| 18 | 190 |
|
191 |
$valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] ); |
|
| 9 | 192 |
if ( ! $valid_date ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
return new WP_Error( 'invalid_date', __( 'Invalid date.' ) ); |
| 0 | 194 |
} |
| 18 | 195 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
196 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
197 |
* Only assign a post date if the user has explicitly set a new value. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
198 |
* See #59125 and #19907. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
199 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
200 |
$previous_date = $post_id ? get_post_field( 'post_date', $post_id ) : false; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
201 |
if ( $previous_date && $previous_date !== $post_data['post_date'] ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
202 |
$post_data['edit_date'] = true; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
203 |
$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
204 |
} else { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
205 |
$post_data['edit_date'] = false; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
206 |
unset( $post_data['post_date'] ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
207 |
unset( $post_data['post_date_gmt'] ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
208 |
} |
| 0 | 209 |
} |
210 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
if ( isset( $post_data['post_category'] ) ) { |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
$category_object = get_taxonomy( 'category' ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
if ( ! current_user_can( $category_object->cap->assign_terms ) ) { |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
unset( $post_data['post_category'] ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
|
| 0 | 218 |
return $post_data; |
219 |
} |
|
220 |
||
221 |
/** |
|
| 19 | 222 |
* Returns only allowed post data fields. |
| 9 | 223 |
* |
224 |
* @since 5.0.1 |
|
225 |
* |
|
| 19 | 226 |
* @param array|WP_Error|null $post_data The array of post data to process, or an error object. |
227 |
* Defaults to the `$_POST` superglobal. |
|
| 16 | 228 |
* @return array|WP_Error Array of post data on success, WP_Error on failure. |
| 9 | 229 |
*/ |
230 |
function _wp_get_allowed_postdata( $post_data = null ) { |
|
231 |
if ( empty( $post_data ) ) { |
|
232 |
$post_data = $_POST; |
|
233 |
} |
|
234 |
||
| 16 | 235 |
// Pass through errors. |
| 9 | 236 |
if ( is_wp_error( $post_data ) ) { |
237 |
return $post_data; |
|
238 |
} |
|
239 |
||
240 |
return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) ); |
|
241 |
} |
|
242 |
||
243 |
/** |
|
| 19 | 244 |
* Updates an existing post with values provided in `$_POST`. |
| 0 | 245 |
* |
| 16 | 246 |
* If post data is passed as an argument, it is treated as an array of data |
247 |
* keyed appropriately for turning into a post object. |
|
248 |
* |
|
| 19 | 249 |
* If post data is not passed, the `$_POST` global variable is used instead. |
| 16 | 250 |
* |
| 0 | 251 |
* @since 1.5.0 |
252 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
* |
| 19 | 255 |
* @param array|null $post_data Optional. The array of post data to process. |
256 |
* Defaults to the `$_POST` superglobal. |
|
| 0 | 257 |
* @return int Post ID. |
258 |
*/ |
|
259 |
function edit_post( $post_data = null ) { |
|
| 5 | 260 |
global $wpdb; |
| 0 | 261 |
|
| 9 | 262 |
if ( empty( $post_data ) ) { |
| 0 | 263 |
$post_data = &$_POST; |
| 9 | 264 |
} |
| 0 | 265 |
|
266 |
// Clear out any data in internal vars. |
|
267 |
unset( $post_data['filter'] ); |
|
268 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
269 |
$post_id = (int) $post_data['post_ID']; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
270 |
$post = get_post( $post_id ); |
| 18 | 271 |
|
| 9 | 272 |
$post_data['post_type'] = $post->post_type; |
| 0 | 273 |
$post_data['post_mime_type'] = $post->post_mime_type; |
274 |
||
| 5 | 275 |
if ( ! empty( $post_data['post_status'] ) ) { |
276 |
$post_data['post_status'] = sanitize_key( $post_data['post_status'] ); |
|
277 |
||
| 16 | 278 |
if ( 'inherit' === $post_data['post_status'] ) { |
| 5 | 279 |
unset( $post_data['post_status'] ); |
280 |
} |
|
281 |
} |
|
282 |
||
| 9 | 283 |
$ptype = get_post_type_object( $post_data['post_type'] ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
284 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
| 16 | 285 |
if ( 'page' === $post_data['post_type'] ) { |
| 9 | 286 |
wp_die( __( 'Sorry, you are not allowed to edit this page.' ) ); |
287 |
} else { |
|
288 |
wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); |
|
289 |
} |
|
| 0 | 290 |
} |
291 |
||
292 |
if ( post_type_supports( $ptype->name, 'revisions' ) ) { |
|
| 9 | 293 |
$revisions = wp_get_post_revisions( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
294 |
$post_id, |
| 9 | 295 |
array( |
296 |
'order' => 'ASC', |
|
297 |
'posts_per_page' => 1, |
|
298 |
) |
|
299 |
); |
|
300 |
$revision = current( $revisions ); |
|
| 0 | 301 |
|
| 16 | 302 |
// Check if the revisions have been upgraded. |
| 9 | 303 |
if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
304 |
_wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_id ) ); |
| 9 | 305 |
} |
| 0 | 306 |
} |
307 |
||
| 9 | 308 |
if ( isset( $post_data['visibility'] ) ) { |
| 0 | 309 |
switch ( $post_data['visibility'] ) { |
| 9 | 310 |
case 'public': |
| 0 | 311 |
$post_data['post_password'] = ''; |
312 |
break; |
|
| 9 | 313 |
case 'password': |
| 0 | 314 |
unset( $post_data['sticky'] ); |
315 |
break; |
|
| 9 | 316 |
case 'private': |
317 |
$post_data['post_status'] = 'private'; |
|
| 0 | 318 |
$post_data['post_password'] = ''; |
319 |
unset( $post_data['sticky'] ); |
|
320 |
break; |
|
321 |
} |
|
322 |
} |
|
323 |
||
| 5 | 324 |
$post_data = _wp_translate_postdata( true, $post_data ); |
| 9 | 325 |
if ( is_wp_error( $post_data ) ) { |
| 5 | 326 |
wp_die( $post_data->get_error_message() ); |
| 9 | 327 |
} |
328 |
$translated = _wp_get_allowed_postdata( $post_data ); |
|
| 5 | 329 |
|
| 16 | 330 |
// Post formats. |
| 9 | 331 |
if ( isset( $post_data['post_format'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
332 |
set_post_format( $post_id, $post_data['post_format'] ); |
| 9 | 333 |
} |
| 0 | 334 |
|
335 |
$format_meta_urls = array( 'url', 'link_url', 'quote_source_url' ); |
|
336 |
foreach ( $format_meta_urls as $format_meta_url ) { |
|
337 |
$keyed = '_format_' . $format_meta_url; |
|
| 9 | 338 |
if ( isset( $post_data[ $keyed ] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
339 |
update_post_meta( $post_id, $keyed, wp_slash( sanitize_url( wp_unslash( $post_data[ $keyed ] ) ) ) ); |
| 9 | 340 |
} |
| 0 | 341 |
} |
342 |
||
343 |
$format_keys = array( 'quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed' ); |
|
344 |
||
345 |
foreach ( $format_keys as $key ) { |
|
346 |
$keyed = '_format_' . $key; |
|
347 |
if ( isset( $post_data[ $keyed ] ) ) { |
|
| 9 | 348 |
if ( current_user_can( 'unfiltered_html' ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
349 |
update_post_meta( $post_id, $keyed, $post_data[ $keyed ] ); |
| 9 | 350 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
351 |
update_post_meta( $post_id, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) ); |
| 9 | 352 |
} |
| 0 | 353 |
} |
354 |
} |
|
355 |
||
| 5 | 356 |
if ( 'attachment' === $post_data['post_type'] && preg_match( '#^(audio|video)/#', $post_data['post_mime_type'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
357 |
$id3data = wp_get_attachment_metadata( $post_id ); |
| 5 | 358 |
if ( ! is_array( $id3data ) ) { |
359 |
$id3data = array(); |
|
360 |
} |
|
361 |
||
362 |
foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) { |
|
363 |
if ( isset( $post_data[ 'id3_' . $key ] ) ) { |
|
364 |
$id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) ); |
|
365 |
} |
|
366 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
367 |
wp_update_attachment_metadata( $post_id, $id3data ); |
| 5 | 368 |
} |
369 |
||
| 16 | 370 |
// Meta stuff. |
| 9 | 371 |
if ( isset( $post_data['meta'] ) && $post_data['meta'] ) { |
| 0 | 372 |
foreach ( $post_data['meta'] as $key => $value ) { |
| 16 | 373 |
$meta = get_post_meta_by_id( $key ); |
374 |
if ( ! $meta ) { |
|
| 9 | 375 |
continue; |
376 |
} |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
377 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
378 |
if ( (int) $meta->post_id !== $post_id ) { |
| 0 | 379 |
continue; |
| 9 | 380 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
381 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
382 |
if ( is_protected_meta( $meta->meta_key, 'post' ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
383 |
|| ! current_user_can( 'edit_post_meta', $post_id, $meta->meta_key ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
384 |
) { |
| 0 | 385 |
continue; |
| 9 | 386 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
387 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
388 |
if ( is_protected_meta( $value['key'], 'post' ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
389 |
|| ! current_user_can( 'edit_post_meta', $post_id, $value['key'] ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
390 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
continue; |
| 9 | 392 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
393 |
|
| 0 | 394 |
update_meta( $key, $value['key'], $value['value'] ); |
395 |
} |
|
396 |
} |
|
397 |
||
| 9 | 398 |
if ( isset( $post_data['deletemeta'] ) && $post_data['deletemeta'] ) { |
| 0 | 399 |
foreach ( $post_data['deletemeta'] as $key => $value ) { |
| 16 | 400 |
$meta = get_post_meta_by_id( $key ); |
401 |
if ( ! $meta ) { |
|
| 0 | 402 |
continue; |
| 9 | 403 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
404 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
405 |
if ( (int) $meta->post_id !== $post_id ) { |
| 0 | 406 |
continue; |
| 9 | 407 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
408 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
409 |
if ( is_protected_meta( $meta->meta_key, 'post' ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
410 |
|| ! current_user_can( 'delete_post_meta', $post_id, $meta->meta_key ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
411 |
) { |
| 0 | 412 |
continue; |
| 9 | 413 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
414 |
|
| 0 | 415 |
delete_meta( $key ); |
416 |
} |
|
417 |
} |
|
418 |
||
| 16 | 419 |
// Attachment stuff. |
420 |
if ( 'attachment' === $post_data['post_type'] ) { |
|
| 9 | 421 |
if ( isset( $post_data['_wp_attachment_image_alt'] ) ) { |
| 0 | 422 |
$image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] ); |
| 16 | 423 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
if ( get_post_meta( $post_id, '_wp_attachment_image_alt', true ) !== $image_alt ) { |
| 0 | 425 |
$image_alt = wp_strip_all_tags( $image_alt, true ); |
| 16 | 426 |
|
427 |
// update_post_meta() expects slashed. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
428 |
update_post_meta( $post_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); |
| 0 | 429 |
} |
430 |
} |
|
431 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
432 |
$attachment_data = isset( $post_data['attachments'][ $post_id ] ) ? $post_data['attachments'][ $post_id ] : array(); |
| 5 | 433 |
|
| 0 | 434 |
/** This filter is documented in wp-admin/includes/media.php */ |
| 9 | 435 |
$translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data ); |
| 0 | 436 |
} |
437 |
||
| 5 | 438 |
// Convert taxonomy input to term IDs, to avoid ambiguity. |
439 |
if ( isset( $post_data['tax_input'] ) ) { |
|
440 |
foreach ( (array) $post_data['tax_input'] as $taxonomy => $terms ) { |
|
| 9 | 441 |
$tax_object = get_taxonomy( $taxonomy ); |
| 5 | 442 |
|
| 9 | 443 |
if ( $tax_object && isset( $tax_object->meta_box_sanitize_cb ) ) { |
444 |
$translated['tax_input'][ $taxonomy ] = call_user_func_array( $tax_object->meta_box_sanitize_cb, array( $taxonomy, $terms ) ); |
|
| 5 | 445 |
} |
446 |
} |
|
447 |
} |
|
448 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
449 |
add_meta( $post_id ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
450 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
451 |
update_post_meta( $post_id, '_edit_last', get_current_user_id() ); |
| 0 | 452 |
|
| 9 | 453 |
$success = wp_update_post( $translated ); |
| 16 | 454 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
455 |
// If the save failed, see if we can confidence check the main fields and try again. |
| 5 | 456 |
if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) { |
457 |
$fields = array( 'post_title', 'post_content', 'post_excerpt' ); |
|
458 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
foreach ( $fields as $field ) { |
| 9 | 460 |
if ( isset( $translated[ $field ] ) ) { |
461 |
$translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] ); |
|
| 5 | 462 |
} |
463 |
} |
|
464 |
||
| 9 | 465 |
wp_update_post( $translated ); |
| 5 | 466 |
} |
| 0 | 467 |
|
| 16 | 468 |
// Now that we have an ID we can fix any attachment anchor hrefs. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
469 |
_fix_attachment_links( $post_id ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
470 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
471 |
wp_set_post_lock( $post_id ); |
| 0 | 472 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) { |
| 9 | 474 |
if ( ! empty( $post_data['sticky'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
475 |
stick_post( $post_id ); |
| 9 | 476 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
477 |
unstick_post( $post_id ); |
| 9 | 478 |
} |
| 0 | 479 |
} |
480 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
481 |
return $post_id; |
| 0 | 482 |
} |
483 |
||
484 |
/** |
|
| 19 | 485 |
* Processes the post data for the bulk editing of posts. |
| 0 | 486 |
* |
487 |
* Updates all bulk edited posts/pages, adding (but not removing) tags and |
|
488 |
* categories. Skips pages when they would be their own parent or child. |
|
489 |
* |
|
490 |
* @since 2.7.0 |
|
491 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
* |
| 19 | 494 |
* @param array|null $post_data Optional. The array of post data to process. |
495 |
* Defaults to the `$_POST` superglobal. |
|
| 0 | 496 |
* @return array |
497 |
*/ |
|
498 |
function bulk_edit_posts( $post_data = null ) { |
|
499 |
global $wpdb; |
|
500 |
||
| 9 | 501 |
if ( empty( $post_data ) ) { |
| 0 | 502 |
$post_data = &$_POST; |
| 9 | 503 |
} |
| 0 | 504 |
|
| 9 | 505 |
if ( isset( $post_data['post_type'] ) ) { |
506 |
$ptype = get_post_type_object( $post_data['post_type'] ); |
|
507 |
} else { |
|
508 |
$ptype = get_post_type_object( 'post' ); |
|
509 |
} |
|
| 0 | 510 |
|
| 9 | 511 |
if ( ! current_user_can( $ptype->cap->edit_posts ) ) { |
| 16 | 512 |
if ( 'page' === $ptype->name ) { |
| 9 | 513 |
wp_die( __( 'Sorry, you are not allowed to edit pages.' ) ); |
514 |
} else { |
|
515 |
wp_die( __( 'Sorry, you are not allowed to edit posts.' ) ); |
|
516 |
} |
|
| 0 | 517 |
} |
518 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
519 |
if ( '-1' === $post_data['_status'] ) { |
| 0 | 520 |
$post_data['post_status'] = null; |
| 9 | 521 |
unset( $post_data['post_status'] ); |
| 0 | 522 |
} else { |
523 |
$post_data['post_status'] = $post_data['_status']; |
|
524 |
} |
|
| 9 | 525 |
unset( $post_data['_status'] ); |
| 0 | 526 |
|
| 5 | 527 |
if ( ! empty( $post_data['post_status'] ) ) { |
528 |
$post_data['post_status'] = sanitize_key( $post_data['post_status'] ); |
|
529 |
||
| 16 | 530 |
if ( 'inherit' === $post_data['post_status'] ) { |
| 5 | 531 |
unset( $post_data['post_status'] ); |
532 |
} |
|
533 |
} |
|
534 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
535 |
$post_ids = array_map( 'intval', (array) $post_data['post'] ); |
| 0 | 536 |
|
537 |
$reset = array( |
|
| 9 | 538 |
'post_author', |
539 |
'post_status', |
|
540 |
'post_password', |
|
541 |
'post_parent', |
|
542 |
'page_template', |
|
543 |
'comment_status', |
|
544 |
'ping_status', |
|
545 |
'keep_private', |
|
546 |
'tax_input', |
|
547 |
'post_category', |
|
548 |
'sticky', |
|
549 |
'post_format', |
|
| 0 | 550 |
); |
551 |
||
552 |
foreach ( $reset as $field ) { |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
553 |
if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || '-1' === $post_data[ $field ] ) ) { |
| 9 | 554 |
unset( $post_data[ $field ] ); |
555 |
} |
|
| 0 | 556 |
} |
557 |
||
| 9 | 558 |
if ( isset( $post_data['post_category'] ) ) { |
559 |
if ( is_array( $post_data['post_category'] ) && ! empty( $post_data['post_category'] ) ) { |
|
| 0 | 560 |
$new_cats = array_map( 'absint', $post_data['post_category'] ); |
| 9 | 561 |
} else { |
562 |
unset( $post_data['post_category'] ); |
|
563 |
} |
|
| 0 | 564 |
} |
565 |
||
566 |
$tax_input = array(); |
|
| 9 | 567 |
if ( isset( $post_data['tax_input'] ) ) { |
| 0 | 568 |
foreach ( $post_data['tax_input'] as $tax_name => $terms ) { |
| 9 | 569 |
if ( empty( $terms ) ) { |
| 0 | 570 |
continue; |
| 9 | 571 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
572 |
|
| 0 | 573 |
if ( is_taxonomy_hierarchical( $tax_name ) ) { |
574 |
$tax_input[ $tax_name ] = array_map( 'absint', $terms ); |
|
575 |
} else { |
|
576 |
$comma = _x( ',', 'tag delimiter' ); |
|
| 9 | 577 |
if ( ',' !== $comma ) { |
| 0 | 578 |
$terms = str_replace( $comma, ',', $terms ); |
| 9 | 579 |
} |
| 0 | 580 |
$tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) ); |
581 |
} |
|
582 |
} |
|
583 |
} |
|
584 |
||
| 16 | 585 |
if ( isset( $post_data['post_parent'] ) && (int) $post_data['post_parent'] ) { |
586 |
$parent = (int) $post_data['post_parent']; |
|
| 9 | 587 |
$pages = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'" ); |
| 0 | 588 |
$children = array(); |
589 |
||
590 |
for ( $i = 0; $i < 50 && $parent > 0; $i++ ) { |
|
591 |
$children[] = $parent; |
|
592 |
||
593 |
foreach ( $pages as $page ) { |
|
| 16 | 594 |
if ( (int) $page->ID === $parent ) { |
595 |
$parent = (int) $page->post_parent; |
|
| 0 | 596 |
break; |
597 |
} |
|
598 |
} |
|
599 |
} |
|
600 |
} |
|
601 |
||
| 16 | 602 |
$updated = array(); |
603 |
$skipped = array(); |
|
604 |
$locked = array(); |
|
| 5 | 605 |
$shared_post_data = $post_data; |
606 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
607 |
foreach ( $post_ids as $post_id ) { |
| 5 | 608 |
// Start with fresh post data with each iteration. |
609 |
$post_data = $shared_post_data; |
|
610 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
611 |
$post_type_object = get_post_type_object( get_post_type( $post_id ) ); |
| 0 | 612 |
|
| 16 | 613 |
if ( ! isset( $post_type_object ) |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
614 |
|| ( isset( $children ) && in_array( $post_id, $children, true ) ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
615 |
|| ! current_user_can( 'edit_post', $post_id ) |
| 16 | 616 |
) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
617 |
$skipped[] = $post_id; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
618 |
continue; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
619 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
620 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
621 |
if ( wp_check_post_lock( $post_id ) ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
622 |
$locked[] = $post_id; |
| 0 | 623 |
continue; |
624 |
} |
|
625 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
626 |
$post = get_post( $post_id ); |
| 0 | 627 |
$tax_names = get_object_taxonomies( $post ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
628 |
|
| 0 | 629 |
foreach ( $tax_names as $tax_name ) { |
| 9 | 630 |
$taxonomy_obj = get_taxonomy( $tax_name ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
631 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
632 |
if ( ! $taxonomy_obj->show_in_quick_edit ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
633 |
continue; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
634 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
635 |
|
| 9 | 636 |
if ( isset( $tax_input[ $tax_name ] ) && current_user_can( $taxonomy_obj->cap->assign_terms ) ) { |
637 |
$new_terms = $tax_input[ $tax_name ]; |
|
638 |
} else { |
|
| 0 | 639 |
$new_terms = array(); |
| 9 | 640 |
} |
| 0 | 641 |
|
| 9 | 642 |
if ( $taxonomy_obj->hierarchical ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
643 |
$current_terms = (array) wp_get_object_terms( $post_id, $tax_name, array( 'fields' => 'ids' ) ); |
| 9 | 644 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
645 |
$current_terms = (array) wp_get_object_terms( $post_id, $tax_name, array( 'fields' => 'names' ) ); |
| 9 | 646 |
} |
| 0 | 647 |
|
| 9 | 648 |
$post_data['tax_input'][ $tax_name ] = array_merge( $current_terms, $new_terms ); |
| 0 | 649 |
} |
650 |
||
| 16 | 651 |
if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
652 |
$cats = (array) wp_get_post_categories( $post_id ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
653 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
654 |
if ( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
655 |
isset( $post_data['indeterminate_post_category'] ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
656 |
&& is_array( $post_data['indeterminate_post_category'] ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
657 |
) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
658 |
$indeterminate_post_category = $post_data['indeterminate_post_category']; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
659 |
} else { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
660 |
$indeterminate_post_category = array(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
661 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
662 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
663 |
$indeterminate_cats = array_intersect( $cats, $indeterminate_post_category ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
664 |
$determinate_cats = array_diff( $new_cats, $indeterminate_post_category ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
665 |
$post_data['post_category'] = array_unique( array_merge( $indeterminate_cats, $determinate_cats ) ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
666 |
|
| 0 | 667 |
unset( $post_data['tax_input']['category'] ); |
668 |
} |
|
669 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
670 |
$post_data['post_ID'] = $post_id; |
| 9 | 671 |
$post_data['post_type'] = $post->post_type; |
| 0 | 672 |
$post_data['post_mime_type'] = $post->post_mime_type; |
673 |
||
| 5 | 674 |
foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) { |
675 |
if ( ! isset( $post_data[ $field ] ) ) { |
|
676 |
$post_data[ $field ] = $post->$field; |
|
677 |
} |
|
678 |
} |
|
679 |
||
680 |
$post_data = _wp_translate_postdata( true, $post_data ); |
|
681 |
if ( is_wp_error( $post_data ) ) { |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
682 |
$skipped[] = $post_id; |
| 5 | 683 |
continue; |
684 |
} |
|
| 9 | 685 |
$post_data = _wp_get_allowed_postdata( $post_data ); |
| 5 | 686 |
|
| 9 | 687 |
if ( isset( $shared_post_data['post_format'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
688 |
set_post_format( $post_id, $shared_post_data['post_format'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
|
| 9 | 691 |
// Prevent wp_insert_post() from overwriting post format with the old data. |
692 |
unset( $post_data['tax_input']['post_format'] ); |
|
693 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
694 |
// Reset post date of scheduled post to be published. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
695 |
if ( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
696 |
in_array( $post->post_status, array( 'future', 'draft' ), true ) && |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
697 |
'publish' === $post_data['post_status'] |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
698 |
) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
699 |
$post_data['post_date'] = current_time( 'mysql' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
700 |
$post_data['post_date_gmt'] = ''; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
701 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
702 |
|
| 19 | 703 |
$post_id = wp_update_post( $post_data ); |
704 |
update_post_meta( $post_id, '_edit_last', get_current_user_id() ); |
|
705 |
$updated[] = $post_id; |
|
| 0 | 706 |
|
707 |
if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) { |
|
| 16 | 708 |
if ( 'sticky' === $post_data['sticky'] ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
709 |
stick_post( $post_id ); |
| 9 | 710 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
711 |
unstick_post( $post_id ); |
| 9 | 712 |
} |
| 0 | 713 |
} |
714 |
} |
|
715 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
716 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
717 |
* Fires after processing the post data for bulk edit. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
718 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
719 |
* @since 6.3.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
720 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
721 |
* @param int[] $updated An array of updated post IDs. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
722 |
* @param array $shared_post_data Associative array containing the post data. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
723 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
724 |
do_action( 'bulk_edit_posts', $updated, $shared_post_data ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
725 |
|
| 9 | 726 |
return array( |
727 |
'updated' => $updated, |
|
728 |
'skipped' => $skipped, |
|
729 |
'locked' => $locked, |
|
730 |
); |
|
| 0 | 731 |
} |
732 |
||
733 |
/** |
|
| 19 | 734 |
* Returns default post information to use when populating the "Write Post" form. |
| 0 | 735 |
* |
736 |
* @since 2.0.0 |
|
737 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
* @param string $post_type Optional. A post type string. Default 'post'. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
* @param bool $create_in_db Optional. Whether to insert the post into database. Default false. |
| 0 | 740 |
* @return WP_Post Post object containing all the default post data as attributes |
741 |
*/ |
|
742 |
function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) { |
|
743 |
$post_title = ''; |
|
| 9 | 744 |
if ( ! empty( $_REQUEST['post_title'] ) ) { |
745 |
$post_title = esc_html( wp_unslash( $_REQUEST['post_title'] ) ); |
|
746 |
} |
|
| 0 | 747 |
|
748 |
$post_content = ''; |
|
| 9 | 749 |
if ( ! empty( $_REQUEST['content'] ) ) { |
750 |
$post_content = esc_html( wp_unslash( $_REQUEST['content'] ) ); |
|
751 |
} |
|
| 0 | 752 |
|
753 |
$post_excerpt = ''; |
|
| 9 | 754 |
if ( ! empty( $_REQUEST['excerpt'] ) ) { |
755 |
$post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] ) ); |
|
756 |
} |
|
| 0 | 757 |
|
758 |
if ( $create_in_db ) { |
|
| 9 | 759 |
$post_id = wp_insert_post( |
760 |
array( |
|
761 |
'post_title' => __( 'Auto Draft' ), |
|
762 |
'post_type' => $post_type, |
|
763 |
'post_status' => 'auto-draft', |
|
| 18 | 764 |
), |
765 |
false, |
|
766 |
false |
|
| 9 | 767 |
); |
768 |
$post = get_post( $post_id ); |
|
769 |
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) { |
|
| 0 | 770 |
set_post_format( $post, get_option( 'default_post_format' ) ); |
| 9 | 771 |
} |
| 18 | 772 |
wp_after_insert_post( $post, false, null ); |
| 9 | 773 |
|
| 16 | 774 |
// Schedule auto-draft cleanup. |
| 9 | 775 |
if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) { |
776 |
wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' ); |
|
777 |
} |
|
| 0 | 778 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
779 |
$post = new stdClass(); |
| 9 | 780 |
$post->ID = 0; |
781 |
$post->post_author = ''; |
|
782 |
$post->post_date = ''; |
|
783 |
$post->post_date_gmt = ''; |
|
784 |
$post->post_password = ''; |
|
785 |
$post->post_name = ''; |
|
786 |
$post->post_type = $post_type; |
|
787 |
$post->post_status = 'draft'; |
|
788 |
$post->to_ping = ''; |
|
789 |
$post->pinged = ''; |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
$post->comment_status = get_default_comment_status( $post_type ); |
| 9 | 791 |
$post->ping_status = get_default_comment_status( $post_type, 'pingback' ); |
792 |
$post->post_pingback = get_option( 'default_pingback_flag' ); |
|
793 |
$post->post_category = get_option( 'default_category' ); |
|
794 |
$post->page_template = 'default'; |
|
795 |
$post->post_parent = 0; |
|
796 |
$post->menu_order = 0; |
|
797 |
$post = new WP_Post( $post ); |
|
| 0 | 798 |
} |
799 |
||
| 5 | 800 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
801 |
* Filters the default post content initially used in the "Write Post" form. |
| 5 | 802 |
* |
803 |
* @since 1.5.0 |
|
804 |
* |
|
805 |
* @param string $post_content Default post content. |
|
806 |
* @param WP_Post $post Post object. |
|
807 |
*/ |
|
| 9 | 808 |
$post->post_content = (string) apply_filters( 'default_content', $post_content, $post ); |
| 5 | 809 |
|
810 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
* Filters the default post title initially used in the "Write Post" form. |
| 5 | 812 |
* |
813 |
* @since 1.5.0 |
|
814 |
* |
|
815 |
* @param string $post_title Default post title. |
|
816 |
* @param WP_Post $post Post object. |
|
817 |
*/ |
|
| 9 | 818 |
$post->post_title = (string) apply_filters( 'default_title', $post_title, $post ); |
| 5 | 819 |
|
820 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
821 |
* Filters the default post excerpt initially used in the "Write Post" form. |
| 5 | 822 |
* |
823 |
* @since 1.5.0 |
|
824 |
* |
|
825 |
* @param string $post_excerpt Default post excerpt. |
|
826 |
* @param WP_Post $post Post object. |
|
827 |
*/ |
|
| 9 | 828 |
$post->post_excerpt = (string) apply_filters( 'default_excerpt', $post_excerpt, $post ); |
| 0 | 829 |
|
830 |
return $post; |
|
831 |
} |
|
832 |
||
833 |
/** |
|
| 9 | 834 |
* Determines if a post exists based on title, content, date and type. |
| 0 | 835 |
* |
836 |
* @since 2.0.0 |
|
| 9 | 837 |
* @since 5.2.0 Added the `$type` parameter. |
| 18 | 838 |
* @since 5.8.0 Added the `$status` parameter. |
| 0 | 839 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
* |
| 9 | 842 |
* @param string $title Post title. |
| 19 | 843 |
* @param string $content Optional. Post content. |
844 |
* @param string $date Optional. Post date. |
|
845 |
* @param string $type Optional. Post type. |
|
846 |
* @param string $status Optional. Post status. |
|
| 0 | 847 |
* @return int Post ID if post exists, 0 otherwise. |
848 |
*/ |
|
| 18 | 849 |
function post_exists( $title, $content = '', $date = '', $type = '', $status = '' ) { |
| 0 | 850 |
global $wpdb; |
851 |
||
| 9 | 852 |
$post_title = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) ); |
| 0 | 853 |
$post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) ); |
| 9 | 854 |
$post_date = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) ); |
855 |
$post_type = wp_unslash( sanitize_post_field( 'post_type', $type, 0, 'db' ) ); |
|
| 18 | 856 |
$post_status = wp_unslash( sanitize_post_field( 'post_status', $status, 0, 'db' ) ); |
| 0 | 857 |
|
858 |
$query = "SELECT ID FROM $wpdb->posts WHERE 1=1"; |
|
| 9 | 859 |
$args = array(); |
| 0 | 860 |
|
| 9 | 861 |
if ( ! empty( $date ) ) { |
| 0 | 862 |
$query .= ' AND post_date = %s'; |
863 |
$args[] = $post_date; |
|
864 |
} |
|
865 |
||
| 9 | 866 |
if ( ! empty( $title ) ) { |
| 0 | 867 |
$query .= ' AND post_title = %s'; |
868 |
$args[] = $post_title; |
|
869 |
} |
|
870 |
||
| 9 | 871 |
if ( ! empty( $content ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
$query .= ' AND post_content = %s'; |
| 0 | 873 |
$args[] = $post_content; |
874 |
} |
|
875 |
||
| 9 | 876 |
if ( ! empty( $type ) ) { |
877 |
$query .= ' AND post_type = %s'; |
|
878 |
$args[] = $post_type; |
|
879 |
} |
|
880 |
||
| 18 | 881 |
if ( ! empty( $status ) ) { |
882 |
$query .= ' AND post_status = %s'; |
|
883 |
$args[] = $post_status; |
|
884 |
} |
|
885 |
||
| 9 | 886 |
if ( ! empty( $args ) ) { |
887 |
return (int) $wpdb->get_var( $wpdb->prepare( $query, $args ) ); |
|
888 |
} |
|
| 0 | 889 |
|
890 |
return 0; |
|
891 |
} |
|
892 |
||
893 |
/** |
|
| 19 | 894 |
* Creates a new post from the "Write Post" form using `$_POST` information. |
| 0 | 895 |
* |
896 |
* @since 2.1.0 |
|
897 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
* @global WP_User $current_user |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
* |
| 18 | 900 |
* @return int|WP_Error Post ID on success, WP_Error on failure. |
| 0 | 901 |
*/ |
902 |
function wp_write_post() { |
|
| 9 | 903 |
if ( isset( $_POST['post_type'] ) ) { |
904 |
$ptype = get_post_type_object( $_POST['post_type'] ); |
|
905 |
} else { |
|
906 |
$ptype = get_post_type_object( 'post' ); |
|
907 |
} |
|
| 0 | 908 |
|
| 9 | 909 |
if ( ! current_user_can( $ptype->cap->edit_posts ) ) { |
| 16 | 910 |
if ( 'page' === $ptype->name ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) ); |
| 9 | 912 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) ); |
| 9 | 914 |
} |
| 0 | 915 |
} |
916 |
||
917 |
$_POST['post_mime_type'] = ''; |
|
918 |
||
919 |
// Clear out any data in internal vars. |
|
920 |
unset( $_POST['filter'] ); |
|
921 |
||
| 16 | 922 |
// Edit, don't write, if we have a post ID. |
| 9 | 923 |
if ( isset( $_POST['post_ID'] ) ) { |
| 0 | 924 |
return edit_post(); |
| 9 | 925 |
} |
| 0 | 926 |
|
| 9 | 927 |
if ( isset( $_POST['visibility'] ) ) { |
| 0 | 928 |
switch ( $_POST['visibility'] ) { |
| 9 | 929 |
case 'public': |
| 0 | 930 |
$_POST['post_password'] = ''; |
931 |
break; |
|
| 9 | 932 |
case 'password': |
| 0 | 933 |
unset( $_POST['sticky'] ); |
934 |
break; |
|
| 9 | 935 |
case 'private': |
936 |
$_POST['post_status'] = 'private'; |
|
| 0 | 937 |
$_POST['post_password'] = ''; |
938 |
unset( $_POST['sticky'] ); |
|
939 |
break; |
|
940 |
} |
|
941 |
} |
|
942 |
||
| 5 | 943 |
$translated = _wp_translate_postdata( false ); |
| 9 | 944 |
if ( is_wp_error( $translated ) ) { |
| 5 | 945 |
return $translated; |
| 9 | 946 |
} |
947 |
$translated = _wp_get_allowed_postdata( $translated ); |
|
| 5 | 948 |
|
| 0 | 949 |
// Create the post. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
950 |
$post_id = wp_insert_post( $translated ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
951 |
if ( is_wp_error( $post_id ) ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
952 |
return $post_id; |
| 9 | 953 |
} |
| 0 | 954 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
955 |
if ( empty( $post_id ) ) { |
| 0 | 956 |
return 0; |
| 9 | 957 |
} |
| 0 | 958 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
959 |
add_meta( $post_id ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
960 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
961 |
add_post_meta( $post_id, '_edit_last', $GLOBALS['current_user']->ID ); |
| 0 | 962 |
|
| 16 | 963 |
// Now that we have an ID we can fix any attachment anchor hrefs. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
964 |
_fix_attachment_links( $post_id ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
965 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
966 |
wp_set_post_lock( $post_id ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
967 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
968 |
return $post_id; |
| 0 | 969 |
} |
970 |
||
971 |
/** |
|
972 |
* Calls wp_write_post() and handles the errors. |
|
973 |
* |
|
974 |
* @since 2.0.0 |
|
| 5 | 975 |
* |
| 18 | 976 |
* @return int|void Post ID on success, void on failure. |
| 0 | 977 |
*/ |
978 |
function write_post() { |
|
979 |
$result = wp_write_post(); |
|
| 9 | 980 |
if ( is_wp_error( $result ) ) { |
| 0 | 981 |
wp_die( $result->get_error_message() ); |
| 9 | 982 |
} else { |
| 0 | 983 |
return $result; |
| 9 | 984 |
} |
| 0 | 985 |
} |
986 |
||
987 |
// |
|
| 16 | 988 |
// Post Meta. |
| 0 | 989 |
// |
990 |
||
991 |
/** |
|
| 19 | 992 |
* Adds post meta data defined in the `$_POST` superglobal for a post with given ID. |
| 0 | 993 |
* |
994 |
* @since 1.2.0 |
|
995 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
996 |
* @param int $post_id |
| 5 | 997 |
* @return int|bool |
| 0 | 998 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
999 |
function add_meta( $post_id ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1000 |
$post_id = (int) $post_id; |
| 0 | 1001 |
|
| 9 | 1002 |
$metakeyselect = isset( $_POST['metakeyselect'] ) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : ''; |
1003 |
$metakeyinput = isset( $_POST['metakeyinput'] ) ? wp_unslash( trim( $_POST['metakeyinput'] ) ) : ''; |
|
1004 |
$metavalue = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : ''; |
|
1005 |
if ( is_string( $metavalue ) ) { |
|
| 0 | 1006 |
$metavalue = trim( $metavalue ); |
| 9 | 1007 |
} |
| 0 | 1008 |
|
| 16 | 1009 |
if ( ( ( '#NONE#' !== $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) { |
| 5 | 1010 |
/* |
1011 |
* We have a key/value pair. If both the select and the input |
|
1012 |
* for the key have data, the input takes precedence. |
|
1013 |
*/ |
|
| 16 | 1014 |
if ( '#NONE#' !== $metakeyselect ) { |
| 0 | 1015 |
$metakey = $metakeyselect; |
| 9 | 1016 |
} |
| 0 | 1017 |
|
| 9 | 1018 |
if ( $metakeyinput ) { |
| 16 | 1019 |
$metakey = $metakeyinput; // Default. |
| 9 | 1020 |
} |
| 0 | 1021 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1022 |
if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_id, $metakey ) ) { |
| 0 | 1023 |
return false; |
| 9 | 1024 |
} |
| 0 | 1025 |
|
1026 |
$metakey = wp_slash( $metakey ); |
|
1027 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1028 |
return add_post_meta( $post_id, $metakey, $metavalue ); |
| 0 | 1029 |
} |
1030 |
||
1031 |
return false; |
|
| 16 | 1032 |
} |
| 0 | 1033 |
|
1034 |
/** |
|
| 19 | 1035 |
* Deletes post meta data by meta ID. |
| 0 | 1036 |
* |
1037 |
* @since 1.2.0 |
|
1038 |
* |
|
| 5 | 1039 |
* @param int $mid |
1040 |
* @return bool |
|
| 0 | 1041 |
*/ |
1042 |
function delete_meta( $mid ) { |
|
| 9 | 1043 |
return delete_metadata_by_mid( 'post', $mid ); |
| 0 | 1044 |
} |
1045 |
||
1046 |
/** |
|
| 19 | 1047 |
* Returns a list of previously defined keys. |
| 0 | 1048 |
* |
1049 |
* @since 1.2.0 |
|
1050 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
* |
| 19 | 1053 |
* @return string[] Array of meta key names. |
| 0 | 1054 |
*/ |
1055 |
function get_meta_keys() { |
|
1056 |
global $wpdb; |
|
1057 |
||
| 9 | 1058 |
$keys = $wpdb->get_col( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1059 |
"SELECT meta_key |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1060 |
FROM $wpdb->postmeta |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1061 |
GROUP BY meta_key |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1062 |
ORDER BY meta_key" |
| 9 | 1063 |
); |
| 0 | 1064 |
|
1065 |
return $keys; |
|
1066 |
} |
|
1067 |
||
1068 |
/** |
|
| 19 | 1069 |
* Returns post meta data by meta ID. |
| 0 | 1070 |
* |
1071 |
* @since 2.1.0 |
|
1072 |
* |
|
| 5 | 1073 |
* @param int $mid |
1074 |
* @return object|bool |
|
| 0 | 1075 |
*/ |
1076 |
function get_post_meta_by_id( $mid ) { |
|
1077 |
return get_metadata_by_mid( 'post', $mid ); |
|
1078 |
} |
|
1079 |
||
1080 |
/** |
|
| 19 | 1081 |
* Returns meta data for the given post ID. |
| 0 | 1082 |
* |
1083 |
* @since 1.2.0 |
|
1084 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1087 |
* @param int $post_id A post ID. |
| 19 | 1088 |
* @return array[] { |
1089 |
* Array of meta data arrays for the given post ID. |
|
1090 |
* |
|
1091 |
* @type array ...$0 { |
|
1092 |
* Associative array of meta data. |
|
1093 |
* |
|
1094 |
* @type string $meta_key Meta key. |
|
1095 |
* @type mixed $meta_value Meta value. |
|
1096 |
* @type string $meta_id Meta ID as a numeric string. |
|
1097 |
* @type string $post_id Post ID as a numeric string. |
|
1098 |
* } |
|
1099 |
* } |
|
| 0 | 1100 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1101 |
function has_meta( $post_id ) { |
| 0 | 1102 |
global $wpdb; |
1103 |
||
| 9 | 1104 |
return $wpdb->get_results( |
1105 |
$wpdb->prepare( |
|
1106 |
"SELECT meta_key, meta_value, meta_id, post_id |
|
| 0 | 1107 |
FROM $wpdb->postmeta WHERE post_id = %d |
| 9 | 1108 |
ORDER BY meta_key,meta_id", |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1109 |
$post_id |
| 9 | 1110 |
), |
1111 |
ARRAY_A |
|
1112 |
); |
|
| 0 | 1113 |
} |
1114 |
||
1115 |
/** |
|
| 19 | 1116 |
* Updates post meta data by meta ID. |
| 0 | 1117 |
* |
1118 |
* @since 1.2.0 |
|
1119 |
* |
|
| 19 | 1120 |
* @param int $meta_id Meta ID. |
1121 |
* @param string $meta_key Meta key. Expect slashed. |
|
1122 |
* @param string $meta_value Meta value. Expect slashed. |
|
| 5 | 1123 |
* @return bool |
| 0 | 1124 |
*/ |
1125 |
function update_meta( $meta_id, $meta_key, $meta_value ) { |
|
| 9 | 1126 |
$meta_key = wp_unslash( $meta_key ); |
| 0 | 1127 |
$meta_value = wp_unslash( $meta_value ); |
1128 |
||
1129 |
return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key ); |
|
1130 |
} |
|
1131 |
||
1132 |
// |
|
| 16 | 1133 |
// Private. |
| 0 | 1134 |
// |
1135 |
||
1136 |
/** |
|
| 19 | 1137 |
* Replaces hrefs of attachment anchors with up-to-date permalinks. |
| 0 | 1138 |
* |
1139 |
* @since 2.3.0 |
|
1140 |
* @access private |
|
1141 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1142 |
* @param int|WP_Post $post Post ID or post object. |
| 0 | 1143 |
* @return void|int|WP_Error Void if nothing fixed. 0 or WP_Error on update failure. The post ID on update success. |
1144 |
*/ |
|
1145 |
function _fix_attachment_links( $post ) { |
|
| 9 | 1146 |
$post = get_post( $post, ARRAY_A ); |
| 0 | 1147 |
$content = $post['post_content']; |
1148 |
||
1149 |
// Don't run if no pretty permalinks or post is not published, scheduled, or privately published. |
|
| 16 | 1150 |
if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ), true ) ) { |
| 0 | 1151 |
return; |
| 9 | 1152 |
} |
| 0 | 1153 |
|
| 16 | 1154 |
// Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero). |
| 9 | 1155 |
if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) { |
| 0 | 1156 |
return; |
| 9 | 1157 |
} |
| 0 | 1158 |
|
| 9 | 1159 |
$site_url = get_bloginfo( 'url' ); |
| 16 | 1160 |
$site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // Remove the http(s). |
| 9 | 1161 |
$replace = ''; |
| 0 | 1162 |
|
1163 |
foreach ( $link_matches[1] as $key => $value ) { |
|
| 9 | 1164 |
if ( ! strpos( $value, '?attachment_id=' ) || ! strpos( $value, 'wp-att-' ) |
1165 |
|| ! preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match ) |
|
1166 |
|| ! preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) ) { |
|
| 0 | 1167 |
continue; |
| 9 | 1168 |
} |
| 0 | 1169 |
|
| 16 | 1170 |
$quote = $url_match[1]; // The quote (single or double). |
| 0 | 1171 |
$url_id = (int) $url_match[2]; |
1172 |
$rel_id = (int) $rel_match[1]; |
|
1173 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1174 |
if ( ! $url_id || ! $rel_id || $url_id != $rel_id || ! str_contains( $url_match[0], $site_url ) ) { |
| 0 | 1175 |
continue; |
| 9 | 1176 |
} |
| 0 | 1177 |
|
| 9 | 1178 |
$link = $link_matches[0][ $key ]; |
| 0 | 1179 |
$replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link ); |
1180 |
||
1181 |
$content = str_replace( $link, $replace, $content ); |
|
1182 |
} |
|
1183 |
||
1184 |
if ( $replace ) { |
|
1185 |
$post['post_content'] = $content; |
|
1186 |
// Escape data pulled from DB. |
|
| 9 | 1187 |
$post = add_magic_quotes( $post ); |
| 0 | 1188 |
|
| 9 | 1189 |
return wp_update_post( $post ); |
| 0 | 1190 |
} |
1191 |
} |
|
1192 |
||
1193 |
/** |
|
| 19 | 1194 |
* Returns all the possible statuses for a post type. |
| 0 | 1195 |
* |
1196 |
* @since 2.5.0 |
|
1197 |
* |
|
| 16 | 1198 |
* @param string $type The post_type you want the statuses for. Default 'post'. |
1199 |
* @return string[] An array of all the statuses for the supplied post type. |
|
| 0 | 1200 |
*/ |
| 9 | 1201 |
function get_available_post_statuses( $type = 'post' ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1202 |
$statuses = wp_count_posts( $type ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1203 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1204 |
return array_keys( get_object_vars( $statuses ) ); |
| 0 | 1205 |
} |
1206 |
||
1207 |
/** |
|
| 19 | 1208 |
* Runs the query to fetch the posts for listing on the edit posts page. |
| 0 | 1209 |
* |
1210 |
* @since 2.5.0 |
|
1211 |
* |
|
| 19 | 1212 |
* @param array|false $q Optional. Array of query variables to use to build the query. |
1213 |
* Defaults to the `$_GET` superglobal. |
|
| 0 | 1214 |
* @return array |
1215 |
*/ |
|
1216 |
function wp_edit_posts_query( $q = false ) { |
|
| 9 | 1217 |
if ( false === $q ) { |
| 0 | 1218 |
$q = $_GET; |
| 9 | 1219 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1220 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1221 |
$q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1222 |
$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1223 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1224 |
$post_statuses = get_post_stati(); |
| 0 | 1225 |
|
| 16 | 1226 |
if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types(), true ) ) { |
| 0 | 1227 |
$post_type = $q['post_type']; |
| 9 | 1228 |
} else { |
| 0 | 1229 |
$post_type = 'post'; |
| 9 | 1230 |
} |
| 0 | 1231 |
|
| 9 | 1232 |
$avail_post_stati = get_available_post_statuses( $post_type ); |
1233 |
$post_status = ''; |
|
1234 |
$perm = ''; |
|
1235 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1236 |
if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_statuses, true ) ) { |
| 0 | 1237 |
$post_status = $q['post_status']; |
| 9 | 1238 |
$perm = 'readable'; |
| 0 | 1239 |
} |
1240 |
||
| 9 | 1241 |
$orderby = ''; |
1242 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
if ( isset( $q['orderby'] ) ) { |
| 0 | 1244 |
$orderby = $q['orderby']; |
| 16 | 1245 |
} elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ), true ) ) { |
| 0 | 1246 |
$orderby = 'modified'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
} |
| 0 | 1248 |
|
| 9 | 1249 |
$order = ''; |
1250 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
if ( isset( $q['order'] ) ) { |
| 0 | 1252 |
$order = $q['order']; |
| 16 | 1253 |
} elseif ( isset( $q['post_status'] ) && 'pending' === $q['post_status'] ) { |
| 0 | 1254 |
$order = 'ASC'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
} |
| 0 | 1256 |
|
| 9 | 1257 |
$per_page = "edit_{$post_type}_per_page"; |
| 0 | 1258 |
$posts_per_page = (int) get_user_option( $per_page ); |
| 9 | 1259 |
if ( empty( $posts_per_page ) || $posts_per_page < 1 ) { |
| 0 | 1260 |
$posts_per_page = 20; |
| 9 | 1261 |
} |
| 0 | 1262 |
|
| 5 | 1263 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
* Filters the number of items per page to show for a specific 'per_page' type. |
| 5 | 1265 |
* |
1266 |
* The dynamic portion of the hook name, `$post_type`, refers to the post type. |
|
1267 |
* |
|
| 18 | 1268 |
* Possible hook names include: |
1269 |
* |
|
1270 |
* - `edit_post_per_page` |
|
1271 |
* - `edit_page_per_page` |
|
1272 |
* - `edit_attachment_per_page` |
|
| 5 | 1273 |
* |
1274 |
* @since 3.0.0 |
|
1275 |
* |
|
1276 |
* @param int $posts_per_page Number of posts to display per page for the given post |
|
1277 |
* type. Default 20. |
|
1278 |
*/ |
|
1279 |
$posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page ); |
|
1280 |
||
1281 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
* Filters the number of posts displayed per page when specifically listing "posts". |
| 5 | 1283 |
* |
1284 |
* @since 2.8.0 |
|
1285 |
* |
|
1286 |
* @param int $posts_per_page Number of posts to be displayed. Default 20. |
|
1287 |
* @param string $post_type The post type. |
|
1288 |
*/ |
|
| 0 | 1289 |
$posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type ); |
1290 |
||
| 9 | 1291 |
$query = compact( 'post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page' ); |
| 0 | 1292 |
|
1293 |
// Hierarchical types require special args. |
|
| 9 | 1294 |
if ( is_post_type_hierarchical( $post_type ) && empty( $orderby ) ) { |
1295 |
$query['orderby'] = 'menu_order title'; |
|
1296 |
$query['order'] = 'asc'; |
|
1297 |
$query['posts_per_page'] = -1; |
|
| 0 | 1298 |
$query['posts_per_archive_page'] = -1; |
| 9 | 1299 |
$query['fields'] = 'id=>parent'; |
| 0 | 1300 |
} |
1301 |
||
| 9 | 1302 |
if ( ! empty( $q['show_sticky'] ) ) { |
| 0 | 1303 |
$query['post__in'] = (array) get_option( 'sticky_posts' ); |
| 9 | 1304 |
} |
| 0 | 1305 |
|
1306 |
wp( $query ); |
|
1307 |
||
1308 |
return $avail_post_stati; |
|
1309 |
} |
|
1310 |
||
1311 |
/** |
|
| 19 | 1312 |
* Returns the query variables for the current attachments request. |
| 0 | 1313 |
* |
| 5 | 1314 |
* @since 4.2.0 |
| 0 | 1315 |
* |
| 19 | 1316 |
* @param array|false $q Optional. Array of query variables to use to build the query. |
1317 |
* Defaults to the `$_GET` superglobal. |
|
| 5 | 1318 |
* @return array The parsed query vars. |
| 0 | 1319 |
*/ |
| 5 | 1320 |
function wp_edit_attachments_query_vars( $q = false ) { |
1321 |
if ( false === $q ) { |
|
| 0 | 1322 |
$q = $_GET; |
| 5 | 1323 |
} |
| 9 | 1324 |
$q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0; |
1325 |
$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; |
|
| 0 | 1326 |
$q['post_type'] = 'attachment'; |
| 9 | 1327 |
$post_type = get_post_type_object( 'attachment' ); |
1328 |
$states = 'inherit'; |
|
| 5 | 1329 |
if ( current_user_can( $post_type->cap->read_private_posts ) ) { |
| 0 | 1330 |
$states .= ',private'; |
| 5 | 1331 |
} |
| 0 | 1332 |
|
| 16 | 1333 |
$q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states; |
1334 |
$q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states; |
|
| 5 | 1335 |
|
| 0 | 1336 |
$media_per_page = (int) get_user_option( 'upload_per_page' ); |
| 5 | 1337 |
if ( empty( $media_per_page ) || $media_per_page < 1 ) { |
| 0 | 1338 |
$media_per_page = 20; |
| 5 | 1339 |
} |
1340 |
||
1341 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
* Filters the number of items to list per page when listing media items. |
| 5 | 1343 |
* |
1344 |
* @since 2.9.0 |
|
1345 |
* |
|
1346 |
* @param int $media_per_page Number of media to list. Default 20. |
|
1347 |
*/ |
|
| 0 | 1348 |
$q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page ); |
1349 |
||
1350 |
$post_mime_types = get_post_mime_types(); |
|
| 9 | 1351 |
if ( isset( $q['post_mime_type'] ) && ! array_intersect( (array) $q['post_mime_type'], array_keys( $post_mime_types ) ) ) { |
1352 |
unset( $q['post_mime_type'] ); |
|
| 5 | 1353 |
} |
| 0 | 1354 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
foreach ( array_keys( $post_mime_types ) as $type ) { |
| 16 | 1356 |
if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) { |
| 5 | 1357 |
$q['post_mime_type'] = $type; |
1358 |
break; |
|
1359 |
} |
|
1360 |
} |
|
| 0 | 1361 |
|
| 16 | 1362 |
if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) { |
| 5 | 1363 |
$q['post_parent'] = 0; |
1364 |
} |
|
| 0 | 1365 |
|
| 16 | 1366 |
if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
$q['author'] = get_current_user_id(); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
// Filter query clauses to include filenames. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
if ( isset( $q['s'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1372 |
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' ); |
|
7
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 |
|
| 5 | 1375 |
return $q; |
| 0 | 1376 |
} |
1377 |
||
| 5 | 1378 |
/** |
1379 |
* Executes a query for attachments. An array of WP_Query arguments |
|
1380 |
* can be passed in, which will override the arguments set by this function. |
|
1381 |
* |
|
1382 |
* @since 2.5.0 |
|
1383 |
* |
|
| 19 | 1384 |
* @param array|false $q Optional. Array of query variables to use to build the query. |
1385 |
* Defaults to the `$_GET` superglobal. |
|
| 5 | 1386 |
* @return array |
1387 |
*/ |
|
1388 |
function wp_edit_attachments_query( $q = false ) { |
|
1389 |
wp( wp_edit_attachments_query_vars( $q ) ); |
|
1390 |
||
| 9 | 1391 |
$post_mime_types = get_post_mime_types(); |
| 5 | 1392 |
$avail_post_mime_types = get_available_post_mime_types( 'attachment' ); |
1393 |
||
1394 |
return array( $post_mime_types, $avail_post_mime_types ); |
|
| 0 | 1395 |
} |
1396 |
||
1397 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
* Returns the list of classes to be used by a meta box. |
| 0 | 1399 |
* |
1400 |
* @since 2.5.0 |
|
1401 |
* |
|
| 9 | 1402 |
* @param string $box_id Meta box ID (used in the 'id' attribute for the meta box). |
1403 |
* @param string $screen_id The screen on which the meta box is shown. |
|
1404 |
* @return string Space-separated string of class names. |
|
| 0 | 1405 |
*/ |
| 9 | 1406 |
function postbox_classes( $box_id, $screen_id ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1407 |
if ( isset( $_GET['edit'] ) && $_GET['edit'] === $box_id ) { |
| 0 | 1408 |
$classes = array( '' ); |
| 16 | 1409 |
} elseif ( get_user_option( 'closedpostboxes_' . $screen_id ) ) { |
1410 |
$closed = get_user_option( 'closedpostboxes_' . $screen_id ); |
|
| 9 | 1411 |
if ( ! is_array( $closed ) ) { |
| 0 | 1412 |
$classes = array( '' ); |
1413 |
} else { |
|
| 16 | 1414 |
$classes = in_array( $box_id, $closed, true ) ? array( 'closed' ) : array( '' ); |
| 0 | 1415 |
} |
1416 |
} else { |
|
1417 |
$classes = array( '' ); |
|
1418 |
} |
|
1419 |
||
| 5 | 1420 |
/** |
| 9 | 1421 |
* Filters the postbox classes for a specific screen and box ID combo. |
| 5 | 1422 |
* |
| 9 | 1423 |
* The dynamic portions of the hook name, `$screen_id` and `$box_id`, refer to |
1424 |
* the screen ID and meta box ID, respectively. |
|
| 5 | 1425 |
* |
1426 |
* @since 3.2.0 |
|
1427 |
* |
|
| 9 | 1428 |
* @param string[] $classes An array of postbox classes. |
| 5 | 1429 |
*/ |
| 9 | 1430 |
$classes = apply_filters( "postbox_classes_{$screen_id}_{$box_id}", $classes ); |
| 19 | 1431 |
|
| 0 | 1432 |
return implode( ' ', $classes ); |
1433 |
} |
|
1434 |
||
1435 |
/** |
|
| 19 | 1436 |
* Returns a sample permalink based on the post name. |
| 0 | 1437 |
* |
1438 |
* @since 2.5.0 |
|
1439 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1440 |
* @param int|WP_Post $post Post ID or post object. |
| 19 | 1441 |
* @param string|null $title Optional. Title to override the post's current title |
1442 |
* when generating the post name. Default null. |
|
1443 |
* @param string|null $name Optional. Name to override the post name. Default null. |
|
| 16 | 1444 |
* @return array { |
1445 |
* Array containing the sample permalink with placeholder for the post name, and the post name. |
|
1446 |
* |
|
1447 |
* @type string $0 The permalink with placeholder for the post name. |
|
1448 |
* @type string $1 The post name. |
|
1449 |
* } |
|
| 0 | 1450 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1451 |
function get_sample_permalink( $post, $title = null, $name = null ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1452 |
$post = get_post( $post ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1453 |
|
| 9 | 1454 |
if ( ! $post ) { |
| 0 | 1455 |
return array( '', '' ); |
| 9 | 1456 |
} |
| 0 | 1457 |
|
| 9 | 1458 |
$ptype = get_post_type_object( $post->post_type ); |
| 0 | 1459 |
|
1460 |
$original_status = $post->post_status; |
|
| 9 | 1461 |
$original_date = $post->post_date; |
1462 |
$original_name = $post->post_name; |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1463 |
$original_filter = $post->filter; |
| 0 | 1464 |
|
| 18 | 1465 |
// Hack: get_permalink() would return plain permalink for drafts, so we will fake that our post is published. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1466 |
if ( in_array( $post->post_status, array( 'auto-draft', 'draft', 'pending', 'future' ), true ) ) { |
| 0 | 1467 |
$post->post_status = 'publish'; |
| 9 | 1468 |
$post->post_name = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID ); |
| 0 | 1469 |
} |
1470 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1471 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1472 |
* If the user wants to set a new name -- override the current one. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1473 |
* Note: if empty name is supplied -- use the title instead, see #6072. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1474 |
*/ |
| 9 | 1475 |
if ( ! is_null( $name ) ) { |
1476 |
$post->post_name = sanitize_title( $name ? $name : $title, $post->ID ); |
|
1477 |
} |
|
| 0 | 1478 |
|
| 9 | 1479 |
$post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent ); |
| 0 | 1480 |
|
1481 |
$post->filter = 'sample'; |
|
1482 |
||
| 9 | 1483 |
$permalink = get_permalink( $post, true ); |
| 0 | 1484 |
|
| 16 | 1485 |
// Replace custom post_type token with generic pagename token for ease of use. |
| 9 | 1486 |
$permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink ); |
| 0 | 1487 |
|
| 16 | 1488 |
// Handle page hierarchy. |
| 0 | 1489 |
if ( $ptype->hierarchical ) { |
| 9 | 1490 |
$uri = get_page_uri( $post ); |
| 5 | 1491 |
if ( $uri ) { |
| 9 | 1492 |
$uri = untrailingslashit( $uri ); |
| 5 | 1493 |
$uri = strrev( stristr( strrev( $uri ), '/' ) ); |
| 9 | 1494 |
$uri = untrailingslashit( $uri ); |
| 5 | 1495 |
} |
1496 |
||
1497 |
/** This filter is documented in wp-admin/edit-tag-form.php */ |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
$uri = apply_filters( 'editable_slug', $uri, $post ); |
| 9 | 1499 |
if ( ! empty( $uri ) ) { |
| 0 | 1500 |
$uri .= '/'; |
| 9 | 1501 |
} |
1502 |
$permalink = str_replace( '%pagename%', "{$uri}%pagename%", $permalink ); |
|
| 0 | 1503 |
} |
1504 |
||
| 5 | 1505 |
/** This filter is documented in wp-admin/edit-tag-form.php */ |
| 9 | 1506 |
$permalink = array( $permalink, apply_filters( 'editable_slug', $post->post_name, $post ) ); |
| 0 | 1507 |
$post->post_status = $original_status; |
| 9 | 1508 |
$post->post_date = $original_date; |
1509 |
$post->post_name = $original_name; |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1510 |
$post->filter = $original_filter; |
| 0 | 1511 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1512 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1513 |
* Filters the sample permalink. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1514 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
* @since 4.4.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
* |
| 16 | 1517 |
* @param array $permalink { |
1518 |
* Array containing the sample permalink with placeholder for the post name, and the post name. |
|
1519 |
* |
|
1520 |
* @type string $0 The permalink with placeholder for the post name. |
|
1521 |
* @type string $1 The post name. |
|
1522 |
* } |
|
| 19 | 1523 |
* @param int $post_id Post ID. |
1524 |
* @param string $title Post title. |
|
1525 |
* @param string $name Post name (slug). |
|
1526 |
* @param WP_Post $post Post object. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1528 |
return apply_filters( 'get_sample_permalink', $permalink, $post->ID, $title, $name, $post ); |
| 0 | 1529 |
} |
1530 |
||
1531 |
/** |
|
1532 |
* Returns the HTML of the sample permalink slug editor. |
|
1533 |
* |
|
1534 |
* @since 2.5.0 |
|
1535 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1536 |
* @param int|WP_Post $post Post ID or post object. |
| 19 | 1537 |
* @param string|null $new_title Optional. New title. Default null. |
1538 |
* @param string|null $new_slug Optional. New slug. Default null. |
|
| 0 | 1539 |
* @return string The HTML of the sample permalink slug editor. |
1540 |
*/ |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1541 |
function get_sample_permalink_html( $post, $new_title = null, $new_slug = null ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1542 |
$post = get_post( $post ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1543 |
|
| 9 | 1544 |
if ( ! $post ) { |
| 0 | 1545 |
return ''; |
| 9 | 1546 |
} |
| 0 | 1547 |
|
| 9 | 1548 |
list($permalink, $post_name) = get_sample_permalink( $post->ID, $new_title, $new_slug ); |
| 0 | 1549 |
|
| 9 | 1550 |
$view_link = false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1551 |
$preview_target = ''; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1552 |
|
| 5 | 1553 |
if ( current_user_can( 'read_post', $post->ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1554 |
if ( 'draft' === $post->post_status || empty( $post->post_name ) ) { |
| 9 | 1555 |
$view_link = get_preview_post_link( $post ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1556 |
$preview_target = " target='wp-preview-{$post->ID}'"; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1557 |
} else { |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) { |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
$view_link = get_permalink( $post ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1560 |
} else { |
| 16 | 1561 |
// Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1562 |
$view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1564 |
} |
| 5 | 1565 |
} |
1566 |
||
| 16 | 1567 |
// Permalinks without a post/page name placeholder don't have anything to edit. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1568 |
if ( ! str_contains( $permalink, '%postname%' ) && ! str_contains( $permalink, '%pagename%' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n"; |
| 0 | 1570 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1571 |
if ( false !== $view_link ) { |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
$display_link = urldecode( $view_link ); |
| 9 | 1573 |
$return .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . esc_html( $display_link ) . "</a>\n"; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
} else { |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
$return .= '<span id="sample-permalink">' . $permalink . "</span>\n"; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1576 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1577 |
|
| 16 | 1578 |
// Encourage a pretty permalink setting. |
1579 |
if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1580 |
&& ! ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post->ID ) |
| 16 | 1581 |
) { |
| 19 | 1582 |
$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small">' . __( 'Change Permalink Structure' ) . "</a></span>\n"; |
| 5 | 1583 |
} |
1584 |
} else { |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1585 |
if ( mb_strlen( $post_name ) > 34 ) { |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1586 |
$post_name_abridged = mb_substr( $post_name, 0, 16 ) . '…' . mb_substr( $post_name, -16 ); |
| 5 | 1587 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
$post_name_abridged = $post_name; |
| 5 | 1589 |
} |
| 0 | 1590 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
$post_name_html = '<span id="editable-post-name">' . esc_html( $post_name_abridged ) . '</span>'; |
| 9 | 1592 |
$display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, esc_html( urldecode( $permalink ) ) ); |
| 0 | 1593 |
|
| 9 | 1594 |
$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n"; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
$return .= '<span id="sample-permalink"><a href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $display_link . "</a></span>\n"; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
$return .= '‎'; // Fix bi-directional text display defect in RTL languages. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
$return .= '<span id="edit-slug-buttons"><button type="button" class="edit-slug button button-small hide-if-no-js" aria-label="' . __( 'Edit permalink' ) . '">' . __( 'Edit' ) . "</button></span>\n"; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1598 |
$return .= '<span id="editable-post-name-full">' . esc_html( $post_name ) . "</span>\n"; |
| 0 | 1599 |
} |
1600 |
||
| 5 | 1601 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1602 |
* Filters the sample permalink HTML markup. |
| 5 | 1603 |
* |
1604 |
* @since 2.9.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1605 |
* @since 4.4.0 Added `$post` parameter. |
| 5 | 1606 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1607 |
* @param string $return Sample permalink HTML markup. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1608 |
* @param int $post_id Post ID. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1609 |
* @param string|null $new_title New sample permalink title. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1610 |
* @param string|null $new_slug New sample permalink slug. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1611 |
* @param WP_Post $post Post object. |
| 5 | 1612 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1613 |
$return = apply_filters( 'get_sample_permalink_html', $return, $post->ID, $new_title, $new_slug, $post ); |
| 0 | 1614 |
|
1615 |
return $return; |
|
1616 |
} |
|
1617 |
||
1618 |
/** |
|
| 16 | 1619 |
* Returns HTML for the post thumbnail meta box. |
| 0 | 1620 |
* |
1621 |
* @since 2.9.0 |
|
1622 |
* |
|
| 19 | 1623 |
* @param int|null $thumbnail_id Optional. Thumbnail attachment ID. Default null. |
1624 |
* @param int|WP_Post|null $post Optional. The post ID or object associated |
|
1625 |
* with the thumbnail. Defaults to global $post. |
|
| 16 | 1626 |
* @return string The post thumbnail HTML. |
| 0 | 1627 |
*/ |
1628 |
function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
$_wp_additional_image_sizes = wp_get_additional_image_sizes(); |
| 0 | 1630 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
$post = get_post( $post ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1632 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1633 |
$set_thumbnail_link = '<p class="hide-if-no-js"><a href="%s" id="set-post-thumbnail"%s class="thickbox">%s</a></p>'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1634 |
$upload_iframe_src = get_upload_iframe_src( 'image', $post->ID ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1635 |
|
| 9 | 1636 |
$content = sprintf( |
1637 |
$set_thumbnail_link, |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
esc_url( $upload_iframe_src ), |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1639 |
'', // Empty when there's no featured image set, `aria-describedby` attribute otherwise. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1640 |
esc_html( $post_type_object->labels->set_featured_image ) |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1641 |
); |
| 0 | 1642 |
|
1643 |
if ( $thumbnail_id && get_post( $thumbnail_id ) ) { |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1644 |
$size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1645 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1646 |
/** |
| 16 | 1647 |
* Filters the size used to display the post thumbnail image in the 'Featured image' meta box. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1648 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1649 |
* Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1650 |
* image size is registered, which differs from the 'thumbnail' image size |
| 18 | 1651 |
* managed via the Settings > Media screen. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1652 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1653 |
* @since 4.4.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1654 |
* |
| 18 | 1655 |
* @param string|int[] $size Requested image size. Can be any registered image size name, or |
1656 |
* an array of width and height values in pixels (in that order). |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1657 |
* @param int $thumbnail_id Post thumbnail attachment ID. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1658 |
* @param WP_Post $post The post object associated with the thumbnail. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1659 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1660 |
$size = apply_filters( 'admin_post_thumbnail_size', $size, $thumbnail_id, $post ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1661 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1662 |
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, $size ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1663 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1664 |
if ( ! empty( $thumbnail_html ) ) { |
| 9 | 1665 |
$content = sprintf( |
1666 |
$set_thumbnail_link, |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1667 |
esc_url( $upload_iframe_src ), |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1668 |
' aria-describedby="set-post-thumbnail-desc"', |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1669 |
$thumbnail_html |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1670 |
); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1671 |
$content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . __( 'Click the image to edit or update' ) . '</p>'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1672 |
$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>'; |
| 0 | 1673 |
} |
1674 |
} |
|
1675 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1676 |
$content .= '<input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
|
| 5 | 1678 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1679 |
* Filters the admin post thumbnail HTML markup to return. |
| 5 | 1680 |
* |
1681 |
* @since 2.9.0 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1682 |
* @since 3.5.0 Added the `$post_id` parameter. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1683 |
* @since 4.6.0 Added the `$thumbnail_id` parameter. |
| 5 | 1684 |
* |
| 9 | 1685 |
* @param string $content Admin post thumbnail HTML markup. |
1686 |
* @param int $post_id Post ID. |
|
1687 |
* @param int|null $thumbnail_id Thumbnail attachment ID, or null if there isn't one. |
|
| 5 | 1688 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1689 |
return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID, $thumbnail_id ); |
| 0 | 1690 |
} |
1691 |
||
1692 |
/** |
|
| 19 | 1693 |
* Determines whether the post is currently being edited by another user. |
| 0 | 1694 |
* |
1695 |
* @since 2.5.0 |
|
1696 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1697 |
* @param int|WP_Post $post ID or object of the post to check for editing. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1698 |
* @return int|false ID of the user with lock. False if the post does not exist, post is not locked, |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
* the user with lock does not exist, or the post is locked by current user. |
| 0 | 1700 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1701 |
function wp_check_post_lock( $post ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1702 |
$post = get_post( $post ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1703 |
|
| 16 | 1704 |
if ( ! $post ) { |
| 0 | 1705 |
return false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1706 |
} |
| 0 | 1707 |
|
| 16 | 1708 |
$lock = get_post_meta( $post->ID, '_edit_lock', true ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1709 |
|
| 16 | 1710 |
if ( ! $lock ) { |
| 0 | 1711 |
return false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1712 |
} |
| 0 | 1713 |
|
1714 |
$lock = explode( ':', $lock ); |
|
1715 |
$time = $lock[0]; |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1716 |
$user = isset( $lock[1] ) ? (int) $lock[1] : (int) get_post_meta( $post->ID, '_edit_last', true ); |
| 0 | 1717 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1718 |
if ( ! get_userdata( $user ) ) { |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1719 |
return false; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1720 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1721 |
|
| 5 | 1722 |
/** This filter is documented in wp-admin/includes/ajax-actions.php */ |
1723 |
$time_window = apply_filters( 'wp_check_post_lock_window', 150 ); |
|
| 0 | 1724 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1725 |
if ( $time && $time > time() - $time_window && get_current_user_id() !== $user ) { |
| 0 | 1726 |
return $user; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1727 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1728 |
|
| 0 | 1729 |
return false; |
1730 |
} |
|
1731 |
||
1732 |
/** |
|
| 19 | 1733 |
* Marks the post as currently being edited by the current user. |
| 0 | 1734 |
* |
1735 |
* @since 2.5.0 |
|
1736 |
* |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1737 |
* @param int|WP_Post $post ID or object of the post being edited. |
| 19 | 1738 |
* @return array|false { |
1739 |
* Array of the lock time and user ID. False if the post does not exist, or there |
|
1740 |
* is no current user. |
|
1741 |
* |
|
1742 |
* @type int $0 The current time as a Unix timestamp. |
|
1743 |
* @type int $1 The ID of the current user. |
|
1744 |
* } |
|
| 0 | 1745 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1746 |
function wp_set_post_lock( $post ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1747 |
$post = get_post( $post ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1748 |
|
| 16 | 1749 |
if ( ! $post ) { |
| 0 | 1750 |
return false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1751 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
|
| 16 | 1753 |
$user_id = get_current_user_id(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1754 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1755 |
if ( 0 === $user_id ) { |
| 0 | 1756 |
return false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1757 |
} |
| 0 | 1758 |
|
| 9 | 1759 |
$now = time(); |
| 0 | 1760 |
$lock = "$now:$user_id"; |
1761 |
||
1762 |
update_post_meta( $post->ID, '_edit_lock', $lock ); |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1763 |
|
| 0 | 1764 |
return array( $now, $user_id ); |
1765 |
} |
|
1766 |
||
1767 |
/** |
|
1768 |
* Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post. |
|
1769 |
* |
|
1770 |
* @since 2.8.5 |
|
1771 |
*/ |
|
1772 |
function _admin_notice_post_locked() { |
|
| 16 | 1773 |
$post = get_post(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1774 |
|
| 16 | 1775 |
if ( ! $post ) { |
| 0 | 1776 |
return; |
| 9 | 1777 |
} |
| 0 | 1778 |
|
| 16 | 1779 |
$user = null; |
1780 |
$user_id = wp_check_post_lock( $post->ID ); |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1781 |
|
| 16 | 1782 |
if ( $user_id ) { |
| 0 | 1783 |
$user = get_userdata( $user_id ); |
| 9 | 1784 |
} |
| 0 | 1785 |
|
1786 |
if ( $user ) { |
|
| 5 | 1787 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1788 |
* Filters whether to show the post locked dialog. |
| 5 | 1789 |
* |
| 16 | 1790 |
* Returning false from the filter will prevent the dialog from being displayed. |
| 5 | 1791 |
* |
1792 |
* @since 3.6.0 |
|
1793 |
* |
|
| 16 | 1794 |
* @param bool $display Whether to display the dialog. Default true. |
1795 |
* @param WP_Post $post Post object. |
|
1796 |
* @param WP_User $user The user with the lock for the post. |
|
| 5 | 1797 |
*/ |
| 9 | 1798 |
if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) { |
| 0 | 1799 |
return; |
| 9 | 1800 |
} |
| 0 | 1801 |
|
1802 |
$locked = true; |
|
1803 |
} else { |
|
1804 |
$locked = false; |
|
1805 |
} |
|
1806 |
||
| 16 | 1807 |
$sendback = wp_get_referer(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1808 |
if ( $locked && $sendback && ! str_contains( $sendback, 'post.php' ) && ! str_contains( $sendback, 'post-new.php' ) ) { |
| 0 | 1809 |
|
| 9 | 1810 |
$sendback_text = __( 'Go back' ); |
| 0 | 1811 |
} else { |
1812 |
$sendback = admin_url( 'edit.php' ); |
|
1813 |
||
| 16 | 1814 |
if ( 'post' !== $post->post_type ) { |
| 0 | 1815 |
$sendback = add_query_arg( 'post_type', $post->post_type, $sendback ); |
| 9 | 1816 |
} |
| 0 | 1817 |
|
1818 |
$sendback_text = get_post_type_object( $post->post_type )->labels->all_items; |
|
1819 |
} |
|
1820 |
||
1821 |
$hidden = $locked ? '' : ' hidden'; |
|
1822 |
||
1823 |
?> |
|
1824 |
<div id="post-lock-dialog" class="notification-dialog-wrap<?php echo $hidden; ?>"> |
|
1825 |
<div class="notification-dialog-background"></div> |
|
1826 |
<div class="notification-dialog"> |
|
1827 |
<?php |
|
1828 |
||
1829 |
if ( $locked ) { |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1830 |
$query_args = array(); |
| 0 | 1831 |
if ( get_post_type_object( $post->post_type )->public ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1832 |
if ( 'publish' === $post->post_status || $user->ID !== (int) $post->post_author ) { |
| 16 | 1833 |
// Latest content is in autosave. |
| 9 | 1834 |
$nonce = wp_create_nonce( 'post_preview_' . $post->ID ); |
1835 |
$query_args['preview_id'] = $post->ID; |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1836 |
$query_args['preview_nonce'] = $nonce; |
| 0 | 1837 |
} |
1838 |
} |
|
1839 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1840 |
$preview_link = get_preview_post_link( $post->ID, $query_args ); |
| 5 | 1841 |
|
1842 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1843 |
* Filters whether to allow the post lock to be overridden. |
| 5 | 1844 |
* |
| 16 | 1845 |
* Returning false from the filter will disable the ability |
| 5 | 1846 |
* to override the post lock. |
1847 |
* |
|
1848 |
* @since 3.6.0 |
|
1849 |
* |
|
| 16 | 1850 |
* @param bool $override Whether to allow the post lock to be overridden. Default true. |
| 5 | 1851 |
* @param WP_Post $post Post object. |
| 16 | 1852 |
* @param WP_User $user The user with the lock for the post. |
| 5 | 1853 |
*/ |
| 0 | 1854 |
$override = apply_filters( 'override_post_lock', true, $post, $user ); |
1855 |
$tab_last = $override ? '' : ' wp-tab-last'; |
|
1856 |
||
1857 |
?> |
|
1858 |
<div class="post-locked-message"> |
|
1859 |
<div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div> |
|
1860 |
<p class="currently-editing wp-tab-first" tabindex="0"> |
|
1861 |
<?php |
|
| 9 | 1862 |
if ( $override ) { |
| 16 | 1863 |
/* translators: %s: User's display name. */ |
| 18 | 1864 |
printf( __( '%s is currently editing this post. Do you want to take over?' ), esc_html( $user->display_name ) ); |
| 9 | 1865 |
} else { |
| 16 | 1866 |
/* translators: %s: User's display name. */ |
| 18 | 1867 |
printf( __( '%s is currently editing this post.' ), esc_html( $user->display_name ) ); |
| 9 | 1868 |
} |
| 0 | 1869 |
?> |
1870 |
</p> |
|
| 5 | 1871 |
<?php |
1872 |
/** |
|
1873 |
* Fires inside the post locked dialog before the buttons are displayed. |
|
1874 |
* |
|
1875 |
* @since 3.6.0 |
|
| 16 | 1876 |
* @since 5.4.0 The $user parameter was added. |
| 5 | 1877 |
* |
1878 |
* @param WP_Post $post Post object. |
|
| 16 | 1879 |
* @param WP_User $user The user with the lock for the post. |
| 5 | 1880 |
*/ |
| 16 | 1881 |
do_action( 'post_locked_dialog', $post, $user ); |
| 5 | 1882 |
?> |
| 0 | 1883 |
<p> |
1884 |
<a class="button" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a> |
|
1885 |
<?php if ( $preview_link ) { ?> |
|
| 9 | 1886 |
<a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e( 'Preview' ); ?></a> |
1887 |
<?php |
|
| 0 | 1888 |
} |
1889 |
||
| 16 | 1890 |
// Allow plugins to prevent some users overriding the post lock. |
| 0 | 1891 |
if ( $override ) { |
1892 |
?> |
|
| 9 | 1893 |
<a class="button button-primary wp-tab-last" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', wp_nonce_url( get_edit_post_link( $post->ID, 'url' ), 'lock-post_' . $post->ID ) ) ); ?>"><?php _e( 'Take over' ); ?></a> |
| 0 | 1894 |
<?php |
1895 |
} |
|
1896 |
||
1897 |
?> |
|
1898 |
</p> |
|
1899 |
</div> |
|
1900 |
<?php |
|
1901 |
} else { |
|
1902 |
?> |
|
1903 |
<div class="post-taken-over"> |
|
1904 |
<div class="post-locked-avatar"></div> |
|
1905 |
<p class="wp-tab-first" tabindex="0"> |
|
| 5 | 1906 |
<span class="currently-editing"></span><br /> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1907 |
<span class="locked-saving hidden"><img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" width="16" height="16" alt="" /> <?php _e( 'Saving revision…' ); ?></span> |
| 9 | 1908 |
<span class="locked-saved hidden"><?php _e( 'Your latest changes were saved as a revision.' ); ?></span> |
| 0 | 1909 |
</p> |
| 5 | 1910 |
<?php |
1911 |
/** |
|
1912 |
* Fires inside the dialog displayed when a user has lost the post lock. |
|
1913 |
* |
|
1914 |
* @since 3.6.0 |
|
1915 |
* |
|
1916 |
* @param WP_Post $post Post object. |
|
1917 |
*/ |
|
1918 |
do_action( 'post_lock_lost_dialog', $post ); |
|
1919 |
?> |
|
| 0 | 1920 |
<p><a class="button button-primary wp-tab-last" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a></p> |
1921 |
</div> |
|
1922 |
<?php |
|
1923 |
} |
|
1924 |
||
1925 |
?> |
|
1926 |
</div> |
|
1927 |
</div> |
|
1928 |
<?php |
|
1929 |
} |
|
1930 |
||
1931 |
/** |
|
| 19 | 1932 |
* Creates autosave data for the specified post from `$_POST` data. |
| 0 | 1933 |
* |
1934 |
* @since 2.6.0 |
|
1935 |
* |
|
| 19 | 1936 |
* @param array|int $post_data Associative array containing the post data, or integer post ID. |
1937 |
* If a numeric post ID is provided, will use the `$_POST` superglobal. |
|
| 16 | 1938 |
* @return int|WP_Error The autosave revision ID. WP_Error or 0 on error. |
| 0 | 1939 |
*/ |
| 5 | 1940 |
function wp_create_post_autosave( $post_data ) { |
1941 |
if ( is_numeric( $post_data ) ) { |
|
| 9 | 1942 |
$post_id = $post_data; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1943 |
$post_data = $_POST; |
| 5 | 1944 |
} else { |
1945 |
$post_id = (int) $post_data['post_ID']; |
|
1946 |
} |
|
1947 |
||
1948 |
$post_data = _wp_translate_postdata( true, $post_data ); |
|
| 9 | 1949 |
if ( is_wp_error( $post_data ) ) { |
| 5 | 1950 |
return $post_data; |
| 9 | 1951 |
} |
1952 |
$post_data = _wp_get_allowed_postdata( $post_data ); |
|
| 0 | 1953 |
|
1954 |
$post_author = get_current_user_id(); |
|
1955 |
||
1956 |
// Store one autosave per author. If there is already an autosave, overwrite it. |
|
| 16 | 1957 |
$old_autosave = wp_get_post_autosave( $post_id, $post_author ); |
1958 |
if ( $old_autosave ) { |
|
| 9 | 1959 |
$new_autosave = _wp_post_revision_data( $post_data, true ); |
1960 |
$new_autosave['ID'] = $old_autosave->ID; |
|
| 0 | 1961 |
$new_autosave['post_author'] = $post_author; |
1962 |
||
| 16 | 1963 |
$post = get_post( $post_id ); |
1964 |
||
| 5 | 1965 |
// If the new autosave has the same content as the post, delete the autosave. |
| 0 | 1966 |
$autosave_is_different = false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1967 |
foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) { |
| 16 | 1968 |
if ( normalize_whitespace( $new_autosave[ $field ] ) !== normalize_whitespace( $post->$field ) ) { |
| 0 | 1969 |
$autosave_is_different = true; |
1970 |
break; |
|
1971 |
} |
|
1972 |
} |
|
1973 |
||
1974 |
if ( ! $autosave_is_different ) { |
|
1975 |
wp_delete_post_revision( $old_autosave->ID ); |
|
| 5 | 1976 |
return 0; |
| 0 | 1977 |
} |
1978 |
||
| 5 | 1979 |
/** |
1980 |
* Fires before an autosave is stored. |
|
1981 |
* |
|
1982 |
* @since 4.1.0 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1983 |
* @since 6.4.0 The `$is_update` parameter was added to indicate if the autosave is being updated or was newly created. |
| 5 | 1984 |
* |
1985 |
* @param array $new_autosave Post array - the autosave that is about to be saved. |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1986 |
* @param bool $is_update Whether this is an existing autosave. |
| 5 | 1987 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1988 |
do_action( 'wp_creating_autosave', $new_autosave, true ); |
| 0 | 1989 |
return wp_update_post( $new_autosave ); |
1990 |
} |
|
1991 |
||
1992 |
// _wp_put_post_revision() expects unescaped. |
|
| 5 | 1993 |
$post_data = wp_unslash( $post_data ); |
| 0 | 1994 |
|
| 16 | 1995 |
// Otherwise create the new autosave as a special post revision. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1996 |
$revision = _wp_put_post_revision( $post_data, true ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1997 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1998 |
if ( ! is_wp_error( $revision ) && 0 !== $revision ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1999 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2000 |
/** This action is documented in wp-admin/includes/post.php */ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2001 |
do_action( 'wp_creating_autosave', get_post( $revision, ARRAY_A ), false ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2002 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2003 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2004 |
return $revision; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2005 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2006 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2007 |
/** |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2008 |
* Autosave the revisioned meta fields. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2009 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2010 |
* Iterates through the revisioned meta fields and checks each to see if they are set, |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2011 |
* and have a changed value. If so, the meta value is saved and attached to the autosave. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2012 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2013 |
* @since 6.4.0 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2014 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2015 |
* @param array $new_autosave The new post data being autosaved. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2016 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2017 |
function wp_autosave_post_revisioned_meta_fields( $new_autosave ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2018 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2019 |
* The post data arrives as either $_POST['data']['wp_autosave'] or the $_POST |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2020 |
* itself. This sets $posted_data to the correct variable. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2021 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2022 |
* Ignoring sanitization to avoid altering meta. Ignoring the nonce check because |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2023 |
* this is hooked on inner core hooks where a valid nonce was already checked. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2024 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2025 |
$posted_data = isset( $_POST['data']['wp_autosave'] ) ? $_POST['data']['wp_autosave'] : $_POST; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2026 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2027 |
$post_type = get_post_type( $new_autosave['post_parent'] ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2028 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2029 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2030 |
* Go thru the revisioned meta keys and save them as part of the autosave, if |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2031 |
* the meta key is part of the posted data, the meta value is not blank and |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2032 |
* the the meta value has changes from the last autosaved value. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2033 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2034 |
foreach ( wp_post_revision_meta_keys( $post_type ) as $meta_key ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2035 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2036 |
if ( |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2037 |
isset( $posted_data[ $meta_key ] ) && |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2038 |
get_post_meta( $new_autosave['ID'], $meta_key, true ) !== wp_unslash( $posted_data[ $meta_key ] ) |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2039 |
) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2040 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2041 |
* Use the underlying delete_metadata() and add_metadata() functions |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2042 |
* vs delete_post_meta() and add_post_meta() to make sure we're working |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2043 |
* with the actual revision meta. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2044 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2045 |
delete_metadata( 'post', $new_autosave['ID'], $meta_key ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2046 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2047 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2048 |
* One last check to ensure meta value not empty(). |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2049 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2050 |
if ( ! empty( $posted_data[ $meta_key ] ) ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2051 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2052 |
* Add the revisions meta data to the autosave. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2053 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2054 |
add_metadata( 'post', $new_autosave['ID'], $meta_key, $posted_data[ $meta_key ] ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2055 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2056 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2057 |
} |
| 0 | 2058 |
} |
2059 |
||
2060 |
/** |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
* Saves a draft or manually autosaves for the purpose of showing a post preview. |
| 0 | 2062 |
* |
2063 |
* @since 2.7.0 |
|
2064 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2065 |
* @return string URL to redirect to show the preview. |
| 0 | 2066 |
*/ |
2067 |
function post_preview() { |
|
2068 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2069 |
$post_id = (int) $_POST['post_ID']; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2070 |
$_POST['ID'] = $post_id; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2071 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2072 |
$post = get_post( $post_id ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2073 |
|
| 16 | 2074 |
if ( ! $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2075 |
wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); |
| 5 | 2076 |
} |
| 0 | 2077 |
|
| 5 | 2078 |
if ( ! current_user_can( 'edit_post', $post->ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2079 |
wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); |
| 5 | 2080 |
} |
| 0 | 2081 |
|
| 5 | 2082 |
$is_autosave = false; |
2083 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2084 |
if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() === (int) $post->post_author |
| 16 | 2085 |
&& ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status ) |
2086 |
) { |
|
| 5 | 2087 |
$saved_post_id = edit_post(); |
2088 |
} else { |
|
2089 |
$is_autosave = true; |
|
| 0 | 2090 |
|
| 16 | 2091 |
if ( isset( $_POST['post_status'] ) && 'auto-draft' === $_POST['post_status'] ) { |
| 5 | 2092 |
$_POST['post_status'] = 'draft'; |
| 9 | 2093 |
} |
| 0 | 2094 |
|
| 5 | 2095 |
$saved_post_id = wp_create_post_autosave( $post->ID ); |
2096 |
} |
|
2097 |
||
| 9 | 2098 |
if ( is_wp_error( $saved_post_id ) ) { |
| 5 | 2099 |
wp_die( $saved_post_id->get_error_message() ); |
| 9 | 2100 |
} |
| 0 | 2101 |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2102 |
$query_args = array(); |
| 5 | 2103 |
|
2104 |
if ( $is_autosave && $saved_post_id ) { |
|
| 9 | 2105 |
$query_args['preview_id'] = $post->ID; |
| 5 | 2106 |
$query_args['preview_nonce'] = wp_create_nonce( 'post_preview_' . $post->ID ); |
2107 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2108 |
if ( isset( $_POST['post_format'] ) ) { |
| 5 | 2109 |
$query_args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2112 |
if ( isset( $_POST['_thumbnail_id'] ) ) { |
| 18 | 2113 |
$query_args['_thumbnail_id'] = ( (int) $_POST['_thumbnail_id'] <= 0 ) ? '-1' : (int) $_POST['_thumbnail_id']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2114 |
} |
| 0 | 2115 |
} |
2116 |
||
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2117 |
return get_preview_post_link( $post, $query_args ); |
| 5 | 2118 |
} |
2119 |
||
2120 |
/** |
|
| 19 | 2121 |
* Saves a post submitted with XHR. |
| 5 | 2122 |
* |
2123 |
* Intended for use with heartbeat and autosave.js |
|
2124 |
* |
|
2125 |
* @since 3.9.0 |
|
2126 |
* |
|
2127 |
* @param array $post_data Associative array of the submitted post data. |
|
2128 |
* @return mixed The value 0 or WP_Error on failure. The saved post ID on success. |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2129 |
* The ID can be the draft post_id or the autosave revision post_id. |
| 5 | 2130 |
*/ |
2131 |
function wp_autosave( $post_data ) { |
|
| 16 | 2132 |
// Back-compat. |
| 9 | 2133 |
if ( ! defined( 'DOING_AUTOSAVE' ) ) { |
| 5 | 2134 |
define( 'DOING_AUTOSAVE', true ); |
| 9 | 2135 |
} |
| 5 | 2136 |
|
| 16 | 2137 |
$post_id = (int) $post_data['post_id']; |
2138 |
$post_data['ID'] = $post_id; |
|
2139 |
$post_data['post_ID'] = $post_id; |
|
| 5 | 2140 |
|
2141 |
if ( false === wp_verify_nonce( $post_data['_wpnonce'], 'update-post_' . $post_id ) ) { |
|
2142 |
return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ) ); |
|
| 0 | 2143 |
} |
2144 |
||
| 5 | 2145 |
$post = get_post( $post_id ); |
| 0 | 2146 |
|
| 5 | 2147 |
if ( ! current_user_can( 'edit_post', $post->ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2148 |
return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to edit this item.' ) ); |
| 0 | 2149 |
} |
2150 |
||
| 16 | 2151 |
if ( 'auto-draft' === $post->post_status ) { |
| 5 | 2152 |
$post_data['post_status'] = 'draft'; |
| 9 | 2153 |
} |
| 5 | 2154 |
|
| 16 | 2155 |
if ( 'page' !== $post_data['post_type'] && ! empty( $post_data['catslist'] ) ) { |
| 5 | 2156 |
$post_data['post_category'] = explode( ',', $post_data['catslist'] ); |
| 9 | 2157 |
} |
| 5 | 2158 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2159 |
if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() === (int) $post->post_author |
| 16 | 2160 |
&& ( 'auto-draft' === $post->post_status || 'draft' === $post->post_status ) |
2161 |
) { |
|
2162 |
// Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked. |
|
| 5 | 2163 |
return edit_post( wp_slash( $post_data ) ); |
2164 |
} else { |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2165 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2166 |
* Non-drafts or other users' drafts are not overwritten. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2167 |
* The autosave is stored in a special post revision for each user. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2168 |
*/ |
| 5 | 2169 |
return wp_create_post_autosave( wp_slash( $post_data ) ); |
2170 |
} |
|
| 0 | 2171 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2172 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2173 |
/** |
| 19 | 2174 |
* Redirects to previous page. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2175 |
* |
| 16 | 2176 |
* @since 2.7.0 |
2177 |
* |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2178 |
* @param int $post_id Optional. Post ID. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2179 |
*/ |
| 9 | 2180 |
function redirect_post( $post_id = '' ) { |
2181 |
if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) { |
|
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2182 |
$status = get_post_status( $post_id ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2183 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2184 |
switch ( $status ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2185 |
case 'pending': |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2186 |
$message = 8; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2187 |
break; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2188 |
case 'future': |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2189 |
$message = 9; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2190 |
break; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2191 |
case 'draft': |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2192 |
$message = 10; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2193 |
break; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2194 |
default: |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2195 |
$message = isset( $_POST['publish'] ) ? 6 : 1; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2196 |
break; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2197 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2198 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2199 |
$location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) ); |
| 9 | 2200 |
} elseif ( isset( $_POST['addmeta'] ) && $_POST['addmeta'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2201 |
$location = add_query_arg( 'message', 2, wp_get_referer() ); |
| 9 | 2202 |
$location = explode( '#', $location ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2203 |
$location = $location[0] . '#postcustom'; |
| 9 | 2204 |
} elseif ( isset( $_POST['deletemeta'] ) && $_POST['deletemeta'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2205 |
$location = add_query_arg( 'message', 3, wp_get_referer() ); |
| 9 | 2206 |
$location = explode( '#', $location ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2207 |
$location = $location[0] . '#postcustom'; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2208 |
} else { |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2209 |
$location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2210 |
} |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2211 |
|
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2212 |
/** |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2213 |
* Filters the post redirect destination URL. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2214 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2215 |
* @since 2.9.0 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2216 |
* |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2217 |
* @param string $location The destination URL. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2218 |
* @param int $post_id The post ID. |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2219 |
*/ |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2220 |
wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) ); |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2221 |
exit; |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
} |
| 9 | 2223 |
|
2224 |
/** |
|
2225 |
* Sanitizes POST values from a checkbox taxonomy metabox. |
|
2226 |
* |
|
2227 |
* @since 5.1.0 |
|
2228 |
* |
|
| 16 | 2229 |
* @param string $taxonomy The taxonomy name. |
2230 |
* @param array $terms Raw term data from the 'tax_input' field. |
|
2231 |
* @return int[] Array of sanitized term IDs. |
|
| 9 | 2232 |
*/ |
2233 |
function taxonomy_meta_box_sanitize_cb_checkboxes( $taxonomy, $terms ) { |
|
2234 |
return array_map( 'intval', $terms ); |
|
2235 |
} |
|
2236 |
||
2237 |
/** |
|
2238 |
* Sanitizes POST values from an input taxonomy metabox. |
|
2239 |
* |
|
2240 |
* @since 5.1.0 |
|
2241 |
* |
|
| 16 | 2242 |
* @param string $taxonomy The taxonomy name. |
2243 |
* @param array|string $terms Raw term data from the 'tax_input' field. |
|
| 9 | 2244 |
* @return array |
2245 |
*/ |
|
2246 |
function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) { |
|
2247 |
/* |
|
2248 |
* Assume that a 'tax_input' string is a comma-separated list of term names. |
|
2249 |
* Some languages may use a character other than a comma as a delimiter, so we standardize on |
|
2250 |
* commas before parsing the list. |
|
2251 |
*/ |
|
2252 |
if ( ! is_array( $terms ) ) { |
|
2253 |
$comma = _x( ',', 'tag delimiter' ); |
|
2254 |
if ( ',' !== $comma ) { |
|
2255 |
$terms = str_replace( $comma, ',', $terms ); |
|
2256 |
} |
|
2257 |
$terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) ); |
|
2258 |
} |
|
2259 |
||
2260 |
$clean_terms = array(); |
|
2261 |
foreach ( $terms as $term ) { |
|
2262 |
// Empty terms are invalid input. |
|
2263 |
if ( empty( $term ) ) { |
|
2264 |
continue; |
|
2265 |
} |
|
2266 |
||
2267 |
$_term = get_terms( |
|
2268 |
array( |
|
| 16 | 2269 |
'taxonomy' => $taxonomy, |
| 9 | 2270 |
'name' => $term, |
2271 |
'fields' => 'ids', |
|
2272 |
'hide_empty' => false, |
|
2273 |
) |
|
2274 |
); |
|
2275 |
||
2276 |
if ( ! empty( $_term ) ) { |
|
| 18 | 2277 |
$clean_terms[] = (int) $_term[0]; |
| 9 | 2278 |
} else { |
2279 |
// No existing term was found, so pass the string. A new term will be created. |
|
2280 |
$clean_terms[] = $term; |
|
2281 |
} |
|
2282 |
} |
|
2283 |
||
2284 |
return $clean_terms; |
|
2285 |
} |
|
2286 |
||
2287 |
/** |
|
2288 |
* Prepares server-registered blocks for the block editor. |
|
2289 |
* |
|
2290 |
* Returns an associative array of registered block data keyed by block name. Data includes properties |
|
2291 |
* of a block relevant for client registration. |
|
2292 |
* |
|
2293 |
* @since 5.0.0 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2294 |
* @since 6.3.0 Added `selectors` field. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2295 |
* @since 6.4.0 Added `block_hooks` field. |
| 9 | 2296 |
* |
2297 |
* @return array An associative array of registered block data. |
|
2298 |
*/ |
|
2299 |
function get_block_editor_server_block_settings() { |
|
2300 |
$block_registry = WP_Block_Type_Registry::get_instance(); |
|
2301 |
$blocks = array(); |
|
| 16 | 2302 |
$fields_to_pick = array( |
| 18 | 2303 |
'api_version' => 'apiVersion', |
| 16 | 2304 |
'title' => 'title', |
2305 |
'description' => 'description', |
|
2306 |
'icon' => 'icon', |
|
2307 |
'attributes' => 'attributes', |
|
2308 |
'provides_context' => 'providesContext', |
|
2309 |
'uses_context' => 'usesContext', |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2310 |
'block_hooks' => 'blockHooks', |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2311 |
'selectors' => 'selectors', |
| 18 | 2312 |
'supports' => 'supports', |
2313 |
'category' => 'category', |
|
| 16 | 2314 |
'styles' => 'styles', |
2315 |
'textdomain' => 'textdomain', |
|
| 18 | 2316 |
'parent' => 'parent', |
| 19 | 2317 |
'ancestor' => 'ancestor', |
| 18 | 2318 |
'keywords' => 'keywords', |
| 16 | 2319 |
'example' => 'example', |
| 18 | 2320 |
'variations' => 'variations', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2321 |
'allowed_blocks' => 'allowedBlocks', |
| 16 | 2322 |
); |
| 9 | 2323 |
|
2324 |
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { |
|
| 16 | 2325 |
foreach ( $fields_to_pick as $field => $key ) { |
2326 |
if ( ! isset( $block_type->{ $field } ) ) { |
|
| 9 | 2327 |
continue; |
2328 |
} |
|
2329 |
||
2330 |
if ( ! isset( $blocks[ $block_name ] ) ) { |
|
2331 |
$blocks[ $block_name ] = array(); |
|
2332 |
} |
|
2333 |
||
| 16 | 2334 |
$blocks[ $block_name ][ $key ] = $block_type->{ $field }; |
| 9 | 2335 |
} |
2336 |
} |
|
2337 |
||
2338 |
return $blocks; |
|
2339 |
} |
|
2340 |
||
2341 |
/** |
|
2342 |
* Renders the meta boxes forms. |
|
2343 |
* |
|
2344 |
* @since 5.0.0 |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2345 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2346 |
* @global WP_Post $post Global post object. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2347 |
* @global WP_Screen $current_screen WordPress current screen object. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2348 |
* @global array $wp_meta_boxes Global meta box state. |
| 9 | 2349 |
*/ |
2350 |
function the_block_editor_meta_boxes() { |
|
2351 |
global $post, $current_screen, $wp_meta_boxes; |
|
2352 |
||
2353 |
// Handle meta box state. |
|
2354 |
$_original_meta_boxes = $wp_meta_boxes; |
|
2355 |
||
2356 |
/** |
|
2357 |
* Fires right before the meta boxes are rendered. |
|
2358 |
* |
|
2359 |
* This allows for the filtering of meta box data, that should already be |
|
2360 |
* present by this point. Do not use as a means of adding meta box data. |
|
2361 |
* |
|
2362 |
* @since 5.0.0 |
|
2363 |
* |
|
2364 |
* @param array $wp_meta_boxes Global meta box state. |
|
2365 |
*/ |
|
2366 |
$wp_meta_boxes = apply_filters( 'filter_block_editor_meta_boxes', $wp_meta_boxes ); |
|
2367 |
$locations = array( 'side', 'normal', 'advanced' ); |
|
2368 |
$priorities = array( 'high', 'sorted', 'core', 'default', 'low' ); |
|
2369 |
||
2370 |
// Render meta boxes. |
|
2371 |
?> |
|
2372 |
<form class="metabox-base-form"> |
|
2373 |
<?php the_block_editor_meta_box_post_form_hidden_fields( $post ); ?> |
|
2374 |
</form> |
|
| 18 | 2375 |
<form id="toggle-custom-fields-form" method="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>"> |
2376 |
<?php wp_nonce_field( 'toggle-custom-fields', 'toggle-custom-fields-nonce' ); ?> |
|
| 9 | 2377 |
<input type="hidden" name="action" value="toggle-custom-fields" /> |
2378 |
</form> |
|
2379 |
<?php foreach ( $locations as $location ) : ?> |
|
2380 |
<form class="metabox-location-<?php echo esc_attr( $location ); ?>" onsubmit="return false;"> |
|
2381 |
<div id="poststuff" class="sidebar-open"> |
|
2382 |
<div id="postbox-container-2" class="postbox-container"> |
|
2383 |
<?php |
|
2384 |
do_meta_boxes( |
|
2385 |
$current_screen, |
|
2386 |
$location, |
|
2387 |
$post |
|
2388 |
); |
|
2389 |
?> |
|
2390 |
</div> |
|
2391 |
</div> |
|
2392 |
</form> |
|
2393 |
<?php endforeach; ?> |
|
2394 |
<?php |
|
2395 |
||
2396 |
$meta_boxes_per_location = array(); |
|
2397 |
foreach ( $locations as $location ) { |
|
2398 |
$meta_boxes_per_location[ $location ] = array(); |
|
2399 |
||
2400 |
if ( ! isset( $wp_meta_boxes[ $current_screen->id ][ $location ] ) ) { |
|
2401 |
continue; |
|
2402 |
} |
|
2403 |
||
2404 |
foreach ( $priorities as $priority ) { |
|
2405 |
if ( ! isset( $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ] ) ) { |
|
2406 |
continue; |
|
2407 |
} |
|
2408 |
||
2409 |
$meta_boxes = (array) $wp_meta_boxes[ $current_screen->id ][ $location ][ $priority ]; |
|
2410 |
foreach ( $meta_boxes as $meta_box ) { |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2411 |
if ( false === $meta_box || ! $meta_box['title'] ) { |
| 9 | 2412 |
continue; |
2413 |
} |
|
2414 |
||
2415 |
// If a meta box is just here for back compat, don't show it in the block editor. |
|
2416 |
if ( isset( $meta_box['args']['__back_compat_meta_box'] ) && $meta_box['args']['__back_compat_meta_box'] ) { |
|
2417 |
continue; |
|
2418 |
} |
|
2419 |
||
2420 |
$meta_boxes_per_location[ $location ][] = array( |
|
2421 |
'id' => $meta_box['id'], |
|
2422 |
'title' => $meta_box['title'], |
|
2423 |
); |
|
2424 |
} |
|
2425 |
} |
|
2426 |
} |
|
2427 |
||
| 19 | 2428 |
/* |
2429 |
* Sadly we probably cannot add this data directly into editor settings. |
|
| 9 | 2430 |
* |
| 19 | 2431 |
* Some meta boxes need `admin_head` to fire for meta box registry. |
2432 |
* `admin_head` fires after `admin_enqueue_scripts`, which is where we create |
|
2433 |
* our editor instance. |
|
| 9 | 2434 |
*/ |
2435 |
$script = 'window._wpLoadBlockEditor.then( function() { |
|
2436 |
wp.data.dispatch( \'core/edit-post\' ).setAvailableMetaBoxesPerLocation( ' . wp_json_encode( $meta_boxes_per_location ) . ' ); |
|
2437 |
} );'; |
|
2438 |
||
2439 |
wp_add_inline_script( 'wp-edit-post', $script ); |
|
2440 |
||
| 19 | 2441 |
/* |
2442 |
* When `wp-edit-post` is output in the `<head>`, the inline script needs to be manually printed. |
|
2443 |
* Otherwise, meta boxes will not display because inline scripts for `wp-edit-post` |
|
2444 |
* will not be printed again after this point. |
|
| 9 | 2445 |
*/ |
2446 |
if ( wp_script_is( 'wp-edit-post', 'done' ) ) { |
|
2447 |
printf( "<script type='text/javascript'>\n%s\n</script>\n", trim( $script ) ); |
|
2448 |
} |
|
2449 |
||
| 19 | 2450 |
/* |
2451 |
* If the 'postcustom' meta box is enabled, then we need to perform |
|
2452 |
* some extra initialization on it. |
|
| 9 | 2453 |
*/ |
2454 |
$enable_custom_fields = (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ); |
|
| 19 | 2455 |
|
| 9 | 2456 |
if ( $enable_custom_fields ) { |
2457 |
$script = "( function( $ ) { |
|
2458 |
if ( $('#postcustom').length ) { |
|
2459 |
$( '#the-list' ).wpList( { |
|
2460 |
addBefore: function( s ) { |
|
2461 |
s.data += '&post_id=$post->ID'; |
|
2462 |
return s; |
|
2463 |
}, |
|
2464 |
addAfter: function() { |
|
2465 |
$('table#list-table').show(); |
|
2466 |
} |
|
2467 |
}); |
|
2468 |
} |
|
2469 |
} )( jQuery );"; |
|
2470 |
wp_enqueue_script( 'wp-lists' ); |
|
2471 |
wp_add_inline_script( 'wp-lists', $script ); |
|
2472 |
} |
|
2473 |
||
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2474 |
/* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2475 |
* Refresh nonces used by the meta box loader. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2476 |
* |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2477 |
* The logic is very similar to that provided by post.js for the classic editor. |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2478 |
*/ |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2479 |
$script = "( function( $ ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2480 |
var check, timeout; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2481 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2482 |
function schedule() { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2483 |
check = false; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2484 |
window.clearTimeout( timeout ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2485 |
timeout = window.setTimeout( function() { check = true; }, 300000 ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2486 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2487 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2488 |
$( document ).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2489 |
var post_id, \$authCheck = $( '#wp-auth-check-wrap' ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2490 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2491 |
if ( check || ( \$authCheck.length && ! \$authCheck.hasClass( 'hidden' ) ) ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2492 |
if ( ( post_id = $( '#post_ID' ).val() ) && $( '#_wpnonce' ).val() ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2493 |
data['wp-refresh-metabox-loader-nonces'] = { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2494 |
post_id: post_id |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2495 |
}; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2496 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2497 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2498 |
}).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2499 |
var nonces = data['wp-refresh-metabox-loader-nonces']; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2500 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2501 |
if ( nonces ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2502 |
if ( nonces.replace ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2503 |
if ( nonces.replace.metabox_loader_nonce && window._wpMetaBoxUrl && wp.url ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2504 |
window._wpMetaBoxUrl= wp.url.addQueryArgs( window._wpMetaBoxUrl, { 'meta-box-loader-nonce': nonces.replace.metabox_loader_nonce } ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2505 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2506 |
|
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2507 |
if ( nonces.replace._wpnonce ) { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2508 |
$( '#_wpnonce' ).val( nonces.replace._wpnonce ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2509 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2510 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2511 |
} |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2512 |
}).ready( function() { |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2513 |
schedule(); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2514 |
}); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2515 |
} )( jQuery );"; |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2516 |
wp_add_inline_script( 'heartbeat', $script ); |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2517 |
|
| 9 | 2518 |
// Reset meta box data. |
2519 |
$wp_meta_boxes = $_original_meta_boxes; |
|
2520 |
} |
|
2521 |
||
2522 |
/** |
|
2523 |
* Renders the hidden form required for the meta boxes form. |
|
2524 |
* |
|
2525 |
* @since 5.0.0 |
|
2526 |
* |
|
2527 |
* @param WP_Post $post Current post object. |
|
2528 |
*/ |
|
2529 |
function the_block_editor_meta_box_post_form_hidden_fields( $post ) { |
|
2530 |
$form_extra = ''; |
|
2531 |
if ( 'auto-draft' === $post->post_status ) { |
|
2532 |
$form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />"; |
|
2533 |
} |
|
2534 |
$form_action = 'editpost'; |
|
2535 |
$nonce_action = 'update-post_' . $post->ID; |
|
2536 |
$form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post->ID ) . "' />"; |
|
2537 |
$referer = wp_get_referer(); |
|
2538 |
$current_user = wp_get_current_user(); |
|
2539 |
$user_id = $current_user->ID; |
|
2540 |
wp_nonce_field( $nonce_action ); |
|
2541 |
||
2542 |
/* |
|
| 19 | 2543 |
* Some meta boxes hook into these actions to add hidden input fields in the classic post form. |
2544 |
* For backward compatibility, we can capture the output from these actions, |
|
2545 |
* and extract the hidden input fields. |
|
| 9 | 2546 |
*/ |
2547 |
ob_start(); |
|
2548 |
/** This filter is documented in wp-admin/edit-form-advanced.php */ |
|
2549 |
do_action( 'edit_form_after_title', $post ); |
|
2550 |
/** This filter is documented in wp-admin/edit-form-advanced.php */ |
|
2551 |
do_action( 'edit_form_advanced', $post ); |
|
2552 |
$classic_output = ob_get_clean(); |
|
2553 |
||
2554 |
$classic_elements = wp_html_split( $classic_output ); |
|
2555 |
$hidden_inputs = ''; |
|
2556 |
foreach ( $classic_elements as $element ) { |
|
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2557 |
if ( ! str_starts_with( $element, '<input ' ) ) { |
| 9 | 2558 |
continue; |
2559 |
} |
|
2560 |
||
2561 |
if ( preg_match( '/\stype=[\'"]hidden[\'"]\s/', $element ) ) { |
|
2562 |
echo $element; |
|
2563 |
} |
|
2564 |
} |
|
2565 |
?> |
|
2566 |
<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_id; ?>" /> |
|
2567 |
<input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" /> |
|
2568 |
<input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" /> |
|
2569 |
<input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post->post_type ); ?>" /> |
|
2570 |
<input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ); ?>" /> |
|
2571 |
<input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" /> |
|
2572 |
||
2573 |
<?php |
|
2574 |
if ( 'draft' !== get_post_status( $post ) ) { |
|
2575 |
wp_original_referer_field( true, 'previous' ); |
|
2576 |
} |
|
2577 |
echo $form_extra; |
|
2578 |
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
|
2579 |
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
|
2580 |
// Permalink title nonce. |
|
2581 |
wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); |
|
2582 |
||
2583 |
/** |
|
| 19 | 2584 |
* Adds hidden input fields to the meta box save form. |
| 9 | 2585 |
* |
2586 |
* Hook into this action to print `<input type="hidden" ... />` fields, which will be POSTed back to |
|
2587 |
* the server when meta boxes are saved. |
|
2588 |
* |
|
2589 |
* @since 5.0.0 |
|
2590 |
* |
|
| 16 | 2591 |
* @param WP_Post $post The post that is being edited. |
| 9 | 2592 |
*/ |
2593 |
do_action( 'block_editor_meta_box_hidden_fields', $post ); |
|
2594 |
} |
|
| 19 | 2595 |
|
2596 |
/** |
|
2597 |
* Disables block editor for wp_navigation type posts so they can be managed via the UI. |
|
2598 |
* |
|
2599 |
* @since 5.9.0 |
|
2600 |
* @access private |
|
2601 |
* |
|
2602 |
* @param bool $value Whether the CPT supports block editor or not. |
|
2603 |
* @param string $post_type Post type. |
|
2604 |
* @return bool Whether the block editor should be disabled or not. |
|
2605 |
*/ |
|
2606 |
function _disable_block_editor_for_navigation_post_type( $value, $post_type ) { |
|
2607 |
if ( 'wp_navigation' === $post_type ) { |
|
2608 |
return false; |
|
2609 |
} |
|
2610 |
||
2611 |
return $value; |
|
2612 |
} |
|
2613 |
||
2614 |
/** |
|
2615 |
* This callback disables the content editor for wp_navigation type posts. |
|
2616 |
* Content editor cannot handle wp_navigation type posts correctly. |
|
2617 |
* We cannot disable the "editor" feature in the wp_navigation's CPT definition |
|
2618 |
* because it disables the ability to save navigation blocks via REST API. |
|
2619 |
* |
|
2620 |
* @since 5.9.0 |
|
2621 |
* @access private |
|
2622 |
* |
|
2623 |
* @param WP_Post $post An instance of WP_Post class. |
|
2624 |
*/ |
|
2625 |
function _disable_content_editor_for_navigation_post_type( $post ) { |
|
2626 |
$post_type = get_post_type( $post ); |
|
2627 |
if ( 'wp_navigation' !== $post_type ) { |
|
2628 |
return; |
|
2629 |
} |
|
2630 |
||
2631 |
remove_post_type_support( $post_type, 'editor' ); |
|
2632 |
} |
|
2633 |
||
2634 |
/** |
|
2635 |
* This callback enables content editor for wp_navigation type posts. |
|
2636 |
* We need to enable it back because we disable it to hide |
|
2637 |
* the content editor for wp_navigation type posts. |
|
2638 |
* |
|
2639 |
* @since 5.9.0 |
|
2640 |
* @access private |
|
2641 |
* |
|
2642 |
* @see _disable_content_editor_for_navigation_post_type |
|
2643 |
* |
|
2644 |
* @param WP_Post $post An instance of WP_Post class. |
|
2645 |
*/ |
|
2646 |
function _enable_content_editor_for_navigation_post_type( $post ) { |
|
2647 |
$post_type = get_post_type( $post ); |
|
2648 |
if ( 'wp_navigation' !== $post_type ) { |
|
2649 |
return; |
|
2650 |
} |
|
2651 |
||
2652 |
add_post_type_support( $post_type, 'editor' ); |
|
2653 |
} |