gcdb::set_prefix()
最后更新于:2021-11-26 09:04:42
gcdb::set_prefix( string$prefix, bool$set_table_names=true)Sets the table prefix for the GeChiUI tables.
参数
- $prefix
-
(string) (Required) Alphanumeric name for the new prefix.
- $set_table_names
-
(bool) (Optional) Whether the table names, e.g. gcdb::$posts, should be updated or not.
Default value: true
响应
(string|GC_Error) Old prefix or GC_Error on error.
源文件
文件: gc-includes/gc-db.php
public function set_prefix( $prefix, $set_table_names = true ) {
if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) {
return new GC_Error( 'invalid_db_prefix', 'Invalid database prefix' );
}
$old_prefix = is_multisite() ? '' : $prefix;
if ( isset( $this->base_prefix ) ) {
$old_prefix = $this->base_prefix;
}
$this->base_prefix = $prefix;
if ( $set_table_names ) {
foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) {
$this->$table = $prefixed_table;
}
if ( is_multisite() && empty( $this->blogid ) ) {
return $old_prefix;
}
$this->prefix = $this->get_blog_prefix();
foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) {
$this->$table = $prefixed_table;
}
foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) {
$this->$table = $prefixed_table;
}
}
return $old_prefix;
}