gcdb::get_blog_prefix()

最后更新于:2021-11-26 08:34:36

gcdb::get_blog_prefix( int$blog_id=null)

Gets blog prefix.

参数

$blog_id

(int) (Optional)

Default value: null

响应

(string) Blog prefix.

源文件

文件: gc-includes/gc-db.php

	public function get_blog_prefix( $blog_id = null ) {
		if ( is_multisite() ) {
			if ( null === $blog_id ) {
				$blog_id = $this->blogid;
			}

			$blog_id = (int) $blog_id;

			if ( defined( 'MULTISITE' ) && ( 0 === $blog_id || 1 === $blog_id ) ) {
				return $this->base_prefix;
			} else {
				return $this->base_prefix . $blog_id . '_';
			}
		} else {
			return $this->base_prefix;
		}
	}
register_activation_hook( __FILE__, 'myplugin_activation' );
function myplugin_activation() {
	// Get access to global database access class
	global $gcdb;
	// Create table on main blog in network mode or single blog
	myplugin_create_table( $gcdb->get_blog_prefix() );
}

function myplugin_create_table( $prefix ) {
	// Prepare SQL query to create database table
	// using function parameter
	$creation_query =
	'CREATE TABLE IF NOT EXISTS ' . $prefix . 'myplugin_bug_data (
	`bug_id` int(20) NOT NULL AUTO_INCREMENT,
	`bug_description` text,
	`bug_version` varchar(10) DEFAULT NULL,
	`bug_report_date` date DEFAULT NULL,
	`bug_status` int(3) NOT NULL DEFAULT 0,
	PRIMARY KEY (`bug_id`)
	);';
	global $gcdb;
	$gcdb->query( $creation_query );
}