@@ -3,47 +3,47 @@ |
||
| 3 | 3 | namespace Wordlift\Features; |
| 4 | 4 | |
| 5 | 5 | class Response_Adapter { |
| 6 | - const WL_FEATURES = '_wl_features'; |
|
| 7 | - const WL_1 = 'wl1'; |
|
| 6 | + const WL_FEATURES = '_wl_features'; |
|
| 7 | + const WL_1 = 'wl1'; |
|
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @var \Wordlift_Log_Service |
|
| 11 | - */ |
|
| 12 | - private $log; |
|
| 9 | + /** |
|
| 10 | + * @var \Wordlift_Log_Service |
|
| 11 | + */ |
|
| 12 | + private $log; |
|
| 13 | 13 | |
| 14 | - function __construct() { |
|
| 14 | + function __construct() { |
|
| 15 | 15 | |
| 16 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 16 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 17 | 17 | |
| 18 | - add_filter( 'wl_api_service__response', array( $this, 'response' ), 10, 1 ); |
|
| 18 | + add_filter( 'wl_api_service__response', array( $this, 'response' ), 10, 1 ); |
|
| 19 | 19 | |
| 20 | - foreach ( (array) get_option( self::WL_FEATURES, array() ) as $name => $enabled ) { |
|
| 21 | - $callback = ( $enabled ? '__return_true' : '__return_false' ); |
|
| 22 | - add_filter( "wl_feature__enable__${name}", $callback ); |
|
| 23 | - } |
|
| 20 | + foreach ( (array) get_option( self::WL_FEATURES, array() ) as $name => $enabled ) { |
|
| 21 | + $callback = ( $enabled ? '__return_true' : '__return_false' ); |
|
| 22 | + add_filter( "wl_feature__enable__${name}", $callback ); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - } |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - function response( $response ) { |
|
| 27 | + function response( $response ) { |
|
| 28 | 28 | |
| 29 | - $headers = wp_remote_retrieve_headers( $response ); |
|
| 29 | + $headers = wp_remote_retrieve_headers( $response ); |
|
| 30 | 30 | |
| 31 | - // Bail out if the `wl1` header isn't defined. |
|
| 32 | - if ( ! isset( $headers[ self::WL_1 ] ) ) { |
|
| 33 | - return $response; |
|
| 34 | - } |
|
| 35 | - $wl1_as_base64_string = $headers[ self::WL_1 ]; |
|
| 36 | - $wl1 = json_decode( base64_decode( $wl1_as_base64_string ), true ); |
|
| 31 | + // Bail out if the `wl1` header isn't defined. |
|
| 32 | + if ( ! isset( $headers[ self::WL_1 ] ) ) { |
|
| 33 | + return $response; |
|
| 34 | + } |
|
| 35 | + $wl1_as_base64_string = $headers[ self::WL_1 ]; |
|
| 36 | + $wl1 = json_decode( base64_decode( $wl1_as_base64_string ), true ); |
|
| 37 | 37 | |
| 38 | - $this->log->debug( "WL1 [ encoded :: $wl1_as_base64_string ] " . var_export( $wl1, true ) ); |
|
| 38 | + $this->log->debug( "WL1 [ encoded :: $wl1_as_base64_string ] " . var_export( $wl1, true ) ); |
|
| 39 | 39 | |
| 40 | - // Update the feature flags. There's no need to check here if values differ (thus avoiding a call to db), since |
|
| 41 | - // WordPress does that in `update_option`. |
|
| 42 | - if ( isset( $wl1['features'] ) ) { |
|
| 43 | - update_option( self::WL_FEATURES, (array) $wl1['features'], true ); |
|
| 44 | - } |
|
| 40 | + // Update the feature flags. There's no need to check here if values differ (thus avoiding a call to db), since |
|
| 41 | + // WordPress does that in `update_option`. |
|
| 42 | + if ( isset( $wl1['features'] ) ) { |
|
| 43 | + update_option( self::WL_FEATURES, (array) $wl1['features'], true ); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - return $response; |
|
| 47 | - } |
|
| 46 | + return $response; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
@@ -13,34 +13,34 @@ |
||
| 13 | 13 | |
| 14 | 14 | function __construct() { |
| 15 | 15 | |
| 16 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 16 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
| 17 | 17 | |
| 18 | - add_filter( 'wl_api_service__response', array( $this, 'response' ), 10, 1 ); |
|
| 18 | + add_filter('wl_api_service__response', array($this, 'response'), 10, 1); |
|
| 19 | 19 | |
| 20 | - foreach ( (array) get_option( self::WL_FEATURES, array() ) as $name => $enabled ) { |
|
| 21 | - $callback = ( $enabled ? '__return_true' : '__return_false' ); |
|
| 22 | - add_filter( "wl_feature__enable__${name}", $callback ); |
|
| 20 | + foreach ((array) get_option(self::WL_FEATURES, array()) as $name => $enabled) { |
|
| 21 | + $callback = ($enabled ? '__return_true' : '__return_false'); |
|
| 22 | + add_filter("wl_feature__enable__${name}", $callback); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - function response( $response ) { |
|
| 27 | + function response($response) { |
|
| 28 | 28 | |
| 29 | - $headers = wp_remote_retrieve_headers( $response ); |
|
| 29 | + $headers = wp_remote_retrieve_headers($response); |
|
| 30 | 30 | |
| 31 | 31 | // Bail out if the `wl1` header isn't defined. |
| 32 | - if ( ! isset( $headers[ self::WL_1 ] ) ) { |
|
| 32 | + if ( ! isset($headers[self::WL_1])) { |
|
| 33 | 33 | return $response; |
| 34 | 34 | } |
| 35 | - $wl1_as_base64_string = $headers[ self::WL_1 ]; |
|
| 36 | - $wl1 = json_decode( base64_decode( $wl1_as_base64_string ), true ); |
|
| 35 | + $wl1_as_base64_string = $headers[self::WL_1]; |
|
| 36 | + $wl1 = json_decode(base64_decode($wl1_as_base64_string), true); |
|
| 37 | 37 | |
| 38 | - $this->log->debug( "WL1 [ encoded :: $wl1_as_base64_string ] " . var_export( $wl1, true ) ); |
|
| 38 | + $this->log->debug("WL1 [ encoded :: $wl1_as_base64_string ] ".var_export($wl1, true)); |
|
| 39 | 39 | |
| 40 | 40 | // Update the feature flags. There's no need to check here if values differ (thus avoiding a call to db), since |
| 41 | 41 | // WordPress does that in `update_option`. |
| 42 | - if ( isset( $wl1['features'] ) ) { |
|
| 43 | - update_option( self::WL_FEATURES, (array) $wl1['features'], true ); |
|
| 42 | + if (isset($wl1['features'])) { |
|
| 43 | + update_option(self::WL_FEATURES, (array) $wl1['features'], true); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | return $response; |