Replace use of global `$user_ID` in favor of `get_current_user_id()`. fixes #25372.

Built from https://develop.svn.wordpress.org/trunk@25669


git-svn-id: http://core.svn.wordpress.org/trunk@25585 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2013-10-02 21:10:09 +00:00
parent 9e9093ab6d
commit e4c8d56b76
4 changed files with 22 additions and 22 deletions

View File

@ -1372,7 +1372,7 @@ function wp_ajax_inline_save() {
$data['excerpt'] = $post['post_excerpt']; $data['excerpt'] = $post['post_excerpt'];
// rename // rename
$data['user_ID'] = $GLOBALS['user_ID']; $data['user_ID'] = get_current_user_id();
if ( isset($data['post_parent']) ) if ( isset($data['post_parent']) )
$data['parent_id'] = $data['post_parent']; $data['parent_id'] = $data['post_parent'];

View File

@ -52,7 +52,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) {
if ( isset($post_data['trackback_url']) ) if ( isset($post_data['trackback_url']) )
$post_data['to_ping'] = $post_data['trackback_url']; $post_data['to_ping'] = $post_data['trackback_url'];
$post_data['user_ID'] = $GLOBALS['user_ID']; $post_data['user_ID'] = get_current_user_id();
if (!empty ( $post_data['post_author_override'] ) ) { if (!empty ( $post_data['post_author_override'] ) ) {
$post_data['post_author'] = (int) $post_data['post_author_override']; $post_data['post_author'] = (int) $post_data['post_author_override'];
@ -266,7 +266,7 @@ function edit_post( $post_data = null ) {
add_meta( $post_ID ); add_meta( $post_ID );
update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
wp_update_post( $post_data ); wp_update_post( $post_data );
@ -538,8 +538,6 @@ function post_exists($title, $content = '', $date = '') {
* @return unknown * @return unknown
*/ */
function wp_write_post() { function wp_write_post() {
global $user_ID;
if ( isset($_POST['post_type']) ) if ( isset($_POST['post_type']) )
$ptype = get_post_type_object($_POST['post_type']); $ptype = get_post_type_object($_POST['post_type']);
else else

View File

@ -2655,7 +2655,6 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
* setting the value for 'comment_status' key. * setting the value for 'comment_status' key.
* *
* @global wpdb $wpdb WordPress database abstraction object. * @global wpdb $wpdb WordPress database abstraction object.
* @global int $user_ID
* *
* @since 1.0.0 * @since 1.0.0
* *
@ -2666,7 +2665,7 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
* be updated. Default 0. * be updated. Default 0.
* @type string 'post_status' The post status. Default 'draft'. * @type string 'post_status' The post status. Default 'draft'.
* @type string 'post_type' The post type. Default 'post'. * @type string 'post_type' The post type. Default 'post'.
* @type int 'post_author' The ID of the user who added the post. Default $user_ID, the current user ID. * @type int 'post_author' The ID of the user who added the post. Default the current user ID.
* @type bool 'ping_status' Whether the post can accept pings. Default value of 'default_ping_status' option. * @type bool 'ping_status' Whether the post can accept pings. Default value of 'default_ping_status' option.
* @type int 'post_parent' Set this for the post it belongs to, if any. Default 0. * @type int 'post_parent' Set this for the post it belongs to, if any. Default 0.
* @type int 'menu_order' The order it is displayed. Default 0. * @type int 'menu_order' The order it is displayed. Default 0.
@ -2682,9 +2681,11 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
* @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
*/ */
function wp_insert_post( $postarr, $wp_error = false ) { function wp_insert_post( $postarr, $wp_error = false ) {
global $wpdb, $user_ID; global $wpdb;
$defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID, $user_id = get_current_user_id();
$defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_id,
'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '',
'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0,
@ -2749,7 +2750,7 @@ function wp_insert_post( $postarr, $wp_error = false ) {
} }
if ( empty($post_author) ) if ( empty($post_author) )
$post_author = $user_ID; $post_author = $user_id;
// Don't allow contributors to set the post slug for pending review posts // Don't allow contributors to set the post slug for pending review posts
if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) )
@ -3943,7 +3944,6 @@ function is_local_attachment($url) {
* *
* @since 2.0.0 * @since 2.0.0
* @uses $wpdb * @uses $wpdb
* @uses $user_ID
* @uses do_action() Calls 'edit_attachment' on $post_ID if this is an update. * @uses do_action() Calls 'edit_attachment' on $post_ID if this is an update.
* @uses do_action() Calls 'add_attachment' on $post_ID if this is not an update. * @uses do_action() Calls 'add_attachment' on $post_ID if this is not an update.
* *
@ -3953,9 +3953,11 @@ function is_local_attachment($url) {
* @return int Attachment ID. * @return int Attachment ID.
*/ */
function wp_insert_attachment($object, $file = false, $parent = 0) { function wp_insert_attachment($object, $file = false, $parent = 0) {
global $wpdb, $user_ID; global $wpdb;
$defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_ID, $user_id = get_current_user_id();
$defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_id,
'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'post_title' => '', 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'post_title' => '',
'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'post_content' => '', 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'post_content' => '',
'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'context' => ''); 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'context' => '');
@ -3972,7 +3974,7 @@ function wp_insert_attachment($object, $file = false, $parent = 0) {
extract($object, EXTR_SKIP); extract($object, EXTR_SKIP);
if ( empty($post_author) ) if ( empty($post_author) )
$post_author = $user_ID; $post_author = $user_id;
$post_type = 'attachment'; $post_type = 'attachment';
@ -4496,8 +4498,6 @@ function wp_check_for_changed_slugs($post_id, $post, $post_before) {
* *
* @since 2.2.0 * @since 2.2.0
* *
* @uses $user_ID
*
* @param string $post_type currently only supports 'post' or 'page'. * @param string $post_type currently only supports 'post' or 'page'.
* @return string SQL code that can be added to a where clause. * @return string SQL code that can be added to a where clause.
*/ */
@ -4518,7 +4518,7 @@ function get_private_posts_cap_sql( $post_type ) {
* @return string SQL WHERE code that can be added to a query. * @return string SQL WHERE code that can be added to a query.
*/ */
function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) { function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) {
global $user_ID, $wpdb; global $wpdb;
// Private posts // Private posts
$post_type_obj = get_post_type_object( $post_type ); $post_type_obj = get_post_type_object( $post_type );
@ -4548,7 +4548,7 @@ function get_posts_by_author_sql( $post_type, $full = true, $post_author = null,
$sql .= " OR post_status = 'private'"; $sql .= " OR post_status = 'private'";
} elseif ( is_user_logged_in() ) { } elseif ( is_user_logged_in() ) {
// Users can view their own private posts. // Users can view their own private posts.
$id = (int) $user_ID; $id = get_current_user_id();
if ( null === $post_author || ! $full ) { if ( null === $post_author || ! $full ) {
$sql .= " OR post_status = 'private' AND post_author = $id"; $sql .= " OR post_status = 'private' AND post_author = $id";
} elseif ( $id == (int) $post_author ) { } elseif ( $id == (int) $post_author ) {

View File

@ -2140,7 +2140,7 @@ class WP_Query {
* @return array List of posts. * @return array List of posts.
*/ */
function get_posts() { function get_posts() {
global $wpdb, $user_ID; global $wpdb;
$this->parse_query(); $this->parse_query();
@ -2713,18 +2713,20 @@ class WP_Query {
unset($p_status); unset($p_status);
} }
$user_id = get_current_user_id();
if ( !empty($e_status) ) { if ( !empty($e_status) ) {
$statuswheres[] = "(" . join( ' AND ', $e_status ) . ")"; $statuswheres[] = "(" . join( ' AND ', $e_status ) . ")";
} }
if ( !empty($r_status) ) { if ( !empty($r_status) ) {
if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) )
$statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))"; $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))";
else else
$statuswheres[] = "(" . join( ' OR ', $r_status ) . ")"; $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")";
} }
if ( !empty($p_status) ) { if ( !empty($p_status) ) {
if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) )
$statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))"; $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))";
else else
$statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")";
} }
@ -2757,7 +2759,7 @@ class WP_Query {
// Add private states that are limited to viewing by the author of a post or someone who has caps to read private states. // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states.
$private_states = get_post_stati( array('private' => true) ); $private_states = get_post_stati( array('private' => true) );
foreach ( (array) $private_states as $state ) foreach ( (array) $private_states as $state )
$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'"; $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'";
} }
$where .= ')'; $where .= ')';