Changeset 29094
- Timestamp:
- 07/11/2014 11:15:49 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r29093 r29094 4723 4723 4724 4724 /** 4725 * Trash es or deletesan attachment.4725 * Trash or delete an attachment. 4726 4726 * 4727 4727 * When an attachment is permanently deleted, the file will also be removed. … … 4733 4733 * 4734 4734 * @since 2.0.0 4735 * @uses $wpdb 4736 * 4737 * @param int $post_id Attachment ID. 4738 * @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false. 4735 * 4736 * @global wpdb $wpdb WordPress database access abstraction object. 4737 * 4738 * @param int $post_id Attachment ID. 4739 * @param bool $force_delete Optional. Whether to bypass trash and force deletion. 4740 * Default false. 4739 4741 * @return mixed False on failure. Post data on success. 4740 4742 */ … … 4801 4803 4802 4804 if ( ! empty($meta['thumb']) ) { 4803 // Don't delete the thumb if another attachment uses it 4805 // Don't delete the thumb if another attachment uses it. 4804 4806 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)) ) { 4805 4807 $thumbfile = str_replace(basename($file), $meta['thumb'], $file); … … 4810 4812 } 4811 4813 4812 // remove intermediate and backup images if there are any4814 // Remove intermediate and backup images if there are any. 4813 4815 foreach ( $intermediate_sizes as $intermediate ) { 4814 4816 /** This filter is documented in wp-admin/custom-header.php */ … … 4842 4844 * @since 2.1.0 4843 4845 * 4844 * @param int $post_idAttachment ID. Default 0.4845 * @param bool $unfiltered Optional , default is false. If true, filters are not run.4846 * @param int $post_id Attachment ID. Default 0. 4847 * @param bool $unfiltered Optional. If true, filters are not run. Default false. 4846 4848 * @return string|bool Attachment meta field. False on failure. 4847 4849 */ … … 4873 4875 * @since 2.1.0 4874 4876 * 4875 * @param int $post_id Attachment ID.4876 * @param array $data Attachment data.4877 * @return int 4877 * @param int $post_id Attachment ID. 4878 * @param array $data Attachment data. 4879 * @return int|bool False if $post is invalid. 4878 4880 */ 4879 4881 function wp_update_attachment_metadata( $post_id, $data ) { … … 4902 4904 * 4903 4905 * @param int $post_id Optional. Attachment ID. Default 0. 4904 * @return string 4906 * @return string|bool Attachment URL, otherwise false. 4905 4907 */ 4906 4908 function wp_get_attachment_url( $post_id = 0 ) { … … 4913 4915 4914 4916 $url = ''; 4915 if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file 4916 if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory 4917 if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location 4918 $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location 4919 elseif ( false !== strpos($file, 'wp-content/uploads') ) 4917 // Get attached file. 4918 if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { 4919 // Get upload directory. 4920 if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { 4921 // Check that the upload base exists in the file location. 4922 if ( 0 === strpos( $file, $uploads['basedir'] ) ) { 4923 // Replace file location with url location. 4924 $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); 4925 } elseif ( false !== strpos($file, 'wp-content/uploads') ) { 4920 4926 $url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 ); 4921 else 4922 $url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir. 4923 } 4924 } 4925 4926 if ( empty($url) ) //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recommended to rely upon this. 4927 } else { 4928 // It's a newly-uploaded file, therefore $file is relative to the basedir. 4929 $url = $uploads['baseurl'] . "/$file"; 4930 } 4931 } 4932 } 4933 4934 /* 4935 * If any of the above options failed, Fallback on the GUID as used pre-2.7, 4936 * not recommended to rely upon this. 4937 */ 4938 if ( empty($url) ) { 4927 4939 $url = get_the_guid( $post->ID ); 4940 } 4928 4941 4929 4942 /** … … 5040 5053 * 5041 5054 * @param string|int $mime MIME type or attachment ID. 5042 * @return string|bool 5055 * @return string|bool Icon, false otherwise. 5043 5056 */ 5044 5057 function wp_mime_type_icon( $mime = 0 ) { … … 5119 5132 } 5120 5133 5121 // Icon basename - extension = MIME wildcard 5134 // Icon basename - extension = MIME wildcard. 5122 5135 foreach ( $icon_files as $file => $uri ) 5123 5136 $types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file]; … … 5156 5169 5157 5170 /** 5158 * Check edfor changed slugs for published post objects and save the old slug.5171 * Check for changed slugs for published post objects and save the old slug. 5159 5172 * 5160 5173 * The function is used when a post object of any type is updated, … … 5170 5183 * @since 2.1.0 5171 5184 * 5172 * @param int $post_idPost ID.5173 * @param object $postThe Post Object5174 * @param object $post_before The Previous Post Object5185 * @param int $post_id Post ID. 5186 * @param WP_Post $post The Post Object 5187 * @param WP_Post $post_before The Previous Post Object 5175 5188 * @return int Same as $post_id 5176 5189 */ 5177 function wp_check_for_changed_slugs( $post_id, $post, $post_before) {5178 // dont bother if it hasnt changed5190 function wp_check_for_changed_slugs( $post_id, $post, $post_before ) { 5191 // Don't bother if it hasnt changed. 5179 5192 if ( $post->post_name == $post_before->post_name ) 5180 5193 return; 5181 5194 5182 // we're only concerned with published, non-hierarchical objects5195 // We're only concerned with published, non-hierarchical objects. 5183 5196 if ( $post->post_status != 'publish' || is_post_type_hierarchical( $post->post_type ) ) 5184 5197 return; … … 5186 5199 $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug'); 5187 5200 5188 // if we haven't added this old slug before, add it now5201 // If we haven't added this old slug before, add it now. 5189 5202 if ( !empty( $post_before->post_name ) && !in_array($post_before->post_name, $old_slugs) ) 5190 5203 add_post_meta($post_id, '_wp_old_slug', $post_before->post_name); 5191 5204 5192 // if the new slug was used previously, delete it from the list5205 // If the new slug was used previously, delete it from the list. 5193 5206 if ( in_array($post->post_name, $old_slugs) ) 5194 5207 delete_post_meta($post_id, '_wp_old_slug', $post->post_name); … … 5205 5218 * @since 2.2.0 5206 5219 * 5207 * @param string $post_type currently only supports 'post' or 'page'.5220 * @param string $post_type Post type. Currently only supports 'post' or 'page'. 5208 5221 * @return string SQL code that can be added to a where clause. 5209 5222 */ … … 5215 5228 * Retrieve the post SQL based on capability, author, and type. 5216 5229 * 5230 * @since 3.0.0 5231 * 5217 5232 * @see get_private_posts_cap_sql() 5218 5233 * 5219 * @since 3.0.0 5220 * @param string $post_type Post type. 5221 * @param bool $full Optional. Returns a full WHERE statement instead of just an 'andalso' term. 5222 * @param int $post_author Optional. Query posts having a single author ID. 5223 * @param bool $public_only Optional. Only return public posts. Skips cap checks for $current_user. Default is false. 5234 * @param string $post_type Post type. 5235 * @param bool $full Optional. Returns a full WHERE statement instead of just 5236 * an 'andalso' term. Default true. 5237 * @param int $post_author Optional. Query posts having a single author ID. Default null. 5238 * @param bool $public_only Optional. Only return public posts. Skips cap checks for 5239 * $current_user. Default false. 5224 5240 * @return string SQL WHERE code that can be added to a query. 5225 5241 */ … … 5227 5243 global $wpdb; 5228 5244 5229 // Private posts 5245 // Private posts. 5230 5246 $post_type_obj = get_post_type_object( $post_type ); 5231 5247 if ( ! $post_type_obj ) … … 5287 5303 * @since 0.71 5288 5304 * 5289 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. 5305 * @param string $timezone The location to get the time. Accepts 'gmt', 'blog', 5306 * or 'server'. Default 'server'. 5290 5307 * @return string The date of the last post. 5291 5308 */ 5292 function get_lastpostdate( $timezone = 'server') {5309 function get_lastpostdate( $timezone = 'server' ) { 5293 5310 /** 5294 5311 * Filter the date the last post was published. … … 5312 5329 * @since 1.2.0 5313 5330 * 5314 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. 5331 * @param string $timezone The location to get the time. Accepts 'gmt', 'blog', or 'server'. 5332 * Default 'server'. 5315 5333 * @return string The date the post was last modified. 5316 5334 */ 5317 function get_lastpostmodified( $timezone = 'server') {5335 function get_lastpostmodified( $timezone = 'server' ) { 5318 5336 $lastpostmodified = _get_last_post_time( $timezone, 'modified' ); 5319 5337 … … 5339 5357 * @since 3.1.0 5340 5358 * 5341 * @param string $timezone The location to get the time. Can be'gmt', 'blog', or 'server'.5359 * @param string $timezone The location to get the time. Accepts 'gmt', 'blog', or 'server'. 5342 5360 * @param string $field Field to check. Can be 'date' or 'modified'. 5343 5361 * @return string The date. … … 5386 5404 * @since 1.5.1 5387 5405 * 5388 * @param array $posts Array of post objects 5406 * @param array $posts Array of post objects, passed by reference. 5389 5407 */ 5390 5408 function update_post_cache( &$posts ) { … … 5406 5424 * 5407 5425 * @since 2.0.0 5426 * 5427 * @global wpdb $wpdb WordPress database access abstraction object. 5408 5428 * 5409 5429 * @param int|WP_Post $post Post ID or post object to remove from the cache. … … 5457 5477 * @since 1.5.0 5458 5478 * 5459 * @uses update_post_cache() 5460 * @uses update_object_term_cache() 5461 * @uses update_postmeta_cache() 5462 * 5463 * @param array $posts Array of Post objects 5464 * @param string $post_type The post type of the posts in $posts. Default is 'post'. 5465 * @param bool $update_term_cache Whether to update the term cache. Default is true. 5466 * @param bool $update_meta_cache Whether to update the meta cache. Default is true. 5467 */ 5468 function update_post_caches(&$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true) { 5479 * @param array $posts Array of Post objects 5480 * @param string $post_type Optional. Post type. Default 'post'. 5481 * @param bool $update_term_cache Optional. Whether to update the term cache. Default true. 5482 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 5483 */ 5484 function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) { 5469 5485 // No point in doing all this work if we didn't match any posts. 5470 5486 if ( !$posts ) … … 5510 5526 * 5511 5527 * @param array $post_ids List of post IDs. 5512 * @return bool|array Returns false if there is nothing to update or an array of metadata. 5513 */ 5514 function update_postmeta_cache($post_ids) { 5528 * @return bool|array Returns false if there is nothing to update or an array 5529 * of metadata. 5530 */ 5531 function update_postmeta_cache( $post_ids ) { 5515 5532 return update_meta_cache('post', $post_ids); 5516 5533 } … … 5522 5539 * object cache associated with the attachment ID. 5523 5540 * 5524 * This function will not run if $_wp_suspend_cache_invalidation is not empty. See 5525 * wp_suspend_cache_invalidation(). 5541 * This function will not run if $_wp_suspend_cache_invalidation is not empty. 5526 5542 * 5527 5543 * @since 3.0.0 5528 5544 * 5529 * @param int $id The attachment ID in the cache to clean 5530 * @param bool $clean_terms optional. Whether to clean terms cache 5531 */ 5532 function clean_attachment_cache($id, $clean_terms = false) { 5545 * @see wp_suspend_cache_invalidation() 5546 * 5547 * @param int $id The attachment ID in the cache to clean. 5548 * @param bool $clean_terms Optional. Whether to clean terms cache. Default false. 5549 */ 5550 function clean_attachment_cache( $id, $clean_terms = false ) { 5533 5551 global $_wp_suspend_cache_invalidation; 5534 5552 … … 5563 5581 * @since 2.3.0 5564 5582 * @access private 5565 * @uses $wpdb 5566 * @uses wp_clear_scheduled_hook() with 'publish_future_post' and post ID. 5567 * 5568 * @param string $new_status New post status 5569 * @param string $old_status Previous post status 5570 * @param object $post Object type containing the post information 5571 */ 5572 function _transition_post_status($new_status, $old_status, $post) { 5583 * 5584 * @see wp_clear_scheduled_hook() 5585 * @global wpdb $wpdb WordPress database access abstraction object. 5586 * 5587 * @param string $new_status New post status. 5588 * @param string $old_status Previous post status. 5589 * @param WP_Post $post Post object. 5590 */ 5591 function _transition_post_status( $new_status, $old_status, $post ) { 5573 5592 global $wpdb; 5574 5593 … … 5614 5633 * @access private 5615 5634 * 5616 * @param int $deprecated Not used. Can be set to null. Never implemented. 5617 * Not marked as deprecated with _deprecated_argument() as it conflicts with 5618 * wp_transition_post_status() and the default filter for _future_post_hook(). 5619 * @param object $post Object type containing the post information 5635 * @param int $deprecated Not used. Can be set to null. Never implemented. Not marked 5636 * as deprecated with _deprecated_argument() as it conflicts with 5637 * wp_transition_post_status() and the default filter for 5638 * {@see _future_post_hook()}. 5639 * @param WP_Post $post Post object. 5620 5640 */ 5621 5641 function _future_post_hook( $deprecated, $post ) { … … 5627 5647 * Hook to schedule pings and enclosures when a post is published. 5628 5648 * 5649 * Uses XMLRPC_REQUEST and WP_IMPORTING constants. 5650 * 5629 5651 * @since 2.3.0 5630 5652 * @access private 5631 * @uses XMLRPC_REQUEST and WP_IMPORTING constants. 5632 * 5633 * @param int $post_id The ID in the database table of the post being published 5634 */ 5635 function _publish_post_hook($post_id) { 5653 * 5654 * @param int $post_id The ID in the database table of the post being published. 5655 */ 5656 function _publish_post_hook( $post_id ) { 5636 5657 if ( defined( 'XMLRPC_REQUEST' ) ) { 5637 5658 /** … … 5656 5677 5657 5678 /** 5658 * Return sthe post's parent's post_ID5679 * Return the post's parent's post_ID 5659 5680 * 5660 5681 * @since 3.1.0 … … 5662 5683 * @param int $post_id 5663 5684 * 5664 * @return int|bool false on error5685 * @return int|bool Post parent ID, otherwise false. 5665 5686 */ 5666 5687 function wp_get_post_parent_id( $post_ID ) { … … 5672 5693 5673 5694 /** 5674 * Check sthe given subset of the post hierarchy for hierarchy loops.5675 * Prevents loops from forming and breaks those that it finds.5676 * 5677 * Attached to the wp_insert_post_parentfilter.5695 * Check the given subset of the post hierarchy for hierarchy loops. 5696 * 5697 * Prevents loops from forming and breaks those that it finds. Attached 5698 * to the 'wp_insert_post_parent' filter. 5678 5699 * 5679 5700 * @since 3.1.0 5680 * @uses wp_find_hierarchy_loop() 5701 * 5702 * @see wp_find_hierarchy_loop() 5681 5703 * 5682 5704 * @param int $post_parent ID of the parent for the post we're checking. 5683 * @param int $post_ID ID of the post we're checking. 5684 * 5685 * @return int The new post_parent for the post. 5705 * @param int $post_ID ID of the post we're checking. 5706 * @return int The new post_parent for the post, 0 otherwise. 5686 5707 */ 5687 5708 function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) { … … 5715 5736 5716 5737 /** 5717 * Set sa post thumbnail.5738 * Set a post thumbnail. 5718 5739 * 5719 5740 * @since 3.1.0 5720 5741 * 5721 * @param int|WP_Post $post Post ID or post object where thumbnail should be attached.5722 * @param int $thumbnail_id Thumbnail to attach.5742 * @param int|WP_Post $post Post ID or post object where thumbnail should be attached. 5743 * @param int $thumbnail_id Thumbnail to attach. 5723 5744 * @return bool True on success, false on failure. 5724 5745 */ … … 5736 5757 5737 5758 /** 5738 * Remove sa post thumbnail.5759 * Remove a post thumbnail. 5739 5760 * 5740 5761 * @since 3.3.0 … … 5751 5772 5752 5773 /** 5753 * Delete s auto-drafts for new posts that are > 7 days old5774 * Delete auto-drafts for new posts that are > 7 days old. 5754 5775 * 5755 5776 * @since 3.4.0 5777 * 5778 * @global wpdb $wpdb WordPress database access abstraction object. 5756 5779 */ 5757 5780 function wp_delete_auto_drafts() { 5758 5781 global $wpdb; 5759 5782 5760 // Cleanup old auto-drafts more than 7 days old 5783 // Cleanup old auto-drafts more than 7 days old. 5761 5784 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); 5762 foreach ( (array) $old_posts as $delete ) 5763 wp_delete_post( $delete, true ); // Force delete 5785 foreach ( (array) $old_posts as $delete ) { 5786 // Force delete. 5787 wp_delete_post( $delete, true ); 5788 } 5764 5789 } 5765 5790 … … 5767 5792 * Update the custom taxonomies' term counts when a post's status is changed. For example, default posts term counts (for custom taxonomies) don't include private / draft posts. 5768 5793 * 5794 * @since 3.3.0 5769 5795 * @access private 5770 * @param string $new_status5771 * @param string $old_status5772 * @param object $post5773 * @ since 3.3.05796 * 5797 * @param string $new_status New post status. 5798 * @param string $old_status Old post status. 5799 * @param WP_Post $post Post object. 5774 5800 */ 5775 5801 function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) { … … 5788 5814 * @access private 5789 5815 * 5790 * @param array $post_ids ID list5791 * @param bool $update_term_cache Whether to update the term cache. Default istrue.5792 * @param bool $update_meta_cache Whether to update the meta cache. Default istrue.5816 * @param array $post_ids ID list 5817 * @param bool $update_term_cache Optional. Whether to update the term cache. Default true. 5818 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 5793 5819 */ 5794 5820 function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) { … … 5802 5828 } 5803 5829 } 5804 5805
Note: See TracChangeset
for help on using the changeset viewer.