Make WordPress Core


Ignore:
Timestamp:
10/10/2016 06:37:02 AM (10 years ago)
Author:
pento
Message:

General: Restore usage of $wpdb, instead of $this->db.

Hiding the $wpdb global behind a property decreases the readability of the code, as well as causing irrelevant output when dumping an object.

Reverts [38275], [38278], [38279], [38280], [38387].
See #37699.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r38747 r38768  
    5555
    5656        /**
    57          * @since 4.7.0
    58          * @access protected
    59          * @var wpdb
    60          */
    61         protected $db;
    62 
    63         /**
    6457         * Registers all of the XMLRPC methods that XMLRPC server understands.
    6558         *
    … …  
    7164         */
    7265        public function __construct() {
    73                 $this->db = $GLOBALS['wpdb'];
    74 
    7566                $this->methods = array(
    7667                        // WordPress API
    … …  
    28952886         * @since 2.2.0
    28962887         *
     2888         * @global wpdb $wpdb WordPress database abstraction object.
     2889         *
    28972890         * @param array  $args {
    28982891         *     Method arguments. Note: arguments must be ordered as documented.
    … …  
    29052898         */
    29062899        public function wp_getPageList( $args ) {
     2900                global $wpdb;
     2901
    29072902                $this->escape( $args );
    29082903
    … …  
    29202915
    29212916                // Get list of pages ids and titles
    2922                 $page_list = $this->db->get_results("
     2917                $page_list = $wpdb->get_results("
    29232918                        SELECT ID page_id,
    29242919                                post_title page_title,
    … …  
    29272922                                post_date,
    29282923                                post_status
    2929                         FROM {$this->db->posts}
     2924                        FROM {$wpdb->posts}
    29302925                        WHERE post_type = 'page'
    29312926                        ORDER BY ID
    … …  
    51445139         * @since 2.1.0
    51455140         *
     5141         * @global wpdb $wpdb WordPress database abstraction object.
     5142         *
    51465143         * @param int $post_ID Post ID.
    51475144         * @param string $post_content Post Content for attachment.
    51485145         */
    51495146        public function attach_uploads( $post_ID, $post_content ) {
     5147                global $wpdb;
     5148
    51505149                // find any unattached files
    5151                 $attachments = $this->db->get_results( "SELECT ID, guid FROM {$this->db->posts} WHERE post_parent = '0' AND post_type = 'attachment'" );
     5150                $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" );
    51525151                if ( is_array( $attachments ) ) {
    51535152                        foreach ( $attachments as $file ) {
    5154                                 if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) {
    5155                                         $this->db->update( $this->db->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) );
    5156                                 }
     5153                                if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false )
     5154                                        $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) );
    51575155                        }
    51585156                }
    … …  
    57745772         * @since 1.5.0
    57755773         *
     5774         * @global wpdb $wpdb WordPress database abstraction object.
     5775         *
    57765776         * @param array  $args {
    57775777         *     Method arguments. Note: arguments must be ordered as documented.
    … …  
    57855785         */
    57865786        public function mw_newMediaObject( $args ) {
     5787                global $wpdb;
     5788
    57875789                $username = $this->escape( $args[1] );
    57885790                $password = $this->escape( $args[2] );
    … …  
    61106112         * @since 1.5.0
    61116113         *
     6114         * @global wpdb $wpdb WordPress database abstraction object.
     6115         *
    61126116         * @param int $post_ID
    61136117         * @return array|IXR_Error
    61146118         */
    61156119        public function mt_getTrackbackPings( $post_ID ) {
     6120                global $wpdb;
     6121
    61166122                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    61176123                do_action( 'xmlrpc_call', 'mt.getTrackbackPings' );
    … …  
    61226128                        return new IXR_Error(404, __('Sorry, no such post.'));
    61236129
    6124                 $comments = $this->db->get_results( $this->db->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM {$this->db->comments} WHERE comment_post_ID = %d", $post_ID) );
     6130                $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
    61256131
    61266132                if ( !$comments )
    … …  
    62576263                                // ...or a string #title, a little more complicated
    62586264                                $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']);
    6259                                 $sql = $this->db->prepare("SELECT ID FROM {$this->db->posts} WHERE post_title RLIKE %s", $title );
    6260                                 if (! ($post_ID = $this->db->get_var($sql)) ) {
     6265                                $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title );
     6266                                if (! ($post_ID = $wpdb->get_var($sql)) ) {
    62616267                                        // returning unknown error '0' is better than die()ing
    62626268                                        return $this->pingback_error( 0, '' );
    … …  
    62826288
    62836289                // Let's check that the remote site didn't already pingback this entry
    6284                 if ( $this->db->get_results( $this->db->prepare("SELECT * FROM {$this->db->comments} WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) )
     6290                if ( $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) )
    62856291                        return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) );
    62866292
    … …  
    64096415         * @since 1.5.0
    64106416         *
     6417         * @global wpdb $wpdb WordPress database abstraction object.
     6418         *
    64116419         * @param string $url
    64126420         * @return array|IXR_Error
    64136421         */
    64146422        public function pingback_extensions_getPingbacks( $url ) {
     6423                global $wpdb;
     6424
    64156425                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    64166426                do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' );
    … …  
    64316441                }
    64326442
    6433                 $comments = $this->db->get_results( $this->db->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM {$this->db->comments} WHERE comment_post_ID = %d", $post_ID) );
     6443                $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
    64346444
    64356445                if ( !$comments )
Note: See TracChangeset for help on using the changeset viewer.