feat: add sync context and operation state

This commit is contained in:
Keith Solomon
2026-04-28 13:51:38 -05:00
parent 90cb78b712
commit b176a37457
6 changed files with 334 additions and 0 deletions
+42
View File
@@ -51,6 +51,18 @@ if ( ! function_exists( 'sanitize_text_field' ) ) {
}
}
if ( ! function_exists( 'sanitize_key' ) ) {
/**
* Minimal WordPress-compatible key sanitizer for unit tests.
*
* @param mixed $key Key to sanitize.
* @return string
*/
function sanitize_key( $key ) {
return strtolower( preg_replace( '/[^a-zA-Z0-9_\-]/', '', (string) $key ) );
}
}
if ( ! function_exists( 'wp_strip_all_tags' ) ) {
/**
* Minimal tag stripper for unit tests.
@@ -223,6 +235,36 @@ if ( ! function_exists( 'delete_transient' ) ) {
*/
function delete_transient( $name ) {
unset( $GLOBALS['wpcs_test_transients'][ $name ] );
unset( $GLOBALS['wpcs_test_transient_expiration'][ $name ] );
return true;
}
}
if ( ! function_exists( 'get_transient' ) ) {
/**
* Minimal WordPress transient reader for unit tests.
*
* @param string $name Transient name.
* @return mixed
*/
function get_transient( $name ) {
return $GLOBALS['wpcs_test_transients'][ $name ] ?? false;
}
}
if ( ! function_exists( 'set_transient' ) ) {
/**
* Minimal WordPress transient writer for unit tests.
*
* @param string $name Transient name.
* @param mixed $value Transient value.
* @param int $expiration Expiration in seconds.
* @return bool
*/
function set_transient( $name, $value, $expiration = 0 ) {
$GLOBALS['wpcs_test_transients'][ $name ] = $value;
$GLOBALS['wpcs_test_transient_expiration'][ $name ] = $expiration;
return true;
}