Changeset 47808 for trunk/src/wp-includes/post.php
- Timestamp:
- 05/16/2020 06:40:52 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r47633 r47808 770 770 $_post = sanitize_post( $post, 'raw' ); 771 771 $_post = new WP_Post( $_post ); 772 } elseif ( 'raw' == $post->filter ) {772 } elseif ( 'raw' === $post->filter ) { 773 773 $_post = new WP_Post( $post ); 774 774 } else { … … 900 900 } 901 901 902 if ( 'attachment' == $post->post_type ) {903 if ( 'private' == $post->post_status ) {902 if ( 'attachment' === $post->post_type ) { 903 if ( 'private' === $post->post_status ) { 904 904 return 'private'; 905 905 } 906 906 907 907 // Unattached attachments are assumed to be published. 908 if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent ) ) {908 if ( ( 'inherit' === $post->post_status ) && ( 0 == $post->post_parent ) ) { 909 909 return 'publish'; 910 910 } … … 913 913 if ( $post->post_parent && ( $post->ID != $post->post_parent ) ) { 914 914 $parent_post_status = get_post_status( $post->post_parent ); 915 if ( 'trash' == $parent_post_status ) {915 if ( 'trash' === $parent_post_status ) { 916 916 return get_post_meta( $post->post_parent, '_wp_trash_meta_status', true ); 917 917 } else { … … 1161 1161 global $wp_post_statuses; 1162 1162 1163 $field = ( 'names' == $output ) ? 'name' : false;1163 $field = ( 'names' === $output ) ? 'name' : false; 1164 1164 1165 1165 return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field ); … … 1266 1266 global $wp_post_types; 1267 1267 1268 $field = ( 'names' == $output ) ? 'name' : false;1268 $field = ( 'names' === $output ) ? 'name' : false; 1269 1269 1270 1270 return wp_filter_object_list( $wp_post_types, $args, $operator, $field ); … … 2028 2028 $parsed_args = wp_parse_args( $args, $defaults ); 2029 2029 if ( empty( $parsed_args['post_status'] ) ) { 2030 $parsed_args['post_status'] = ( 'attachment' == $parsed_args['post_type'] ) ? 'inherit' : 'publish';2030 $parsed_args['post_status'] = ( 'attachment' === $parsed_args['post_type'] ) ? 'inherit' : 'publish'; 2031 2031 } 2032 2032 if ( ! empty( $parsed_args['numberposts'] ) && empty( $parsed_args['posts_per_page'] ) ) { … … 2382 2382 } 2383 2383 2384 if ( 'raw' == $context ) {2384 if ( 'raw' === $context ) { 2385 2385 return $value; 2386 2386 } … … 2392 2392 } 2393 2393 2394 if ( 'edit' == $context ) {2394 if ( 'edit' === $context ) { 2395 2395 $format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password' ); 2396 2396 … … 2427 2427 2428 2428 if ( in_array( $field, $format_to_edit, true ) ) { 2429 if ( 'post_content' == $field ) {2429 if ( 'post_content' === $field ) { 2430 2430 $value = format_to_edit( $value, user_can_richedit() ); 2431 2431 } else { … … 2435 2435 $value = esc_attr( $value ); 2436 2436 } 2437 } elseif ( 'db' == $context ) {2437 } elseif ( 'db' === $context ) { 2438 2438 if ( $prefixed ) { 2439 2439 … … 2500 2500 } 2501 2501 2502 if ( 'attribute' == $context ) {2502 if ( 'attribute' === $context ) { 2503 2503 $value = esc_attr( $value ); 2504 } elseif ( 'js' == $context ) {2504 } elseif ( 'js' === $context ) { 2505 2505 $value = esc_js( $value ); 2506 2506 } … … 2603 2603 function _count_posts_cache_key( $type = 'post', $perm = '' ) { 2604 2604 $cache_key = 'posts-' . $type; 2605 if ( 'readable' == $perm && is_user_logged_in() ) { 2605 2606 if ( 'readable' === $perm && is_user_logged_in() ) { 2606 2607 $post_type_object = get_post_type_object( $type ); 2608 2607 2609 if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) { 2608 2610 $cache_key .= '_' . $perm . '_' . get_current_user_id(); 2609 2611 } 2610 2612 } 2613 2611 2614 return $cache_key; 2612 2615 } … … 2647 2650 2648 2651 $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; 2649 if ( 'readable' == $perm && is_user_logged_in() ) { 2652 2653 if ( 'readable' === $perm && is_user_logged_in() ) { 2650 2654 $post_type_object = get_post_type_object( $type ); 2651 2655 if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) { … … 2656 2660 } 2657 2661 } 2662 2658 2663 $query .= ' GROUP BY post_status'; 2659 2664 … … 3115 3120 function _reset_front_page_settings_for_post( $post_id ) { 3116 3121 $post = get_post( $post_id ); 3117 if ( 'page' == $post->post_type ) { 3122 3123 if ( 'page' === $post->post_type ) { 3118 3124 /* 3119 3125 * If the page is defined in option page_on_front or post_for_posts, … … 3128 3134 } 3129 3135 } 3136 3130 3137 unstick_post( $post->ID ); 3131 3138 } … … 3382 3389 foreach ( $group_by_status as $status => $comments ) { 3383 3390 // Sanity check. This shouldn't happen. 3384 if ( 'post-trashed' == $status ) {3391 if ( 'post-trashed' === $status ) { 3385 3392 $status = '0'; 3386 3393 } … … 3705 3712 if ( empty( $post_category ) || 0 == count( $post_category ) || ! is_array( $post_category ) ) { 3706 3713 // 'post' requires at least one category. 3707 if ( 'post' == $post_type && 'auto-draft' != $post_status ) {3714 if ( 'post' === $post_type && 'auto-draft' !== $post_status ) { 3708 3715 $post_category = array( get_option( 'default_category' ) ); 3709 3716 } else { … … 3749 3756 * is not 'draft' or 'pending', set date to now. 3750 3757 */ 3751 if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' == $postarr['post_date'] ) {3752 if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) {3758 if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' === $postarr['post_date'] ) { 3759 if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) { 3753 3760 $post_date = current_time( 'mysql' ); 3754 3761 } else { … … 3772 3779 } 3773 3780 3774 if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) {3781 if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) { 3775 3782 if ( ! in_array( $post_status, get_post_stati( array( 'date_floating' => true ) ), true ) ) { 3776 3783 $post_date_gmt = get_gmt_from_date( $post_date ); … … 3782 3789 } 3783 3790 3784 if ( $update || '0000-00-00 00:00:00' == $post_date ) {3791 if ( $update || '0000-00-00 00:00:00' === $post_date ) { 3785 3792 $post_modified = current_time( 'mysql' ); 3786 3793 $post_modified_gmt = current_time( 'mysql', 1 ); … … 3834 3841 3835 3842 $post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : ''; 3836 if ( 'private' == $post_status ) {3843 if ( 'private' === $post_status ) { 3837 3844 $post_password = ''; 3838 3845 } … … 4028 4035 4029 4036 // Set GUID. 4030 if ( ! $update && '' == $current_guid ) {4037 if ( ! $update && '' === $current_guid ) { 4031 4038 $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where ); 4032 4039 } … … 4070 4077 $post->page_template = $postarr['page_template']; 4071 4078 $page_templates = wp_get_theme()->get_page_templates( $post ); 4072 if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {4079 if ( 'default' !== $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) { 4073 4080 if ( $wp_error ) { 4074 4081 return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) ); … … 4240 4247 if ( isset( $post['post_status'] ) 4241 4248 && in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ), true ) 4242 && empty( $postarr['edit_date'] ) && ( '0000-00-00 00:00:00' == $post['post_date_gmt'] )4249 && empty( $postarr['edit_date'] ) && ( '0000-00-00 00:00:00' === $post['post_date_gmt'] ) 4243 4250 ) { 4244 4251 $clear_date = true; … … 4293 4300 } 4294 4301 4295 if ( 'publish' == $post->post_status ) {4302 if ( 'publish' === $post->post_status ) { 4296 4303 return; 4297 4304 } … … 4338 4345 } 4339 4346 4340 if ( 'future' != $post->post_status ) {4347 if ( 'future' !== $post->post_status ) { 4341 4348 return; 4342 4349 } … … 4372 4379 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { 4373 4380 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ), true ) 4374 || ( 'inherit' == $post_status && 'revision'== $post_type ) || 'user_request' === $post_type4381 || ( 'inherit' === $post_status && 'revision' === $post_type ) || 'user_request' === $post_type 4375 4382 ) { 4376 4383 return $slug; … … 4406 4413 } 4407 4414 4408 if ( 'attachment' == $post_type ) {4415 if ( 'attachment' === $post_type ) { 4409 4416 // Attachment slugs must be unique across all types. 4410 4417 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; … … 4434 4441 } 4435 4442 } elseif ( is_post_type_hierarchical( $post_type ) ) { 4436 if ( 'nav_menu_item' == $post_type ) {4443 if ( 'nav_menu_item' === $post_type ) { 4437 4444 return $slug; 4438 4445 } … … 4672 4679 $post_categories = (array) $post_categories; 4673 4680 if ( empty( $post_categories ) ) { 4674 if ( 'post' == $post_type && 'auto-draft' != $post_status ) {4681 if ( 'post' === $post_type && 'auto-draft' !== $post_status ) { 4675 4682 $post_categories = array( get_option( 'default_category' ) ); 4676 4683 $append = false; … … 4678 4685 $post_categories = array(); 4679 4686 } 4680 } elseif ( 1 == count( $post_categories ) && '' == reset( $post_categories ) ) {4687 } elseif ( 1 == count( $post_categories ) && '' === reset( $post_categories ) ) { 4681 4688 return true; 4682 4689 } … … 4817 4824 4818 4825 foreach ( $custom_fields as $key => $val ) { 4819 if ( 'enclosure' != $key || ! is_array( $val ) ) {4826 if ( 'enclosure' !== $key || ! is_array( $val ) ) { 4820 4827 continue; 4821 4828 } … … 5396 5403 } 5397 5404 5398 if ( '' == $author_query ) {5405 if ( '' === $author_query ) { 5399 5406 $author_query = $wpdb->prepare( ' post_author = %d ', $post_author ); 5400 5407 } else { … … 5402 5409 } 5403 5410 } 5404 if ( '' != $author_query ) {5411 if ( '' !== $author_query ) { 5405 5412 $author_query = " AND ($author_query)"; 5406 5413 } … … 5594 5601 if ( $id ) { 5595 5602 $post = get_post( $id ); 5596 if ( 'attachment' == $post->post_type ) {5603 if ( 'attachment' === $post->post_type ) { 5597 5604 return true; 5598 5605 } … … 5926 5933 } 5927 5934 5928 if ( 'attachment' != $post->post_type ) {5935 if ( 'attachment' !== $post->post_type ) { 5929 5936 return false; 5930 5937 } … … 6240 6247 while ( false !== $file = readdir( $dh ) ) { 6241 6248 $file = wp_basename( $file ); 6242 if ( substr( $file, 0, 1 ) == '.') {6249 if ( '.' === substr( $file, 0, 1 ) ) { 6243 6250 continue; 6244 6251 } … … 6702 6709 do_action( 'clean_post_cache', $post->ID, $post ); 6703 6710 6704 if ( 'page' == $post->post_type ) {6711 if ( 'page' === $post->post_type ) { 6705 6712 wp_cache_delete( 'all_page_ids', 'posts' ); 6706 6713 … … 6748 6755 if ( is_array( $post_type ) ) { 6749 6756 $ptypes = $post_type; 6750 } elseif ( 'any' == $post_type ) {6757 } elseif ( 'any' === $post_type ) { 6751 6758 $ptypes = array(); 6752 6759 // Just use the post_types in the supplied posts. … … 6848 6855 if ( 'publish' !== $old_status && 'publish' === $new_status ) { 6849 6856 // Reset GUID if transitioning to publish and it is empty. 6850 if ( '' == get_the_guid( $post->ID ) ) {6857 if ( '' === get_the_guid( $post->ID ) ) { 6851 6858 $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) ); 6852 6859 } … … 6864 6871 6865 6872 // If published posts changed clear the lastpostmodified cache. 6866 if ( 'publish' == $new_status || 'publish'== $old_status ) {6873 if ( 'publish' === $new_status || 'publish' === $old_status ) { 6867 6874 foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { 6868 6875 wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' );
Note: See TracChangeset
for help on using the changeset viewer.