Changeset 45590 for trunk/src/wp-includes/post.php
- Timestamp:
- 07/02/2019 11:41:16 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r45424 r45590 454 454 455 455 // If the file is relative, prepend upload dir. 456 if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) && ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) ) { 457 $file = $uploads['basedir'] . "/$file"; 456 if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) ) { 457 $uploads = wp_get_upload_dir(); 458 if ( false === $uploads['error'] ) { 459 $file = $uploads['basedir'] . "/$file"; 460 } 458 461 } 459 462 … … 500 503 $file = apply_filters( 'update_attached_file', $file, $attachment_id ); 501 504 502 if ( $file = _wp_relative_upload_path( $file ) ) { 505 $file = _wp_relative_upload_path( $file ); 506 if ( $file ) { 503 507 return update_post_meta( $attachment_id, '_wp_attached_file', $file ); 504 508 } else { … … 756 760 $ancestors = array(); 757 761 758 $id = $ancestors[] = $post->post_parent; 762 $id = $post->post_parent; 763 $ancestors[] = $id; 759 764 760 765 while ( $ancestor = get_post( $id ) ) { … … 764 769 } 765 770 766 $id = $ancestors[] = $ancestor->post_parent; 771 $id = $ancestor->post_parent; 772 $ancestors[] = $id; 767 773 } 768 774 … … 1149 1155 */ 1150 1156 function get_post_type( $post = null ) { 1151 if ( $post = get_post( $post ) ) { 1157 $post = get_post( $post ); 1158 if ( $post ) { 1152 1159 return $post->post_type; 1153 1160 } … … 2155 2162 } 2156 2163 2157 if ( $keys = array_keys( $custom ) ) { 2164 $keys = array_keys( $custom ); 2165 if ( $keys ) { 2158 2166 return $keys; 2159 2167 } … … 4052 4060 global $wpdb; 4053 4061 4054 if ( ! $post = get_post( $post ) ) { 4062 $post = get_post( $post ); 4063 if ( ! $post ) { 4055 4064 return; 4056 4065 } … … 4228 4237 $post = get_post( $post_ID ); 4229 4238 $conflicts_with_date_archive = false; 4230 if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) { 4231 $permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) ); 4232 $postname_index = array_search( '%postname%', $permastructs ); 4233 4234 /* 4235 * Potential date clashes are as follows: 4236 * 4237 * - Any integer in the first permastruct position could be a year. 4238 * - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'. 4239 * - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'. 4240 */ 4241 if ( 0 === $postname_index || 4242 ( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && 13 > $slug_num ) || 4243 ( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && 32 > $slug_num ) 4244 ) { 4245 $conflicts_with_date_archive = true; 4239 if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) ) { 4240 $slug_num = intval( $slug ); 4241 4242 if ( $slug_num ) { 4243 $permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) ); 4244 $postname_index = array_search( '%postname%', $permastructs ); 4245 4246 /* 4247 * Potential date clashes are as follows: 4248 * 4249 * - Any integer in the first permastruct position could be a year. 4250 * - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'. 4251 * - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'. 4252 */ 4253 if ( 0 === $postname_index || 4254 ( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && 13 > $slug_num ) || 4255 ( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && 32 > $slug_num ) 4256 ) { 4257 $conflicts_with_date_archive = true; 4258 } 4246 4259 } 4247 4260 } … … 5321 5334 return true; 5322 5335 } 5323 if ( $id = url_to_postid( $url ) ) { 5336 5337 $id = url_to_postid( $url ); 5338 if ( $id ) { 5324 5339 $post = get_post( $id ); 5325 5340 if ( 'attachment' == $post->post_type ) { … … 5545 5560 function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) { 5546 5561 $attachment_id = (int) $attachment_id; 5547 if ( ! $post = get_post( $attachment_id ) ) { 5562 $post = get_post( $attachment_id ); 5563 if ( ! $post ) { 5548 5564 return false; 5549 5565 } … … 5578 5594 function wp_update_attachment_metadata( $attachment_id, $data ) { 5579 5595 $attachment_id = (int) $attachment_id; 5580 if ( ! $post = get_post( $attachment_id ) ) { 5596 $post = get_post( $attachment_id ); 5597 if ( ! $post ) { 5581 5598 return false; 5582 5599 } … … 5590 5607 * @param int $attachment_id Attachment post ID. 5591 5608 */ 5592 if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) { 5609 $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ); 5610 if ( $data ) { 5593 5611 return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); 5594 5612 } else { … … 5609 5627 function wp_get_attachment_url( $attachment_id = 0 ) { 5610 5628 $attachment_id = (int) $attachment_id; 5611 if ( ! $post = get_post( $attachment_id ) ) { 5629 $post = get_post( $attachment_id ); 5630 if ( ! $post ) { 5612 5631 return false; 5613 5632 } … … 5619 5638 $url = ''; 5620 5639 // Get attached file. 5621 if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true ) ) { 5640 $file = get_post_meta( $post->ID, '_wp_attached_file', true ); 5641 if ( $file ) { 5622 5642 // Get upload directory. 5623 if ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) { 5643 $uploads = wp_get_upload_dir(); 5644 if ( $uploads && false === $uploads['error'] ) { 5624 5645 // Check that the upload base exists in the file location. 5625 5646 if ( 0 === strpos( $file, $uploads['basedir'] ) ) { … … 5676 5697 function wp_get_attachment_caption( $post_id = 0 ) { 5677 5698 $post_id = (int) $post_id; 5678 if ( ! $post = get_post( $post_id ) ) { 5699 $post = get_post( $post_id ); 5700 if ( ! $post ) { 5679 5701 return false; 5680 5702 } … … 5707 5729 function wp_get_attachment_thumb_file( $post_id = 0 ) { 5708 5730 $post_id = (int) $post_id; 5709 if ( ! $post = get_post( $post_id ) ) { 5731 $post = get_post( $post_id ); 5732 if ( ! $post ) { 5710 5733 return false; 5711 5734 } 5712 if ( ! is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) { 5735 5736 $imagedata = wp_get_attachment_metadata( $post->ID ); 5737 if ( ! is_array( $imagedata ) ) { 5713 5738 return false; 5714 5739 } … … 5716 5741 $file = get_attached_file( $post->ID ); 5717 5742 5718 if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) { 5719 /** 5720 * Filters the attachment thumbnail file path. 5721 * 5722 * @since 2.1.0 5723 * 5724 * @param string $thumbfile File path to the attachment thumbnail. 5725 * @param int $post_id Attachment ID. 5726 */ 5727 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID ); 5743 if ( ! empty( $imagedata['thumb'] ) ) { 5744 $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ); 5745 if ( file_exists( $thumbfile ) ) { 5746 /** 5747 * Filters the attachment thumbnail file path. 5748 * 5749 * @since 2.1.0 5750 * 5751 * @param string $thumbfile File path to the attachment thumbnail. 5752 * @param int $post_id Attachment ID. 5753 */ 5754 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID ); 5755 } 5728 5756 } 5729 5757 return false; … … 5740 5768 function wp_get_attachment_thumb_url( $post_id = 0 ) { 5741 5769 $post_id = (int) $post_id; 5742 if ( ! $post = get_post( $post_id ) ) { 5770 $post = get_post( $post_id ); 5771 if ( ! $post ) { 5743 5772 return false; 5744 5773 } 5745 if ( ! $url = wp_get_attachment_url( $post->ID ) ) { 5774 5775 $url = wp_get_attachment_url( $post->ID ); 5776 if ( ! $url ) { 5746 5777 return false; 5747 5778 } … … 5752 5783 } 5753 5784 5754 if ( ! $thumb = wp_get_attachment_thumb_file( $post->ID ) ) { 5785 $thumb = wp_get_attachment_thumb_file( $post->ID ); 5786 if ( ! $thumb ) { 5755 5787 return false; 5756 5788 } … … 5779 5811 */ 5780 5812 function wp_attachment_is( $type, $post = null ) { 5781 if ( ! $post = get_post( $post ) ) { 5813 $post = get_post( $post ); 5814 if ( ! $post ) { 5782 5815 return false; 5783 5816 } 5784 5817 5785 if ( ! $file = get_attached_file( $post->ID ) ) { 5818 $file = get_attached_file( $post->ID ); 5819 if ( ! $file ) { 5786 5820 return false; 5787 5821 } … … 5854 5888 if ( is_numeric( $mime ) ) { 5855 5889 $mime = (int) $mime; 5856 if ( $post = get_post( $mime ) ) { 5890 $post = get_post( $mime ); 5891 if ( $post ) { 5857 5892 $post_id = (int) $post->ID; 5858 5893 $file = get_attached_file( $post_id ); … … 5860 5895 if ( ! empty( $ext ) ) { 5861 5896 $post_mimes[] = $ext; 5862 if ( $ext_type = wp_ext2type( $ext ) ) { 5897 $ext_type = wp_ext2type( $ext ); 5898 if ( $ext_type ) { 5863 5899 $post_mimes[] = $ext_type; 5864 5900 } … … 5906 5942 $dir = array_shift( $keys ); 5907 5943 $uri = array_shift( $dirs ); 5908 if ( $dh = opendir( $dir ) ) { 5944 $dh = opendir( $dir ); 5945 if ( $dh ) { 5909 5946 while ( false !== $file = readdir( $dh ) ) { 5910 5947 $file = wp_basename( $file ); … … 6113 6150 * @param string $cap Capability. 6114 6151 */ 6115 if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) ) { 6152 $cap = apply_filters( 'pub_priv_sql_capability', '' ); 6153 if ( ! $cap ) { 6116 6154 $cap = current_user_can( $post_type_obj->cap->read_private_posts ); 6117 6155 } … … 6643 6681 6644 6682 // Now look for larger loops. 6645 if ( ! $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) { 6683 $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ); 6684 if ( ! $loop ) { 6646 6685 return $post_parent; // No loop 6647 6686 } … … 6729 6768 */ 6730 6769 function wp_queue_posts_for_term_meta_lazyload( $posts ) { 6731 $post_type_taxonomies = $term_ids = array(); 6770 $post_type_taxonomies = array(); 6771 $term_ids = array(); 6732 6772 foreach ( $posts as $post ) { 6733 6773 if ( ! ( $post instanceof WP_Post ) ) {
Note: See TracChangeset
for help on using the changeset viewer.