@@ -11,12 +11,12 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | class Api_Data_Hooks |
| 13 | 13 | { |
| 14 | - const API_URL = 'https://api.wordlift.io/data/'; |
|
| 14 | + const API_URL = 'https://api.wordlift.io/data/'; |
|
| 15 | 15 | |
| 16 | - const META_KEY = 'wl_schema_url'; |
|
| 16 | + const META_KEY = 'wl_schema_url'; |
|
| 17 | 17 | |
| 18 | - public function __construct() |
|
| 19 | - { |
|
| 18 | + public function __construct() |
|
| 19 | + { |
|
| 20 | 20 | /** |
| 21 | 21 | * Hook for Post Save |
| 22 | 22 | */ |
@@ -25,26 +25,26 @@ discard block |
||
| 25 | 25 | * Check for Meta Key change on Post Save |
| 26 | 26 | */ |
| 27 | 27 | add_action( 'updated_post_meta', array( $this, 'post_meta_request_delete_cache'), 10, 4 ); |
| 28 | - } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function post_save_request_delete_cache( $post_id ) |
|
| 31 | - { |
|
| 30 | + public function post_save_request_delete_cache( $post_id ) |
|
| 31 | + { |
|
| 32 | 32 | return $this->get_values( $post_id ); |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function post_meta_request_delete_cache( $meta_id, $post_id, $meta_key, $_meta_value ) |
|
| 36 | - { |
|
| 35 | + public function post_meta_request_delete_cache( $meta_id, $post_id, $meta_key, $_meta_value ) |
|
| 36 | + { |
|
| 37 | 37 | if ( self::META_KEY === $meta_key ) { |
| 38 | - return $this->get_values( $post_id ); |
|
| 38 | + return $this->get_values( $post_id ); |
|
| 39 | + } |
|
| 39 | 40 | } |
| 40 | - } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param integer $post_id |
|
| 44 | - * @return |
|
| 45 | - * |
|
| 46 | - */ |
|
| 47 | - private function get_values( $post_id ) { |
|
| 42 | + /** |
|
| 43 | + * @param integer $post_id |
|
| 44 | + * @return |
|
| 45 | + * |
|
| 46 | + */ |
|
| 47 | + private function get_values( $post_id ) { |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Get Post Meta Values |
@@ -55,13 +55,13 @@ discard block |
||
| 55 | 55 | * Iterate over $values array |
| 56 | 56 | */ |
| 57 | 57 | if ( !empty( $values ) && count( $values ) > 1 ) { |
| 58 | - foreach ( $values as $link ) { |
|
| 58 | + foreach ( $values as $link ) { |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Skip the <permalink> |
| 62 | 62 | */ |
| 63 | 63 | if ( $link === '<permalink>' ) { |
| 64 | - $link = get_permalink(); |
|
| 64 | + $link = get_permalink(); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -72,26 +72,26 @@ discard block |
||
| 72 | 72 | * Make actual API DELETE cache request |
| 73 | 73 | */ |
| 74 | 74 | return $this->api_call_delete_cache( $link ); |
| 75 | - } |
|
| 75 | + } |
|
| 76 | + } |
|
| 76 | 77 | } |
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @desc Sanitize the $link |
|
| 81 | - * @param string $link |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - private function sanitize( $link ) { |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @desc Sanitize the $link |
|
| 81 | + * @param string $link |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + private function sanitize( $link ) { |
|
| 85 | 85 | return preg_replace( '/:\//i', '/', $link ); |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @desc Do a DELETE request with WP request function |
|
| 90 | - * @param string $path path that goes after the URL eg. "/user/login" |
|
| 91 | - * |
|
| 92 | - * @return bool True if successful otherwise false |
|
| 93 | - */ |
|
| 94 | - private function api_call_delete_cache( $path ) { |
|
| 88 | + /** |
|
| 89 | + * @desc Do a DELETE request with WP request function |
|
| 90 | + * @param string $path path that goes after the URL eg. "/user/login" |
|
| 91 | + * |
|
| 92 | + * @return bool True if successful otherwise false |
|
| 93 | + */ |
|
| 94 | + private function api_call_delete_cache( $path ) { |
|
| 95 | 95 | |
| 96 | 96 | $log = \Wordlift_Log_Service::get_logger('api_call_delete_cache'); |
| 97 | 97 | |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | $url = self::API_URL . $path; |
| 101 | 101 | $args = array( |
| 102 | - 'method' => 'DELETE', |
|
| 103 | - 'port' => 443 |
|
| 102 | + 'method' => 'DELETE', |
|
| 103 | + 'port' => 443 |
|
| 104 | 104 | ); |
| 105 | 105 | |
| 106 | 106 | // Execute the request |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | // If an error occured, return false |
| 110 | 110 | if ( is_wp_error( $api_response ) || 200 !== (int) $api_response['response']['code'] ) { |
| 111 | 111 | |
| 112 | - $log->warn( var_export($api_response, true) ); |
|
| 112 | + $log->warn( var_export($api_response, true) ); |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 114 | + return false; |
|
| 115 | 115 | |
| 116 | 116 | } |
| 117 | 117 | |
@@ -119,5 +119,5 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | return true; |
| 121 | 121 | |
| 122 | - } |
|
| 122 | + } |
|
| 123 | 123 | } |
@@ -20,22 +20,22 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * Hook for Post Save |
| 22 | 22 | */ |
| 23 | - add_action( 'save_post', array( $this, 'post_save_request_delete_cache' )); |
|
| 23 | + add_action('save_post', array($this, 'post_save_request_delete_cache')); |
|
| 24 | 24 | /** |
| 25 | 25 | * Check for Meta Key change on Post Save |
| 26 | 26 | */ |
| 27 | - add_action( 'updated_post_meta', array( $this, 'post_meta_request_delete_cache'), 10, 4 ); |
|
| 27 | + add_action('updated_post_meta', array($this, 'post_meta_request_delete_cache'), 10, 4); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function post_save_request_delete_cache( $post_id ) |
|
| 30 | + public function post_save_request_delete_cache($post_id) |
|
| 31 | 31 | { |
| 32 | - return $this->get_values( $post_id ); |
|
| 32 | + return $this->get_values($post_id); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function post_meta_request_delete_cache( $meta_id, $post_id, $meta_key, $_meta_value ) |
|
| 35 | + public function post_meta_request_delete_cache($meta_id, $post_id, $meta_key, $_meta_value) |
|
| 36 | 36 | { |
| 37 | - if ( self::META_KEY === $meta_key ) { |
|
| 38 | - return $this->get_values( $post_id ); |
|
| 37 | + if (self::META_KEY === $meta_key) { |
|
| 38 | + return $this->get_values($post_id); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -44,34 +44,34 @@ discard block |
||
| 44 | 44 | * @return |
| 45 | 45 | * |
| 46 | 46 | */ |
| 47 | - private function get_values( $post_id ) { |
|
| 47 | + private function get_values($post_id) { |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Get Post Meta Values |
| 51 | 51 | */ |
| 52 | - $values = get_post_meta( $post_id, self::META_KEY, false ); |
|
| 52 | + $values = get_post_meta($post_id, self::META_KEY, false); |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Iterate over $values array |
| 56 | 56 | */ |
| 57 | - if ( !empty( $values ) && count( $values ) > 1 ) { |
|
| 58 | - foreach ( $values as $link ) { |
|
| 57 | + if ( ! empty($values) && count($values) > 1) { |
|
| 58 | + foreach ($values as $link) { |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Skip the <permalink> |
| 62 | 62 | */ |
| 63 | - if ( $link === '<permalink>' ) { |
|
| 63 | + if ($link === '<permalink>') { |
|
| 64 | 64 | $link = get_permalink(); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * Sanitize the link |
| 69 | 69 | */ |
| 70 | - $link = $this->sanitize( $link ); |
|
| 70 | + $link = $this->sanitize($link); |
|
| 71 | 71 | /** |
| 72 | 72 | * Make actual API DELETE cache request |
| 73 | 73 | */ |
| 74 | - return $this->api_call_delete_cache( $link ); |
|
| 74 | + return $this->api_call_delete_cache($link); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | * @param string $link |
| 82 | 82 | * @return string |
| 83 | 83 | */ |
| 84 | - private function sanitize( $link ) { |
|
| 85 | - return preg_replace( '/:\//i', '/', $link ); |
|
| 84 | + private function sanitize($link) { |
|
| 85 | + return preg_replace('/:\//i', '/', $link); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -91,31 +91,31 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * @return bool True if successful otherwise false |
| 93 | 93 | */ |
| 94 | - private function api_call_delete_cache( $path ) { |
|
| 94 | + private function api_call_delete_cache($path) { |
|
| 95 | 95 | |
| 96 | 96 | $log = \Wordlift_Log_Service::get_logger('api_call_delete_cache'); |
| 97 | 97 | |
| 98 | - $log->debug( "Request started:: $path" ); |
|
| 98 | + $log->debug("Request started:: $path"); |
|
| 99 | 99 | |
| 100 | - $url = self::API_URL . $path; |
|
| 100 | + $url = self::API_URL.$path; |
|
| 101 | 101 | $args = array( |
| 102 | 102 | 'method' => 'DELETE', |
| 103 | 103 | 'port' => 443 |
| 104 | 104 | ); |
| 105 | 105 | |
| 106 | 106 | // Execute the request |
| 107 | - $api_response = wp_remote_request( $url, $args ); |
|
| 107 | + $api_response = wp_remote_request($url, $args); |
|
| 108 | 108 | |
| 109 | 109 | // If an error occured, return false |
| 110 | - if ( is_wp_error( $api_response ) || 200 !== (int) $api_response['response']['code'] ) { |
|
| 110 | + if (is_wp_error($api_response) || 200 !== (int) $api_response['response']['code']) { |
|
| 111 | 111 | |
| 112 | - $log->warn( var_export($api_response, true) ); |
|
| 112 | + $log->warn(var_export($api_response, true)); |
|
| 113 | 113 | |
| 114 | 114 | return false; |
| 115 | 115 | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - $log->debug( "Request executed successfully" ); |
|
| 118 | + $log->debug("Request executed successfully"); |
|
| 119 | 119 | |
| 120 | 120 | return true; |
| 121 | 121 | |