: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
private static $table = null;
public static function init(){
if (self::$table === null) {
$errors = $wpdb->show_errors;
self::$table = $wpdb->prefix . 'tf_storage';
$q = 'CREATE TABLE IF NOT EXISTS ' . self::$table . ' (
`key` CHAR(16) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL PRIMARY KEY,
`value` MEDIUMTEXT NOT NULL,
) ENGINE=InnoDB ' . $wpdb->get_charset_collate() . ';';
public static function cleanDb(){
if (self::init() !== false) {
$q = 'DELETE FROM %s WHERE `expire` IS NOT NULL AND `expire`<' . time();
public static function query(string $q){
if (self::init() !== false) {
return $wpdb->query(sprintf($q, self::$table));
public static function get(string $key,string $prefix = ''){
$k = self::getHash($key, $prefix);
if (self::init() !== false) {
$res = $wpdb->get_row('SELECT `value`,`expire` FROM ' . self::$table . ' WHERE `key`="' . esc_sql($k) . '" LIMIT 1');
if (!empty($res->expire) && time() > $res->expire) {
self::delete($key, $prefix);
elseif (isset($res->value)) {
return get_transient($k);
public static function set(string $key, $v, $exp = null,string $prefix = ''){
$k = self::getHash($key, $prefix);
} elseif ($v === true || $v === false) {
$v = $v === true ? '1' : '0';
if (self::init() !== false) {
$exp = $exp === null?'DEFAULT':((int)$exp + time());
$q = 'INSERT INTO ' . self::$table . ' (`key`,`value`,`expire`) VALUES ("' . esc_sql($k) . '","' . esc_sql($v) . '",' . $exp . ') ON DUPLICATE KEY UPDATE `value`=VALUES(value),`expire`=VALUES(expire)';
return set_transient($k, $v, $exp);
public static function delete(string $k,string $prefix = ''){
$k = self::getHash($k, $prefix);
if (self::init() !== false) {
$q = 'DELETE FROM ' . self::$table . ' WHERE `key`="' . esc_sql($k) . '" LIMIT 1';
return delete_transient($k);
public static function getHash(string $k,string $prefix = ''):string{
if (in_array('xxh3', $hashs, true)) {
} elseif (in_array('fnv1a64', $hashs, true)) {
$k = substr_replace($k, $prefix, 0, strlen($prefix));
public static function deleteByPrefix(string $prefix){
return self::query('DELETE FROM %s WHERE `key` LIKE "' . esc_sql($prefix) . '%%' . '"');