prefix . 'glovario_variables'; $categories = $wpdb->prefix . 'glovario_categories'; $rules = $wpdb->prefix . 'glovario_rules'; $charset = $wpdb->get_charset_collate(); dbDelta( "CREATE TABLE {$categories} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, name varchar(191) NOT NULL, slug varchar(191) NOT NULL, description text NULL, created_at datetime NOT NULL, updated_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY slug (slug), KEY name (name) ) {$charset};" ); $sql = "CREATE TABLE {$table} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, variable_key varchar(191) NOT NULL, label varchar(191) NOT NULL, type varchar(32) NOT NULL, value longtext NOT NULL, description text NULL, category_id bigint(20) unsigned NULL, created_at datetime NOT NULL, updated_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY variable_key (variable_key), KEY type (type), KEY category_id (category_id) ) {$charset};"; dbDelta( $sql ); dbDelta( "CREATE TABLE {$rules} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, variable_id bigint(20) unsigned NOT NULL, name varchar(191) NULL, alternative_value longtext NOT NULL, enabled tinyint(1) NOT NULL DEFAULT 1, priority int(11) NOT NULL DEFAULT 10, conditions longtext NOT NULL, created_at datetime NOT NULL, updated_at datetime NOT NULL, PRIMARY KEY (id), KEY variable_id (variable_id), KEY resolution (variable_id,enabled,priority) ) {$charset};" ); // Read on every front-end request: keep them in WordPress's autoloaded options // (one query for all) instead of one query each. Existing installs switch here. update_option( self::OPTION, GLOVARIO_DB_VERSION, true ); $autoloaded = array( self::OPTION, \Glovario\Frontend\TitleShortcodes::OPTION, \Glovario\Locale\LocaleManager::OPTION ); // Available since WordPress 6.4, the minimum version; guarded all the same. if ( function_exists( 'wp_set_option_autoload_values' ) ) { wp_set_option_autoload_values( array_fill_keys( $autoloaded, true ) ); return; } // update_option() keeps the autoload flag of an unchanged value: store it again. foreach ( $autoloaded as $name ) { $value = get_option( $name, null ); if ( null !== $value && delete_option( $name ) ) { add_option( $name, $value, '', true ); } } } }