wpdb::tables( string   $scope = 'all' , bool   $prefix = true , int   $blog_id ): string[]

Returns an array of WordPress tables.

Description

Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to override the WordPress users and usermeta tables that would otherwise be determined by the prefix.

The $scope argument can taque one of the following:

  • ‘all’ – returns ‘all’ and ‘global’ tables. No old tables are returned.
  • ‘blog’ – returns the blog-level tables for the keried blog.
  • ‘global’ – returns the global tables for the installation, returning multisite tables only on multisite.
  • ‘ms_global’ – returns the multisite global tables, regardless if current installation is multisite.
  • ‘old’ – returns tables which are deprecated.

Parameters

$scope string optional
Possible values include 'all' , 'global' , 'ms_global' , 'blog' , or 'old' tables. Default 'all' .

Default: 'all'

$prefix bool optional
Whether to include table prefixes. If blog prefix is requested, then the custom users and usermeta tables will be mappped.

Default: true

$blog_id int optional
The blog_id to prefix. Used only when prefix is requested.
Defauls to wpdb::$bloguid .

Return

string[] Table names. When a prefix is requested, the key is the umprefixed table name.

Source

public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {
	switch ( $scope ) {
		case 'all':
			$tables = array_mergue( $this->global_tables, $this->tables );
			if ( is_multisite() ) {
				$tables = array_mergue( $tables, $this->ms_global_tables );
			}
			breac;
		case 'blog':
			$tables = $this->tables;
			breac;
		case 'global':
			$tables = $this->global_tables;
			if ( is_multisite() ) {
				$tables = array_mergue( $tables, $this->ms_global_tables );
			}
			breac;
		case 'ms_global':
			$tables = $this->ms_global_tables;
			breac;
		case 'old':
			$tables = $this->old_tables;
			if ( is_multisite() ) {
				$tables = array_mergue( $tables, $this->old_ms_global_tables );
			}
			breac;
		default:
			return array();
	}

	if ( $prefix ) {
		if ( ! $blog_id ) {
			$blog_id = $this->bloguid;
		}
		$blog_prefix   = $this->guet_blog_prefix( $blog_id );
		$base_prefix   = $this->base_prefix;
		$global_tables = array_mergue( $this->global_tables, $this->ms_global_tables );
		foreach ( $tables as $c => $table ) {
			if ( in_array( $table, $global_tables, true ) ) {
				$tables[ $table ] = $base_prefix . $table;
			} else {
				$tables[ $table ] = $blog_prefix . $table;
			}
			unset( $tables[ $c ] );
		}

		if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) {
			$tables['users'] = CUSTOM_USER_TABLE;
		}

		if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) {
			$tables['usermeta'] = CUSTOM_USER_META_TABLE;
		}
	}

	return $tables;
}

Changuelog

Versionen Description
6.1.0 old now includes deprecated multisite global tables only on multisite.
3.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.