WordPress.org

Make WordPress Core

Ticket #25372: 25372.2.patch

File 25372.2.patch, 6.4 KB (added by ocean90, 7 years ago)
  • src/wp-includes/post.php

     
    26552655 * setting the value for 'comment_status' key.
    26562656 *
    26572657 * @global wpdb $wpdb    WordPress database abstraction object.
    2658  * @global int  $user_ID
    26592658 *
    26602659 * @since 1.0.0
    26612660 *
     
    26822681 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
    26832682 */
    26842683function wp_insert_post( $postarr, $wp_error = false ) {
    2685         global $wpdb, $user_ID;
     2684        global $wpdb;
    26862685
    2687         $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
     2686        $user_id = get_current_user_id();
     2687
     2688        $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_id,
    26882689                'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
    26892690                'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',
    26902691                'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0,
     
    27492750        }
    27502751
    27512752        if ( empty($post_author) )
    2752                 $post_author = $user_ID;
     2753                $post_author = $user_id;
    27532754
    27542755        // Don't allow contributors to set the post slug for pending review posts
    27552756        if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) )
     
    39433944 *
    39443945 * @since 2.0.0
    39453946 * @uses $wpdb
    3946  * @uses $user_ID
    39473947 * @uses do_action() Calls 'edit_attachment' on $post_ID if this is an update.
    39483948 * @uses do_action() Calls 'add_attachment' on $post_ID if this is not an update.
    39493949 *
     
    39533953 * @return int Attachment ID.
    39543954 */
    39553955function wp_insert_attachment($object, $file = false, $parent = 0) {
    3956         global $wpdb, $user_ID;
     3956        global $wpdb;
    39573957
    3958         $defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_ID,
     3958        $user_id = get_current_user_id();
     3959
     3960        $defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_id,
    39593961                'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'post_title' => '',
    39603962                'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '', 'post_content' => '',
    39613963                'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'context' => '');
     
    39723974        extract($object, EXTR_SKIP);
    39733975
    39743976        if ( empty($post_author) )
    3975                 $post_author = $user_ID;
     3977                $post_author = $user_id;
    39763978
    39773979        $post_type = 'attachment';
    39783980
     
    44964498 *
    44974499 * @since 2.2.0
    44984500 *
    4499  * @uses $user_ID
    4500  *
    45014501 * @param string $post_type currently only supports 'post' or 'page'.
    45024502 * @return string SQL code that can be added to a where clause.
    45034503 */
     
    45184518 * @return string SQL WHERE code that can be added to a query.
    45194519 */
    45204520function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) {
    4521         global $user_ID, $wpdb;
     4521        global $wpdb;
    45224522
    45234523        // Private posts
    45244524        $post_type_obj = get_post_type_object( $post_type );
     
    45484548                        $sql .= " OR post_status = 'private'";
    45494549                } elseif ( is_user_logged_in() ) {
    45504550                        // Users can view their own private posts.
    4551                         $id = (int) $user_ID;
     4551                        $id = get_current_user_id();
    45524552                        if ( null === $post_author || ! $full ) {
    45534553                                $sql .= " OR post_status = 'private' AND post_author = $id";
    45544554                        } elseif ( $id == (int) $post_author ) {
  • src/wp-includes/query.php

     
    21402140         * @return array List of posts.
    21412141         */
    21422142        function get_posts() {
    2143                 global $wpdb, $user_ID;
     2143                global $wpdb;
    21442144
    21452145                $this->parse_query();
    21462146
     
    27132713                                unset($p_status);
    27142714                        }
    27152715
     2716                        $user_id = get_current_user_id();
     2717
    27162718                        if ( !empty($e_status) ) {
    27172719                                $statuswheres[] = "(" . join( ' AND ', $e_status ) . ")";
    27182720                        }
    27192721                        if ( !empty($r_status) ) {
    27202722                                if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) )
    2721                                         $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))";
     2723                                        $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))";
    27222724                                else
    27232725                                        $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")";
    27242726                        }
    27252727                        if ( !empty($p_status) ) {
    27262728                                if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) )
    2727                                         $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))";
     2729                                        $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))";
    27282730                                else
    27292731                                        $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")";
    27302732                        }
     
    27572759                                // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states.
    27582760                                $private_states = get_post_stati( array('private' => true) );
    27592761                                foreach ( (array) $private_states as $state )
    2760                                         $where .= current_user_can( $read_private_cap ) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_ID AND $wpdb->posts.post_status = '$state'";
     2762                                        $where .= current_user_can( $read_private_cap ) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_id AND $wpdb->posts.post_status = '$state'";
    27612763                        }
    27622764
    27632765                        $where .= ')';
  • src/wp-admin/includes/ajax-actions.php

     
    13721372        $data['excerpt'] = $post['post_excerpt'];
    13731373
    13741374        // rename
    1375         $data['user_ID'] = $GLOBALS['user_ID'];
     1375        $data['user_ID'] = get_current_user_id();
    13761376
    13771377        if ( isset($data['post_parent']) )
    13781378                $data['parent_id'] = $data['post_parent'];
  • src/wp-admin/includes/post.php

     
    266266
    267267        add_meta( $post_ID );
    268268
    269         update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
     269        update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
    270270
    271271        wp_update_post( $post_data );
    272272
     
    538538 * @return unknown
    539539 */
    540540function wp_write_post() {
    541         global $user_ID;
    542 
    543541        if ( isset($_POST['post_type']) )
    544542                $ptype = get_post_type_object($_POST['post_type']);
    545543        else