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 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Core Post API |
0 | 4 |
* |
5 |
* @package WordPress |
|
6 |
* @subpackage Post |
|
7 |
*/ |
|
8 |
||
9 |
// |
|
16 | 10 |
// Post Type registration. |
0 | 11 |
// |
12 |
||
13 |
/** |
|
14 |
* Creates the initial post types when 'init' action is fired. |
|
15 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* See {@see 'init'}. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* |
0 | 18 |
* @since 2.9.0 |
19 |
*/ |
|
20 |
function create_initial_post_types() { |
|
19 | 21 |
WP_Post_Type::reset_default_labels(); |
22 |
||
9 | 23 |
register_post_type( |
24 |
'post', |
|
25 |
array( |
|
26 |
'labels' => array( |
|
27 |
'name_admin_bar' => _x( 'Post', 'add new from admin bar' ), |
|
28 |
), |
|
29 |
'public' => true, |
|
30 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
31 |
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ |
|
32 |
'capability_type' => 'post', |
|
33 |
'map_meta_cap' => true, |
|
34 |
'menu_position' => 5, |
|
16 | 35 |
'menu_icon' => 'dashicons-admin-post', |
9 | 36 |
'hierarchical' => false, |
37 |
'rewrite' => false, |
|
38 |
'query_var' => false, |
|
39 |
'delete_with_user' => true, |
|
40 |
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ), |
|
41 |
'show_in_rest' => true, |
|
42 |
'rest_base' => 'posts', |
|
43 |
'rest_controller_class' => 'WP_REST_Posts_Controller', |
|
44 |
) |
|
45 |
); |
|
46 |
||
47 |
register_post_type( |
|
48 |
'page', |
|
49 |
array( |
|
50 |
'labels' => array( |
|
51 |
'name_admin_bar' => _x( 'Page', 'add new from admin bar' ), |
|
52 |
), |
|
53 |
'public' => true, |
|
54 |
'publicly_queryable' => false, |
|
55 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
56 |
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ |
|
57 |
'capability_type' => 'page', |
|
58 |
'map_meta_cap' => true, |
|
59 |
'menu_position' => 20, |
|
16 | 60 |
'menu_icon' => 'dashicons-admin-page', |
9 | 61 |
'hierarchical' => true, |
62 |
'rewrite' => false, |
|
63 |
'query_var' => false, |
|
64 |
'delete_with_user' => true, |
|
65 |
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ), |
|
66 |
'show_in_rest' => true, |
|
67 |
'rest_base' => 'pages', |
|
68 |
'rest_controller_class' => 'WP_REST_Posts_Controller', |
|
69 |
) |
|
70 |
); |
|
71 |
||
72 |
register_post_type( |
|
73 |
'attachment', |
|
74 |
array( |
|
75 |
'labels' => array( |
|
76 |
'name' => _x( 'Media', 'post type general name' ), |
|
77 |
'name_admin_bar' => _x( 'Media', 'add new from admin bar' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
78 |
'add_new' => __( 'Add New Media File' ), |
9 | 79 |
'edit_item' => __( 'Edit Media' ), |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
80 |
'view_item' => ( '1' === get_option( 'wp_attachment_pages_enabled' ) ) ? __( 'View Attachment Page' ) : __( 'View Media File' ), |
9 | 81 |
'attributes' => __( 'Attachment Attributes' ), |
82 |
), |
|
83 |
'public' => true, |
|
84 |
'show_ui' => true, |
|
85 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
86 |
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ |
|
87 |
'capability_type' => 'post', |
|
88 |
'capabilities' => array( |
|
89 |
'create_posts' => 'upload_files', |
|
90 |
), |
|
91 |
'map_meta_cap' => true, |
|
16 | 92 |
'menu_icon' => 'dashicons-admin-media', |
9 | 93 |
'hierarchical' => false, |
94 |
'rewrite' => false, |
|
95 |
'query_var' => false, |
|
96 |
'show_in_nav_menus' => false, |
|
97 |
'delete_with_user' => true, |
|
98 |
'supports' => array( 'title', 'author', 'comments' ), |
|
99 |
'show_in_rest' => true, |
|
100 |
'rest_base' => 'media', |
|
101 |
'rest_controller_class' => 'WP_REST_Attachments_Controller', |
|
102 |
) |
|
103 |
); |
|
5 | 104 |
add_post_type_support( 'attachment:audio', 'thumbnail' ); |
105 |
add_post_type_support( 'attachment:video', 'thumbnail' ); |
|
0 | 106 |
|
9 | 107 |
register_post_type( |
108 |
'revision', |
|
109 |
array( |
|
110 |
'labels' => array( |
|
111 |
'name' => __( 'Revisions' ), |
|
112 |
'singular_name' => __( 'Revision' ), |
|
113 |
), |
|
114 |
'public' => false, |
|
115 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
116 |
'_edit_link' => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */ |
|
117 |
'capability_type' => 'post', |
|
118 |
'map_meta_cap' => true, |
|
119 |
'hierarchical' => false, |
|
120 |
'rewrite' => false, |
|
121 |
'query_var' => false, |
|
122 |
'can_export' => false, |
|
123 |
'delete_with_user' => true, |
|
124 |
'supports' => array( 'author' ), |
|
125 |
) |
|
126 |
); |
|
127 |
||
128 |
register_post_type( |
|
129 |
'nav_menu_item', |
|
130 |
array( |
|
19 | 131 |
'labels' => array( |
9 | 132 |
'name' => __( 'Navigation Menu Items' ), |
133 |
'singular_name' => __( 'Navigation Menu Item' ), |
|
134 |
), |
|
19 | 135 |
'public' => false, |
136 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
137 |
'hierarchical' => false, |
|
138 |
'rewrite' => false, |
|
139 |
'delete_with_user' => false, |
|
140 |
'query_var' => false, |
|
141 |
'map_meta_cap' => true, |
|
142 |
'capability_type' => array( 'edit_theme_options', 'edit_theme_options' ), |
|
143 |
'capabilities' => array( |
|
144 |
// Meta Capabilities. |
|
145 |
'edit_post' => 'edit_post', |
|
146 |
'read_post' => 'read_post', |
|
147 |
'delete_post' => 'delete_post', |
|
148 |
// Primitive Capabilities. |
|
149 |
'edit_posts' => 'edit_theme_options', |
|
150 |
'edit_others_posts' => 'edit_theme_options', |
|
151 |
'delete_posts' => 'edit_theme_options', |
|
152 |
'publish_posts' => 'edit_theme_options', |
|
153 |
'read_private_posts' => 'edit_theme_options', |
|
154 |
'read' => 'read', |
|
155 |
'delete_private_posts' => 'edit_theme_options', |
|
156 |
'delete_published_posts' => 'edit_theme_options', |
|
157 |
'delete_others_posts' => 'edit_theme_options', |
|
158 |
'edit_private_posts' => 'edit_theme_options', |
|
159 |
'edit_published_posts' => 'edit_theme_options', |
|
160 |
), |
|
161 |
'show_in_rest' => true, |
|
162 |
'rest_base' => 'menu-items', |
|
163 |
'rest_controller_class' => 'WP_REST_Menu_Items_Controller', |
|
9 | 164 |
) |
165 |
); |
|
166 |
||
167 |
register_post_type( |
|
168 |
'custom_css', |
|
169 |
array( |
|
170 |
'labels' => array( |
|
171 |
'name' => __( 'Custom CSS' ), |
|
172 |
'singular_name' => __( 'Custom CSS' ), |
|
173 |
), |
|
174 |
'public' => false, |
|
175 |
'hierarchical' => false, |
|
176 |
'rewrite' => false, |
|
177 |
'query_var' => false, |
|
178 |
'delete_with_user' => false, |
|
179 |
'can_export' => true, |
|
180 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
181 |
'supports' => array( 'title', 'revisions' ), |
|
182 |
'capabilities' => array( |
|
183 |
'delete_posts' => 'edit_theme_options', |
|
184 |
'delete_post' => 'edit_theme_options', |
|
185 |
'delete_published_posts' => 'edit_theme_options', |
|
186 |
'delete_private_posts' => 'edit_theme_options', |
|
187 |
'delete_others_posts' => 'edit_theme_options', |
|
188 |
'edit_post' => 'edit_css', |
|
189 |
'edit_posts' => 'edit_css', |
|
190 |
'edit_others_posts' => 'edit_css', |
|
191 |
'edit_published_posts' => 'edit_css', |
|
192 |
'read_post' => 'read', |
|
193 |
'read_private_posts' => 'read', |
|
194 |
'publish_posts' => 'edit_theme_options', |
|
195 |
), |
|
196 |
) |
|
197 |
); |
|
198 |
||
199 |
register_post_type( |
|
200 |
'customize_changeset', |
|
201 |
array( |
|
202 |
'labels' => array( |
|
203 |
'name' => _x( 'Changesets', 'post type general name' ), |
|
204 |
'singular_name' => _x( 'Changeset', 'post type singular name' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
205 |
'add_new' => __( 'Add New Changeset' ), |
9 | 206 |
'add_new_item' => __( 'Add New Changeset' ), |
207 |
'new_item' => __( 'New Changeset' ), |
|
208 |
'edit_item' => __( 'Edit Changeset' ), |
|
209 |
'view_item' => __( 'View Changeset' ), |
|
210 |
'all_items' => __( 'All Changesets' ), |
|
211 |
'search_items' => __( 'Search Changesets' ), |
|
212 |
'not_found' => __( 'No changesets found.' ), |
|
213 |
'not_found_in_trash' => __( 'No changesets found in Trash.' ), |
|
214 |
), |
|
215 |
'public' => false, |
|
216 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
217 |
'map_meta_cap' => true, |
|
218 |
'hierarchical' => false, |
|
219 |
'rewrite' => false, |
|
220 |
'query_var' => false, |
|
221 |
'can_export' => false, |
|
222 |
'delete_with_user' => false, |
|
223 |
'supports' => array( 'title', 'author' ), |
|
224 |
'capability_type' => 'customize_changeset', |
|
225 |
'capabilities' => array( |
|
226 |
'create_posts' => 'customize', |
|
227 |
'delete_others_posts' => 'customize', |
|
228 |
'delete_post' => 'customize', |
|
229 |
'delete_posts' => 'customize', |
|
230 |
'delete_private_posts' => 'customize', |
|
231 |
'delete_published_posts' => 'customize', |
|
232 |
'edit_others_posts' => 'customize', |
|
233 |
'edit_post' => 'customize', |
|
234 |
'edit_posts' => 'customize', |
|
235 |
'edit_private_posts' => 'customize', |
|
236 |
'edit_published_posts' => 'do_not_allow', |
|
237 |
'publish_posts' => 'customize', |
|
238 |
'read' => 'read', |
|
239 |
'read_post' => 'customize', |
|
240 |
'read_private_posts' => 'customize', |
|
241 |
), |
|
242 |
) |
|
243 |
); |
|
244 |
||
245 |
register_post_type( |
|
246 |
'oembed_cache', |
|
247 |
array( |
|
248 |
'labels' => array( |
|
249 |
'name' => __( 'oEmbed Responses' ), |
|
250 |
'singular_name' => __( 'oEmbed Response' ), |
|
251 |
), |
|
252 |
'public' => false, |
|
253 |
'hierarchical' => false, |
|
254 |
'rewrite' => false, |
|
255 |
'query_var' => false, |
|
256 |
'delete_with_user' => false, |
|
257 |
'can_export' => false, |
|
258 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
259 |
'supports' => array(), |
|
260 |
) |
|
261 |
); |
|
262 |
||
263 |
register_post_type( |
|
264 |
'user_request', |
|
265 |
array( |
|
266 |
'labels' => array( |
|
267 |
'name' => __( 'User Requests' ), |
|
268 |
'singular_name' => __( 'User Request' ), |
|
269 |
), |
|
270 |
'public' => false, |
|
271 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
272 |
'hierarchical' => false, |
|
273 |
'rewrite' => false, |
|
274 |
'query_var' => false, |
|
275 |
'can_export' => false, |
|
276 |
'delete_with_user' => false, |
|
277 |
'supports' => array(), |
|
278 |
) |
|
279 |
); |
|
280 |
||
281 |
register_post_type( |
|
282 |
'wp_block', |
|
283 |
array( |
|
284 |
'labels' => array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
285 |
'name' => _x( 'Patterns', 'post type general name' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
286 |
'singular_name' => _x( 'Pattern', 'post type singular name' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
287 |
'add_new' => __( 'Add New Pattern' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
288 |
'add_new_item' => __( 'Add New Pattern' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
289 |
'new_item' => __( 'New Pattern' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
290 |
'edit_item' => __( 'Edit Block Pattern' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
291 |
'view_item' => __( 'View Pattern' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
292 |
'view_items' => __( 'View Patterns' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
293 |
'all_items' => __( 'All Patterns' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
294 |
'search_items' => __( 'Search Patterns' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
295 |
'not_found' => __( 'No patterns found.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
296 |
'not_found_in_trash' => __( 'No patterns found in Trash.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
297 |
'filter_items_list' => __( 'Filter patterns list' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
298 |
'items_list_navigation' => __( 'Patterns list navigation' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
299 |
'items_list' => __( 'Patterns list' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
300 |
'item_published' => __( 'Pattern published.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
301 |
'item_published_privately' => __( 'Pattern published privately.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
302 |
'item_reverted_to_draft' => __( 'Pattern reverted to draft.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
303 |
'item_scheduled' => __( 'Pattern scheduled.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
304 |
'item_updated' => __( 'Pattern updated.' ), |
9 | 305 |
), |
306 |
'public' => false, |
|
307 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
308 |
'show_ui' => true, |
|
309 |
'show_in_menu' => false, |
|
310 |
'rewrite' => false, |
|
311 |
'show_in_rest' => true, |
|
312 |
'rest_base' => 'blocks', |
|
313 |
'rest_controller_class' => 'WP_REST_Blocks_Controller', |
|
314 |
'capability_type' => 'block', |
|
315 |
'capabilities' => array( |
|
316 |
// You need to be able to edit posts, in order to read blocks in their raw form. |
|
317 |
'read' => 'edit_posts', |
|
318 |
// You need to be able to publish posts, in order to create blocks. |
|
319 |
'create_posts' => 'publish_posts', |
|
320 |
'edit_posts' => 'edit_posts', |
|
321 |
'edit_published_posts' => 'edit_published_posts', |
|
322 |
'delete_published_posts' => 'delete_published_posts', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
323 |
// Enables trashing draft posts as well. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
324 |
'delete_posts' => 'delete_posts', |
9 | 325 |
'edit_others_posts' => 'edit_others_posts', |
326 |
'delete_others_posts' => 'delete_others_posts', |
|
327 |
), |
|
328 |
'map_meta_cap' => true, |
|
329 |
'supports' => array( |
|
330 |
'title', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
331 |
'excerpt', |
9 | 332 |
'editor', |
18 | 333 |
'revisions', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
334 |
'custom-fields', |
18 | 335 |
), |
336 |
) |
|
337 |
); |
|
338 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
339 |
$template_edit_link = 'site-editor.php?' . build_query( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
340 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
341 |
'postType' => '%s', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
342 |
'postId' => '%s', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
343 |
'canvas' => 'edit', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
344 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
345 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
346 |
|
18 | 347 |
register_post_type( |
348 |
'wp_template', |
|
349 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
350 |
'labels' => array( |
19 | 351 |
'name' => _x( 'Templates', 'post type general name' ), |
352 |
'singular_name' => _x( 'Template', 'post type singular name' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
353 |
'add_new' => __( 'Add New Template' ), |
18 | 354 |
'add_new_item' => __( 'Add New Template' ), |
355 |
'new_item' => __( 'New Template' ), |
|
356 |
'edit_item' => __( 'Edit Template' ), |
|
357 |
'view_item' => __( 'View Template' ), |
|
19 | 358 |
'all_items' => __( 'Templates' ), |
18 | 359 |
'search_items' => __( 'Search Templates' ), |
360 |
'parent_item_colon' => __( 'Parent Template:' ), |
|
361 |
'not_found' => __( 'No templates found.' ), |
|
362 |
'not_found_in_trash' => __( 'No templates found in Trash.' ), |
|
363 |
'archives' => __( 'Template archives' ), |
|
364 |
'insert_into_item' => __( 'Insert into template' ), |
|
365 |
'uploaded_to_this_item' => __( 'Uploaded to this template' ), |
|
366 |
'filter_items_list' => __( 'Filter templates list' ), |
|
367 |
'items_list_navigation' => __( 'Templates list navigation' ), |
|
368 |
'items_list' => __( 'Templates list' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
369 |
'item_updated' => __( 'Template updated.' ), |
18 | 370 |
), |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
371 |
'description' => __( 'Templates to include in your theme.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
372 |
'public' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
373 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
'_edit_link' => $template_edit_link, /* internal use only. don't use this when registering your own post type. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
375 |
'has_archive' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
376 |
'show_ui' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
377 |
'show_in_menu' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
378 |
'show_in_rest' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
379 |
'rewrite' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
380 |
'rest_base' => 'templates', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
381 |
'rest_controller_class' => 'WP_REST_Templates_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
382 |
'autosave_rest_controller_class' => 'WP_REST_Template_Autosaves_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
383 |
'revisions_rest_controller_class' => 'WP_REST_Template_Revisions_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
384 |
'late_route_registration' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
385 |
'capability_type' => array( 'template', 'templates' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
386 |
'capabilities' => array( |
18 | 387 |
'create_posts' => 'edit_theme_options', |
388 |
'delete_posts' => 'edit_theme_options', |
|
389 |
'delete_others_posts' => 'edit_theme_options', |
|
390 |
'delete_private_posts' => 'edit_theme_options', |
|
391 |
'delete_published_posts' => 'edit_theme_options', |
|
392 |
'edit_posts' => 'edit_theme_options', |
|
393 |
'edit_others_posts' => 'edit_theme_options', |
|
394 |
'edit_private_posts' => 'edit_theme_options', |
|
395 |
'edit_published_posts' => 'edit_theme_options', |
|
396 |
'publish_posts' => 'edit_theme_options', |
|
397 |
'read' => 'edit_theme_options', |
|
398 |
'read_private_posts' => 'edit_theme_options', |
|
399 |
), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
400 |
'map_meta_cap' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
401 |
'supports' => array( |
18 | 402 |
'title', |
403 |
'slug', |
|
404 |
'excerpt', |
|
405 |
'editor', |
|
406 |
'revisions', |
|
19 | 407 |
'author', |
408 |
), |
|
409 |
) |
|
410 |
); |
|
411 |
||
412 |
register_post_type( |
|
413 |
'wp_template_part', |
|
414 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
'labels' => array( |
19 | 416 |
'name' => _x( 'Template Parts', 'post type general name' ), |
417 |
'singular_name' => _x( 'Template Part', 'post type singular name' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
418 |
'add_new' => __( 'Add New Template Part' ), |
19 | 419 |
'add_new_item' => __( 'Add New Template Part' ), |
420 |
'new_item' => __( 'New Template Part' ), |
|
421 |
'edit_item' => __( 'Edit Template Part' ), |
|
422 |
'view_item' => __( 'View Template Part' ), |
|
423 |
'all_items' => __( 'Template Parts' ), |
|
424 |
'search_items' => __( 'Search Template Parts' ), |
|
425 |
'parent_item_colon' => __( 'Parent Template Part:' ), |
|
426 |
'not_found' => __( 'No template parts found.' ), |
|
427 |
'not_found_in_trash' => __( 'No template parts found in Trash.' ), |
|
428 |
'archives' => __( 'Template part archives' ), |
|
429 |
'insert_into_item' => __( 'Insert into template part' ), |
|
430 |
'uploaded_to_this_item' => __( 'Uploaded to this template part' ), |
|
431 |
'filter_items_list' => __( 'Filter template parts list' ), |
|
432 |
'items_list_navigation' => __( 'Template parts list navigation' ), |
|
433 |
'items_list' => __( 'Template parts list' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
434 |
'item_updated' => __( 'Template part updated.' ), |
19 | 435 |
), |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
436 |
'description' => __( 'Template parts to include in your templates.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
437 |
'public' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
438 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
439 |
'_edit_link' => $template_edit_link, /* internal use only. don't use this when registering your own post type. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
440 |
'has_archive' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
441 |
'show_ui' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
442 |
'show_in_menu' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
443 |
'show_in_rest' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
444 |
'rewrite' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
445 |
'rest_base' => 'template-parts', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
446 |
'rest_controller_class' => 'WP_REST_Templates_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
447 |
'autosave_rest_controller_class' => 'WP_REST_Template_Autosaves_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
448 |
'revisions_rest_controller_class' => 'WP_REST_Template_Revisions_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
449 |
'late_route_registration' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
450 |
'map_meta_cap' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
451 |
'capabilities' => array( |
19 | 452 |
'create_posts' => 'edit_theme_options', |
453 |
'delete_posts' => 'edit_theme_options', |
|
454 |
'delete_others_posts' => 'edit_theme_options', |
|
455 |
'delete_private_posts' => 'edit_theme_options', |
|
456 |
'delete_published_posts' => 'edit_theme_options', |
|
457 |
'edit_posts' => 'edit_theme_options', |
|
458 |
'edit_others_posts' => 'edit_theme_options', |
|
459 |
'edit_private_posts' => 'edit_theme_options', |
|
460 |
'edit_published_posts' => 'edit_theme_options', |
|
461 |
'publish_posts' => 'edit_theme_options', |
|
462 |
'read' => 'edit_theme_options', |
|
463 |
'read_private_posts' => 'edit_theme_options', |
|
464 |
), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
465 |
'supports' => array( |
19 | 466 |
'title', |
467 |
'slug', |
|
468 |
'excerpt', |
|
469 |
'editor', |
|
470 |
'revisions', |
|
471 |
'author', |
|
472 |
), |
|
473 |
) |
|
474 |
); |
|
475 |
||
476 |
register_post_type( |
|
477 |
'wp_global_styles', |
|
478 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
479 |
'label' => _x( 'Global Styles', 'post type general name' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
480 |
'description' => __( 'Global styles to include in themes.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
481 |
'public' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
482 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
483 |
'_edit_link' => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
484 |
'show_ui' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
485 |
'show_in_rest' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
486 |
'rewrite' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
487 |
'rest_base' => 'global-styles', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
488 |
'rest_controller_class' => 'WP_REST_Global_Styles_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
489 |
'revisions_rest_controller_class' => 'WP_REST_Global_Styles_Revisions_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
490 |
'late_route_registration' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
491 |
'capabilities' => array( |
19 | 492 |
'read' => 'edit_theme_options', |
493 |
'create_posts' => 'edit_theme_options', |
|
494 |
'edit_posts' => 'edit_theme_options', |
|
495 |
'edit_published_posts' => 'edit_theme_options', |
|
496 |
'delete_published_posts' => 'edit_theme_options', |
|
497 |
'edit_others_posts' => 'edit_theme_options', |
|
498 |
'delete_others_posts' => 'edit_theme_options', |
|
499 |
), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
500 |
'map_meta_cap' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
501 |
'supports' => array( |
19 | 502 |
'title', |
503 |
'editor', |
|
504 |
'revisions', |
|
505 |
), |
|
506 |
) |
|
507 |
); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
508 |
// Disable autosave endpoints for global styles. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
509 |
remove_post_type_support( 'wp_global_styles', 'autosave' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
510 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
511 |
$navigation_post_edit_link = 'site-editor.php?' . build_query( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
512 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
513 |
'postId' => '%s', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
514 |
'postType' => 'wp_navigation', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
515 |
'canvas' => 'edit', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
516 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
517 |
); |
19 | 518 |
|
519 |
register_post_type( |
|
520 |
'wp_navigation', |
|
521 |
array( |
|
522 |
'labels' => array( |
|
523 |
'name' => _x( 'Navigation Menus', 'post type general name' ), |
|
524 |
'singular_name' => _x( 'Navigation Menu', 'post type singular name' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
525 |
'add_new' => __( 'Add New Navigation Menu' ), |
19 | 526 |
'add_new_item' => __( 'Add New Navigation Menu' ), |
527 |
'new_item' => __( 'New Navigation Menu' ), |
|
528 |
'edit_item' => __( 'Edit Navigation Menu' ), |
|
529 |
'view_item' => __( 'View Navigation Menu' ), |
|
530 |
'all_items' => __( 'Navigation Menus' ), |
|
531 |
'search_items' => __( 'Search Navigation Menus' ), |
|
532 |
'parent_item_colon' => __( 'Parent Navigation Menu:' ), |
|
533 |
'not_found' => __( 'No Navigation Menu found.' ), |
|
534 |
'not_found_in_trash' => __( 'No Navigation Menu found in Trash.' ), |
|
535 |
'archives' => __( 'Navigation Menu archives' ), |
|
536 |
'insert_into_item' => __( 'Insert into Navigation Menu' ), |
|
537 |
'uploaded_to_this_item' => __( 'Uploaded to this Navigation Menu' ), |
|
538 |
'filter_items_list' => __( 'Filter Navigation Menu list' ), |
|
539 |
'items_list_navigation' => __( 'Navigation Menus list navigation' ), |
|
540 |
'items_list' => __( 'Navigation Menus list' ), |
|
541 |
), |
|
542 |
'description' => __( 'Navigation menus that can be inserted into your site.' ), |
|
543 |
'public' => false, |
|
544 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
545 |
'_edit_link' => $navigation_post_edit_link, /* internal use only. don't use this when registering your own post type. */ |
19 | 546 |
'has_archive' => false, |
547 |
'show_ui' => true, |
|
548 |
'show_in_menu' => false, |
|
549 |
'show_in_admin_bar' => false, |
|
550 |
'show_in_rest' => true, |
|
551 |
'rewrite' => false, |
|
552 |
'map_meta_cap' => true, |
|
553 |
'capabilities' => array( |
|
554 |
'edit_others_posts' => 'edit_theme_options', |
|
555 |
'delete_posts' => 'edit_theme_options', |
|
556 |
'publish_posts' => 'edit_theme_options', |
|
557 |
'create_posts' => 'edit_theme_options', |
|
558 |
'read_private_posts' => 'edit_theme_options', |
|
559 |
'delete_private_posts' => 'edit_theme_options', |
|
560 |
'delete_published_posts' => 'edit_theme_options', |
|
561 |
'delete_others_posts' => 'edit_theme_options', |
|
562 |
'edit_private_posts' => 'edit_theme_options', |
|
563 |
'edit_published_posts' => 'edit_theme_options', |
|
564 |
'edit_posts' => 'edit_theme_options', |
|
565 |
), |
|
566 |
'rest_base' => 'navigation', |
|
567 |
'rest_controller_class' => 'WP_REST_Posts_Controller', |
|
568 |
'supports' => array( |
|
569 |
'title', |
|
570 |
'editor', |
|
571 |
'revisions', |
|
9 | 572 |
), |
573 |
) |
|
574 |
); |
|
575 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
576 |
register_post_type( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
577 |
'wp_font_family', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
578 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
579 |
'labels' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
580 |
'name' => __( 'Font Families' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
581 |
'singular_name' => __( 'Font Family' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
582 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
583 |
'public' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
584 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
585 |
'hierarchical' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
586 |
'capabilities' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
587 |
'read' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
588 |
'read_private_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
589 |
'create_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
590 |
'publish_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
591 |
'edit_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
592 |
'edit_others_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
593 |
'edit_published_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
594 |
'delete_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
595 |
'delete_others_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
596 |
'delete_published_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
597 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
598 |
'map_meta_cap' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
599 |
'query_var' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
600 |
'rewrite' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
601 |
'show_in_rest' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
602 |
'rest_base' => 'font-families', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
603 |
'rest_controller_class' => 'WP_REST_Font_Families_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
604 |
'supports' => array( 'title' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
605 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
606 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
607 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
608 |
register_post_type( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
609 |
'wp_font_face', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
610 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
611 |
'labels' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
612 |
'name' => __( 'Font Faces' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
613 |
'singular_name' => __( 'Font Face' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
614 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
615 |
'public' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
616 |
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
617 |
'hierarchical' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
618 |
'capabilities' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
619 |
'read' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
620 |
'read_private_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
621 |
'create_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
622 |
'publish_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
623 |
'edit_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
624 |
'edit_others_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
625 |
'edit_published_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
626 |
'delete_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
627 |
'delete_others_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
628 |
'delete_published_posts' => 'edit_theme_options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
629 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
630 |
'map_meta_cap' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
631 |
'query_var' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
632 |
'rewrite' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
633 |
'show_in_rest' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
634 |
'rest_base' => 'font-families/(?P<font_family_id>[\d]+)/font-faces', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
635 |
'rest_controller_class' => 'WP_REST_Font_Faces_Controller', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
636 |
'supports' => array( 'title' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
637 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
638 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
639 |
|
9 | 640 |
register_post_status( |
641 |
'publish', |
|
642 |
array( |
|
643 |
'label' => _x( 'Published', 'post status' ), |
|
644 |
'public' => true, |
|
645 |
'_builtin' => true, /* internal use only. */ |
|
16 | 646 |
/* translators: %s: Number of published posts. */ |
647 |
'label_count' => _n_noop( |
|
648 |
'Published <span class="count">(%s)</span>', |
|
649 |
'Published <span class="count">(%s)</span>' |
|
650 |
), |
|
9 | 651 |
) |
652 |
); |
|
653 |
||
654 |
register_post_status( |
|
655 |
'future', |
|
656 |
array( |
|
657 |
'label' => _x( 'Scheduled', 'post status' ), |
|
658 |
'protected' => true, |
|
659 |
'_builtin' => true, /* internal use only. */ |
|
16 | 660 |
/* translators: %s: Number of scheduled posts. */ |
661 |
'label_count' => _n_noop( |
|
662 |
'Scheduled <span class="count">(%s)</span>', |
|
663 |
'Scheduled <span class="count">(%s)</span>' |
|
664 |
), |
|
9 | 665 |
) |
666 |
); |
|
667 |
||
668 |
register_post_status( |
|
669 |
'draft', |
|
670 |
array( |
|
16 | 671 |
'label' => _x( 'Draft', 'post status' ), |
672 |
'protected' => true, |
|
673 |
'_builtin' => true, /* internal use only. */ |
|
674 |
/* translators: %s: Number of draft posts. */ |
|
675 |
'label_count' => _n_noop( |
|
676 |
'Draft <span class="count">(%s)</span>', |
|
677 |
'Drafts <span class="count">(%s)</span>' |
|
678 |
), |
|
679 |
'date_floating' => true, |
|
9 | 680 |
) |
681 |
); |
|
682 |
||
683 |
register_post_status( |
|
684 |
'pending', |
|
685 |
array( |
|
16 | 686 |
'label' => _x( 'Pending', 'post status' ), |
687 |
'protected' => true, |
|
688 |
'_builtin' => true, /* internal use only. */ |
|
689 |
/* translators: %s: Number of pending posts. */ |
|
690 |
'label_count' => _n_noop( |
|
691 |
'Pending <span class="count">(%s)</span>', |
|
692 |
'Pending <span class="count">(%s)</span>' |
|
693 |
), |
|
694 |
'date_floating' => true, |
|
9 | 695 |
) |
696 |
); |
|
697 |
||
698 |
register_post_status( |
|
699 |
'private', |
|
700 |
array( |
|
701 |
'label' => _x( 'Private', 'post status' ), |
|
702 |
'private' => true, |
|
703 |
'_builtin' => true, /* internal use only. */ |
|
16 | 704 |
/* translators: %s: Number of private posts. */ |
705 |
'label_count' => _n_noop( |
|
706 |
'Private <span class="count">(%s)</span>', |
|
707 |
'Private <span class="count">(%s)</span>' |
|
708 |
), |
|
9 | 709 |
) |
710 |
); |
|
711 |
||
712 |
register_post_status( |
|
713 |
'trash', |
|
714 |
array( |
|
715 |
'label' => _x( 'Trash', 'post status' ), |
|
716 |
'internal' => true, |
|
717 |
'_builtin' => true, /* internal use only. */ |
|
16 | 718 |
/* translators: %s: Number of trashed posts. */ |
719 |
'label_count' => _n_noop( |
|
720 |
'Trash <span class="count">(%s)</span>', |
|
721 |
'Trash <span class="count">(%s)</span>' |
|
722 |
), |
|
9 | 723 |
'show_in_admin_status_list' => true, |
724 |
) |
|
725 |
); |
|
726 |
||
727 |
register_post_status( |
|
728 |
'auto-draft', |
|
729 |
array( |
|
16 | 730 |
'label' => 'auto-draft', |
731 |
'internal' => true, |
|
732 |
'_builtin' => true, /* internal use only. */ |
|
733 |
'date_floating' => true, |
|
9 | 734 |
) |
735 |
); |
|
736 |
||
737 |
register_post_status( |
|
738 |
'inherit', |
|
739 |
array( |
|
740 |
'label' => 'inherit', |
|
741 |
'internal' => true, |
|
742 |
'_builtin' => true, /* internal use only. */ |
|
743 |
'exclude_from_search' => false, |
|
744 |
) |
|
745 |
); |
|
746 |
||
747 |
register_post_status( |
|
748 |
'request-pending', |
|
749 |
array( |
|
750 |
'label' => _x( 'Pending', 'request status' ), |
|
751 |
'internal' => true, |
|
752 |
'_builtin' => true, /* internal use only. */ |
|
16 | 753 |
/* translators: %s: Number of pending requests. */ |
754 |
'label_count' => _n_noop( |
|
755 |
'Pending <span class="count">(%s)</span>', |
|
756 |
'Pending <span class="count">(%s)</span>' |
|
757 |
), |
|
9 | 758 |
'exclude_from_search' => false, |
759 |
) |
|
760 |
); |
|
761 |
||
762 |
register_post_status( |
|
763 |
'request-confirmed', |
|
764 |
array( |
|
765 |
'label' => _x( 'Confirmed', 'request status' ), |
|
766 |
'internal' => true, |
|
767 |
'_builtin' => true, /* internal use only. */ |
|
16 | 768 |
/* translators: %s: Number of confirmed requests. */ |
769 |
'label_count' => _n_noop( |
|
770 |
'Confirmed <span class="count">(%s)</span>', |
|
771 |
'Confirmed <span class="count">(%s)</span>' |
|
772 |
), |
|
9 | 773 |
'exclude_from_search' => false, |
774 |
) |
|
775 |
); |
|
776 |
||
777 |
register_post_status( |
|
778 |
'request-failed', |
|
779 |
array( |
|
780 |
'label' => _x( 'Failed', 'request status' ), |
|
781 |
'internal' => true, |
|
782 |
'_builtin' => true, /* internal use only. */ |
|
16 | 783 |
/* translators: %s: Number of failed requests. */ |
784 |
'label_count' => _n_noop( |
|
785 |
'Failed <span class="count">(%s)</span>', |
|
786 |
'Failed <span class="count">(%s)</span>' |
|
787 |
), |
|
9 | 788 |
'exclude_from_search' => false, |
789 |
) |
|
790 |
); |
|
791 |
||
792 |
register_post_status( |
|
793 |
'request-completed', |
|
794 |
array( |
|
795 |
'label' => _x( 'Completed', 'request status' ), |
|
796 |
'internal' => true, |
|
797 |
'_builtin' => true, /* internal use only. */ |
|
16 | 798 |
/* translators: %s: Number of completed requests. */ |
799 |
'label_count' => _n_noop( |
|
800 |
'Completed <span class="count">(%s)</span>', |
|
801 |
'Completed <span class="count">(%s)</span>' |
|
802 |
), |
|
9 | 803 |
'exclude_from_search' => false, |
804 |
) |
|
805 |
); |
|
0 | 806 |
} |
807 |
||
808 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
809 |
* Retrieves attached file path based on attachment ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
810 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
811 |
* By default the path will go through the {@see 'get_attached_file'} filter, but |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
812 |
* passing `true` to the `$unfiltered` argument will return the file path unfiltered. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
813 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
814 |
* The function works by retrieving the `_wp_attached_file` post meta value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
815 |
* This is a convenience function to prevent looking up the meta name and provide |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
816 |
* a mechanism for sending the attached filename through a filter. |
0 | 817 |
* |
818 |
* @since 2.0.0 |
|
819 |
* |
|
5 | 820 |
* @param int $attachment_id Attachment ID. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
821 |
* @param bool $unfiltered Optional. Whether to skip the {@see 'get_attached_file'} filter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
822 |
* Default false. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
* @return string|false The file path to where the attached file should be, false otherwise. |
0 | 824 |
*/ |
825 |
function get_attached_file( $attachment_id, $unfiltered = false ) { |
|
826 |
$file = get_post_meta( $attachment_id, '_wp_attached_file', true ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
|
5 | 828 |
// If the file is relative, prepend upload dir. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
829 |
if ( $file && ! str_starts_with( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) ) { |
16 | 830 |
$uploads = wp_get_upload_dir(); |
831 |
if ( false === $uploads['error'] ) { |
|
832 |
$file = $uploads['basedir'] . "/$file"; |
|
833 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
if ( $unfiltered ) { |
0 | 837 |
return $file; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
} |
5 | 839 |
|
840 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
* Filters the attached file based on the given ID. |
5 | 842 |
* |
843 |
* @since 2.1.0 |
|
844 |
* |
|
16 | 845 |
* @param string|false $file The file path to where the attached file should be, false otherwise. |
846 |
* @param int $attachment_id Attachment ID. |
|
5 | 847 |
*/ |
0 | 848 |
return apply_filters( 'get_attached_file', $file, $attachment_id ); |
849 |
} |
|
850 |
||
851 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
852 |
* Updates attachment file path based on attachment ID. |
0 | 853 |
* |
854 |
* Used to update the file path of the attachment, which uses post meta name |
|
855 |
* '_wp_attached_file' to store the path of the attachment. |
|
856 |
* |
|
857 |
* @since 2.1.0 |
|
5 | 858 |
* |
859 |
* @param int $attachment_id Attachment ID. |
|
860 |
* @param string $file File path for the attachment. |
|
0 | 861 |
* @return bool True on success, false on failure. |
862 |
*/ |
|
863 |
function update_attached_file( $attachment_id, $file ) { |
|
9 | 864 |
if ( ! get_post( $attachment_id ) ) { |
0 | 865 |
return false; |
9 | 866 |
} |
0 | 867 |
|
5 | 868 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
* Filters the path to the attached file to update. |
5 | 870 |
* |
871 |
* @since 2.1.0 |
|
872 |
* |
|
873 |
* @param string $file Path to the attached file to update. |
|
874 |
* @param int $attachment_id Attachment ID. |
|
875 |
*/ |
|
0 | 876 |
$file = apply_filters( 'update_attached_file', $file, $attachment_id ); |
5 | 877 |
|
16 | 878 |
$file = _wp_relative_upload_path( $file ); |
879 |
if ( $file ) { |
|
0 | 880 |
return update_post_meta( $attachment_id, '_wp_attached_file', $file ); |
9 | 881 |
} else { |
0 | 882 |
return delete_post_meta( $attachment_id, '_wp_attached_file' ); |
9 | 883 |
} |
0 | 884 |
} |
885 |
||
886 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
887 |
* Returns relative path to an uploaded file. |
0 | 888 |
* |
889 |
* The path is relative to the current upload dir. |
|
890 |
* |
|
891 |
* @since 2.9.0 |
|
9 | 892 |
* @access private |
5 | 893 |
* |
894 |
* @param string $path Full path to the file. |
|
895 |
* @return string Relative path on success, unchanged path on failure. |
|
0 | 896 |
*/ |
897 |
function _wp_relative_upload_path( $path ) { |
|
898 |
$new_path = $path; |
|
899 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
$uploads = wp_get_upload_dir(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
901 |
if ( str_starts_with( $new_path, $uploads['basedir'] ) ) { |
0 | 902 |
$new_path = str_replace( $uploads['basedir'], '', $new_path ); |
903 |
$new_path = ltrim( $new_path, '/' ); |
|
904 |
} |
|
905 |
||
5 | 906 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
* Filters the relative path to an uploaded file. |
5 | 908 |
* |
909 |
* @since 2.9.0 |
|
910 |
* |
|
911 |
* @param string $new_path Relative path to the file. |
|
912 |
* @param string $path Full path to the file. |
|
913 |
*/ |
|
0 | 914 |
return apply_filters( '_wp_relative_upload_path', $new_path, $path ); |
915 |
} |
|
916 |
||
917 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
918 |
* Retrieves all children of the post parent ID. |
0 | 919 |
* |
920 |
* Normally, without any enhancements, the children would apply to pages. In the |
|
921 |
* context of the inner workings of WordPress, pages, posts, and attachments |
|
922 |
* share the same table, so therefore the functionality could apply to any one |
|
923 |
* of them. It is then noted that while this function does not work on posts, it |
|
924 |
* does not mean that it won't work on posts. It is recommended that you know |
|
925 |
* what context you wish to retrieve the children of. |
|
926 |
* |
|
927 |
* Attachments may also be made the child of a post, so if that is an accurate |
|
928 |
* statement (which needs to be verified), it would then be possible to get |
|
929 |
* all of the attachments for a post. Attachments have since changed since |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
* version 2.5, so this is most likely inaccurate, but serves generally as an |
0 | 931 |
* example of what is possible. |
932 |
* |
|
933 |
* The arguments listed as defaults are for this function and also of the |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
* get_posts() function. The arguments are combined with the get_children defaults |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
* and are then passed to the get_posts() function, which accepts additional arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
* You can replace the defaults in this function, listed below and the additional |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
* arguments listed in the get_posts() function. |
0 | 938 |
* |
939 |
* The 'post_parent' is the most important argument and important attention |
|
940 |
* needs to be paid to the $args parameter. If you pass either an object or an |
|
941 |
* integer (number), then just the 'post_parent' is grabbed and everything else |
|
942 |
* is lost. If you don't specify any arguments, then it is assumed that you are |
|
943 |
* in The Loop and the post parent will be grabbed for from the current post. |
|
944 |
* |
|
945 |
* The 'post_parent' argument is the ID to get the children. The 'numberposts' |
|
946 |
* is the amount of posts to retrieve that has a default of '-1', which is |
|
947 |
* used to get all of the posts. Giving a number higher than 0 will only |
|
948 |
* retrieve that amount of posts. |
|
949 |
* |
|
950 |
* The 'post_type' and 'post_status' arguments can be used to choose what |
|
951 |
* criteria of posts to retrieve. The 'post_type' can be anything, but WordPress |
|
952 |
* post types are 'post', 'pages', and 'attachments'. The 'post_status' |
|
953 |
* argument will accept any post status within the write administration panels. |
|
954 |
* |
|
955 |
* @since 2.0.0 |
|
956 |
* |
|
5 | 957 |
* @see get_posts() |
958 |
* @todo Check validity of description. |
|
959 |
* |
|
16 | 960 |
* @global WP_Post $post Global post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
* |
5 | 962 |
* @param mixed $args Optional. User defined arguments for replacing the defaults. Default empty. |
16 | 963 |
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
964 |
* correspond to a WP_Post object, an associative array, or a numeric array, |
|
965 |
* respectively. Default OBJECT. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
966 |
* @return WP_Post[]|array[]|int[] Array of post objects, arrays, or IDs, depending on `$output`. |
0 | 967 |
*/ |
5 | 968 |
function get_children( $args = '', $output = OBJECT ) { |
0 | 969 |
$kids = array(); |
970 |
if ( empty( $args ) ) { |
|
971 |
if ( isset( $GLOBALS['post'] ) ) { |
|
9 | 972 |
$args = array( 'post_parent' => (int) $GLOBALS['post']->post_parent ); |
0 | 973 |
} else { |
974 |
return $kids; |
|
975 |
} |
|
976 |
} elseif ( is_object( $args ) ) { |
|
9 | 977 |
$args = array( 'post_parent' => (int) $args->post_parent ); |
0 | 978 |
} elseif ( is_numeric( $args ) ) { |
9 | 979 |
$args = array( 'post_parent' => (int) $args ); |
0 | 980 |
} |
981 |
||
982 |
$defaults = array( |
|
9 | 983 |
'numberposts' => -1, |
984 |
'post_type' => 'any', |
|
985 |
'post_status' => 'any', |
|
986 |
'post_parent' => 0, |
|
0 | 987 |
); |
988 |
||
16 | 989 |
$parsed_args = wp_parse_args( $args, $defaults ); |
990 |
||
991 |
$children = get_posts( $parsed_args ); |
|
0 | 992 |
|
9 | 993 |
if ( ! $children ) { |
0 | 994 |
return $kids; |
9 | 995 |
} |
996 |
||
16 | 997 |
if ( ! empty( $parsed_args['fields'] ) ) { |
0 | 998 |
return $children; |
9 | 999 |
} |
1000 |
||
1001 |
update_post_cache( $children ); |
|
1002 |
||
1003 |
foreach ( $children as $key => $child ) { |
|
1004 |
$kids[ $child->ID ] = $children[ $key ]; |
|
1005 |
} |
|
0 | 1006 |
|
18 | 1007 |
if ( OBJECT === $output ) { |
0 | 1008 |
return $kids; |
18 | 1009 |
} elseif ( ARRAY_A === $output ) { |
5 | 1010 |
$weeuns = array(); |
1011 |
foreach ( (array) $kids as $kid ) { |
|
9 | 1012 |
$weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] ); |
5 | 1013 |
} |
0 | 1014 |
return $weeuns; |
18 | 1015 |
} elseif ( ARRAY_N === $output ) { |
5 | 1016 |
$babes = array(); |
1017 |
foreach ( (array) $kids as $kid ) { |
|
9 | 1018 |
$babes[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) ); |
5 | 1019 |
} |
0 | 1020 |
return $babes; |
1021 |
} else { |
|
1022 |
return $kids; |
|
1023 |
} |
|
1024 |
} |
|
1025 |
||
1026 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1027 |
* Gets extended entry info (<!--more-->). |
0 | 1028 |
* |
1029 |
* There should not be any space after the second dash and before the word |
|
1030 |
* 'more'. There can be text or space(s) after the word 'more', but won't be |
|
1031 |
* referenced. |
|
1032 |
* |
|
1033 |
* The returned array has 'main', 'extended', and 'more_text' keys. Main has the text before |
|
5 | 1034 |
* the `<!--more-->`. The 'extended' key has the content after the |
1035 |
* `<!--more-->` comment. The 'more_text' key has the custom "Read More" text. |
|
0 | 1036 |
* |
1037 |
* @since 1.0.0 |
|
1038 |
* |
|
1039 |
* @param string $post Post content. |
|
16 | 1040 |
* @return string[] { |
1041 |
* Extended entry info. |
|
1042 |
* |
|
1043 |
* @type string $main Content before the more tag. |
|
1044 |
* @type string $extended Content after the more tag. |
|
1045 |
* @type string $more_text Custom read more text, or empty string. |
|
1046 |
* } |
|
0 | 1047 |
*/ |
5 | 1048 |
function get_extended( $post ) { |
16 | 1049 |
// Match the new style more links. |
9 | 1050 |
if ( preg_match( '/<!--more(.*?)?-->/', $post, $matches ) ) { |
1051 |
list($main, $extended) = explode( $matches[0], $post, 2 ); |
|
1052 |
$more_text = $matches[1]; |
|
0 | 1053 |
} else { |
9 | 1054 |
$main = $post; |
1055 |
$extended = ''; |
|
0 | 1056 |
$more_text = ''; |
1057 |
} |
|
1058 |
||
16 | 1059 |
// Leading and trailing whitespace. |
9 | 1060 |
$main = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $main ); |
1061 |
$extended = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $extended ); |
|
1062 |
$more_text = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $more_text ); |
|
1063 |
||
1064 |
return array( |
|
1065 |
'main' => $main, |
|
1066 |
'extended' => $extended, |
|
1067 |
'more_text' => $more_text, |
|
1068 |
); |
|
0 | 1069 |
} |
1070 |
||
1071 |
/** |
|
1072 |
* Retrieves post data given a post ID or post object. |
|
1073 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
* See sanitize_post() for optional $filter values. Also, the parameter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
* `$post`, must be given as a variable, since it is passed by reference. |
0 | 1076 |
* |
1077 |
* @since 1.5.1 |
|
5 | 1078 |
* |
16 | 1079 |
* @global WP_Post $post Global post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
* |
19 | 1081 |
* @param int|WP_Post|null $post Optional. Post ID or post object. `null`, `false`, `0` and other PHP falsey values |
1082 |
* return the current global post inside the loop. A numerically valid post ID that |
|
1083 |
* points to a non-existent post returns `null`. Defaults to global $post. |
|
16 | 1084 |
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
1085 |
* correspond to a WP_Post object, an associative array, or a numeric array, |
|
1086 |
* respectively. Default OBJECT. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
* @param string $filter Optional. Type of filter to apply. Accepts 'raw', 'edit', 'db', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
* or 'display'. Default 'raw'. |
5 | 1089 |
* @return WP_Post|array|null Type corresponding to $output on success or null on failure. |
1090 |
* When $output is OBJECT, a `WP_Post` instance is returned. |
|
0 | 1091 |
*/ |
1092 |
function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { |
|
9 | 1093 |
if ( empty( $post ) && isset( $GLOBALS['post'] ) ) { |
0 | 1094 |
$post = $GLOBALS['post']; |
9 | 1095 |
} |
0 | 1096 |
|
5 | 1097 |
if ( $post instanceof WP_Post ) { |
0 | 1098 |
$_post = $post; |
1099 |
} elseif ( is_object( $post ) ) { |
|
1100 |
if ( empty( $post->filter ) ) { |
|
1101 |
$_post = sanitize_post( $post, 'raw' ); |
|
1102 |
$_post = new WP_Post( $_post ); |
|
16 | 1103 |
} elseif ( 'raw' === $post->filter ) { |
0 | 1104 |
$_post = new WP_Post( $post ); |
1105 |
} else { |
|
1106 |
$_post = WP_Post::get_instance( $post->ID ); |
|
1107 |
} |
|
1108 |
} else { |
|
1109 |
$_post = WP_Post::get_instance( $post ); |
|
1110 |
} |
|
1111 |
||
9 | 1112 |
if ( ! $_post ) { |
0 | 1113 |
return null; |
9 | 1114 |
} |
0 | 1115 |
|
1116 |
$_post = $_post->filter( $filter ); |
|
1117 |
||
18 | 1118 |
if ( ARRAY_A === $output ) { |
0 | 1119 |
return $_post->to_array(); |
18 | 1120 |
} elseif ( ARRAY_N === $output ) { |
0 | 1121 |
return array_values( $_post->to_array() ); |
9 | 1122 |
} |
0 | 1123 |
|
1124 |
return $_post; |
|
1125 |
} |
|
1126 |
||
1127 |
/** |
|
18 | 1128 |
* Retrieves the IDs of the ancestors of a post. |
0 | 1129 |
* |
1130 |
* @since 2.5.0 |
|
1131 |
* |
|
5 | 1132 |
* @param int|WP_Post $post Post ID or post object. |
18 | 1133 |
* @return int[] Array of ancestor IDs or empty array if there are none. |
0 | 1134 |
*/ |
1135 |
function get_post_ancestors( $post ) { |
|
1136 |
$post = get_post( $post ); |
|
1137 |
||
9 | 1138 |
if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) { |
0 | 1139 |
return array(); |
9 | 1140 |
} |
0 | 1141 |
|
1142 |
$ancestors = array(); |
|
1143 |
||
16 | 1144 |
$id = $post->post_parent; |
1145 |
$ancestors[] = $id; |
|
0 | 1146 |
|
1147 |
while ( $ancestor = get_post( $id ) ) { |
|
1148 |
// Loop detection: If the ancestor has been seen before, break. |
|
16 | 1149 |
if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors, true ) ) { |
0 | 1150 |
break; |
9 | 1151 |
} |
0 | 1152 |
|
16 | 1153 |
$id = $ancestor->post_parent; |
1154 |
$ancestors[] = $id; |
|
0 | 1155 |
} |
1156 |
||
1157 |
return $ancestors; |
|
1158 |
} |
|
1159 |
||
1160 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1161 |
* Retrieves data from a post field based on Post ID. |
0 | 1162 |
* |
1163 |
* Examples of the post field will be, 'post_type', 'post_status', 'post_content', |
|
1164 |
* etc and based off of the post object property or key names. |
|
1165 |
* |
|
1166 |
* The context values are based off of the taxonomy filter functions and |
|
1167 |
* supported values are found within those functions. |
|
1168 |
* |
|
1169 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
* @since 4.5.0 The `$post` parameter was made optional. |
5 | 1171 |
* |
1172 |
* @see sanitize_post_field() |
|
1173 |
* |
|
1174 |
* @param string $field Post field name. |
|
9 | 1175 |
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post. |
5 | 1176 |
* @param string $context Optional. How to filter the field. Accepts 'raw', 'edit', 'db', |
1177 |
* or 'display'. Default 'display'. |
|
0 | 1178 |
* @return string The value of the post field on success, empty string on failure. |
1179 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
function get_post_field( $field, $post = null, $context = 'display' ) { |
0 | 1181 |
$post = get_post( $post ); |
1182 |
||
9 | 1183 |
if ( ! $post ) { |
0 | 1184 |
return ''; |
9 | 1185 |
} |
1186 |
||
1187 |
if ( ! isset( $post->$field ) ) { |
|
0 | 1188 |
return ''; |
9 | 1189 |
} |
1190 |
||
1191 |
return sanitize_post_field( $field, $post->$field, $post->ID, $context ); |
|
0 | 1192 |
} |
1193 |
||
1194 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1195 |
* Retrieves the mime type of an attachment based on the ID. |
0 | 1196 |
* |
1197 |
* This function can be used with any post type, but it makes more sense with |
|
1198 |
* attachments. |
|
1199 |
* |
|
1200 |
* @since 2.0.0 |
|
1201 |
* |
|
9 | 1202 |
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post. |
5 | 1203 |
* @return string|false The mime type on success, false on failure. |
0 | 1204 |
*/ |
9 | 1205 |
function get_post_mime_type( $post = null ) { |
1206 |
$post = get_post( $post ); |
|
1207 |
||
1208 |
if ( is_object( $post ) ) { |
|
0 | 1209 |
return $post->post_mime_type; |
9 | 1210 |
} |
0 | 1211 |
|
1212 |
return false; |
|
1213 |
} |
|
1214 |
||
1215 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1216 |
* Retrieves the post status based on the post ID. |
0 | 1217 |
* |
1218 |
* If the post ID is of an attachment, then the parent post status will be given |
|
1219 |
* instead. |
|
1220 |
* |
|
1221 |
* @since 2.0.0 |
|
1222 |
* |
|
19 | 1223 |
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post. |
5 | 1224 |
* @return string|false Post status on success, false on failure. |
0 | 1225 |
*/ |
9 | 1226 |
function get_post_status( $post = null ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1227 |
// Normalize the post object if necessary, skip normalization if called from get_sample_permalink(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1228 |
if ( ! $post instanceof WP_Post || ! isset( $post->filter ) || 'sample' !== $post->filter ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1229 |
$post = get_post( $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1230 |
} |
9 | 1231 |
|
1232 |
if ( ! is_object( $post ) ) { |
|
0 | 1233 |
return false; |
9 | 1234 |
} |
0 | 1235 |
|
18 | 1236 |
$post_status = $post->post_status; |
1237 |
||
1238 |
if ( |
|
1239 |
'attachment' === $post->post_type && |
|
1240 |
'inherit' === $post_status |
|
1241 |
) { |
|
1242 |
if ( |
|
1243 |
0 === $post->post_parent || |
|
1244 |
! get_post( $post->post_parent ) || |
|
1245 |
$post->ID === $post->post_parent |
|
1246 |
) { |
|
1247 |
// Unattached attachments with inherit status are assumed to be published. |
|
1248 |
$post_status = 'publish'; |
|
1249 |
} elseif ( 'trash' === get_post_status( $post->post_parent ) ) { |
|
1250 |
// Get parent status prior to trashing. |
|
1251 |
$post_status = get_post_meta( $post->post_parent, '_wp_trash_meta_status', true ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1252 |
|
18 | 1253 |
if ( ! $post_status ) { |
1254 |
// Assume publish as above. |
|
1255 |
$post_status = 'publish'; |
|
1256 |
} |
|
1257 |
} else { |
|
1258 |
$post_status = get_post_status( $post->post_parent ); |
|
9 | 1259 |
} |
18 | 1260 |
} elseif ( |
1261 |
'attachment' === $post->post_type && |
|
1262 |
! in_array( $post_status, array( 'private', 'trash', 'auto-draft' ), true ) |
|
1263 |
) { |
|
1264 |
/* |
|
1265 |
* Ensure uninherited attachments have a permitted status either 'private', 'trash', 'auto-draft'. |
|
1266 |
* This is to match the logic in wp_insert_post(). |
|
1267 |
* |
|
1268 |
* Note: 'inherit' is excluded from this check as it is resolved to the parent post's |
|
1269 |
* status in the logic block above. |
|
1270 |
*/ |
|
1271 |
$post_status = 'publish'; |
|
0 | 1272 |
} |
1273 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1274 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1275 |
* Filters the post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1276 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
* @since 4.4.0 |
18 | 1278 |
* @since 5.7.0 The attachment post type is now passed through this filter. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
* @param string $post_status The post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
* @param WP_Post $post The post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
*/ |
18 | 1283 |
return apply_filters( 'get_post_status', $post_status, $post ); |
0 | 1284 |
} |
1285 |
||
1286 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1287 |
* Retrieves all of the WordPress supported post statuses. |
0 | 1288 |
* |
1289 |
* Posts have a limited set of valid status values, this provides the |
|
1290 |
* post_status values and descriptions. |
|
1291 |
* |
|
1292 |
* @since 2.5.0 |
|
1293 |
* |
|
16 | 1294 |
* @return string[] Array of post status labels keyed by their status. |
0 | 1295 |
*/ |
1296 |
function get_post_statuses() { |
|
1297 |
$status = array( |
|
5 | 1298 |
'draft' => __( 'Draft' ), |
1299 |
'pending' => __( 'Pending Review' ), |
|
1300 |
'private' => __( 'Private' ), |
|
9 | 1301 |
'publish' => __( 'Published' ), |
0 | 1302 |
); |
1303 |
||
1304 |
return $status; |
|
1305 |
} |
|
1306 |
||
1307 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1308 |
* Retrieves all of the WordPress support page statuses. |
0 | 1309 |
* |
1310 |
* Pages have a limited set of valid status values, this provides the |
|
1311 |
* post_status values and descriptions. |
|
1312 |
* |
|
1313 |
* @since 2.5.0 |
|
1314 |
* |
|
16 | 1315 |
* @return string[] Array of page status labels keyed by their status. |
0 | 1316 |
*/ |
1317 |
function get_page_statuses() { |
|
1318 |
$status = array( |
|
5 | 1319 |
'draft' => __( 'Draft' ), |
1320 |
'private' => __( 'Private' ), |
|
9 | 1321 |
'publish' => __( 'Published' ), |
0 | 1322 |
); |
1323 |
||
1324 |
return $status; |
|
1325 |
} |
|
1326 |
||
1327 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1328 |
* Returns statuses for privacy requests. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
* |
9 | 1330 |
* @since 4.9.6 |
1331 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1333 |
* @return string[] Array of privacy request status labels keyed by their status. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
function _wp_privacy_statuses() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
return array( |
16 | 1337 |
'request-pending' => _x( 'Pending', 'request status' ), // Pending confirmation from user. |
1338 |
'request-confirmed' => _x( 'Confirmed', 'request status' ), // User has confirmed the action. |
|
1339 |
'request-failed' => _x( 'Failed', 'request status' ), // User failed to confirm the action. |
|
1340 |
'request-completed' => _x( 'Completed', 'request status' ), // Admin has handled the request. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1345 |
* Registers a post status. Do not use before init. |
0 | 1346 |
* |
1347 |
* A simple function for creating or modifying a post status based on the |
|
1348 |
* parameters given. The function will accept an array (second optional |
|
1349 |
* parameter), along with a string for the post status name. |
|
1350 |
* |
|
1351 |
* Arguments prefixed with an _underscore shouldn't be used by plugins and themes. |
|
1352 |
* |
|
1353 |
* @since 3.0.0 |
|
16 | 1354 |
* |
19 | 1355 |
* @global stdClass[] $wp_post_statuses Inserts new post status object into the list |
0 | 1356 |
* |
16 | 1357 |
* @param string $post_status Name of the post status. |
5 | 1358 |
* @param array|string $args { |
1359 |
* Optional. Array or string of post status arguments. |
|
1360 |
* |
|
1361 |
* @type bool|string $label A descriptive name for the post status marked |
|
1362 |
* for translation. Defaults to value of $post_status. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1363 |
* @type array|false $label_count Nooped plural text from _n_noop() to provide the singular |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1364 |
* and plural forms of the label for counts. Default false |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1365 |
* which means the `$label` argument will be used for both |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1366 |
* the singular and plural forms of this label. |
5 | 1367 |
* @type bool $exclude_from_search Whether to exclude posts with this post status |
1368 |
* from search results. Default is value of $internal. |
|
1369 |
* @type bool $_builtin Whether the status is built-in. Core-use only. |
|
1370 |
* Default false. |
|
1371 |
* @type bool $public Whether posts of this status should be shown |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
* in the front end of the site. Default false. |
5 | 1373 |
* @type bool $internal Whether the status is for internal use only. |
1374 |
* Default false. |
|
1375 |
* @type bool $protected Whether posts with this status should be protected. |
|
1376 |
* Default false. |
|
1377 |
* @type bool $private Whether posts with this status should be private. |
|
1378 |
* Default false. |
|
1379 |
* @type bool $publicly_queryable Whether posts with this status should be publicly- |
|
1380 |
* queryable. Default is value of $public. |
|
1381 |
* @type bool $show_in_admin_all_list Whether to include posts in the edit listing for |
|
16 | 1382 |
* their post type. Default is the opposite value |
1383 |
* of $internal. |
|
5 | 1384 |
* @type bool $show_in_admin_status_list Show in the list of statuses with post counts at |
1385 |
* the top of the edit listings, |
|
1386 |
* e.g. All (12) | Published (9) | My Custom Status (2) |
|
16 | 1387 |
* Default is the opposite value of $internal. |
1388 |
* @type bool $date_floating Whether the post has a floating creation date. |
|
1389 |
* Default to false. |
|
5 | 1390 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
* @return object |
0 | 1392 |
*/ |
5 | 1393 |
function register_post_status( $post_status, $args = array() ) { |
0 | 1394 |
global $wp_post_statuses; |
1395 |
||
9 | 1396 |
if ( ! is_array( $wp_post_statuses ) ) { |
0 | 1397 |
$wp_post_statuses = array(); |
9 | 1398 |
} |
0 | 1399 |
|
1400 |
// Args prefixed with an underscore are reserved for internal use. |
|
1401 |
$defaults = array( |
|
9 | 1402 |
'label' => false, |
1403 |
'label_count' => false, |
|
1404 |
'exclude_from_search' => null, |
|
1405 |
'_builtin' => false, |
|
1406 |
'public' => null, |
|
1407 |
'internal' => null, |
|
1408 |
'protected' => null, |
|
1409 |
'private' => null, |
|
1410 |
'publicly_queryable' => null, |
|
0 | 1411 |
'show_in_admin_status_list' => null, |
9 | 1412 |
'show_in_admin_all_list' => null, |
16 | 1413 |
'date_floating' => null, |
0 | 1414 |
); |
9 | 1415 |
$args = wp_parse_args( $args, $defaults ); |
1416 |
$args = (object) $args; |
|
1417 |
||
1418 |
$post_status = sanitize_key( $post_status ); |
|
1419 |
$args->name = $post_status; |
|
0 | 1420 |
|
5 | 1421 |
// Set various defaults. |
9 | 1422 |
if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) { |
0 | 1423 |
$args->internal = true; |
9 | 1424 |
} |
1425 |
||
1426 |
if ( null === $args->public ) { |
|
0 | 1427 |
$args->public = false; |
9 | 1428 |
} |
1429 |
||
1430 |
if ( null === $args->private ) { |
|
0 | 1431 |
$args->private = false; |
9 | 1432 |
} |
1433 |
||
1434 |
if ( null === $args->protected ) { |
|
0 | 1435 |
$args->protected = false; |
9 | 1436 |
} |
1437 |
||
1438 |
if ( null === $args->internal ) { |
|
0 | 1439 |
$args->internal = false; |
9 | 1440 |
} |
1441 |
||
1442 |
if ( null === $args->publicly_queryable ) { |
|
0 | 1443 |
$args->publicly_queryable = $args->public; |
9 | 1444 |
} |
1445 |
||
1446 |
if ( null === $args->exclude_from_search ) { |
|
0 | 1447 |
$args->exclude_from_search = $args->internal; |
9 | 1448 |
} |
1449 |
||
1450 |
if ( null === $args->show_in_admin_all_list ) { |
|
1451 |
$args->show_in_admin_all_list = ! $args->internal; |
|
1452 |
} |
|
1453 |
||
1454 |
if ( null === $args->show_in_admin_status_list ) { |
|
1455 |
$args->show_in_admin_status_list = ! $args->internal; |
|
1456 |
} |
|
1457 |
||
16 | 1458 |
if ( null === $args->date_floating ) { |
1459 |
$args->date_floating = false; |
|
1460 |
} |
|
1461 |
||
9 | 1462 |
if ( false === $args->label ) { |
0 | 1463 |
$args->label = $post_status; |
9 | 1464 |
} |
1465 |
||
1466 |
if ( false === $args->label_count ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1467 |
// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralSingular,WordPress.WP.I18n.NonSingularStringLiteralPlural |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
$args->label_count = _n_noop( $args->label, $args->label ); |
9 | 1469 |
} |
1470 |
||
1471 |
$wp_post_statuses[ $post_status ] = $args; |
|
0 | 1472 |
|
1473 |
return $args; |
|
1474 |
} |
|
1475 |
||
1476 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1477 |
* Retrieves a post status object by name. |
5 | 1478 |
* |
0 | 1479 |
* @since 3.0.0 |
5 | 1480 |
* |
19 | 1481 |
* @global stdClass[] $wp_post_statuses List of post statuses. |
5 | 1482 |
* |
1483 |
* @see register_post_status() |
|
1484 |
* |
|
1485 |
* @param string $post_status The name of a registered post status. |
|
19 | 1486 |
* @return stdClass|null A post status object. |
0 | 1487 |
*/ |
1488 |
function get_post_status_object( $post_status ) { |
|
1489 |
global $wp_post_statuses; |
|
1490 |
||
9 | 1491 |
if ( empty( $wp_post_statuses[ $post_status ] ) ) { |
0 | 1492 |
return null; |
9 | 1493 |
} |
1494 |
||
1495 |
return $wp_post_statuses[ $post_status ]; |
|
0 | 1496 |
} |
1497 |
||
1498 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1499 |
* Gets a list of post statuses. |
5 | 1500 |
* |
0 | 1501 |
* @since 3.0.0 |
5 | 1502 |
* |
19 | 1503 |
* @global stdClass[] $wp_post_statuses List of post statuses. |
5 | 1504 |
* |
1505 |
* @see register_post_status() |
|
1506 |
* |
|
1507 |
* @param array|string $args Optional. Array or string of post status arguments to compare against |
|
1508 |
* properties of the global `$wp_post_statuses objects`. Default empty array. |
|
1509 |
* @param string $output Optional. The type of output to return, either 'names' or 'objects'. Default 'names'. |
|
1510 |
* @param string $operator Optional. The logical operation to perform. 'or' means only one element |
|
1511 |
* from the array needs to match; 'and' means all elements must match. |
|
1512 |
* Default 'and'. |
|
19 | 1513 |
* @return string[]|stdClass[] A list of post status names or objects. |
0 | 1514 |
*/ |
1515 |
function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) { |
|
1516 |
global $wp_post_statuses; |
|
1517 |
||
16 | 1518 |
$field = ( 'names' === $output ) ? 'name' : false; |
9 | 1519 |
|
1520 |
return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field ); |
|
0 | 1521 |
} |
1522 |
||
1523 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1524 |
* Determines whether the post type is hierarchical. |
0 | 1525 |
* |
1526 |
* A false return value might also mean that the post type does not exist. |
|
1527 |
* |
|
1528 |
* @since 3.0.0 |
|
5 | 1529 |
* |
1530 |
* @see get_post_type_object() |
|
0 | 1531 |
* |
1532 |
* @param string $post_type Post type name |
|
1533 |
* @return bool Whether post type is hierarchical. |
|
1534 |
*/ |
|
1535 |
function is_post_type_hierarchical( $post_type ) { |
|
9 | 1536 |
if ( ! post_type_exists( $post_type ) ) { |
0 | 1537 |
return false; |
9 | 1538 |
} |
0 | 1539 |
|
1540 |
$post_type = get_post_type_object( $post_type ); |
|
1541 |
return $post_type->hierarchical; |
|
1542 |
} |
|
1543 |
||
1544 |
/** |
|
9 | 1545 |
* Determines whether a post type is registered. |
1546 |
* |
|
1547 |
* For more information on this and similar theme functions, check out |
|
1548 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1549 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 1550 |
* |
1551 |
* @since 3.0.0 |
|
5 | 1552 |
* |
1553 |
* @see get_post_type_object() |
|
1554 |
* |
|
1555 |
* @param string $post_type Post type name. |
|
0 | 1556 |
* @return bool Whether post type is registered. |
1557 |
*/ |
|
1558 |
function post_type_exists( $post_type ) { |
|
1559 |
return (bool) get_post_type_object( $post_type ); |
|
1560 |
} |
|
1561 |
||
1562 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
* Retrieves the post type of the current post or of a given post. |
0 | 1564 |
* |
1565 |
* @since 2.1.0 |
|
1566 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1567 |
* @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1568 |
* @return string|false Post type on success, false on failure. |
0 | 1569 |
*/ |
1570 |
function get_post_type( $post = null ) { |
|
16 | 1571 |
$post = get_post( $post ); |
1572 |
if ( $post ) { |
|
0 | 1573 |
return $post->post_type; |
9 | 1574 |
} |
0 | 1575 |
|
1576 |
return false; |
|
1577 |
} |
|
1578 |
||
1579 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
* Retrieves a post type object by name. |
5 | 1581 |
* |
0 | 1582 |
* @since 3.0.0 |
9 | 1583 |
* @since 4.6.0 Object returned is now an instance of `WP_Post_Type`. |
5 | 1584 |
* |
1585 |
* @global array $wp_post_types List of post types. |
|
1586 |
* |
|
1587 |
* @see register_post_type() |
|
1588 |
* |
|
1589 |
* @param string $post_type The name of a registered post type. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
* @return WP_Post_Type|null WP_Post_Type object if it exists, null otherwise. |
0 | 1591 |
*/ |
1592 |
function get_post_type_object( $post_type ) { |
|
1593 |
global $wp_post_types; |
|
1594 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
if ( ! is_scalar( $post_type ) || empty( $wp_post_types[ $post_type ] ) ) { |
0 | 1596 |
return null; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1598 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1599 |
return $wp_post_types[ $post_type ]; |
0 | 1600 |
} |
1601 |
||
1602 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1603 |
* Gets a list of all registered post type objects. |
0 | 1604 |
* |
1605 |
* @since 2.9.0 |
|
5 | 1606 |
* |
1607 |
* @global array $wp_post_types List of post types. |
|
1608 |
* |
|
1609 |
* @see register_post_type() for accepted arguments. |
|
1610 |
* |
|
1611 |
* @param array|string $args Optional. An array of key => value arguments to match against |
|
1612 |
* the post type objects. Default empty array. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1613 |
* @param string $output Optional. The type of output to return. Either 'names' |
5 | 1614 |
* or 'objects'. Default 'names'. |
1615 |
* @param string $operator Optional. The logical operation to perform. 'or' means only one |
|
1616 |
* element from the array needs to match; 'and' means all elements |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1617 |
* must match; 'not' means no elements may match. Default 'and'. |
9 | 1618 |
* @return string[]|WP_Post_Type[] An array of post type names or objects. |
0 | 1619 |
*/ |
1620 |
function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) { |
|
1621 |
global $wp_post_types; |
|
1622 |
||
16 | 1623 |
$field = ( 'names' === $output ) ? 'name' : false; |
9 | 1624 |
|
1625 |
return wp_filter_object_list( $wp_post_types, $args, $operator, $field ); |
|
0 | 1626 |
} |
1627 |
||
1628 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
* Registers a post type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1630 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
* Note: Post type registrations should not be hooked before the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1632 |
* {@see 'init'} action. Also, any taxonomy connections should be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1633 |
* registered via the `$taxonomies` argument to ensure consistency |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1634 |
* when hooks such as {@see 'parse_query'} or {@see 'pre_get_posts'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1635 |
* are used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1636 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
* Post types can support any number of built-in core features such |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
* as meta boxes, custom fields, post thumbnails, post statuses, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1639 |
* comments, and more. See the `$supports` argument for a complete |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1640 |
* list of supported features. |
0 | 1641 |
* |
1642 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1643 |
* @since 3.0.0 The `show_ui` argument is now enforced on the new post screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1644 |
* @since 4.4.0 The `show_ui` argument is now enforced on the post type listing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1645 |
* screen and post editing screen. |
9 | 1646 |
* @since 4.6.0 Post type object returned is now an instance of `WP_Post_Type`. |
1647 |
* @since 4.7.0 Introduced `show_in_rest`, `rest_base` and `rest_controller_class` |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1648 |
* arguments to register the post type in REST API. |
18 | 1649 |
* @since 5.0.0 The `template` and `template_lock` arguments were added. |
16 | 1650 |
* @since 5.3.0 The `supports` argument will now accept an array of arguments for a feature. |
19 | 1651 |
* @since 5.9.0 The `rest_namespace` argument was added. |
18 | 1652 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1653 |
* @global array $wp_post_types List of post types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1654 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1655 |
* @param string $post_type Post type key. Must not exceed 20 characters and may only contain |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1656 |
* lowercase alphanumeric characters, dashes, and underscores. See sanitize_key(). |
5 | 1657 |
* @param array|string $args { |
1658 |
* Array or string of arguments for registering a post type. |
|
1659 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1660 |
* @type string $label Name of the post type shown in the menu. Usually plural. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1661 |
* Default is value of $labels['name']. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1662 |
* @type string[] $labels An array of labels for this post type. If not set, post |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1663 |
* labels are inherited for non-hierarchical types and page |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1664 |
* labels for hierarchical ones. See get_post_type_labels() for a full |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1665 |
* list of supported labels. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1666 |
* @type string $description A short descriptive summary of what the post type is. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1667 |
* Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1668 |
* @type bool $public Whether a post type is intended for use publicly either via |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1669 |
* the admin interface or by front-end users. While the default |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1670 |
* settings of $exclude_from_search, $publicly_queryable, $show_ui, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1671 |
* and $show_in_nav_menus are inherited from $public, each does not |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1672 |
* rely on this relationship and controls a very specific intention. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1673 |
* Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1674 |
* @type bool $hierarchical Whether the post type is hierarchical (e.g. page). Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1675 |
* @type bool $exclude_from_search Whether to exclude posts with this post type from front end search |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1676 |
* results. Default is the opposite value of $public. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1677 |
* @type bool $publicly_queryable Whether queries can be performed on the front end for the post type |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1678 |
* as part of parse_request(). Endpoints would include: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1679 |
* * ?post_type={post_type_key} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1680 |
* * ?{post_type_key}={single_post_slug} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1681 |
* * ?{post_type_query_var}={single_post_slug} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1682 |
* If not set, the default is inherited from $public. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1683 |
* @type bool $show_ui Whether to generate and allow a UI for managing this post type in the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1684 |
* admin. Default is value of $public. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1685 |
* @type bool|string $show_in_menu Where to show the post type in the admin menu. To work, $show_ui |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1686 |
* must be true. If true, the post type is shown in its own top level |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1687 |
* menu. If false, no menu is shown. If a string of an existing top |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1688 |
* level menu ('tools.php' or 'edit.php?post_type=page', for example), the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1689 |
* post type will be placed as a sub-menu of that. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1690 |
* Default is value of $show_ui. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1691 |
* @type bool $show_in_nav_menus Makes this post type available for selection in navigation menus. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1692 |
* Default is value of $public. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1693 |
* @type bool $show_in_admin_bar Makes this post type available via the admin bar. Default is value |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1694 |
* of $show_in_menu. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1695 |
* @type bool $show_in_rest Whether to include the post type in the REST API. Set this to true |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1696 |
* for the post type to be available in the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1697 |
* @type string $rest_base To change the base URL of REST API route. Default is $post_type. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1698 |
* @type string $rest_namespace To change the namespace URL of REST API route. Default is wp/v2. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1699 |
* @type string $rest_controller_class REST API controller class name. Default is 'WP_REST_Posts_Controller'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1700 |
* @type string|bool $autosave_rest_controller_class REST API controller class name. Default is 'WP_REST_Autosaves_Controller'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1701 |
* @type string|bool $revisions_rest_controller_class REST API controller class name. Default is 'WP_REST_Revisions_Controller'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1702 |
* @type bool $late_route_registration A flag to direct the REST API controllers for autosave / revisions |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1703 |
* should be registered before/after the post type controller. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1704 |
* @type int $menu_position The position in the menu order the post type should appear. To work, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1705 |
* $show_in_menu must be true. Default null (at the bottom). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1706 |
* @type string $menu_icon The URL to the icon to be used for this menu. Pass a base64-encoded |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1707 |
* SVG using a data URI, which will be colored to match the color scheme |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1708 |
* -- this should begin with 'data:image/svg+xml;base64,'. Pass the name |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1709 |
* of a Dashicons helper class to use a font icon, e.g. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1710 |
* 'dashicons-chart-pie'. Pass 'none' to leave div.wp-menu-image empty |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1711 |
* so an icon can be added via CSS. Defaults to use the posts icon. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1712 |
* @type string|array $capability_type The string to use to build the read, edit, and delete capabilities. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1713 |
* May be passed as an array to allow for alternative plurals when using |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1714 |
* this argument as a base to construct the capabilities, e.g. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1715 |
* array('story', 'stories'). Default 'post'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1716 |
* @type string[] $capabilities Array of capabilities for this post type. $capability_type is used |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1717 |
* as a base to construct capabilities by default. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1718 |
* See get_post_type_capabilities(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1719 |
* @type bool $map_meta_cap Whether to use the internal default meta capability handling. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1720 |
* Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1721 |
* @type array|false $supports Core feature(s) the post type supports. Serves as an alias for calling |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1722 |
* add_post_type_support() directly. Core features include 'title', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1723 |
* 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1724 |
* 'page-attributes', 'thumbnail', 'custom-fields', and 'post-formats'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1725 |
* Additionally, the 'revisions' feature dictates whether the post type |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1726 |
* will store revisions, the 'autosave' feature dictates whether the post type |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1727 |
* will be autosaved, and the 'comments' feature dictates whether the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1728 |
* comments count will show on the edit screen. For backward compatibility reasons, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1729 |
* adding 'editor' support implies 'autosave' support too. A feature can also be |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1730 |
* specified as an array of arguments to provide additional information |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1731 |
* about supporting that feature. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1732 |
* Example: `array( 'my_feature', array( 'field' => 'value' ) )`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1733 |
* If false, no features will be added. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1734 |
* Default is an array containing 'title' and 'editor'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1735 |
* @type callable $register_meta_box_cb Provide a callback function that sets up the meta boxes for the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1736 |
* edit form. Do remove_meta_box() and add_meta_box() calls in the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1737 |
* callback. Default null. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1738 |
* @type string[] $taxonomies An array of taxonomy identifiers that will be registered for the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1739 |
* post type. Taxonomies can be registered later with register_taxonomy() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1740 |
* or register_taxonomy_for_object_type(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1741 |
* Default empty array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1742 |
* @type bool|string $has_archive Whether there should be post type archives, or if a string, the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1743 |
* archive slug to use. Will generate the proper rewrite rules if |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1744 |
* $rewrite is enabled. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1745 |
* @type bool|array $rewrite { |
5 | 1746 |
* Triggers the handling of rewrites for this post type. To prevent rewrite, set to false. |
1747 |
* Defaults to true, using $post_type as slug. To specify rewrite rules, an array can be |
|
1748 |
* passed with any of these keys: |
|
1749 |
* |
|
1750 |
* @type string $slug Customize the permastruct slug. Defaults to $post_type key. |
|
1751 |
* @type bool $with_front Whether the permastruct should be prepended with WP_Rewrite::$front. |
|
1752 |
* Default true. |
|
1753 |
* @type bool $feeds Whether the feed permastruct should be built for this post type. |
|
1754 |
* Default is value of $has_archive. |
|
1755 |
* @type bool $pages Whether the permastruct should provide for pagination. Default true. |
|
18 | 1756 |
* @type int $ep_mask Endpoint mask to assign. If not specified and permalink_epmask is set, |
5 | 1757 |
* inherits from $permalink_epmask. If not specified and permalink_epmask |
1758 |
* is not set, defaults to EP_PERMALINK. |
|
1759 |
* } |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1760 |
* @type string|bool $query_var Sets the query_var key for this post type. Defaults to $post_type |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1761 |
* key. If false, a post type cannot be loaded at |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1762 |
* ?{query_var}={post_slug}. If specified as a string, the query |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1763 |
* ?{query_var_string}={post_slug} will be valid. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1764 |
* @type bool $can_export Whether to allow this post type to be exported. Default true. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1765 |
* @type bool $delete_with_user Whether to delete posts of this type when deleting a user. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1766 |
* * If true, posts of this type belonging to the user will be moved |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1767 |
* to Trash when the user is deleted. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1768 |
* * If false, posts of this type belonging to the user will *not* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1769 |
* be trashed or deleted. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1770 |
* * If not set (the default), posts are trashed if post type supports |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1771 |
* the 'author' feature. Otherwise posts are not trashed or deleted. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1772 |
* Default null. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1773 |
* @type array $template Array of blocks to use as the default initial state for an editor |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1774 |
* session. Each item should be an array containing block name and |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1775 |
* optional attributes. Default empty array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1776 |
* @type string|false $template_lock Whether the block template should be locked if $template is set. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1777 |
* * If set to 'all', the user is unable to insert new blocks, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1778 |
* move existing blocks and delete blocks. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1779 |
* * If set to 'insert', the user is able to move existing blocks |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1780 |
* but is unable to insert new blocks and delete blocks. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1781 |
* Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1782 |
* @type bool $_builtin FOR INTERNAL USE ONLY! True if this post type is a native or |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1783 |
* "built-in" post_type. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1784 |
* @type string $_edit_link FOR INTERNAL USE ONLY! URL segment to use for edit link of |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1785 |
* this post type. Default 'post.php?post=%d'. |
5 | 1786 |
* } |
16 | 1787 |
* @return WP_Post_Type|WP_Error The registered post type object on success, |
1788 |
* WP_Error object on failure. |
|
0 | 1789 |
*/ |
1790 |
function register_post_type( $post_type, $args = array() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1791 |
global $wp_post_types; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1792 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1793 |
if ( ! is_array( $wp_post_types ) ) { |
0 | 1794 |
$wp_post_types = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1795 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1796 |
|
16 | 1797 |
// Sanitize post type name. |
0 | 1798 |
$post_type = sanitize_key( $post_type ); |
1799 |
||
5 | 1800 |
if ( empty( $post_type ) || strlen( $post_type ) > 20 ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1801 |
_doing_it_wrong( __FUNCTION__, __( 'Post type names must be between 1 and 20 characters in length.' ), '4.2.0' ); |
5 | 1802 |
return new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) ); |
1803 |
} |
|
0 | 1804 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1805 |
$post_type_object = new WP_Post_Type( $post_type, $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1806 |
$post_type_object->add_supports(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1807 |
$post_type_object->add_rewrite_rules(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1808 |
$post_type_object->register_meta_boxes(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1809 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1810 |
$wp_post_types[ $post_type ] = $post_type_object; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1811 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1812 |
$post_type_object->add_hooks(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1813 |
$post_type_object->register_taxonomies(); |
0 | 1814 |
|
5 | 1815 |
/** |
1816 |
* Fires after a post type is registered. |
|
1817 |
* |
|
1818 |
* @since 3.3.0 |
|
9 | 1819 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object. |
5 | 1820 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1821 |
* @param string $post_type Post type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1822 |
* @param WP_Post_Type $post_type_object Arguments used to register the post type. |
5 | 1823 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1824 |
do_action( 'registered_post_type', $post_type, $post_type_object ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1825 |
|
19 | 1826 |
/** |
1827 |
* Fires after a specific post type is registered. |
|
1828 |
* |
|
1829 |
* The dynamic portion of the filter name, `$post_type`, refers to the post type key. |
|
1830 |
* |
|
1831 |
* Possible hook names include: |
|
1832 |
* |
|
1833 |
* - `registered_post_type_post` |
|
1834 |
* - `registered_post_type_page` |
|
1835 |
* |
|
1836 |
* @since 6.0.0 |
|
1837 |
* |
|
1838 |
* @param string $post_type Post type. |
|
1839 |
* @param WP_Post_Type $post_type_object Arguments used to register the post type. |
|
1840 |
*/ |
|
1841 |
do_action( "registered_post_type_{$post_type}", $post_type, $post_type_object ); |
|
1842 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1843 |
return $post_type_object; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1844 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1845 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1846 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1847 |
* Unregisters a post type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1848 |
* |
19 | 1849 |
* Cannot be used to unregister built-in post types. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1850 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1851 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1852 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1853 |
* @global array $wp_post_types List of post types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1854 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1855 |
* @param string $post_type Post type to unregister. |
18 | 1856 |
* @return true|WP_Error True on success, WP_Error on failure or if the post type doesn't exist. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1857 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1858 |
function unregister_post_type( $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1859 |
global $wp_post_types; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1860 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1861 |
if ( ! post_type_exists( $post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1862 |
return new WP_Error( 'invalid_post_type', __( 'Invalid post type.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1863 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1864 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1865 |
$post_type_object = get_post_type_object( $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1866 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1867 |
// Do not allow unregistering internal post types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1868 |
if ( $post_type_object->_builtin ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1869 |
return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1870 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1871 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1872 |
$post_type_object->remove_supports(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1873 |
$post_type_object->remove_rewrite_rules(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1874 |
$post_type_object->unregister_meta_boxes(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1875 |
$post_type_object->remove_hooks(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1876 |
$post_type_object->unregister_taxonomies(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1877 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1878 |
unset( $wp_post_types[ $post_type ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1879 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1880 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1881 |
* Fires after a post type was unregistered. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1882 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1883 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1884 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1885 |
* @param string $post_type Post type key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1886 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1887 |
do_action( 'unregistered_post_type', $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1888 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1889 |
return true; |
0 | 1890 |
} |
1891 |
||
1892 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1893 |
* Builds an object with all post type capabilities out of a post type object |
0 | 1894 |
* |
1895 |
* Post type capabilities use the 'capability_type' argument as a base, if the |
|
1896 |
* capability is not set in the 'capabilities' argument array or if the |
|
1897 |
* 'capabilities' argument is not supplied. |
|
1898 |
* |
|
1899 |
* The capability_type argument can optionally be registered as an array, with |
|
1900 |
* the first value being singular and the second plural, e.g. array('story, 'stories') |
|
1901 |
* Otherwise, an 's' will be added to the value for the plural form. After |
|
1902 |
* registration, capability_type will always be a string of the singular value. |
|
1903 |
* |
|
16 | 1904 |
* By default, eight keys are accepted as part of the capabilities array: |
0 | 1905 |
* |
1906 |
* - edit_post, read_post, and delete_post are meta capabilities, which are then |
|
1907 |
* generally mapped to corresponding primitive capabilities depending on the |
|
1908 |
* context, which would be the post being edited/read/deleted and the user or |
|
1909 |
* role being checked. Thus these capabilities would generally not be granted |
|
1910 |
* directly to users or roles. |
|
1911 |
* |
|
1912 |
* - edit_posts - Controls whether objects of this post type can be edited. |
|
1913 |
* - edit_others_posts - Controls whether objects of this type owned by other users |
|
1914 |
* can be edited. If the post type does not support an author, then this will |
|
1915 |
* behave like edit_posts. |
|
16 | 1916 |
* - delete_posts - Controls whether objects of this post type can be deleted. |
0 | 1917 |
* - publish_posts - Controls publishing objects of this post type. |
1918 |
* - read_private_posts - Controls whether private objects can be read. |
|
1919 |
* |
|
16 | 1920 |
* These five primitive capabilities are checked in core in various locations. |
1921 |
* There are also six other primitive capabilities which are not referenced |
|
0 | 1922 |
* directly in core, except in map_meta_cap(), which takes the three aforementioned |
1923 |
* meta capabilities and translates them into one or more primitive capabilities |
|
1924 |
* that must then be checked against the user or role, depending on the context. |
|
1925 |
* |
|
1926 |
* - read - Controls whether objects of this post type can be read. |
|
1927 |
* - delete_private_posts - Controls whether private objects can be deleted. |
|
1928 |
* - delete_published_posts - Controls whether published objects can be deleted. |
|
1929 |
* - delete_others_posts - Controls whether objects owned by other users can be |
|
1930 |
* can be deleted. If the post type does not support an author, then this will |
|
1931 |
* behave like delete_posts. |
|
1932 |
* - edit_private_posts - Controls whether private objects can be edited. |
|
1933 |
* - edit_published_posts - Controls whether published objects can be edited. |
|
1934 |
* |
|
1935 |
* These additional capabilities are only used in map_meta_cap(). Thus, they are |
|
1936 |
* only assigned by default if the post type is registered with the 'map_meta_cap' |
|
1937 |
* argument set to true (default is false). |
|
1938 |
* |
|
5 | 1939 |
* @since 3.0.0 |
16 | 1940 |
* @since 5.4.0 'delete_posts' is included in default capabilities. |
5 | 1941 |
* |
1942 |
* @see register_post_type() |
|
0 | 1943 |
* @see map_meta_cap() |
5 | 1944 |
* |
1945 |
* @param object $args Post type registration arguments. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1946 |
* @return object Object with all the capabilities as member variables. |
0 | 1947 |
*/ |
1948 |
function get_post_type_capabilities( $args ) { |
|
9 | 1949 |
if ( ! is_array( $args->capability_type ) ) { |
0 | 1950 |
$args->capability_type = array( $args->capability_type, $args->capability_type . 's' ); |
9 | 1951 |
} |
0 | 1952 |
|
1953 |
// Singular base for meta capabilities, plural base for primitive capabilities. |
|
1954 |
list( $singular_base, $plural_base ) = $args->capability_type; |
|
1955 |
||
1956 |
$default_capabilities = array( |
|
16 | 1957 |
// Meta capabilities. |
9 | 1958 |
'edit_post' => 'edit_' . $singular_base, |
1959 |
'read_post' => 'read_' . $singular_base, |
|
1960 |
'delete_post' => 'delete_' . $singular_base, |
|
0 | 1961 |
// Primitive capabilities used outside of map_meta_cap(): |
9 | 1962 |
'edit_posts' => 'edit_' . $plural_base, |
1963 |
'edit_others_posts' => 'edit_others_' . $plural_base, |
|
16 | 1964 |
'delete_posts' => 'delete_' . $plural_base, |
9 | 1965 |
'publish_posts' => 'publish_' . $plural_base, |
0 | 1966 |
'read_private_posts' => 'read_private_' . $plural_base, |
1967 |
); |
|
1968 |
||
1969 |
// Primitive capabilities used within map_meta_cap(): |
|
1970 |
if ( $args->map_meta_cap ) { |
|
1971 |
$default_capabilities_for_mapping = array( |
|
1972 |
'read' => 'read', |
|
9 | 1973 |
'delete_private_posts' => 'delete_private_' . $plural_base, |
0 | 1974 |
'delete_published_posts' => 'delete_published_' . $plural_base, |
9 | 1975 |
'delete_others_posts' => 'delete_others_' . $plural_base, |
1976 |
'edit_private_posts' => 'edit_private_' . $plural_base, |
|
1977 |
'edit_published_posts' => 'edit_published_' . $plural_base, |
|
0 | 1978 |
); |
9 | 1979 |
$default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping ); |
0 | 1980 |
} |
1981 |
||
1982 |
$capabilities = array_merge( $default_capabilities, $args->capabilities ); |
|
1983 |
||
1984 |
// Post creation capability simply maps to edit_posts by default: |
|
9 | 1985 |
if ( ! isset( $capabilities['create_posts'] ) ) { |
0 | 1986 |
$capabilities['create_posts'] = $capabilities['edit_posts']; |
9 | 1987 |
} |
0 | 1988 |
|
1989 |
// Remember meta capabilities for future reference. |
|
9 | 1990 |
if ( $args->map_meta_cap ) { |
0 | 1991 |
_post_type_meta_capabilities( $capabilities ); |
9 | 1992 |
} |
0 | 1993 |
|
1994 |
return (object) $capabilities; |
|
1995 |
} |
|
1996 |
||
1997 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1998 |
* Stores or returns a list of post type meta caps for map_meta_cap(). |
0 | 1999 |
* |
2000 |
* @since 3.1.0 |
|
2001 |
* @access private |
|
5 | 2002 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2003 |
* @global array $post_type_meta_caps Used to store meta capabilities. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2004 |
* |
16 | 2005 |
* @param string[] $capabilities Post type meta capabilities. |
0 | 2006 |
*/ |
2007 |
function _post_type_meta_capabilities( $capabilities = null ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2008 |
global $post_type_meta_caps; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2009 |
|
0 | 2010 |
foreach ( $capabilities as $core => $custom ) { |
16 | 2011 |
if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ), true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2012 |
$post_type_meta_caps[ $custom ] = $core; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2013 |
} |
0 | 2014 |
} |
2015 |
} |
|
2016 |
||
2017 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2018 |
* Builds an object with all post type labels out of a post type object. |
0 | 2019 |
* |
2020 |
* Accepted keys of the label array in the post type object: |
|
5 | 2021 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2022 |
* - `name` - General name for the post type, usually plural. The same and overridden |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2023 |
* by `$post_type_object->label`. Default is 'Posts' / 'Pages'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2024 |
* - `singular_name` - Name for one object of this post type. Default is 'Post' / 'Page'. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2025 |
* - `add_new` - Label for adding a new item. Default is 'Add New Post' / 'Add New Page'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
* - `add_new_item` - Label for adding a new singular item. Default is 'Add New Post' / 'Add New Page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
* - `edit_item` - Label for editing a singular item. Default is 'Edit Post' / 'Edit Page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
* - `new_item` - Label for the new item page title. Default is 'New Post' / 'New Page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
* - `view_item` - Label for viewing a singular item. Default is 'View Post' / 'View Page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2030 |
* - `view_items` - Label for viewing post type archives. Default is 'View Posts' / 'View Pages'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2031 |
* - `search_items` - Label for searching plural items. Default is 'Search Posts' / 'Search Pages'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2032 |
* - `not_found` - Label used when no items are found. Default is 'No posts found' / 'No pages found'. |
16 | 2033 |
* - `not_found_in_trash` - Label used when no items are in the Trash. Default is 'No posts found in Trash' / |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2034 |
* 'No pages found in Trash'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
* - `parent_item_colon` - Label used to prefix parents of hierarchical items. Not used on non-hierarchical |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2036 |
* post types. Default is 'Parent Page:'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2037 |
* - `all_items` - Label to signify all items in a submenu link. Default is 'All Posts' / 'All Pages'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2038 |
* - `archives` - Label for archives in nav menus. Default is 'Post Archives' / 'Page Archives'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2039 |
* - `attributes` - Label for the attributes meta box. Default is 'Post Attributes' / 'Page Attributes'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
* - `insert_into_item` - Label for the media frame button. Default is 'Insert into post' / 'Insert into page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2041 |
* - `uploaded_to_this_item` - Label for the media frame filter. Default is 'Uploaded to this post' / |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2042 |
* 'Uploaded to this page'. |
16 | 2043 |
* - `featured_image` - Label for the featured image meta box title. Default is 'Featured image'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2044 |
* - `set_featured_image` - Label for setting the featured image. Default is 'Set featured image'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2045 |
* - `remove_featured_image` - Label for removing the featured image. Default is 'Remove featured image'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2046 |
* - `use_featured_image` - Label in the media frame for using a featured image. Default is 'Use as featured image'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2047 |
* - `menu_name` - Label for the menu name. Default is the same as `name`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
* - `filter_items_list` - Label for the table views hidden heading. Default is 'Filter posts list' / |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2049 |
* 'Filter pages list'. |
18 | 2050 |
* - `filter_by_date` - Label for the date filter in list tables. Default is 'Filter by date'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
* - `items_list_navigation` - Label for the table pagination hidden heading. Default is 'Posts list navigation' / |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
* 'Pages list navigation'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
* - `items_list` - Label for the table hidden heading. Default is 'Posts list' / 'Pages list'. |
9 | 2054 |
* - `item_published` - Label used when an item is published. Default is 'Post published.' / 'Page published.' |
2055 |
* - `item_published_privately` - Label used when an item is published with private visibility. |
|
2056 |
* Default is 'Post published privately.' / 'Page published privately.' |
|
2057 |
* - `item_reverted_to_draft` - Label used when an item is switched to a draft. |
|
2058 |
* Default is 'Post reverted to draft.' / 'Page reverted to draft.' |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2059 |
* - `item_trashed` - Label used when an item is moved to Trash. Default is 'Post trashed.' / 'Page trashed.' |
9 | 2060 |
* - `item_scheduled` - Label used when an item is scheduled for publishing. Default is 'Post scheduled.' / |
2061 |
* 'Page scheduled.' |
|
2062 |
* - `item_updated` - Label used when an item is updated. Default is 'Post updated.' / 'Page updated.' |
|
18 | 2063 |
* - `item_link` - Title for a navigation link block variation. Default is 'Post Link' / 'Page Link'. |
2064 |
* - `item_link_description` - Description for a navigation link block variation. Default is 'A link to a post.' / |
|
2065 |
* 'A link to a page.' |
|
5 | 2066 |
* |
2067 |
* Above, the first default value is for non-hierarchical post types (like posts) |
|
2068 |
* and the second one is for hierarchical post types (like pages). |
|
0 | 2069 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2070 |
* Note: To set labels used in post type admin notices, see the {@see 'post_updated_messages'} filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2071 |
* |
0 | 2072 |
* @since 3.0.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2073 |
* @since 4.3.0 Added the `featured_image`, `set_featured_image`, `remove_featured_image`, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2074 |
* and `use_featured_image` labels. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2075 |
* @since 4.4.0 Added the `archives`, `insert_into_item`, `uploaded_to_this_item`, `filter_items_list`, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
* `items_list_navigation`, and `items_list` labels. |
9 | 2077 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2078 |
* @since 4.7.0 Added the `view_items` and `attributes` labels. |
9 | 2079 |
* @since 5.0.0 Added the `item_published`, `item_published_privately`, `item_reverted_to_draft`, |
2080 |
* `item_scheduled`, and `item_updated` labels. |
|
18 | 2081 |
* @since 5.7.0 Added the `filter_by_date` label. |
2082 |
* @since 5.8.0 Added the `item_link` and `item_link_description` labels. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2083 |
* @since 6.3.0 Added the `item_trashed` label. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2084 |
* @since 6.4.0 Changed default values for the `add_new` label to include the type of content. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2085 |
* This matches `add_new_item` and provides more context for better accessibility. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2086 |
* @since 6.6.0 Added the `template_name` label. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
* |
0 | 2088 |
* @access private |
2089 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
* @param object|WP_Post_Type $post_type_object Post type object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2091 |
* @return object Object with all the labels as member variables. |
0 | 2092 |
*/ |
2093 |
function get_post_type_labels( $post_type_object ) { |
|
19 | 2094 |
$nohier_vs_hier_defaults = WP_Post_Type::get_default_labels(); |
18 | 2095 |
|
0 | 2096 |
$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; |
2097 |
||
2098 |
$labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); |
|
2099 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2100 |
if ( ! isset( $post_type_object->labels->template_name ) && isset( $post_type_object->labels->singular_name ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2101 |
/* translators: %s: Post type name. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2102 |
$labels->template_name = sprintf( __( 'Single item: %s' ), $post_type_object->labels->singular_name ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2103 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2104 |
|
0 | 2105 |
$post_type = $post_type_object->name; |
5 | 2106 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2107 |
$default_labels = clone $labels; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2108 |
|
5 | 2109 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
* Filters the labels of a specific post type. |
5 | 2111 |
* |
2112 |
* The dynamic portion of the hook name, `$post_type`, refers to |
|
2113 |
* the post type slug. |
|
2114 |
* |
|
18 | 2115 |
* Possible hook names include: |
2116 |
* |
|
2117 |
* - `post_type_labels_post` |
|
2118 |
* - `post_type_labels_page` |
|
2119 |
* - `post_type_labels_attachment` |
|
2120 |
* |
|
5 | 2121 |
* @since 3.5.0 |
2122 |
* |
|
2123 |
* @see get_post_type_labels() for the full list of labels. |
|
2124 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2125 |
* @param object $labels Object with labels for the post type as member variables. |
5 | 2126 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2127 |
$labels = apply_filters( "post_type_labels_{$post_type}", $labels ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2128 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2129 |
// Ensure that the filtered labels contain all required default values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2130 |
$labels = (object) array_merge( (array) $default_labels, (array) $labels ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2131 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2132 |
return $labels; |
0 | 2133 |
} |
2134 |
||
2135 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2136 |
* Builds an object with custom-something object (post type, taxonomy) labels |
5 | 2137 |
* out of a custom-something object |
2138 |
* |
|
2139 |
* @since 3.0.0 |
|
0 | 2140 |
* @access private |
5 | 2141 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2142 |
* @param object $data_object A custom-something object. |
5 | 2143 |
* @param array $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2144 |
* @return object Object containing labels for the given custom-something object. |
0 | 2145 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2146 |
function _get_custom_object_labels( $data_object, $nohier_vs_hier_defaults ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2147 |
$data_object->labels = (array) $data_object->labels; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2148 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2149 |
if ( isset( $data_object->label ) && empty( $data_object->labels['name'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2150 |
$data_object->labels['name'] = $data_object->label; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2151 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2152 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2153 |
if ( ! isset( $data_object->labels['singular_name'] ) && isset( $data_object->labels['name'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2154 |
$data_object->labels['singular_name'] = $data_object->labels['name']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2155 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2156 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2157 |
if ( ! isset( $data_object->labels['name_admin_bar'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2158 |
$data_object->labels['name_admin_bar'] = |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2159 |
isset( $data_object->labels['singular_name'] ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2160 |
? $data_object->labels['singular_name'] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2161 |
: $data_object->name; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2162 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2163 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2164 |
if ( ! isset( $data_object->labels['menu_name'] ) && isset( $data_object->labels['name'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2165 |
$data_object->labels['menu_name'] = $data_object->labels['name']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2166 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2167 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2168 |
if ( ! isset( $data_object->labels['all_items'] ) && isset( $data_object->labels['menu_name'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2169 |
$data_object->labels['all_items'] = $data_object->labels['menu_name']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2170 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2171 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2172 |
if ( ! isset( $data_object->labels['archives'] ) && isset( $data_object->labels['all_items'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2173 |
$data_object->labels['archives'] = $data_object->labels['all_items']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2174 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2175 |
|
5 | 2176 |
$defaults = array(); |
2177 |
foreach ( $nohier_vs_hier_defaults as $key => $value ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2178 |
$defaults[ $key ] = $data_object->hierarchical ? $value[1] : $value[0]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2179 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2180 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2181 |
$labels = array_merge( $defaults, $data_object->labels ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2182 |
$data_object->labels = (object) $data_object->labels; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2183 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2184 |
return (object) $labels; |
0 | 2185 |
} |
2186 |
||
2187 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2188 |
* Adds submenus for post types. |
0 | 2189 |
* |
2190 |
* @access private |
|
2191 |
* @since 3.1.0 |
|
2192 |
*/ |
|
2193 |
function _add_post_type_submenus() { |
|
2194 |
foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) { |
|
2195 |
$ptype_obj = get_post_type_object( $ptype ); |
|
5 | 2196 |
// Sub-menus only. |
16 | 2197 |
if ( ! $ptype_obj->show_in_menu || true === $ptype_obj->show_in_menu ) { |
0 | 2198 |
continue; |
9 | 2199 |
} |
0 | 2200 |
add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" ); |
2201 |
} |
|
2202 |
} |
|
2203 |
||
2204 |
/** |
|
16 | 2205 |
* Registers support of certain features for a post type. |
0 | 2206 |
* |
5 | 2207 |
* All core features are directly associated with a functional area of the edit |
2208 |
* screen, such as the editor or a meta box. Features include: 'title', 'editor', |
|
2209 |
* 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes', |
|
2210 |
* 'thumbnail', 'custom-fields', and 'post-formats'. |
|
2211 |
* |
|
2212 |
* Additionally, the 'revisions' feature dictates whether the post type will |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2213 |
* store revisions, the 'autosave' feature dictates whether the post type |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2214 |
* will be autosaved, and the 'comments' feature dictates whether the comments |
5 | 2215 |
* count will show on the edit screen. |
0 | 2216 |
* |
16 | 2217 |
* A third, optional parameter can also be passed along with a feature to provide |
2218 |
* additional information about supporting that feature. |
|
2219 |
* |
|
2220 |
* Example usage: |
|
2221 |
* |
|
2222 |
* add_post_type_support( 'my_post_type', 'comments' ); |
|
2223 |
* add_post_type_support( 'my_post_type', array( |
|
2224 |
* 'author', 'excerpt', |
|
2225 |
* ) ); |
|
2226 |
* add_post_type_support( 'my_post_type', 'my_feature', array( |
|
2227 |
* 'field' => 'value', |
|
2228 |
* ) ); |
|
2229 |
* |
|
0 | 2230 |
* @since 3.0.0 |
16 | 2231 |
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter |
2232 |
* by adding it to the function signature. |
|
5 | 2233 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2234 |
* @global array $_wp_post_type_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2235 |
* |
5 | 2236 |
* @param string $post_type The post type for which to add the feature. |
2237 |
* @param string|array $feature The feature being added, accepts an array of |
|
2238 |
* feature strings or a single string. |
|
16 | 2239 |
* @param mixed ...$args Optional extra arguments to pass along with certain features. |
2240 |
*/ |
|
2241 |
function add_post_type_support( $post_type, $feature, ...$args ) { |
|
0 | 2242 |
global $_wp_post_type_features; |
2243 |
||
2244 |
$features = (array) $feature; |
|
9 | 2245 |
foreach ( $features as $feature ) { |
16 | 2246 |
if ( $args ) { |
2247 |
$_wp_post_type_features[ $post_type ][ $feature ] = $args; |
|
2248 |
} else { |
|
9 | 2249 |
$_wp_post_type_features[ $post_type ][ $feature ] = true; |
2250 |
} |
|
0 | 2251 |
} |
2252 |
} |
|
2253 |
||
2254 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2255 |
* Removes support for a feature from a post type. |
0 | 2256 |
* |
2257 |
* @since 3.0.0 |
|
5 | 2258 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2259 |
* @global array $_wp_post_type_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2260 |
* |
5 | 2261 |
* @param string $post_type The post type for which to remove the feature. |
2262 |
* @param string $feature The feature being removed. |
|
0 | 2263 |
*/ |
2264 |
function remove_post_type_support( $post_type, $feature ) { |
|
2265 |
global $_wp_post_type_features; |
|
2266 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2267 |
unset( $_wp_post_type_features[ $post_type ][ $feature ] ); |
0 | 2268 |
} |
2269 |
||
2270 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2271 |
* Gets all the post type features |
0 | 2272 |
* |
2273 |
* @since 3.4.0 |
|
5 | 2274 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2275 |
* @global array $_wp_post_type_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2276 |
* |
5 | 2277 |
* @param string $post_type The post type. |
2278 |
* @return array Post type supports list. |
|
0 | 2279 |
*/ |
2280 |
function get_all_post_type_supports( $post_type ) { |
|
2281 |
global $_wp_post_type_features; |
|
2282 |
||
9 | 2283 |
if ( isset( $_wp_post_type_features[ $post_type ] ) ) { |
2284 |
return $_wp_post_type_features[ $post_type ]; |
|
2285 |
} |
|
0 | 2286 |
|
2287 |
return array(); |
|
2288 |
} |
|
2289 |
||
2290 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2291 |
* Checks a post type's support for a given feature. |
0 | 2292 |
* |
2293 |
* @since 3.0.0 |
|
5 | 2294 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2295 |
* @global array $_wp_post_type_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2296 |
* |
5 | 2297 |
* @param string $post_type The post type being checked. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2298 |
* @param string $feature The feature being checked. |
5 | 2299 |
* @return bool Whether the post type supports the given feature. |
0 | 2300 |
*/ |
2301 |
function post_type_supports( $post_type, $feature ) { |
|
2302 |
global $_wp_post_type_features; |
|
2303 |
||
9 | 2304 |
return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) ); |
0 | 2305 |
} |
2306 |
||
2307 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2308 |
* Retrieves a list of post type names that support a specific feature. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2309 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2310 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2311 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2312 |
* @global array $_wp_post_type_features Post type features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2313 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2314 |
* @param array|string $feature Single feature or an array of features the post types should support. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2315 |
* @param string $operator Optional. The logical operation to perform. 'or' means |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2316 |
* only one element from the array needs to match; 'and' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2317 |
* means all elements must match; 'not' means no elements may |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2318 |
* match. Default 'and'. |
16 | 2319 |
* @return string[] A list of post type names. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2320 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2321 |
function get_post_types_by_support( $feature, $operator = 'and' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2322 |
global $_wp_post_type_features; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2323 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2324 |
$features = array_fill_keys( (array) $feature, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2325 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2326 |
return array_keys( wp_filter_object_list( $_wp_post_type_features, $features, $operator ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2327 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2328 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2329 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2330 |
* Updates the post type for the post ID. |
0 | 2331 |
* |
2332 |
* The page or post cache will be cleaned for the post ID. |
|
2333 |
* |
|
2334 |
* @since 2.5.0 |
|
2335 |
* |
|
5 | 2336 |
* @global wpdb $wpdb WordPress database abstraction object. |
2337 |
* |
|
2338 |
* @param int $post_id Optional. Post ID to change post type. Default 0. |
|
2339 |
* @param string $post_type Optional. Post type. Accepts 'post' or 'page' to |
|
2340 |
* name a few. Default 'post'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2341 |
* @return int|false Amount of rows changed. Should be 1 for success and 0 for failure. |
0 | 2342 |
*/ |
2343 |
function set_post_type( $post_id = 0, $post_type = 'post' ) { |
|
2344 |
global $wpdb; |
|
2345 |
||
9 | 2346 |
$post_type = sanitize_post_field( 'post_type', $post_type, $post_id, 'db' ); |
2347 |
$return = $wpdb->update( $wpdb->posts, array( 'post_type' => $post_type ), array( 'ID' => $post_id ) ); |
|
0 | 2348 |
|
2349 |
clean_post_cache( $post_id ); |
|
2350 |
||
2351 |
return $return; |
|
2352 |
} |
|
2353 |
||
2354 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2355 |
* Determines whether a post type is considered "viewable". |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2356 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2357 |
* For built-in post types such as posts and pages, the 'public' value will be evaluated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2358 |
* For all others, the 'publicly_queryable' value will be used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2359 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2360 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2361 |
* @since 4.5.0 Added the ability to pass a post type name in addition to object. |
9 | 2362 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object. |
19 | 2363 |
* @since 5.9.0 Added `is_post_type_viewable` hook to filter the result. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2364 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2365 |
* @param string|WP_Post_Type $post_type Post type name or object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2366 |
* @return bool Whether the post type should be considered viewable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2367 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2368 |
function is_post_type_viewable( $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2369 |
if ( is_scalar( $post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2370 |
$post_type = get_post_type_object( $post_type ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2371 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2372 |
if ( ! $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2373 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2374 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2375 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2376 |
|
18 | 2377 |
if ( ! is_object( $post_type ) ) { |
2378 |
return false; |
|
2379 |
} |
|
2380 |
||
19 | 2381 |
$is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); |
2382 |
||
2383 |
/** |
|
2384 |
* Filters whether a post type is considered "viewable". |
|
2385 |
* |
|
2386 |
* The returned filtered value must be a boolean type to ensure |
|
2387 |
* `is_post_type_viewable()` only returns a boolean. This strictness |
|
2388 |
* is by design to maintain backwards-compatibility and guard against |
|
2389 |
* potential type errors in PHP 8.1+. Non-boolean values (even falsey |
|
2390 |
* and truthy values) will result in the function returning false. |
|
2391 |
* |
|
2392 |
* @since 5.9.0 |
|
2393 |
* |
|
2394 |
* @param bool $is_viewable Whether the post type is "viewable" (strict type). |
|
2395 |
* @param WP_Post_Type $post_type Post type object. |
|
2396 |
*/ |
|
2397 |
return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2398 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2399 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2400 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2401 |
* Determines whether a post status is considered "viewable". |
18 | 2402 |
* |
19 | 2403 |
* For built-in post statuses such as publish and private, the 'public' value will be evaluated. |
18 | 2404 |
* For all others, the 'publicly_queryable' value will be used. |
2405 |
* |
|
2406 |
* @since 5.7.0 |
|
19 | 2407 |
* @since 5.9.0 Added `is_post_status_viewable` hook to filter the result. |
18 | 2408 |
* |
2409 |
* @param string|stdClass $post_status Post status name or object. |
|
2410 |
* @return bool Whether the post status should be considered viewable. |
|
2411 |
*/ |
|
2412 |
function is_post_status_viewable( $post_status ) { |
|
2413 |
if ( is_scalar( $post_status ) ) { |
|
2414 |
$post_status = get_post_status_object( $post_status ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2415 |
|
18 | 2416 |
if ( ! $post_status ) { |
2417 |
return false; |
|
2418 |
} |
|
2419 |
} |
|
2420 |
||
2421 |
if ( |
|
2422 |
! is_object( $post_status ) || |
|
2423 |
$post_status->internal || |
|
2424 |
$post_status->protected |
|
2425 |
) { |
|
2426 |
return false; |
|
2427 |
} |
|
2428 |
||
19 | 2429 |
$is_viewable = $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public ); |
2430 |
||
2431 |
/** |
|
2432 |
* Filters whether a post status is considered "viewable". |
|
2433 |
* |
|
2434 |
* The returned filtered value must be a boolean type to ensure |
|
2435 |
* `is_post_status_viewable()` only returns a boolean. This strictness |
|
2436 |
* is by design to maintain backwards-compatibility and guard against |
|
2437 |
* potential type errors in PHP 8.1+. Non-boolean values (even falsey |
|
2438 |
* and truthy values) will result in the function returning false. |
|
2439 |
* |
|
2440 |
* @since 5.9.0 |
|
2441 |
* |
|
2442 |
* @param bool $is_viewable Whether the post status is "viewable" (strict type). |
|
2443 |
* @param stdClass $post_status Post status object. |
|
2444 |
*/ |
|
2445 |
return true === apply_filters( 'is_post_status_viewable', $is_viewable, $post_status ); |
|
18 | 2446 |
} |
2447 |
||
2448 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2449 |
* Determines whether a post is publicly viewable. |
18 | 2450 |
* |
2451 |
* Posts are considered publicly viewable if both the post status and post type |
|
2452 |
* are viewable. |
|
2453 |
* |
|
2454 |
* @since 5.7.0 |
|
2455 |
* |
|
2456 |
* @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. |
|
2457 |
* @return bool Whether the post is publicly viewable. |
|
2458 |
*/ |
|
2459 |
function is_post_publicly_viewable( $post = null ) { |
|
2460 |
$post = get_post( $post ); |
|
2461 |
||
2462 |
if ( ! $post ) { |
|
2463 |
return false; |
|
2464 |
} |
|
2465 |
||
2466 |
$post_type = get_post_type( $post ); |
|
2467 |
$post_status = get_post_status( $post ); |
|
2468 |
||
2469 |
return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status ); |
|
2470 |
} |
|
2471 |
||
2472 |
/** |
|
9 | 2473 |
* Retrieves an array of the latest posts, or posts matching the given criteria. |
0 | 2474 |
* |
18 | 2475 |
* For more information on the accepted arguments, see the |
2476 |
* {@link https://developer.wordpress.org/reference/classes/wp_query/ |
|
2477 |
* WP_Query} documentation in the Developer Handbook. |
|
2478 |
* |
|
2479 |
* The `$ignore_sticky_posts` and `$no_found_rows` arguments are ignored by |
|
2480 |
* this function and both are set to `true`. |
|
2481 |
* |
|
0 | 2482 |
* The defaults are as follows: |
2483 |
* |
|
2484 |
* @since 1.2.0 |
|
5 | 2485 |
* |
18 | 2486 |
* @see WP_Query |
5 | 2487 |
* @see WP_Query::parse_query() |
2488 |
* |
|
2489 |
* @param array $args { |
|
19 | 2490 |
* Optional. Arguments to retrieve posts. See WP_Query::parse_query() for all available arguments. |
5 | 2491 |
* |
18 | 2492 |
* @type int $numberposts Total number of posts to retrieve. Is an alias of `$posts_per_page` |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2493 |
* in WP_Query. Accepts -1 for all. Default 5. |
5 | 2494 |
* @type int|string $category Category ID or comma-separated list of IDs (this or any children). |
18 | 2495 |
* Is an alias of `$cat` in WP_Query. Default 0. |
2496 |
* @type int[] $include An array of post IDs to retrieve, sticky posts will be included. |
|
2497 |
* Is an alias of `$post__in` in WP_Query. Default empty array. |
|
2498 |
* @type int[] $exclude An array of post IDs not to retrieve. Default empty array. |
|
5 | 2499 |
* @type bool $suppress_filters Whether to suppress filters. Default true. |
2500 |
* } |
|
9 | 2501 |
* @return WP_Post[]|int[] Array of post objects or post IDs. |
0 | 2502 |
*/ |
5 | 2503 |
function get_posts( $args = null ) { |
0 | 2504 |
$defaults = array( |
9 | 2505 |
'numberposts' => 5, |
2506 |
'category' => 0, |
|
2507 |
'orderby' => 'date', |
|
2508 |
'order' => 'DESC', |
|
2509 |
'include' => array(), |
|
2510 |
'exclude' => array(), |
|
2511 |
'meta_key' => '', |
|
2512 |
'meta_value' => '', |
|
2513 |
'post_type' => 'post', |
|
2514 |
'suppress_filters' => true, |
|
0 | 2515 |
); |
2516 |
||
16 | 2517 |
$parsed_args = wp_parse_args( $args, $defaults ); |
2518 |
if ( empty( $parsed_args['post_status'] ) ) { |
|
2519 |
$parsed_args['post_status'] = ( 'attachment' === $parsed_args['post_type'] ) ? 'inherit' : 'publish'; |
|
2520 |
} |
|
2521 |
if ( ! empty( $parsed_args['numberposts'] ) && empty( $parsed_args['posts_per_page'] ) ) { |
|
2522 |
$parsed_args['posts_per_page'] = $parsed_args['numberposts']; |
|
2523 |
} |
|
2524 |
if ( ! empty( $parsed_args['category'] ) ) { |
|
2525 |
$parsed_args['cat'] = $parsed_args['category']; |
|
2526 |
} |
|
2527 |
if ( ! empty( $parsed_args['include'] ) ) { |
|
2528 |
$incposts = wp_parse_id_list( $parsed_args['include'] ); |
|
2529 |
$parsed_args['posts_per_page'] = count( $incposts ); // Only the number of posts included. |
|
2530 |
$parsed_args['post__in'] = $incposts; |
|
2531 |
} elseif ( ! empty( $parsed_args['exclude'] ) ) { |
|
2532 |
$parsed_args['post__not_in'] = wp_parse_id_list( $parsed_args['exclude'] ); |
|
2533 |
} |
|
2534 |
||
2535 |
$parsed_args['ignore_sticky_posts'] = true; |
|
2536 |
$parsed_args['no_found_rows'] = true; |
|
0 | 2537 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2538 |
$get_posts = new WP_Query(); |
16 | 2539 |
return $get_posts->query( $parsed_args ); |
0 | 2540 |
} |
2541 |
||
2542 |
// |
|
16 | 2543 |
// Post meta functions. |
0 | 2544 |
// |
2545 |
||
2546 |
/** |
|
9 | 2547 |
* Adds a meta field to the given post. |
0 | 2548 |
* |
2549 |
* Post meta data is called "Custom Fields" on the Administration Screen. |
|
2550 |
* |
|
2551 |
* @since 1.5.0 |
|
5 | 2552 |
* |
2553 |
* @param int $post_id Post ID. |
|
2554 |
* @param string $meta_key Metadata name. |
|
2555 |
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
|
2556 |
* @param bool $unique Optional. Whether the same key should not be added. |
|
2557 |
* Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2558 |
* @return int|false Meta ID on success, false on failure. |
0 | 2559 |
*/ |
5 | 2560 |
function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { |
2561 |
// Make sure meta is added to the post, not a revision. |
|
9 | 2562 |
$the_post = wp_is_post_revision( $post_id ); |
2563 |
if ( $the_post ) { |
|
0 | 2564 |
$post_id = $the_post; |
9 | 2565 |
} |
2566 |
||
2567 |
return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); |
|
0 | 2568 |
} |
2569 |
||
2570 |
/** |
|
9 | 2571 |
* Deletes a post meta field for the given post ID. |
0 | 2572 |
* |
2573 |
* You can match based on the key, or key and value. Removing based on key and |
|
2574 |
* value, will keep from removing duplicate metadata with the same key. It also |
|
9 | 2575 |
* allows removing all metadata matching the key, if needed. |
0 | 2576 |
* |
2577 |
* @since 1.5.0 |
|
5 | 2578 |
* |
2579 |
* @param int $post_id Post ID. |
|
2580 |
* @param string $meta_key Metadata name. |
|
16 | 2581 |
* @param mixed $meta_value Optional. Metadata value. If provided, |
2582 |
* rows will only be removed that match the value. |
|
2583 |
* Must be serializable if non-scalar. Default empty. |
|
0 | 2584 |
* @return bool True on success, false on failure. |
2585 |
*/ |
|
5 | 2586 |
function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { |
19 | 2587 |
// Make sure meta is deleted from the post, not from a revision. |
9 | 2588 |
$the_post = wp_is_post_revision( $post_id ); |
2589 |
if ( $the_post ) { |
|
0 | 2590 |
$post_id = $the_post; |
9 | 2591 |
} |
2592 |
||
2593 |
return delete_metadata( 'post', $post_id, $meta_key, $meta_value ); |
|
0 | 2594 |
} |
2595 |
||
2596 |
/** |
|
9 | 2597 |
* Retrieves a post meta field for the given post ID. |
0 | 2598 |
* |
2599 |
* @since 1.5.0 |
|
5 | 2600 |
* |
2601 |
* @param int $post_id Post ID. |
|
16 | 2602 |
* @param string $key Optional. The meta key to retrieve. By default, |
2603 |
* returns data for all keys. Default empty. |
|
2604 |
* @param bool $single Optional. Whether to return a single value. |
|
18 | 2605 |
* This parameter has no effect if `$key` is not specified. |
16 | 2606 |
* Default false. |
18 | 2607 |
* @return mixed An array of values if `$single` is false. |
2608 |
* The value of the meta field if `$single` is true. |
|
2609 |
* False for an invalid `$post_id` (non-numeric, zero, or negative value). |
|
2610 |
* An empty string if a valid but non-existing post ID is passed. |
|
0 | 2611 |
*/ |
5 | 2612 |
function get_post_meta( $post_id, $key = '', $single = false ) { |
9 | 2613 |
return get_metadata( 'post', $post_id, $key, $single ); |
0 | 2614 |
} |
2615 |
||
2616 |
/** |
|
9 | 2617 |
* Updates a post meta field based on the given post ID. |
2618 |
* |
|
2619 |
* Use the `$prev_value` parameter to differentiate between meta fields with the |
|
0 | 2620 |
* same key and post ID. |
2621 |
* |
|
9 | 2622 |
* If the meta field for the post does not exist, it will be added and its ID returned. |
2623 |
* |
|
2624 |
* Can be used in place of add_post_meta(). |
|
0 | 2625 |
* |
2626 |
* @since 1.5.0 |
|
5 | 2627 |
* |
2628 |
* @param int $post_id Post ID. |
|
2629 |
* @param string $meta_key Metadata key. |
|
2630 |
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
|
9 | 2631 |
* @param mixed $prev_value Optional. Previous value to check before updating. |
16 | 2632 |
* If specified, only update existing metadata entries with |
2633 |
* this value. Otherwise, update all entries. Default empty. |
|
2634 |
* @return int|bool Meta ID if the key didn't exist, true on successful update, |
|
2635 |
* false on failure or if the value passed to the function |
|
2636 |
* is the same as the one that is already in the database. |
|
0 | 2637 |
*/ |
5 | 2638 |
function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) { |
19 | 2639 |
// Make sure meta is updated for the post, not for a revision. |
9 | 2640 |
$the_post = wp_is_post_revision( $post_id ); |
2641 |
if ( $the_post ) { |
|
0 | 2642 |
$post_id = $the_post; |
9 | 2643 |
} |
2644 |
||
2645 |
return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); |
|
0 | 2646 |
} |
2647 |
||
2648 |
/** |
|
9 | 2649 |
* Deletes everything from post meta matching the given meta key. |
0 | 2650 |
* |
2651 |
* @since 2.3.0 |
|
2652 |
* |
|
2653 |
* @param string $post_meta_key Key to search for when deleting. |
|
5 | 2654 |
* @return bool Whether the post meta key was deleted from the database. |
0 | 2655 |
*/ |
5 | 2656 |
function delete_post_meta_by_key( $post_meta_key ) { |
9 | 2657 |
return delete_metadata( 'post', null, $post_meta_key, '', true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2658 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2659 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2660 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2661 |
* Registers a meta key for posts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2662 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2663 |
* @since 4.9.8 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2664 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2665 |
* @param string $post_type Post type to register a meta key for. Pass an empty string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2666 |
* to register the meta key across all existing post types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2667 |
* @param string $meta_key The meta key to register. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2668 |
* @param array $args Data used to describe the meta key when registered. See |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2669 |
* {@see register_meta()} for a list of supported arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2670 |
* @return bool True if the meta key was successfully registered, false if not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2671 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2672 |
function register_post_meta( $post_type, $meta_key, array $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2673 |
$args['object_subtype'] = $post_type; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2674 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2675 |
return register_meta( 'post', $meta_key, $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2676 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2677 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2678 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2679 |
* Unregisters a meta key for posts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2680 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2681 |
* @since 4.9.8 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2682 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2683 |
* @param string $post_type Post type the meta key is currently registered for. Pass |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2684 |
* an empty string if the meta key is registered across all |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2685 |
* existing post types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2686 |
* @param string $meta_key The meta key to unregister. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2687 |
* @return bool True on success, false if the meta key was not previously registered. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2688 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2689 |
function unregister_post_meta( $post_type, $meta_key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2690 |
return unregister_meta_key( 'post', $meta_key, $post_type ); |
0 | 2691 |
} |
2692 |
||
2693 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2694 |
* Retrieves post meta fields, based on post ID. |
0 | 2695 |
* |
2696 |
* The post meta fields are retrieved from the cache where possible, |
|
2697 |
* so the function is optimized to be called more than once. |
|
2698 |
* |
|
2699 |
* @since 1.2.0 |
|
5 | 2700 |
* |
19 | 2701 |
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
2702 |
* @return mixed An array of values. |
|
2703 |
* False for an invalid `$post_id` (non-numeric, zero, or negative value). |
|
2704 |
* An empty string if a valid but non-existing post ID is passed. |
|
0 | 2705 |
*/ |
2706 |
function get_post_custom( $post_id = 0 ) { |
|
2707 |
$post_id = absint( $post_id ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2708 |
|
9 | 2709 |
if ( ! $post_id ) { |
0 | 2710 |
$post_id = get_the_ID(); |
9 | 2711 |
} |
0 | 2712 |
|
2713 |
return get_post_meta( $post_id ); |
|
2714 |
} |
|
2715 |
||
2716 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2717 |
* Retrieves meta field names for a post. |
0 | 2718 |
* |
2719 |
* If there are no meta fields, then nothing (null) will be returned. |
|
2720 |
* |
|
2721 |
* @since 1.2.0 |
|
5 | 2722 |
* |
19 | 2723 |
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2724 |
* @return array|void Array of the keys, if retrieved. |
0 | 2725 |
*/ |
2726 |
function get_post_custom_keys( $post_id = 0 ) { |
|
2727 |
$custom = get_post_custom( $post_id ); |
|
2728 |
||
9 | 2729 |
if ( ! is_array( $custom ) ) { |
0 | 2730 |
return; |
9 | 2731 |
} |
2732 |
||
16 | 2733 |
$keys = array_keys( $custom ); |
2734 |
if ( $keys ) { |
|
0 | 2735 |
return $keys; |
9 | 2736 |
} |
0 | 2737 |
} |
2738 |
||
2739 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2740 |
* Retrieves values for a custom post field. |
0 | 2741 |
* |
2742 |
* The parameters must not be considered optional. All of the post meta fields |
|
2743 |
* will be retrieved and only the meta field key values returned. |
|
2744 |
* |
|
2745 |
* @since 1.2.0 |
|
5 | 2746 |
* |
2747 |
* @param string $key Optional. Meta field key. Default empty. |
|
19 | 2748 |
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2749 |
* @return array|null Meta field values. |
0 | 2750 |
*/ |
2751 |
function get_post_custom_values( $key = '', $post_id = 0 ) { |
|
9 | 2752 |
if ( ! $key ) { |
0 | 2753 |
return null; |
9 | 2754 |
} |
2755 |
||
2756 |
$custom = get_post_custom( $post_id ); |
|
2757 |
||
2758 |
return isset( $custom[ $key ] ) ? $custom[ $key ] : null; |
|
0 | 2759 |
} |
2760 |
||
2761 |
/** |
|
9 | 2762 |
* Determines whether a post is sticky. |
0 | 2763 |
* |
2764 |
* Sticky posts should remain at the top of The Loop. If the post ID is not |
|
2765 |
* given, then The Loop ID for the current post will be used. |
|
2766 |
* |
|
9 | 2767 |
* For more information on this and similar theme functions, check out |
2768 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
2769 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
2770 |
* |
|
0 | 2771 |
* @since 2.7.0 |
2772 |
* |
|
19 | 2773 |
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
0 | 2774 |
* @return bool Whether post is sticky. |
2775 |
*/ |
|
2776 |
function is_sticky( $post_id = 0 ) { |
|
2777 |
$post_id = absint( $post_id ); |
|
2778 |
||
9 | 2779 |
if ( ! $post_id ) { |
0 | 2780 |
$post_id = get_the_ID(); |
9 | 2781 |
} |
0 | 2782 |
|
2783 |
$stickies = get_option( 'sticky_posts' ); |
|
2784 |
||
16 | 2785 |
if ( is_array( $stickies ) ) { |
2786 |
$stickies = array_map( 'intval', $stickies ); |
|
2787 |
$is_sticky = in_array( $post_id, $stickies, true ); |
|
2788 |
} else { |
|
2789 |
$is_sticky = false; |
|
2790 |
} |
|
2791 |
||
2792 |
/** |
|
2793 |
* Filters whether a post is sticky. |
|
2794 |
* |
|
2795 |
* @since 5.3.0 |
|
2796 |
* |
|
2797 |
* @param bool $is_sticky Whether a post is sticky. |
|
2798 |
* @param int $post_id Post ID. |
|
2799 |
*/ |
|
2800 |
return apply_filters( 'is_sticky', $is_sticky, $post_id ); |
|
0 | 2801 |
} |
2802 |
||
2803 |
/** |
|
18 | 2804 |
* Sanitizes every post field. |
0 | 2805 |
* |
5 | 2806 |
* If the context is 'raw', then the post object or array will get minimal |
2807 |
* sanitization of the integer fields. |
|
0 | 2808 |
* |
2809 |
* @since 2.3.0 |
|
5 | 2810 |
* |
2811 |
* @see sanitize_post_field() |
|
2812 |
* |
|
18 | 2813 |
* @param object|WP_Post|array $post The post object or array |
5 | 2814 |
* @param string $context Optional. How to sanitize post fields. |
18 | 2815 |
* Accepts 'raw', 'edit', 'db', 'display', |
2816 |
* 'attribute', or 'js'. Default 'display'. |
|
2817 |
* @return object|WP_Post|array The now sanitized post object or array (will be the |
|
2818 |
* same type as `$post`). |
|
0 | 2819 |
*/ |
5 | 2820 |
function sanitize_post( $post, $context = 'display' ) { |
9 | 2821 |
if ( is_object( $post ) ) { |
5 | 2822 |
// Check if post already filtered for this context. |
9 | 2823 |
if ( isset( $post->filter ) && $context == $post->filter ) { |
0 | 2824 |
return $post; |
9 | 2825 |
} |
2826 |
if ( ! isset( $post->ID ) ) { |
|
0 | 2827 |
$post->ID = 0; |
9 | 2828 |
} |
2829 |
foreach ( array_keys( get_object_vars( $post ) ) as $field ) { |
|
2830 |
$post->$field = sanitize_post_field( $field, $post->$field, $post->ID, $context ); |
|
2831 |
} |
|
0 | 2832 |
$post->filter = $context; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2833 |
} elseif ( is_array( $post ) ) { |
5 | 2834 |
// Check if post already filtered for this context. |
9 | 2835 |
if ( isset( $post['filter'] ) && $context == $post['filter'] ) { |
0 | 2836 |
return $post; |
9 | 2837 |
} |
2838 |
if ( ! isset( $post['ID'] ) ) { |
|
0 | 2839 |
$post['ID'] = 0; |
9 | 2840 |
} |
2841 |
foreach ( array_keys( $post ) as $field ) { |
|
2842 |
$post[ $field ] = sanitize_post_field( $field, $post[ $field ], $post['ID'], $context ); |
|
2843 |
} |
|
0 | 2844 |
$post['filter'] = $context; |
2845 |
} |
|
2846 |
return $post; |
|
2847 |
} |
|
2848 |
||
2849 |
/** |
|
16 | 2850 |
* Sanitizes a post field based on context. |
0 | 2851 |
* |
5 | 2852 |
* Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and |
2853 |
* 'js'. The 'display' context is used by default. 'attribute' and 'js' contexts |
|
2854 |
* are treated like 'display' when calling filters. |
|
0 | 2855 |
* |
2856 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
* @since 4.4.0 Like `sanitize_post()`, `$context` defaults to 'display'. |
5 | 2858 |
* |
2859 |
* @param string $field The Post Object field name. |
|
2860 |
* @param mixed $value The Post Object value. |
|
2861 |
* @param int $post_id Post ID. |
|
16 | 2862 |
* @param string $context Optional. How to sanitize the field. Possible values are 'raw', 'edit', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2863 |
* 'db', 'display', 'attribute' and 'js'. Default 'display'. |
0 | 2864 |
* @return mixed Sanitized value. |
2865 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2866 |
function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { |
9 | 2867 |
$int_fields = array( 'ID', 'post_parent', 'menu_order' ); |
16 | 2868 |
if ( in_array( $field, $int_fields, true ) ) { |
0 | 2869 |
$value = (int) $value; |
9 | 2870 |
} |
0 | 2871 |
|
5 | 2872 |
// Fields which contain arrays of integers. |
0 | 2873 |
$array_int_fields = array( 'ancestors' ); |
16 | 2874 |
if ( in_array( $field, $array_int_fields, true ) ) { |
9 | 2875 |
$value = array_map( 'absint', $value ); |
0 | 2876 |
return $value; |
2877 |
} |
|
2878 |
||
16 | 2879 |
if ( 'raw' === $context ) { |
0 | 2880 |
return $value; |
9 | 2881 |
} |
0 | 2882 |
|
2883 |
$prefixed = false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2884 |
if ( str_contains( $field, 'post_' ) ) { |
9 | 2885 |
$prefixed = true; |
2886 |
$field_no_prefix = str_replace( 'post_', '', $field ); |
|
0 | 2887 |
} |
2888 |
||
16 | 2889 |
if ( 'edit' === $context ) { |
9 | 2890 |
$format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password' ); |
0 | 2891 |
|
2892 |
if ( $prefixed ) { |
|
5 | 2893 |
|
2894 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2895 |
* Filters the value of a specific post field to edit. |
5 | 2896 |
* |
2897 |
* The dynamic portion of the hook name, `$field`, refers to the post |
|
2898 |
* field name. |
|
2899 |
* |
|
2900 |
* @since 2.3.0 |
|
2901 |
* |
|
2902 |
* @param mixed $value Value of the post field. |
|
2903 |
* @param int $post_id Post ID. |
|
2904 |
*/ |
|
2905 |
$value = apply_filters( "edit_{$field}", $value, $post_id ); |
|
2906 |
||
2907 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2908 |
* Filters the value of a specific post field to edit. |
5 | 2909 |
* |
2910 |
* The dynamic portion of the hook name, `$field_no_prefix`, refers to |
|
2911 |
* the post field name. |
|
2912 |
* |
|
2913 |
* @since 2.3.0 |
|
2914 |
* |
|
2915 |
* @param mixed $value Value of the post field. |
|
2916 |
* @param int $post_id Post ID. |
|
2917 |
*/ |
|
2918 |
$value = apply_filters( "{$field_no_prefix}_edit_pre", $value, $post_id ); |
|
0 | 2919 |
} else { |
5 | 2920 |
$value = apply_filters( "edit_post_{$field}", $value, $post_id ); |
0 | 2921 |
} |
2922 |
||
16 | 2923 |
if ( in_array( $field, $format_to_edit, true ) ) { |
2924 |
if ( 'post_content' === $field ) { |
|
9 | 2925 |
$value = format_to_edit( $value, user_can_richedit() ); |
2926 |
} else { |
|
2927 |
$value = format_to_edit( $value ); |
|
2928 |
} |
|
0 | 2929 |
} else { |
9 | 2930 |
$value = esc_attr( $value ); |
0 | 2931 |
} |
16 | 2932 |
} elseif ( 'db' === $context ) { |
0 | 2933 |
if ( $prefixed ) { |
5 | 2934 |
|
2935 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2936 |
* Filters the value of a specific post field before saving. |
5 | 2937 |
* |
2938 |
* The dynamic portion of the hook name, `$field`, refers to the post |
|
2939 |
* field name. |
|
2940 |
* |
|
2941 |
* @since 2.3.0 |
|
2942 |
* |
|
2943 |
* @param mixed $value Value of the post field. |
|
2944 |
*/ |
|
2945 |
$value = apply_filters( "pre_{$field}", $value ); |
|
2946 |
||
2947 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2948 |
* Filters the value of a specific field before saving. |
5 | 2949 |
* |
2950 |
* The dynamic portion of the hook name, `$field_no_prefix`, refers |
|
2951 |
* to the post field name. |
|
2952 |
* |
|
2953 |
* @since 2.3.0 |
|
2954 |
* |
|
2955 |
* @param mixed $value Value of the post field. |
|
2956 |
*/ |
|
2957 |
$value = apply_filters( "{$field_no_prefix}_save_pre", $value ); |
|
0 | 2958 |
} else { |
5 | 2959 |
$value = apply_filters( "pre_post_{$field}", $value ); |
2960 |
||
2961 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2962 |
* Filters the value of a specific post field before saving. |
5 | 2963 |
* |
2964 |
* The dynamic portion of the hook name, `$field`, refers to the post |
|
2965 |
* field name. |
|
2966 |
* |
|
2967 |
* @since 2.3.0 |
|
2968 |
* |
|
2969 |
* @param mixed $value Value of the post field. |
|
2970 |
*/ |
|
2971 |
$value = apply_filters( "{$field}_pre", $value ); |
|
0 | 2972 |
} |
2973 |
} else { |
|
5 | 2974 |
|
0 | 2975 |
// Use display filters by default. |
5 | 2976 |
if ( $prefixed ) { |
2977 |
||
2978 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2979 |
* Filters the value of a specific post field for display. |
5 | 2980 |
* |
2981 |
* The dynamic portion of the hook name, `$field`, refers to the post |
|
2982 |
* field name. |
|
2983 |
* |
|
2984 |
* @since 2.3.0 |
|
2985 |
* |
|
2986 |
* @param mixed $value Value of the prefixed post field. |
|
2987 |
* @param int $post_id Post ID. |
|
18 | 2988 |
* @param string $context Context for how to sanitize the field. |
2989 |
* Accepts 'raw', 'edit', 'db', 'display', |
|
2990 |
* 'attribute', or 'js'. Default 'display'. |
|
5 | 2991 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2992 |
$value = apply_filters( "{$field}", $value, $post_id, $context ); |
5 | 2993 |
} else { |
2994 |
$value = apply_filters( "post_{$field}", $value, $post_id, $context ); |
|
2995 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2996 |
|
16 | 2997 |
if ( 'attribute' === $context ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2998 |
$value = esc_attr( $value ); |
16 | 2999 |
} elseif ( 'js' === $context ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3000 |
$value = esc_js( $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3001 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3002 |
} |
0 | 3003 |
|
18 | 3004 |
// Restore the type for integer fields after esc_attr(). |
3005 |
if ( in_array( $field, $int_fields, true ) ) { |
|
3006 |
$value = (int) $value; |
|
3007 |
} |
|
3008 |
||
0 | 3009 |
return $value; |
3010 |
} |
|
3011 |
||
3012 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3013 |
* Makes a post sticky. |
0 | 3014 |
* |
3015 |
* Sticky posts should be displayed at the top of the front page. |
|
3016 |
* |
|
3017 |
* @since 2.7.0 |
|
3018 |
* |
|
3019 |
* @param int $post_id Post ID. |
|
3020 |
*/ |
|
5 | 3021 |
function stick_post( $post_id ) { |
16 | 3022 |
$post_id = (int) $post_id; |
9 | 3023 |
$stickies = get_option( 'sticky_posts' ); |
18 | 3024 |
$updated = false; |
9 | 3025 |
|
3026 |
if ( ! is_array( $stickies ) ) { |
|
19 | 3027 |
$stickies = array(); |
18 | 3028 |
} else { |
3029 |
$stickies = array_unique( array_map( 'intval', $stickies ) ); |
|
3030 |
} |
|
16 | 3031 |
|
3032 |
if ( ! in_array( $post_id, $stickies, true ) ) { |
|
0 | 3033 |
$stickies[] = $post_id; |
18 | 3034 |
$updated = update_option( 'sticky_posts', array_values( $stickies ) ); |
3035 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3036 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3037 |
if ( $updated ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3038 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3039 |
* Fires once a post has been added to the sticky list. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3040 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3041 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3042 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3043 |
* @param int $post_id ID of the post that was stuck. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3044 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3045 |
do_action( 'post_stuck', $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3046 |
} |
0 | 3047 |
} |
3048 |
||
3049 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3050 |
* Un-sticks a post. |
0 | 3051 |
* |
3052 |
* Sticky posts should be displayed at the top of the front page. |
|
3053 |
* |
|
3054 |
* @since 2.7.0 |
|
3055 |
* |
|
3056 |
* @param int $post_id Post ID. |
|
3057 |
*/ |
|
5 | 3058 |
function unstick_post( $post_id ) { |
16 | 3059 |
$post_id = (int) $post_id; |
9 | 3060 |
$stickies = get_option( 'sticky_posts' ); |
3061 |
||
3062 |
if ( ! is_array( $stickies ) ) { |
|
0 | 3063 |
return; |
9 | 3064 |
} |
3065 |
||
18 | 3066 |
$stickies = array_values( array_unique( array_map( 'intval', $stickies ) ) ); |
16 | 3067 |
|
3068 |
if ( ! in_array( $post_id, $stickies, true ) ) { |
|
0 | 3069 |
return; |
9 | 3070 |
} |
3071 |
||
16 | 3072 |
$offset = array_search( $post_id, $stickies, true ); |
9 | 3073 |
if ( false === $offset ) { |
0 | 3074 |
return; |
9 | 3075 |
} |
3076 |
||
3077 |
array_splice( $stickies, $offset, 1 ); |
|
0 | 3078 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3079 |
$updated = update_option( 'sticky_posts', $stickies ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3081 |
if ( $updated ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3082 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3083 |
* Fires once a post has been removed from the sticky list. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3084 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3085 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3086 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3087 |
* @param int $post_id ID of the post that was unstuck. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3088 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3089 |
do_action( 'post_unstuck', $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3090 |
} |
0 | 3091 |
} |
3092 |
||
3093 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3094 |
* Returns the cache key for wp_count_posts() based on the passed arguments. |
5 | 3095 |
* |
3096 |
* @since 3.9.0 |
|
9 | 3097 |
* @access private |
5 | 3098 |
* |
3099 |
* @param string $type Optional. Post type to retrieve count Default 'post'. |
|
3100 |
* @param string $perm Optional. 'readable' or empty. Default empty. |
|
3101 |
* @return string The cache key. |
|
3102 |
*/ |
|
3103 |
function _count_posts_cache_key( $type = 'post', $perm = '' ) { |
|
3104 |
$cache_key = 'posts-' . $type; |
|
16 | 3105 |
|
3106 |
if ( 'readable' === $perm && is_user_logged_in() ) { |
|
5 | 3107 |
$post_type_object = get_post_type_object( $type ); |
16 | 3108 |
|
5 | 3109 |
if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) { |
3110 |
$cache_key .= '_' . $perm . '_' . get_current_user_id(); |
|
3111 |
} |
|
3112 |
} |
|
16 | 3113 |
|
5 | 3114 |
return $cache_key; |
3115 |
} |
|
3116 |
||
3117 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3118 |
* Counts number of posts of a post type and if user has permissions to view. |
0 | 3119 |
* |
3120 |
* This function provides an efficient method of finding the amount of post's |
|
3121 |
* type a blog has. Another method is to count the amount of items in |
|
3122 |
* get_posts(), but that method has a lot of overhead with doing so. Therefore, |
|
3123 |
* when developing for 2.5+, use this function instead. |
|
3124 |
* |
|
3125 |
* The $perm parameter checks for 'readable' value and if the user can read |
|
3126 |
* private posts, it will display that for the user that is signed in. |
|
3127 |
* |
|
3128 |
* @since 2.5.0 |
|
3129 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3130 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3131 |
* |
5 | 3132 |
* @param string $type Optional. Post type to retrieve count. Default 'post'. |
3133 |
* @param string $perm Optional. 'readable' or empty. Default empty. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3134 |
* @return stdClass An object containing the number of posts for each status, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3135 |
* or an empty object if the post type does not exist. |
0 | 3136 |
*/ |
3137 |
function wp_count_posts( $type = 'post', $perm = '' ) { |
|
3138 |
global $wpdb; |
|
3139 |
||
9 | 3140 |
if ( ! post_type_exists( $type ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3141 |
return new stdClass(); |
9 | 3142 |
} |
0 | 3143 |
|
5 | 3144 |
$cache_key = _count_posts_cache_key( $type, $perm ); |
3145 |
||
3146 |
$counts = wp_cache_get( $cache_key, 'counts' ); |
|
3147 |
if ( false !== $counts ) { |
|
16 | 3148 |
// We may have cached this before every status was registered. |
3149 |
foreach ( get_post_stati() as $status ) { |
|
3150 |
if ( ! isset( $counts->{$status} ) ) { |
|
3151 |
$counts->{$status} = 0; |
|
3152 |
} |
|
3153 |
} |
|
3154 |
||
5 | 3155 |
/** This filter is documented in wp-includes/post.php */ |
3156 |
return apply_filters( 'wp_count_posts', $counts, $type, $perm ); |
|
3157 |
} |
|
0 | 3158 |
|
3159 |
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; |
|
16 | 3160 |
|
3161 |
if ( 'readable' === $perm && is_user_logged_in() ) { |
|
9 | 3162 |
$post_type_object = get_post_type_object( $type ); |
5 | 3163 |
if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) { |
9 | 3164 |
$query .= $wpdb->prepare( |
3165 |
" AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", |
|
5 | 3166 |
get_current_user_id() |
3167 |
); |
|
0 | 3168 |
} |
3169 |
} |
|
16 | 3170 |
|
0 | 3171 |
$query .= ' GROUP BY post_status'; |
3172 |
||
5 | 3173 |
$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); |
9 | 3174 |
$counts = array_fill_keys( get_post_stati(), 0 ); |
5 | 3175 |
|
3176 |
foreach ( $results as $row ) { |
|
3177 |
$counts[ $row['post_status'] ] = $row['num_posts']; |
|
0 | 3178 |
} |
3179 |
||
5 | 3180 |
$counts = (object) $counts; |
3181 |
wp_cache_set( $cache_key, $counts, 'counts' ); |
|
3182 |
||
0 | 3183 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3184 |
* Filters the post counts by status for the current post type. |
0 | 3185 |
* |
3186 |
* @since 3.7.0 |
|
3187 |
* |
|
19 | 3188 |
* @param stdClass $counts An object containing the current post_type's post |
3189 |
* counts by status. |
|
3190 |
* @param string $type Post type. |
|
3191 |
* @param string $perm The permission to determine if the posts are 'readable' |
|
3192 |
* by the current user. |
|
0 | 3193 |
*/ |
3194 |
return apply_filters( 'wp_count_posts', $counts, $type, $perm ); |
|
3195 |
} |
|
3196 |
||
3197 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3198 |
* Counts number of attachments for the mime type(s). |
0 | 3199 |
* |
3200 |
* If you set the optional mime_type parameter, then an array will still be |
|
3201 |
* returned, but will only have the item you are looking for. It does not give |
|
3202 |
* you the number of attachments that are children of a post. You can get that |
|
3203 |
* by counting the number of children that post has. |
|
3204 |
* |
|
3205 |
* @since 2.5.0 |
|
3206 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3207 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3208 |
* |
18 | 3209 |
* @param string|string[] $mime_type Optional. Array or comma-separated list of |
3210 |
* MIME patterns. Default empty. |
|
19 | 3211 |
* @return stdClass An object containing the attachment counts by mime type. |
0 | 3212 |
*/ |
3213 |
function wp_count_attachments( $mime_type = '' ) { |
|
3214 |
global $wpdb; |
|
3215 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3216 |
$cache_key = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3217 |
'attachments%s', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3218 |
! empty( $mime_type ) ? ':' . str_replace( '/', '_', implode( '-', (array) $mime_type ) ) : '' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3219 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3220 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3221 |
$counts = wp_cache_get( $cache_key, 'counts' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3222 |
if ( false == $counts ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3223 |
$and = wp_post_mime_type_where( $mime_type ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3224 |
$count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3225 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3226 |
$counts = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3227 |
foreach ( (array) $count as $row ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3228 |
$counts[ $row['post_mime_type'] ] = $row['num_posts']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3229 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3230 |
$counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and" ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3231 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3232 |
wp_cache_set( $cache_key, (object) $counts, 'counts' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3233 |
} |
0 | 3234 |
|
3235 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3236 |
* Filters the attachment counts by mime type. |
0 | 3237 |
* |
3238 |
* @since 3.7.0 |
|
3239 |
* |
|
19 | 3240 |
* @param stdClass $counts An object containing the attachment counts by |
18 | 3241 |
* mime type. |
3242 |
* @param string|string[] $mime_type Array or comma-separated list of MIME patterns. |
|
0 | 3243 |
*/ |
3244 |
return apply_filters( 'wp_count_attachments', (object) $counts, $mime_type ); |
|
3245 |
} |
|
3246 |
||
3247 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3248 |
* Gets default post mime types. |
0 | 3249 |
* |
3250 |
* @since 2.9.0 |
|
16 | 3251 |
* @since 5.3.0 Added the 'Documents', 'Spreadsheets', and 'Archives' mime type groups. |
0 | 3252 |
* |
5 | 3253 |
* @return array List of post mime types. |
0 | 3254 |
*/ |
3255 |
function get_post_mime_types() { |
|
16 | 3256 |
$post_mime_types = array( // array( adj, noun ) |
3257 |
'image' => array( |
|
3258 |
__( 'Images' ), |
|
3259 |
__( 'Manage Images' ), |
|
3260 |
/* translators: %s: Number of images. */ |
|
3261 |
_n_noop( |
|
3262 |
'Image <span class="count">(%s)</span>', |
|
3263 |
'Images <span class="count">(%s)</span>' |
|
3264 |
), |
|
3265 |
), |
|
3266 |
'audio' => array( |
|
19 | 3267 |
_x( 'Audio', 'file type group' ), |
16 | 3268 |
__( 'Manage Audio' ), |
3269 |
/* translators: %s: Number of audio files. */ |
|
3270 |
_n_noop( |
|
3271 |
'Audio <span class="count">(%s)</span>', |
|
3272 |
'Audio <span class="count">(%s)</span>' |
|
3273 |
), |
|
3274 |
), |
|
3275 |
'video' => array( |
|
19 | 3276 |
_x( 'Video', 'file type group' ), |
16 | 3277 |
__( 'Manage Video' ), |
3278 |
/* translators: %s: Number of video files. */ |
|
3279 |
_n_noop( |
|
3280 |
'Video <span class="count">(%s)</span>', |
|
3281 |
'Video <span class="count">(%s)</span>' |
|
3282 |
), |
|
3283 |
), |
|
3284 |
'document' => array( |
|
3285 |
__( 'Documents' ), |
|
3286 |
__( 'Manage Documents' ), |
|
3287 |
/* translators: %s: Number of documents. */ |
|
3288 |
_n_noop( |
|
3289 |
'Document <span class="count">(%s)</span>', |
|
3290 |
'Documents <span class="count">(%s)</span>' |
|
3291 |
), |
|
3292 |
), |
|
3293 |
'spreadsheet' => array( |
|
3294 |
__( 'Spreadsheets' ), |
|
3295 |
__( 'Manage Spreadsheets' ), |
|
3296 |
/* translators: %s: Number of spreadsheets. */ |
|
3297 |
_n_noop( |
|
3298 |
'Spreadsheet <span class="count">(%s)</span>', |
|
3299 |
'Spreadsheets <span class="count">(%s)</span>' |
|
3300 |
), |
|
3301 |
), |
|
3302 |
'archive' => array( |
|
3303 |
_x( 'Archives', 'file type group' ), |
|
3304 |
__( 'Manage Archives' ), |
|
3305 |
/* translators: %s: Number of archives. */ |
|
3306 |
_n_noop( |
|
3307 |
'Archive <span class="count">(%s)</span>', |
|
3308 |
'Archives <span class="count">(%s)</span>' |
|
3309 |
), |
|
3310 |
), |
|
0 | 3311 |
); |
3312 |
||
16 | 3313 |
$ext_types = wp_get_ext_types(); |
3314 |
$mime_types = wp_get_mime_types(); |
|
3315 |
||
3316 |
foreach ( $post_mime_types as $group => $labels ) { |
|
3317 |
if ( in_array( $group, array( 'image', 'audio', 'video' ), true ) ) { |
|
3318 |
continue; |
|
3319 |
} |
|
3320 |
||
3321 |
if ( ! isset( $ext_types[ $group ] ) ) { |
|
3322 |
unset( $post_mime_types[ $group ] ); |
|
3323 |
continue; |
|
3324 |
} |
|
3325 |
||
3326 |
$group_mime_types = array(); |
|
3327 |
foreach ( $ext_types[ $group ] as $extension ) { |
|
3328 |
foreach ( $mime_types as $exts => $mime ) { |
|
3329 |
if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
|
3330 |
$group_mime_types[] = $mime; |
|
3331 |
break; |
|
3332 |
} |
|
3333 |
} |
|
3334 |
} |
|
3335 |
$group_mime_types = implode( ',', array_unique( $group_mime_types ) ); |
|
3336 |
||
3337 |
$post_mime_types[ $group_mime_types ] = $labels; |
|
3338 |
unset( $post_mime_types[ $group ] ); |
|
3339 |
} |
|
3340 |
||
5 | 3341 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3342 |
* Filters the default list of post mime types. |
5 | 3343 |
* |
3344 |
* @since 2.5.0 |
|
3345 |
* |
|
3346 |
* @param array $post_mime_types Default list of post mime types. |
|
3347 |
*/ |
|
3348 |
return apply_filters( 'post_mime_types', $post_mime_types ); |
|
0 | 3349 |
} |
3350 |
||
3351 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3352 |
* Checks a MIME-Type against a list. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3353 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3354 |
* If the `$wildcard_mime_types` parameter is a string, it must be comma separated |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3355 |
* list. If the `$real_mime_types` is a string, it is also comma separated to |
0 | 3356 |
* create the list. |
3357 |
* |
|
3358 |
* @since 2.5.0 |
|
3359 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3360 |
* @param string|string[] $wildcard_mime_types Mime types, e.g. `audio/mpeg`, `image` (same as `image/*`), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3361 |
* or `flash` (same as `*flash*`). |
18 | 3362 |
* @param string|string[] $real_mime_types Real post mime type values. |
5 | 3363 |
* @return array array(wildcard=>array(real types)). |
0 | 3364 |
*/ |
5 | 3365 |
function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) { |
0 | 3366 |
$matches = array(); |
5 | 3367 |
if ( is_string( $wildcard_mime_types ) ) { |
3368 |
$wildcard_mime_types = array_map( 'trim', explode( ',', $wildcard_mime_types ) ); |
|
3369 |
} |
|
3370 |
if ( is_string( $real_mime_types ) ) { |
|
3371 |
$real_mime_types = array_map( 'trim', explode( ',', $real_mime_types ) ); |
|
3372 |
} |
|
3373 |
||
3374 |
$patternses = array(); |
|
9 | 3375 |
$wild = '[-._a-z0-9]*'; |
5 | 3376 |
|
0 | 3377 |
foreach ( (array) $wildcard_mime_types as $type ) { |
5 | 3378 |
$mimes = array_map( 'trim', explode( ',', $type ) ); |
3379 |
foreach ( $mimes as $mime ) { |
|
16 | 3380 |
$regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) ); |
3381 |
||
9 | 3382 |
$patternses[][ $type ] = "^$regex$"; |
16 | 3383 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3384 |
if ( ! str_contains( $mime, '/' ) ) { |
9 | 3385 |
$patternses[][ $type ] = "^$regex/"; |
3386 |
$patternses[][ $type ] = $regex; |
|
5 | 3387 |
} |
0 | 3388 |
} |
3389 |
} |
|
5 | 3390 |
asort( $patternses ); |
3391 |
||
3392 |
foreach ( $patternses as $patterns ) { |
|
3393 |
foreach ( $patterns as $type => $pattern ) { |
|
3394 |
foreach ( (array) $real_mime_types as $real ) { |
|
16 | 3395 |
if ( preg_match( "#$pattern#", $real ) |
3396 |
&& ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ], true ) ) |
|
3397 |
) { |
|
9 | 3398 |
$matches[ $type ][] = $real; |
5 | 3399 |
} |
3400 |
} |
|
3401 |
} |
|
3402 |
} |
|
16 | 3403 |
|
0 | 3404 |
return $matches; |
3405 |
} |
|
3406 |
||
3407 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3408 |
* Converts MIME types into SQL. |
0 | 3409 |
* |
3410 |
* @since 2.5.0 |
|
3411 |
* |
|
18 | 3412 |
* @param string|string[] $post_mime_types List of mime types or comma separated string |
3413 |
* of mime types. |
|
3414 |
* @param string $table_alias Optional. Specify a table alias, if needed. |
|
3415 |
* Default empty. |
|
0 | 3416 |
* @return string The SQL AND clause for mime searching. |
3417 |
*/ |
|
5 | 3418 |
function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { |
9 | 3419 |
$where = ''; |
3420 |
$wildcards = array( '', '%', '%/%' ); |
|
3421 |
if ( is_string( $post_mime_types ) ) { |
|
3422 |
$post_mime_types = array_map( 'trim', explode( ',', $post_mime_types ) ); |
|
3423 |
} |
|
5 | 3424 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3425 |
$where_clauses = array(); |
5 | 3426 |
|
0 | 3427 |
foreach ( (array) $post_mime_types as $mime_type ) { |
9 | 3428 |
$mime_type = preg_replace( '/\s/', '', $mime_type ); |
3429 |
$slashpos = strpos( $mime_type, '/' ); |
|
0 | 3430 |
if ( false !== $slashpos ) { |
9 | 3431 |
$mime_group = preg_replace( '/[^-*.a-zA-Z0-9]/', '', substr( $mime_type, 0, $slashpos ) ); |
3432 |
$mime_subgroup = preg_replace( '/[^-*.+a-zA-Z0-9]/', '', substr( $mime_type, $slashpos + 1 ) ); |
|
3433 |
if ( empty( $mime_subgroup ) ) { |
|
0 | 3434 |
$mime_subgroup = '*'; |
9 | 3435 |
} else { |
3436 |
$mime_subgroup = str_replace( '/', '', $mime_subgroup ); |
|
3437 |
} |
|
0 | 3438 |
$mime_pattern = "$mime_group/$mime_subgroup"; |
3439 |
} else { |
|
9 | 3440 |
$mime_pattern = preg_replace( '/[^-*.a-zA-Z0-9]/', '', $mime_type ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3441 |
if ( ! str_contains( $mime_pattern, '*' ) ) { |
0 | 3442 |
$mime_pattern .= '/*'; |
9 | 3443 |
} |
0 | 3444 |
} |
3445 |
||
9 | 3446 |
$mime_pattern = preg_replace( '/\*+/', '%', $mime_pattern ); |
3447 |
||
16 | 3448 |
if ( in_array( $mime_type, $wildcards, true ) ) { |
0 | 3449 |
return ''; |
9 | 3450 |
} |
3451 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3452 |
if ( str_contains( $mime_pattern, '%' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3453 |
$where_clauses[] = empty( $table_alias ) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; |
9 | 3454 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3455 |
$where_clauses[] = empty( $table_alias ) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3456 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3457 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3458 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3459 |
if ( ! empty( $where_clauses ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3460 |
$where = ' AND (' . implode( ' OR ', $where_clauses ) . ') '; |
9 | 3461 |
} |
16 | 3462 |
|
0 | 3463 |
return $where; |
3464 |
} |
|
3465 |
||
3466 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3467 |
* Trashes or deletes a post or page. |
5 | 3468 |
* |
3469 |
* When the post and page is permanently deleted, everything that is tied to |
|
3470 |
* it is deleted also. This includes comments, post meta fields, and terms |
|
3471 |
* associated with the post. |
|
3472 |
* |
|
16 | 3473 |
* The post or page is moved to Trash instead of permanently deleted unless |
3474 |
* Trash is disabled, item is already in the Trash, or $force_delete is true. |
|
0 | 3475 |
* |
3476 |
* @since 1.0.0 |
|
5 | 3477 |
* |
3478 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
3479 |
* @see wp_delete_attachment() |
|
3480 |
* @see wp_trash_post() |
|
3481 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3482 |
* @param int $post_id Optional. Post ID. Default 0. |
16 | 3483 |
* @param bool $force_delete Optional. Whether to bypass Trash and force deletion. |
5 | 3484 |
* Default false. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3485 |
* @return WP_Post|false|null Post data on success, false or null on failure. |
0 | 3486 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3487 |
function wp_delete_post( $post_id = 0, $force_delete = false ) { |
0 | 3488 |
global $wpdb; |
3489 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3490 |
$post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3491 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3492 |
if ( ! $post ) { |
0 | 3493 |
return $post; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3494 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3495 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3496 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3497 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3498 |
if ( ! $force_delete |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3499 |
&& ( 'post' === $post->post_type || 'page' === $post->post_type ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3500 |
&& 'trash' !== get_post_status( $post_id ) && EMPTY_TRASH_DAYS |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3501 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3502 |
return wp_trash_post( $post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3503 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3504 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3505 |
if ( 'attachment' === $post->post_type ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3506 |
return wp_delete_attachment( $post_id, $force_delete ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3507 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3508 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3509 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3510 |
* Filters whether a post deletion should take place. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3511 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3512 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3513 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3514 |
* @param WP_Post|false|null $delete Whether to go forward with deletion. |
19 | 3515 |
* @param WP_Post $post Post object. |
3516 |
* @param bool $force_delete Whether to bypass the Trash. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3517 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3518 |
$check = apply_filters( 'pre_delete_post', null, $post, $force_delete ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
if ( null !== $check ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3520 |
return $check; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3521 |
} |
0 | 3522 |
|
5 | 3523 |
/** |
3524 |
* Fires before a post is deleted, at the start of wp_delete_post(). |
|
3525 |
* |
|
3526 |
* @since 3.2.0 |
|
16 | 3527 |
* @since 5.5.0 Added the `$post` parameter. |
5 | 3528 |
* |
3529 |
* @see wp_delete_post() |
|
3530 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3531 |
* @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
|
3532 |
* @param WP_Post $post Post object. |
5 | 3533 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3534 |
do_action( 'before_delete_post', $post_id, $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3535 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3536 |
delete_post_meta( $post_id, '_wp_trash_meta_status' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3537 |
delete_post_meta( $post_id, '_wp_trash_meta_time' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3538 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3539 |
wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) ); |
9 | 3540 |
|
3541 |
$parent_data = array( 'post_parent' => $post->post_parent ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3542 |
$parent_where = array( 'post_parent' => $post_id ); |
0 | 3543 |
|
3544 |
if ( is_post_type_hierarchical( $post->post_type ) ) { |
|
5 | 3545 |
// Point children of this page to its parent, also clean the cache of affected children. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3546 |
$children_query = $wpdb->prepare( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3547 |
"SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3548 |
$post_id, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3549 |
$post->post_type |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3550 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3551 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3552 |
$children = $wpdb->get_results( $children_query ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3553 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3554 |
if ( $children ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3555 |
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3556 |
} |
0 | 3557 |
} |
3558 |
||
5 | 3559 |
// Do raw query. wp_get_post_revisions() is filtered. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3560 |
$revision_ids = $wpdb->get_col( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3561 |
$wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $post_id ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3562 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3563 |
|
0 | 3564 |
// Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. |
9 | 3565 |
foreach ( $revision_ids as $revision_id ) { |
0 | 3566 |
wp_delete_post_revision( $revision_id ); |
9 | 3567 |
} |
0 | 3568 |
|
5 | 3569 |
// Point all attachments to this post up one level. |
0 | 3570 |
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) ); |
3571 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3572 |
wp_defer_comment_counting( true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3573 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3574 |
$comment_ids = $wpdb->get_col( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3575 |
$wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $post_id ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3576 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3577 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3578 |
foreach ( $comment_ids as $comment_id ) { |
0 | 3579 |
wp_delete_comment( $comment_id, true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3581 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
wp_defer_comment_counting( false ); |
0 | 3583 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3584 |
$post_meta_ids = $wpdb->get_col( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3585 |
$wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3586 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3587 |
|
9 | 3588 |
foreach ( $post_meta_ids as $mid ) { |
0 | 3589 |
delete_metadata_by_mid( 'post', $mid ); |
9 | 3590 |
} |
0 | 3591 |
|
5 | 3592 |
/** |
3593 |
* Fires immediately before a post is deleted from the database. |
|
3594 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3595 |
* The dynamic portion of the hook name, `$post->post_type`, refers to |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3596 |
* the post type slug. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3597 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3598 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3599 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3600 |
* @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
|
3601 |
* @param WP_Post $post Post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3602 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3603 |
do_action( "delete_post_{$post->post_type}", $post_id, $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3604 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3605 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3606 |
* Fires immediately before a post is deleted from the database. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3607 |
* |
5 | 3608 |
* @since 1.2.0 |
16 | 3609 |
* @since 5.5.0 Added the `$post` parameter. |
5 | 3610 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3611 |
* @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
|
3612 |
* @param WP_Post $post Post object. |
5 | 3613 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3614 |
do_action( 'delete_post', $post_id, $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3615 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3616 |
$result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) ); |
5 | 3617 |
if ( ! $result ) { |
3618 |
return false; |
|
3619 |
} |
|
3620 |
||
3621 |
/** |
|
3622 |
* Fires immediately after a post is deleted from the database. |
|
3623 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3624 |
* The dynamic portion of the hook name, `$post->post_type`, refers to |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3625 |
* the post type slug. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3626 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3627 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3628 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3629 |
* @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
|
3630 |
* @param WP_Post $post Post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3631 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3632 |
do_action( "deleted_post_{$post->post_type}", $post_id, $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3633 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3634 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3635 |
* Fires immediately after a post is deleted from the database. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3636 |
* |
5 | 3637 |
* @since 2.2.0 |
16 | 3638 |
* @since 5.5.0 Added the `$post` parameter. |
5 | 3639 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3640 |
* @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
|
3641 |
* @param WP_Post $post Post object. |
5 | 3642 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3643 |
do_action( 'deleted_post', $post_id, $post ); |
0 | 3644 |
|
3645 |
clean_post_cache( $post ); |
|
3646 |
||
3647 |
if ( is_post_type_hierarchical( $post->post_type ) && $children ) { |
|
9 | 3648 |
foreach ( $children as $child ) { |
0 | 3649 |
clean_post_cache( $child ); |
9 | 3650 |
} |
3651 |
} |
|
3652 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3653 |
wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); |
0 | 3654 |
|
5 | 3655 |
/** |
3656 |
* Fires after a post is deleted, at the conclusion of wp_delete_post(). |
|
3657 |
* |
|
3658 |
* @since 3.2.0 |
|
16 | 3659 |
* @since 5.5.0 Added the `$post` parameter. |
5 | 3660 |
* |
3661 |
* @see wp_delete_post() |
|
3662 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3663 |
* @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
|
3664 |
* @param WP_Post $post Post object. |
5 | 3665 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3666 |
do_action( 'after_delete_post', $post_id, $post ); |
0 | 3667 |
|
3668 |
return $post; |
|
3669 |
} |
|
3670 |
||
3671 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3672 |
* Resets the page_on_front, show_on_front, and page_for_post settings when |
5 | 3673 |
* a linked page is deleted or trashed. |
0 | 3674 |
* |
3675 |
* Also ensures the post is no longer sticky. |
|
3676 |
* |
|
5 | 3677 |
* @since 3.7.0 |
0 | 3678 |
* @access private |
5 | 3679 |
* |
3680 |
* @param int $post_id Post ID. |
|
0 | 3681 |
*/ |
3682 |
function _reset_front_page_settings_for_post( $post_id ) { |
|
3683 |
$post = get_post( $post_id ); |
|
16 | 3684 |
|
3685 |
if ( 'page' === $post->post_type ) { |
|
9 | 3686 |
/* |
16 | 3687 |
* If the page is defined in option page_on_front or post_for_posts, |
3688 |
* adjust the corresponding options. |
|
3689 |
*/ |
|
0 | 3690 |
if ( get_option( 'page_on_front' ) == $post->ID ) { |
3691 |
update_option( 'show_on_front', 'posts' ); |
|
3692 |
update_option( 'page_on_front', 0 ); |
|
3693 |
} |
|
3694 |
if ( get_option( 'page_for_posts' ) == $post->ID ) { |
|
16 | 3695 |
update_option( 'page_for_posts', 0 ); |
0 | 3696 |
} |
3697 |
} |
|
16 | 3698 |
|
0 | 3699 |
unstick_post( $post->ID ); |
3700 |
} |
|
3701 |
||
3702 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3703 |
* Moves a post or page to the Trash |
0 | 3704 |
* |
16 | 3705 |
* If Trash is disabled, the post or page is permanently deleted. |
0 | 3706 |
* |
3707 |
* @since 2.9.0 |
|
5 | 3708 |
* |
3709 |
* @see wp_delete_post() |
|
3710 |
* |
|
19 | 3711 |
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post` |
3712 |
* if `EMPTY_TRASH_DAYS` equals true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3713 |
* @return WP_Post|false|null Post data on success, false or null on failure. |
0 | 3714 |
*/ |
5 | 3715 |
function wp_trash_post( $post_id = 0 ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3716 |
if ( ! EMPTY_TRASH_DAYS ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3717 |
return wp_delete_post( $post_id, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3718 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3720 |
$post = get_post( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3721 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3722 |
if ( ! $post ) { |
0 | 3723 |
return $post; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3724 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3725 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3726 |
if ( 'trash' === $post->post_status ) { |
0 | 3727 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3728 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3729 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3730 |
$previous_status = $post->post_status; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3731 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3732 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3733 |
* Filters whether a post trashing should take place. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3734 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3735 |
* @since 4.9.0 |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3736 |
* @since 6.3.0 Added the `$previous_status` parameter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3737 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3738 |
* @param bool|null $trash Whether to go forward with trashing. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3739 |
* @param WP_Post $post Post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3740 |
* @param string $previous_status The status of the post about to be trashed. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3742 |
$check = apply_filters( 'pre_trash_post', null, $post, $previous_status ); |
18 | 3743 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
if ( null !== $check ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
return $check; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
} |
0 | 3747 |
|
5 | 3748 |
/** |
16 | 3749 |
* Fires before a post is sent to the Trash. |
5 | 3750 |
* |
3751 |
* @since 3.3.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3752 |
* @since 6.3.0 Added the `$previous_status` parameter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3753 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3754 |
* @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
|
3755 |
* @param string $previous_status The status of the post about to be trashed. |
5 | 3756 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3757 |
do_action( 'wp_trash_post', $post_id, $previous_status ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3758 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3759 |
add_post_meta( $post_id, '_wp_trash_meta_status', $previous_status ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3760 |
add_post_meta( $post_id, '_wp_trash_meta_time', time() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3761 |
|
16 | 3762 |
$post_updated = wp_update_post( |
9 | 3763 |
array( |
3764 |
'ID' => $post_id, |
|
3765 |
'post_status' => 'trash', |
|
3766 |
) |
|
3767 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3768 |
|
16 | 3769 |
if ( ! $post_updated ) { |
3770 |
return false; |
|
3771 |
} |
|
3772 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3773 |
wp_trash_post_comments( $post_id ); |
0 | 3774 |
|
5 | 3775 |
/** |
16 | 3776 |
* Fires after a post is sent to the Trash. |
5 | 3777 |
* |
3778 |
* @since 2.9.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3779 |
* @since 6.3.0 Added the `$previous_status` parameter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3780 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3781 |
* @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
|
3782 |
* @param string $previous_status The status of the post at the point where it was trashed. |
5 | 3783 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3784 |
do_action( 'trashed_post', $post_id, $previous_status ); |
0 | 3785 |
|
3786 |
return $post; |
|
3787 |
} |
|
3788 |
||
3789 |
/** |
|
18 | 3790 |
* Restores a post from the Trash. |
0 | 3791 |
* |
3792 |
* @since 2.9.0 |
|
18 | 3793 |
* @since 5.6.0 An untrashed post is now returned to 'draft' status by default, except for |
3794 |
* attachments which are returned to their original 'inherit' status. |
|
3795 |
* |
|
19 | 3796 |
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3797 |
* @return WP_Post|false|null Post data on success, false or null on failure. |
0 | 3798 |
*/ |
5 | 3799 |
function wp_untrash_post( $post_id = 0 ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3800 |
$post = get_post( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3801 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3802 |
if ( ! $post ) { |
0 | 3803 |
return $post; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3804 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3805 |
|
18 | 3806 |
$post_id = $post->ID; |
3807 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3808 |
if ( 'trash' !== $post->post_status ) { |
0 | 3809 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3810 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3811 |
|
18 | 3812 |
$previous_status = get_post_meta( $post_id, '_wp_trash_meta_status', true ); |
3813 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3814 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3815 |
* Filters whether a post untrashing should take place. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3816 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3817 |
* @since 4.9.0 |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3818 |
* @since 5.6.0 Added the `$previous_status` parameter. |
18 | 3819 |
* |
3820 |
* @param bool|null $untrash Whether to go forward with untrashing. |
|
3821 |
* @param WP_Post $post Post object. |
|
3822 |
* @param string $previous_status The status of the post at the point where it was trashed. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3823 |
*/ |
18 | 3824 |
$check = apply_filters( 'pre_untrash_post', null, $post, $previous_status ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
if ( null !== $check ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3826 |
return $check; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3827 |
} |
0 | 3828 |
|
5 | 3829 |
/** |
16 | 3830 |
* Fires before a post is restored from the Trash. |
5 | 3831 |
* |
3832 |
* @since 2.9.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3833 |
* @since 5.6.0 Added the `$previous_status` parameter. |
18 | 3834 |
* |
3835 |
* @param int $post_id Post ID. |
|
3836 |
* @param string $previous_status The status of the post at the point where it was trashed. |
|
5 | 3837 |
*/ |
18 | 3838 |
do_action( 'untrash_post', $post_id, $previous_status ); |
3839 |
||
3840 |
$new_status = ( 'attachment' === $post->post_type ) ? 'inherit' : 'draft'; |
|
3841 |
||
3842 |
/** |
|
3843 |
* Filters the status that a post gets assigned when it is restored from the trash (untrashed). |
|
3844 |
* |
|
3845 |
* By default posts that are restored will be assigned a status of 'draft'. Return the value of `$previous_status` |
|
3846 |
* in order to assign the status that the post had before it was trashed. The `wp_untrash_post_set_previous_status()` |
|
3847 |
* function is available for this. |
|
3848 |
* |
|
3849 |
* Prior to WordPress 5.6.0, restored posts were always assigned their original status. |
|
3850 |
* |
|
3851 |
* @since 5.6.0 |
|
3852 |
* |
|
3853 |
* @param string $new_status The new status of the post being restored. |
|
3854 |
* @param int $post_id The ID of the post being restored. |
|
3855 |
* @param string $previous_status The status of the post at the point where it was trashed. |
|
3856 |
*/ |
|
3857 |
$post_status = apply_filters( 'wp_untrash_post_status', $new_status, $post_id, $previous_status ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3858 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3859 |
delete_post_meta( $post_id, '_wp_trash_meta_status' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3860 |
delete_post_meta( $post_id, '_wp_trash_meta_time' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3861 |
|
16 | 3862 |
$post_updated = wp_update_post( |
9 | 3863 |
array( |
3864 |
'ID' => $post_id, |
|
3865 |
'post_status' => $post_status, |
|
3866 |
) |
|
3867 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3868 |
|
16 | 3869 |
if ( ! $post_updated ) { |
3870 |
return false; |
|
3871 |
} |
|
3872 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3873 |
wp_untrash_post_comments( $post_id ); |
0 | 3874 |
|
5 | 3875 |
/** |
16 | 3876 |
* Fires after a post is restored from the Trash. |
5 | 3877 |
* |
3878 |
* @since 2.9.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3879 |
* @since 5.6.0 Added the `$previous_status` parameter. |
18 | 3880 |
* |
3881 |
* @param int $post_id Post ID. |
|
3882 |
* @param string $previous_status The status of the post at the point where it was trashed. |
|
5 | 3883 |
*/ |
18 | 3884 |
do_action( 'untrashed_post', $post_id, $previous_status ); |
0 | 3885 |
|
3886 |
return $post; |
|
3887 |
} |
|
3888 |
||
3889 |
/** |
|
16 | 3890 |
* Moves comments for a post to the Trash. |
0 | 3891 |
* |
3892 |
* @since 2.9.0 |
|
5 | 3893 |
* |
3894 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
3895 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3896 |
* @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3897 |
* @return mixed|void False on failure. |
0 | 3898 |
*/ |
5 | 3899 |
function wp_trash_post_comments( $post = null ) { |
0 | 3900 |
global $wpdb; |
3901 |
||
9 | 3902 |
$post = get_post( $post ); |
18 | 3903 |
|
3904 |
if ( ! $post ) { |
|
0 | 3905 |
return; |
9 | 3906 |
} |
0 | 3907 |
|
3908 |
$post_id = $post->ID; |
|
3909 |
||
5 | 3910 |
/** |
16 | 3911 |
* Fires before comments are sent to the Trash. |
5 | 3912 |
* |
3913 |
* @since 2.9.0 |
|
3914 |
* |
|
3915 |
* @param int $post_id Post ID. |
|
3916 |
*/ |
|
3917 |
do_action( 'trash_post_comments', $post_id ); |
|
0 | 3918 |
|
9 | 3919 |
$comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) ); |
18 | 3920 |
|
3921 |
if ( ! $comments ) { |
|
0 | 3922 |
return; |
9 | 3923 |
} |
0 | 3924 |
|
5 | 3925 |
// Cache current status for each comment. |
0 | 3926 |
$statuses = array(); |
9 | 3927 |
foreach ( $comments as $comment ) { |
3928 |
$statuses[ $comment->comment_ID ] = $comment->comment_approved; |
|
3929 |
} |
|
3930 |
add_post_meta( $post_id, '_wp_trash_meta_comments_status', $statuses ); |
|
0 | 3931 |
|
5 | 3932 |
// Set status for all comments to post-trashed. |
9 | 3933 |
$result = $wpdb->update( $wpdb->comments, array( 'comment_approved' => 'post-trashed' ), array( 'comment_post_ID' => $post_id ) ); |
3934 |
||
3935 |
clean_comment_cache( array_keys( $statuses ) ); |
|
0 | 3936 |
|
5 | 3937 |
/** |
16 | 3938 |
* Fires after comments are sent to the Trash. |
5 | 3939 |
* |
3940 |
* @since 2.9.0 |
|
3941 |
* |
|
3942 |
* @param int $post_id Post ID. |
|
3943 |
* @param array $statuses Array of comment statuses. |
|
3944 |
*/ |
|
3945 |
do_action( 'trashed_post_comments', $post_id, $statuses ); |
|
0 | 3946 |
|
3947 |
return $result; |
|
3948 |
} |
|
3949 |
||
3950 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3951 |
* Restores comments for a post from the Trash. |
0 | 3952 |
* |
3953 |
* @since 2.9.0 |
|
5 | 3954 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3955 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3956 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3957 |
* @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3958 |
* @return true|void |
0 | 3959 |
*/ |
5 | 3960 |
function wp_untrash_post_comments( $post = null ) { |
0 | 3961 |
global $wpdb; |
3962 |
||
9 | 3963 |
$post = get_post( $post ); |
18 | 3964 |
|
3965 |
if ( ! $post ) { |
|
0 | 3966 |
return; |
9 | 3967 |
} |
0 | 3968 |
|
3969 |
$post_id = $post->ID; |
|
3970 |
||
9 | 3971 |
$statuses = get_post_meta( $post_id, '_wp_trash_meta_comments_status', true ); |
3972 |
||
18 | 3973 |
if ( ! $statuses ) { |
0 | 3974 |
return true; |
9 | 3975 |
} |
0 | 3976 |
|
5 | 3977 |
/** |
16 | 3978 |
* Fires before comments are restored for a post from the Trash. |
5 | 3979 |
* |
3980 |
* @since 2.9.0 |
|
3981 |
* |
|
3982 |
* @param int $post_id Post ID. |
|
3983 |
*/ |
|
3984 |
do_action( 'untrash_post_comments', $post_id ); |
|
3985 |
||
3986 |
// Restore each comment to its original status. |
|
0 | 3987 |
$group_by_status = array(); |
9 | 3988 |
foreach ( $statuses as $comment_id => $comment_status ) { |
3989 |
$group_by_status[ $comment_status ][] = $comment_id; |
|
3990 |
} |
|
0 | 3991 |
|
3992 |
foreach ( $group_by_status as $status => $comments ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3993 |
// Confidence check. This shouldn't happen. |
16 | 3994 |
if ( 'post-trashed' === $status ) { |
0 | 3995 |
$status = '0'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3996 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3997 |
$comments_in = implode( ', ', array_map( 'intval', $comments ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3998 |
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID IN ($comments_in)", $status ) ); |
0 | 3999 |
} |
4000 |
||
9 | 4001 |
clean_comment_cache( array_keys( $statuses ) ); |
4002 |
||
4003 |
delete_post_meta( $post_id, '_wp_trash_meta_comments_status' ); |
|
0 | 4004 |
|
5 | 4005 |
/** |
16 | 4006 |
* Fires after comments are restored for a post from the Trash. |
5 | 4007 |
* |
4008 |
* @since 2.9.0 |
|
4009 |
* |
|
4010 |
* @param int $post_id Post ID. |
|
4011 |
*/ |
|
4012 |
do_action( 'untrashed_post_comments', $post_id ); |
|
0 | 4013 |
} |
4014 |
||
4015 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4016 |
* Retrieves the list of categories for a post. |
0 | 4017 |
* |
4018 |
* Compatibility layer for themes and plugins. Also an easy layer of abstraction |
|
4019 |
* away from the complexity of the taxonomy layer. |
|
4020 |
* |
|
4021 |
* @since 2.1.0 |
|
4022 |
* |
|
5 | 4023 |
* @see wp_get_object_terms() |
4024 |
* |
|
4025 |
* @param int $post_id Optional. The Post ID. Does not default to the ID of the |
|
4026 |
* global $post. Default 0. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4027 |
* @param array $args Optional. Category query parameters. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4028 |
* See WP_Term_Query::__construct() for supported arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4029 |
* @return array|WP_Error List of categories. If the `$fields` argument passed via `$args` is 'all' or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4030 |
* 'all_with_object_id', an array of WP_Term objects will be returned. If `$fields` |
16 | 4031 |
* is 'ids', an array of category IDs. If `$fields` is 'names', an array of category names. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4032 |
* WP_Error object if 'category' taxonomy doesn't exist. |
0 | 4033 |
*/ |
4034 |
function wp_get_post_categories( $post_id = 0, $args = array() ) { |
|
4035 |
$post_id = (int) $post_id; |
|
4036 |
||
9 | 4037 |
$defaults = array( 'fields' => 'ids' ); |
4038 |
$args = wp_parse_args( $args, $defaults ); |
|
4039 |
||
4040 |
$cats = wp_get_object_terms( $post_id, 'category', $args ); |
|
0 | 4041 |
return $cats; |
4042 |
} |
|
4043 |
||
4044 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4045 |
* Retrieves the tags for a post. |
0 | 4046 |
* |
4047 |
* There is only one default for this function, called 'fields' and by default |
|
4048 |
* is set to 'all'. There are other defaults that can be overridden in |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4049 |
* wp_get_object_terms(). |
0 | 4050 |
* |
4051 |
* @since 2.3.0 |
|
4052 |
* |
|
5 | 4053 |
* @param int $post_id Optional. The Post ID. Does not default to the ID of the |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4054 |
* global $post. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4055 |
* @param array $args Optional. Tag query parameters. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4056 |
* See WP_Term_Query::__construct() for supported arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4057 |
* @return array|WP_Error Array of WP_Term objects on success or empty array if no tags were found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4058 |
* WP_Error object if 'post_tag' taxonomy doesn't exist. |
0 | 4059 |
*/ |
4060 |
function wp_get_post_tags( $post_id = 0, $args = array() ) { |
|
9 | 4061 |
return wp_get_post_terms( $post_id, 'post_tag', $args ); |
0 | 4062 |
} |
4063 |
||
4064 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4065 |
* Retrieves the terms for a post. |
0 | 4066 |
* |
4067 |
* @since 2.8.0 |
|
4068 |
* |
|
18 | 4069 |
* @param int $post_id Optional. The Post ID. Does not default to the ID of the |
4070 |
* global $post. Default 0. |
|
4071 |
* @param string|string[] $taxonomy Optional. The taxonomy slug or array of slugs for which |
|
4072 |
* to retrieve terms. Default 'post_tag'. |
|
4073 |
* @param array $args { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4074 |
* Optional. Term query parameters. See WP_Term_Query::__construct() for supported arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4075 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4076 |
* @type string $fields Term fields to retrieve. Default 'all'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4077 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4078 |
* @return array|WP_Error Array of WP_Term objects on success or empty array if no terms were found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4079 |
* WP_Error object if `$taxonomy` doesn't exist. |
0 | 4080 |
*/ |
4081 |
function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) { |
|
4082 |
$post_id = (int) $post_id; |
|
4083 |
||
9 | 4084 |
$defaults = array( 'fields' => 'all' ); |
4085 |
$args = wp_parse_args( $args, $defaults ); |
|
4086 |
||
4087 |
$tags = wp_get_object_terms( $post_id, $taxonomy, $args ); |
|
0 | 4088 |
|
4089 |
return $tags; |
|
4090 |
} |
|
4091 |
||
4092 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4093 |
* Retrieves a number of recent posts. |
0 | 4094 |
* |
4095 |
* @since 1.0.0 |
|
5 | 4096 |
* |
4097 |
* @see get_posts() |
|
4098 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4099 |
* @param array $args Optional. Arguments to retrieve posts. Default empty array. |
16 | 4100 |
* @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which |
4101 |
* correspond to a WP_Post object or an associative array, respectively. |
|
4102 |
* Default ARRAY_A. |
|
4103 |
* @return array|false Array of recent posts, where the type of each element is determined |
|
4104 |
* by the `$output` parameter. Empty array on failure. |
|
0 | 4105 |
*/ |
4106 |
function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { |
|
4107 |
||
4108 |
if ( is_numeric( $args ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4109 |
_deprecated_argument( __FUNCTION__, '3.1.0', __( 'Passing an integer number of posts is deprecated. Pass an array of arguments instead.' ) ); |
0 | 4110 |
$args = array( 'numberposts' => absint( $args ) ); |
4111 |
} |
|
4112 |
||
5 | 4113 |
// Set default arguments. |
0 | 4114 |
$defaults = array( |
9 | 4115 |
'numberposts' => 10, |
4116 |
'offset' => 0, |
|
4117 |
'category' => 0, |
|
4118 |
'orderby' => 'post_date', |
|
4119 |
'order' => 'DESC', |
|
4120 |
'include' => '', |
|
4121 |
'exclude' => '', |
|
4122 |
'meta_key' => '', |
|
4123 |
'meta_value' => '', |
|
4124 |
'post_type' => 'post', |
|
4125 |
'post_status' => 'draft, publish, future, pending, private', |
|
4126 |
'suppress_filters' => true, |
|
0 | 4127 |
); |
4128 |
||
16 | 4129 |
$parsed_args = wp_parse_args( $args, $defaults ); |
4130 |
||
4131 |
$results = get_posts( $parsed_args ); |
|
0 | 4132 |
|
5 | 4133 |
// Backward compatibility. Prior to 3.1 expected posts to be returned in array. |
18 | 4134 |
if ( ARRAY_A === $output ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4135 |
foreach ( $results as $key => $result ) { |
9 | 4136 |
$results[ $key ] = get_object_vars( $result ); |
0 | 4137 |
} |
4138 |
return $results ? $results : array(); |
|
4139 |
} |
|
4140 |
||
4141 |
return $results ? $results : false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4142 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4143 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4144 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4145 |
* Inserts or update a post. |
0 | 4146 |
* |
4147 |
* If the $postarr parameter has 'ID' set to a value, then post will be updated. |
|
4148 |
* |
|
4149 |
* You can set the post date manually, by setting the values for 'post_date' |
|
4150 |
* and 'post_date_gmt' keys. You can close the comments or open the comments by |
|
4151 |
* setting the value for 'comment_status' key. |
|
4152 |
* |
|
4153 |
* @since 1.0.0 |
|
18 | 4154 |
* @since 2.6.0 Added the `$wp_error` parameter to allow a WP_Error to be returned on failure. |
5 | 4155 |
* @since 4.2.0 Support was added for encoding emoji in the post title, content, and excerpt. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4156 |
* @since 4.4.0 A 'meta_input' array can now be passed to `$postarr` to add post meta data. |
18 | 4157 |
* @since 5.6.0 Added the `$fire_after_hooks` parameter. |
5 | 4158 |
* |
4159 |
* @see sanitize_post() |
|
4160 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 4161 |
* |
4162 |
* @param array $postarr { |
|
4163 |
* An array of elements that make up a post to update or insert. |
|
4164 |
* |
|
5 | 4165 |
* @type int $ID The post ID. If equal to something other than 0, |
4166 |
* the post with that ID will be updated. Default 0. |
|
4167 |
* @type int $post_author The ID of the user who added the post. Default is |
|
4168 |
* the current user ID. |
|
4169 |
* @type string $post_date The date of the post. Default is the current time. |
|
4170 |
* @type string $post_date_gmt The date of the post in the GMT timezone. Default is |
|
4171 |
* the value of `$post_date`. |
|
19 | 4172 |
* @type string $post_content The post content. Default empty. |
5 | 4173 |
* @type string $post_content_filtered The filtered post content. Default empty. |
4174 |
* @type string $post_title The post title. Default empty. |
|
4175 |
* @type string $post_excerpt The post excerpt. Default empty. |
|
4176 |
* @type string $post_status The post status. Default 'draft'. |
|
4177 |
* @type string $post_type The post type. Default 'post'. |
|
4178 |
* @type string $comment_status Whether the post can accept comments. Accepts 'open' or 'closed'. |
|
4179 |
* Default is the value of 'default_comment_status' option. |
|
4180 |
* @type string $ping_status Whether the post can accept pings. Accepts 'open' or 'closed'. |
|
4181 |
* Default is the value of 'default_ping_status' option. |
|
4182 |
* @type string $post_password The password to access the post. Default empty. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4183 |
* @type string $post_name The post name. Default is the sanitized post title |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4184 |
* when creating a new post. |
5 | 4185 |
* @type string $to_ping Space or carriage return-separated list of URLs to ping. |
4186 |
* Default empty. |
|
4187 |
* @type string $pinged Space or carriage return-separated list of URLs that have |
|
4188 |
* been pinged. Default empty. |
|
4189 |
* @type int $post_parent Set this for the post it belongs to, if any. Default 0. |
|
4190 |
* @type int $menu_order The order the post should be displayed in. Default 0. |
|
4191 |
* @type string $post_mime_type The mime type of the post. Default empty. |
|
4192 |
* @type string $guid Global Unique ID for referencing the post. Default empty. |
|
18 | 4193 |
* @type int $import_id The post ID to be used when inserting a new post. |
4194 |
* If specified, must not match any existing post ID. Default 0. |
|
4195 |
* @type int[] $post_category Array of category IDs. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4196 |
* Defaults to value of the 'default_category' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4197 |
* @type array $tags_input Array of tag names, slugs, or IDs. Default empty. |
19 | 4198 |
* @type array $tax_input An array of taxonomy terms keyed by their taxonomy name. |
4199 |
* If the taxonomy is hierarchical, the term list needs to be |
|
4200 |
* either an array of term IDs or a comma-separated string of IDs. |
|
4201 |
* If the taxonomy is non-hierarchical, the term list can be an array |
|
4202 |
* that contains term names or slugs, or a comma-separated string |
|
4203 |
* of names or slugs. This is because, in hierarchical taxonomy, |
|
4204 |
* child terms can have the same names with different parent terms, |
|
4205 |
* so the only way to connect them is using ID. Default empty. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4206 |
* @type array $meta_input Array of post meta values keyed by their post meta key. Default empty. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4207 |
* @type string $page_template Page template to use. |
0 | 4208 |
* } |
18 | 4209 |
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. |
4210 |
* @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true. |
|
0 | 4211 |
* @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. |
4212 |
*/ |
|
18 | 4213 |
function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) { |
0 | 4214 |
global $wpdb; |
4215 |
||
16 | 4216 |
// Capture original pre-sanitized array for passing into filters. |
4217 |
$unsanitized_postarr = $postarr; |
|
4218 |
||
0 | 4219 |
$user_id = get_current_user_id(); |
4220 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4221 |
$defaults = array( |
9 | 4222 |
'post_author' => $user_id, |
4223 |
'post_content' => '', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4224 |
'post_content_filtered' => '', |
9 | 4225 |
'post_title' => '', |
4226 |
'post_excerpt' => '', |
|
4227 |
'post_status' => 'draft', |
|
4228 |
'post_type' => 'post', |
|
4229 |
'comment_status' => '', |
|
4230 |
'ping_status' => '', |
|
4231 |
'post_password' => '', |
|
4232 |
'to_ping' => '', |
|
4233 |
'pinged' => '', |
|
4234 |
'post_parent' => 0, |
|
4235 |
'menu_order' => 0, |
|
4236 |
'guid' => '', |
|
4237 |
'import_id' => 0, |
|
4238 |
'context' => '', |
|
18 | 4239 |
'post_date' => '', |
4240 |
'post_date_gmt' => '', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4241 |
); |
0 | 4242 |
|
9 | 4243 |
$postarr = wp_parse_args( $postarr, $defaults ); |
4244 |
||
4245 |
unset( $postarr['filter'] ); |
|
4246 |
||
4247 |
$postarr = sanitize_post( $postarr, 'db' ); |
|
0 | 4248 |
|
4249 |
// Are we updating or creating? |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4250 |
$post_id = 0; |
9 | 4251 |
$update = false; |
4252 |
$guid = $postarr['guid']; |
|
5 | 4253 |
|
4254 |
if ( ! empty( $postarr['ID'] ) ) { |
|
0 | 4255 |
$update = true; |
4256 |
||
5 | 4257 |
// Get the post ID and GUID. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4258 |
$post_id = $postarr['ID']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4259 |
$post_before = get_post( $post_id ); |
16 | 4260 |
|
0 | 4261 |
if ( is_null( $post_before ) ) { |
5 | 4262 |
if ( $wp_error ) { |
0 | 4263 |
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); |
5 | 4264 |
} |
0 | 4265 |
return 0; |
4266 |
} |
|
4267 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4268 |
$guid = get_post_field( 'guid', $post_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4269 |
$previous_status = get_post_field( 'post_status', $post_id ); |
0 | 4270 |
} else { |
4271 |
$previous_status = 'new'; |
|
18 | 4272 |
$post_before = null; |
0 | 4273 |
} |
4274 |
||
5 | 4275 |
$post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type']; |
4276 |
||
9 | 4277 |
$post_title = $postarr['post_title']; |
5 | 4278 |
$post_content = $postarr['post_content']; |
4279 |
$post_excerpt = $postarr['post_excerpt']; |
|
16 | 4280 |
|
5 | 4281 |
if ( isset( $postarr['post_name'] ) ) { |
4282 |
$post_name = $postarr['post_name']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4283 |
} elseif ( $update ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4284 |
// For an update, don't modify the post_name if it wasn't supplied as an argument. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4285 |
$post_name = $post_before->post_name; |
0 | 4286 |
} |
4287 |
||
5 | 4288 |
$maybe_empty = 'attachment' !== $post_type |
4289 |
&& ! $post_content && ! $post_title && ! $post_excerpt |
|
4290 |
&& post_type_supports( $post_type, 'editor' ) |
|
4291 |
&& post_type_supports( $post_type, 'title' ) |
|
4292 |
&& post_type_supports( $post_type, 'excerpt' ); |
|
4293 |
||
4294 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4295 |
* Filters whether the post should be considered "empty". |
5 | 4296 |
* |
4297 |
* The post is considered "empty" if both: |
|
4298 |
* 1. The post type supports the title, editor, and excerpt fields |
|
4299 |
* 2. The title, editor, and excerpt fields are all empty |
|
4300 |
* |
|
16 | 4301 |
* Returning a truthy value from the filter will effectively short-circuit |
4302 |
* the new post being inserted and return 0. If $wp_error is true, a WP_Error |
|
5 | 4303 |
* will be returned instead. |
4304 |
* |
|
4305 |
* @since 3.3.0 |
|
4306 |
* |
|
4307 |
* @param bool $maybe_empty Whether the post should be considered "empty". |
|
4308 |
* @param array $postarr Array of post data. |
|
4309 |
*/ |
|
4310 |
if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) { |
|
4311 |
if ( $wp_error ) { |
|
4312 |
return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) ); |
|
4313 |
} else { |
|
4314 |
return 0; |
|
4315 |
} |
|
4316 |
} |
|
4317 |
||
4318 |
$post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status']; |
|
16 | 4319 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4320 |
if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private', 'trash', 'auto-draft' ), true ) ) { |
5 | 4321 |
$post_status = 'inherit'; |
4322 |
} |
|
4323 |
||
4324 |
if ( ! empty( $postarr['post_category'] ) ) { |
|
4325 |
// Filter out empty terms. |
|
4326 |
$post_category = array_filter( $postarr['post_category'] ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4327 |
} elseif ( $update && ! isset( $postarr['post_category'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4328 |
$post_category = $post_before->post_category; |
5 | 4329 |
} |
0 | 4330 |
|
4331 |
// Make sure we set a valid category. |
|
16 | 4332 |
if ( empty( $post_category ) || 0 === count( $post_category ) || ! is_array( $post_category ) ) { |
0 | 4333 |
// 'post' requires at least one category. |
16 | 4334 |
if ( 'post' === $post_type && 'auto-draft' !== $post_status ) { |
9 | 4335 |
$post_category = array( get_option( 'default_category' ) ); |
5 | 4336 |
} else { |
0 | 4337 |
$post_category = array(); |
5 | 4338 |
} |
0 | 4339 |
} |
4340 |
||
9 | 4341 |
/* |
4342 |
* Don't allow contributors to set the post slug for pending review posts. |
|
4343 |
* |
|
4344 |
* For new posts check the primitive capability, for updates check the meta capability. |
|
4345 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4346 |
if ( 'pending' === $post_status ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4347 |
$post_type_object = get_post_type_object( $post_type ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4348 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4349 |
if ( ! $update && $post_type_object && ! current_user_can( $post_type_object->cap->publish_posts ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4350 |
$post_name = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4351 |
} elseif ( $update && ! current_user_can( 'publish_post', $post_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4352 |
$post_name = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4353 |
} |
5 | 4354 |
} |
4355 |
||
4356 |
/* |
|
4357 |
* Create a valid post name. Drafts and pending posts are allowed to have |
|
4358 |
* an empty post name. |
|
4359 |
*/ |
|
9 | 4360 |
if ( empty( $post_name ) ) { |
16 | 4361 |
if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ), true ) ) { |
9 | 4362 |
$post_name = sanitize_title( $post_title ); |
5 | 4363 |
} else { |
0 | 4364 |
$post_name = ''; |
5 | 4365 |
} |
0 | 4366 |
} else { |
4367 |
// On updates, we need to check to see if it's using the old, fixed sanitization context. |
|
4368 |
$check_name = sanitize_title( $post_name, '', 'old-save' ); |
|
16 | 4369 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4370 |
if ( $update |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4371 |
&& strtolower( urlencode( $post_name ) ) === $check_name |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4372 |
&& get_post_field( 'post_name', $post_id ) === $check_name |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4373 |
) { |
0 | 4374 |
$post_name = $check_name; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4375 |
} else { // New post, or slug has changed. |
9 | 4376 |
$post_name = sanitize_title( $post_name ); |
5 | 4377 |
} |
4378 |
} |
|
4379 |
||
4380 |
/* |
|
18 | 4381 |
* Resolve the post date from any provided post date or post date GMT strings; |
4382 |
* if none are provided, the date will be set to now. |
|
5 | 4383 |
*/ |
18 | 4384 |
$post_date = wp_resolve_post_date( $postarr['post_date'], $postarr['post_date_gmt'] ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4385 |
|
18 | 4386 |
if ( ! $post_date ) { |
5 | 4387 |
if ( $wp_error ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4388 |
return new WP_Error( 'invalid_date', __( 'Invalid date.' ) ); |
5 | 4389 |
} else { |
4390 |
return 0; |
|
0 | 4391 |
} |
5 | 4392 |
} |
4393 |
||
16 | 4394 |
if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) { |
4395 |
if ( ! in_array( $post_status, get_post_stati( array( 'date_floating' => true ) ), true ) ) { |
|
5 | 4396 |
$post_date_gmt = get_gmt_from_date( $post_date ); |
4397 |
} else { |
|
0 | 4398 |
$post_date_gmt = '0000-00-00 00:00:00'; |
5 | 4399 |
} |
4400 |
} else { |
|
4401 |
$post_date_gmt = $postarr['post_date_gmt']; |
|
0 | 4402 |
} |
4403 |
||
16 | 4404 |
if ( $update || '0000-00-00 00:00:00' === $post_date ) { |
0 | 4405 |
$post_modified = current_time( 'mysql' ); |
4406 |
$post_modified_gmt = current_time( 'mysql', 1 ); |
|
4407 |
} else { |
|
4408 |
$post_modified = $post_date; |
|
4409 |
$post_modified_gmt = $post_date_gmt; |
|
4410 |
} |
|
4411 |
||
5 | 4412 |
if ( 'attachment' !== $post_type ) { |
16 | 4413 |
$now = gmdate( 'Y-m-d H:i:s' ); |
4414 |
||
4415 |
if ( 'publish' === $post_status ) { |
|
4416 |
if ( strtotime( $post_date_gmt ) - strtotime( $now ) >= MINUTE_IN_SECONDS ) { |
|
5 | 4417 |
$post_status = 'future'; |
4418 |
} |
|
16 | 4419 |
} elseif ( 'future' === $post_status ) { |
4420 |
if ( strtotime( $post_date_gmt ) - strtotime( $now ) < MINUTE_IN_SECONDS ) { |
|
5 | 4421 |
$post_status = 'publish'; |
4422 |
} |
|
4423 |
} |
|
4424 |
} |
|
4425 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4426 |
// Comment status. |
5 | 4427 |
if ( empty( $postarr['comment_status'] ) ) { |
4428 |
if ( $update ) { |
|
4429 |
$comment_status = 'closed'; |
|
4430 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4431 |
$comment_status = get_default_comment_status( $post_type ); |
5 | 4432 |
} |
4433 |
} else { |
|
4434 |
$comment_status = $postarr['comment_status']; |
|
0 | 4435 |
} |
4436 |
||
5 | 4437 |
// These variables are needed by compact() later. |
4438 |
$post_content_filtered = $postarr['post_content_filtered']; |
|
9 | 4439 |
$post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id; |
4440 |
$ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status']; |
|
4441 |
$to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : ''; |
|
4442 |
$pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : ''; |
|
4443 |
$import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0; |
|
5 | 4444 |
|
4445 |
/* |
|
4446 |
* The 'wp_insert_post_parent' filter expects all variables to be present. |
|
4447 |
* Previously, these variables would have already been extracted |
|
4448 |
*/ |
|
4449 |
if ( isset( $postarr['menu_order'] ) ) { |
|
4450 |
$menu_order = (int) $postarr['menu_order']; |
|
4451 |
} else { |
|
4452 |
$menu_order = 0; |
|
4453 |
} |
|
4454 |
||
4455 |
$post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : ''; |
|
16 | 4456 |
if ( 'private' === $post_status ) { |
5 | 4457 |
$post_password = ''; |
4458 |
} |
|
4459 |
||
4460 |
if ( isset( $postarr['post_parent'] ) ) { |
|
4461 |
$post_parent = (int) $postarr['post_parent']; |
|
4462 |
} else { |
|
4463 |
$post_parent = 0; |
|
0 | 4464 |
} |
5 | 4465 |
|
9 | 4466 |
$new_postarr = array_merge( |
4467 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4468 |
'ID' => $post_id, |
9 | 4469 |
), |
4470 |
compact( array_diff( array_keys( $defaults ), array( 'context', 'filter' ) ) ) |
|
4471 |
); |
|
4472 |
||
5 | 4473 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4474 |
* Filters the post parent -- used to check for and prevent hierarchy loops. |
5 | 4475 |
* |
4476 |
* @since 3.1.0 |
|
4477 |
* |
|
4478 |
* @param int $post_parent Post parent ID. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4479 |
* @param int $post_id Post ID. |
5 | 4480 |
* @param array $new_postarr Array of parsed post data. |
4481 |
* @param array $postarr Array of sanitized, but otherwise unmodified post data. |
|
4482 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4483 |
$post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_id, $new_postarr, $postarr ); |
0 | 4484 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4485 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4486 |
* If the post is being untrashed and it has a desired slug stored in post meta, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4487 |
* reassign it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4488 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4489 |
if ( 'trash' === $previous_status && 'trash' !== $post_status ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4490 |
$desired_post_slug = get_post_meta( $post_id, '_wp_desired_post_slug', true ); |
16 | 4491 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4492 |
if ( $desired_post_slug ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4493 |
delete_post_meta( $post_id, '_wp_desired_post_slug' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4494 |
$post_name = $desired_post_slug; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4495 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4496 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4497 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4498 |
// If a trashed post has the desired slug, change it and let this post have it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4499 |
if ( 'trash' !== $post_status && $post_name ) { |
16 | 4500 |
/** |
4501 |
* Filters whether or not to add a `__trashed` suffix to trashed posts that match the name of the updated post. |
|
4502 |
* |
|
4503 |
* @since 5.4.0 |
|
4504 |
* |
|
4505 |
* @param bool $add_trashed_suffix Whether to attempt to add the suffix. |
|
4506 |
* @param string $post_name The name of the post being updated. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4507 |
* @param int $post_id Post ID. |
16 | 4508 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4509 |
$add_trashed_suffix = apply_filters( 'add_trashed_suffix_to_trashed_posts', true, $post_name, $post_id ); |
16 | 4510 |
|
4511 |
if ( $add_trashed_suffix ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4512 |
wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_id ); |
16 | 4513 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4514 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4515 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4516 |
// When trashing an existing post, change its slug to allow non-trashed posts to use it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4517 |
if ( 'trash' === $post_status && 'trash' !== $previous_status && 'new' !== $previous_status ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4518 |
$post_name = wp_add_trashed_suffix_to_post_name_for_post( $post_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4519 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4520 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4521 |
$post_name = wp_unique_post_slug( $post_name, $post_id, $post_status, $post_type, $post_parent ); |
5 | 4522 |
|
4523 |
// Don't unslash. |
|
4524 |
$post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : ''; |
|
4525 |
||
4526 |
// Expected_slashed (everything!). |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4527 |
$data = compact( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4528 |
'post_author', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4529 |
'post_date', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4530 |
'post_date_gmt', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4531 |
'post_content', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4532 |
'post_content_filtered', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4533 |
'post_title', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4534 |
'post_excerpt', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4535 |
'post_status', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4536 |
'post_type', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4537 |
'comment_status', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4538 |
'ping_status', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4539 |
'post_password', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4540 |
'post_name', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4541 |
'to_ping', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4542 |
'pinged', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4543 |
'post_modified', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4544 |
'post_modified_gmt', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4545 |
'post_parent', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4546 |
'menu_order', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4547 |
'post_mime_type', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4548 |
'guid' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4549 |
); |
5 | 4550 |
|
4551 |
$emoji_fields = array( 'post_title', 'post_content', 'post_excerpt' ); |
|
4552 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4553 |
foreach ( $emoji_fields as $emoji_field ) { |
5 | 4554 |
if ( isset( $data[ $emoji_field ] ) ) { |
4555 |
$charset = $wpdb->get_col_charset( $wpdb->posts, $emoji_field ); |
|
16 | 4556 |
|
5 | 4557 |
if ( 'utf8' === $charset ) { |
4558 |
$data[ $emoji_field ] = wp_encode_emoji( $data[ $emoji_field ] ); |
|
4559 |
} |
|
4560 |
} |
|
4561 |
} |
|
4562 |
||
4563 |
if ( 'attachment' === $post_type ) { |
|
4564 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4565 |
* Filters attachment post data before it is updated in or added to the database. |
5 | 4566 |
* |
4567 |
* @since 3.9.0 |
|
19 | 4568 |
* @since 5.4.1 The `$unsanitized_postarr` parameter was added. |
4569 |
* @since 6.0.0 The `$update` parameter was added. |
|
5 | 4570 |
* |
16 | 4571 |
* @param array $data An array of slashed, sanitized, and processed attachment post data. |
4572 |
* @param array $postarr An array of slashed and sanitized attachment post data, but not processed. |
|
4573 |
* @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed attachment post data |
|
4574 |
* as originally passed to wp_insert_post(). |
|
19 | 4575 |
* @param bool $update Whether this is an existing attachment post being updated. |
5 | 4576 |
*/ |
19 | 4577 |
$data = apply_filters( 'wp_insert_attachment_data', $data, $postarr, $unsanitized_postarr, $update ); |
5 | 4578 |
} else { |
4579 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4580 |
* Filters slashed post data just before it is inserted into the database. |
5 | 4581 |
* |
4582 |
* @since 2.7.0 |
|
19 | 4583 |
* @since 5.4.1 The `$unsanitized_postarr` parameter was added. |
4584 |
* @since 6.0.0 The `$update` parameter was added. |
|
5 | 4585 |
* |
16 | 4586 |
* @param array $data An array of slashed, sanitized, and processed post data. |
4587 |
* @param array $postarr An array of sanitized (and slashed) but otherwise unmodified post data. |
|
4588 |
* @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as |
|
4589 |
* originally passed to wp_insert_post(). |
|
19 | 4590 |
* @param bool $update Whether this is an existing post being updated. |
5 | 4591 |
*/ |
19 | 4592 |
$data = apply_filters( 'wp_insert_post_data', $data, $postarr, $unsanitized_postarr, $update ); |
16 | 4593 |
} |
4594 |
||
9 | 4595 |
$data = wp_unslash( $data ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4596 |
$where = array( 'ID' => $post_id ); |
0 | 4597 |
|
4598 |
if ( $update ) { |
|
5 | 4599 |
/** |
4600 |
* Fires immediately before an existing post is updated in the database. |
|
4601 |
* |
|
4602 |
* @since 2.5.0 |
|
4603 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4604 |
* @param int $post_id Post ID. |
5 | 4605 |
* @param array $data Array of unslashed post data. |
4606 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4607 |
do_action( 'pre_post_update', $post_id, $data ); |
16 | 4608 |
|
0 | 4609 |
if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) { |
5 | 4610 |
if ( $wp_error ) { |
16 | 4611 |
if ( 'attachment' === $post_type ) { |
4612 |
$message = __( 'Could not update attachment in the database.' ); |
|
4613 |
} else { |
|
4614 |
$message = __( 'Could not update post in the database.' ); |
|
4615 |
} |
|
4616 |
||
4617 |
return new WP_Error( 'db_update_error', $message, $wpdb->last_error ); |
|
5 | 4618 |
} else { |
0 | 4619 |
return 0; |
5 | 4620 |
} |
0 | 4621 |
} |
4622 |
} else { |
|
5 | 4623 |
// If there is a suggested ID, use it if not already present. |
4624 |
if ( ! empty( $import_id ) ) { |
|
0 | 4625 |
$import_id = (int) $import_id; |
16 | 4626 |
|
9 | 4627 |
if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id ) ) ) { |
0 | 4628 |
$data['ID'] = $import_id; |
4629 |
} |
|
4630 |
} |
|
16 | 4631 |
|
0 | 4632 |
if ( false === $wpdb->insert( $wpdb->posts, $data ) ) { |
5 | 4633 |
if ( $wp_error ) { |
16 | 4634 |
if ( 'attachment' === $post_type ) { |
4635 |
$message = __( 'Could not insert attachment into the database.' ); |
|
4636 |
} else { |
|
4637 |
$message = __( 'Could not insert post into the database.' ); |
|
4638 |
} |
|
4639 |
||
4640 |
return new WP_Error( 'db_insert_error', $message, $wpdb->last_error ); |
|
5 | 4641 |
} else { |
0 | 4642 |
return 0; |
5 | 4643 |
} |
0 | 4644 |
} |
16 | 4645 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4646 |
$post_id = (int) $wpdb->insert_id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4647 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4648 |
// Use the newly generated $post_id. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4649 |
$where = array( 'ID' => $post_id ); |
0 | 4650 |
} |
4651 |
||
16 | 4652 |
if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ), true ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4653 |
$data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'], $post_id ), $post_id, $data['post_status'], $post_type, $post_parent ); |
16 | 4654 |
|
0 | 4655 |
$wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4656 |
clean_post_cache( $post_id ); |
0 | 4657 |
} |
4658 |
||
5 | 4659 |
if ( is_object_in_taxonomy( $post_type, 'category' ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4660 |
wp_set_post_categories( $post_id, $post_category ); |
5 | 4661 |
} |
4662 |
||
4663 |
if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $post_type, 'post_tag' ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4664 |
wp_set_post_tags( $post_id, $postarr['tags_input'] ); |
5 | 4665 |
} |
4666 |
||
16 | 4667 |
// Add default term for all associated custom taxonomies. |
4668 |
if ( 'auto-draft' !== $post_status ) { |
|
4669 |
foreach ( get_object_taxonomies( $post_type, 'object' ) as $taxonomy => $tax_object ) { |
|
4670 |
||
4671 |
if ( ! empty( $tax_object->default_term ) ) { |
|
4672 |
||
4673 |
// Filter out empty terms. |
|
18 | 4674 |
if ( isset( $postarr['tax_input'][ $taxonomy ] ) && is_array( $postarr['tax_input'][ $taxonomy ] ) ) { |
16 | 4675 |
$postarr['tax_input'][ $taxonomy ] = array_filter( $postarr['tax_input'][ $taxonomy ] ); |
4676 |
} |
|
4677 |
||
4678 |
// Passed custom taxonomy list overwrites the existing list if not empty. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4679 |
$terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'ids' ) ); |
16 | 4680 |
if ( ! empty( $terms ) && empty( $postarr['tax_input'][ $taxonomy ] ) ) { |
4681 |
$postarr['tax_input'][ $taxonomy ] = $terms; |
|
4682 |
} |
|
4683 |
||
4684 |
if ( empty( $postarr['tax_input'][ $taxonomy ] ) ) { |
|
4685 |
$default_term_id = get_option( 'default_term_' . $taxonomy ); |
|
4686 |
if ( ! empty( $default_term_id ) ) { |
|
4687 |
$postarr['tax_input'][ $taxonomy ] = array( (int) $default_term_id ); |
|
4688 |
} |
|
4689 |
} |
|
4690 |
} |
|
4691 |
} |
|
4692 |
} |
|
4693 |
||
5 | 4694 |
// New-style support for all custom taxonomies. |
4695 |
if ( ! empty( $postarr['tax_input'] ) ) { |
|
4696 |
foreach ( $postarr['tax_input'] as $taxonomy => $tags ) { |
|
9 | 4697 |
$taxonomy_obj = get_taxonomy( $taxonomy ); |
16 | 4698 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4699 |
if ( ! $taxonomy_obj ) { |
16 | 4700 |
/* translators: %s: Taxonomy name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4701 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid taxonomy: %s.' ), $taxonomy ), '4.4.0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4702 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4703 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4704 |
|
5 | 4705 |
// array = hierarchical, string = non-hierarchical. |
4706 |
if ( is_array( $tags ) ) { |
|
9 | 4707 |
$tags = array_filter( $tags ); |
5 | 4708 |
} |
16 | 4709 |
|
5 | 4710 |
if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4711 |
wp_set_post_terms( $post_id, $tags, $taxonomy ); |
5 | 4712 |
} |
0 | 4713 |
} |
4714 |
} |
|
4715 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4716 |
if ( ! empty( $postarr['meta_input'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4717 |
foreach ( $postarr['meta_input'] as $field => $value ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4718 |
update_post_meta( $post_id, $field, $value ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4719 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4720 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4721 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4722 |
$current_guid = get_post_field( 'guid', $post_id ); |
0 | 4723 |
|
5 | 4724 |
// Set GUID. |
16 | 4725 |
if ( ! $update && '' === $current_guid ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4726 |
$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_id ) ), $where ); |
5 | 4727 |
} |
4728 |
||
4729 |
if ( 'attachment' === $postarr['post_type'] ) { |
|
4730 |
if ( ! empty( $postarr['file'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4731 |
update_attached_file( $post_id, $postarr['file'] ); |
5 | 4732 |
} |
4733 |
||
4734 |
if ( ! empty( $postarr['context'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4735 |
add_post_meta( $post_id, '_wp_attachment_context', $postarr['context'], true ); |
5 | 4736 |
} |
4737 |
} |
|
0 | 4738 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4739 |
// Set or remove featured image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4740 |
if ( isset( $postarr['_thumbnail_id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4741 |
$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type; |
16 | 4742 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4743 |
if ( ! $thumbnail_support && 'attachment' === $post_type && $post_mime_type ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4744 |
if ( wp_attachment_is( 'audio', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4745 |
$thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4746 |
} elseif ( wp_attachment_is( 'video', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4747 |
$thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4748 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4749 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4750 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4751 |
if ( $thumbnail_support ) { |
18 | 4752 |
$thumbnail_id = (int) $postarr['_thumbnail_id']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4753 |
if ( -1 === $thumbnail_id ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4754 |
delete_post_thumbnail( $post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4755 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4756 |
set_post_thumbnail( $post_id, $thumbnail_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4757 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4758 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4759 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4760 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4761 |
clean_post_cache( $post_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4762 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4763 |
$post = get_post( $post_id ); |
5 | 4764 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4765 |
if ( ! empty( $postarr['page_template'] ) ) { |
5 | 4766 |
$post->page_template = $postarr['page_template']; |
9 | 4767 |
$page_templates = wp_get_theme()->get_page_templates( $post ); |
16 | 4768 |
|
4769 |
if ( 'default' !== $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) { |
|
5 | 4770 |
if ( $wp_error ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4771 |
return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) ); |
5 | 4772 |
} |
16 | 4773 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4774 |
update_post_meta( $post_id, '_wp_page_template', 'default' ); |
5 | 4775 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4776 |
update_post_meta( $post_id, '_wp_page_template', $postarr['page_template'] ); |
0 | 4777 |
} |
4778 |
} |
|
4779 |
||
5 | 4780 |
if ( 'attachment' !== $postarr['post_type'] ) { |
4781 |
wp_transition_post_status( $data['post_status'], $previous_status, $post ); |
|
4782 |
} else { |
|
4783 |
if ( $update ) { |
|
4784 |
/** |
|
4785 |
* Fires once an existing attachment has been updated. |
|
4786 |
* |
|
4787 |
* @since 2.0.0 |
|
4788 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4789 |
* @param int $post_id Attachment ID. |
5 | 4790 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4791 |
do_action( 'edit_attachment', $post_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4792 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4793 |
$post_after = get_post( $post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4794 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4795 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4796 |
* Fires once an existing attachment has been updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4797 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4798 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4799 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4800 |
* @param int $post_id Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4801 |
* @param WP_Post $post_after Post object following the update. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4802 |
* @param WP_Post $post_before Post object before the update. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4803 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4804 |
do_action( 'attachment_updated', $post_id, $post_after, $post_before ); |
5 | 4805 |
} else { |
4806 |
||
4807 |
/** |
|
4808 |
* Fires once an attachment has been added. |
|
4809 |
* |
|
4810 |
* @since 2.0.0 |
|
4811 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4812 |
* @param int $post_id Attachment ID. |
5 | 4813 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4814 |
do_action( 'add_attachment', $post_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4815 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4816 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4817 |
return $post_id; |
5 | 4818 |
} |
0 | 4819 |
|
4820 |
if ( $update ) { |
|
5 | 4821 |
/** |
4822 |
* Fires once an existing post has been updated. |
|
4823 |
* |
|
9 | 4824 |
* The dynamic portion of the hook name, `$post->post_type`, refers to |
4825 |
* the post type slug. |
|
4826 |
* |
|
19 | 4827 |
* Possible hook names include: |
4828 |
* |
|
4829 |
* - `edit_post_post` |
|
4830 |
* - `edit_post_page` |
|
4831 |
* |
|
9 | 4832 |
* @since 5.1.0 |
4833 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4834 |
* @param int $post_id Post ID. |
9 | 4835 |
* @param WP_Post $post Post object. |
4836 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4837 |
do_action( "edit_post_{$post->post_type}", $post_id, $post ); |
9 | 4838 |
|
4839 |
/** |
|
4840 |
* Fires once an existing post has been updated. |
|
4841 |
* |
|
5 | 4842 |
* @since 1.2.0 |
4843 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4844 |
* @param int $post_id Post ID. |
5 | 4845 |
* @param WP_Post $post Post object. |
4846 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4847 |
do_action( 'edit_post', $post_id, $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4848 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4849 |
$post_after = get_post( $post_id ); |
5 | 4850 |
|
4851 |
/** |
|
4852 |
* Fires once an existing post has been updated. |
|
4853 |
* |
|
4854 |
* @since 3.0.0 |
|
4855 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4856 |
* @param int $post_id Post ID. |
5 | 4857 |
* @param WP_Post $post_after Post object following the update. |
4858 |
* @param WP_Post $post_before Post object before the update. |
|
4859 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4860 |
do_action( 'post_updated', $post_id, $post_after, $post_before ); |
0 | 4861 |
} |
4862 |
||
5 | 4863 |
/** |
4864 |
* Fires once a post has been saved. |
|
4865 |
* |
|
4866 |
* The dynamic portion of the hook name, `$post->post_type`, refers to |
|
4867 |
* the post type slug. |
|
4868 |
* |
|
19 | 4869 |
* Possible hook names include: |
4870 |
* |
|
4871 |
* - `save_post_post` |
|
4872 |
* - `save_post_page` |
|
4873 |
* |
|
5 | 4874 |
* @since 3.7.0 |
4875 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4876 |
* @param int $post_id Post ID. |
5 | 4877 |
* @param WP_Post $post Post object. |
16 | 4878 |
* @param bool $update Whether this is an existing post being updated. |
5 | 4879 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4880 |
do_action( "save_post_{$post->post_type}", $post_id, $post, $update ); |
5 | 4881 |
|
4882 |
/** |
|
4883 |
* Fires once a post has been saved. |
|
4884 |
* |
|
4885 |
* @since 1.5.0 |
|
4886 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4887 |
* @param int $post_id Post ID. |
5 | 4888 |
* @param WP_Post $post Post object. |
16 | 4889 |
* @param bool $update Whether this is an existing post being updated. |
5 | 4890 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4891 |
do_action( 'save_post', $post_id, $post, $update ); |
5 | 4892 |
|
4893 |
/** |
|
4894 |
* Fires once a post has been saved. |
|
4895 |
* |
|
4896 |
* @since 2.0.0 |
|
4897 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4898 |
* @param int $post_id Post ID. |
5 | 4899 |
* @param WP_Post $post Post object. |
16 | 4900 |
* @param bool $update Whether this is an existing post being updated. |
5 | 4901 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4902 |
do_action( 'wp_insert_post', $post_id, $post, $update ); |
0 | 4903 |
|
18 | 4904 |
if ( $fire_after_hooks ) { |
4905 |
wp_after_insert_post( $post, $update, $post_before ); |
|
4906 |
} |
|
4907 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4908 |
return $post_id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4909 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4910 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4911 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4912 |
* Updates a post with new post data. |
0 | 4913 |
* |
4914 |
* The date does not have to be set for drafts. You can set the date and it will |
|
4915 |
* not be overridden. |
|
4916 |
* |
|
4917 |
* @since 1.0.0 |
|
18 | 4918 |
* @since 3.5.0 Added the `$wp_error` parameter to allow a WP_Error to be returned on failure. |
4919 |
* @since 5.6.0 Added the `$fire_after_hooks` parameter. |
|
4920 |
* |
|
4921 |
* @param array|object $postarr Optional. Post data. Arrays are expected to be escaped, |
|
4922 |
* objects are not. See wp_insert_post() for accepted arguments. |
|
4923 |
* Default array. |
|
4924 |
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. |
|
4925 |
* @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true. |
|
16 | 4926 |
* @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. |
0 | 4927 |
*/ |
18 | 4928 |
function wp_update_post( $postarr = array(), $wp_error = false, $fire_after_hooks = true ) { |
9 | 4929 |
if ( is_object( $postarr ) ) { |
5 | 4930 |
// Non-escaped post was passed. |
9 | 4931 |
$postarr = get_object_vars( $postarr ); |
4932 |
$postarr = wp_slash( $postarr ); |
|
0 | 4933 |
} |
4934 |
||
5 | 4935 |
// First, get all of the original fields. |
9 | 4936 |
$post = get_post( $postarr['ID'], ARRAY_A ); |
0 | 4937 |
|
4938 |
if ( is_null( $post ) ) { |
|
9 | 4939 |
if ( $wp_error ) { |
0 | 4940 |
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); |
9 | 4941 |
} |
0 | 4942 |
return 0; |
4943 |
} |
|
4944 |
||
4945 |
// Escape data pulled from DB. |
|
9 | 4946 |
$post = wp_slash( $post ); |
0 | 4947 |
|
4948 |
// Passed post category list overwrites existing category list if not empty. |
|
9 | 4949 |
if ( isset( $postarr['post_category'] ) && is_array( $postarr['post_category'] ) |
16 | 4950 |
&& count( $postarr['post_category'] ) > 0 |
4951 |
) { |
|
0 | 4952 |
$post_cats = $postarr['post_category']; |
9 | 4953 |
} else { |
0 | 4954 |
$post_cats = $post['post_category']; |
9 | 4955 |
} |
0 | 4956 |
|
5 | 4957 |
// Drafts shouldn't be assigned a date unless explicitly done so by the user. |
16 | 4958 |
if ( isset( $post['post_status'] ) |
4959 |
&& in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ), true ) |
|
4960 |
&& empty( $postarr['edit_date'] ) && ( '0000-00-00 00:00:00' === $post['post_date_gmt'] ) |
|
4961 |
) { |
|
0 | 4962 |
$clear_date = true; |
9 | 4963 |
} else { |
0 | 4964 |
$clear_date = false; |
9 | 4965 |
} |
0 | 4966 |
|
4967 |
// Merge old and new fields with new fields overwriting old ones. |
|
9 | 4968 |
$postarr = array_merge( $post, $postarr ); |
0 | 4969 |
$postarr['post_category'] = $post_cats; |
4970 |
if ( $clear_date ) { |
|
9 | 4971 |
$postarr['post_date'] = current_time( 'mysql' ); |
0 | 4972 |
$postarr['post_date_gmt'] = ''; |
4973 |
} |
|
4974 |
||
16 | 4975 |
if ( 'attachment' === $postarr['post_type'] ) { |
9 | 4976 |
return wp_insert_attachment( $postarr, false, 0, $wp_error ); |
4977 |
} |
|
0 | 4978 |
|
16 | 4979 |
// Discard 'tags_input' parameter if it's the same as existing post tags. |
4980 |
if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $postarr['post_type'], 'post_tag' ) ) { |
|
4981 |
$tags = get_the_terms( $postarr['ID'], 'post_tag' ); |
|
4982 |
$tag_names = array(); |
|
4983 |
||
4984 |
if ( $tags && ! is_wp_error( $tags ) ) { |
|
4985 |
$tag_names = wp_list_pluck( $tags, 'name' ); |
|
4986 |
} |
|
4987 |
||
4988 |
if ( $postarr['tags_input'] === $tag_names ) { |
|
4989 |
unset( $postarr['tags_input'] ); |
|
4990 |
} |
|
4991 |
} |
|
4992 |
||
18 | 4993 |
return wp_insert_post( $postarr, $wp_error, $fire_after_hooks ); |
0 | 4994 |
} |
4995 |
||
4996 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4997 |
* Publishes a post by transitioning the post status. |
0 | 4998 |
* |
4999 |
* @since 2.1.0 |
|
5 | 5000 |
* |
5001 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
5002 |
* |
|
5003 |
* @param int|WP_Post $post Post ID or post object. |
|
0 | 5004 |
*/ |
5005 |
function wp_publish_post( $post ) { |
|
5006 |
global $wpdb; |
|
5007 |
||
16 | 5008 |
$post = get_post( $post ); |
18 | 5009 |
|
16 | 5010 |
if ( ! $post ) { |
0 | 5011 |
return; |
9 | 5012 |
} |
5013 |
||
16 | 5014 |
if ( 'publish' === $post->post_status ) { |
0 | 5015 |
return; |
9 | 5016 |
} |
0 | 5017 |
|
18 | 5018 |
$post_before = get_post( $post->ID ); |
5019 |
||
5020 |
// Ensure at least one term is applied for taxonomies with a default term. |
|
5021 |
foreach ( get_object_taxonomies( $post->post_type, 'object' ) as $taxonomy => $tax_object ) { |
|
5022 |
// Skip taxonomy if no default term is set. |
|
5023 |
if ( |
|
5024 |
'category' !== $taxonomy && |
|
5025 |
empty( $tax_object->default_term ) |
|
5026 |
) { |
|
5027 |
continue; |
|
5028 |
} |
|
5029 |
||
5030 |
// Do not modify previously set terms. |
|
5031 |
if ( ! empty( get_the_terms( $post, $taxonomy ) ) ) { |
|
5032 |
continue; |
|
5033 |
} |
|
5034 |
||
5035 |
if ( 'category' === $taxonomy ) { |
|
5036 |
$default_term_id = (int) get_option( 'default_category', 0 ); |
|
5037 |
} else { |
|
5038 |
$default_term_id = (int) get_option( 'default_term_' . $taxonomy, 0 ); |
|
5039 |
} |
|
5040 |
||
5041 |
if ( ! $default_term_id ) { |
|
5042 |
continue; |
|
5043 |
} |
|
5044 |
wp_set_post_terms( $post->ID, array( $default_term_id ), $taxonomy ); |
|
5045 |
} |
|
5046 |
||
0 | 5047 |
$wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) ); |
5048 |
||
5049 |
clean_post_cache( $post->ID ); |
|
5050 |
||
9 | 5051 |
$old_status = $post->post_status; |
0 | 5052 |
$post->post_status = 'publish'; |
5053 |
wp_transition_post_status( 'publish', $old_status, $post ); |
|
5054 |
||
5 | 5055 |
/** This action is documented in wp-includes/post.php */ |
9 | 5056 |
do_action( "edit_post_{$post->post_type}", $post->ID, $post ); |
5057 |
||
5058 |
/** This action is documented in wp-includes/post.php */ |
|
0 | 5059 |
do_action( 'edit_post', $post->ID, $post ); |
5 | 5060 |
|
5061 |
/** This action is documented in wp-includes/post.php */ |
|
0 | 5062 |
do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
5 | 5063 |
|
5064 |
/** This action is documented in wp-includes/post.php */ |
|
0 | 5065 |
do_action( 'save_post', $post->ID, $post, true ); |
5 | 5066 |
|
5067 |
/** This action is documented in wp-includes/post.php */ |
|
0 | 5068 |
do_action( 'wp_insert_post', $post->ID, $post, true ); |
18 | 5069 |
|
5070 |
wp_after_insert_post( $post, true, $post_before ); |
|
0 | 5071 |
} |
5072 |
||
5073 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5074 |
* Publishes future post and make sure post ID has future post status. |
0 | 5075 |
* |
5076 |
* Invoked by cron 'publish_future_post' event. This safeguard prevents cron |
|
5077 |
* from publishing drafts, etc. |
|
5078 |
* |
|
5079 |
* @since 2.5.0 |
|
5080 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5081 |
* @param int|WP_Post $post Post ID or post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5082 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5083 |
function check_and_publish_future_post( $post ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5084 |
$post = get_post( $post ); |
9 | 5085 |
|
18 | 5086 |
if ( ! $post ) { |
0 | 5087 |
return; |
9 | 5088 |
} |
5089 |
||
16 | 5090 |
if ( 'future' !== $post->post_status ) { |
0 | 5091 |
return; |
9 | 5092 |
} |
0 | 5093 |
|
5094 |
$time = strtotime( $post->post_date_gmt . ' GMT' ); |
|
5095 |
||
5 | 5096 |
// Uh oh, someone jumped the gun! |
5097 |
if ( $time > time() ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5098 |
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); // Clear anything else in the system. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5099 |
wp_schedule_single_event( $time, 'publish_future_post', array( $post->ID ) ); |
0 | 5100 |
return; |
5101 |
} |
|
5102 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5103 |
// wp_publish_post() returns no meaningful value. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5104 |
wp_publish_post( $post->ID ); |
0 | 5105 |
} |
5106 |
||
5107 |
/** |
|
18 | 5108 |
* Uses wp_checkdate to return a valid Gregorian-calendar value for post_date. |
5109 |
* If post_date is not provided, this first checks post_date_gmt if provided, |
|
5110 |
* then falls back to use the current time. |
|
5111 |
* |
|
5112 |
* For back-compat purposes in wp_insert_post, an empty post_date and an invalid |
|
5113 |
* post_date_gmt will continue to return '1970-01-01 00:00:00' rather than false. |
|
5114 |
* |
|
5115 |
* @since 5.7.0 |
|
5116 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5117 |
* @param string $post_date The date in mysql format (`Y-m-d H:i:s`). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5118 |
* @param string $post_date_gmt The GMT date in mysql format (`Y-m-d H:i:s`). |
18 | 5119 |
* @return string|false A valid Gregorian-calendar date string, or false on failure. |
5120 |
*/ |
|
5121 |
function wp_resolve_post_date( $post_date = '', $post_date_gmt = '' ) { |
|
5122 |
// If the date is empty, set the date to now. |
|
5123 |
if ( empty( $post_date ) || '0000-00-00 00:00:00' === $post_date ) { |
|
5124 |
if ( empty( $post_date_gmt ) || '0000-00-00 00:00:00' === $post_date_gmt ) { |
|
5125 |
$post_date = current_time( 'mysql' ); |
|
5126 |
} else { |
|
5127 |
$post_date = get_date_from_gmt( $post_date_gmt ); |
|
5128 |
} |
|
5129 |
} |
|
5130 |
||
5131 |
// Validate the date. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5132 |
$month = (int) substr( $post_date, 5, 2 ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5133 |
$day = (int) substr( $post_date, 8, 2 ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5134 |
$year = (int) substr( $post_date, 0, 4 ); |
18 | 5135 |
|
5136 |
$valid_date = wp_checkdate( $month, $day, $year, $post_date ); |
|
5137 |
||
5138 |
if ( ! $valid_date ) { |
|
5139 |
return false; |
|
5140 |
} |
|
5141 |
return $post_date; |
|
5142 |
} |
|
5143 |
||
5144 |
/** |
|
0 | 5145 |
* Computes a unique slug for the post, when given the desired slug and some post details. |
5146 |
* |
|
5147 |
* @since 2.8.0 |
|
5148 |
* |
|
16 | 5149 |
* @global wpdb $wpdb WordPress database abstraction object. |
5150 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
|
5 | 5151 |
* |
5152 |
* @param string $slug The desired slug (post_name). |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5153 |
* @param int $post_id Post ID. |
5 | 5154 |
* @param string $post_status No uniqueness checks are made if the post is still draft or pending. |
5155 |
* @param string $post_type Post type. |
|
5156 |
* @param int $post_parent Post parent ID. |
|
5157 |
* @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) |
|
0 | 5158 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5159 |
function wp_unique_post_slug( $slug, $post_id, $post_status, $post_type, $post_parent ) { |
16 | 5160 |
if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ), true ) |
5161 |
|| ( 'inherit' === $post_status && 'revision' === $post_type ) || 'user_request' === $post_type |
|
5162 |
) { |
|
0 | 5163 |
return $slug; |
9 | 5164 |
} |
5165 |
||
5166 |
/** |
|
5167 |
* Filters the post slug before it is generated to be unique. |
|
5168 |
* |
|
5169 |
* Returning a non-null value will short-circuit the |
|
5170 |
* unique slug generation, returning the passed value instead. |
|
5171 |
* |
|
5172 |
* @since 5.1.0 |
|
5173 |
* |
|
16 | 5174 |
* @param string|null $override_slug Short-circuit return value. |
5175 |
* @param string $slug The desired slug (post_name). |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5176 |
* @param int $post_id Post ID. |
16 | 5177 |
* @param string $post_status The post status. |
5178 |
* @param string $post_type Post type. |
|
5179 |
* @param int $post_parent Post parent ID. |
|
9 | 5180 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5181 |
$override_slug = apply_filters( 'pre_wp_unique_post_slug', null, $slug, $post_id, $post_status, $post_type, $post_parent ); |
9 | 5182 |
if ( null !== $override_slug ) { |
5183 |
return $override_slug; |
|
5184 |
} |
|
0 | 5185 |
|
5186 |
global $wpdb, $wp_rewrite; |
|
5187 |
||
5188 |
$original_slug = $slug; |
|
5189 |
||
5190 |
$feeds = $wp_rewrite->feeds; |
|
9 | 5191 |
if ( ! is_array( $feeds ) ) { |
0 | 5192 |
$feeds = array(); |
9 | 5193 |
} |
0 | 5194 |
|
16 | 5195 |
if ( 'attachment' === $post_type ) { |
0 | 5196 |
// Attachment slugs must be unique across all types. |
9 | 5197 |
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5198 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_id ) ); |
0 | 5199 |
|
5 | 5200 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5201 |
* Filters whether the post slug would make a bad attachment slug. |
5 | 5202 |
* |
5203 |
* @since 3.1.0 |
|
5204 |
* |
|
5205 |
* @param bool $bad_slug Whether the slug would be bad as an attachment slug. |
|
5206 |
* @param string $slug The post slug. |
|
5207 |
*/ |
|
16 | 5208 |
$is_bad_attachment_slug = apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ); |
5209 |
||
5210 |
if ( $post_name_check |
|
5211 |
|| in_array( $slug, $feeds, true ) || 'embed' === $slug |
|
5212 |
|| $is_bad_attachment_slug |
|
5213 |
) { |
|
0 | 5214 |
$suffix = 2; |
5215 |
do { |
|
9 | 5216 |
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5217 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_id ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5218 |
++$suffix; |
0 | 5219 |
} while ( $post_name_check ); |
5220 |
$slug = $alt_post_name; |
|
5221 |
} |
|
5 | 5222 |
} elseif ( is_post_type_hierarchical( $post_type ) ) { |
16 | 5223 |
if ( 'nav_menu_item' === $post_type ) { |
0 | 5224 |
return $slug; |
9 | 5225 |
} |
5 | 5226 |
|
5227 |
/* |
|
5228 |
* Page slugs must be unique within their own trees. Pages are in a separate |
|
5229 |
* namespace than posts so page slugs are allowed to overlap post slugs. |
|
5230 |
*/ |
|
9 | 5231 |
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5232 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_id, $post_parent ) ); |
5 | 5233 |
|
5234 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5235 |
* Filters whether the post slug would make a bad hierarchical post slug. |
5 | 5236 |
* |
5237 |
* @since 3.1.0 |
|
5238 |
* |
|
5239 |
* @param bool $bad_slug Whether the post slug would be bad in a hierarchical post context. |
|
5240 |
* @param string $slug The post slug. |
|
5241 |
* @param string $post_type Post type. |
|
5242 |
* @param int $post_parent Post parent ID. |
|
5243 |
*/ |
|
16 | 5244 |
$is_bad_hierarchical_slug = apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ); |
5245 |
||
5246 |
if ( $post_name_check |
|
5247 |
|| in_array( $slug, $feeds, true ) || 'embed' === $slug |
|
5248 |
|| preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) |
|
5249 |
|| $is_bad_hierarchical_slug |
|
5250 |
) { |
|
0 | 5251 |
$suffix = 2; |
5252 |
do { |
|
9 | 5253 |
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5254 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_id, $post_parent ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5255 |
++$suffix; |
0 | 5256 |
} while ( $post_name_check ); |
5257 |
$slug = $alt_post_name; |
|
5258 |
} |
|
5259 |
} else { |
|
5260 |
// Post slugs must be unique across all posts. |
|
9 | 5261 |
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5262 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_id ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5263 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5264 |
$post = get_post( $post_id ); |
16 | 5265 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5266 |
// Prevent new post slugs that could result in URLs that conflict with date archives. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5267 |
$conflicts_with_date_archive = false; |
16 | 5268 |
if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) ) { |
18 | 5269 |
$slug_num = (int) $slug; |
16 | 5270 |
|
5271 |
if ( $slug_num ) { |
|
5272 |
$permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) ); |
|
5273 |
$postname_index = array_search( '%postname%', $permastructs, true ); |
|
5274 |
||
5275 |
/* |
|
5276 |
* Potential date clashes are as follows: |
|
5277 |
* |
|
5278 |
* - Any integer in the first permastruct position could be a year. |
|
5279 |
* - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'. |
|
5280 |
* - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'. |
|
5281 |
*/ |
|
5282 |
if ( 0 === $postname_index || |
|
5283 |
( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && 13 > $slug_num ) || |
|
5284 |
( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && 32 > $slug_num ) |
|
5285 |
) { |
|
5286 |
$conflicts_with_date_archive = true; |
|
5287 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5288 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5289 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5290 |
|
5 | 5291 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5292 |
* Filters whether the post slug would be bad as a flat slug. |
5 | 5293 |
* |
5294 |
* @since 3.1.0 |
|
5295 |
* |
|
5296 |
* @param bool $bad_slug Whether the post slug would be bad as a flat slug. |
|
5297 |
* @param string $slug The post slug. |
|
5298 |
* @param string $post_type Post type. |
|
5299 |
*/ |
|
16 | 5300 |
$is_bad_flat_slug = apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ); |
5301 |
||
5302 |
if ( $post_name_check |
|
5303 |
|| in_array( $slug, $feeds, true ) || 'embed' === $slug |
|
5304 |
|| $conflicts_with_date_archive |
|
5305 |
|| $is_bad_flat_slug |
|
5306 |
) { |
|
0 | 5307 |
$suffix = 2; |
5308 |
do { |
|
9 | 5309 |
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5310 |
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_id ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5311 |
++$suffix; |
0 | 5312 |
} while ( $post_name_check ); |
5313 |
$slug = $alt_post_name; |
|
5314 |
} |
|
5315 |
} |
|
5316 |
||
5 | 5317 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5318 |
* Filters the unique post slug. |
5 | 5319 |
* |
5320 |
* @since 3.3.0 |
|
5321 |
* |
|
5322 |
* @param string $slug The post slug. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5323 |
* @param int $post_id Post ID. |
5 | 5324 |
* @param string $post_status The post status. |
5325 |
* @param string $post_type Post type. |
|
5326 |
* @param int $post_parent Post parent ID |
|
5327 |
* @param string $original_slug The original post slug. |
|
5328 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5329 |
return apply_filters( 'wp_unique_post_slug', $slug, $post_id, $post_status, $post_type, $post_parent, $original_slug ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5330 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5331 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5332 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5333 |
* Truncates a post slug. |
0 | 5334 |
* |
5335 |
* @since 3.6.0 |
|
5336 |
* @access private |
|
5 | 5337 |
* |
5338 |
* @see utf8_uri_encode() |
|
5339 |
* |
|
5340 |
* @param string $slug The slug to truncate. |
|
5341 |
* @param int $length Optional. Max length of the slug. Default 200 (characters). |
|
0 | 5342 |
* @return string The truncated slug. |
5343 |
*/ |
|
5344 |
function _truncate_post_slug( $slug, $length = 200 ) { |
|
5345 |
if ( strlen( $slug ) > $length ) { |
|
5346 |
$decoded_slug = urldecode( $slug ); |
|
9 | 5347 |
if ( $decoded_slug === $slug ) { |
0 | 5348 |
$slug = substr( $slug, 0, $length ); |
9 | 5349 |
} else { |
19 | 5350 |
$slug = utf8_uri_encode( $decoded_slug, $length, true ); |
9 | 5351 |
} |
0 | 5352 |
} |
5353 |
||
5354 |
return rtrim( $slug, '-' ); |
|
5355 |
} |
|
5356 |
||
5357 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5358 |
* Adds tags to a post. |
5 | 5359 |
* |
5360 |
* @see wp_set_post_tags() |
|
5361 |
* |
|
0 | 5362 |
* @since 2.3.0 |
5363 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5364 |
* @param int $post_id Optional. The Post ID. Does not default to the ID of the global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5365 |
* @param string|array $tags Optional. An array of tags to set for the post, or a string of tags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5366 |
* separated by commas. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5367 |
* @return array|false|WP_Error Array of affected term IDs. WP_Error or false on failure. |
0 | 5368 |
*/ |
5 | 5369 |
function wp_add_post_tags( $post_id = 0, $tags = '' ) { |
9 | 5370 |
return wp_set_post_tags( $post_id, $tags, true ); |
0 | 5371 |
} |
5372 |
||
5373 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5374 |
* Sets the tags for a post. |
0 | 5375 |
* |
5376 |
* @since 2.3.0 |
|
5 | 5377 |
* |
5378 |
* @see wp_set_object_terms() |
|
5379 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5380 |
* @param int $post_id Optional. The Post ID. Does not default to the ID of the global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5381 |
* @param string|array $tags Optional. An array of tags to set for the post, or a string of tags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5382 |
* separated by commas. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5383 |
* @param bool $append Optional. If true, don't delete existing tags, just add on. If false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5384 |
* replace the tags with the new tags. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5385 |
* @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. |
0 | 5386 |
*/ |
5387 |
function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { |
|
9 | 5388 |
return wp_set_post_terms( $post_id, $tags, 'post_tag', $append ); |
0 | 5389 |
} |
5390 |
||
5391 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5392 |
* Sets the terms for a post. |
0 | 5393 |
* |
5394 |
* @since 2.8.0 |
|
5 | 5395 |
* |
5396 |
* @see wp_set_object_terms() |
|
5397 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5398 |
* @param int $post_id Optional. The Post ID. Does not default to the ID of the global $post. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5399 |
* @param string|array $terms Optional. An array of terms to set for the post, or a string of terms |
9 | 5400 |
* separated by commas. Hierarchical taxonomies must always pass IDs rather |
5401 |
* than names so that children with the same names but different parents |
|
5402 |
* aren't confused. Default empty. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5403 |
* @param string $taxonomy Optional. Taxonomy name. Default 'post_tag'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5404 |
* @param bool $append Optional. If true, don't delete existing terms, just add on. If false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5405 |
* replace the terms with the new terms. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5406 |
* @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. |
0 | 5407 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5408 |
function wp_set_post_terms( $post_id = 0, $terms = '', $taxonomy = 'post_tag', $append = false ) { |
0 | 5409 |
$post_id = (int) $post_id; |
5410 |
||
9 | 5411 |
if ( ! $post_id ) { |
0 | 5412 |
return false; |
9 | 5413 |
} |
5414 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5415 |
if ( empty( $terms ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5416 |
$terms = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5417 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5418 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5419 |
if ( ! is_array( $terms ) ) { |
0 | 5420 |
$comma = _x( ',', 'tag delimiter' ); |
9 | 5421 |
if ( ',' !== $comma ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5422 |
$terms = str_replace( $comma, ',', $terms ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5423 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5424 |
$terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) ); |
0 | 5425 |
} |
5426 |
||
5 | 5427 |
/* |
5428 |
* Hierarchical taxonomies must always pass IDs rather than names so that |
|
5429 |
* children with the same names but different parents aren't confused. |
|
5430 |
*/ |
|
0 | 5431 |
if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5432 |
$terms = array_unique( array_map( 'intval', $terms ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5433 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5434 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5435 |
return wp_set_object_terms( $post_id, $terms, $taxonomy, $append ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5436 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5437 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5438 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5439 |
* Sets categories for a post. |
0 | 5440 |
* |
16 | 5441 |
* If no categories are provided, the default category is used. |
0 | 5442 |
* |
5443 |
* @since 2.1.0 |
|
5444 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5445 |
* @param int $post_id Optional. The Post ID. Does not default to the ID |
5 | 5446 |
* of the global $post. Default 0. |
18 | 5447 |
* @param int[]|int $post_categories Optional. List of category IDs, or the ID of a single category. |
5 | 5448 |
* Default empty array. |
9 | 5449 |
* @param bool $append If true, don't delete existing categories, just add on. |
5450 |
* If false, replace the categories with the new categories. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5451 |
* @return array|false|WP_Error Array of term taxonomy IDs of affected categories. WP_Error or false on failure. |
0 | 5452 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5453 |
function wp_set_post_categories( $post_id = 0, $post_categories = array(), $append = false ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5454 |
$post_id = (int) $post_id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5455 |
$post_type = get_post_type( $post_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5456 |
$post_status = get_post_status( $post_id ); |
16 | 5457 |
|
5458 |
// If $post_categories isn't already an array, make it one. |
|
0 | 5459 |
$post_categories = (array) $post_categories; |
16 | 5460 |
|
0 | 5461 |
if ( empty( $post_categories ) ) { |
16 | 5462 |
/** |
5463 |
* Filters post types (in addition to 'post') that require a default category. |
|
5464 |
* |
|
5465 |
* @since 5.5.0 |
|
5466 |
* |
|
5467 |
* @param string[] $post_types An array of post type names. Default empty array. |
|
5468 |
*/ |
|
5469 |
$default_category_post_types = apply_filters( 'default_category_post_types', array() ); |
|
5470 |
||
5471 |
// Regular posts always require a default category. |
|
5472 |
$default_category_post_types = array_merge( $default_category_post_types, array( 'post' ) ); |
|
5473 |
||
5474 |
if ( in_array( $post_type, $default_category_post_types, true ) |
|
5475 |
&& is_object_in_taxonomy( $post_type, 'category' ) |
|
5476 |
&& 'auto-draft' !== $post_status |
|
5477 |
) { |
|
9 | 5478 |
$post_categories = array( get_option( 'default_category' ) ); |
5479 |
$append = false; |
|
0 | 5480 |
} else { |
5481 |
$post_categories = array(); |
|
5482 |
} |
|
16 | 5483 |
} elseif ( 1 === count( $post_categories ) && '' === reset( $post_categories ) ) { |
0 | 5484 |
return true; |
5485 |
} |
|
5486 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5487 |
return wp_set_post_terms( $post_id, $post_categories, 'category', $append ); |
0 | 5488 |
} |
5489 |
||
5490 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5491 |
* Fires actions related to the transitioning of a post's status. |
0 | 5492 |
* |
5 | 5493 |
* When a post is saved, the post status is "transitioned" from one status to another, |
5494 |
* though this does not always mean the status has actually changed before and after |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5495 |
* the save. This function fires a number of action hooks related to that transition: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5496 |
* the generic {@see 'transition_post_status'} action, as well as the dynamic hooks |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5497 |
* {@see '$old_status_to_$new_status'} and {@see '$new_status_$post->post_type'}. Note |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5498 |
* that the function does not transition the post object in the database. |
5 | 5499 |
* |
5500 |
* For instance: When publishing a post for the first time, the post status may transition |
|
5501 |
* from 'draft' – or some other status – to 'publish'. However, if a post is already |
|
5502 |
* published and is simply being updated, the "old" and "new" statuses may both be 'publish' |
|
5503 |
* before and after the transition. |
|
0 | 5504 |
* |
5505 |
* @since 2.3.0 |
|
5 | 5506 |
* |
5507 |
* @param string $new_status Transition to this post status. |
|
5508 |
* @param string $old_status Previous post status. |
|
5509 |
* @param WP_Post $post Post data. |
|
0 | 5510 |
*/ |
5 | 5511 |
function wp_transition_post_status( $new_status, $old_status, $post ) { |
5512 |
/** |
|
5513 |
* Fires when a post is transitioned from one status to another. |
|
5514 |
* |
|
5515 |
* @since 2.3.0 |
|
5516 |
* |
|
5517 |
* @param string $new_status New post status. |
|
5518 |
* @param string $old_status Old post status. |
|
5519 |
* @param WP_Post $post Post object. |
|
5520 |
*/ |
|
5521 |
do_action( 'transition_post_status', $new_status, $old_status, $post ); |
|
5522 |
||
5523 |
/** |
|
5524 |
* Fires when a post is transitioned from one status to another. |
|
5525 |
* |
|
18 | 5526 |
* The dynamic portions of the hook name, `$new_status` and `$old_status`, |
5 | 5527 |
* refer to the old and new post statuses, respectively. |
5528 |
* |
|
19 | 5529 |
* Possible hook names include: |
5530 |
* |
|
5531 |
* - `draft_to_publish` |
|
5532 |
* - `publish_to_trash` |
|
5533 |
* - `pending_to_draft` |
|
5534 |
* |
|
5 | 5535 |
* @since 2.3.0 |
5536 |
* |
|
5537 |
* @param WP_Post $post Post object. |
|
5538 |
*/ |
|
5539 |
do_action( "{$old_status}_to_{$new_status}", $post ); |
|
5540 |
||
5541 |
/** |
|
5542 |
* Fires when a post is transitioned from one status to another. |
|
5543 |
* |
|
5544 |
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`, |
|
5545 |
* refer to the new post status and post type, respectively. |
|
5546 |
* |
|
18 | 5547 |
* Possible hook names include: |
5548 |
* |
|
5549 |
* - `draft_post` |
|
5550 |
* - `future_post` |
|
5551 |
* - `pending_post` |
|
5552 |
* - `private_post` |
|
5553 |
* - `publish_post` |
|
5554 |
* - `trash_post` |
|
5555 |
* - `draft_page` |
|
5556 |
* - `future_page` |
|
5557 |
* - `pending_page` |
|
5558 |
* - `private_page` |
|
5559 |
* - `publish_page` |
|
5560 |
* - `trash_page` |
|
5561 |
* - `publish_attachment` |
|
5562 |
* - `trash_attachment` |
|
5563 |
* |
|
5 | 5564 |
* Please note: When this action is hooked using a particular post status (like |
5565 |
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is |
|
5566 |
* first transitioned to that status from something else, as well as upon |
|
5567 |
* subsequent post updates (old and new status are both the same). |
|
5568 |
* |
|
5569 |
* Therefore, if you are looking to only fire a callback when a post is first |
|
5570 |
* transitioned to a status, use the {@see 'transition_post_status'} hook instead. |
|
5571 |
* |
|
5572 |
* @since 2.3.0 |
|
19 | 5573 |
* @since 5.9.0 Added `$old_status` parameter. |
5574 |
* |
|
5575 |
* @param int $post_id Post ID. |
|
5576 |
* @param WP_Post $post Post object. |
|
5577 |
* @param string $old_status Old post status. |
|
5 | 5578 |
*/ |
19 | 5579 |
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post, $old_status ); |
0 | 5580 |
} |
5581 |
||
18 | 5582 |
/** |
5583 |
* Fires actions after a post, its terms and meta data has been saved. |
|
5584 |
* |
|
5585 |
* @since 5.6.0 |
|
5586 |
* |
|
5587 |
* @param int|WP_Post $post The post ID or object that has been saved. |
|
5588 |
* @param bool $update Whether this is an existing post being updated. |
|
5589 |
* @param null|WP_Post $post_before Null for new posts, the WP_Post object prior |
|
5590 |
* to the update for updated posts. |
|
5591 |
*/ |
|
5592 |
function wp_after_insert_post( $post, $update, $post_before ) { |
|
5593 |
$post = get_post( $post ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5594 |
|
18 | 5595 |
if ( ! $post ) { |
5596 |
return; |
|
5597 |
} |
|
5598 |
||
5599 |
$post_id = $post->ID; |
|
5600 |
||
5601 |
/** |
|
5602 |
* Fires once a post, its terms and meta data has been saved. |
|
5603 |
* |
|
5604 |
* @since 5.6.0 |
|
5605 |
* |
|
5606 |
* @param int $post_id Post ID. |
|
5607 |
* @param WP_Post $post Post object. |
|
5608 |
* @param bool $update Whether this is an existing post being updated. |
|
5609 |
* @param null|WP_Post $post_before Null for new posts, the WP_Post object prior |
|
5610 |
* to the update for updated posts. |
|
5611 |
*/ |
|
5612 |
do_action( 'wp_after_insert_post', $post_id, $post, $update, $post_before ); |
|
5613 |
} |
|
5614 |
||
0 | 5615 |
// |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5616 |
// Comment, trackback, and pingback functions. |
0 | 5617 |
// |
5618 |
||
5619 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5620 |
* Adds a URL to those already pinged. |
0 | 5621 |
* |
5622 |
* @since 1.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5623 |
* @since 4.7.0 `$post` can be a WP_Post object. |
9 | 5624 |
* @since 4.7.0 `$uri` can be an array of URIs. |
5 | 5625 |
* |
5626 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
5627 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5628 |
* @param int|WP_Post $post Post ID or post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5629 |
* @param string|array $uri Ping URI or array of URIs. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5630 |
* @return int|false How many rows were updated. |
0 | 5631 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5632 |
function add_ping( $post, $uri ) { |
0 | 5633 |
global $wpdb; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5634 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5635 |
$post = get_post( $post ); |
18 | 5636 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5637 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5638 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5639 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5640 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5641 |
$pung = trim( $post->pinged ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5642 |
$pung = preg_split( '/\s/', $pung ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5643 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5644 |
if ( is_array( $uri ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5645 |
$pung = array_merge( $pung, $uri ); |
9 | 5646 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5647 |
$pung[] = $uri; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5648 |
} |
9 | 5649 |
$new = implode( "\n", $pung ); |
5 | 5650 |
|
5651 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5652 |
* Filters the new ping URL to add for the given post. |
5 | 5653 |
* |
5654 |
* @since 2.0.0 |
|
5655 |
* |
|
5656 |
* @param string $new New ping URL to add. |
|
5657 |
*/ |
|
5658 |
$new = apply_filters( 'add_ping', $new ); |
|
5659 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5660 |
$return = $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post->ID ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5661 |
clean_post_cache( $post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5662 |
return $return; |
0 | 5663 |
} |
5664 |
||
5665 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5666 |
* Retrieves enclosures already enclosed for a post. |
0 | 5667 |
* |
5668 |
* @since 1.5.0 |
|
5669 |
* |
|
5670 |
* @param int $post_id Post ID. |
|
16 | 5671 |
* @return string[] Array of enclosures for the given post. |
0 | 5672 |
*/ |
5 | 5673 |
function get_enclosed( $post_id ) { |
0 | 5674 |
$custom_fields = get_post_custom( $post_id ); |
9 | 5675 |
$pung = array(); |
5676 |
if ( ! is_array( $custom_fields ) ) { |
|
0 | 5677 |
return $pung; |
9 | 5678 |
} |
0 | 5679 |
|
5680 |
foreach ( $custom_fields as $key => $val ) { |
|
16 | 5681 |
if ( 'enclosure' !== $key || ! is_array( $val ) ) { |
0 | 5682 |
continue; |
9 | 5683 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5684 |
foreach ( $val as $enc ) { |
0 | 5685 |
$enclosure = explode( "\n", $enc ); |
9 | 5686 |
$pung[] = trim( $enclosure[0] ); |
0 | 5687 |
} |
5688 |
} |
|
5 | 5689 |
|
5690 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5691 |
* Filters the list of enclosures already enclosed for the given post. |
5 | 5692 |
* |
5693 |
* @since 2.0.0 |
|
5694 |
* |
|
16 | 5695 |
* @param string[] $pung Array of enclosures for the given post. |
5696 |
* @param int $post_id Post ID. |
|
5 | 5697 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5698 |
return apply_filters( 'get_enclosed', $pung, $post_id ); |
0 | 5699 |
} |
5700 |
||
5701 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5702 |
* Retrieves URLs already pinged for a post. |
0 | 5703 |
* |
5704 |
* @since 1.5.0 |
|
5 | 5705 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5706 |
* @since 4.7.0 `$post` can be a WP_Post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5707 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5708 |
* @param int|WP_Post $post Post ID or object. |
18 | 5709 |
* @return string[]|false Array of URLs already pinged for the given post, false if the post is not found. |
0 | 5710 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5711 |
function get_pung( $post ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5712 |
$post = get_post( $post ); |
18 | 5713 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5714 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5715 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5716 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5717 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5718 |
$pung = trim( $post->pinged ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5719 |
$pung = preg_split( '/\s/', $pung ); |
5 | 5720 |
|
5721 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5722 |
* Filters the list of already-pinged URLs for the given post. |
5 | 5723 |
* |
5724 |
* @since 2.0.0 |
|
5725 |
* |
|
9 | 5726 |
* @param string[] $pung Array of URLs already pinged for the given post. |
5 | 5727 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5728 |
return apply_filters( 'get_pung', $pung ); |
0 | 5729 |
} |
5730 |
||
5731 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5732 |
* Retrieves URLs that need to be pinged. |
0 | 5733 |
* |
5734 |
* @since 1.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5735 |
* @since 4.7.0 `$post` can be a WP_Post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5736 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5737 |
* @param int|WP_Post $post Post ID or post object. |
16 | 5738 |
* @return string[]|false List of URLs yet to ping. |
0 | 5739 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5740 |
function get_to_ping( $post ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5741 |
$post = get_post( $post ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5742 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5743 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5744 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5745 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5746 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5747 |
$to_ping = sanitize_trackback_urls( $post->to_ping ); |
9 | 5748 |
$to_ping = preg_split( '/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY ); |
5 | 5749 |
|
5750 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5751 |
* Filters the list of URLs yet to ping for the given post. |
5 | 5752 |
* |
5753 |
* @since 2.0.0 |
|
5754 |
* |
|
16 | 5755 |
* @param string[] $to_ping List of URLs yet to ping. |
5 | 5756 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5757 |
return apply_filters( 'get_to_ping', $to_ping ); |
0 | 5758 |
} |
5759 |
||
5760 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5761 |
* Does trackbacks for a list of URLs. |
0 | 5762 |
* |
5763 |
* @since 1.0.0 |
|
5764 |
* |
|
5 | 5765 |
* @param string $tb_list Comma separated list of URLs. |
5766 |
* @param int $post_id Post ID. |
|
0 | 5767 |
*/ |
5 | 5768 |
function trackback_url_list( $tb_list, $post_id ) { |
0 | 5769 |
if ( ! empty( $tb_list ) ) { |
5 | 5770 |
// Get post data. |
5771 |
$postdata = get_post( $post_id, ARRAY_A ); |
|
5772 |
||
5773 |
// Form an excerpt. |
|
5774 |
$excerpt = strip_tags( $postdata['post_excerpt'] ? $postdata['post_excerpt'] : $postdata['post_content'] ); |
|
5775 |
||
5776 |
if ( strlen( $excerpt ) > 255 ) { |
|
5777 |
$excerpt = substr( $excerpt, 0, 252 ) . '…'; |
|
0 | 5778 |
} |
5779 |
||
5 | 5780 |
$trackback_urls = explode( ',', $tb_list ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5781 |
foreach ( (array) $trackback_urls as $tb_url ) { |
5 | 5782 |
$tb_url = trim( $tb_url ); |
5783 |
trackback( $tb_url, wp_unslash( $postdata['post_title'] ), $excerpt, $post_id ); |
|
0 | 5784 |
} |
5785 |
} |
|
5786 |
} |
|
5787 |
||
5788 |
// |
|
16 | 5789 |
// Page functions. |
0 | 5790 |
// |
5791 |
||
5792 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5793 |
* Gets a list of page IDs. |
0 | 5794 |
* |
5795 |
* @since 2.0.0 |
|
5 | 5796 |
* |
5797 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 5798 |
* |
16 | 5799 |
* @return string[] List of page IDs as strings. |
0 | 5800 |
*/ |
5801 |
function get_all_page_ids() { |
|
5802 |
global $wpdb; |
|
5803 |
||
9 | 5804 |
$page_ids = wp_cache_get( 'all_page_ids', 'posts' ); |
0 | 5805 |
if ( ! is_array( $page_ids ) ) { |
9 | 5806 |
$page_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page'" ); |
5807 |
wp_cache_add( 'all_page_ids', $page_ids, 'posts' ); |
|
0 | 5808 |
} |
5809 |
||
5810 |
return $page_ids; |
|
5811 |
} |
|
5812 |
||
5813 |
/** |
|
5814 |
* Retrieves page data given a page ID or page object. |
|
5815 |
* |
|
5816 |
* Use get_post() instead of get_page(). |
|
5817 |
* |
|
5818 |
* @since 1.5.1 |
|
5 | 5819 |
* @deprecated 3.5.0 Use get_post() |
5820 |
* |
|
16 | 5821 |
* @param int|WP_Post $page Page object or page ID. Passed by reference. |
5822 |
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
|
5823 |
* correspond to a WP_Post object, an associative array, or a numeric array, |
|
5824 |
* respectively. Default OBJECT. |
|
5825 |
* @param string $filter Optional. How the return value should be filtered. Accepts 'raw', |
|
5826 |
* 'edit', 'db', 'display'. Default 'raw'. |
|
5827 |
* @return WP_Post|array|null WP_Post or array on success, null on failure. |
|
0 | 5828 |
*/ |
9 | 5829 |
function get_page( $page, $output = OBJECT, $filter = 'raw' ) { |
0 | 5830 |
return get_post( $page, $output, $filter ); |
5831 |
} |
|
5832 |
||
5833 |
/** |
|
5834 |
* Retrieves a page given its path. |
|
5835 |
* |
|
5836 |
* @since 2.1.0 |
|
5 | 5837 |
* |
5838 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
5839 |
* |
|
5840 |
* @param string $page_path Page path. |
|
16 | 5841 |
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
5842 |
* correspond to a WP_Post object, an associative array, or a numeric array, |
|
5843 |
* respectively. Default OBJECT. |
|
5 | 5844 |
* @param string|array $post_type Optional. Post type or array of post types. Default 'page'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5845 |
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure. |
0 | 5846 |
*/ |
5 | 5847 |
function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { |
0 | 5848 |
global $wpdb; |
5849 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5850 |
$last_changed = wp_cache_get_last_changed( 'posts' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5851 |
|
9 | 5852 |
$hash = md5( $page_path . serialize( $post_type ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5853 |
$cache_key = "get_page_by_path:$hash:$last_changed"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5854 |
$cached = wp_cache_get( $cache_key, 'post-queries' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5855 |
if ( false !== $cached ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5856 |
// Special case: '0' is a bad `$page_path`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5857 |
if ( '0' === $cached || 0 === $cached ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5858 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5859 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5860 |
return get_post( $cached, $output ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5861 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5862 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5863 |
|
9 | 5864 |
$page_path = rawurlencode( urldecode( $page_path ) ); |
5865 |
$page_path = str_replace( '%2F', '/', $page_path ); |
|
5866 |
$page_path = str_replace( '%20', ' ', $page_path ); |
|
5867 |
$parts = explode( '/', trim( $page_path, '/' ) ); |
|
5868 |
$parts = array_map( 'sanitize_title_for_query', $parts ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5869 |
$escaped_parts = esc_sql( $parts ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5870 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5871 |
$in_string = "'" . implode( "','", $escaped_parts ) . "'"; |
5 | 5872 |
|
5873 |
if ( is_array( $post_type ) ) { |
|
5874 |
$post_types = $post_type; |
|
5875 |
} else { |
|
5876 |
$post_types = array( $post_type, 'attachment' ); |
|
5877 |
} |
|
5878 |
||
9 | 5879 |
$post_types = esc_sql( $post_types ); |
5 | 5880 |
$post_type_in_string = "'" . implode( "','", $post_types ) . "'"; |
9 | 5881 |
$sql = " |
5 | 5882 |
SELECT ID, post_name, post_parent, post_type |
5883 |
FROM $wpdb->posts |
|
5884 |
WHERE post_name IN ($in_string) |
|
5885 |
AND post_type IN ($post_type_in_string) |
|
5886 |
"; |
|
5887 |
||
5888 |
$pages = $wpdb->get_results( $sql, OBJECT_K ); |
|
0 | 5889 |
|
5890 |
$revparts = array_reverse( $parts ); |
|
5891 |
||
5892 |
$foundid = 0; |
|
5893 |
foreach ( (array) $pages as $page ) { |
|
5894 |
if ( $page->post_name == $revparts[0] ) { |
|
5895 |
$count = 0; |
|
9 | 5896 |
$p = $page; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5897 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5898 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5899 |
* Loop through the given path parts from right to left, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5900 |
* ensuring each matches the post ancestry. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5901 |
*/ |
16 | 5902 |
while ( 0 != $p->post_parent && isset( $pages[ $p->post_parent ] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5903 |
++$count; |
0 | 5904 |
$parent = $pages[ $p->post_parent ]; |
9 | 5905 |
if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) { |
0 | 5906 |
break; |
9 | 5907 |
} |
0 | 5908 |
$p = $parent; |
5909 |
} |
|
5910 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5911 |
if ( 0 == $p->post_parent && count( $revparts ) === $count + 1 && $p->post_name == $revparts[ $count ] ) { |
0 | 5912 |
$foundid = $page->ID; |
9 | 5913 |
if ( $page->post_type == $post_type ) { |
0 | 5914 |
break; |
9 | 5915 |
} |
0 | 5916 |
} |
5917 |
} |
|
5918 |
} |
|
5919 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5920 |
// We cache misses as well as hits. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5921 |
wp_cache_set( $cache_key, $foundid, 'post-queries' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5922 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5923 |
if ( $foundid ) { |
0 | 5924 |
return get_post( $foundid, $output ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5925 |
} |
19 | 5926 |
|
5927 |
return null; |
|
0 | 5928 |
} |
5929 |
||
5930 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5931 |
* Identifies descendants of a given page ID in a list of page objects. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5932 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5933 |
* Descendants are identified from the `$pages` array passed to the function. No database queries are performed. |
0 | 5934 |
* |
5935 |
* @since 1.5.1 |
|
5936 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5937 |
* @param int $page_id Page ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5938 |
* @param WP_Post[] $pages List of page objects from which descendants should be identified. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5939 |
* @return WP_Post[] List of page children. |
0 | 5940 |
*/ |
5 | 5941 |
function get_page_children( $page_id, $pages ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5942 |
// Build a hash of ID -> children. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5943 |
$children = array(); |
0 | 5944 |
foreach ( (array) $pages as $page ) { |
18 | 5945 |
$children[ (int) $page->post_parent ][] = $page; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5946 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5947 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5948 |
$page_list = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5949 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5950 |
// Start the search by looking at immediate children. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5951 |
if ( isset( $children[ $page_id ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5952 |
// Always start at the end of the stack in order to preserve original `$pages` order. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5953 |
$to_look = array_reverse( $children[ $page_id ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5954 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5955 |
while ( $to_look ) { |
9 | 5956 |
$p = array_pop( $to_look ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5957 |
$page_list[] = $p; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5958 |
if ( isset( $children[ $p->ID ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5959 |
foreach ( array_reverse( $children[ $p->ID ] ) as $child ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5960 |
// Append to the `$to_look` stack to descend the tree. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5961 |
$to_look[] = $child; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5962 |
} |
5 | 5963 |
} |
0 | 5964 |
} |
5965 |
} |
|
5 | 5966 |
|
0 | 5967 |
return $page_list; |
5968 |
} |
|
5969 |
||
5970 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5971 |
* Orders the pages with children under parents in a flat list. |
0 | 5972 |
* |
5973 |
* It uses auxiliary structure to hold parent-children relationships and |
|
5974 |
* runs in O(N) complexity |
|
5975 |
* |
|
5976 |
* @since 2.0.0 |
|
5977 |
* |
|
16 | 5978 |
* @param WP_Post[] $pages Posts array (passed by reference). |
5979 |
* @param int $page_id Optional. Parent page ID. Default 0. |
|
5980 |
* @return string[] Array of post names keyed by ID and arranged by hierarchy. Children immediately follow their parents. |
|
0 | 5981 |
*/ |
5982 |
function get_page_hierarchy( &$pages, $page_id = 0 ) { |
|
5983 |
if ( empty( $pages ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5984 |
return array(); |
0 | 5985 |
} |
5986 |
||
5987 |
$children = array(); |
|
5988 |
foreach ( (array) $pages as $p ) { |
|
18 | 5989 |
$parent_id = (int) $p->post_parent; |
0 | 5990 |
$children[ $parent_id ][] = $p; |
5991 |
} |
|
5992 |
||
5993 |
$result = array(); |
|
5994 |
_page_traverse_name( $page_id, $children, $result ); |
|
5995 |
||
5996 |
return $result; |
|
5997 |
} |
|
5998 |
||
5999 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6000 |
* Traverses and return all the nested children post names of a root page. |
5 | 6001 |
* |
0 | 6002 |
* $children contains parent-children relations |
6003 |
* |
|
6004 |
* @since 2.9.0 |
|
9 | 6005 |
* @access private |
5 | 6006 |
* |
6007 |
* @see _page_traverse_name() |
|
6008 |
* |
|
16 | 6009 |
* @param int $page_id Page ID. |
6010 |
* @param array $children Parent-children relations (passed by reference). |
|
6011 |
* @param string[] $result Array of page names keyed by ID (passed by reference). |
|
0 | 6012 |
*/ |
9 | 6013 |
function _page_traverse_name( $page_id, &$children, &$result ) { |
6014 |
if ( isset( $children[ $page_id ] ) ) { |
|
6015 |
foreach ( (array) $children[ $page_id ] as $child ) { |
|
0 | 6016 |
$result[ $child->ID ] = $child->post_name; |
6017 |
_page_traverse_name( $child->ID, $children, $result ); |
|
6018 |
} |
|
6019 |
} |
|
6020 |
} |
|
6021 |
||
6022 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6023 |
* Builds the URI path for a page. |
0 | 6024 |
* |
6025 |
* Sub pages will be in the "directory" under the parent page post name. |
|
6026 |
* |
|
6027 |
* @since 1.5.0 |
|
16 | 6028 |
* @since 4.6.0 The `$page` parameter was made optional. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6029 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6030 |
* @param WP_Post|object|int $page Optional. Page ID or WP_Post object. Default is global $post. |
0 | 6031 |
* @return string|false Page URI, false on error. |
6032 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6033 |
function get_page_uri( $page = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6034 |
if ( ! $page instanceof WP_Post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6035 |
$page = get_post( $page ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6036 |
} |
0 | 6037 |
|
9 | 6038 |
if ( ! $page ) { |
0 | 6039 |
return false; |
9 | 6040 |
} |
0 | 6041 |
|
6042 |
$uri = $page->post_name; |
|
6043 |
||
6044 |
foreach ( $page->ancestors as $parent ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6045 |
$parent = get_post( $parent ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6046 |
if ( $parent && $parent->post_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6047 |
$uri = $parent->post_name . '/' . $uri; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6048 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6049 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6050 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6051 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6052 |
* Filters the URI for a page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6053 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6054 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6055 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6056 |
* @param string $uri Page URI. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6057 |
* @param WP_Post $page Page object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6058 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6059 |
return apply_filters( 'get_page_uri', $uri, $page ); |
0 | 6060 |
} |
6061 |
||
6062 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6063 |
* Retrieves an array of pages (or hierarchical post type items). |
0 | 6064 |
* |
6065 |
* @since 1.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6066 |
* @since 6.3.0 Use WP_Query internally. |
0 | 6067 |
* |
5 | 6068 |
* @param array|string $args { |
6069 |
* Optional. Array or string of arguments to retrieve pages. |
|
6070 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6071 |
* @type int $child_of Page ID to return child and grandchild pages of. Note: The value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6072 |
* of `$hierarchical` has no bearing on whether `$child_of` returns |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6073 |
* hierarchical results. Default 0, or no restriction. |
5 | 6074 |
* @type string $sort_order How to sort retrieved pages. Accepts 'ASC', 'DESC'. Default 'ASC'. |
6075 |
* @type string $sort_column What columns to sort pages by, comma-separated. Accepts 'post_author', |
|
6076 |
* 'post_date', 'post_title', 'post_name', 'post_modified', 'menu_order', |
|
6077 |
* 'post_modified_gmt', 'post_parent', 'ID', 'rand', 'comment_count'. |
|
6078 |
* 'post_' can be omitted for any values that start with it. |
|
6079 |
* Default 'post_title'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6080 |
* @type bool $hierarchical Whether to return pages hierarchically. If false in conjunction with |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6081 |
* `$child_of` also being false, both arguments will be disregarded. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6082 |
* Default true. |
18 | 6083 |
* @type int[] $exclude Array of page IDs to exclude. Default empty array. |
6084 |
* @type int[] $include Array of page IDs to include. Cannot be used with `$child_of`, |
|
5 | 6085 |
* `$parent`, `$exclude`, `$meta_key`, `$meta_value`, or `$hierarchical`. |
6086 |
* Default empty array. |
|
6087 |
* @type string $meta_key Only include pages with this meta key. Default empty. |
|
6088 |
* @type string $meta_value Only include pages with this meta value. Requires `$meta_key`. |
|
6089 |
* Default empty. |
|
6090 |
* @type string $authors A comma-separated list of author IDs. Default empty. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6091 |
* @type int $parent Page ID to return direct children of. Default -1, or no restriction. |
18 | 6092 |
* @type string|int[] $exclude_tree Comma-separated string or array of page IDs to exclude. |
5 | 6093 |
* Default empty array. |
6094 |
* @type int $number The number of pages to return. Default 0, or all pages. |
|
6095 |
* @type int $offset The number of pages to skip before returning. Requires `$number`. |
|
6096 |
* Default 0. |
|
6097 |
* @type string $post_type The post type to query. Default 'page'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6098 |
* @type string|array $post_status A comma-separated list or array of post statuses to include. |
5 | 6099 |
* Default 'publish'. |
0 | 6100 |
* } |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6101 |
* @return WP_Post[]|false Array of pages (or hierarchical post type items). Boolean false if the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6102 |
* specified post type is not hierarchical or the specified status is not |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6103 |
* supported by the post type. |
0 | 6104 |
*/ |
6105 |
function get_pages( $args = array() ) { |
|
6106 |
$defaults = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6107 |
'child_of' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6108 |
'sort_order' => 'ASC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6109 |
'sort_column' => 'post_title', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6110 |
'hierarchical' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6111 |
'exclude' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6112 |
'include' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6113 |
'meta_key' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6114 |
'meta_value' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6115 |
'authors' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6116 |
'parent' => -1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6117 |
'exclude_tree' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6118 |
'number' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6119 |
'offset' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6120 |
'post_type' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6121 |
'post_status' => 'publish', |
0 | 6122 |
); |
6123 |
||
16 | 6124 |
$parsed_args = wp_parse_args( $args, $defaults ); |
6125 |
||
6126 |
$number = (int) $parsed_args['number']; |
|
6127 |
$offset = (int) $parsed_args['offset']; |
|
6128 |
$child_of = (int) $parsed_args['child_of']; |
|
6129 |
$hierarchical = $parsed_args['hierarchical']; |
|
6130 |
$exclude = $parsed_args['exclude']; |
|
6131 |
$meta_key = $parsed_args['meta_key']; |
|
6132 |
$meta_value = $parsed_args['meta_value']; |
|
6133 |
$parent = $parsed_args['parent']; |
|
6134 |
$post_status = $parsed_args['post_status']; |
|
5 | 6135 |
|
6136 |
// Make sure the post type is hierarchical. |
|
0 | 6137 |
$hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); |
16 | 6138 |
if ( ! in_array( $parsed_args['post_type'], $hierarchical_post_types, true ) ) { |
5 | 6139 |
return false; |
6140 |
} |
|
6141 |
||
6142 |
if ( $parent > 0 && ! $child_of ) { |
|
0 | 6143 |
$hierarchical = false; |
5 | 6144 |
} |
6145 |
||
6146 |
// Make sure we have a valid post status. |
|
6147 |
if ( ! is_array( $post_status ) ) { |
|
0 | 6148 |
$post_status = explode( ',', $post_status ); |
5 | 6149 |
} |
6150 |
if ( array_diff( $post_status, get_post_stati() ) ) { |
|
6151 |
return false; |
|
6152 |
} |
|
6153 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6154 |
$query_args = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6155 |
'orderby' => 'post_title', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6156 |
'order' => 'ASC', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6157 |
'post__not_in' => wp_parse_id_list( $exclude ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6158 |
'meta_key' => $meta_key, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6159 |
'meta_value' => $meta_value, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6160 |
'posts_per_page' => -1, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6161 |
'offset' => $offset, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6162 |
'post_type' => $parsed_args['post_type'], |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6163 |
'post_status' => $post_status, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6164 |
'update_post_term_cache' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6165 |
'update_post_meta_cache' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6166 |
'ignore_sticky_posts' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6167 |
'no_found_rows' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6168 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6169 |
|
16 | 6170 |
if ( ! empty( $parsed_args['include'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6171 |
$child_of = 0; // Ignore child_of, parent, exclude, meta_key, and meta_value params if using include. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6172 |
$parent = -1; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6173 |
unset( $query_args['post__not_in'], $query_args['meta_key'], $query_args['meta_value'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6174 |
$hierarchical = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6175 |
$query_args['post__in'] = wp_parse_id_list( $parsed_args['include'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6176 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6177 |
|
16 | 6178 |
if ( ! empty( $parsed_args['authors'] ) ) { |
6179 |
$post_authors = wp_parse_list( $parsed_args['authors'] ); |
|
0 | 6180 |
|
6181 |
if ( ! empty( $post_authors ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6182 |
$query_args['author__in'] = array(); |
0 | 6183 |
foreach ( $post_authors as $post_author ) { |
16 | 6184 |
// Do we have an author id or an author login? |
18 | 6185 |
if ( 0 == (int) $post_author ) { |
9 | 6186 |
$post_author = get_user_by( 'login', $post_author ); |
5 | 6187 |
if ( empty( $post_author ) ) { |
0 | 6188 |
continue; |
5 | 6189 |
} |
6190 |
if ( empty( $post_author->ID ) ) { |
|
0 | 6191 |
continue; |
5 | 6192 |
} |
0 | 6193 |
$post_author = $post_author->ID; |
6194 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6195 |
$query_args['author__in'][] = (int) $post_author; |
5 | 6196 |
} |
0 | 6197 |
} |
6198 |
} |
|
6199 |
||
6200 |
if ( is_array( $parent ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6201 |
$post_parent__in = array_map( 'absint', (array) $parent ); |
5 | 6202 |
if ( ! empty( $post_parent__in ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6203 |
$query_args['post_parent__in'] = $post_parent__in; |
5 | 6204 |
} |
0 | 6205 |
} elseif ( $parent >= 0 ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6206 |
$query_args['post_parent'] = $parent; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6207 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6208 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6209 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6210 |
* Maintain backward compatibility for `sort_column` key. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6211 |
* Additionally to `WP_Query`, it has been supporting the `post_modified_gmt` field, so this logic will translate |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6212 |
* it to `post_modified` which should result in the same order given the two dates in the fields match. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6213 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6214 |
$orderby = wp_parse_list( $parsed_args['sort_column'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6215 |
$orderby = array_map( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6216 |
static function ( $orderby_field ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6217 |
$orderby_field = trim( $orderby_field ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6218 |
if ( 'post_modified_gmt' === $orderby_field || 'modified_gmt' === $orderby_field ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6219 |
$orderby_field = str_replace( '_gmt', '', $orderby_field ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6220 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6221 |
return $orderby_field; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6222 |
}, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6223 |
$orderby |
9 | 6224 |
); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6225 |
if ( $orderby ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6226 |
$query_args['orderby'] = array_fill_keys( $orderby, $parsed_args['sort_order'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6227 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6228 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6229 |
$order = $parsed_args['sort_order']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6230 |
if ( $order ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6231 |
$query_args['order'] = $order; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6232 |
} |
0 | 6233 |
|
5 | 6234 |
if ( ! empty( $number ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6235 |
$query_args['posts_per_page'] = $number; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6236 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6237 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6238 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6239 |
* Filters query arguments passed to WP_Query in get_pages. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6240 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6241 |
* @since 6.3.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6242 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6243 |
* @param array $query_args Array of arguments passed to WP_Query. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6244 |
* @param array $parsed_args Array of get_pages() arguments. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6245 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6246 |
$query_args = apply_filters( 'get_pages_query_args', $query_args, $parsed_args ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6247 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6248 |
$pages = new WP_Query(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6249 |
$pages = $pages->query( $query_args ); |
0 | 6250 |
|
5 | 6251 |
if ( $child_of || $hierarchical ) { |
9 | 6252 |
$pages = get_page_children( $child_of, $pages ); |
5 | 6253 |
} |
6254 |
||
16 | 6255 |
if ( ! empty( $parsed_args['exclude_tree'] ) ) { |
6256 |
$exclude = wp_parse_id_list( $parsed_args['exclude_tree'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6257 |
foreach ( $exclude as $id ) { |
5 | 6258 |
$children = get_page_children( $id, $pages ); |
6259 |
foreach ( $children as $child ) { |
|
6260 |
$exclude[] = $child->ID; |
|
6261 |
} |
|
6262 |
} |
|
6263 |
||
6264 |
$num_pages = count( $pages ); |
|
0 | 6265 |
for ( $i = 0; $i < $num_pages; $i++ ) { |
16 | 6266 |
if ( in_array( $pages[ $i ]->ID, $exclude, true ) ) { |
9 | 6267 |
unset( $pages[ $i ] ); |
5 | 6268 |
} |
0 | 6269 |
} |
6270 |
} |
|
6271 |
||
5 | 6272 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6273 |
* Filters the retrieved list of pages. |
5 | 6274 |
* |
6275 |
* @since 2.1.0 |
|
6276 |
* |
|
16 | 6277 |
* @param WP_Post[] $pages Array of page objects. |
6278 |
* @param array $parsed_args Array of get_pages() arguments. |
|
5 | 6279 |
*/ |
16 | 6280 |
return apply_filters( 'get_pages', $pages, $parsed_args ); |
0 | 6281 |
} |
6282 |
||
6283 |
// |
|
16 | 6284 |
// Attachment functions. |
0 | 6285 |
// |
6286 |
||
6287 |
/** |
|
9 | 6288 |
* Determines whether an attachment URI is local and really an attachment. |
6289 |
* |
|
6290 |
* For more information on this and similar theme functions, check out |
|
6291 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
6292 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 6293 |
* |
6294 |
* @since 2.0.0 |
|
6295 |
* |
|
6296 |
* @param string $url URL to check |
|
6297 |
* @return bool True on success, false on failure. |
|
6298 |
*/ |
|
9 | 6299 |
function is_local_attachment( $url ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6300 |
if ( ! str_contains( $url, home_url() ) ) { |
0 | 6301 |
return false; |
9 | 6302 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6303 |
if ( str_contains( $url, home_url( '/?attachment_id=' ) ) ) { |
0 | 6304 |
return true; |
9 | 6305 |
} |
16 | 6306 |
|
6307 |
$id = url_to_postid( $url ); |
|
6308 |
if ( $id ) { |
|
9 | 6309 |
$post = get_post( $id ); |
16 | 6310 |
if ( 'attachment' === $post->post_type ) { |
0 | 6311 |
return true; |
9 | 6312 |
} |
0 | 6313 |
} |
6314 |
return false; |
|
6315 |
} |
|
6316 |
||
6317 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6318 |
* Inserts an attachment. |
0 | 6319 |
* |
5 | 6320 |
* If you set the 'ID' in the $args parameter, it will mean that you are |
0 | 6321 |
* updating and attempt to update the attachment. You can also set the |
6322 |
* attachment name or title by setting the key 'post_name' or 'post_title'. |
|
6323 |
* |
|
6324 |
* You can set the dates for the attachment manually by setting the 'post_date' |
|
6325 |
* and 'post_date_gmt' keys' values. |
|
6326 |
* |
|
6327 |
* By default, the comments will use the default settings for whether the |
|
6328 |
* comments are allowed. You can close them manually or keep them open by |
|
6329 |
* setting the value for the 'comment_status' key. |
|
6330 |
* |
|
6331 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6332 |
* @since 4.7.0 Added the `$wp_error` parameter to allow a WP_Error to be returned on failure. |
18 | 6333 |
* @since 5.6.0 Added the `$fire_after_hooks` parameter. |
5 | 6334 |
* |
6335 |
* @see wp_insert_post() |
|
6336 |
* |
|
18 | 6337 |
* @param string|array $args Arguments for inserting an attachment. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6338 |
* @param string|false $file Optional. Filename. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6339 |
* @param int $parent_post_id Optional. Parent post ID or 0 for no parent. Default 0. |
18 | 6340 |
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. |
6341 |
* @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6342 |
* @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. |
0 | 6343 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6344 |
function wp_insert_attachment( $args, $file = false, $parent_post_id = 0, $wp_error = false, $fire_after_hooks = true ) { |
5 | 6345 |
$defaults = array( |
6346 |
'file' => $file, |
|
9 | 6347 |
'post_parent' => 0, |
5 | 6348 |
); |
6349 |
||
6350 |
$data = wp_parse_args( $args, $defaults ); |
|
6351 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6352 |
if ( ! empty( $parent_post_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6353 |
$data['post_parent'] = $parent_post_id; |
0 | 6354 |
} |
5 | 6355 |
|
6356 |
$data['post_type'] = 'attachment'; |
|
6357 |
||
18 | 6358 |
return wp_insert_post( $data, $wp_error, $fire_after_hooks ); |
0 | 6359 |
} |
6360 |
||
6361 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6362 |
* Trashes or deletes an attachment. |
0 | 6363 |
* |
6364 |
* When an attachment is permanently deleted, the file will also be removed. |
|
6365 |
* Deletion removes all post meta fields, taxonomy, comments, etc. associated |
|
6366 |
* with the attachment (except the main post). |
|
6367 |
* |
|
16 | 6368 |
* The attachment is moved to the Trash instead of permanently deleted unless Trash |
6369 |
* for media is disabled, item is already in the Trash, or $force_delete is true. |
|
0 | 6370 |
* |
6371 |
* @since 2.0.0 |
|
5 | 6372 |
* |
6373 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
6374 |
* |
|
6375 |
* @param int $post_id Attachment ID. |
|
16 | 6376 |
* @param bool $force_delete Optional. Whether to bypass Trash and force deletion. |
5 | 6377 |
* Default false. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6378 |
* @return WP_Post|false|null Post data on success, false or null on failure. |
0 | 6379 |
*/ |
6380 |
function wp_delete_attachment( $post_id, $force_delete = false ) { |
|
6381 |
global $wpdb; |
|
6382 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6383 |
$post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6384 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6385 |
if ( ! $post ) { |
0 | 6386 |
return $post; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6387 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6388 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6389 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6391 |
if ( 'attachment' !== $post->post_type ) { |
0 | 6392 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6393 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6394 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6395 |
if ( ! $force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' !== $post->post_status ) { |
0 | 6396 |
return wp_trash_post( $post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6397 |
} |
0 | 6398 |
|
16 | 6399 |
/** |
6400 |
* Filters whether an attachment deletion should take place. |
|
6401 |
* |
|
6402 |
* @since 5.5.0 |
|
6403 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6404 |
* @param WP_Post|false|null $delete Whether to go forward with deletion. |
19 | 6405 |
* @param WP_Post $post Post object. |
6406 |
* @param bool $force_delete Whether to bypass the Trash. |
|
16 | 6407 |
*/ |
6408 |
$check = apply_filters( 'pre_delete_attachment', null, $post, $force_delete ); |
|
6409 |
if ( null !== $check ) { |
|
6410 |
return $check; |
|
6411 |
} |
|
6412 |
||
9 | 6413 |
delete_post_meta( $post_id, '_wp_trash_meta_status' ); |
6414 |
delete_post_meta( $post_id, '_wp_trash_meta_time' ); |
|
6415 |
||
6416 |
$meta = wp_get_attachment_metadata( $post_id ); |
|
0 | 6417 |
$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); |
9 | 6418 |
$file = get_attached_file( $post_id ); |
6419 |
||
19 | 6420 |
if ( is_multisite() && is_string( $file ) && ! empty( $file ) ) { |
18 | 6421 |
clean_dirsize_cache( $file ); |
9 | 6422 |
} |
0 | 6423 |
|
5 | 6424 |
/** |
6425 |
* Fires before an attachment is deleted, at the start of wp_delete_attachment(). |
|
6426 |
* |
|
6427 |
* @since 2.0.0 |
|
16 | 6428 |
* @since 5.5.0 Added the `$post` parameter. |
5 | 6429 |
* |
16 | 6430 |
* @param int $post_id Attachment ID. |
6431 |
* @param WP_Post $post Post object. |
|
5 | 6432 |
*/ |
16 | 6433 |
do_action( 'delete_attachment', $post_id, $post ); |
0 | 6434 |
|
9 | 6435 |
wp_delete_object_term_relationships( $post_id, array( 'category', 'post_tag' ) ); |
6436 |
wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) ); |
|
0 | 6437 |
|
5 | 6438 |
// Delete all for any posts. |
6439 |
delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); |
|
0 | 6440 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6441 |
wp_defer_comment_counting( true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6442 |
|
19 | 6443 |
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $post_id ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6444 |
foreach ( $comment_ids as $comment_id ) { |
0 | 6445 |
wp_delete_comment( $comment_id, true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6446 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6447 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6448 |
wp_defer_comment_counting( false ); |
0 | 6449 |
|
9 | 6450 |
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) ); |
6451 |
foreach ( $post_meta_ids as $mid ) { |
|
0 | 6452 |
delete_metadata_by_mid( 'post', $mid ); |
9 | 6453 |
} |
0 | 6454 |
|
5 | 6455 |
/** This action is documented in wp-includes/post.php */ |
16 | 6456 |
do_action( 'delete_post', $post_id, $post ); |
5 | 6457 |
$result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) ); |
6458 |
if ( ! $result ) { |
|
6459 |
return false; |
|
6460 |
} |
|
6461 |
/** This action is documented in wp-includes/post.php */ |
|
16 | 6462 |
do_action( 'deleted_post', $post_id, $post ); |
0 | 6463 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6464 |
wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ); |
0 | 6465 |
|
6466 |
clean_post_cache( $post ); |
|
6467 |
||
6468 |
return $post; |
|
6469 |
} |
|
6470 |
||
6471 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6472 |
* Deletes all files that belong to the given attachment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6473 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6474 |
* @since 4.9.7 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6475 |
* |
18 | 6476 |
* @global wpdb $wpdb WordPress database abstraction object. |
6477 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6478 |
* @param int $post_id Attachment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6479 |
* @param array $meta The attachment's meta data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6480 |
* @param array $backup_sizes The meta data for the attachment's backup images. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6481 |
* @param string $file Absolute path to the attachment's file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6482 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6483 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6484 |
function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6485 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6486 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6487 |
$uploadpath = wp_get_upload_dir(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6488 |
$deleted = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6489 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6490 |
if ( ! empty( $meta['thumb'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6491 |
// Don't delete the thumb if another attachment uses it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6492 |
if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) { |
9 | 6493 |
$thumbfile = str_replace( wp_basename( $file ), $meta['thumb'], $file ); |
16 | 6494 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6495 |
if ( ! empty( $thumbfile ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6496 |
$thumbfile = path_join( $uploadpath['basedir'], $thumbfile ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6497 |
$thumbdir = path_join( $uploadpath['basedir'], dirname( $file ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6498 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6499 |
if ( ! wp_delete_file_from_directory( $thumbfile, $thumbdir ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6500 |
$deleted = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6501 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6502 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6503 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6504 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6505 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6506 |
// Remove intermediate and backup images if there are any. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6507 |
if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6508 |
$intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) ); |
16 | 6509 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6510 |
foreach ( $meta['sizes'] as $size => $sizeinfo ) { |
9 | 6511 |
$intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file ); |
16 | 6512 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6513 |
if ( ! empty( $intermediate_file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6514 |
$intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6515 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6516 |
if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6517 |
$deleted = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6518 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6519 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6520 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6521 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6522 |
|
16 | 6523 |
if ( ! empty( $meta['original_image'] ) ) { |
6524 |
if ( empty( $intermediate_dir ) ) { |
|
6525 |
$intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) ); |
|
6526 |
} |
|
6527 |
||
6528 |
$original_image = str_replace( wp_basename( $file ), $meta['original_image'], $file ); |
|
6529 |
||
6530 |
if ( ! empty( $original_image ) ) { |
|
6531 |
$original_image = path_join( $uploadpath['basedir'], $original_image ); |
|
6532 |
||
6533 |
if ( ! wp_delete_file_from_directory( $original_image, $intermediate_dir ) ) { |
|
6534 |
$deleted = false; |
|
6535 |
} |
|
6536 |
} |
|
6537 |
} |
|
6538 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6539 |
if ( is_array( $backup_sizes ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6540 |
$del_dir = path_join( $uploadpath['basedir'], dirname( $meta['file'] ) ); |
16 | 6541 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6542 |
foreach ( $backup_sizes as $size ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6543 |
$del_file = path_join( dirname( $meta['file'] ), $size['file'] ); |
16 | 6544 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6545 |
if ( ! empty( $del_file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6546 |
$del_file = path_join( $uploadpath['basedir'], $del_file ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6547 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6548 |
if ( ! wp_delete_file_from_directory( $del_file, $del_dir ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6549 |
$deleted = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6550 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6551 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6552 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6553 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6554 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6555 |
if ( ! wp_delete_file_from_directory( $file, $uploadpath['basedir'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6556 |
$deleted = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6557 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6558 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6559 |
return $deleted; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6560 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6561 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6562 |
/** |
16 | 6563 |
* Retrieves attachment metadata for attachment ID. |
0 | 6564 |
* |
6565 |
* @since 2.1.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6566 |
* @since 6.0.0 The `$filesize` value was added to the returned array. |
0 | 6567 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6568 |
* @param int $attachment_id Attachment post ID. Defaults to global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6569 |
* @param bool $unfiltered Optional. If true, filters are not run. Default false. |
16 | 6570 |
* @return array|false { |
6571 |
* Attachment metadata. False on failure. |
|
6572 |
* |
|
6573 |
* @type int $width The width of the attachment. |
|
6574 |
* @type int $height The height of the attachment. |
|
6575 |
* @type string $file The file path relative to `wp-content/uploads`. |
|
6576 |
* @type array $sizes Keys are size slugs, each value is an array containing |
|
6577 |
* 'file', 'width', 'height', and 'mime-type'. |
|
6578 |
* @type array $image_meta Image metadata. |
|
19 | 6579 |
* @type int $filesize File size of the attachment. |
16 | 6580 |
* } |
0 | 6581 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6582 |
function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6583 |
$attachment_id = (int) $attachment_id; |
16 | 6584 |
|
18 | 6585 |
if ( ! $attachment_id ) { |
6586 |
$post = get_post(); |
|
6587 |
||
6588 |
if ( ! $post ) { |
|
6589 |
return false; |
|
6590 |
} |
|
6591 |
||
6592 |
$attachment_id = $post->ID; |
|
6593 |
} |
|
6594 |
||
6595 |
$data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true ); |
|
6596 |
||
6597 |
if ( ! $data ) { |
|
0 | 6598 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6599 |
} |
0 | 6600 |
|
9 | 6601 |
if ( $unfiltered ) { |
0 | 6602 |
return $data; |
9 | 6603 |
} |
0 | 6604 |
|
5 | 6605 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6606 |
* Filters the attachment meta data. |
5 | 6607 |
* |
6608 |
* @since 2.1.0 |
|
6609 |
* |
|
18 | 6610 |
* @param array $data Array of meta data for the given attachment. |
6611 |
* @param int $attachment_id Attachment post ID. |
|
5 | 6612 |
*/ |
18 | 6613 |
return apply_filters( 'wp_get_attachment_metadata', $data, $attachment_id ); |
0 | 6614 |
} |
6615 |
||
6616 |
/** |
|
16 | 6617 |
* Updates metadata for an attachment. |
0 | 6618 |
* |
6619 |
* @since 2.1.0 |
|
6620 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6621 |
* @param int $attachment_id Attachment post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6622 |
* @param array $data Attachment meta data. |
18 | 6623 |
* @return int|false False if $post is invalid. |
0 | 6624 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6625 |
function wp_update_attachment_metadata( $attachment_id, $data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6626 |
$attachment_id = (int) $attachment_id; |
16 | 6627 |
|
6628 |
$post = get_post( $attachment_id ); |
|
18 | 6629 |
|
16 | 6630 |
if ( ! $post ) { |
0 | 6631 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6632 |
} |
0 | 6633 |
|
5 | 6634 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6635 |
* Filters the updated attachment meta data. |
5 | 6636 |
* |
6637 |
* @since 2.1.0 |
|
6638 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6639 |
* @param array $data Array of updated attachment meta data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6640 |
* @param int $attachment_id Attachment post ID. |
5 | 6641 |
*/ |
16 | 6642 |
$data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ); |
6643 |
if ( $data ) { |
|
0 | 6644 |
return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); |
9 | 6645 |
} else { |
0 | 6646 |
return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); |
9 | 6647 |
} |
0 | 6648 |
} |
6649 |
||
6650 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6651 |
* Retrieves the URL for an attachment. |
0 | 6652 |
* |
6653 |
* @since 2.1.0 |
|
6654 |
* |
|
19 | 6655 |
* @global string $pagenow The filename of the current screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6656 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6657 |
* @param int $attachment_id Optional. Attachment post ID. Defaults to global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6658 |
* @return string|false Attachment URL, otherwise false. |
0 | 6659 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6660 |
function wp_get_attachment_url( $attachment_id = 0 ) { |
18 | 6661 |
global $pagenow; |
6662 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6663 |
$attachment_id = (int) $attachment_id; |
16 | 6664 |
|
6665 |
$post = get_post( $attachment_id ); |
|
18 | 6666 |
|
16 | 6667 |
if ( ! $post ) { |
0 | 6668 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6669 |
} |
0 | 6670 |
|
16 | 6671 |
if ( 'attachment' !== $post->post_type ) { |
0 | 6672 |
return false; |
9 | 6673 |
} |
0 | 6674 |
|
6675 |
$url = ''; |
|
5 | 6676 |
// Get attached file. |
16 | 6677 |
$file = get_post_meta( $post->ID, '_wp_attached_file', true ); |
6678 |
if ( $file ) { |
|
5 | 6679 |
// Get upload directory. |
16 | 6680 |
$uploads = wp_get_upload_dir(); |
6681 |
if ( $uploads && false === $uploads['error'] ) { |
|
5 | 6682 |
// Check that the upload base exists in the file location. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6683 |
if ( str_starts_with( $file, $uploads['basedir'] ) ) { |
5 | 6684 |
// Replace file location with url location. |
9 | 6685 |
$url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6686 |
} elseif ( str_contains( $file, 'wp-content/uploads' ) ) { |
16 | 6687 |
// Get the directory name relative to the basedir (back compat for pre-2.7 uploads). |
9 | 6688 |
$url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . wp_basename( $file ); |
5 | 6689 |
} else { |
6690 |
// It's a newly-uploaded file, therefore $file is relative to the basedir. |
|
6691 |
$url = $uploads['baseurl'] . "/$file"; |
|
6692 |
} |
|
0 | 6693 |
} |
6694 |
} |
|
6695 |
||
5 | 6696 |
/* |
6697 |
* If any of the above options failed, Fallback on the GUID as used pre-2.7, |
|
6698 |
* not recommended to rely upon this. |
|
6699 |
*/ |
|
18 | 6700 |
if ( ! $url ) { |
0 | 6701 |
$url = get_the_guid( $post->ID ); |
5 | 6702 |
} |
6703 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6704 |
// On SSL front end, URLs should be HTTPS. |
18 | 6705 |
if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) { |
5 | 6706 |
$url = set_url_scheme( $url ); |
6707 |
} |
|
6708 |
||
6709 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6710 |
* Filters the attachment URL. |
5 | 6711 |
* |
6712 |
* @since 2.1.0 |
|
6713 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6714 |
* @param string $url URL for the given attachment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6715 |
* @param int $attachment_id Attachment post ID. |
5 | 6716 |
*/ |
0 | 6717 |
$url = apply_filters( 'wp_get_attachment_url', $url, $post->ID ); |
6718 |
||
18 | 6719 |
if ( ! $url ) { |
0 | 6720 |
return false; |
9 | 6721 |
} |
0 | 6722 |
|
6723 |
return $url; |
|
6724 |
} |
|
6725 |
||
6726 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6727 |
* Retrieves the caption for an attachment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6728 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6729 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6730 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6731 |
* @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`. |
18 | 6732 |
* @return string|false Attachment caption on success, false on failure. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6733 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6734 |
function wp_get_attachment_caption( $post_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6735 |
$post_id = (int) $post_id; |
16 | 6736 |
$post = get_post( $post_id ); |
18 | 6737 |
|
16 | 6738 |
if ( ! $post ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6739 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6740 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6741 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6742 |
if ( 'attachment' !== $post->post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6743 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6744 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6745 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6746 |
$caption = $post->post_excerpt; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6747 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6748 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6749 |
* Filters the attachment caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6750 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6751 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6752 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6753 |
* @param string $caption Caption for the given attachment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6754 |
* @param int $post_id Attachment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6755 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6756 |
return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6757 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6758 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6759 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6760 |
* Retrieves URL for an attachment thumbnail. |
0 | 6761 |
* |
6762 |
* @since 2.1.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6763 |
* @since 6.1.0 Changed to use wp_get_attachment_image_url(). |
0 | 6764 |
* |
19 | 6765 |
* @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`. |
18 | 6766 |
* @return string|false Thumbnail URL on success, false on failure. |
0 | 6767 |
*/ |
6768 |
function wp_get_attachment_thumb_url( $post_id = 0 ) { |
|
6769 |
$post_id = (int) $post_id; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6770 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6771 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6772 |
* This uses image_downsize() which also looks for the (very) old format $image_meta['thumb'] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6773 |
* when the newer format $image_meta['sizes']['thumbnail'] doesn't exist. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6774 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6775 |
$thumbnail_url = wp_get_attachment_image_url( $post_id, 'thumbnail' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6776 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6777 |
if ( empty( $thumbnail_url ) ) { |
0 | 6778 |
return false; |
9 | 6779 |
} |
0 | 6780 |
|
5 | 6781 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6782 |
* Filters the attachment thumbnail URL. |
5 | 6783 |
* |
6784 |
* @since 2.1.0 |
|
6785 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6786 |
* @param string $thumbnail_url URL for the attachment thumbnail. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6787 |
* @param int $post_id Attachment ID. |
5 | 6788 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6789 |
return apply_filters( 'wp_get_attachment_thumb_url', $thumbnail_url, $post_id ); |
0 | 6790 |
} |
6791 |
||
6792 |
/** |
|
5 | 6793 |
* Verifies an attachment is of a given type. |
6794 |
* |
|
6795 |
* @since 4.2.0 |
|
6796 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6797 |
* @param string $type Attachment type. Accepts `image`, `audio`, `video`, or a file extension. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6798 |
* @param int|WP_Post $post Optional. Attachment ID or object. Default is global $post. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6799 |
* @return bool True if an accepted type or a matching file extension, false otherwise. |
5 | 6800 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6801 |
function wp_attachment_is( $type, $post = null ) { |
16 | 6802 |
$post = get_post( $post ); |
18 | 6803 |
|
16 | 6804 |
if ( ! $post ) { |
5 | 6805 |
return false; |
6806 |
} |
|
6807 |
||
16 | 6808 |
$file = get_attached_file( $post->ID ); |
18 | 6809 |
|
16 | 6810 |
if ( ! $file ) { |
5 | 6811 |
return false; |
6812 |
} |
|
6813 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6814 |
if ( str_starts_with( $post->post_mime_type, $type . '/' ) ) { |
5 | 6815 |
return true; |
6816 |
} |
|
6817 |
||
6818 |
$check = wp_check_filetype( $file ); |
|
18 | 6819 |
|
5 | 6820 |
if ( empty( $check['ext'] ) ) { |
6821 |
return false; |
|
6822 |
} |
|
6823 |
||
6824 |
$ext = $check['ext']; |
|
6825 |
||
6826 |
if ( 'import' !== $post->post_mime_type ) { |
|
6827 |
return $type === $ext; |
|
6828 |
} |
|
6829 |
||
6830 |
switch ( $type ) { |
|
9 | 6831 |
case 'image': |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6832 |
$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp', 'avif' ); |
16 | 6833 |
return in_array( $ext, $image_exts, true ); |
9 | 6834 |
|
6835 |
case 'audio': |
|
16 | 6836 |
return in_array( $ext, wp_get_audio_extensions(), true ); |
9 | 6837 |
|
6838 |
case 'video': |
|
16 | 6839 |
return in_array( $ext, wp_get_video_extensions(), true ); |
9 | 6840 |
|
6841 |
default: |
|
6842 |
return $type === $ext; |
|
5 | 6843 |
} |
6844 |
} |
|
6845 |
||
6846 |
/** |
|
9 | 6847 |
* Determines whether an attachment is an image. |
6848 |
* |
|
6849 |
* For more information on this and similar theme functions, check out |
|
6850 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
6851 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 6852 |
* |
6853 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6854 |
* @since 4.2.0 Modified into wrapper for wp_attachment_is() and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6855 |
* allowed WP_Post object to be passed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6856 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6857 |
* @param int|WP_Post $post Optional. Attachment ID or object. Default is global $post. |
5 | 6858 |
* @return bool Whether the attachment is an image. |
0 | 6859 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6860 |
function wp_attachment_is_image( $post = null ) { |
5 | 6861 |
return wp_attachment_is( 'image', $post ); |
0 | 6862 |
} |
6863 |
||
6864 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6865 |
* Retrieves the icon for a MIME type or attachment. |
0 | 6866 |
* |
6867 |
* @since 2.1.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6868 |
* @since 6.5.0 Added the `$preferred_ext` parameter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6869 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6870 |
* @param string|int $mime MIME type or attachment ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6871 |
* @param string $preferred_ext File format to prefer in return. Default '.png'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6872 |
* @return string|false Icon, false otherwise. |
0 | 6873 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6874 |
function wp_mime_type_icon( $mime = 0, $preferred_ext = '.png' ) { |
9 | 6875 |
if ( ! is_numeric( $mime ) ) { |
6876 |
$icon = wp_cache_get( "mime_type_icon_$mime" ); |
|
6877 |
} |
|
0 | 6878 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6879 |
// Check if preferred file format variable is present and is a validly formatted file extension. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6880 |
if ( ! empty( $preferred_ext ) && is_string( $preferred_ext ) && ! str_starts_with( $preferred_ext, '.' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6881 |
$preferred_ext = '.' . strtolower( $preferred_ext ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6882 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6883 |
|
0 | 6884 |
$post_id = 0; |
9 | 6885 |
if ( empty( $icon ) ) { |
0 | 6886 |
$post_mimes = array(); |
9 | 6887 |
if ( is_numeric( $mime ) ) { |
0 | 6888 |
$mime = (int) $mime; |
16 | 6889 |
$post = get_post( $mime ); |
6890 |
if ( $post ) { |
|
0 | 6891 |
$post_id = (int) $post->ID; |
9 | 6892 |
$file = get_attached_file( $post_id ); |
6893 |
$ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $file ); |
|
6894 |
if ( ! empty( $ext ) ) { |
|
0 | 6895 |
$post_mimes[] = $ext; |
16 | 6896 |
$ext_type = wp_ext2type( $ext ); |
6897 |
if ( $ext_type ) { |
|
0 | 6898 |
$post_mimes[] = $ext_type; |
9 | 6899 |
} |
0 | 6900 |
} |
6901 |
$mime = $post->post_mime_type; |
|
6902 |
} else { |
|
6903 |
$mime = 0; |
|
6904 |
} |
|
6905 |
} else { |
|
6906 |
$post_mimes[] = $mime; |
|
6907 |
} |
|
6908 |
||
9 | 6909 |
$icon_files = wp_cache_get( 'icon_files' ); |
6910 |
||
6911 |
if ( ! is_array( $icon_files ) ) { |
|
5 | 6912 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6913 |
* Filters the icon directory path. |
5 | 6914 |
* |
6915 |
* @since 2.0.0 |
|
6916 |
* |
|
6917 |
* @param string $path Icon directory absolute path. |
|
6918 |
*/ |
|
6919 |
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); |
|
6920 |
||
6921 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6922 |
* Filters the icon directory URI. |
5 | 6923 |
* |
6924 |
* @since 2.0.0 |
|
6925 |
* |
|
6926 |
* @param string $uri Icon directory URI. |
|
6927 |
*/ |
|
6928 |
$icon_dir_uri = apply_filters( 'icon_dir_uri', includes_url( 'images/media' ) ); |
|
6929 |
||
6930 |
/** |
|
16 | 6931 |
* Filters the array of icon directory URIs. |
5 | 6932 |
* |
6933 |
* @since 2.5.0 |
|
6934 |
* |
|
16 | 6935 |
* @param string[] $uris Array of icon directory URIs keyed by directory absolute path. |
5 | 6936 |
*/ |
9 | 6937 |
$dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) ); |
0 | 6938 |
$icon_files = array(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6939 |
$all_icons = array(); |
0 | 6940 |
while ( $dirs ) { |
6941 |
$keys = array_keys( $dirs ); |
|
9 | 6942 |
$dir = array_shift( $keys ); |
6943 |
$uri = array_shift( $dirs ); |
|
16 | 6944 |
$dh = opendir( $dir ); |
6945 |
if ( $dh ) { |
|
9 | 6946 |
while ( false !== $file = readdir( $dh ) ) { |
6947 |
$file = wp_basename( $file ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6948 |
if ( str_starts_with( $file, '.' ) ) { |
0 | 6949 |
continue; |
6950 |
} |
|
16 | 6951 |
|
6952 |
$ext = strtolower( substr( $file, -4 ) ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6953 |
if ( ! in_array( $ext, array( '.svg', '.png', '.gif', '.jpg' ), true ) ) { |
9 | 6954 |
if ( is_dir( "$dir/$file" ) ) { |
6955 |
$dirs[ "$dir/$file" ] = "$uri/$file"; |
|
6956 |
} |
|
6957 |
continue; |
|
6958 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6959 |
$all_icons[ "$dir/$file" ] = "$uri/$file"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6960 |
if ( $ext === $preferred_ext ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6961 |
$icon_files[ "$dir/$file" ] = "$uri/$file"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6962 |
} |
0 | 6963 |
} |
9 | 6964 |
closedir( $dh ); |
0 | 6965 |
} |
6966 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6967 |
// If directory only contained icons of a non-preferred format, return those. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6968 |
if ( empty( $icon_files ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6969 |
$icon_files = $all_icons; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6970 |
} |
0 | 6971 |
wp_cache_add( 'icon_files', $icon_files, 'default', 600 ); |
6972 |
} |
|
6973 |
||
5 | 6974 |
$types = array(); |
9 | 6975 |
// Icon wp_basename - extension = MIME wildcard. |
6976 |
foreach ( $icon_files as $file => $uri ) { |
|
6977 |
$types[ preg_replace( '/^([^.]*).*$/', '$1', wp_basename( $file ) ) ] =& $icon_files[ $file ]; |
|
0 | 6978 |
} |
6979 |
||
9 | 6980 |
if ( ! empty( $mime ) ) { |
6981 |
$post_mimes[] = substr( $mime, 0, strpos( $mime, '/' ) ); |
|
6982 |
$post_mimes[] = substr( $mime, strpos( $mime, '/' ) + 1 ); |
|
6983 |
$post_mimes[] = str_replace( '/', '_', $mime ); |
|
6984 |
} |
|
6985 |
||
6986 |
$matches = wp_match_mime_types( array_keys( $types ), $post_mimes ); |
|
6987 |
$matches['default'] = array( 'default' ); |
|
0 | 6988 |
|
6989 |
foreach ( $matches as $match => $wilds ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6990 |
foreach ( $wilds as $wild ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6991 |
if ( ! isset( $types[ $wild ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6992 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6993 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6994 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6995 |
$icon = $types[ $wild ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6996 |
if ( ! is_numeric( $mime ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6997 |
wp_cache_add( "mime_type_icon_$mime", $icon ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6998 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6999 |
break 2; |
0 | 7000 |
} |
7001 |
} |
|
7002 |
} |
|
7003 |
||
5 | 7004 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7005 |
* Filters the mime type icon. |
5 | 7006 |
* |
7007 |
* @since 2.1.0 |
|
7008 |
* |
|
7009 |
* @param string $icon Path to the mime type icon. |
|
7010 |
* @param string $mime Mime type. |
|
7011 |
* @param int $post_id Attachment ID. Will equal 0 if the function passed |
|
7012 |
* the mime type. |
|
7013 |
*/ |
|
7014 |
return apply_filters( 'wp_mime_type_icon', $icon, $mime, $post_id ); |
|
0 | 7015 |
} |
7016 |
||
7017 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7018 |
* Checks for changed slugs for published post objects and save the old slug. |
0 | 7019 |
* |
7020 |
* The function is used when a post object of any type is updated, |
|
7021 |
* by comparing the current and previous post objects. |
|
7022 |
* |
|
7023 |
* If the slug was changed and not already part of the old slugs then it will be |
|
7024 |
* added to the post meta field ('_wp_old_slug') for storing old slugs for that |
|
7025 |
* post. |
|
7026 |
* |
|
7027 |
* The most logically usage of this function is redirecting changed post objects, so |
|
7028 |
* that those that linked to an changed post will be redirected to the new post. |
|
7029 |
* |
|
7030 |
* @since 2.1.0 |
|
7031 |
* |
|
5 | 7032 |
* @param int $post_id Post ID. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7033 |
* @param WP_Post $post The post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7034 |
* @param WP_Post $post_before The previous post object. |
0 | 7035 |
*/ |
5 | 7036 |
function wp_check_for_changed_slugs( $post_id, $post, $post_before ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7037 |
// Don't bother if it hasn't changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7038 |
if ( $post->post_name == $post_before->post_name ) { |
0 | 7039 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7040 |
} |
0 | 7041 |
|
5 | 7042 |
// We're only concerned with published, non-hierarchical objects. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7043 |
if ( ! ( 'publish' === $post->post_status || ( 'attachment' === get_post_type( $post ) && 'inherit' === $post->post_status ) ) || is_post_type_hierarchical( $post->post_type ) ) { |
0 | 7044 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7045 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7046 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7047 |
$old_slugs = (array) get_post_meta( $post_id, '_wp_old_slug' ); |
0 | 7048 |
|
5 | 7049 |
// If we haven't added this old slug before, add it now. |
16 | 7050 |
if ( ! empty( $post_before->post_name ) && ! in_array( $post_before->post_name, $old_slugs, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7051 |
add_post_meta( $post_id, '_wp_old_slug', $post_before->post_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7052 |
} |
0 | 7053 |
|
5 | 7054 |
// If the new slug was used previously, delete it from the list. |
16 | 7055 |
if ( in_array( $post->post_name, $old_slugs, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7056 |
delete_post_meta( $post_id, '_wp_old_slug', $post->post_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7057 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7058 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7059 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7060 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7061 |
* Checks for changed dates for published post objects and save the old date. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7062 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7063 |
* The function is used when a post object of any type is updated, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7064 |
* by comparing the current and previous post objects. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7065 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7066 |
* If the date was changed and not already part of the old dates then it will be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7067 |
* added to the post meta field ('_wp_old_date') for storing old dates for that |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7068 |
* post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7069 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7070 |
* The most logically usage of this function is redirecting changed post objects, so |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7071 |
* that those that linked to an changed post will be redirected to the new post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7072 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7073 |
* @since 4.9.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7074 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7075 |
* @param int $post_id Post ID. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7076 |
* @param WP_Post $post The post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7077 |
* @param WP_Post $post_before The previous post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7078 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7079 |
function wp_check_for_changed_dates( $post_id, $post, $post_before ) { |
16 | 7080 |
$previous_date = gmdate( 'Y-m-d', strtotime( $post_before->post_date ) ); |
7081 |
$new_date = gmdate( 'Y-m-d', strtotime( $post->post_date ) ); |
|
7082 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7083 |
// Don't bother if it hasn't changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7084 |
if ( $new_date == $previous_date ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7085 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7086 |
} |
16 | 7087 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7088 |
// We're only concerned with published, non-hierarchical objects. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7089 |
if ( ! ( 'publish' === $post->post_status || ( 'attachment' === get_post_type( $post ) && 'inherit' === $post->post_status ) ) || is_post_type_hierarchical( $post->post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7090 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7091 |
} |
16 | 7092 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7093 |
$old_dates = (array) get_post_meta( $post_id, '_wp_old_date' ); |
16 | 7094 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7095 |
// If we haven't added this old date before, add it now. |
16 | 7096 |
if ( ! empty( $previous_date ) && ! in_array( $previous_date, $old_dates, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7097 |
add_post_meta( $post_id, '_wp_old_date', $previous_date ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7098 |
} |
16 | 7099 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7100 |
// If the new slug was used previously, delete it from the list. |
16 | 7101 |
if ( in_array( $new_date, $old_dates, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7102 |
delete_post_meta( $post_id, '_wp_old_date', $new_date ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7103 |
} |
0 | 7104 |
} |
7105 |
||
7106 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7107 |
* Retrieves the private post SQL based on capability. |
0 | 7108 |
* |
7109 |
* This function provides a standardized way to appropriately select on the |
|
7110 |
* post_status of a post type. The function will return a piece of SQL code |
|
7111 |
* that can be added to a WHERE clause; this SQL is constructed to allow all |
|
7112 |
* published posts, and all private posts to which the user has access. |
|
7113 |
* |
|
7114 |
* @since 2.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7115 |
* @since 4.3.0 Added the ability to pass an array to `$post_type`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7116 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7117 |
* @param string|array $post_type Single post type or an array of post types. Currently only supports 'post' or 'page'. |
0 | 7118 |
* @return string SQL code that can be added to a where clause. |
7119 |
*/ |
|
7120 |
function get_private_posts_cap_sql( $post_type ) { |
|
7121 |
return get_posts_by_author_sql( $post_type, false ); |
|
7122 |
} |
|
7123 |
||
7124 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7125 |
* Retrieves the post SQL based on capability, author, and type. |
0 | 7126 |
* |
7127 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7128 |
* @since 4.3.0 Introduced the ability to pass an array of post types to `$post_type`. |
5 | 7129 |
* |
7130 |
* @see get_private_posts_cap_sql() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7131 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7132 |
* |
16 | 7133 |
* @param string|string[] $post_type Single post type or an array of post types. |
7134 |
* @param bool $full Optional. Returns a full WHERE statement instead of just |
|
7135 |
* an 'andalso' term. Default true. |
|
7136 |
* @param int $post_author Optional. Query posts having a single author ID. Default null. |
|
7137 |
* @param bool $public_only Optional. Only return public posts. Skips cap checks for |
|
7138 |
* $current_user. Default false. |
|
0 | 7139 |
* @return string SQL WHERE code that can be added to a query. |
7140 |
*/ |
|
7141 |
function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) { |
|
7142 |
global $wpdb; |
|
7143 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7144 |
if ( is_array( $post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7145 |
$post_types = $post_type; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7146 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7147 |
$post_types = array( $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7148 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7149 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7150 |
$post_type_clauses = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7151 |
foreach ( $post_types as $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7152 |
$post_type_obj = get_post_type_object( $post_type ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7153 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7154 |
if ( ! $post_type_obj ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7155 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7156 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7157 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7158 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7159 |
* Filters the capability to read private posts for a custom post type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7160 |
* when generating SQL for getting posts by author. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7161 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7162 |
* @since 2.2.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7163 |
* @deprecated 3.2.0 The hook transitioned from "somewhat useless" to "totally useless". |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7164 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7165 |
* @param string $cap Capability. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7166 |
*/ |
16 | 7167 |
$cap = apply_filters_deprecated( 'pub_priv_sql_capability', array( '' ), '3.2.0' ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7168 |
|
16 | 7169 |
if ( ! $cap ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7170 |
$cap = current_user_can( $post_type_obj->cap->read_private_posts ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7171 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7172 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7173 |
// Only need to check the cap if $public_only is false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7174 |
$post_status_sql = "post_status = 'publish'"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7175 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7176 |
if ( false === $public_only ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7177 |
if ( $cap ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7178 |
// Does the user have the capability to view private posts? Guess so. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7179 |
$post_status_sql .= " OR post_status = 'private'"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7180 |
} elseif ( is_user_logged_in() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7181 |
// Users can view their own private posts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7182 |
$id = get_current_user_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7183 |
if ( null === $post_author || ! $full ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7184 |
$post_status_sql .= " OR post_status = 'private' AND post_author = $id"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7185 |
} elseif ( $id == (int) $post_author ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7186 |
$post_status_sql .= " OR post_status = 'private'"; |
16 | 7187 |
} // Else none. |
7188 |
} // Else none. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7189 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7190 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7191 |
$post_type_clauses[] = "( post_type = '" . $post_type . "' AND ( $post_status_sql ) )"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7192 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7193 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7194 |
if ( empty( $post_type_clauses ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7195 |
return $full ? 'WHERE 1 = 0' : '1 = 0'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7196 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7197 |
|
9 | 7198 |
$sql = '( ' . implode( ' OR ', $post_type_clauses ) . ' )'; |
5 | 7199 |
|
7200 |
if ( null !== $post_author ) { |
|
7201 |
$sql .= $wpdb->prepare( ' AND post_author = %d', $post_author ); |
|
7202 |
} |
|
7203 |
||
7204 |
if ( $full ) { |
|
7205 |
$sql = 'WHERE ' . $sql; |
|
7206 |
} |
|
0 | 7207 |
|
7208 |
return $sql; |
|
7209 |
} |
|
7210 |
||
7211 |
/** |
|
16 | 7212 |
* Retrieves the most recent time that a post on the site was published. |
0 | 7213 |
* |
7214 |
* The server timezone is the default and is the difference between GMT and |
|
16 | 7215 |
* server time. The 'blog' value is the date when the last post was posted. |
7216 |
* The 'gmt' is when the last post was posted in GMT formatted date. |
|
0 | 7217 |
* |
7218 |
* @since 0.71 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7219 |
* @since 4.4.0 The `$post_type` argument was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7220 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7221 |
* @param string $timezone Optional. The timezone for the timestamp. Accepts 'server', 'blog', or 'gmt'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7222 |
* 'server' uses the server's internal timezone. |
16 | 7223 |
* 'blog' uses the `post_date` field, which proxies to the timezone set for the site. |
7224 |
* 'gmt' uses the `post_date_gmt` field. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7225 |
* Default 'server'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7226 |
* @param string $post_type Optional. The post type to check. Default 'any'. |
16 | 7227 |
* @return string The date of the last post, or false on failure. |
0 | 7228 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7229 |
function get_lastpostdate( $timezone = 'server', $post_type = 'any' ) { |
16 | 7230 |
$lastpostdate = _get_last_post_time( $timezone, 'date', $post_type ); |
7231 |
||
5 | 7232 |
/** |
16 | 7233 |
* Filters the most recent time that a post on the site was published. |
5 | 7234 |
* |
7235 |
* @since 2.3.0 |
|
16 | 7236 |
* @since 5.5.0 Added the `$post_type` parameter. |
5 | 7237 |
* |
16 | 7238 |
* @param string|false $lastpostdate The most recent time that a post was published, |
7239 |
* in 'Y-m-d H:i:s' format. False on failure. |
|
7240 |
* @param string $timezone Location to use for getting the post published date. |
|
7241 |
* See get_lastpostdate() for accepted `$timezone` values. |
|
7242 |
* @param string $post_type The post type to check. |
|
5 | 7243 |
*/ |
16 | 7244 |
return apply_filters( 'get_lastpostdate', $lastpostdate, $timezone, $post_type ); |
7245 |
} |
|
7246 |
||
7247 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7248 |
* Gets the most recent time that a post on the site was modified. |
0 | 7249 |
* |
7250 |
* The server timezone is the default and is the difference between GMT and |
|
16 | 7251 |
* server time. The 'blog' value is just when the last post was modified. |
7252 |
* The 'gmt' is when the last post was modified in GMT time. |
|
0 | 7253 |
* |
7254 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7255 |
* @since 4.4.0 The `$post_type` argument was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7256 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7257 |
* @param string $timezone Optional. The timezone for the timestamp. See get_lastpostdate() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7258 |
* for information on accepted values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7259 |
* Default 'server'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7260 |
* @param string $post_type Optional. The post type to check. Default 'any'. |
16 | 7261 |
* @return string The timestamp in 'Y-m-d H:i:s' format, or false on failure. |
0 | 7262 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7263 |
function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7264 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7265 |
* Pre-filter the return value of get_lastpostmodified() before the query is run. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7266 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7267 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7268 |
* |
16 | 7269 |
* @param string|false $lastpostmodified The most recent time that a post was modified, |
7270 |
* in 'Y-m-d H:i:s' format, or false. Returning anything |
|
7271 |
* other than false will short-circuit the function. |
|
7272 |
* @param string $timezone Location to use for getting the post modified date. |
|
7273 |
* See get_lastpostdate() for accepted `$timezone` values. |
|
7274 |
* @param string $post_type The post type to check. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7275 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7276 |
$lastpostmodified = apply_filters( 'pre_get_lastpostmodified', false, $timezone, $post_type ); |
16 | 7277 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7278 |
if ( false !== $lastpostmodified ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7279 |
return $lastpostmodified; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7280 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7281 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7282 |
$lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type ); |
16 | 7283 |
$lastpostdate = get_lastpostdate( $timezone, $post_type ); |
7284 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7285 |
if ( $lastpostdate > $lastpostmodified ) { |
0 | 7286 |
$lastpostmodified = $lastpostdate; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7287 |
} |
0 | 7288 |
|
5 | 7289 |
/** |
16 | 7290 |
* Filters the most recent time that a post on the site was modified. |
5 | 7291 |
* |
7292 |
* @since 2.3.0 |
|
16 | 7293 |
* @since 5.5.0 Added the `$post_type` parameter. |
5 | 7294 |
* |
16 | 7295 |
* @param string|false $lastpostmodified The most recent time that a post was modified, |
7296 |
* in 'Y-m-d H:i:s' format. False on failure. |
|
7297 |
* @param string $timezone Location to use for getting the post modified date. |
|
7298 |
* See get_lastpostdate() for accepted `$timezone` values. |
|
7299 |
* @param string $post_type The post type to check. |
|
5 | 7300 |
*/ |
16 | 7301 |
return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone, $post_type ); |
7302 |
} |
|
7303 |
||
7304 |
/** |
|
7305 |
* Gets the timestamp of the last time any post was modified or published. |
|
5 | 7306 |
* |
0 | 7307 |
* @since 3.1.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7308 |
* @since 4.4.0 The `$post_type` argument was added. |
5 | 7309 |
* @access private |
7310 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7311 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7312 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7313 |
* @param string $timezone The timezone for the timestamp. See get_lastpostdate(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7314 |
* for information on accepted values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7315 |
* @param string $field Post field to check. Accepts 'date' or 'modified'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7316 |
* @param string $post_type Optional. The post type to check. Default 'any'. |
16 | 7317 |
* @return string|false The timestamp in 'Y-m-d H:i:s' format, or false on failure. |
0 | 7318 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7319 |
function _get_last_post_time( $timezone, $field, $post_type = 'any' ) { |
0 | 7320 |
global $wpdb; |
7321 |
||
16 | 7322 |
if ( ! in_array( $field, array( 'date', 'modified' ), true ) ) { |
0 | 7323 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7324 |
} |
0 | 7325 |
|
7326 |
$timezone = strtolower( $timezone ); |
|
7327 |
||
7328 |
$key = "lastpost{$field}:$timezone"; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7329 |
if ( 'any' !== $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7330 |
$key .= ':' . sanitize_key( $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7331 |
} |
0 | 7332 |
|
7333 |
$date = wp_cache_get( $key, 'timeinfo' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7334 |
if ( false !== $date ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7335 |
return $date; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7336 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7337 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7338 |
if ( 'any' === $post_type ) { |
0 | 7339 |
$post_types = get_post_types( array( 'public' => true ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7340 |
array_walk( $post_types, array( $wpdb, 'escape_by_ref' ) ); |
0 | 7341 |
$post_types = "'" . implode( "', '", $post_types ) . "'"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7342 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7343 |
$post_types = "'" . sanitize_key( $post_type ) . "'"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7344 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7345 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7346 |
switch ( $timezone ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7347 |
case 'gmt': |
9 | 7348 |
$date = $wpdb->get_var( "SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7349 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7350 |
case 'blog': |
9 | 7351 |
$date = $wpdb->get_var( "SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7352 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7353 |
case 'server': |
16 | 7354 |
$add_seconds_server = gmdate( 'Z' ); |
9 | 7355 |
$date = $wpdb->get_var( "SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7356 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7357 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7358 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7359 |
if ( $date ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7360 |
wp_cache_set( $key, $date, 'timeinfo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7361 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7362 |
return $date; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7363 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7364 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7365 |
return false; |
0 | 7366 |
} |
7367 |
||
7368 |
/** |
|
7369 |
* Updates posts in cache. |
|
7370 |
* |
|
7371 |
* @since 1.5.1 |
|
7372 |
* |
|
16 | 7373 |
* @param WP_Post[] $posts Array of post objects (passed by reference). |
0 | 7374 |
*/ |
7375 |
function update_post_cache( &$posts ) { |
|
9 | 7376 |
if ( ! $posts ) { |
0 | 7377 |
return; |
9 | 7378 |
} |
7379 |
||
19 | 7380 |
$data = array(); |
9 | 7381 |
foreach ( $posts as $post ) { |
19 | 7382 |
if ( empty( $post->filter ) || 'raw' !== $post->filter ) { |
7383 |
$post = sanitize_post( $post, 'raw' ); |
|
7384 |
} |
|
7385 |
$data[ $post->ID ] = $post; |
|
7386 |
} |
|
7387 |
wp_cache_add_multiple( $data, 'posts' ); |
|
0 | 7388 |
} |
7389 |
||
7390 |
/** |
|
7391 |
* Will clean the post in the cache. |
|
7392 |
* |
|
7393 |
* Cleaning means delete from the cache of the post. Will call to clean the term |
|
7394 |
* object cache associated with the post ID. |
|
7395 |
* |
|
7396 |
* This function not run if $_wp_suspend_cache_invalidation is not empty. See |
|
7397 |
* wp_suspend_cache_invalidation(). |
|
7398 |
* |
|
7399 |
* @since 2.0.0 |
|
7400 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7401 |
* @global bool $_wp_suspend_cache_invalidation |
5 | 7402 |
* |
7403 |
* @param int|WP_Post $post Post ID or post object to remove from the cache. |
|
0 | 7404 |
*/ |
7405 |
function clean_post_cache( $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7406 |
global $_wp_suspend_cache_invalidation; |
0 | 7407 |
|
9 | 7408 |
if ( ! empty( $_wp_suspend_cache_invalidation ) ) { |
0 | 7409 |
return; |
9 | 7410 |
} |
0 | 7411 |
|
7412 |
$post = get_post( $post ); |
|
18 | 7413 |
|
7414 |
if ( ! $post ) { |
|
0 | 7415 |
return; |
9 | 7416 |
} |
0 | 7417 |
|
7418 |
wp_cache_delete( $post->ID, 'posts' ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7419 |
wp_cache_delete( 'post_parent:' . (string) $post->ID, 'posts' ); |
0 | 7420 |
wp_cache_delete( $post->ID, 'post_meta' ); |
7421 |
||
7422 |
clean_object_term_cache( $post->ID, $post->post_type ); |
|
7423 |
||
7424 |
wp_cache_delete( 'wp_get_archives', 'general' ); |
|
7425 |
||
5 | 7426 |
/** |
7427 |
* Fires immediately after the given post's cache is cleaned. |
|
7428 |
* |
|
7429 |
* @since 2.5.0 |
|
7430 |
* |
|
7431 |
* @param int $post_id Post ID. |
|
7432 |
* @param WP_Post $post Post object. |
|
7433 |
*/ |
|
0 | 7434 |
do_action( 'clean_post_cache', $post->ID, $post ); |
7435 |
||
16 | 7436 |
if ( 'page' === $post->post_type ) { |
0 | 7437 |
wp_cache_delete( 'all_page_ids', 'posts' ); |
5 | 7438 |
|
7439 |
/** |
|
7440 |
* Fires immediately after the given page's cache is cleaned. |
|
7441 |
* |
|
7442 |
* @since 2.5.0 |
|
7443 |
* |
|
7444 |
* @param int $post_id Post ID. |
|
7445 |
*/ |
|
0 | 7446 |
do_action( 'clean_page_cache', $post->ID ); |
7447 |
} |
|
7448 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7449 |
wp_cache_set_posts_last_changed(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7450 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7451 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7452 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7453 |
* Updates post, term, and metadata caches for a list of post objects. |
0 | 7454 |
* |
7455 |
* @since 1.5.0 |
|
7456 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7457 |
* @param WP_Post[] $posts Array of post objects (passed by reference). |
16 | 7458 |
* @param string $post_type Optional. Post type. Default 'post'. |
7459 |
* @param bool $update_term_cache Optional. Whether to update the term cache. Default true. |
|
7460 |
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. |
|
0 | 7461 |
*/ |
5 | 7462 |
function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) { |
0 | 7463 |
// No point in doing all this work if we didn't match any posts. |
9 | 7464 |
if ( ! $posts ) { |
0 | 7465 |
return; |
9 | 7466 |
} |
7467 |
||
7468 |
update_post_cache( $posts ); |
|
0 | 7469 |
|
7470 |
$post_ids = array(); |
|
9 | 7471 |
foreach ( $posts as $post ) { |
0 | 7472 |
$post_ids[] = $post->ID; |
9 | 7473 |
} |
7474 |
||
7475 |
if ( ! $post_type ) { |
|
0 | 7476 |
$post_type = 'any'; |
9 | 7477 |
} |
0 | 7478 |
|
7479 |
if ( $update_term_cache ) { |
|
9 | 7480 |
if ( is_array( $post_type ) ) { |
0 | 7481 |
$ptypes = $post_type; |
16 | 7482 |
} elseif ( 'any' === $post_type ) { |
5 | 7483 |
$ptypes = array(); |
0 | 7484 |
// Just use the post_types in the supplied posts. |
5 | 7485 |
foreach ( $posts as $post ) { |
0 | 7486 |
$ptypes[] = $post->post_type; |
5 | 7487 |
} |
9 | 7488 |
$ptypes = array_unique( $ptypes ); |
0 | 7489 |
} else { |
9 | 7490 |
$ptypes = array( $post_type ); |
0 | 7491 |
} |
7492 |
||
9 | 7493 |
if ( ! empty( $ptypes ) ) { |
7494 |
update_object_term_cache( $post_ids, $ptypes ); |
|
7495 |
} |
|
7496 |
} |
|
7497 |
||
7498 |
if ( $update_meta_cache ) { |
|
7499 |
update_postmeta_cache( $post_ids ); |
|
7500 |
} |
|
0 | 7501 |
} |
7502 |
||
7503 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7504 |
* Updates post author user caches for a list of post objects. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7505 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7506 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7507 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7508 |
* @param WP_Post[] $posts Array of post objects. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7509 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7510 |
function update_post_author_caches( $posts ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7511 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7512 |
* cache_users() is a pluggable function so is not available prior |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7513 |
* to the `plugins_loaded` hook firing. This is to ensure against |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7514 |
* fatal errors when the function is not available. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7515 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7516 |
if ( ! function_exists( 'cache_users' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7517 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7518 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7519 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7520 |
$author_ids = wp_list_pluck( $posts, 'post_author' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7521 |
$author_ids = array_map( 'absint', $author_ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7522 |
$author_ids = array_unique( array_filter( $author_ids ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7523 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7524 |
cache_users( $author_ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7525 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7526 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7527 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7528 |
* Updates parent post caches for a list of post objects. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7529 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7530 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7531 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7532 |
* @param WP_Post[] $posts Array of post objects. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7533 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7534 |
function update_post_parent_caches( $posts ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7535 |
$parent_ids = wp_list_pluck( $posts, 'post_parent' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7536 |
$parent_ids = array_map( 'absint', $parent_ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7537 |
$parent_ids = array_unique( array_filter( $parent_ids ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7538 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7539 |
if ( ! empty( $parent_ids ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7540 |
_prime_post_caches( $parent_ids, false ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7541 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7542 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7543 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7544 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7545 |
* Updates metadata cache for a list of post IDs. |
0 | 7546 |
* |
7547 |
* Performs SQL query to retrieve the metadata for the post IDs and updates the |
|
7548 |
* metadata cache for the posts. Therefore, the functions, which call this |
|
7549 |
* function, do not need to perform SQL queries on their own. |
|
7550 |
* |
|
7551 |
* @since 2.1.0 |
|
7552 |
* |
|
16 | 7553 |
* @param int[] $post_ids Array of post IDs. |
7554 |
* @return array|false An array of metadata on success, false if there is nothing to update. |
|
0 | 7555 |
*/ |
5 | 7556 |
function update_postmeta_cache( $post_ids ) { |
9 | 7557 |
return update_meta_cache( 'post', $post_ids ); |
0 | 7558 |
} |
7559 |
||
7560 |
/** |
|
7561 |
* Will clean the attachment in the cache. |
|
7562 |
* |
|
7563 |
* Cleaning means delete from the cache. Optionally will clean the term |
|
7564 |
* object cache associated with the attachment ID. |
|
7565 |
* |
|
5 | 7566 |
* This function will not run if $_wp_suspend_cache_invalidation is not empty. |
7567 |
* |
|
0 | 7568 |
* @since 3.0.0 |
7569 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7570 |
* @global bool $_wp_suspend_cache_invalidation |
5 | 7571 |
* |
7572 |
* @param int $id The attachment ID in the cache to clean. |
|
7573 |
* @param bool $clean_terms Optional. Whether to clean terms cache. Default false. |
|
0 | 7574 |
*/ |
5 | 7575 |
function clean_attachment_cache( $id, $clean_terms = false ) { |
0 | 7576 |
global $_wp_suspend_cache_invalidation; |
7577 |
||
9 | 7578 |
if ( ! empty( $_wp_suspend_cache_invalidation ) ) { |
0 | 7579 |
return; |
9 | 7580 |
} |
0 | 7581 |
|
7582 |
$id = (int) $id; |
|
7583 |
||
9 | 7584 |
wp_cache_delete( $id, 'posts' ); |
7585 |
wp_cache_delete( $id, 'post_meta' ); |
|
7586 |
||
7587 |
if ( $clean_terms ) { |
|
7588 |
clean_object_term_cache( $id, 'attachment' ); |
|
7589 |
} |
|
0 | 7590 |
|
5 | 7591 |
/** |
7592 |
* Fires after the given attachment's cache is cleaned. |
|
7593 |
* |
|
7594 |
* @since 3.0.0 |
|
7595 |
* |
|
7596 |
* @param int $id Attachment ID. |
|
7597 |
*/ |
|
7598 |
do_action( 'clean_attachment_cache', $id ); |
|
0 | 7599 |
} |
7600 |
||
7601 |
// |
|
16 | 7602 |
// Hooks. |
0 | 7603 |
// |
7604 |
||
7605 |
/** |
|
7606 |
* Hook for managing future post transitions to published. |
|
7607 |
* |
|
7608 |
* @since 2.3.0 |
|
7609 |
* @access private |
|
5 | 7610 |
* |
7611 |
* @see wp_clear_scheduled_hook() |
|
7612 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
7613 |
* |
|
7614 |
* @param string $new_status New post status. |
|
7615 |
* @param string $old_status Previous post status. |
|
7616 |
* @param WP_Post $post Post object. |
|
0 | 7617 |
*/ |
5 | 7618 |
function _transition_post_status( $new_status, $old_status, $post ) { |
0 | 7619 |
global $wpdb; |
7620 |
||
16 | 7621 |
if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
5 | 7622 |
// Reset GUID if transitioning to publish and it is empty. |
16 | 7623 |
if ( '' === get_the_guid( $post->ID ) ) { |
0 | 7624 |
$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) ); |
9 | 7625 |
} |
5 | 7626 |
|
7627 |
/** |
|
7628 |
* Fires when a post's status is transitioned from private to published. |
|
7629 |
* |
|
7630 |
* @since 1.5.0 |
|
16 | 7631 |
* @deprecated 2.3.0 Use {@see 'private_to_publish'} instead. |
5 | 7632 |
* |
7633 |
* @param int $post_id Post ID. |
|
7634 |
*/ |
|
16 | 7635 |
do_action_deprecated( 'private_to_published', array( $post->ID ), '2.3.0', 'private_to_publish' ); |
0 | 7636 |
} |
7637 |
||
5 | 7638 |
// If published posts changed clear the lastpostmodified cache. |
16 | 7639 |
if ( 'publish' === $new_status || 'publish' === $old_status ) { |
0 | 7640 |
foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { |
7641 |
wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' ); |
|
7642 |
wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7643 |
wp_cache_delete( "lastpostdate:$timezone:{$post->post_type}", 'timeinfo' ); |
0 | 7644 |
} |
7645 |
} |
|
7646 |
||
5 | 7647 |
if ( $new_status !== $old_status ) { |
7648 |
wp_cache_delete( _count_posts_cache_key( $post->post_type ), 'counts' ); |
|
7649 |
wp_cache_delete( _count_posts_cache_key( $post->post_type, 'readable' ), 'counts' ); |
|
7650 |
} |
|
7651 |
||
0 | 7652 |
// Always clears the hook in case the post status bounced from future to draft. |
9 | 7653 |
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); |
0 | 7654 |
} |
7655 |
||
7656 |
/** |
|
7657 |
* Hook used to schedule publication for a post marked for the future. |
|
7658 |
* |
|
7659 |
* The $post properties used and must exist are 'ID' and 'post_date_gmt'. |
|
7660 |
* |
|
7661 |
* @since 2.3.0 |
|
7662 |
* @access private |
|
7663 |
* |
|
5 | 7664 |
* @param int $deprecated Not used. Can be set to null. Never implemented. Not marked |
7665 |
* as deprecated with _deprecated_argument() as it conflicts with |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7666 |
* wp_transition_post_status() and the default filter for _future_post_hook(). |
5 | 7667 |
* @param WP_Post $post Post object. |
0 | 7668 |
*/ |
7669 |
function _future_post_hook( $deprecated, $post ) { |
|
7670 |
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); |
|
9 | 7671 |
wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT' ), 'publish_future_post', array( $post->ID ) ); |
0 | 7672 |
} |
7673 |
||
7674 |
/** |
|
7675 |
* Hook to schedule pings and enclosures when a post is published. |
|
7676 |
* |
|
5 | 7677 |
* Uses XMLRPC_REQUEST and WP_IMPORTING constants. |
7678 |
* |
|
0 | 7679 |
* @since 2.3.0 |
7680 |
* @access private |
|
5 | 7681 |
* |
19 | 7682 |
* @param int $post_id The ID of the post being published. |
0 | 7683 |
*/ |
5 | 7684 |
function _publish_post_hook( $post_id ) { |
7685 |
if ( defined( 'XMLRPC_REQUEST' ) ) { |
|
7686 |
/** |
|
7687 |
* Fires when _publish_post_hook() is called during an XML-RPC request. |
|
7688 |
* |
|
7689 |
* @since 2.1.0 |
|
7690 |
* |
|
7691 |
* @param int $post_id Post ID. |
|
7692 |
*/ |
|
7693 |
do_action( 'xmlrpc_publish_post', $post_id ); |
|
7694 |
} |
|
0 | 7695 |
|
9 | 7696 |
if ( defined( 'WP_IMPORTING' ) ) { |
0 | 7697 |
return; |
9 | 7698 |
} |
7699 |
||
7700 |
if ( get_option( 'default_pingback_flag' ) ) { |
|
16 | 7701 |
add_post_meta( $post_id, '_pingme', '1', true ); |
7702 |
} |
|
7703 |
add_post_meta( $post_id, '_encloseme', '1', true ); |
|
7704 |
||
7705 |
$to_ping = get_to_ping( $post_id ); |
|
7706 |
if ( ! empty( $to_ping ) ) { |
|
7707 |
add_post_meta( $post_id, '_trackbackme', '1' ); |
|
7708 |
} |
|
0 | 7709 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7710 |
if ( ! wp_next_scheduled( 'do_pings' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7711 |
wp_schedule_single_event( time(), 'do_pings' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7712 |
} |
0 | 7713 |
} |
7714 |
||
7715 |
/** |
|
9 | 7716 |
* Returns the ID of the post's parent. |
0 | 7717 |
* |
7718 |
* @since 3.1.0 |
|
19 | 7719 |
* @since 5.9.0 The `$post` parameter was made optional. |
7720 |
* |
|
7721 |
* @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. |
|
16 | 7722 |
* @return int|false Post parent ID (which can be 0 if there is no parent), |
7723 |
* or false if the post does not exist. |
|
0 | 7724 |
*/ |
19 | 7725 |
function wp_get_post_parent_id( $post = null ) { |
9 | 7726 |
$post = get_post( $post ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7727 |
|
9 | 7728 |
if ( ! $post || is_wp_error( $post ) ) { |
0 | 7729 |
return false; |
9 | 7730 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7731 |
|
0 | 7732 |
return (int) $post->post_parent; |
7733 |
} |
|
7734 |
||
7735 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7736 |
* Checks the given subset of the post hierarchy for hierarchy loops. |
5 | 7737 |
* |
7738 |
* Prevents loops from forming and breaks those that it finds. Attached |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7739 |
* to the {@see 'wp_insert_post_parent'} filter. |
0 | 7740 |
* |
7741 |
* @since 3.1.0 |
|
5 | 7742 |
* |
7743 |
* @see wp_find_hierarchy_loop() |
|
0 | 7744 |
* |
7745 |
* @param int $post_parent ID of the parent for the post we're checking. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7746 |
* @param int $post_id ID of the post we're checking. |
5 | 7747 |
* @return int The new post_parent for the post, 0 otherwise. |
0 | 7748 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7749 |
function wp_check_post_hierarchy_for_loops( $post_parent, $post_id ) { |
5 | 7750 |
// Nothing fancy here - bail. |
9 | 7751 |
if ( ! $post_parent ) { |
0 | 7752 |
return 0; |
9 | 7753 |
} |
0 | 7754 |
|
5 | 7755 |
// New post can't cause a loop. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7756 |
if ( ! $post_id ) { |
0 | 7757 |
return $post_parent; |
9 | 7758 |
} |
0 | 7759 |
|
5 | 7760 |
// Can't be its own parent. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7761 |
if ( $post_parent == $post_id ) { |
0 | 7762 |
return 0; |
9 | 7763 |
} |
0 | 7764 |
|
5 | 7765 |
// Now look for larger loops. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7766 |
$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_id, $post_parent ); |
16 | 7767 |
if ( ! $loop ) { |
7768 |
return $post_parent; // No loop. |
|
9 | 7769 |
} |
0 | 7770 |
|
5 | 7771 |
// Setting $post_parent to the given value causes a loop. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7772 |
if ( isset( $loop[ $post_id ] ) ) { |
0 | 7773 |
return 0; |
9 | 7774 |
} |
0 | 7775 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7776 |
// There's a loop, but it doesn't contain $post_id. Break the loop. |
9 | 7777 |
foreach ( array_keys( $loop ) as $loop_member ) { |
7778 |
wp_update_post( |
|
7779 |
array( |
|
7780 |
'ID' => $loop_member, |
|
7781 |
'post_parent' => 0, |
|
7782 |
) |
|
7783 |
); |
|
7784 |
} |
|
0 | 7785 |
|
7786 |
return $post_parent; |
|
7787 |
} |
|
7788 |
||
7789 |
/** |
|
9 | 7790 |
* Sets the post thumbnail (featured image) for the given post. |
0 | 7791 |
* |
7792 |
* @since 3.1.0 |
|
7793 |
* |
|
5 | 7794 |
* @param int|WP_Post $post Post ID or post object where thumbnail should be attached. |
7795 |
* @param int $thumbnail_id Thumbnail to attach. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7796 |
* @return int|bool True on success, false on failure. |
0 | 7797 |
*/ |
7798 |
function set_post_thumbnail( $post, $thumbnail_id ) { |
|
9 | 7799 |
$post = get_post( $post ); |
0 | 7800 |
$thumbnail_id = absint( $thumbnail_id ); |
7801 |
if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) { |
|
9 | 7802 |
if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) { |
0 | 7803 |
return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); |
9 | 7804 |
} else { |
0 | 7805 |
return delete_post_meta( $post->ID, '_thumbnail_id' ); |
9 | 7806 |
} |
0 | 7807 |
} |
7808 |
return false; |
|
7809 |
} |
|
7810 |
||
7811 |
/** |
|
9 | 7812 |
* Removes the thumbnail (featured image) from the given post. |
0 | 7813 |
* |
7814 |
* @since 3.3.0 |
|
7815 |
* |
|
9 | 7816 |
* @param int|WP_Post $post Post ID or post object from which the thumbnail should be removed. |
0 | 7817 |
* @return bool True on success, false on failure. |
7818 |
*/ |
|
7819 |
function delete_post_thumbnail( $post ) { |
|
7820 |
$post = get_post( $post ); |
|
9 | 7821 |
if ( $post ) { |
0 | 7822 |
return delete_post_meta( $post->ID, '_thumbnail_id' ); |
9 | 7823 |
} |
0 | 7824 |
return false; |
7825 |
} |
|
7826 |
||
7827 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7828 |
* Deletes auto-drafts for new posts that are > 7 days old. |
0 | 7829 |
* |
7830 |
* @since 3.4.0 |
|
5 | 7831 |
* |
7832 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
0 | 7833 |
*/ |
7834 |
function wp_delete_auto_drafts() { |
|
7835 |
global $wpdb; |
|
7836 |
||
5 | 7837 |
// Cleanup old auto-drafts more than 7 days old. |
0 | 7838 |
$old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); |
5 | 7839 |
foreach ( (array) $old_posts as $delete ) { |
7840 |
// Force delete. |
|
7841 |
wp_delete_post( $delete, true ); |
|
7842 |
} |
|
0 | 7843 |
} |
7844 |
||
7845 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7846 |
* Queues posts for lazy-loading of term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7847 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7848 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7849 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7850 |
* @param WP_Post[] $posts Array of WP_Post objects. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7851 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7852 |
function wp_queue_posts_for_term_meta_lazyload( $posts ) { |
16 | 7853 |
$post_type_taxonomies = array(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7854 |
$prime_post_terms = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7855 |
foreach ( $posts as $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7856 |
if ( ! ( $post instanceof WP_Post ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7857 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7858 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7859 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7860 |
if ( ! isset( $post_type_taxonomies[ $post->post_type ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7861 |
$post_type_taxonomies[ $post->post_type ] = get_object_taxonomies( $post->post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7862 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7863 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7864 |
foreach ( $post_type_taxonomies[ $post->post_type ] as $taxonomy ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7865 |
$prime_post_terms[ $taxonomy ][] = $post->ID; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7866 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7867 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7868 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7869 |
$term_ids = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7870 |
if ( $prime_post_terms ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7871 |
foreach ( $prime_post_terms as $taxonomy => $post_ids ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7872 |
$cached_term_ids = wp_cache_get_multiple( $post_ids, "{$taxonomy}_relationships" ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7873 |
if ( is_array( $cached_term_ids ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7874 |
$cached_term_ids = array_filter( $cached_term_ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7875 |
foreach ( $cached_term_ids as $_term_ids ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7876 |
// Backward compatibility for if a plugin is putting objects into the cache, rather than IDs. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7877 |
foreach ( $_term_ids as $term_id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7878 |
if ( is_numeric( $term_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7879 |
$term_ids[] = (int) $term_id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7880 |
} elseif ( isset( $term_id->term_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7881 |
$term_ids[] = (int) $term_id->term_id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7882 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7883 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7884 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7885 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7886 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7887 |
$term_ids = array_unique( $term_ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7888 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7889 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7890 |
wp_lazyload_term_meta( $term_ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7891 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7892 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7893 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7894 |
* Updates the custom taxonomies' term counts when a post's status is changed. |
5 | 7895 |
* |
7896 |
* For example, default posts term counts (for custom taxonomies) don't include |
|
7897 |
* private / draft posts. |
|
7898 |
* |
|
7899 |
* @since 3.3.0 |
|
0 | 7900 |
* @access private |
5 | 7901 |
* |
7902 |
* @param string $new_status New post status. |
|
7903 |
* @param string $old_status Old post status. |
|
7904 |
* @param WP_Post $post Post object. |
|
0 | 7905 |
*/ |
7906 |
function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) { |
|
7907 |
// Update counts for the post's terms. |
|
7908 |
foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) { |
|
7909 |
$tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) ); |
|
7910 |
wp_update_term_count( $tt_ids, $taxonomy ); |
|
7911 |
} |
|
7912 |
} |
|
7913 |
||
7914 |
/** |
|
18 | 7915 |
* Adds any posts from the given IDs to the cache that do not already exist in cache. |
0 | 7916 |
* |
7917 |
* @since 3.4.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7918 |
* @since 6.1.0 This function is no longer marked as "private". |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7919 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7920 |
* @see update_post_cache() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7921 |
* @see update_postmeta_cache() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7922 |
* @see update_object_term_cache() |
5 | 7923 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7924 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7925 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7926 |
* @param int[] $ids ID list. |
5 | 7927 |
* @param bool $update_term_cache Optional. Whether to update the term cache. Default true. |
7928 |
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. |
|
0 | 7929 |
*/ |
7930 |
function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) { |
|
7931 |
global $wpdb; |
|
7932 |
||
7933 |
$non_cached_ids = _get_non_cached_ids( $ids, 'posts' ); |
|
9 | 7934 |
if ( ! empty( $non_cached_ids ) ) { |
18 | 7935 |
$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) ); |
0 | 7936 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7937 |
if ( $fresh_posts ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7938 |
// Despite the name, update_post_cache() expects an array rather than a single post. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7939 |
update_post_cache( $fresh_posts ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7940 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7941 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7942 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7943 |
if ( $update_meta_cache ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7944 |
update_postmeta_cache( $ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7945 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7946 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7947 |
if ( $update_term_cache ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7948 |
$post_types = array_map( 'get_post_type', $ids ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7949 |
$post_types = array_unique( $post_types ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7950 |
update_object_term_cache( $ids, $post_types ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7951 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7952 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7953 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7954 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7955 |
* Prime the cache containing the parent ID of various post objects. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7956 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7957 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7958 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7959 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7960 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7961 |
* @param int[] $ids ID list. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7962 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7963 |
function _prime_post_parent_id_caches( array $ids ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7964 |
global $wpdb; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7965 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7966 |
$ids = array_filter( $ids, '_validate_cache_id' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7967 |
$ids = array_unique( array_map( 'intval', $ids ), SORT_NUMERIC ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7968 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7969 |
if ( empty( $ids ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7970 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7971 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7972 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7973 |
$cache_keys = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7974 |
foreach ( $ids as $id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7975 |
$cache_keys[ $id ] = 'post_parent:' . (string) $id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7976 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7977 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7978 |
$cached_data = wp_cache_get_multiple( array_values( $cache_keys ), 'posts' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7979 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7980 |
$non_cached_ids = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7981 |
foreach ( $cache_keys as $id => $cache_key ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7982 |
if ( false === $cached_data[ $cache_key ] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7983 |
$non_cached_ids[] = $id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7984 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7985 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7986 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7987 |
if ( ! empty( $non_cached_ids ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7988 |
$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.ID, $wpdb->posts.post_parent FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7989 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7990 |
if ( $fresh_posts ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7991 |
$post_parent_data = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7992 |
foreach ( $fresh_posts as $fresh_post ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7993 |
$post_parent_data[ 'post_parent:' . (string) $fresh_post->ID ] = (int) $fresh_post->post_parent; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7994 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7995 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7996 |
wp_cache_add_multiple( $post_parent_data, 'posts' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7997 |
} |
0 | 7998 |
} |
7999 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8000 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8001 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8002 |
* Adds a suffix if any trashed posts have a given slug. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8003 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8004 |
* Store its desired (i.e. current) slug so it can try to reclaim it |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8005 |
* if the post is untrashed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8006 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8007 |
* For internal use. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8008 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8009 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8010 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8011 |
* |
19 | 8012 |
* @param string $post_name Post slug. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8013 |
* @param int $post_id Optional. Post ID that should be ignored. Default 0. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8014 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8015 |
function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_id = 0 ) { |
9 | 8016 |
$trashed_posts_with_desired_slug = get_posts( |
8017 |
array( |
|
8018 |
'name' => $post_name, |
|
8019 |
'post_status' => 'trash', |
|
8020 |
'post_type' => 'any', |
|
8021 |
'nopaging' => true, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8022 |
'post__not_in' => array( $post_id ), |
9 | 8023 |
) |
8024 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8025 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8026 |
if ( ! empty( $trashed_posts_with_desired_slug ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8027 |
foreach ( $trashed_posts_with_desired_slug as $_post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8028 |
wp_add_trashed_suffix_to_post_name_for_post( $_post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8029 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8030 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8031 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8032 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8033 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8034 |
* Adds a trashed suffix for a given post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8035 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8036 |
* Store its desired (i.e. current) slug so it can try to reclaim it |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8037 |
* if the post is untrashed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8038 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8039 |
* For internal use. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8040 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8041 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8042 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8043 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8044 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8045 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8046 |
* @param WP_Post $post The post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8047 |
* @return string New slug for the post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8048 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8049 |
function wp_add_trashed_suffix_to_post_name_for_post( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8050 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8051 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8052 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8053 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8054 |
if ( str_ends_with( $post->post_name, '__trashed' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8055 |
return $post->post_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8056 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8057 |
add_post_meta( $post->ID, '_wp_desired_post_slug', $post->post_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8058 |
$post_name = _truncate_post_slug( $post->post_name, 191 ) . '__trashed'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8059 |
$wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8060 |
clean_post_cache( $post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8061 |
return $post_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8062 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8063 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8064 |
/** |
9 | 8065 |
* Sets the last changed time for the 'posts' cache group. |
8066 |
* |
|
8067 |
* @since 5.0.0 |
|
8068 |
*/ |
|
8069 |
function wp_cache_set_posts_last_changed() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8070 |
wp_cache_set_last_changed( 'posts' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8071 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8072 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8073 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8074 |
* Gets all available post MIME types for a given post type. |
9 | 8075 |
* |
8076 |
* @since 2.5.0 |
|
8077 |
* |
|
8078 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
8079 |
* |
|
8080 |
* @param string $type |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8081 |
* @return string[] An array of MIME types. |
9 | 8082 |
*/ |
8083 |
function get_available_post_mime_types( $type = 'attachment' ) { |
|
8084 |
global $wpdb; |
|
8085 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8086 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8087 |
* Filters the list of available post MIME types for the given post type. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8088 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8089 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8090 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8091 |
* @param string[]|null $mime_types An array of MIME types. Default null. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8092 |
* @param string $type The post type name. Usually 'attachment' but can be any post type. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8093 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8094 |
$mime_types = apply_filters( 'pre_get_available_post_mime_types', null, $type ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8095 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8096 |
if ( ! is_array( $mime_types ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8097 |
$mime_types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s AND post_mime_type != ''", $type ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8098 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8099 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8100 |
// Remove nulls from returned $mime_types. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8101 |
return array_values( array_filter( $mime_types ) ); |
9 | 8102 |
} |
16 | 8103 |
|
8104 |
/** |
|
8105 |
* Retrieves the path to an uploaded image file. |
|
8106 |
* |
|
8107 |
* Similar to `get_attached_file()` however some images may have been processed after uploading |
|
8108 |
* to make them suitable for web use. In this case the attached "full" size file is usually replaced |
|
8109 |
* with a scaled down version of the original image. This function always returns the path |
|
8110 |
* to the originally uploaded image file. |
|
8111 |
* |
|
8112 |
* @since 5.3.0 |
|
8113 |
* @since 5.4.0 Added the `$unfiltered` parameter. |
|
8114 |
* |
|
8115 |
* @param int $attachment_id Attachment ID. |
|
8116 |
* @param bool $unfiltered Optional. Passed through to `get_attached_file()`. Default false. |
|
8117 |
* @return string|false Path to the original image file or false if the attachment is not an image. |
|
8118 |
*/ |
|
8119 |
function wp_get_original_image_path( $attachment_id, $unfiltered = false ) { |
|
8120 |
if ( ! wp_attachment_is_image( $attachment_id ) ) { |
|
8121 |
return false; |
|
8122 |
} |
|
8123 |
||
8124 |
$image_meta = wp_get_attachment_metadata( $attachment_id ); |
|
8125 |
$image_file = get_attached_file( $attachment_id, $unfiltered ); |
|
8126 |
||
8127 |
if ( empty( $image_meta['original_image'] ) ) { |
|
8128 |
$original_image = $image_file; |
|
8129 |
} else { |
|
8130 |
$original_image = path_join( dirname( $image_file ), $image_meta['original_image'] ); |
|
8131 |
} |
|
8132 |
||
8133 |
/** |
|
8134 |
* Filters the path to the original image. |
|
8135 |
* |
|
8136 |
* @since 5.3.0 |
|
8137 |
* |
|
8138 |
* @param string $original_image Path to original image file. |
|
8139 |
* @param int $attachment_id Attachment ID. |
|
8140 |
*/ |
|
8141 |
return apply_filters( 'wp_get_original_image_path', $original_image, $attachment_id ); |
|
8142 |
} |
|
8143 |
||
8144 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8145 |
* Retrieves the URL to an original attachment image. |
16 | 8146 |
* |
8147 |
* Similar to `wp_get_attachment_url()` however some images may have been |
|
8148 |
* processed after uploading. In this case this function returns the URL |
|
8149 |
* to the originally uploaded image file. |
|
8150 |
* |
|
8151 |
* @since 5.3.0 |
|
8152 |
* |
|
8153 |
* @param int $attachment_id Attachment post ID. |
|
8154 |
* @return string|false Attachment image URL, false on error or if the attachment is not an image. |
|
8155 |
*/ |
|
8156 |
function wp_get_original_image_url( $attachment_id ) { |
|
8157 |
if ( ! wp_attachment_is_image( $attachment_id ) ) { |
|
8158 |
return false; |
|
8159 |
} |
|
8160 |
||
8161 |
$image_url = wp_get_attachment_url( $attachment_id ); |
|
8162 |
||
18 | 8163 |
if ( ! $image_url ) { |
16 | 8164 |
return false; |
8165 |
} |
|
8166 |
||
8167 |
$image_meta = wp_get_attachment_metadata( $attachment_id ); |
|
8168 |
||
8169 |
if ( empty( $image_meta['original_image'] ) ) { |
|
8170 |
$original_image_url = $image_url; |
|
8171 |
} else { |
|
8172 |
$original_image_url = path_join( dirname( $image_url ), $image_meta['original_image'] ); |
|
8173 |
} |
|
8174 |
||
8175 |
/** |
|
8176 |
* Filters the URL to the original attachment image. |
|
8177 |
* |
|
8178 |
* @since 5.3.0 |
|
8179 |
* |
|
8180 |
* @param string $original_image_url URL to original image. |
|
8181 |
* @param int $attachment_id Attachment ID. |
|
8182 |
*/ |
|
8183 |
return apply_filters( 'wp_get_original_image_url', $original_image_url, $attachment_id ); |
|
8184 |
} |
|
18 | 8185 |
|
8186 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8187 |
* Filters callback which sets the status of an untrashed post to its previous status. |
18 | 8188 |
* |
8189 |
* This can be used as a callback on the `wp_untrash_post_status` filter. |
|
8190 |
* |
|
8191 |
* @since 5.6.0 |
|
8192 |
* |
|
8193 |
* @param string $new_status The new status of the post being restored. |
|
8194 |
* @param int $post_id The ID of the post being restored. |
|
8195 |
* @param string $previous_status The status of the post at the point where it was trashed. |
|
8196 |
* @return string The new status of the post. |
|
8197 |
*/ |
|
8198 |
function wp_untrash_post_set_previous_status( $new_status, $post_id, $previous_status ) { |
|
8199 |
return $previous_status; |
|
8200 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8201 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8202 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8203 |
* Returns whether the post can be edited in the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8204 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8205 |
* @since 5.0.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8206 |
* @since 6.1.0 Moved to wp-includes from wp-admin. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8207 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8208 |
* @param int|WP_Post $post Post ID or WP_Post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8209 |
* @return bool Whether the post can be edited in the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8210 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8211 |
function use_block_editor_for_post( $post ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8212 |
$post = get_post( $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8213 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8214 |
if ( ! $post ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8215 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8216 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8217 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8218 |
// We're in the meta box loader, so don't use the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8219 |
if ( is_admin() && isset( $_GET['meta-box-loader'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8220 |
check_admin_referer( 'meta-box-loader', 'meta-box-loader-nonce' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8221 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8222 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8223 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8224 |
$use_block_editor = use_block_editor_for_post_type( $post->post_type ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8225 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8226 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8227 |
* Filters whether a post is able to be edited in the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8228 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8229 |
* @since 5.0.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8230 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8231 |
* @param bool $use_block_editor Whether the post can be edited or not. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8232 |
* @param WP_Post $post The post being checked. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8233 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8234 |
return apply_filters( 'use_block_editor_for_post', $use_block_editor, $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8235 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8236 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8237 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8238 |
* Returns whether a post type is compatible with the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8239 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8240 |
* The block editor depends on the REST API, and if the post type is not shown in the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8241 |
* REST API, then it won't work with the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8242 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8243 |
* @since 5.0.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8244 |
* @since 6.1.0 Moved to wp-includes from wp-admin. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8245 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8246 |
* @param string $post_type The post type. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8247 |
* @return bool Whether the post type can be edited with the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8248 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8249 |
function use_block_editor_for_post_type( $post_type ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8250 |
if ( ! post_type_exists( $post_type ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8251 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8252 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8253 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8254 |
if ( ! post_type_supports( $post_type, 'editor' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8255 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8256 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8257 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8258 |
$post_type_object = get_post_type_object( $post_type ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8259 |
if ( $post_type_object && ! $post_type_object->show_in_rest ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8260 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8261 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8262 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8263 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8264 |
* Filters whether a post is able to be edited in the block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8265 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8266 |
* @since 5.0.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8267 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8268 |
* @param bool $use_block_editor Whether the post type can be edited or not. Default true. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8269 |
* @param string $post_type The post type being checked. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8270 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8271 |
return apply_filters( 'use_block_editor_for_post_type', true, $post_type ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8272 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8273 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8274 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8275 |
* Registers any additional post meta fields. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8276 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8277 |
* @since 6.3.0 Adds `wp_pattern_sync_status` meta field to the wp_block post type so an unsynced option can be added. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8278 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8279 |
* @link https://github.com/WordPress/gutenberg/pull/51144 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8280 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8281 |
function wp_create_initial_post_meta() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8282 |
register_post_meta( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8283 |
'wp_block', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8284 |
'wp_pattern_sync_status', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8285 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8286 |
'sanitize_callback' => 'sanitize_text_field', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8287 |
'single' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8288 |
'type' => 'string', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8289 |
'show_in_rest' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8290 |
'schema' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8291 |
'type' => 'string', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8292 |
'enum' => array( 'partial', 'unsynced' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8293 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8294 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8295 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8296 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8297 |
} |