Redactor::MASK, 'truncated' => false, ); } $value = maybe_unserialize( $value ); if ( ! is_scalar( $value ) && null !== $value ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode -- preview text only. $value = (string) json_encode( Redactor::redact( $value ), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); } $text = (string) $value; if ( strlen( $text ) > self::PREVIEW_LENGTH ) { return array( 'value' => substr( $text, 0, self::PREVIEW_LENGTH ) . '...', 'truncated' => true, ); } return array( 'value' => $text, 'truncated' => false, ); } /** * ISO 8601 time for a Unix timestamp, or null. * * @param mixed $timestamp Timestamp. * @return string|null */ public static function iso( $timestamp ): ?string { if ( ! is_numeric( $timestamp ) || (int) $timestamp <= 0 ) { return null; } return gmdate( 'c', (int) $timestamp ); } /** * Turns a WP-CLI style pattern (* and ?) into a LIKE pattern. * * @param object $db The $wpdb object. * @param string $search Pattern. * @return string */ public static function like( $db, string $search ): string { return str_replace( array( '*', '?' ), array( '%', '_' ), $db->esc_like( $search ) ); } }