feat: guard admin package imports
This commit is contained in:
+69
-1
@@ -47,6 +47,22 @@ if ( ! function_exists( 'wp_strip_all_tags' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wp_unslash' ) ) {
|
||||
/**
|
||||
* Minimal slashes remover for unit tests.
|
||||
*
|
||||
* @param mixed $value Value to unslash.
|
||||
* @return mixed
|
||||
*/
|
||||
function wp_unslash( $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
return array_map( 'wp_unslash', $value );
|
||||
}
|
||||
|
||||
return is_string( $value ) ? stripslashes( $value ) : $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'esc_html' ) ) {
|
||||
/**
|
||||
* Minimal HTML escaper for unit tests.
|
||||
@@ -323,7 +339,59 @@ if ( ! function_exists( 'current_user_can' ) ) {
|
||||
* @return bool
|
||||
*/
|
||||
function current_user_can( $capability ) {
|
||||
return 'manage_options' === $capability;
|
||||
return $GLOBALS['wpcs_current_user_can'][ $capability ] ?? 'manage_options' === $capability;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'check_admin_referer' ) ) {
|
||||
/**
|
||||
* Minimal nonce checker for unit tests.
|
||||
*
|
||||
* @param string $action Nonce action.
|
||||
* @param string $query_arg Nonce request field.
|
||||
* @return bool
|
||||
*/
|
||||
function check_admin_referer( $action, $query_arg = '_wpnonce' ) {
|
||||
return $GLOBALS['wpcs_nonce_valid'][ $action ][ $query_arg ] ?? true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wp_safe_redirect' ) ) {
|
||||
/**
|
||||
* Minimal safe redirect helper for unit tests.
|
||||
*
|
||||
* @param string $location Redirect location.
|
||||
* @return bool
|
||||
*/
|
||||
function wp_safe_redirect( $location ) {
|
||||
$GLOBALS['wpcs_redirect_location'] = $location;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'admin_url' ) ) {
|
||||
/**
|
||||
* Minimal admin URL helper for unit tests.
|
||||
*
|
||||
* @param string $path Admin path.
|
||||
* @return string
|
||||
*/
|
||||
function admin_url( $path = '' ) {
|
||||
return 'https://example.test/wp-admin/' . ltrim( $path, '/' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'add_query_arg' ) ) {
|
||||
/**
|
||||
* Minimal query arg helper for unit tests.
|
||||
*
|
||||
* @param array<string, string> $args Query args.
|
||||
* @param string $url URL.
|
||||
* @return string
|
||||
*/
|
||||
function add_query_arg( array $args, $url ) {
|
||||
return $url . ( false === strpos( $url, '?' ) ? '?' : '&' ) . http_build_query( $args );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user