prefix . 'siteaudithub_' . preg_replace( '/[^a-z_]/', '', $name ); } /** * Whether a plugin table exists. * * @param string $name Short name. * @return bool */ public static function table_exists( $name ) { global $wpdb; $table = self::table( $name ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery return $table === $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ) ); } /** * Current UTC datetime string for DB columns. * * @return string */ public static function now() { return gmdate( 'Y-m-d H:i:s' ); } /** * Safe JSON encode for storage. * * @param mixed $value Value. * @return string */ public static function encode( $value ) { $json = wp_json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR ); return false === $json ? '{}' : $json; } /** * Safe JSON decode (never unserialize). * * @param string|null $json JSON. * @return array */ public static function decode( $json ) { if ( ! is_string( $json ) || '' === $json ) { return array(); } $data = json_decode( $json, true ); return is_array( $data ) ? $data : array(); } }