WordPress.org

Make WordPress Core

Ticket #25372: 25372.patch

File 25372.patch, 9.0 KB (added by ocean90, 7 years ago)

First pass

  • src/wp-includes/post.php

     
    26412641 * The defaults for the parameter $postarr are:
    26422642 *     'post_status'   - Default is 'draft'.
    26432643 *     'post_type'     - Default is 'post'.
    2644  *     'post_author'   - Default is current user ID ($user_ID). The ID of the user who added the post.
     2644 *     'post_author'   - Default is current user ID. The ID of the user who added the post.
    26452645 *     'ping_status'   - Default is the value in 'default_ping_status' option.
    26462646 *                       Whether the attachment can accept pings.
    26472647 *     'post_parent'   - Default is 0. Set this for the post it belongs to, if any.
     
    26552655 *
    26562656 * @since 1.0.0
    26572657 * @uses $wpdb
    2658  * @uses $user_ID
    26592658 * @uses do_action() Calls 'pre_post_update' on post ID if this is an update.
    26602659 * @uses do_action() Calls 'edit_post' action on post ID and post data if this is an update.
    26612660 * @uses do_action() Calls 'save_post_{$post_type}', 'save_post' and 'wp_insert_post' on post id and post data just before returning.
     
    26672666 * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success.
    26682667 */
    26692668function wp_insert_post($postarr, $wp_error = false) {
    2670         global $wpdb, $user_ID;
     2669        global $wpdb;
    26712670
    2672         $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
     2671        $user_id = get_current_user_id();
     2672
     2673        $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_id,
    26732674                'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
    26742675                'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',
    26752676                'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0,
     
    27342735        }
    27352736
    27362737        if ( empty($post_author) )
    2737                 $post_author = $user_ID;
     2738                $post_author = $user_id;
    27382739
    27392740        // Don't allow contributors to set the post slug for pending review posts
    27402741        if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) )
     
    39283929 *
    39293930 * @since 2.0.0
    39303931 * @uses $wpdb
    3931  * @uses $user_ID
    39323932 * @uses do_action() Calls 'edit_attachment' on $post_ID if this is an update.
    39333933 * @uses do_action() Calls 'add_attachment' on $post_ID if this is not an update.
    39343934 *
     
    39383938 * @return int Attachment ID.
    39393939 */
    39403940function wp_insert_attachment($object, $file = false, $parent = 0) {
    3941         global $wpdb, $user_ID;
     3941        global $wpdb;
    39423942
    3943         $defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_ID,
     3943        $user_id = get_current_user_id();
     3944
     3945        $defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_id,
    39443946                'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'post_title' => '',
    39453947                'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',
    39463948                'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'context' => '');
     
    39573959        extract($object, EXTR_SKIP);
    39583960
    39593961        if ( empty($post_author) )
    3960                 $post_author = $user_ID;
     3962                $post_author = $user_id;
    39613963
    39623964        $post_type = 'attachment';
    39633965
     
    44814483 *
    44824484 * @since 2.2.0
    44834485 *
    4484  * @uses $user_ID
    4485  *
    44864486 * @param string $post_type currently only supports 'post' or 'page'.
    44874487 * @return string SQL code that can be added to a where clause.
    44884488 */
     
    45034503 * @return string SQL WHERE code that can be added to a query.
    45044504 */
    45054505function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) {
    4506         global $user_ID, $wpdb;
     4506        global $wpdb;
    45074507
    45084508        // Private posts
    45094509        $post_type_obj = get_post_type_object( $post_type );
     
    45334533                        $sql .= " OR post_status = 'private'";
    45344534                } elseif ( is_user_logged_in() ) {
    45354535                        // Users can view their own private posts.
    4536                         $id = (int) $user_ID;
     4536                        $id = (int) get_current_user_id();
    45374537                        if ( null === $post_author || ! $full ) {
    45384538                                $sql .= " OR post_status = 'private' AND post_author = $id";
    45394539                        } elseif ( $id == (int) $post_author ) {
  • src/wp-includes/query.php

     
    19481948         * @return array List of posts.
    19491949         */
    19501950        function get_posts() {
    1951                 global $wpdb, $user_ID;
     1951                global $wpdb;
    19521952
    19531953                $this->parse_query();
    19541954
     
    25282528                                unset($p_status);
    25292529                        }
    25302530
     2531                        $user_id = get_current_user_id();
     2532
    25312533                        if ( !empty($e_status) ) {
    25322534                                $statuswheres[] = "(" . join( ' AND ', $e_status ) . ")";
    25332535                        }
    25342536                        if ( !empty($r_status) ) {
    25352537                                if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) )
    2536                                         $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))";
     2538                                        $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))";
    25372539                                else
    25382540                                        $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")";
    25392541                        }
    25402542                        if ( !empty($p_status) ) {
    25412543                                if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) )
    2542                                         $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))";
     2544                                        $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))";
    25432545                                else
    25442546                                        $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")";
    25452547                        }
     
    25722574                                // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states.
    25732575                                $private_states = get_post_stati( array('private' => true) );
    25742576                                foreach ( (array) $private_states as $state )
    2575                                         $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'";
     2577                                        $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'";
    25762578                        }
    25772579
    25782580                        $where .= ')';
  • src/wp-admin/includes/ajax-actions.php

     
    13281328        $data['excerpt'] = $post['post_excerpt'];
    13291329
    13301330        // rename
    1331         $data['user_ID'] = $GLOBALS['user_ID'];
     1331        $data['user_ID'] = get_current_user_id();
    13321332
    13331333        if ( isset($data['post_parent']) )
    13341334                $data['parent_id'] = $data['post_parent'];
  • src/wp-admin/includes/post.php

     
    5252        if ( isset($post_data['trackback_url']) )
    5353                $post_data['to_ping'] = $post_data['trackback_url'];
    5454
    55         $post_data['user_ID'] = $GLOBALS['user_ID'];
     55        $post_data['user_ID'] = get_current_user_id();
    5656
    5757        if (!empty ( $post_data['post_author_override'] ) ) {
    5858                $post_data['post_author'] = (int) $post_data['post_author_override'];
     
    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
     
    591589
    592590        add_meta( $post_ID );
    593591
    594         add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
     592        add_post_meta( $post_ID, '_edit_last', get_current_user_id() );
    595593
    596594        // Now that we have an ID we can fix any attachment anchor hrefs
    597595        _fix_attachment_links( $post_ID );
  • src/wp-admin/includes/meta-boxes.php

     
    601601 * @param object $post
    602602 */
    603603function post_author_meta_box($post) {
    604         global $user_ID;
    605604?>
    606605<label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label>
    607606<?php
    608607        wp_dropdown_users( array(
    609608                'who' => 'authors',
    610609                'name' => 'post_author_override',
    611                 'selected' => empty($post->ID) ? $user_ID : $post->post_author,
     610                'selected' => empty($post->ID) ? get_current_user_id() : $post->post_author,
    612611                'include_selected' => true
    613612        ) );
    614613}
  • src/wp-admin/includes/user.php

     
    326326 * @since 2.8.0
    327327 */
    328328function default_password_nag_handler($errors = false) {
    329         global $user_ID;
    330329        if ( ! get_user_option('default_password_nag') ) //Short circuit it.
    331330                return;
    332331
    333332        //get_user_setting = JS saved UI setting. else no-js-fallback code.
    334333        if ( 'hide' == get_user_setting('default_password_nag') || isset($_GET['default_password_nag']) && '0' == $_GET['default_password_nag'] ) {
    335334                delete_user_setting('default_password_nag');
    336                 update_user_option($user_ID, 'default_password_nag', false, true);
     335                update_user_option( get_current_user_id(), 'default_password_nag', false, true);
    337336        }
    338337}
    339338