Styling fix

This commit is contained in:
moon 2022-04-15 06:51:12 -07:00
parent c3ad996eb2
commit 9aaf994638
1 changed files with 93 additions and 87 deletions

View File

@ -57,17 +57,18 @@ class WCA_Test_Helper_Rest_Api_Filters {
const WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION = 'wc-admin-test-helper-rest-api-filters'; const WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION = 'wc-admin-test-helper-rest-api-filters';
public static function create( $request ) { public static function create( $request ) {
$endpoint = $request->get_param( 'endpoint' ); $endpoint = $request->get_param('endpoint');
$dot_notation = $request->get_param( 'dot_notation' ); $dot_notation = $request->get_param('dot_notation');
$replacement = $request->get_param( 'replacement' ); $replacement = $request->get_param('replacement');
if ( $replacement === 'false' ) { if ($replacement === 'false' ) {
$replacement = false; $replacement = false;
} else if ( $replacement === 'true' ) { } else if ($replacement === 'true' ) {
$replacement = true; $replacement = true;
} }
self::update( function( $filters ) use ( self::update(
function ( $filters ) use (
$endpoint, $endpoint,
$dot_notation, $dot_notation,
$replacement $replacement
@ -79,31 +80,36 @@ class WCA_Test_Helper_Rest_Api_Filters {
'enabled' => true, 'enabled' => true,
); );
return $filters; return $filters;
}); }
return new WP_REST_RESPONSE( null, 204 ); );
return new WP_REST_RESPONSE(null, 204);
} }
public static function update( callable $callback ) { public static function update( callable $callback ) {
$filters = get_option( self::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, array() ); $filters = get_option(self::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, array());
$filters = $callback( $filters ); $filters = $callback( $filters );
return update_option( self::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, $filters ); return update_option(self::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, $filters);
} }
public static function delete( $request ) { public static function delete( $request ) {
self::update(function($filters) use ($request) { self::update(
array_splice( $filters, $request->get_param( 'index' ), 1 ); function ( $filters ) use ( $request ) {
array_splice($filters, $request->get_param('index'), 1);
return $filters; return $filters;
}); }
);
return new WP_REST_RESPONSE( null, 204 ); return new WP_REST_RESPONSE(null, 204);
} }
public static function toggle( $request ) { public static function toggle( $request ) {
self::update(function($filters) use ($request) { self::update(
$index = $request->get_param( 'index' ); function ( $filters ) use ( $request ) {
$index = $request->get_param('index');
$filters[$index]['enabled'] = !$filters[$index]['enabled']; $filters[$index]['enabled'] = !$filters[$index]['enabled'];
return $filters; return $filters;
}); }
return new WP_REST_RESPONSE( null, 204 ); );
return new WP_REST_RESPONSE(null, 204);
} }
} }