Styling fix

This commit is contained in:
moon 2022-04-15 06:50:04 -07:00
parent 7ae6f3e584
commit c3ad996eb2
1 changed files with 24 additions and 22 deletions

View File

@ -1,17 +1,17 @@
<?php <?php
$filters = get_option( WCA_Test_Helper_Rest_Api_Filters::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION ); $filters = get_option(WCA_Test_Helper_Rest_Api_Filters::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION);
function array_dot_set( &$array, $key, $value ) { function array_dot_set( &$array, $key, $value ) {
if ( is_null( $key ) ) { if ( is_null( $key ) ) {
return $array = $value; return $array = $value;
} }
$keys = explode( '.', $key ); $keys = explode('.', $key);
while ( count( $keys ) > 1 ) { while ( count($keys) > 1 ) {
$key = array_shift( $keys ); $key = array_shift($keys);
if (! isset( $array[$key] ) || ! is_array( $array[$key]) ) { if (! isset($array[$key]) || ! is_array($array[$key]) ) {
$array[$key] = []; $array[$key] = [];
} }
$array = &$array[$key]; $array = &$array[$key];
@ -23,25 +23,27 @@ function array_dot_set( &$array, $key, $value ) {
add_filter( add_filter(
'rest_request_after_callbacks', 'rest_request_after_callbacks',
function( $response, array $handler, \WP_REST_Request $request ) use ( $filters ) { function ( $response, array $handler, \WP_REST_Request $request ) use ( $filters ) {
if ( ! $response instanceof \WP_REST_Response ) { if (! $response instanceof \WP_REST_Response ) {
return $response; return $response;
} }
$route = $request->get_route(); $route = $request->get_route();
$filters = array_filter( $filters, function( $filter ) use ( $request, $route ) { $filters = array_filter(
if ( $filter['enabled'] && $filter['endpoint'] == $route ) { $filters, function ( $filter ) use ( $request, $route ) {
if ($filter['enabled'] && $filter['endpoint'] == $route ) {
return true; return true;
} }
return false; return false;
}); }
);
$data = $response->get_data(); $data = $response->get_data();
foreach ( $filters as $filter ) { foreach ( $filters as $filter ) {
array_dot_set( $data, $filter['dot_notation'], $filter['replacement'] ); array_dot_set($data, $filter['dot_notation'], $filter['replacement']);
} }
$response->set_data( $data ); $response->set_data($data);
return $response; return $response;
}, },