prefix . 'rb_redirects'; } public static function log_table(): string { global $wpdb; return $wpdb->prefix . 'rb_redirect_404'; } /** on activation: this site, or every site of a network activation */ public static function activate( $network_wide = false ): void { if ( is_multisite() && $network_wide ) { foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0 ) ) as $blog_id ) { switch_to_blog( $blog_id ); self::create_tables(); restore_current_blog(); } return; } self::create_tables(); } /** an update without activation, a new site of the network */ public static function maybe_upgrade(): void { if ( get_option( self::DB_VERSION_OPTION ) !== self::DB_VERSION ) { self::create_tables(); } } public static function create_tables(): void { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $charset = $wpdb->get_charset_collate(); $r = self::redirects_table(); $l = self::log_table(); dbDelta( "CREATE TABLE {$r} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, source text NOT NULL, source_hash char(32) NOT NULL DEFAULT '', match_type varchar(20) NOT NULL DEFAULT 'exact', target text NOT NULL, target_post_id bigint(20) unsigned NOT NULL DEFAULT 0, code smallint(5) unsigned NOT NULL DEFAULT 301, enabled tinyint(1) NOT NULL DEFAULT 1, origin varchar(40) NOT NULL DEFAULT 'manual', note varchar(255) NOT NULL DEFAULT '', hits bigint(20) unsigned NOT NULL DEFAULT 0, last_hit datetime NULL DEFAULT NULL, created datetime NOT NULL, PRIMARY KEY (id), KEY source_hash (source_hash), KEY match_type (match_type), KEY origin (origin) ) {$charset};" ); dbDelta( "CREATE TABLE {$l} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, url text NOT NULL, url_hash char(32) NOT NULL DEFAULT '', hits bigint(20) unsigned NOT NULL DEFAULT 1, referrer text NULL, user_agent varchar(255) NOT NULL DEFAULT '', first_seen datetime NOT NULL, last_seen datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY url_hash (url_hash), KEY last_seen (last_seen) ) {$charset};" ); update_option( self::DB_VERSION_OPTION, self::DB_VERSION ); } }