@@ -11,77 +11,77 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Webhooks_Manager { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Registering the actions to call up sync_many or sync_delete methods |
|
| 16 | - */ |
|
| 17 | - |
|
| 18 | - public function __construct() { |
|
| 19 | - add_action( 'wl_sync__sync_many', array( $this, 'sync_many' ), 10 ); |
|
| 20 | - add_action( 'wl_sync__delete_one', array( $this, 'sync_delete' ), 10, 3 ); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Method to call up webhook with post requested |
|
| 25 | - * |
|
| 26 | - * @param array $hashes |
|
| 27 | - */ |
|
| 28 | - |
|
| 29 | - public function sync_many( $hashes ) { |
|
| 30 | - |
|
| 31 | - $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
| 32 | - if ( empty( $urls ) ) { |
|
| 33 | - return; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Allow 3rd parties to filter out the objects that we want to send via webhooks. |
|
| 38 | - * @since 3.34.0 |
|
| 39 | - * @var Sync_Object_Adapter[] $filtered_objects |
|
| 40 | - */ |
|
| 41 | - $filtered_hashes = apply_filters( 'wl_webhooks__sync_many__objects', $hashes ); |
|
| 42 | - |
|
| 43 | - foreach ( $urls as $url ) { |
|
| 44 | - foreach ( $filtered_hashes as $hash ) { |
|
| 45 | - $jsonld = $hash[2]; |
|
| 46 | - $filtered_url = apply_filters( 'wl_webhooks__sync_many__url', $url, $hash ); |
|
| 47 | - wp_remote_request( $filtered_url, apply_filters( 'wl_webhooks__sync_many__args', array( |
|
| 48 | - 'blocking' => false, |
|
| 49 | - 'method' => 'PUT', |
|
| 50 | - 'headers' => array( 'content-type' => 'application/json; ' . get_bloginfo( 'charset' ) ), |
|
| 51 | - 'body' => $jsonld |
|
| 52 | - ) ) ); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Method to call up webhook with delete requested |
|
| 59 | - * |
|
| 60 | - * @param string $type |
|
| 61 | - * @param int $object_id |
|
| 62 | - * @param string $uri |
|
| 63 | - */ |
|
| 64 | - |
|
| 65 | - public function sync_delete( $type, $object_id, $uri ) { |
|
| 66 | - |
|
| 67 | - $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
| 68 | - if ( empty( $urls ) ) { |
|
| 69 | - return; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - if ( ! apply_filters( 'wl_webhooks__sync_delete', true, $type, $object_id, $uri ) ) { |
|
| 73 | - return; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - foreach ( $urls as $template_url ) { |
|
| 77 | - $url = add_query_arg( array( 'uri' => $uri ), $template_url ); |
|
| 78 | - $filtered_url = apply_filters( 'wl_webhooks__sync_delete__url', $url, $type, $object_id, $uri ); |
|
| 79 | - wp_remote_request( $filtered_url, apply_filters( 'wl_webhooks__sync_delete__args', array( |
|
| 80 | - 'blocking' => false, |
|
| 81 | - 'method' => 'DELETE', |
|
| 82 | - ) ) ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - } |
|
| 14 | + /** |
|
| 15 | + * Registering the actions to call up sync_many or sync_delete methods |
|
| 16 | + */ |
|
| 17 | + |
|
| 18 | + public function __construct() { |
|
| 19 | + add_action( 'wl_sync__sync_many', array( $this, 'sync_many' ), 10 ); |
|
| 20 | + add_action( 'wl_sync__delete_one', array( $this, 'sync_delete' ), 10, 3 ); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Method to call up webhook with post requested |
|
| 25 | + * |
|
| 26 | + * @param array $hashes |
|
| 27 | + */ |
|
| 28 | + |
|
| 29 | + public function sync_many( $hashes ) { |
|
| 30 | + |
|
| 31 | + $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
| 32 | + if ( empty( $urls ) ) { |
|
| 33 | + return; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Allow 3rd parties to filter out the objects that we want to send via webhooks. |
|
| 38 | + * @since 3.34.0 |
|
| 39 | + * @var Sync_Object_Adapter[] $filtered_objects |
|
| 40 | + */ |
|
| 41 | + $filtered_hashes = apply_filters( 'wl_webhooks__sync_many__objects', $hashes ); |
|
| 42 | + |
|
| 43 | + foreach ( $urls as $url ) { |
|
| 44 | + foreach ( $filtered_hashes as $hash ) { |
|
| 45 | + $jsonld = $hash[2]; |
|
| 46 | + $filtered_url = apply_filters( 'wl_webhooks__sync_many__url', $url, $hash ); |
|
| 47 | + wp_remote_request( $filtered_url, apply_filters( 'wl_webhooks__sync_many__args', array( |
|
| 48 | + 'blocking' => false, |
|
| 49 | + 'method' => 'PUT', |
|
| 50 | + 'headers' => array( 'content-type' => 'application/json; ' . get_bloginfo( 'charset' ) ), |
|
| 51 | + 'body' => $jsonld |
|
| 52 | + ) ) ); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Method to call up webhook with delete requested |
|
| 59 | + * |
|
| 60 | + * @param string $type |
|
| 61 | + * @param int $object_id |
|
| 62 | + * @param string $uri |
|
| 63 | + */ |
|
| 64 | + |
|
| 65 | + public function sync_delete( $type, $object_id, $uri ) { |
|
| 66 | + |
|
| 67 | + $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
| 68 | + if ( empty( $urls ) ) { |
|
| 69 | + return; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + if ( ! apply_filters( 'wl_webhooks__sync_delete', true, $type, $object_id, $uri ) ) { |
|
| 73 | + return; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + foreach ( $urls as $template_url ) { |
|
| 77 | + $url = add_query_arg( array( 'uri' => $uri ), $template_url ); |
|
| 78 | + $filtered_url = apply_filters( 'wl_webhooks__sync_delete__url', $url, $type, $object_id, $uri ); |
|
| 79 | + wp_remote_request( $filtered_url, apply_filters( 'wl_webhooks__sync_delete__args', array( |
|
| 80 | + 'blocking' => false, |
|
| 81 | + 'method' => 'DELETE', |
|
| 82 | + ) ) ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | } |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | public function __construct() { |
| 19 | - add_action( 'wl_sync__sync_many', array( $this, 'sync_many' ), 10 ); |
|
| 20 | - add_action( 'wl_sync__delete_one', array( $this, 'sync_delete' ), 10, 3 ); |
|
| 19 | + add_action('wl_sync__sync_many', array($this, 'sync_many'), 10); |
|
| 20 | + add_action('wl_sync__delete_one', array($this, 'sync_delete'), 10, 3); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | * @param array $hashes |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | - public function sync_many( $hashes ) { |
|
| 29 | + public function sync_many($hashes) { |
|
| 30 | 30 | |
| 31 | - $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
| 32 | - if ( empty( $urls ) ) { |
|
| 31 | + $urls = explode("\n", get_option(Webhooks_Loader::URLS_OPTION_NAME, '')); |
|
| 32 | + if (empty($urls)) { |
|
| 33 | 33 | return; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -38,18 +38,18 @@ discard block |
||
| 38 | 38 | * @since 3.34.0 |
| 39 | 39 | * @var Sync_Object_Adapter[] $filtered_objects |
| 40 | 40 | */ |
| 41 | - $filtered_hashes = apply_filters( 'wl_webhooks__sync_many__objects', $hashes ); |
|
| 41 | + $filtered_hashes = apply_filters('wl_webhooks__sync_many__objects', $hashes); |
|
| 42 | 42 | |
| 43 | - foreach ( $urls as $url ) { |
|
| 44 | - foreach ( $filtered_hashes as $hash ) { |
|
| 43 | + foreach ($urls as $url) { |
|
| 44 | + foreach ($filtered_hashes as $hash) { |
|
| 45 | 45 | $jsonld = $hash[2]; |
| 46 | - $filtered_url = apply_filters( 'wl_webhooks__sync_many__url', $url, $hash ); |
|
| 47 | - wp_remote_request( $filtered_url, apply_filters( 'wl_webhooks__sync_many__args', array( |
|
| 46 | + $filtered_url = apply_filters('wl_webhooks__sync_many__url', $url, $hash); |
|
| 47 | + wp_remote_request($filtered_url, apply_filters('wl_webhooks__sync_many__args', array( |
|
| 48 | 48 | 'blocking' => false, |
| 49 | 49 | 'method' => 'PUT', |
| 50 | - 'headers' => array( 'content-type' => 'application/json; ' . get_bloginfo( 'charset' ) ), |
|
| 50 | + 'headers' => array('content-type' => 'application/json; '.get_bloginfo('charset')), |
|
| 51 | 51 | 'body' => $jsonld |
| 52 | - ) ) ); |
|
| 52 | + ))); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -62,24 +62,24 @@ discard block |
||
| 62 | 62 | * @param string $uri |
| 63 | 63 | */ |
| 64 | 64 | |
| 65 | - public function sync_delete( $type, $object_id, $uri ) { |
|
| 65 | + public function sync_delete($type, $object_id, $uri) { |
|
| 66 | 66 | |
| 67 | - $urls = explode( "\n", get_option( Webhooks_Loader::URLS_OPTION_NAME, '' ) ); |
|
| 68 | - if ( empty( $urls ) ) { |
|
| 67 | + $urls = explode("\n", get_option(Webhooks_Loader::URLS_OPTION_NAME, '')); |
|
| 68 | + if (empty($urls)) { |
|
| 69 | 69 | return; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if ( ! apply_filters( 'wl_webhooks__sync_delete', true, $type, $object_id, $uri ) ) { |
|
| 72 | + if ( ! apply_filters('wl_webhooks__sync_delete', true, $type, $object_id, $uri)) { |
|
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - foreach ( $urls as $template_url ) { |
|
| 77 | - $url = add_query_arg( array( 'uri' => $uri ), $template_url ); |
|
| 78 | - $filtered_url = apply_filters( 'wl_webhooks__sync_delete__url', $url, $type, $object_id, $uri ); |
|
| 79 | - wp_remote_request( $filtered_url, apply_filters( 'wl_webhooks__sync_delete__args', array( |
|
| 76 | + foreach ($urls as $template_url) { |
|
| 77 | + $url = add_query_arg(array('uri' => $uri), $template_url); |
|
| 78 | + $filtered_url = apply_filters('wl_webhooks__sync_delete__url', $url, $type, $object_id, $uri); |
|
| 79 | + wp_remote_request($filtered_url, apply_filters('wl_webhooks__sync_delete__args', array( |
|
| 80 | 80 | 'blocking' => false, |
| 81 | 81 | 'method' => 'DELETE', |
| 82 | - ) ) ); |
|
| 82 | + ))); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | } |