From fd5e6b5f6bf15ce734eeb1f17554cf3aa37692e6 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 19 May 2014 15:36:13 +0000 Subject: [PATCH] In `wpdb`, make some things explicitly `public`. Do not set anything to `private`. This would instantly blow up `hyperdb` in the wild. See #27881, #22234. Built from https://develop.svn.wordpress.org/trunk@28526 git-svn-id: http://core.svn.wordpress.org/trunk@28352 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/wp-db.php | 134 +++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index eed2401e4b..03e4e08910 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -78,7 +78,7 @@ class wpdb { * @since 2.5.0 * @var string */ - var $last_error = ''; + public $last_error = ''; /** * Amount of queries made @@ -209,7 +209,7 @@ class wpdb { * @access public * @var int */ - var $blogid = 0; + public $blogid = 0; /** * {@internal Missing Description}} @@ -218,7 +218,7 @@ class wpdb { * @access public * @var int */ - var $siteid = 0; + public $siteid = 0; /** * List of WordPress per-blog tables @@ -271,7 +271,7 @@ class wpdb { * @access public * @var string */ - var $comments; + public $comments; /** * WordPress Comment Metadata table @@ -280,7 +280,7 @@ class wpdb { * @access public * @var string */ - var $commentmeta; + public $commentmeta; /** * WordPress Links table @@ -289,7 +289,7 @@ class wpdb { * @access public * @var string */ - var $links; + public $links; /** * WordPress Options table @@ -298,7 +298,7 @@ class wpdb { * @access public * @var string */ - var $options; + public $options; /** * WordPress Post Metadata table @@ -307,7 +307,7 @@ class wpdb { * @access public * @var string */ - var $postmeta; + public $postmeta; /** * WordPress Posts table @@ -316,7 +316,7 @@ class wpdb { * @access public * @var string */ - var $posts; + public $posts; /** * WordPress Terms table @@ -325,7 +325,7 @@ class wpdb { * @access public * @var string */ - var $terms; + public $terms; /** * WordPress Term Relationships table @@ -334,7 +334,7 @@ class wpdb { * @access public * @var string */ - var $term_relationships; + public $term_relationships; /** * WordPress Term Taxonomy table @@ -343,7 +343,7 @@ class wpdb { * @access public * @var string */ - var $term_taxonomy; + public $term_taxonomy; /* * Global and Multisite tables @@ -356,7 +356,7 @@ class wpdb { * @access public * @var string */ - var $usermeta; + public $usermeta; /** * WordPress Users table @@ -365,7 +365,7 @@ class wpdb { * @access public * @var string */ - var $users; + public $users; /** * Multisite Blogs table @@ -374,7 +374,7 @@ class wpdb { * @access public * @var string */ - var $blogs; + public $blogs; /** * Multisite Blog Versions table @@ -383,7 +383,7 @@ class wpdb { * @access public * @var string */ - var $blog_versions; + public $blog_versions; /** * Multisite Registration Log table @@ -392,7 +392,7 @@ class wpdb { * @access public * @var string */ - var $registration_log; + public $registration_log; /** * Multisite Signups table @@ -401,7 +401,7 @@ class wpdb { * @access public * @var string */ - var $signups; + public $signups; /** * Multisite Sites table @@ -410,7 +410,7 @@ class wpdb { * @access public * @var string */ - var $site; + public $site; /** * Multisite Sitewide Terms table @@ -419,7 +419,7 @@ class wpdb { * @access public * @var string */ - var $sitecategories; + public $sitecategories; /** * Multisite Site Metadata table @@ -428,7 +428,7 @@ class wpdb { * @access public * @var string */ - var $sitemeta; + public $sitemeta; /** * Format specifiers for DB columns. Columns not listed here default to %s. Initialized during WP load. @@ -444,7 +444,7 @@ class wpdb { * @access public * @var array */ - var $field_types = array(); + public $field_types = array(); /** * Database table columns charset @@ -453,7 +453,7 @@ class wpdb { * @access public * @var string */ - var $charset; + public $charset; /** * Database table columns collate @@ -462,7 +462,7 @@ class wpdb { * @access public * @var string */ - var $collate; + public $collate; /** * Database Username @@ -516,7 +516,7 @@ class wpdb { * @access public * @var string */ - var $func_call; + public $func_call; /** * Whether MySQL is used as the database engine. @@ -575,7 +575,7 @@ class wpdb { * @param string $dbname MySQL database name * @param string $dbhost MySQL database host */ - function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { + public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { register_shutdown_function( array( $this, '__destruct' ) ); if ( WP_DEBUG && WP_DEBUG_DISPLAY ) @@ -614,7 +614,7 @@ class wpdb { * @since 2.0.8 * @return bool true */ - function __destruct() { + public function __destruct() { return true; } @@ -626,7 +626,7 @@ class wpdb { * @param string $name The private member to get, and optionally process * @return mixed The private member */ - function __get( $name ) { + public function __get( $name ) { if ( 'col_info' == $name ) $this->load_col_info(); @@ -641,7 +641,7 @@ class wpdb { * @param string $name The private member to set * @param mixed $value The value to set */ - function __set( $name, $value ) { + public function __set( $name, $value ) { $this->$name = $value; } @@ -654,7 +654,7 @@ class wpdb { * * @return bool If the member is set or not */ - function __isset( $name ) { + public function __isset( $name ) { return isset( $this->$name ); } @@ -665,7 +665,7 @@ class wpdb { * * @param string $name The private member to unset */ - function __unset( $name ) { + public function __unset( $name ) { unset( $this->$name ); } @@ -674,7 +674,7 @@ class wpdb { * * @since 3.1.0 */ - function init_charset() { + public function init_charset() { if ( function_exists('is_multisite') && is_multisite() ) { $this->charset = 'utf8'; if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) @@ -698,7 +698,7 @@ class wpdb { * @param string $charset The character set (optional) * @param string $collate The collation (optional) */ - function set_charset( $dbh, $charset = null, $collate = null ) { + public function set_charset( $dbh, $charset = null, $collate = null ) { if ( ! isset( $charset ) ) $charset = $this->charset; if ( ! isset( $collate ) ) @@ -736,7 +736,7 @@ class wpdb { * * @param array $modes Optional. A list of SQL modes to set. */ - function set_sql_mode( $modes = array() ) { + public function set_sql_mode( $modes = array() ) { if ( empty( $modes ) ) { if ( $this->use_mysqli ) { $res = mysqli_query( $this->dbh, 'SELECT @@SESSION.sql_mode' ); @@ -802,7 +802,7 @@ class wpdb { * @param bool $set_table_names Optional. Whether the table names, e.g. wpdb::$posts, should be updated or not. * @return string|WP_Error Old prefix or WP_Error on error */ - function set_prefix( $prefix, $set_table_names = true ) { + public function set_prefix( $prefix, $set_table_names = true ) { if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) return new WP_Error('invalid_db_prefix', 'Invalid database prefix' ); @@ -841,7 +841,7 @@ class wpdb { * @param int $site_id Optional. * @return string previous blog id */ - function set_blog_id( $blog_id, $site_id = 0 ) { + public function set_blog_id( $blog_id, $site_id = 0 ) { if ( ! empty( $site_id ) ) $this->siteid = $site_id; @@ -867,7 +867,7 @@ class wpdb { * @param int $blog_id Optional. * @return string Blog prefix. */ - function get_blog_prefix( $blog_id = null ) { + public function get_blog_prefix( $blog_id = null ) { if ( is_multisite() ) { if ( null === $blog_id ) $blog_id = $this->blogid; @@ -909,7 +909,7 @@ class wpdb { * @param int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested. * @return array Table names. When a prefix is requested, the key is the unprefixed table name. */ - function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) { + public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) { switch ( $scope ) { case 'all' : $tables = array_merge( $this->global_tables, $this->tables ); @@ -970,7 +970,7 @@ class wpdb { * @param resource $dbh Optional link identifier. * @return null Always null. */ - function select( $db, $dbh = null ) { + public function select( $db, $dbh = null ) { if ( is_null($dbh) ) $dbh = $this->dbh; @@ -1079,7 +1079,7 @@ class wpdb { * @param mixed $data * @return mixed */ - function escape( $data ) { + public function escape( $data ) { if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); if ( is_array( $data ) ) { @@ -1104,7 +1104,7 @@ class wpdb { * @param string $string to escape * @return void */ - function escape_by_ref( &$string ) { + public function escape_by_ref( &$string ) { if ( ! is_float( $string ) ) $string = $this->_real_escape( $string ); } @@ -1146,7 +1146,7 @@ class wpdb { * @return null|false|string Sanitized query string, null if there is no query, false if there is an error and string * if there was something to prepare */ - function prepare( $query, $args ) { + public function prepare( $query, $args ) { if ( is_null( $query ) ) return; @@ -1177,7 +1177,7 @@ class wpdb { * @param string $str The error to display * @return bool False if the showing of errors is disabled. */ - function print_error( $str = '' ) { + public function print_error( $str = '' ) { global $EZSQL_ERROR; if ( !$str ) { @@ -1237,7 +1237,7 @@ class wpdb { * @param bool $show Whether to show or hide errors * @return bool Old value for showing errors. */ - function show_errors( $show = true ) { + public function show_errors( $show = true ) { $errors = $this->show_errors; $this->show_errors = $show; return $errors; @@ -1253,7 +1253,7 @@ class wpdb { * * @return bool Whether showing of errors was active */ - function hide_errors() { + public function hide_errors() { $show = $this->show_errors; $this->show_errors = false; return $show; @@ -1270,7 +1270,7 @@ class wpdb { * @param bool $suppress Optional. New value. Defaults to true. * @return bool Old value */ - function suppress_errors( $suppress = true ) { + public function suppress_errors( $suppress = true ) { $errors = $this->suppress_errors; $this->suppress_errors = (bool) $suppress; return $errors; @@ -1282,7 +1282,7 @@ class wpdb { * @since 0.71 * @return void */ - function flush() { + public function flush() { $this->last_result = array(); $this->col_info = null; $this->last_query = null; @@ -1310,7 +1310,7 @@ class wpdb { * @param bool $allow_bail Optional. Allows the function to bail. Default true. * @return bool True with a successful connection, false on failure. */ - function db_connect( $allow_bail = true ) { + public function db_connect( $allow_bail = true ) { $this->is_mysql = true; @@ -1425,7 +1425,7 @@ class wpdb { * @param bool $allow_bail Optional. Allows the function to bail. Default true. * @return bool True if the connection is up. */ - function check_connection( $allow_bail = true ) { + public function check_connection( $allow_bail = true ) { if ( $this->use_mysqli ) { if ( @mysqli_ping( $this->dbh ) ) { return true; @@ -1497,7 +1497,7 @@ class wpdb { * @param string $query Database query * @return int|false Number of rows affected/selected or false on error */ - function query( $query ) { + public function query( $query ) { if ( ! $this->ready ) return false; @@ -1645,7 +1645,7 @@ class wpdb { * A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. * @return int|false The number of rows inserted, or false on error. */ - function insert( $table, $data, $format = null ) { + public function insert( $table, $data, $format = null ) { return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' ); } @@ -1668,7 +1668,7 @@ class wpdb { * A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. * @return int|false The number of rows affected, or false on error. */ - function replace( $table, $data, $format = null ) { + public function replace( $table, $data, $format = null ) { return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' ); } @@ -1731,7 +1731,7 @@ class wpdb { * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings. * @return int|false The number of rows updated, or false on error. */ - function update( $table, $data, $where, $format = null, $where_format = null ) { + public function update( $table, $data, $where, $format = null, $where_format = null ) { if ( ! is_array( $data ) || ! is_array( $where ) ) return false; @@ -1780,7 +1780,7 @@ class wpdb { * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types. * @return int|false The number of rows updated, or false on error. */ - function delete( $table, $where, $where_format = null ) { + public function delete( $table, $where, $where_format = null ) { if ( ! is_array( $where ) ) return false; @@ -1819,7 +1819,7 @@ class wpdb { * @param int $y Optional. Row of value to return. Indexed from 0. * @return string|null Database query result (as string), or null on failure */ - function get_var( $query = null, $x = 0, $y = 0 ) { + public function get_var( $query = null, $x = 0, $y = 0 ) { $this->func_call = "\$db->get_var(\"$query\", $x, $y)"; if ( $query ) $this->query( $query ); @@ -1846,7 +1846,7 @@ class wpdb { * @param int $y Optional. Row to return. Indexed from 0. * @return mixed Database query result in format specified by $output or null on failure */ - function get_row( $query = null, $output = OBJECT, $y = 0 ) { + public function get_row( $query = null, $output = OBJECT, $y = 0 ) { $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; if ( $query ) $this->query( $query ); @@ -1883,7 +1883,7 @@ class wpdb { * @param int $x Optional. Column to return. Indexed from 0. * @return array Database query result. Array indexed from 0 by SQL result row number. */ - function get_col( $query = null , $x = 0 ) { + public function get_col( $query = null , $x = 0 ) { if ( $query ) $this->query( $query ); @@ -1908,7 +1908,7 @@ class wpdb { * With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value. Duplicate keys are discarded. * @return mixed Database query results */ - function get_results( $query = null, $output = OBJECT ) { + public function get_results( $query = null, $output = OBJECT ) { $this->func_call = "\$db->get_results(\"$query\", $output)"; if ( $query ) @@ -1982,7 +1982,7 @@ class wpdb { * @param int $col_offset Optional. 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type * @return mixed Column Results */ - function get_col_info( $info_type = 'name', $col_offset = -1 ) { + public function get_col_info( $info_type = 'name', $col_offset = -1 ) { $this->load_col_info(); if ( $this->col_info ) { @@ -2007,7 +2007,7 @@ class wpdb { * * @return true */ - function timer_start() { + public function timer_start() { $this->time_start = microtime( true ); return true; } @@ -2019,7 +2019,7 @@ class wpdb { * * @return float Total time spent on the query, in seconds */ - function timer_stop() { + public function timer_stop() { return ( microtime( true ) - $this->time_start ); } @@ -2034,7 +2034,7 @@ class wpdb { * @param string $error_code Optional. A Computer readable string to identify the error. * @return false|void */ - function bail( $message, $error_code = '500' ) { + public function bail( $message, $error_code = '500' ) { if ( !$this->show_errors ) { if ( class_exists( 'WP_Error' ) ) $this->error = new WP_Error($error_code, $message); @@ -2054,7 +2054,7 @@ class wpdb { * * @return WP_Error */ - function check_database_version() { + public function check_database_version() { global $wp_version, $required_mysql_version; // Make sure the server has the required MySQL version if ( version_compare($this->db_version(), $required_mysql_version, '<') ) @@ -2072,7 +2072,7 @@ class wpdb { * * @return bool True if collation is supported, false if version does not */ - function supports_collation() { + public function supports_collation() { _deprecated_function( __FUNCTION__, '3.5', 'wpdb::has_cap( \'collation\' )' ); return $this->has_cap( 'collation' ); } @@ -2104,7 +2104,7 @@ class wpdb { * @param string $db_cap The feature to check for. * @return bool */ - function has_cap( $db_cap ) { + public function has_cap( $db_cap ) { $version = $this->db_version(); switch ( strtolower( $db_cap ) ) { @@ -2129,7 +2129,7 @@ class wpdb { * * @return string The name of the calling function */ - function get_caller() { + public function get_caller() { return wp_debug_backtrace_summary( __CLASS__ ); } @@ -2140,7 +2140,7 @@ class wpdb { * * @return false|string false on failure, version number on success */ - function db_version() { + public function db_version() { if ( $this->use_mysqli ) { $server_info = mysqli_get_server_info( $this->dbh ); } else {