Changeset 42343 for trunk/src/wp-includes/post.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r42228 r42343 19 19 */ 20 20 function create_initial_post_types() { 21 register_post_type( 'post', array( 22 'labels' => array( 23 'name_admin_bar' => _x( 'Post', 'add new from admin bar' ), 24 ), 25 'public' => true, 26 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 27 '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ 28 'capability_type' => 'post', 29 'map_meta_cap' => true, 30 'menu_position' => 5, 31 'hierarchical' => false, 32 'rewrite' => false, 33 'query_var' => false, 34 'delete_with_user' => true, 35 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ), 36 'show_in_rest' => true, 37 'rest_base' => 'posts', 38 'rest_controller_class' => 'WP_REST_Posts_Controller', 39 ) ); 40 41 register_post_type( 'page', array( 42 'labels' => array( 43 'name_admin_bar' => _x( 'Page', 'add new from admin bar' ), 44 ), 45 'public' => true, 46 'publicly_queryable' => false, 47 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 48 '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ 49 'capability_type' => 'page', 50 'map_meta_cap' => true, 51 'menu_position' => 20, 52 'hierarchical' => true, 53 'rewrite' => false, 54 'query_var' => false, 55 'delete_with_user' => true, 56 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ), 57 'show_in_rest' => true, 58 'rest_base' => 'pages', 59 'rest_controller_class' => 'WP_REST_Posts_Controller', 60 ) ); 61 62 register_post_type( 'attachment', array( 63 'labels' => array( 64 'name' => _x('Media', 'post type general name'), 65 'name_admin_bar' => _x( 'Media', 'add new from admin bar' ), 66 'add_new' => _x( 'Add New', 'add new media' ), 67 'edit_item' => __( 'Edit Media' ), 68 'view_item' => __( 'View Attachment Page' ), 69 'attributes' => __( 'Attachment Attributes' ), 70 ), 71 'public' => true, 72 'show_ui' => true, 73 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 74 '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ 75 'capability_type' => 'post', 76 'capabilities' => array( 77 'create_posts' => 'upload_files', 78 ), 79 'map_meta_cap' => true, 80 'hierarchical' => false, 81 'rewrite' => false, 82 'query_var' => false, 83 'show_in_nav_menus' => false, 84 'delete_with_user' => true, 85 'supports' => array( 'title', 'author', 'comments' ), 86 'show_in_rest' => true, 87 'rest_base' => 'media', 88 'rest_controller_class' => 'WP_REST_Attachments_Controller', 89 ) ); 21 register_post_type( 22 'post', array( 23 'labels' => array( 24 'name_admin_bar' => _x( 'Post', 'add new from admin bar' ), 25 ), 26 'public' => true, 27 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 28 '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ 29 'capability_type' => 'post', 30 'map_meta_cap' => true, 31 'menu_position' => 5, 32 'hierarchical' => false, 33 'rewrite' => false, 34 'query_var' => false, 35 'delete_with_user' => true, 36 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ), 37 'show_in_rest' => true, 38 'rest_base' => 'posts', 39 'rest_controller_class' => 'WP_REST_Posts_Controller', 40 ) 41 ); 42 43 register_post_type( 44 'page', array( 45 'labels' => array( 46 'name_admin_bar' => _x( 'Page', 'add new from admin bar' ), 47 ), 48 'public' => true, 49 'publicly_queryable' => false, 50 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 51 '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ 52 'capability_type' => 'page', 53 'map_meta_cap' => true, 54 'menu_position' => 20, 55 'hierarchical' => true, 56 'rewrite' => false, 57 'query_var' => false, 58 'delete_with_user' => true, 59 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ), 60 'show_in_rest' => true, 61 'rest_base' => 'pages', 62 'rest_controller_class' => 'WP_REST_Posts_Controller', 63 ) 64 ); 65 66 register_post_type( 67 'attachment', array( 68 'labels' => array( 69 'name' => _x( 'Media', 'post type general name' ), 70 'name_admin_bar' => _x( 'Media', 'add new from admin bar' ), 71 'add_new' => _x( 'Add New', 'add new media' ), 72 'edit_item' => __( 'Edit Media' ), 73 'view_item' => __( 'View Attachment Page' ), 74 'attributes' => __( 'Attachment Attributes' ), 75 ), 76 'public' => true, 77 'show_ui' => true, 78 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 79 '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ 80 'capability_type' => 'post', 81 'capabilities' => array( 82 'create_posts' => 'upload_files', 83 ), 84 'map_meta_cap' => true, 85 'hierarchical' => false, 86 'rewrite' => false, 87 'query_var' => false, 88 'show_in_nav_menus' => false, 89 'delete_with_user' => true, 90 'supports' => array( 'title', 'author', 'comments' ), 91 'show_in_rest' => true, 92 'rest_base' => 'media', 93 'rest_controller_class' => 'WP_REST_Attachments_Controller', 94 ) 95 ); 90 96 add_post_type_support( 'attachment:audio', 'thumbnail' ); 91 97 add_post_type_support( 'attachment:video', 'thumbnail' ); 92 98 93 register_post_type( 'revision', array( 94 'labels' => array( 95 'name' => __( 'Revisions' ), 96 'singular_name' => __( 'Revision' ), 97 ), 98 'public' => false, 99 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 100 '_edit_link' => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */ 101 'capability_type' => 'post', 102 'map_meta_cap' => true, 103 'hierarchical' => false, 104 'rewrite' => false, 105 'query_var' => false, 106 'can_export' => false, 107 'delete_with_user' => true, 108 'supports' => array( 'author' ), 109 ) ); 110 111 register_post_type( 'nav_menu_item', array( 112 'labels' => array( 113 'name' => __( 'Navigation Menu Items' ), 114 'singular_name' => __( 'Navigation Menu Item' ), 115 ), 116 'public' => false, 117 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 118 'hierarchical' => false, 119 'rewrite' => false, 120 'delete_with_user' => false, 121 'query_var' => false, 122 ) ); 123 124 register_post_type( 'custom_css', array( 125 'labels' => array( 126 'name' => __( 'Custom CSS' ), 127 'singular_name' => __( 'Custom CSS' ), 128 ), 129 'public' => false, 130 'hierarchical' => false, 131 'rewrite' => false, 132 'query_var' => false, 133 'delete_with_user' => false, 134 'can_export' => true, 135 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 136 'supports' => array( 'title', 'revisions' ), 137 'capabilities' => array( 138 'delete_posts' => 'edit_theme_options', 139 'delete_post' => 'edit_theme_options', 140 'delete_published_posts' => 'edit_theme_options', 141 'delete_private_posts' => 'edit_theme_options', 142 'delete_others_posts' => 'edit_theme_options', 143 'edit_post' => 'edit_css', 144 'edit_posts' => 'edit_css', 145 'edit_others_posts' => 'edit_css', 146 'edit_published_posts' => 'edit_css', 147 'read_post' => 'read', 148 'read_private_posts' => 'read', 149 'publish_posts' => 'edit_theme_options', 150 ), 151 ) ); 152 153 register_post_type( 'customize_changeset', array( 154 'labels' => array( 155 'name' => _x( 'Changesets', 'post type general name' ), 156 'singular_name' => _x( 'Changeset', 'post type singular name' ), 157 'menu_name' => _x( 'Changesets', 'admin menu' ), 158 'name_admin_bar' => _x( 'Changeset', 'add new on admin bar' ), 159 'add_new' => _x( 'Add New', 'Customize Changeset' ), 160 'add_new_item' => __( 'Add New Changeset' ), 161 'new_item' => __( 'New Changeset' ), 162 'edit_item' => __( 'Edit Changeset' ), 163 'view_item' => __( 'View Changeset' ), 164 'all_items' => __( 'All Changesets' ), 165 'search_items' => __( 'Search Changesets' ), 166 'not_found' => __( 'No changesets found.' ), 167 'not_found_in_trash' => __( 'No changesets found in Trash.' ), 168 ), 169 'public' => false, 170 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 171 'map_meta_cap' => true, 172 'hierarchical' => false, 173 'rewrite' => false, 174 'query_var' => false, 175 'can_export' => false, 176 'delete_with_user' => false, 177 'supports' => array( 'title', 'author' ), 178 'capability_type' => 'customize_changeset', 179 'capabilities' => array( 180 'create_posts' => 'customize', 181 'delete_others_posts' => 'customize', 182 'delete_post' => 'customize', 183 'delete_posts' => 'customize', 184 'delete_private_posts' => 'customize', 185 'delete_published_posts' => 'customize', 186 'edit_others_posts' => 'customize', 187 'edit_post' => 'customize', 188 'edit_posts' => 'customize', 189 'edit_private_posts' => 'customize', 190 'edit_published_posts' => 'do_not_allow', 191 'publish_posts' => 'customize', 192 'read' => 'read', 193 'read_post' => 'customize', 194 'read_private_posts' => 'customize', 195 ), 196 ) ); 197 198 register_post_type( 'oembed_cache', array( 199 'labels' => array( 200 'name' => __( 'oEmbed Responses' ), 201 'singular_name' => __( 'oEmbed Response' ), 202 ), 203 'public' => false, 204 'hierarchical' => false, 205 'rewrite' => false, 206 'query_var' => false, 207 'delete_with_user' => false, 208 'can_export' => false, 209 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 210 'supports' => array(), 211 ) ); 212 213 register_post_status( 'publish', array( 214 'label' => _x( 'Published', 'post status' ), 215 'public' => true, 216 '_builtin' => true, /* internal use only. */ 217 'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ), 218 ) ); 219 220 register_post_status( 'future', array( 221 'label' => _x( 'Scheduled', 'post status' ), 222 'protected' => true, 223 '_builtin' => true, /* internal use only. */ 224 'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' ), 225 ) ); 226 227 register_post_status( 'draft', array( 228 'label' => _x( 'Draft', 'post status' ), 229 'protected' => true, 230 '_builtin' => true, /* internal use only. */ 231 'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ), 232 ) ); 233 234 register_post_status( 'pending', array( 235 'label' => _x( 'Pending', 'post status' ), 236 'protected' => true, 237 '_builtin' => true, /* internal use only. */ 238 'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ), 239 ) ); 240 241 register_post_status( 'private', array( 242 'label' => _x( 'Private', 'post status' ), 243 'private' => true, 244 '_builtin' => true, /* internal use only. */ 245 'label_count' => _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' ), 246 ) ); 247 248 register_post_status( 'trash', array( 249 'label' => _x( 'Trash', 'post status' ), 250 'internal' => true, 251 '_builtin' => true, /* internal use only. */ 252 'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ), 253 'show_in_admin_status_list' => true, 254 ) ); 255 256 register_post_status( 'auto-draft', array( 257 'label' => 'auto-draft', 258 'internal' => true, 259 '_builtin' => true, /* internal use only. */ 260 ) ); 261 262 register_post_status( 'inherit', array( 263 'label' => 'inherit', 264 'internal' => true, 265 '_builtin' => true, /* internal use only. */ 266 'exclude_from_search' => false, 267 ) ); 99 register_post_type( 100 'revision', array( 101 'labels' => array( 102 'name' => __( 'Revisions' ), 103 'singular_name' => __( 'Revision' ), 104 ), 105 'public' => false, 106 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 107 '_edit_link' => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */ 108 'capability_type' => 'post', 109 'map_meta_cap' => true, 110 'hierarchical' => false, 111 'rewrite' => false, 112 'query_var' => false, 113 'can_export' => false, 114 'delete_with_user' => true, 115 'supports' => array( 'author' ), 116 ) 117 ); 118 119 register_post_type( 120 'nav_menu_item', array( 121 'labels' => array( 122 'name' => __( 'Navigation Menu Items' ), 123 'singular_name' => __( 'Navigation Menu Item' ), 124 ), 125 'public' => false, 126 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 127 'hierarchical' => false, 128 'rewrite' => false, 129 'delete_with_user' => false, 130 'query_var' => false, 131 ) 132 ); 133 134 register_post_type( 135 'custom_css', array( 136 'labels' => array( 137 'name' => __( 'Custom CSS' ), 138 'singular_name' => __( 'Custom CSS' ), 139 ), 140 'public' => false, 141 'hierarchical' => false, 142 'rewrite' => false, 143 'query_var' => false, 144 'delete_with_user' => false, 145 'can_export' => true, 146 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 147 'supports' => array( 'title', 'revisions' ), 148 'capabilities' => array( 149 'delete_posts' => 'edit_theme_options', 150 'delete_post' => 'edit_theme_options', 151 'delete_published_posts' => 'edit_theme_options', 152 'delete_private_posts' => 'edit_theme_options', 153 'delete_others_posts' => 'edit_theme_options', 154 'edit_post' => 'edit_css', 155 'edit_posts' => 'edit_css', 156 'edit_others_posts' => 'edit_css', 157 'edit_published_posts' => 'edit_css', 158 'read_post' => 'read', 159 'read_private_posts' => 'read', 160 'publish_posts' => 'edit_theme_options', 161 ), 162 ) 163 ); 164 165 register_post_type( 166 'customize_changeset', array( 167 'labels' => array( 168 'name' => _x( 'Changesets', 'post type general name' ), 169 'singular_name' => _x( 'Changeset', 'post type singular name' ), 170 'menu_name' => _x( 'Changesets', 'admin menu' ), 171 'name_admin_bar' => _x( 'Changeset', 'add new on admin bar' ), 172 'add_new' => _x( 'Add New', 'Customize Changeset' ), 173 'add_new_item' => __( 'Add New Changeset' ), 174 'new_item' => __( 'New Changeset' ), 175 'edit_item' => __( 'Edit Changeset' ), 176 'view_item' => __( 'View Changeset' ), 177 'all_items' => __( 'All Changesets' ), 178 'search_items' => __( 'Search Changesets' ), 179 'not_found' => __( 'No changesets found.' ), 180 'not_found_in_trash' => __( 'No changesets found in Trash.' ), 181 ), 182 'public' => false, 183 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 184 'map_meta_cap' => true, 185 'hierarchical' => false, 186 'rewrite' => false, 187 'query_var' => false, 188 'can_export' => false, 189 'delete_with_user' => false, 190 'supports' => array( 'title', 'author' ), 191 'capability_type' => 'customize_changeset', 192 'capabilities' => array( 193 'create_posts' => 'customize', 194 'delete_others_posts' => 'customize', 195 'delete_post' => 'customize', 196 'delete_posts' => 'customize', 197 'delete_private_posts' => 'customize', 198 'delete_published_posts' => 'customize', 199 'edit_others_posts' => 'customize', 200 'edit_post' => 'customize', 201 'edit_posts' => 'customize', 202 'edit_private_posts' => 'customize', 203 'edit_published_posts' => 'do_not_allow', 204 'publish_posts' => 'customize', 205 'read' => 'read', 206 'read_post' => 'customize', 207 'read_private_posts' => 'customize', 208 ), 209 ) 210 ); 211 212 register_post_type( 213 'oembed_cache', array( 214 'labels' => array( 215 'name' => __( 'oEmbed Responses' ), 216 'singular_name' => __( 'oEmbed Response' ), 217 ), 218 'public' => false, 219 'hierarchical' => false, 220 'rewrite' => false, 221 'query_var' => false, 222 'delete_with_user' => false, 223 'can_export' => false, 224 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 225 'supports' => array(), 226 ) 227 ); 228 229 register_post_status( 230 'publish', array( 231 'label' => _x( 'Published', 'post status' ), 232 'public' => true, 233 '_builtin' => true, /* internal use only. */ 234 'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ), 235 ) 236 ); 237 238 register_post_status( 239 'future', array( 240 'label' => _x( 'Scheduled', 'post status' ), 241 'protected' => true, 242 '_builtin' => true, /* internal use only. */ 243 'label_count' => _n_noop( 'Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' ), 244 ) 245 ); 246 247 register_post_status( 248 'draft', array( 249 'label' => _x( 'Draft', 'post status' ), 250 'protected' => true, 251 '_builtin' => true, /* internal use only. */ 252 'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ), 253 ) 254 ); 255 256 register_post_status( 257 'pending', array( 258 'label' => _x( 'Pending', 'post status' ), 259 'protected' => true, 260 '_builtin' => true, /* internal use only. */ 261 'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ), 262 ) 263 ); 264 265 register_post_status( 266 'private', array( 267 'label' => _x( 'Private', 'post status' ), 268 'private' => true, 269 '_builtin' => true, /* internal use only. */ 270 'label_count' => _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' ), 271 ) 272 ); 273 274 register_post_status( 275 'trash', array( 276 'label' => _x( 'Trash', 'post status' ), 277 'internal' => true, 278 '_builtin' => true, /* internal use only. */ 279 'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ), 280 'show_in_admin_status_list' => true, 281 ) 282 ); 283 284 register_post_status( 285 'auto-draft', array( 286 'label' => 'auto-draft', 287 'internal' => true, 288 '_builtin' => true, /* internal use only. */ 289 ) 290 ); 291 292 register_post_status( 293 'inherit', array( 294 'label' => 'inherit', 295 'internal' => true, 296 '_builtin' => true, /* internal use only. */ 297 'exclude_from_search' => false, 298 ) 299 ); 268 300 } 269 301 … … 322 354 */ 323 355 function update_attached_file( $attachment_id, $file ) { 324 if ( ! get_post( $attachment_id ) )356 if ( ! get_post( $attachment_id ) ) { 325 357 return false; 358 } 326 359 327 360 /** … … 335 368 $file = apply_filters( 'update_attached_file', $file, $attachment_id ); 336 369 337 if ( $file = _wp_relative_upload_path( $file ) ) 370 if ( $file = _wp_relative_upload_path( $file ) ) { 338 371 return update_post_meta( $attachment_id, '_wp_attached_file', $file ); 339 else372 } else { 340 373 return delete_post_meta( $attachment_id, '_wp_attached_file' ); 374 } 341 375 } 342 376 … … 426 460 if ( empty( $args ) ) { 427 461 if ( isset( $GLOBALS['post'] ) ) { 428 $args = array( 'post_parent' => (int) $GLOBALS['post']->post_parent );462 $args = array( 'post_parent' => (int) $GLOBALS['post']->post_parent ); 429 463 } else { 430 464 return $kids; 431 465 } 432 466 } elseif ( is_object( $args ) ) { 433 $args = array( 'post_parent' => (int) $args->post_parent );467 $args = array( 'post_parent' => (int) $args->post_parent ); 434 468 } elseif ( is_numeric( $args ) ) { 435 $args = array( 'post_parent' => (int) $args);469 $args = array( 'post_parent' => (int) $args ); 436 470 } 437 471 438 472 $defaults = array( 439 'numberposts' => -1, 'post_type' => 'any', 440 'post_status' => 'any', 'post_parent' => 0, 473 'numberposts' => -1, 474 'post_type' => 'any', 475 'post_status' => 'any', 476 'post_parent' => 0, 441 477 ); 442 478 … … 445 481 $children = get_posts( $r ); 446 482 447 if ( ! $children ) 483 if ( ! $children ) { 448 484 return $kids; 449 450 if ( ! empty( $r['fields'] ) ) 485 } 486 487 if ( ! empty( $r['fields'] ) ) { 451 488 return $children; 452 453 update_post_cache($children); 454 455 foreach ( $children as $key => $child ) 456 $kids[$child->ID] = $children[$key]; 489 } 490 491 update_post_cache( $children ); 492 493 foreach ( $children as $key => $child ) { 494 $kids[ $child->ID ] = $children[ $key ]; 495 } 457 496 458 497 if ( $output == OBJECT ) { … … 461 500 $weeuns = array(); 462 501 foreach ( (array) $kids as $kid ) { 463 $weeuns[ $kid->ID] = get_object_vars($kids[$kid->ID]);502 $weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] ); 464 503 } 465 504 return $weeuns; … … 467 506 $babes = array(); 468 507 foreach ( (array) $kids as $kid ) { 469 $babes[ $kid->ID] = array_values(get_object_vars($kids[$kid->ID]));508 $babes[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) ); 470 509 } 471 510 return $babes; … … 493 532 function get_extended( $post ) { 494 533 //Match the new style more links. 495 if ( preg_match( '/<!--more(.*?)?-->/', $post, $matches) ) {496 list($main, $extended) = explode( $matches[0], $post, 2);497 $more_text = $matches[1];534 if ( preg_match( '/<!--more(.*?)?-->/', $post, $matches ) ) { 535 list($main, $extended) = explode( $matches[0], $post, 2 ); 536 $more_text = $matches[1]; 498 537 } else { 499 $main = $post;500 $extended = '';538 $main = $post; 539 $extended = ''; 501 540 $more_text = ''; 502 541 } 503 542 504 543 // leading and trailing whitespace. 505 $main = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $main); 506 $extended = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $extended); 507 $more_text = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $more_text); 508 509 return array( 'main' => $main, 'extended' => $extended, 'more_text' => $more_text ); 544 $main = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $main ); 545 $extended = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $extended ); 546 $more_text = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $more_text ); 547 548 return array( 549 'main' => $main, 550 'extended' => $extended, 551 'more_text' => $more_text, 552 ); 510 553 } 511 554 … … 529 572 */ 530 573 function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { 531 if ( empty( $post ) && isset( $GLOBALS['post'] ) ) 574 if ( empty( $post ) && isset( $GLOBALS['post'] ) ) { 532 575 $post = $GLOBALS['post']; 576 } 533 577 534 578 if ( $post instanceof WP_Post ) { … … 547 591 } 548 592 549 if ( ! $_post ) 593 if ( ! $_post ) { 550 594 return null; 595 } 551 596 552 597 $_post = $_post->filter( $filter ); 553 598 554 if ( $output == ARRAY_A ) 599 if ( $output == ARRAY_A ) { 555 600 return $_post->to_array(); 556 elseif ( $output == ARRAY_N )601 } elseif ( $output == ARRAY_N ) { 557 602 return array_values( $_post->to_array() ); 603 } 558 604 559 605 return $_post; … … 571 617 $post = get_post( $post ); 572 618 573 if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) 619 if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) { 574 620 return array(); 621 } 575 622 576 623 $ancestors = array(); … … 580 627 while ( $ancestor = get_post( $id ) ) { 581 628 // Loop detection: If the ancestor has been seen before, break. 582 if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) 629 if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) { 583 630 break; 631 } 584 632 585 633 $id = $ancestors[] = $ancestor->post_parent; … … 612 660 $post = get_post( $post ); 613 661 614 if ( ! $post )662 if ( ! $post ) { 615 663 return ''; 616 617 if ( !isset($post->$field) ) 664 } 665 666 if ( ! isset( $post->$field ) ) { 618 667 return ''; 619 620 return sanitize_post_field($field, $post->$field, $post->ID, $context); 668 } 669 670 return sanitize_post_field( $field, $post->$field, $post->ID, $context ); 621 671 } 622 672 … … 633 683 */ 634 684 function get_post_mime_type( $ID = '' ) { 635 $post = get_post( $ID);636 637 if ( is_object( $post) )685 $post = get_post( $ID ); 686 687 if ( is_object( $post ) ) { 638 688 return $post->post_mime_type; 689 } 639 690 640 691 return false; … … 653 704 */ 654 705 function get_post_status( $ID = '' ) { 655 $post = get_post( $ID);656 657 if ( ! is_object($post) )706 $post = get_post( $ID ); 707 708 if ( ! is_object( $post ) ) { 658 709 return false; 710 } 659 711 660 712 if ( 'attachment' == $post->post_type ) { 661 if ( 'private' == $post->post_status ) 713 if ( 'private' == $post->post_status ) { 662 714 return 'private'; 715 } 663 716 664 717 // Unattached attachments are assumed to be published. 665 if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent ) )718 if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent ) ) { 666 719 return 'publish'; 720 } 667 721 668 722 // Inherit status from the parent. … … 675 729 } 676 730 } 677 678 731 } 679 732 … … 704 757 'pending' => __( 'Pending Review' ), 705 758 'private' => __( 'Private' ), 706 'publish' => __( 'Published' ) 759 'publish' => __( 'Published' ), 707 760 ); 708 761 … … 724 777 'draft' => __( 'Draft' ), 725 778 'private' => __( 'Private' ), 726 'publish' => __( 'Published' ) 779 'publish' => __( 'Published' ), 727 780 ); 728 781 … … 776 829 global $wp_post_statuses; 777 830 778 if ( !is_array($wp_post_statuses))831 if ( ! is_array( $wp_post_statuses ) ) { 779 832 $wp_post_statuses = array(); 833 } 780 834 781 835 // Args prefixed with an underscore are reserved for internal use. 782 836 $defaults = array( 783 'label' => false,784 'label_count' => false,785 'exclude_from_search' => null,786 '_builtin' => false,787 'public' => null,788 'internal' => null,789 'protected' => null,790 'private' => null,791 'publicly_queryable' => null,837 'label' => false, 838 'label_count' => false, 839 'exclude_from_search' => null, 840 '_builtin' => false, 841 'public' => null, 842 'internal' => null, 843 'protected' => null, 844 'private' => null, 845 'publicly_queryable' => null, 792 846 'show_in_admin_status_list' => null, 793 'show_in_admin_all_list' => null,847 'show_in_admin_all_list' => null, 794 848 ); 795 $args = wp_parse_args($args, $defaults);796 $args = (object) $args;797 798 $post_status = sanitize_key( $post_status);799 $args->name = $post_status;849 $args = wp_parse_args( $args, $defaults ); 850 $args = (object) $args; 851 852 $post_status = sanitize_key( $post_status ); 853 $args->name = $post_status; 800 854 801 855 // Set various defaults. 802 if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) 856 if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) { 803 857 $args->internal = true; 804 805 if ( null === $args->public ) 858 } 859 860 if ( null === $args->public ) { 806 861 $args->public = false; 807 808 if ( null === $args->private ) 862 } 863 864 if ( null === $args->private ) { 809 865 $args->private = false; 810 811 if ( null === $args->protected ) 866 } 867 868 if ( null === $args->protected ) { 812 869 $args->protected = false; 813 814 if ( null === $args->internal ) 870 } 871 872 if ( null === $args->internal ) { 815 873 $args->internal = false; 816 817 if ( null === $args->publicly_queryable ) 874 } 875 876 if ( null === $args->publicly_queryable ) { 818 877 $args->publicly_queryable = $args->public; 819 820 if ( null === $args->exclude_from_search ) 878 } 879 880 if ( null === $args->exclude_from_search ) { 821 881 $args->exclude_from_search = $args->internal; 822 823 if ( null === $args->show_in_admin_all_list ) 824 $args->show_in_admin_all_list = !$args->internal; 825 826 if ( null === $args->show_in_admin_status_list ) 827 $args->show_in_admin_status_list = !$args->internal; 828 829 if ( false === $args->label ) 882 } 883 884 if ( null === $args->show_in_admin_all_list ) { 885 $args->show_in_admin_all_list = ! $args->internal; 886 } 887 888 if ( null === $args->show_in_admin_status_list ) { 889 $args->show_in_admin_status_list = ! $args->internal; 890 } 891 892 if ( false === $args->label ) { 830 893 $args->label = $post_status; 831 832 if ( false === $args->label_count ) 894 } 895 896 if ( false === $args->label_count ) { 833 897 $args->label_count = _n_noop( $args->label, $args->label ); 834 835 $wp_post_statuses[$post_status] = $args; 898 } 899 900 $wp_post_statuses[ $post_status ] = $args; 836 901 837 902 return $args; … … 853 918 global $wp_post_statuses; 854 919 855 if ( empty( $wp_post_statuses[$post_status]) )920 if ( empty( $wp_post_statuses[ $post_status ] ) ) { 856 921 return null; 857 858 return $wp_post_statuses[$post_status]; 922 } 923 924 return $wp_post_statuses[ $post_status ]; 859 925 } 860 926 … … 879 945 global $wp_post_statuses; 880 946 881 $field = ( 'names' == $output) ? 'name' : false;882 883 return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field);947 $field = ( 'names' == $output ) ? 'name' : false; 948 949 return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field ); 884 950 } 885 951 … … 897 963 */ 898 964 function is_post_type_hierarchical( $post_type ) { 899 if ( ! post_type_exists( $post_type ) ) 965 if ( ! post_type_exists( $post_type ) ) { 900 966 return false; 967 } 901 968 902 969 $post_type = get_post_type_object( $post_type ); … … 927 994 */ 928 995 function get_post_type( $post = null ) { 929 if ( $post = get_post( $post ) ) 996 if ( $post = get_post( $post ) ) { 930 997 return $post->post_type; 998 } 931 999 932 1000 return false; … … 977 1045 global $wp_post_types; 978 1046 979 $field = ( 'names' == $output) ? 'name' : false;980 981 return wp_filter_object_list( $wp_post_types, $args, $operator, $field);1047 $field = ( 'names' == $output ) ? 'name' : false; 1048 1049 return wp_filter_object_list( $wp_post_types, $args, $operator, $field ); 982 1050 } 983 1051 … … 1259 1327 */ 1260 1328 function get_post_type_capabilities( $args ) { 1261 if ( ! is_array( $args->capability_type ) ) 1329 if ( ! is_array( $args->capability_type ) ) { 1262 1330 $args->capability_type = array( $args->capability_type, $args->capability_type . 's' ); 1331 } 1263 1332 1264 1333 // Singular base for meta capabilities, plural base for primitive capabilities. … … 1267 1336 $default_capabilities = array( 1268 1337 // Meta capabilities 1269 'edit_post' => 'edit_' 1270 'read_post' => 'read_' 1271 'delete_post' => 'delete_' 1338 'edit_post' => 'edit_' . $singular_base, 1339 'read_post' => 'read_' . $singular_base, 1340 'delete_post' => 'delete_' . $singular_base, 1272 1341 // Primitive capabilities used outside of map_meta_cap(): 1273 'edit_posts' => 'edit_' 1274 'edit_others_posts' => 'edit_others_' 1275 'publish_posts' => 'publish_' 1342 'edit_posts' => 'edit_' . $plural_base, 1343 'edit_others_posts' => 'edit_others_' . $plural_base, 1344 'publish_posts' => 'publish_' . $plural_base, 1276 1345 'read_private_posts' => 'read_private_' . $plural_base, 1277 1346 ); … … 1281 1350 $default_capabilities_for_mapping = array( 1282 1351 'read' => 'read', 1283 'delete_posts' => 'delete_' 1284 'delete_private_posts' => 'delete_private_' 1352 'delete_posts' => 'delete_' . $plural_base, 1353 'delete_private_posts' => 'delete_private_' . $plural_base, 1285 1354 'delete_published_posts' => 'delete_published_' . $plural_base, 1286 'delete_others_posts' => 'delete_others_' 1287 'edit_private_posts' => 'edit_private_' 1288 'edit_published_posts' => 'edit_published_' 1355 'delete_others_posts' => 'delete_others_' . $plural_base, 1356 'edit_private_posts' => 'edit_private_' . $plural_base, 1357 'edit_published_posts' => 'edit_published_' . $plural_base, 1289 1358 ); 1290 $default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping );1359 $default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping ); 1291 1360 } 1292 1361 … … 1294 1363 1295 1364 // Post creation capability simply maps to edit_posts by default: 1296 if ( ! isset( $capabilities['create_posts'] ) ) 1365 if ( ! isset( $capabilities['create_posts'] ) ) { 1297 1366 $capabilities['create_posts'] = $capabilities['edit_posts']; 1367 } 1298 1368 1299 1369 // Remember meta capabilities for future reference. 1300 if ( $args->map_meta_cap ) 1370 if ( $args->map_meta_cap ) { 1301 1371 _post_type_meta_capabilities( $capabilities ); 1372 } 1302 1373 1303 1374 return (object) $capabilities; … … 1382 1453 */ 1383 1454 function get_post_type_labels( $post_type_object ) { 1384 $nohier_vs_hier_defaults = array(1385 'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ),1386 'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ),1387 'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ),1388 'add_new_item' => array( __('Add New Post'), __('Add New Page') ),1389 'edit_item' => array( __('Edit Post'), __('Edit Page') ),1390 'new_item' => array( __('New Post'), __('New Page') ),1391 'view_item' => array( __('View Post'), __('View Page') ),1392 'view_items' => array( __('View Posts'), __('View Pages') ),1393 'search_items' => array( __('Search Posts'), __('Search Pages') ),1394 'not_found' => array( __('No posts found.'), __('No pages found.') ),1395 'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ),1396 'parent_item_colon' => array( null, __('Parent Page:') ),1397 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ),1398 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ),1399 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),1400 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ),1455 $nohier_vs_hier_defaults = array( 1456 'name' => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ), 1457 'singular_name' => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ), 1458 'add_new' => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ), 1459 'add_new_item' => array( __( 'Add New Post' ), __( 'Add New Page' ) ), 1460 'edit_item' => array( __( 'Edit Post' ), __( 'Edit Page' ) ), 1461 'new_item' => array( __( 'New Post' ), __( 'New Page' ) ), 1462 'view_item' => array( __( 'View Post' ), __( 'View Page' ) ), 1463 'view_items' => array( __( 'View Posts' ), __( 'View Pages' ) ), 1464 'search_items' => array( __( 'Search Posts' ), __( 'Search Pages' ) ), 1465 'not_found' => array( __( 'No posts found.' ), __( 'No pages found.' ) ), 1466 'not_found_in_trash' => array( __( 'No posts found in Trash.' ), __( 'No pages found in Trash.' ) ), 1467 'parent_item_colon' => array( null, __( 'Parent Page:' ) ), 1468 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), 1469 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ), 1470 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ), 1471 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ), 1401 1472 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ), 1402 'featured_image' => array( _x( 'Featured Image', 'post' ), _x( 'Featured Image', 'page' ) ),1403 'set_featured_image' => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ),1473 'featured_image' => array( _x( 'Featured Image', 'post' ), _x( 'Featured Image', 'page' ) ), 1474 'set_featured_image' => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ), 1404 1475 'remove_featured_image' => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ), 1405 'use_featured_image' => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ),1406 'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),1476 'use_featured_image' => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ), 1477 'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ), 1407 1478 'items_list_navigation' => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ), 1408 'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ),1479 'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ), 1409 1480 ); 1410 1481 $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; … … 1450 1521 $object->labels = (array) $object->labels; 1451 1522 1452 if ( isset( $object->label ) && empty( $object->labels['name'] ) ) 1523 if ( isset( $object->label ) && empty( $object->labels['name'] ) ) { 1453 1524 $object->labels['name'] = $object->label; 1454 1455 if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) 1525 } 1526 1527 if ( ! isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) { 1456 1528 $object->labels['singular_name'] = $object->labels['name']; 1457 1458 if ( ! isset( $object->labels['name_admin_bar'] ) ) 1529 } 1530 1531 if ( ! isset( $object->labels['name_admin_bar'] ) ) { 1459 1532 $object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name; 1460 1461 if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) 1533 } 1534 1535 if ( ! isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) { 1462 1536 $object->labels['menu_name'] = $object->labels['name']; 1463 1464 if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) 1537 } 1538 1539 if ( ! isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) { 1465 1540 $object->labels['all_items'] = $object->labels['menu_name']; 1466 1467 if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) { 1541 } 1542 1543 if ( ! isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) { 1468 1544 $object->labels['archives'] = $object->labels['all_items']; 1469 1545 } … … 1471 1547 $defaults = array(); 1472 1548 foreach ( $nohier_vs_hier_defaults as $key => $value ) { 1473 $defaults[ $key] = $object->hierarchical ? $value[1] : $value[0];1474 } 1475 $labels = array_merge( $defaults, $object->labels );1549 $defaults[ $key ] = $object->hierarchical ? $value[1] : $value[0]; 1550 } 1551 $labels = array_merge( $defaults, $object->labels ); 1476 1552 $object->labels = (object) $object->labels; 1477 1553 … … 1489 1565 $ptype_obj = get_post_type_object( $ptype ); 1490 1566 // Sub-menus only. 1491 if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) 1567 if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) { 1492 1568 continue; 1569 } 1493 1570 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" ); 1494 1571 } … … 1519 1596 1520 1597 $features = (array) $feature; 1521 foreach ($features as $feature) { 1522 if ( func_num_args() == 2 ) 1523 $_wp_post_type_features[$post_type][$feature] = true; 1524 else 1525 $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 ); 1598 foreach ( $features as $feature ) { 1599 if ( func_num_args() == 2 ) { 1600 $_wp_post_type_features[ $post_type ][ $feature ] = true; 1601 } else { 1602 $_wp_post_type_features[ $post_type ][ $feature ] = array_slice( func_get_args(), 2 ); 1603 } 1526 1604 } 1527 1605 } … … 1556 1634 global $_wp_post_type_features; 1557 1635 1558 if ( isset( $_wp_post_type_features[$post_type] ) ) 1559 return $_wp_post_type_features[$post_type]; 1636 if ( isset( $_wp_post_type_features[ $post_type ] ) ) { 1637 return $_wp_post_type_features[ $post_type ]; 1638 } 1560 1639 1561 1640 return array(); … … 1576 1655 global $_wp_post_type_features; 1577 1656 1578 return ( isset( $_wp_post_type_features[ $post_type][$feature] ) );1657 return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) ); 1579 1658 } 1580 1659 … … 1618 1697 global $wpdb; 1619 1698 1620 $post_type = sanitize_post_field( 'post_type', $post_type, $post_id, 'db');1621 $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );1699 $post_type = sanitize_post_field( 'post_type', $post_type, $post_id, 'db' ); 1700 $return = $wpdb->update( $wpdb->posts, array( 'post_type' => $post_type ), array( 'ID' => $post_id ) ); 1622 1701 1623 1702 clean_post_cache( $post_id ); … … 1676 1755 function get_posts( $args = null ) { 1677 1756 $defaults = array( 1678 'numberposts' => 5, 1679 'category' => 0, 'orderby' => 'date', 1680 'order' => 'DESC', 'include' => array(), 1681 'exclude' => array(), 'meta_key' => '', 1682 'meta_value' =>'', 'post_type' => 'post', 1683 'suppress_filters' => true 1757 'numberposts' => 5, 1758 'category' => 0, 1759 'orderby' => 'date', 1760 'order' => 'DESC', 1761 'include' => array(), 1762 'exclude' => array(), 1763 'meta_key' => '', 1764 'meta_value' => '', 1765 'post_type' => 'post', 1766 'suppress_filters' => true, 1684 1767 ); 1685 1768 1686 1769 $r = wp_parse_args( $args, $defaults ); 1687 if ( empty( $r['post_status'] ) ) 1770 if ( empty( $r['post_status'] ) ) { 1688 1771 $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish'; 1689 if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) ) 1772 } 1773 if ( ! empty( $r['numberposts'] ) && empty( $r['posts_per_page'] ) ) { 1690 1774 $r['posts_per_page'] = $r['numberposts']; 1691 if ( ! empty($r['category']) ) 1775 } 1776 if ( ! empty( $r['category'] ) ) { 1692 1777 $r['cat'] = $r['category']; 1693 if ( ! empty($r['include']) ) { 1694 $incposts = wp_parse_id_list( $r['include'] ); 1695 $r['posts_per_page'] = count($incposts); // only the number of posts included 1696 $r['post__in'] = $incposts; 1697 } elseif ( ! empty($r['exclude']) ) 1778 } 1779 if ( ! empty( $r['include'] ) ) { 1780 $incposts = wp_parse_id_list( $r['include'] ); 1781 $r['posts_per_page'] = count( $incposts ); // only the number of posts included 1782 $r['post__in'] = $incposts; 1783 } elseif ( ! empty( $r['exclude'] ) ) { 1698 1784 $r['post__not_in'] = wp_parse_id_list( $r['exclude'] ); 1785 } 1699 1786 1700 1787 $r['ignore_sticky_posts'] = true; 1701 $r['no_found_rows'] = true;1788 $r['no_found_rows'] = true; 1702 1789 1703 1790 $get_posts = new WP_Query; 1704 return $get_posts->query( $r);1791 return $get_posts->query( $r ); 1705 1792 1706 1793 } … … 1726 1813 function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { 1727 1814 // Make sure meta is added to the post, not a revision. 1728 if ( $the_post = wp_is_post_revision( $post_id) )1815 if ( $the_post = wp_is_post_revision( $post_id ) ) { 1729 1816 $post_id = $the_post; 1817 } 1730 1818 1731 1819 $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); … … 1753 1841 function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { 1754 1842 // Make sure meta is added to the post, not a revision. 1755 if ( $the_post = wp_is_post_revision( $post_id) )1843 if ( $the_post = wp_is_post_revision( $post_id ) ) { 1756 1844 $post_id = $the_post; 1845 } 1757 1846 1758 1847 $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value ); … … 1778 1867 */ 1779 1868 function get_post_meta( $post_id, $key = '', $single = false ) { 1780 return get_metadata( 'post', $post_id, $key, $single);1869 return get_metadata( 'post', $post_id, $key, $single ); 1781 1870 } 1782 1871 … … 1801 1890 function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) { 1802 1891 // Make sure meta is added to the post, not a revision. 1803 if ( $the_post = wp_is_post_revision( $post_id) )1892 if ( $the_post = wp_is_post_revision( $post_id ) ) { 1804 1893 $post_id = $the_post; 1894 } 1805 1895 1806 1896 $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); … … 1840 1930 function get_post_custom( $post_id = 0 ) { 1841 1931 $post_id = absint( $post_id ); 1842 if ( ! $post_id ) 1932 if ( ! $post_id ) { 1843 1933 $post_id = get_the_ID(); 1934 } 1844 1935 1845 1936 return get_post_meta( $post_id ); … … 1859 1950 $custom = get_post_custom( $post_id ); 1860 1951 1861 if ( ! is_array($custom) )1952 if ( ! is_array( $custom ) ) { 1862 1953 return; 1863 1864 if ( $keys = array_keys($custom) ) 1954 } 1955 1956 if ( $keys = array_keys( $custom ) ) { 1865 1957 return $keys; 1958 } 1866 1959 } 1867 1960 … … 1879 1972 */ 1880 1973 function get_post_custom_values( $key = '', $post_id = 0 ) { 1881 if ( ! $key )1974 if ( ! $key ) { 1882 1975 return null; 1883 1884 $custom = get_post_custom($post_id); 1885 1886 return isset($custom[$key]) ? $custom[$key] : null; 1976 } 1977 1978 $custom = get_post_custom( $post_id ); 1979 1980 return isset( $custom[ $key ] ) ? $custom[ $key ] : null; 1887 1981 } 1888 1982 … … 1901 1995 $post_id = absint( $post_id ); 1902 1996 1903 if ( ! $post_id ) 1997 if ( ! $post_id ) { 1904 1998 $post_id = get_the_ID(); 1999 } 1905 2000 1906 2001 $stickies = get_option( 'sticky_posts' ); 1907 2002 1908 if ( ! is_array( $stickies ) ) 2003 if ( ! is_array( $stickies ) ) { 1909 2004 return false; 1910 1911 if ( in_array( $post_id, $stickies ) ) 2005 } 2006 2007 if ( in_array( $post_id, $stickies ) ) { 1912 2008 return true; 2009 } 1913 2010 1914 2011 return false; … … 1933 2030 */ 1934 2031 function sanitize_post( $post, $context = 'display' ) { 1935 if ( is_object( $post) ) {2032 if ( is_object( $post ) ) { 1936 2033 // Check if post already filtered for this context. 1937 if ( isset( $post->filter) && $context == $post->filter )2034 if ( isset( $post->filter ) && $context == $post->filter ) { 1938 2035 return $post; 1939 if ( !isset($post->ID) ) 2036 } 2037 if ( ! isset( $post->ID ) ) { 1940 2038 $post->ID = 0; 1941 foreach ( array_keys(get_object_vars($post)) as $field ) 1942 $post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context); 2039 } 2040 foreach ( array_keys( get_object_vars( $post ) ) as $field ) { 2041 $post->$field = sanitize_post_field( $field, $post->$field, $post->ID, $context ); 2042 } 1943 2043 $post->filter = $context; 1944 2044 } elseif ( is_array( $post ) ) { 1945 2045 // Check if post already filtered for this context. 1946 if ( isset( $post['filter']) && $context == $post['filter'] )2046 if ( isset( $post['filter'] ) && $context == $post['filter'] ) { 1947 2047 return $post; 1948 if ( !isset($post['ID']) ) 2048 } 2049 if ( ! isset( $post['ID'] ) ) { 1949 2050 $post['ID'] = 0; 1950 foreach ( array_keys($post) as $field ) 1951 $post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context); 2051 } 2052 foreach ( array_keys( $post ) as $field ) { 2053 $post[ $field ] = sanitize_post_field( $field, $post[ $field ], $post['ID'], $context ); 2054 } 1952 2055 $post['filter'] = $context; 1953 2056 } … … 1973 2076 */ 1974 2077 function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { 1975 $int_fields = array( 'ID', 'post_parent', 'menu_order');1976 if ( in_array( $field, $int_fields) )2078 $int_fields = array( 'ID', 'post_parent', 'menu_order' ); 2079 if ( in_array( $field, $int_fields ) ) { 1977 2080 $value = (int) $value; 2081 } 1978 2082 1979 2083 // Fields which contain arrays of integers. 1980 2084 $array_int_fields = array( 'ancestors' ); 1981 if ( in_array( $field, $array_int_fields) ) {1982 $value = array_map( 'absint', $value );2085 if ( in_array( $field, $array_int_fields ) ) { 2086 $value = array_map( 'absint', $value ); 1983 2087 return $value; 1984 2088 } 1985 2089 1986 if ( 'raw' == $context ) 2090 if ( 'raw' == $context ) { 1987 2091 return $value; 2092 } 1988 2093 1989 2094 $prefixed = false; 1990 if ( false !== strpos( $field, 'post_') ) {1991 $prefixed = true;1992 $field_no_prefix = str_replace( 'post_', '', $field);2095 if ( false !== strpos( $field, 'post_' ) ) { 2096 $prefixed = true; 2097 $field_no_prefix = str_replace( 'post_', '', $field ); 1993 2098 } 1994 2099 1995 2100 if ( 'edit' == $context ) { 1996 $format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password');2101 $format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password' ); 1997 2102 1998 2103 if ( $prefixed ) { … … 2027 2132 } 2028 2133 2029 if ( in_array($field, $format_to_edit) ) { 2030 if ( 'post_content' == $field ) 2031 $value = format_to_edit($value, user_can_richedit()); 2032 else 2033 $value = format_to_edit($value); 2134 if ( in_array( $field, $format_to_edit ) ) { 2135 if ( 'post_content' == $field ) { 2136 $value = format_to_edit( $value, user_can_richedit() ); 2137 } else { 2138 $value = format_to_edit( $value ); 2139 } 2034 2140 } else { 2035 $value = esc_attr( $value);2141 $value = esc_attr( $value ); 2036 2142 } 2037 2143 } elseif ( 'db' == $context ) { … … 2120 2226 */ 2121 2227 function stick_post( $post_id ) { 2122 $stickies = get_option('sticky_posts'); 2123 2124 if ( !is_array($stickies) ) 2125 $stickies = array($post_id); 2126 2127 if ( ! in_array($post_id, $stickies) ) 2228 $stickies = get_option( 'sticky_posts' ); 2229 2230 if ( ! is_array( $stickies ) ) { 2231 $stickies = array( $post_id ); 2232 } 2233 2234 if ( ! in_array( $post_id, $stickies ) ) { 2128 2235 $stickies[] = $post_id; 2236 } 2129 2237 2130 2238 $updated = update_option( 'sticky_posts', $stickies ); … … 2152 2260 */ 2153 2261 function unstick_post( $post_id ) { 2154 $stickies = get_option( 'sticky_posts');2155 2156 if ( ! is_array($stickies) )2262 $stickies = get_option( 'sticky_posts' ); 2263 2264 if ( ! is_array( $stickies ) ) { 2157 2265 return; 2158 2159 if ( ! in_array($post_id, $stickies) ) 2266 } 2267 2268 if ( ! in_array( $post_id, $stickies ) ) { 2160 2269 return; 2161 2162 $offset = array_search($post_id, $stickies); 2163 if ( false === $offset ) 2270 } 2271 2272 $offset = array_search( $post_id, $stickies ); 2273 if ( false === $offset ) { 2164 2274 return; 2165 2166 array_splice($stickies, $offset, 1); 2275 } 2276 2277 array_splice( $stickies, $offset, 1 ); 2167 2278 2168 2279 $updated = update_option( 'sticky_posts', $stickies ); … … 2222 2333 global $wpdb; 2223 2334 2224 if ( ! post_type_exists( $type ) ) 2335 if ( ! post_type_exists( $type ) ) { 2225 2336 return new stdClass; 2337 } 2226 2338 2227 2339 $cache_key = _count_posts_cache_key( $type, $perm ); … … 2235 2347 $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; 2236 2348 if ( 'readable' == $perm && is_user_logged_in() ) { 2237 $post_type_object = get_post_type_object( $type);2349 $post_type_object = get_post_type_object( $type ); 2238 2350 if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) { 2239 $query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", 2351 $query .= $wpdb->prepare( 2352 " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", 2240 2353 get_current_user_id() 2241 2354 ); … … 2245 2358 2246 2359 $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); 2247 $counts = array_fill_keys( get_post_stati(), 0 );2360 $counts = array_fill_keys( get_post_stati(), 0 ); 2248 2361 2249 2362 foreach ( $results as $row ) { … … 2287 2400 global $wpdb; 2288 2401 2289 $and = wp_post_mime_type_where( $mime_type );2402 $and = wp_post_mime_type_where( $mime_type ); 2290 2403 $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 ); 2291 2404 … … 2294 2407 $counts[ $row['post_mime_type'] ] = $row['num_posts']; 2295 2408 } 2296 $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and" );2409 $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and" ); 2297 2410 2298 2411 /** … … 2317 2430 */ 2318 2431 function get_post_mime_types() { 2319 $post_mime_types = array( 2320 'image' => array( __('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),2321 'audio' => array( __('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),2322 'video' => array( __('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),2432 $post_mime_types = array( // array( adj, noun ) 2433 'image' => array( __( 'Images' ), __( 'Manage Images' ), _n_noop( 'Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>' ) ), 2434 'audio' => array( __( 'Audio' ), __( 'Manage Audio' ), _n_noop( 'Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>' ) ), 2435 'video' => array( __( 'Video' ), __( 'Manage Video' ), _n_noop( 'Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>' ) ), 2323 2436 ); 2324 2437 … … 2357 2470 2358 2471 $patternses = array(); 2359 $wild = '[-._a-z0-9]*';2472 $wild = '[-._a-z0-9]*'; 2360 2473 2361 2474 foreach ( (array) $wildcard_mime_types as $type ) { 2362 2475 $mimes = array_map( 'trim', explode( ',', $type ) ); 2363 2476 foreach ( $mimes as $mime ) { 2364 $regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );2365 $patternses[][ $type] = "^$regex$";2477 $regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) ); 2478 $patternses[][ $type ] = "^$regex$"; 2366 2479 if ( false === strpos( $mime, '/' ) ) { 2367 $patternses[][ $type] = "^$regex/";2368 $patternses[][ $type] = $regex;2480 $patternses[][ $type ] = "^$regex/"; 2481 $patternses[][ $type ] = $regex; 2369 2482 } 2370 2483 } … … 2375 2488 foreach ( $patterns as $type => $pattern ) { 2376 2489 foreach ( (array) $real_mime_types as $real ) { 2377 if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[ $type] ) || false === array_search( $real, $matches[$type] ) ) ) {2378 $matches[ $type][] = $real;2490 if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ] ) ) ) { 2491 $matches[ $type ][] = $real; 2379 2492 } 2380 2493 } … … 2396 2509 */ 2397 2510 function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { 2398 $where = ''; 2399 $wildcards = array('', '%', '%/%'); 2400 if ( is_string($post_mime_types) ) 2401 $post_mime_types = array_map('trim', explode(',', $post_mime_types)); 2511 $where = ''; 2512 $wildcards = array( '', '%', '%/%' ); 2513 if ( is_string( $post_mime_types ) ) { 2514 $post_mime_types = array_map( 'trim', explode( ',', $post_mime_types ) ); 2515 } 2402 2516 2403 2517 $wheres = array(); 2404 2518 2405 2519 foreach ( (array) $post_mime_types as $mime_type ) { 2406 $mime_type = preg_replace( '/\s/', '', $mime_type);2407 $slashpos = strpos($mime_type, '/');2520 $mime_type = preg_replace( '/\s/', '', $mime_type ); 2521 $slashpos = strpos( $mime_type, '/' ); 2408 2522 if ( false !== $slashpos ) { 2409 $mime_group = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, 0, $slashpos));2410 $mime_subgroup = preg_replace( '/[^-*.+a-zA-Z0-9]/', '', substr($mime_type, $slashpos + 1));2411 if ( empty( $mime_subgroup) )2523 $mime_group = preg_replace( '/[^-*.a-zA-Z0-9]/', '', substr( $mime_type, 0, $slashpos ) ); 2524 $mime_subgroup = preg_replace( '/[^-*.+a-zA-Z0-9]/', '', substr( $mime_type, $slashpos + 1 ) ); 2525 if ( empty( $mime_subgroup ) ) { 2412 2526 $mime_subgroup = '*'; 2413 else 2414 $mime_subgroup = str_replace('/', '', $mime_subgroup); 2527 } else { 2528 $mime_subgroup = str_replace( '/', '', $mime_subgroup ); 2529 } 2415 2530 $mime_pattern = "$mime_group/$mime_subgroup"; 2416 2531 } else { 2417 $mime_pattern = preg_replace( '/[^-*.a-zA-Z0-9]/', '', $mime_type);2418 if ( false === strpos( $mime_pattern, '*') )2532 $mime_pattern = preg_replace( '/[^-*.a-zA-Z0-9]/', '', $mime_type ); 2533 if ( false === strpos( $mime_pattern, '*' ) ) { 2419 2534 $mime_pattern .= '/*'; 2420 } 2421 2422 $mime_pattern = preg_replace('/\*+/', '%', $mime_pattern); 2423 2424 if ( in_array( $mime_type, $wildcards ) ) 2535 } 2536 } 2537 2538 $mime_pattern = preg_replace( '/\*+/', '%', $mime_pattern ); 2539 2540 if ( in_array( $mime_type, $wildcards ) ) { 2425 2541 return ''; 2426 2427 if ( false !== strpos($mime_pattern, '%') ) 2428 $wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; 2429 else 2430 $wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; 2431 } 2432 if ( !empty($wheres) ) 2433 $where = ' AND (' . join(' OR ', $wheres) . ') '; 2542 } 2543 2544 if ( false !== strpos( $mime_pattern, '%' ) ) { 2545 $wheres[] = empty( $table_alias ) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; 2546 } else { 2547 $wheres[] = empty( $table_alias ) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; 2548 } 2549 } 2550 if ( ! empty( $wheres ) ) { 2551 $where = ' AND (' . join( ' OR ', $wheres ) . ') '; 2552 } 2434 2553 return $where; 2435 2554 } … … 2500 2619 do_action( 'before_delete_post', $postid ); 2501 2620 2502 delete_post_meta( $postid,'_wp_trash_meta_status');2503 delete_post_meta( $postid,'_wp_trash_meta_time');2504 2505 wp_delete_object_term_relationships( $postid, get_object_taxonomies($post->post_type));2506 2507 $parent_data = array( 'post_parent' => $post->post_parent );2621 delete_post_meta( $postid, '_wp_trash_meta_status' ); 2622 delete_post_meta( $postid, '_wp_trash_meta_time' ); 2623 2624 wp_delete_object_term_relationships( $postid, get_object_taxonomies( $post->post_type ) ); 2625 2626 $parent_data = array( 'post_parent' => $post->post_parent ); 2508 2627 $parent_where = array( 'post_parent' => $postid ); 2509 2628 … … 2511 2630 // Point children of this page to its parent, also clean the cache of affected children. 2512 2631 $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type ); 2513 $children = $wpdb->get_results( $children_query );2632 $children = $wpdb->get_results( $children_query ); 2514 2633 if ( $children ) { 2515 2634 $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); … … 2520 2639 $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); 2521 2640 // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. 2522 foreach ( $revision_ids as $revision_id ) 2641 foreach ( $revision_ids as $revision_id ) { 2523 2642 wp_delete_post_revision( $revision_id ); 2643 } 2524 2644 2525 2645 // Point all attachments to this post up one level. … … 2528 2648 wp_defer_comment_counting( true ); 2529 2649 2530 $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ) );2650 $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ) ); 2531 2651 foreach ( $comment_ids as $comment_id ) { 2532 2652 wp_delete_comment( $comment_id, true ); … … 2535 2655 wp_defer_comment_counting( false ); 2536 2656 2537 $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ) );2538 foreach ( $post_meta_ids as $mid ) 2657 $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ) ); 2658 foreach ( $post_meta_ids as $mid ) { 2539 2659 delete_metadata_by_mid( 'post', $mid ); 2660 } 2540 2661 2541 2662 /** … … 2564 2685 2565 2686 if ( is_post_type_hierarchical( $post->post_type ) && $children ) { 2566 foreach ( $children as $child ) 2687 foreach ( $children as $child ) { 2567 2688 clean_post_cache( $child ); 2568 } 2569 2570 wp_clear_scheduled_hook('publish_future_post', array( $postid ) ); 2689 } 2690 } 2691 2692 wp_clear_scheduled_hook( 'publish_future_post', array( $postid ) ); 2571 2693 2572 2694 /** … … 2598 2720 $post = get_post( $post_id ); 2599 2721 if ( 'page' == $post->post_type ) { 2600 2601 2602 2603 2722 /* 2723 * If the page is defined in option page_on_front or post_for_posts, 2724 * adjust the corresponding options. 2725 */ 2604 2726 if ( get_option( 'page_on_front' ) == $post->ID ) { 2605 2727 update_option( 'show_on_front', 'posts' ); … … 2666 2788 add_post_meta( $post_id, '_wp_trash_meta_time', time() ); 2667 2789 2668 wp_update_post( array( 'ID' => $post_id, 'post_status' => 'trash' ) ); 2790 wp_update_post( 2791 array( 2792 'ID' => $post_id, 2793 'post_status' => 'trash', 2794 ) 2795 ); 2669 2796 2670 2797 wp_trash_post_comments( $post_id ); … … 2728 2855 delete_post_meta( $post_id, '_wp_trash_meta_time' ); 2729 2856 2730 wp_update_post( array( 'ID' => $post_id, 'post_status' => $post_status ) ); 2857 wp_update_post( 2858 array( 2859 'ID' => $post_id, 2860 'post_status' => $post_status, 2861 ) 2862 ); 2731 2863 2732 2864 wp_untrash_post_comments( $post_id ); … … 2757 2889 global $wpdb; 2758 2890 2759 $post = get_post( $post);2760 if ( empty( $post) )2891 $post = get_post( $post ); 2892 if ( empty( $post ) ) { 2761 2893 return; 2894 } 2762 2895 2763 2896 $post_id = $post->ID; … … 2772 2905 do_action( 'trash_post_comments', $post_id ); 2773 2906 2774 $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) );2775 if ( empty( $comments) )2907 $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) ); 2908 if ( empty( $comments ) ) { 2776 2909 return; 2910 } 2777 2911 2778 2912 // Cache current status for each comment. 2779 2913 $statuses = array(); 2780 foreach ( $comments as $comment ) 2781 $statuses[$comment->comment_ID] = $comment->comment_approved; 2782 add_post_meta($post_id, '_wp_trash_meta_comments_status', $statuses); 2914 foreach ( $comments as $comment ) { 2915 $statuses[ $comment->comment_ID ] = $comment->comment_approved; 2916 } 2917 add_post_meta( $post_id, '_wp_trash_meta_comments_status', $statuses ); 2783 2918 2784 2919 // Set status for all comments to post-trashed. 2785 $result = $wpdb->update( $wpdb->comments, array('comment_approved' => 'post-trashed'), array('comment_post_ID' => $post_id));2786 2787 clean_comment_cache( array_keys( $statuses) );2920 $result = $wpdb->update( $wpdb->comments, array( 'comment_approved' => 'post-trashed' ), array( 'comment_post_ID' => $post_id ) ); 2921 2922 clean_comment_cache( array_keys( $statuses ) ); 2788 2923 2789 2924 /** … … 2813 2948 global $wpdb; 2814 2949 2815 $post = get_post( $post);2816 if ( empty( $post) )2950 $post = get_post( $post ); 2951 if ( empty( $post ) ) { 2817 2952 return; 2953 } 2818 2954 2819 2955 $post_id = $post->ID; 2820 2956 2821 $statuses = get_post_meta( $post_id, '_wp_trash_meta_comments_status', true);2822 2823 if ( empty( $statuses) )2957 $statuses = get_post_meta( $post_id, '_wp_trash_meta_comments_status', true ); 2958 2959 if ( empty( $statuses ) ) { 2824 2960 return true; 2961 } 2825 2962 2826 2963 /** … … 2835 2972 // Restore each comment to its original status. 2836 2973 $group_by_status = array(); 2837 foreach ( $statuses as $comment_id => $comment_status ) 2838 $group_by_status[$comment_status][] = $comment_id; 2974 foreach ( $statuses as $comment_id => $comment_status ) { 2975 $group_by_status[ $comment_status ][] = $comment_id; 2976 } 2839 2977 2840 2978 foreach ( $group_by_status as $status => $comments ) { … … 2847 2985 } 2848 2986 2849 clean_comment_cache( array_keys( $statuses) );2850 2851 delete_post_meta( $post_id, '_wp_trash_meta_comments_status');2987 clean_comment_cache( array_keys( $statuses ) ); 2988 2989 delete_post_meta( $post_id, '_wp_trash_meta_comments_status' ); 2852 2990 2853 2991 /** … … 2883 3021 $post_id = (int) $post_id; 2884 3022 2885 $defaults = array( 'fields' => 'ids');2886 $args = wp_parse_args( $args, $defaults );2887 2888 $cats = wp_get_object_terms( $post_id, 'category', $args);3023 $defaults = array( 'fields' => 'ids' ); 3024 $args = wp_parse_args( $args, $defaults ); 3025 3026 $cats = wp_get_object_terms( $post_id, 'category', $args ); 2889 3027 return $cats; 2890 3028 } … … 2907 3045 */ 2908 3046 function wp_get_post_tags( $post_id = 0, $args = array() ) { 2909 return wp_get_post_terms( $post_id, 'post_tag', $args );3047 return wp_get_post_terms( $post_id, 'post_tag', $args ); 2910 3048 } 2911 3049 … … 2930 3068 $post_id = (int) $post_id; 2931 3069 2932 $defaults = array( 'fields' => 'all');2933 $args = wp_parse_args( $args, $defaults );2934 2935 $tags = wp_get_object_terms( $post_id, $taxonomy, $args);3070 $defaults = array( 'fields' => 'all' ); 3071 $args = wp_parse_args( $args, $defaults ); 3072 3073 $tags = wp_get_object_terms( $post_id, $taxonomy, $args ); 2936 3074 2937 3075 return $tags; … … 2960 3098 // Set default arguments. 2961 3099 $defaults = array( 2962 'numberposts' => 10, 'offset' => 0, 2963 'category' => 0, 'orderby' => 'post_date', 2964 'order' => 'DESC', 'include' => '', 2965 'exclude' => '', 'meta_key' => '', 2966 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 2967 'suppress_filters' => true 3100 'numberposts' => 10, 3101 'offset' => 0, 3102 'category' => 0, 3103 'orderby' => 'post_date', 3104 'order' => 'DESC', 3105 'include' => '', 3106 'exclude' => '', 3107 'meta_key' => '', 3108 'meta_value' => '', 3109 'post_type' => 'post', 3110 'post_status' => 'draft, publish, future, pending, private', 3111 'suppress_filters' => true, 2968 3112 ); 2969 3113 … … 2973 3117 2974 3118 // Backward compatibility. Prior to 3.1 expected posts to be returned in array. 2975 if ( ARRAY_A == $output ) {3119 if ( ARRAY_A == $output ) { 2976 3120 foreach ( $results as $key => $result ) { 2977 $results[ $key] = get_object_vars( $result );3121 $results[ $key ] = get_object_vars( $result ); 2978 3122 } 2979 3123 return $results ? $results : array(); … … 3050 3194 3051 3195 $defaults = array( 3052 'post_author' => $user_id,3053 'post_content' => '',3196 'post_author' => $user_id, 3197 'post_content' => '', 3054 3198 'post_content_filtered' => '', 3055 'post_title' => '',3056 'post_excerpt' => '',3057 'post_status' => 'draft',3058 'post_type' => 'post',3059 'comment_status' => '',3060 'ping_status' => '',3061 'post_password' => '',3062 'to_ping' =>'',3063 'pinged' => '',3064 'post_parent' => 0,3065 'menu_order' => 0,3066 'guid' => '',3067 'import_id' => 0,3068 'context' => '',3199 'post_title' => '', 3200 'post_excerpt' => '', 3201 'post_status' => 'draft', 3202 'post_type' => 'post', 3203 'comment_status' => '', 3204 'ping_status' => '', 3205 'post_password' => '', 3206 'to_ping' => '', 3207 'pinged' => '', 3208 'post_parent' => 0, 3209 'menu_order' => 0, 3210 'guid' => '', 3211 'import_id' => 0, 3212 'context' => '', 3069 3213 ); 3070 3214 3071 $postarr = wp_parse_args( $postarr, $defaults);3072 3073 unset( $postarr[ 'filter'] );3074 3075 $postarr = sanitize_post( $postarr, 'db');3215 $postarr = wp_parse_args( $postarr, $defaults ); 3216 3217 unset( $postarr['filter'] ); 3218 3219 $postarr = sanitize_post( $postarr, 'db' ); 3076 3220 3077 3221 // Are we updating or creating? 3078 3222 $post_ID = 0; 3079 $update = false;3080 $guid = $postarr['guid'];3223 $update = false; 3224 $guid = $postarr['guid']; 3081 3225 3082 3226 if ( ! empty( $postarr['ID'] ) ) { … … 3084 3228 3085 3229 // Get the post ID and GUID. 3086 $post_ID = $postarr['ID'];3230 $post_ID = $postarr['ID']; 3087 3231 $post_before = get_post( $post_ID ); 3088 3232 if ( is_null( $post_before ) ) { … … 3093 3237 } 3094 3238 3095 $guid = get_post_field( 'guid', $post_ID );3096 $previous_status = get_post_field( 'post_status', $post_ID );3239 $guid = get_post_field( 'guid', $post_ID ); 3240 $previous_status = get_post_field( 'post_status', $post_ID ); 3097 3241 } else { 3098 3242 $previous_status = 'new'; … … 3101 3245 $post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type']; 3102 3246 3103 $post_title = $postarr['post_title'];3247 $post_title = $postarr['post_title']; 3104 3248 $post_content = $postarr['post_content']; 3105 3249 $post_excerpt = $postarr['post_excerpt']; … … 3155 3299 // 'post' requires at least one category. 3156 3300 if ( 'post' == $post_type && 'auto-draft' != $post_status ) { 3157 $post_category = array( get_option( 'default_category') );3301 $post_category = array( get_option( 'default_category' ) ); 3158 3302 } else { 3159 3303 $post_category = array(); … … 3162 3306 3163 3307 // Don't allow contributors to set the post slug for pending review posts. 3164 if ( 'pending' == $post_status && ! current_user_can( 'publish_posts' ) ) {3308 if ( 'pending' == $post_status && ! current_user_can( 'publish_posts' ) ) { 3165 3309 $post_name = ''; 3166 3310 } … … 3170 3314 * an empty post name. 3171 3315 */ 3172 if ( empty( $post_name) ) {3173 if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {3174 $post_name = sanitize_title( $post_title);3316 if ( empty( $post_name ) ) { 3317 if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { 3318 $post_name = sanitize_title( $post_title ); 3175 3319 } else { 3176 3320 $post_name = ''; … … 3182 3326 $post_name = $check_name; 3183 3327 } else { // new post, or slug has changed. 3184 $post_name = sanitize_title( $post_name);3328 $post_name = sanitize_title( $post_name ); 3185 3329 } 3186 3330 } … … 3201 3345 3202 3346 // Validate the date. 3203 $mm = substr( $post_date, 5, 2 );3204 $jj = substr( $post_date, 8, 2 );3205 $aa = substr( $post_date, 0, 4 );3347 $mm = substr( $post_date, 5, 2 ); 3348 $jj = substr( $post_date, 8, 2 ); 3349 $aa = substr( $post_date, 0, 4 ); 3206 3350 $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date ); 3207 3351 if ( ! $valid_date ) { … … 3233 3377 if ( 'attachment' !== $post_type ) { 3234 3378 if ( 'publish' == $post_status ) { 3235 $now = gmdate( 'Y-m-d H:i:59');3236 if ( mysql2date( 'U', $post_date_gmt, false) > mysql2date('U', $now, false) ) {3379 $now = gmdate( 'Y-m-d H:i:59' ); 3380 if ( mysql2date( 'U', $post_date_gmt, false ) > mysql2date( 'U', $now, false ) ) { 3237 3381 $post_status = 'future'; 3238 3382 } 3239 3383 } elseif ( 'future' == $post_status ) { 3240 $now = gmdate( 'Y-m-d H:i:59');3241 if ( mysql2date( 'U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) {3384 $now = gmdate( 'Y-m-d H:i:59' ); 3385 if ( mysql2date( 'U', $post_date_gmt, false ) <= mysql2date( 'U', $now, false ) ) { 3242 3386 $post_status = 'publish'; 3243 3387 } … … 3258 3402 // These variables are needed by compact() later. 3259 3403 $post_content_filtered = $postarr['post_content_filtered']; 3260 $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;3261 $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];3262 $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';3263 $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';3264 $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;3404 $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id; 3405 $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status']; 3406 $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : ''; 3407 $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : ''; 3408 $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0; 3265 3409 3266 3410 /* … … 3359 3503 $data = apply_filters( 'wp_insert_post_data', $data, $postarr ); 3360 3504 } 3361 $data = wp_unslash( $data );3505 $data = wp_unslash( $data ); 3362 3506 $where = array( 'ID' => $post_ID ); 3363 3507 … … 3374 3518 if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) { 3375 3519 if ( $wp_error ) { 3376 return new WP_Error( 'db_update_error', __('Could not update post in the database'), $wpdb->last_error);3520 return new WP_Error( 'db_update_error', __( 'Could not update post in the database' ), $wpdb->last_error ); 3377 3521 } else { 3378 3522 return 0; … … 3383 3527 if ( ! empty( $import_id ) ) { 3384 3528 $import_id = (int) $import_id; 3385 if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) {3529 if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id ) ) ) { 3386 3530 $data['ID'] = $import_id; 3387 3531 } … … 3389 3533 if ( false === $wpdb->insert( $wpdb->posts, $data ) ) { 3390 3534 if ( $wp_error ) { 3391 return new WP_Error( 'db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);3535 return new WP_Error( 'db_insert_error', __( 'Could not insert post into the database' ), $wpdb->last_error ); 3392 3536 } else { 3393 3537 return 0; … … 3417 3561 if ( ! empty( $postarr['tax_input'] ) ) { 3418 3562 foreach ( $postarr['tax_input'] as $taxonomy => $tags ) { 3419 $taxonomy_obj = get_taxonomy( $taxonomy);3563 $taxonomy_obj = get_taxonomy( $taxonomy ); 3420 3564 if ( ! $taxonomy_obj ) { 3421 3565 /* translators: %s: taxonomy name */ … … 3426 3570 // array = hierarchical, string = non-hierarchical. 3427 3571 if ( is_array( $tags ) ) { 3428 $tags = array_filter( $tags);3572 $tags = array_filter( $tags ); 3429 3573 } 3430 3574 if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) { … … 3484 3628 if ( ! empty( $postarr['page_template'] ) ) { 3485 3629 $post->page_template = $postarr['page_template']; 3486 $page_templates = wp_get_theme()->get_page_templates( $post );3630 $page_templates = wp_get_theme()->get_page_templates( $post ); 3487 3631 if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) { 3488 3632 if ( $wp_error ) { … … 3544 3688 */ 3545 3689 do_action( 'edit_post', $post_ID, $post ); 3546 $post_after = get_post( $post_ID);3690 $post_after = get_post( $post_ID ); 3547 3691 3548 3692 /** … … 3555 3699 * @param WP_Post $post_before Post object before the update. 3556 3700 */ 3557 do_action( 'post_updated', $post_ID, $post_after, $post_before );3701 do_action( 'post_updated', $post_ID, $post_after, $post_before ); 3558 3702 } 3559 3703 … … 3611 3755 */ 3612 3756 function wp_update_post( $postarr = array(), $wp_error = false ) { 3613 if ( is_object( $postarr) ) {3757 if ( is_object( $postarr ) ) { 3614 3758 // Non-escaped post was passed. 3615 $postarr = get_object_vars( $postarr);3616 $postarr = wp_slash( $postarr);3759 $postarr = get_object_vars( $postarr ); 3760 $postarr = wp_slash( $postarr ); 3617 3761 } 3618 3762 3619 3763 // First, get all of the original fields. 3620 $post = get_post( $postarr['ID'], ARRAY_A);3764 $post = get_post( $postarr['ID'], ARRAY_A ); 3621 3765 3622 3766 if ( is_null( $post ) ) { 3623 if ( $wp_error ) 3767 if ( $wp_error ) { 3624 3768 return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); 3769 } 3625 3770 return 0; 3626 3771 } 3627 3772 3628 3773 // Escape data pulled from DB. 3629 $post = wp_slash( $post);3774 $post = wp_slash( $post ); 3630 3775 3631 3776 // Passed post category list overwrites existing category list if not empty. 3632 if ( isset( $postarr['post_category']) && is_array($postarr['post_category'])3633 && 0 != count( $postarr['post_category']) )3777 if ( isset( $postarr['post_category'] ) && is_array( $postarr['post_category'] ) 3778 && 0 != count( $postarr['post_category'] ) ) { 3634 3779 $post_cats = $postarr['post_category']; 3635 else3780 } else { 3636 3781 $post_cats = $post['post_category']; 3782 } 3637 3783 3638 3784 // Drafts shouldn't be assigned a date unless explicitly done so by the user. 3639 if ( isset( $post['post_status'] ) && in_array( $post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) &&3640 ( '0000-00-00 00:00:00' == $post['post_date_gmt']) )3785 if ( isset( $post['post_status'] ) && in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) && empty( $postarr['edit_date'] ) && 3786 ( '0000-00-00 00:00:00' == $post['post_date_gmt'] ) ) { 3641 3787 $clear_date = true; 3642 else3788 } else { 3643 3789 $clear_date = false; 3790 } 3644 3791 3645 3792 // Merge old and new fields with new fields overwriting old ones. 3646 $postarr = array_merge($post, $postarr);3793 $postarr = array_merge( $post, $postarr ); 3647 3794 $postarr['post_category'] = $post_cats; 3648 3795 if ( $clear_date ) { 3649 $postarr['post_date'] = current_time('mysql');3796 $postarr['post_date'] = current_time( 'mysql' ); 3650 3797 $postarr['post_date_gmt'] = ''; 3651 3798 } 3652 3799 3653 if ($postarr['post_type'] == 'attachment') 3654 return wp_insert_attachment($postarr); 3800 if ( $postarr['post_type'] == 'attachment' ) { 3801 return wp_insert_attachment( $postarr ); 3802 } 3655 3803 3656 3804 return wp_insert_post( $postarr, $wp_error ); … … 3669 3817 global $wpdb; 3670 3818 3671 if ( ! $post = get_post( $post ) ) 3819 if ( ! $post = get_post( $post ) ) { 3672 3820 return; 3673 3674 if ( 'publish' == $post->post_status ) 3821 } 3822 3823 if ( 'publish' == $post->post_status ) { 3675 3824 return; 3825 } 3676 3826 3677 3827 $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) ); … … 3679 3829 clean_post_cache( $post->ID ); 3680 3830 3681 $old_status = $post->post_status;3831 $old_status = $post->post_status; 3682 3832 $post->post_status = 'publish'; 3683 3833 wp_transition_post_status( 'publish', $old_status, $post ); … … 3707 3857 */ 3708 3858 function check_and_publish_future_post( $post_id ) { 3709 $post = get_post( $post_id);3710 3711 if ( empty( $post) )3859 $post = get_post( $post_id ); 3860 3861 if ( empty( $post ) ) { 3712 3862 return; 3713 3714 if ( 'future' != $post->post_status ) 3863 } 3864 3865 if ( 'future' != $post->post_status ) { 3715 3866 return; 3867 } 3716 3868 3717 3869 $time = strtotime( $post->post_date_gmt . ' GMT' ); … … 3744 3896 */ 3745 3897 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { 3746 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) 3898 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) { 3747 3899 return $slug; 3900 } 3748 3901 3749 3902 global $wpdb, $wp_rewrite; … … 3752 3905 3753 3906 $feeds = $wp_rewrite->feeds; 3754 if ( ! is_array( $feeds ) ) 3907 if ( ! is_array( $feeds ) ) { 3755 3908 $feeds = array(); 3909 } 3756 3910 3757 3911 if ( 'attachment' == $post_type ) { 3758 3912 // Attachment slugs must be unique across all types. 3759 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";3913 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 3760 3914 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); 3761 3915 … … 3771 3925 $suffix = 2; 3772 3926 do { 3773 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";3927 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3774 3928 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) ); 3775 3929 $suffix++; … … 3778 3932 } 3779 3933 } elseif ( is_post_type_hierarchical( $post_type ) ) { 3780 if ( 'nav_menu_item' == $post_type ) 3934 if ( 'nav_menu_item' == $post_type ) { 3781 3935 return $slug; 3936 } 3782 3937 3783 3938 /* … … 3785 3940 * namespace than posts so page slugs are allowed to overlap post slugs. 3786 3941 */ 3787 $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";3942 $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"; 3788 3943 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) ); 3789 3944 … … 3798 3953 * @param int $post_parent Post parent ID. 3799 3954 */ 3800 if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) 3955 if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) { 3801 3956 $suffix = 2; 3802 3957 do { 3803 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";3958 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3804 3959 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) ); 3805 3960 $suffix++; … … 3809 3964 } else { 3810 3965 // Post slugs must be unique across all posts. 3811 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";3966 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 3812 3967 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); 3813 3968 3814 3969 // Prevent new post slugs that could result in URLs that conflict with date archives. 3815 $post = get_post( $post_ID );3970 $post = get_post( $post_ID ); 3816 3971 $conflicts_with_date_archive = false; 3817 3972 if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) { … … 3846 4001 $suffix = 2; 3847 4002 do { 3848 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";4003 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3849 4004 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) ); 3850 4005 $suffix++; … … 3884 4039 if ( strlen( $slug ) > $length ) { 3885 4040 $decoded_slug = urldecode( $slug ); 3886 if ( $decoded_slug === $slug ) 4041 if ( $decoded_slug === $slug ) { 3887 4042 $slug = substr( $slug, 0, $length ); 3888 else4043 } else { 3889 4044 $slug = utf8_uri_encode( $decoded_slug, $length ); 4045 } 3890 4046 } 3891 4047 … … 3906 4062 */ 3907 4063 function wp_add_post_tags( $post_id = 0, $tags = '' ) { 3908 return wp_set_post_tags( $post_id, $tags, true);4064 return wp_set_post_tags( $post_id, $tags, true ); 3909 4065 } 3910 4066 … … 3924 4080 */ 3925 4081 function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { 3926 return wp_set_post_terms( $post_id, $tags, 'post_tag', $append );4082 return wp_set_post_terms( $post_id, $tags, 'post_tag', $append ); 3927 4083 } 3928 4084 … … 3945 4101 $post_id = (int) $post_id; 3946 4102 3947 if ( ! $post_id )4103 if ( ! $post_id ) { 3948 4104 return false; 3949 3950 if ( empty($tags) ) 4105 } 4106 4107 if ( empty( $tags ) ) { 3951 4108 $tags = array(); 4109 } 3952 4110 3953 4111 if ( ! is_array( $tags ) ) { 3954 4112 $comma = _x( ',', 'tag delimiter' ); 3955 if ( ',' !== $comma ) 4113 if ( ',' !== $comma ) { 3956 4114 $tags = str_replace( $comma, ',', $tags ); 4115 } 3957 4116 $tags = explode( ',', trim( $tags, " \n\t\r\0\x0B," ) ); 3958 4117 } … … 3986 4145 */ 3987 4146 function wp_set_post_categories( $post_ID = 0, $post_categories = array(), $append = false ) { 3988 $post_ID = (int) $post_ID;3989 $post_type = get_post_type( $post_ID );4147 $post_ID = (int) $post_ID; 4148 $post_type = get_post_type( $post_ID ); 3990 4149 $post_status = get_post_status( $post_ID ); 3991 4150 // If $post_categories isn't already an array, make it one: … … 3993 4152 if ( empty( $post_categories ) ) { 3994 4153 if ( 'post' == $post_type && 'auto-draft' != $post_status ) { 3995 $post_categories = array( get_option( 'default_category') );3996 $append = false;4154 $post_categories = array( get_option( 'default_category' ) ); 4155 $append = false; 3997 4156 } else { 3998 4157 $post_categories = array(); … … 4102 4261 if ( is_array( $uri ) ) { 4103 4262 $pung = array_merge( $pung, $uri ); 4104 } 4105 else { 4263 } else { 4106 4264 $pung[] = $uri; 4107 4265 } 4108 $new = implode( "\n", $pung);4266 $new = implode( "\n", $pung ); 4109 4267 4110 4268 /** … … 4132 4290 function get_enclosed( $post_id ) { 4133 4291 $custom_fields = get_post_custom( $post_id ); 4134 $pung = array();4135 if ( ! is_array( $custom_fields ) )4292 $pung = array(); 4293 if ( ! is_array( $custom_fields ) ) { 4136 4294 return $pung; 4295 } 4137 4296 4138 4297 foreach ( $custom_fields as $key => $val ) { 4139 if ( 'enclosure' != $key || ! is_array( $val ) )4298 if ( 'enclosure' != $key || ! is_array( $val ) ) { 4140 4299 continue; 4300 } 4141 4301 foreach ( $val as $enc ) { 4142 4302 $enclosure = explode( "\n", $enc ); 4143 $pung[] = trim( $enclosure[ 0] );4303 $pung[] = trim( $enclosure[0] ); 4144 4304 } 4145 4305 } … … 4202 4362 4203 4363 $to_ping = sanitize_trackback_urls( $post->to_ping ); 4204 $to_ping = preg_split( '/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY);4364 $to_ping = preg_split( '/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY ); 4205 4365 4206 4366 /** … … 4258 4418 global $wpdb; 4259 4419 4260 $page_ids = wp_cache_get( 'all_page_ids', 'posts');4420 $page_ids = wp_cache_get( 'all_page_ids', 'posts' ); 4261 4421 if ( ! is_array( $page_ids ) ) { 4262 $page_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page'");4263 wp_cache_add( 'all_page_ids', $page_ids, 'posts');4422 $page_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page'" ); 4423 wp_cache_add( 'all_page_ids', $page_ids, 'posts' ); 4264 4424 } 4265 4425 … … 4282 4442 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. 4283 4443 */ 4284 function get_page( $page, $output = OBJECT, $filter = 'raw' ) {4444 function get_page( $page, $output = OBJECT, $filter = 'raw' ) { 4285 4445 return get_post( $page, $output, $filter ); 4286 4446 } … … 4304 4464 $last_changed = wp_cache_get_last_changed( 'posts' ); 4305 4465 4306 $hash = md5( $page_path . serialize( $post_type ) );4466 $hash = md5( $page_path . serialize( $post_type ) ); 4307 4467 $cache_key = "get_page_by_path:$hash:$last_changed"; 4308 $cached = wp_cache_get( $cache_key, 'posts' );4468 $cached = wp_cache_get( $cache_key, 'posts' ); 4309 4469 if ( false !== $cached ) { 4310 4470 // Special case: '0' is a bad `$page_path`. … … 4316 4476 } 4317 4477 4318 $page_path = rawurlencode(urldecode($page_path));4319 $page_path = str_replace('%2F', '/', $page_path);4320 $page_path = str_replace('%20', ' ', $page_path);4321 $parts = explode( '/', trim( $page_path, '/' ) );4322 $parts = array_map( 'sanitize_title_for_query', $parts );4478 $page_path = rawurlencode( urldecode( $page_path ) ); 4479 $page_path = str_replace( '%2F', '/', $page_path ); 4480 $page_path = str_replace( '%20', ' ', $page_path ); 4481 $parts = explode( '/', trim( $page_path, '/' ) ); 4482 $parts = array_map( 'sanitize_title_for_query', $parts ); 4323 4483 $escaped_parts = esc_sql( $parts ); 4324 4484 … … 4331 4491 } 4332 4492 4333 $post_types = esc_sql( $post_types );4493 $post_types = esc_sql( $post_types ); 4334 4494 $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; 4335 $sql = "4495 $sql = " 4336 4496 SELECT ID, post_name, post_parent, post_type 4337 4497 FROM $wpdb->posts … … 4348 4508 if ( $page->post_name == $revparts[0] ) { 4349 4509 $count = 0; 4350 $p = $page;4510 $p = $page; 4351 4511 4352 4512 /* … … 4357 4517 $count++; 4358 4518 $parent = $pages[ $p->post_parent ]; 4359 if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) 4519 if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) { 4360 4520 break; 4521 } 4361 4522 $p = $parent; 4362 4523 } 4363 4524 4364 if ( $p->post_parent == 0 && $count +1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) {4525 if ( $p->post_parent == 0 && $count + 1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) { 4365 4526 $foundid = $page->ID; 4366 if ( $page->post_type == $post_type ) 4527 if ( $page->post_type == $post_type ) { 4367 4528 break; 4529 } 4368 4530 } 4369 4531 } … … 4395 4557 4396 4558 if ( is_array( $post_type ) ) { 4397 $post_type = esc_sql( $post_type );4559 $post_type = esc_sql( $post_type ); 4398 4560 $post_type_in_string = "'" . implode( "','", $post_type ) . "'"; 4399 $sql = $wpdb->prepare( " 4561 $sql = $wpdb->prepare( 4562 " 4400 4563 SELECT ID 4401 4564 FROM $wpdb->posts 4402 4565 WHERE post_title = %s 4403 4566 AND post_type IN ($post_type_in_string) 4404 ", $page_title ); 4567 ", $page_title 4568 ); 4405 4569 } else { 4406 $sql = $wpdb->prepare( " 4570 $sql = $wpdb->prepare( 4571 " 4407 4572 SELECT ID 4408 4573 FROM $wpdb->posts 4409 4574 WHERE post_title = %s 4410 4575 AND post_type = %s 4411 ", $page_title, $post_type ); 4576 ", $page_title, $post_type 4577 ); 4412 4578 } 4413 4579 … … 4445 4611 4446 4612 while ( $to_look ) { 4447 $p = array_pop( $to_look );4613 $p = array_pop( $to_look ); 4448 4614 $page_list[] = $p; 4449 4615 if ( isset( $children[ $p->ID ] ) ) { … … 4478 4644 $children = array(); 4479 4645 foreach ( (array) $pages as $p ) { 4480 $parent_id = intval( $p->post_parent );4646 $parent_id = intval( $p->post_parent ); 4481 4647 $children[ $parent_id ][] = $p; 4482 4648 } … … 4501 4667 * @param array $result Result (passed by reference). 4502 4668 */ 4503 function _page_traverse_name( $page_id, &$children, &$result ) {4504 if ( isset( $children[ $page_id ] ) ) {4505 foreach ( (array) $children[ $page_id ] as $child ) {4669 function _page_traverse_name( $page_id, &$children, &$result ) { 4670 if ( isset( $children[ $page_id ] ) ) { 4671 foreach ( (array) $children[ $page_id ] as $child ) { 4506 4672 $result[ $child->ID ] = $child->post_name; 4507 4673 _page_traverse_name( $child->ID, $children, $result ); … … 4526 4692 } 4527 4693 4528 if ( ! $page ) 4694 if ( ! $page ) { 4529 4695 return false; 4696 } 4530 4697 4531 4698 $uri = $page->post_name; … … 4614 4781 $r = wp_parse_args( $args, $defaults ); 4615 4782 4616 $number = (int) $r['number'];4617 $offset = (int) $r['offset'];4618 $child_of = (int) $r['child_of'];4783 $number = (int) $r['number']; 4784 $offset = (int) $r['offset']; 4785 $child_of = (int) $r['child_of']; 4619 4786 $hierarchical = $r['hierarchical']; 4620 $exclude = $r['exclude'];4621 $meta_key = $r['meta_key'];4622 $meta_value = $r['meta_value'];4623 $parent = $r['parent'];4624 $post_status = $r['post_status'];4787 $exclude = $r['exclude']; 4788 $meta_key = $r['meta_key']; 4789 $meta_value = $r['meta_value']; 4790 $parent = $r['parent']; 4791 $post_status = $r['post_status']; 4625 4792 4626 4793 // Make sure the post type is hierarchical. … … 4643 4810 4644 4811 // $args can be whatever, only use the args defined in defaults to compute the key. 4645 $key = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) );4812 $key = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) ); 4646 4813 $last_changed = wp_cache_get_last_changed( 'posts' ); 4647 4814 … … 4657 4824 $inclusions = ''; 4658 4825 if ( ! empty( $r['include'] ) ) { 4659 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include4660 $parent = -1;4661 $exclude = '';4662 $meta_key = '';4663 $meta_value = '';4826 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include 4827 $parent = -1; 4828 $exclude = ''; 4829 $meta_key = ''; 4830 $meta_value = ''; 4664 4831 $hierarchical = false; 4665 $incpages = wp_parse_id_list( $r['include'] );4832 $incpages = wp_parse_id_list( $r['include'] ); 4666 4833 if ( ! empty( $incpages ) ) { 4667 $inclusions = ' AND ID IN (' . implode( ',', $incpages ) . 4834 $inclusions = ' AND ID IN (' . implode( ',', $incpages ) . ')'; 4668 4835 } 4669 4836 } … … 4673 4840 $expages = wp_parse_id_list( $exclude ); 4674 4841 if ( ! empty( $expages ) ) { 4675 $exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) . 4842 $exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) . ')'; 4676 4843 } 4677 4844 } … … 4684 4851 foreach ( $post_authors as $post_author ) { 4685 4852 //Do we have an author id or an author login? 4686 if ( 0 == intval( $post_author) ) {4687 $post_author = get_user_by( 'login', $post_author);4853 if ( 0 == intval( $post_author ) ) { 4854 $post_author = get_user_by( 'login', $post_author ); 4688 4855 if ( empty( $post_author ) ) { 4689 4856 continue; … … 4696 4863 4697 4864 if ( '' == $author_query ) { 4698 $author_query = $wpdb->prepare( ' post_author = %d ', $post_author);4865 $author_query = $wpdb->prepare( ' post_author = %d ', $post_author ); 4699 4866 } else { 4700 $author_query .= $wpdb->prepare( ' OR post_author = %d ', $post_author);4867 $author_query .= $wpdb->prepare( ' OR post_author = %d ', $post_author ); 4701 4868 } 4702 4869 } … … 4707 4874 } 4708 4875 4709 $join = '';4876 $join = ''; 4710 4877 $where = "$exclusions $inclusions "; 4711 4878 if ( '' !== $meta_key || '' !== $meta_value ) { … … 4713 4880 4714 4881 // meta_key and meta_value might be slashed 4715 $meta_key = wp_unslash($meta_key);4716 $meta_value = wp_unslash( $meta_value);4882 $meta_key = wp_unslash( $meta_key ); 4883 $meta_value = wp_unslash( $meta_value ); 4717 4884 if ( '' !== $meta_key ) { 4718 $where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_key = %s", $meta_key);4885 $where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_key = %s", $meta_key ); 4719 4886 } 4720 4887 if ( '' !== $meta_value ) { 4721 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value); 4722 } 4723 4888 $where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_value = %s", $meta_value ); 4889 } 4724 4890 } 4725 4891 … … 4730 4896 } 4731 4897 } elseif ( $parent >= 0 ) { 4732 $where .= $wpdb->prepare( ' AND post_parent = %d ', $parent);4898 $where .= $wpdb->prepare( ' AND post_parent = %d ', $parent ); 4733 4899 } 4734 4900 4735 4901 if ( 1 == count( $post_status ) ) { 4736 $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], reset( $post_status ) );4902 $where_post_type = $wpdb->prepare( 'post_type = %s AND post_status = %s', $r['post_type'], reset( $post_status ) ); 4737 4903 } else { 4738 $post_status = implode( "', '", $post_status );4904 $post_status = implode( "', '", $post_status ); 4739 4905 $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $r['post_type'] ); 4740 4906 } 4741 4907 4742 4908 $orderby_array = array(); 4743 $allowed_keys = array( 'author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', 4744 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', 4745 'ID', 'rand', 'comment_count' ); 4909 $allowed_keys = array( 4910 'author', 4911 'post_author', 4912 'date', 4913 'post_date', 4914 'title', 4915 'post_title', 4916 'name', 4917 'post_name', 4918 'modified', 4919 'post_modified', 4920 'modified_gmt', 4921 'post_modified_gmt', 4922 'menu_order', 4923 'parent', 4924 'post_parent', 4925 'ID', 4926 'rand', 4927 'comment_count', 4928 ); 4746 4929 4747 4930 foreach ( explode( ',', $r['sort_column'] ) as $orderby ) { … … 4781 4964 } 4782 4965 4783 $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";4966 $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where "; 4784 4967 $query .= $author_query; 4785 $query .= " ORDER BY " . $sort_column . " " . $sort_order;4968 $query .= ' ORDER BY ' . $sort_column . ' ' . $sort_order; 4786 4969 4787 4970 if ( ! empty( $number ) ) { … … 4789 4972 } 4790 4973 4791 $pages = $wpdb->get_results( $query);4792 4793 if ( empty( $pages) ) {4974 $pages = $wpdb->get_results( $query ); 4975 4976 if ( empty( $pages ) ) { 4794 4977 /** This filter is documented in wp-includes/post.php */ 4795 4978 $pages = apply_filters( 'get_pages', array(), $r ); … … 4798 4981 4799 4982 // Sanitize before caching so it'll only get done once. 4800 $num_pages = count( $pages);4801 for ( $i = 0; $i < $num_pages; $i++) {4802 $pages[ $i] = sanitize_post($pages[$i], 'raw');4983 $num_pages = count( $pages ); 4984 for ( $i = 0; $i < $num_pages; $i++ ) { 4985 $pages[ $i ] = sanitize_post( $pages[ $i ], 'raw' ); 4803 4986 } 4804 4987 … … 4807 4990 4808 4991 if ( $child_of || $hierarchical ) { 4809 $pages = get_page_children( $child_of, $pages);4992 $pages = get_page_children( $child_of, $pages ); 4810 4993 } 4811 4994 … … 4821 5004 $num_pages = count( $pages ); 4822 5005 for ( $i = 0; $i < $num_pages; $i++ ) { 4823 if ( in_array( $pages[ $i]->ID, $exclude ) ) {4824 unset( $pages[ $i] );5006 if ( in_array( $pages[ $i ]->ID, $exclude ) ) { 5007 unset( $pages[ $i ] ); 4825 5008 } 4826 5009 } … … 4860 5043 * @return bool True on success, false on failure. 4861 5044 */ 4862 function is_local_attachment( $url) {4863 if ( strpos($url, home_url()) === false)5045 function is_local_attachment( $url ) { 5046 if ( strpos( $url, home_url() ) === false ) { 4864 5047 return false; 4865 if (strpos($url, home_url('/?attachment_id=')) !== false) 5048 } 5049 if ( strpos( $url, home_url( '/?attachment_id=' ) ) !== false ) { 4866 5050 return true; 4867 if ( $id = url_to_postid($url) ) { 4868 $post = get_post($id); 4869 if ( 'attachment' == $post->post_type ) 5051 } 5052 if ( $id = url_to_postid( $url ) ) { 5053 $post = get_post( $id ); 5054 if ( 'attachment' == $post->post_type ) { 4870 5055 return true; 5056 } 4871 5057 } 4872 5058 return false; … … 4901 5087 $defaults = array( 4902 5088 'file' => $file, 4903 'post_parent' => 0 5089 'post_parent' => 0, 4904 5090 ); 4905 5091 … … 4953 5139 } 4954 5140 4955 delete_post_meta( $post_id, '_wp_trash_meta_status');4956 delete_post_meta( $post_id, '_wp_trash_meta_time');4957 4958 $meta = wp_get_attachment_metadata( $post_id );5141 delete_post_meta( $post_id, '_wp_trash_meta_status' ); 5142 delete_post_meta( $post_id, '_wp_trash_meta_time' ); 5143 5144 $meta = wp_get_attachment_metadata( $post_id ); 4959 5145 $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); 4960 $file = get_attached_file( $post_id );4961 4962 if ( is_multisite() ) 5146 $file = get_attached_file( $post_id ); 5147 5148 if ( is_multisite() ) { 4963 5149 delete_transient( 'dirsize_cache' ); 5150 } 4964 5151 4965 5152 /** … … 4972 5159 do_action( 'delete_attachment', $post_id ); 4973 5160 4974 wp_delete_object_term_relationships( $post_id, array('category', 'post_tag'));4975 wp_delete_object_term_relationships( $post_id, get_object_taxonomies($post->post_type));5161 wp_delete_object_term_relationships( $post_id, array( 'category', 'post_tag' ) ); 5162 wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) ); 4976 5163 4977 5164 // Delete all for any posts. … … 4980 5167 wp_defer_comment_counting( true ); 4981 5168 4982 $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) );5169 $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) ); 4983 5170 foreach ( $comment_ids as $comment_id ) { 4984 5171 wp_delete_comment( $comment_id, true ); … … 4987 5174 wp_defer_comment_counting( false ); 4988 5175 4989 $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) );4990 foreach ( $post_meta_ids as $mid ) 5176 $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) ); 5177 foreach ( $post_meta_ids as $mid ) { 4991 5178 delete_metadata_by_mid( 'post', $mid ); 5179 } 4992 5180 4993 5181 /** This action is documented in wp-includes/post.php */ … … 5002 5190 $uploadpath = wp_get_upload_dir(); 5003 5191 5004 if ( ! empty( $meta['thumb']) ) {5192 if ( ! empty( $meta['thumb'] ) ) { 5005 5193 // Don't delete the thumb if another attachment uses it. 5006 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)) ) {5007 $thumbfile = str_replace( basename($file), $meta['thumb'], $file);5194 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 ) ) ) { 5195 $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file ); 5008 5196 /** This filter is documented in wp-includes/functions.php */ 5009 5197 $thumbfile = apply_filters( 'wp_delete_file', $thumbfile ); 5010 @ unlink( path_join( $uploadpath['basedir'], $thumbfile) );5198 @ unlink( path_join( $uploadpath['basedir'], $thumbfile ) ); 5011 5199 } 5012 5200 } … … 5022 5210 } 5023 5211 5024 if ( is_array( $backup_sizes) ) {5212 if ( is_array( $backup_sizes ) ) { 5025 5213 foreach ( $backup_sizes as $size ) { 5026 $del_file = path_join( dirname( $meta['file']), $size['file'] );5214 $del_file = path_join( dirname( $meta['file'] ), $size['file'] ); 5027 5215 /** This filter is documented in wp-includes/functions.php */ 5028 5216 $del_file = apply_filters( 'wp_delete_file', $del_file ); 5029 @ unlink( path_join( $uploadpath['basedir'], $del_file) );5217 @ unlink( path_join( $uploadpath['basedir'], $del_file ) ); 5030 5218 } 5031 5219 } … … 5055 5243 $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); 5056 5244 5057 if ( $unfiltered ) 5245 if ( $unfiltered ) { 5058 5246 return $data; 5247 } 5059 5248 5060 5249 /** … … 5093 5282 * @param int $attachment_id Attachment post ID. 5094 5283 */ 5095 if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) 5284 if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) { 5096 5285 return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); 5097 else5286 } else { 5098 5287 return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); 5288 } 5099 5289 } 5100 5290 … … 5115 5305 } 5116 5306 5117 if ( 'attachment' != $post->post_type ) 5307 if ( 'attachment' != $post->post_type ) { 5118 5308 return false; 5309 } 5119 5310 5120 5311 $url = ''; … … 5126 5317 if ( 0 === strpos( $file, $uploads['basedir'] ) ) { 5127 5318 // Replace file location with url location. 5128 $url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file);5129 } elseif ( false !== strpos( $file, 'wp-content/uploads') ) {5319 $url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file ); 5320 } elseif ( false !== strpos( $file, 'wp-content/uploads' ) ) { 5130 5321 // Get the directory name relative to the basedir (back compat for pre-2.7 uploads) 5131 5322 $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file ); … … 5141 5332 * not recommended to rely upon this. 5142 5333 */ 5143 if ( empty( $url) ) {5334 if ( empty( $url ) ) { 5144 5335 $url = get_the_guid( $post->ID ); 5145 5336 } … … 5160 5351 $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID ); 5161 5352 5162 if ( empty( $url ) ) 5353 if ( empty( $url ) ) { 5163 5354 return false; 5355 } 5164 5356 5165 5357 return $url; … … 5207 5399 function wp_get_attachment_thumb_file( $post_id = 0 ) { 5208 5400 $post_id = (int) $post_id; 5209 if ( ! $post = get_post( $post_id ) )5401 if ( ! $post = get_post( $post_id ) ) { 5210 5402 return false; 5211 if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) 5403 } 5404 if ( ! is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) { 5212 5405 return false; 5406 } 5213 5407 5214 5408 $file = get_attached_file( $post->ID ); 5215 5409 5216 if ( ! empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) {5410 if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) { 5217 5411 /** 5218 5412 * Filters the attachment thumbnail file path. … … 5238 5432 function wp_get_attachment_thumb_url( $post_id = 0 ) { 5239 5433 $post_id = (int) $post_id; 5240 if ( ! $post = get_post( $post_id ) )5434 if ( ! $post = get_post( $post_id ) ) { 5241 5435 return false; 5242 if ( !$url = wp_get_attachment_url( $post->ID ) ) 5436 } 5437 if ( ! $url = wp_get_attachment_url( $post->ID ) ) { 5243 5438 return false; 5439 } 5244 5440 5245 5441 $sized = image_downsize( $post_id, 'thumbnail' ); 5246 if ( $sized ) 5442 if ( $sized ) { 5247 5443 return $sized[0]; 5248 5249 if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) ) 5444 } 5445 5446 if ( ! $thumb = wp_get_attachment_thumb_file( $post->ID ) ) { 5250 5447 return false; 5251 5252 $url = str_replace(basename($url), basename($thumb), $url); 5448 } 5449 5450 $url = str_replace( basename( $url ), basename( $thumb ), $url ); 5253 5451 5254 5452 /** … … 5297 5495 5298 5496 switch ( $type ) { 5299 case 'image':5300 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );5301 return in_array( $ext, $image_exts );5302 5303 case 'audio':5304 return in_array( $ext, wp_get_audio_extensions() );5305 5306 case 'video':5307 return in_array( $ext, wp_get_video_extensions() );5308 5309 default:5310 return $type === $ext;5497 case 'image': 5498 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); 5499 return in_array( $ext, $image_exts ); 5500 5501 case 'audio': 5502 return in_array( $ext, wp_get_audio_extensions() ); 5503 5504 case 'video': 5505 return in_array( $ext, wp_get_video_extensions() ); 5506 5507 default: 5508 return $type === $ext; 5311 5509 } 5312 5510 } … … 5335 5533 */ 5336 5534 function wp_mime_type_icon( $mime = 0 ) { 5337 if ( !is_numeric($mime) ) 5338 $icon = wp_cache_get("mime_type_icon_$mime"); 5535 if ( ! is_numeric( $mime ) ) { 5536 $icon = wp_cache_get( "mime_type_icon_$mime" ); 5537 } 5339 5538 5340 5539 $post_id = 0; 5341 if ( empty( $icon) ) {5540 if ( empty( $icon ) ) { 5342 5541 $post_mimes = array(); 5343 if ( is_numeric( $mime) ) {5542 if ( is_numeric( $mime ) ) { 5344 5543 $mime = (int) $mime; 5345 5544 if ( $post = get_post( $mime ) ) { 5346 5545 $post_id = (int) $post->ID; 5347 $file = get_attached_file( $post_id );5348 $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);5349 if ( ! empty($ext) ) {5546 $file = get_attached_file( $post_id ); 5547 $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $file ); 5548 if ( ! empty( $ext ) ) { 5350 5549 $post_mimes[] = $ext; 5351 if ( $ext_type = wp_ext2type( $ext ) ) 5550 if ( $ext_type = wp_ext2type( $ext ) ) { 5352 5551 $post_mimes[] = $ext_type; 5552 } 5353 5553 } 5354 5554 $mime = $post->post_mime_type; … … 5360 5560 } 5361 5561 5362 $icon_files = wp_cache_get( 'icon_files');5363 5364 if ( ! is_array($icon_files) ) {5562 $icon_files = wp_cache_get( 'icon_files' ); 5563 5564 if ( ! is_array( $icon_files ) ) { 5365 5565 /** 5366 5566 * Filters the icon directory path. … … 5388 5588 * @param array $uris List of icon directory URIs. 5389 5589 */ 5390 $dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) );5590 $dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) ); 5391 5591 $icon_files = array(); 5392 5592 while ( $dirs ) { 5393 5593 $keys = array_keys( $dirs ); 5394 $dir = array_shift( $keys ); 5395 $uri = array_shift($dirs); 5396 if ( $dh = opendir($dir) ) { 5397 while ( false !== $file = readdir($dh) ) { 5398 $file = basename($file); 5399 if ( substr($file, 0, 1) == '.' ) 5400 continue; 5401 if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) { 5402 if ( is_dir("$dir/$file") ) 5403 $dirs["$dir/$file"] = "$uri/$file"; 5594 $dir = array_shift( $keys ); 5595 $uri = array_shift( $dirs ); 5596 if ( $dh = opendir( $dir ) ) { 5597 while ( false !== $file = readdir( $dh ) ) { 5598 $file = basename( $file ); 5599 if ( substr( $file, 0, 1 ) == '.' ) { 5404 5600 continue; 5405 5601 } 5406 $icon_files["$dir/$file"] = "$uri/$file"; 5602 if ( ! in_array( strtolower( substr( $file, -4 ) ), array( '.png', '.gif', '.jpg' ) ) ) { 5603 if ( is_dir( "$dir/$file" ) ) { 5604 $dirs[ "$dir/$file" ] = "$uri/$file"; 5605 } 5606 continue; 5607 } 5608 $icon_files[ "$dir/$file" ] = "$uri/$file"; 5407 5609 } 5408 closedir( $dh);5610 closedir( $dh ); 5409 5611 } 5410 5612 } … … 5414 5616 $types = array(); 5415 5617 // Icon basename - extension = MIME wildcard. 5416 foreach ( $icon_files as $file => $uri ) 5417 $types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file]; 5418 5419 if ( ! empty($mime) ) { 5420 $post_mimes[] = substr($mime, 0, strpos($mime, '/')); 5421 $post_mimes[] = substr($mime, strpos($mime, '/') + 1); 5422 $post_mimes[] = str_replace('/', '_', $mime); 5423 } 5424 5425 $matches = wp_match_mime_types(array_keys($types), $post_mimes); 5426 $matches['default'] = array('default'); 5618 foreach ( $icon_files as $file => $uri ) { 5619 $types[ preg_replace( '/^([^.]*).*$/', '$1', basename( $file ) ) ] =& $icon_files[ $file ]; 5620 } 5621 5622 if ( ! empty( $mime ) ) { 5623 $post_mimes[] = substr( $mime, 0, strpos( $mime, '/' ) ); 5624 $post_mimes[] = substr( $mime, strpos( $mime, '/' ) + 1 ); 5625 $post_mimes[] = str_replace( '/', '_', $mime ); 5626 } 5627 5628 $matches = wp_match_mime_types( array_keys( $types ), $post_mimes ); 5629 $matches['default'] = array( 'default' ); 5427 5630 5428 5631 foreach ( $matches as $match => $wilds ) { … … 5585 5788 } 5586 5789 5587 $sql = '( ' . implode( ' OR ', $post_type_clauses ) . ' )';5790 $sql = '( ' . implode( ' OR ', $post_type_clauses ) . ' )'; 5588 5791 5589 5792 if ( null !== $post_author ) { … … 5664 5867 $lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type ); 5665 5868 5666 $lastpostdate = get_lastpostdate( $timezone);5869 $lastpostdate = get_lastpostdate( $timezone ); 5667 5870 if ( $lastpostdate > $lastpostmodified ) { 5668 5871 $lastpostmodified = $lastpostdate; … … 5725 5928 switch ( $timezone ) { 5726 5929 case 'gmt': 5727 $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");5930 $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" ); 5728 5931 break; 5729 5932 case 'blog': 5730 $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");5933 $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" ); 5731 5934 break; 5732 5935 case 'server': 5733 5936 $add_seconds_server = date( 'Z' ); 5734 $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");5937 $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" ); 5735 5938 break; 5736 5939 } … … 5753 5956 */ 5754 5957 function update_post_cache( &$posts ) { 5755 if ( ! $posts ) 5958 if ( ! $posts ) { 5756 5959 return; 5757 5758 foreach ( $posts as $post ) 5960 } 5961 5962 foreach ( $posts as $post ) { 5759 5963 wp_cache_add( $post->ID, $post, 'posts' ); 5964 } 5760 5965 } 5761 5966 … … 5778 5983 global $_wp_suspend_cache_invalidation; 5779 5984 5780 if ( ! empty( $_wp_suspend_cache_invalidation ) ) 5985 if ( ! empty( $_wp_suspend_cache_invalidation ) ) { 5781 5986 return; 5987 } 5782 5988 5783 5989 $post = get_post( $post ); 5784 if ( empty( $post ) ) 5990 if ( empty( $post ) ) { 5785 5991 return; 5992 } 5786 5993 5787 5994 wp_cache_delete( $post->ID, 'posts' ); … … 5830 6037 function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) { 5831 6038 // No point in doing all this work if we didn't match any posts. 5832 if ( ! $posts )6039 if ( ! $posts ) { 5833 6040 return; 5834 5835 update_post_cache($posts); 6041 } 6042 6043 update_post_cache( $posts ); 5836 6044 5837 6045 $post_ids = array(); 5838 foreach ( $posts as $post ) 6046 foreach ( $posts as $post ) { 5839 6047 $post_ids[] = $post->ID; 5840 5841 if ( ! $post_type ) 6048 } 6049 6050 if ( ! $post_type ) { 5842 6051 $post_type = 'any'; 6052 } 5843 6053 5844 6054 if ( $update_term_cache ) { 5845 if ( is_array( $post_type) ) {6055 if ( is_array( $post_type ) ) { 5846 6056 $ptypes = $post_type; 5847 6057 } elseif ( 'any' == $post_type ) { … … 5851 6061 $ptypes[] = $post->post_type; 5852 6062 } 5853 $ptypes = array_unique( $ptypes);6063 $ptypes = array_unique( $ptypes ); 5854 6064 } else { 5855 $ptypes = array($post_type); 5856 } 5857 5858 if ( ! empty($ptypes) ) 5859 update_object_term_cache($post_ids, $ptypes); 5860 } 5861 5862 if ( $update_meta_cache ) 5863 update_postmeta_cache($post_ids); 6065 $ptypes = array( $post_type ); 6066 } 6067 6068 if ( ! empty( $ptypes ) ) { 6069 update_object_term_cache( $post_ids, $ptypes ); 6070 } 6071 } 6072 6073 if ( $update_meta_cache ) { 6074 update_postmeta_cache( $post_ids ); 6075 } 5864 6076 } 5865 6077 … … 5878 6090 */ 5879 6091 function update_postmeta_cache( $post_ids ) { 5880 return update_meta_cache( 'post', $post_ids);6092 return update_meta_cache( 'post', $post_ids ); 5881 6093 } 5882 6094 … … 5899 6111 global $_wp_suspend_cache_invalidation; 5900 6112 5901 if ( ! empty($_wp_suspend_cache_invalidation) )6113 if ( ! empty( $_wp_suspend_cache_invalidation ) ) { 5902 6114 return; 6115 } 5903 6116 5904 6117 $id = (int) $id; 5905 6118 5906 wp_cache_delete($id, 'posts'); 5907 wp_cache_delete($id, 'post_meta'); 5908 5909 if ( $clean_terms ) 5910 clean_object_term_cache($id, 'attachment'); 6119 wp_cache_delete( $id, 'posts' ); 6120 wp_cache_delete( $id, 'post_meta' ); 6121 6122 if ( $clean_terms ) { 6123 clean_object_term_cache( $id, 'attachment' ); 6124 } 5911 6125 5912 6126 /** … … 5942 6156 if ( $old_status != 'publish' && $new_status == 'publish' ) { 5943 6157 // Reset GUID if transitioning to publish and it is empty. 5944 if ( '' == get_the_guid( $post->ID) )6158 if ( '' == get_the_guid( $post->ID ) ) { 5945 6159 $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) ); 6160 } 5946 6161 5947 6162 /** … … 5953 6168 * @param int $post_id Post ID. 5954 6169 */ 5955 do_action( 'private_to_published', $post->ID);6170 do_action( 'private_to_published', $post->ID ); 5956 6171 } 5957 6172 5958 6173 // If published posts changed clear the lastpostmodified cache. 5959 if ( 'publish' == $new_status || 'publish' == $old_status ) {6174 if ( 'publish' == $new_status || 'publish' == $old_status ) { 5960 6175 foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { 5961 6176 wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' ); … … 5971 6186 5972 6187 // Always clears the hook in case the post status bounced from future to draft. 5973 wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );6188 wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); 5974 6189 } 5975 6190 … … 5989 6204 function _future_post_hook( $deprecated, $post ) { 5990 6205 wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); 5991 wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT' ), 'publish_future_post', array( $post->ID ) );6206 wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT' ), 'publish_future_post', array( $post->ID ) ); 5992 6207 } 5993 6208 … … 6014 6229 } 6015 6230 6016 if ( defined( 'WP_IMPORTING') )6231 if ( defined( 'WP_IMPORTING' ) ) { 6017 6232 return; 6018 6019 if ( get_option('default_pingback_flag') ) 6233 } 6234 6235 if ( get_option( 'default_pingback_flag' ) ) { 6020 6236 add_post_meta( $post_id, '_pingme', '1' ); 6237 } 6021 6238 add_post_meta( $post_id, '_encloseme', '1' ); 6022 6239 … … 6037 6254 function wp_get_post_parent_id( $post_ID ) { 6038 6255 $post = get_post( $post_ID ); 6039 if ( ! $post || is_wp_error( $post ) )6256 if ( ! $post || is_wp_error( $post ) ) { 6040 6257 return false; 6258 } 6041 6259 return (int) $post->post_parent; 6042 6260 } … … 6058 6276 function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) { 6059 6277 // Nothing fancy here - bail. 6060 if ( ! $post_parent )6278 if ( ! $post_parent ) { 6061 6279 return 0; 6280 } 6062 6281 6063 6282 // New post can't cause a loop. 6064 if ( empty( $post_ID ) ) 6283 if ( empty( $post_ID ) ) { 6065 6284 return $post_parent; 6285 } 6066 6286 6067 6287 // Can't be its own parent. 6068 if ( $post_parent == $post_ID ) 6288 if ( $post_parent == $post_ID ) { 6069 6289 return 0; 6290 } 6070 6291 6071 6292 // Now look for larger loops. 6072 if ( ! $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) )6293 if ( ! $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) { 6073 6294 return $post_parent; // No loop 6295 } 6074 6296 6075 6297 // Setting $post_parent to the given value causes a loop. 6076 if ( isset( $loop[ $post_ID] ) )6298 if ( isset( $loop[ $post_ID ] ) ) { 6077 6299 return 0; 6300 } 6078 6301 6079 6302 // There's a loop, but it doesn't contain $post_ID. Break the loop. 6080 foreach ( array_keys( $loop ) as $loop_member ) 6081 wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) ); 6303 foreach ( array_keys( $loop ) as $loop_member ) { 6304 wp_update_post( 6305 array( 6306 'ID' => $loop_member, 6307 'post_parent' => 0, 6308 ) 6309 ); 6310 } 6082 6311 6083 6312 return $post_parent; … … 6094 6323 */ 6095 6324 function set_post_thumbnail( $post, $thumbnail_id ) { 6096 $post = get_post( $post );6325 $post = get_post( $post ); 6097 6326 $thumbnail_id = absint( $thumbnail_id ); 6098 6327 if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) { 6099 if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) 6328 if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) { 6100 6329 return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); 6101 else6330 } else { 6102 6331 return delete_post_meta( $post->ID, '_thumbnail_id' ); 6332 } 6103 6333 } 6104 6334 return false; … … 6115 6345 function delete_post_thumbnail( $post ) { 6116 6346 $post = get_post( $post ); 6117 if ( $post ) 6347 if ( $post ) { 6118 6348 return delete_post_meta( $post->ID, '_thumbnail_id' ); 6349 } 6119 6350 return false; 6120 6351 } … … 6214 6445 6215 6446 $non_cached_ids = _get_non_cached_ids( $ids, 'posts' ); 6216 if ( ! empty( $non_cached_ids ) ) {6217 $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) );6447 if ( ! empty( $non_cached_ids ) ) { 6448 $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ',', $non_cached_ids ) ) ); 6218 6449 6219 6450 update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache ); … … 6236 6467 */ 6237 6468 function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID = 0 ) { 6238 $trashed_posts_with_desired_slug = get_posts( array( 6239 'name' => $post_name, 6240 'post_status' => 'trash', 6241 'post_type' => 'any', 6242 'nopaging' => true, 6243 'post__not_in' => array( $post_ID ) 6244 ) ); 6469 $trashed_posts_with_desired_slug = get_posts( 6470 array( 6471 'name' => $post_name, 6472 'post_status' => 'trash', 6473 'post_type' => 'any', 6474 'nopaging' => true, 6475 'post__not_in' => array( $post_ID ), 6476 ) 6477 ); 6245 6478 6246 6479 if ( ! empty( $trashed_posts_with_desired_slug ) ) { … … 6303 6536 $clauses['where'] = preg_replace( 6304 6537 "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/", 6305 "$0 OR ( sq1.meta_value $1 $2 )", 6306 $clauses['where'] ); 6538 '$0 OR ( sq1.meta_value $1 $2 )', 6539 $clauses['where'] 6540 ); 6307 6541 6308 6542 return $clauses;
Note: See TracChangeset
for help on using the changeset viewer.