diff --git a/src/actions/class-action.php b/src/actions/class-action.php index 86ad159..2c5789c 100644 --- a/src/actions/class-action.php +++ b/src/actions/class-action.php @@ -22,6 +22,8 @@ abstract class Action { * Webhook topic. * * @var string + * + * @since 0.0.14 */ public $topic; @@ -44,7 +46,7 @@ public function register() { } public function unregister() { } /** - * Send events request. + * Send events to Storipress. * * @param array $args The request arguments. * @return void @@ -68,9 +70,33 @@ public function send( $args ): void { $signature = $this->sign( $args ); - $domain = 'D' === substr( $args['client'], 0, 1 ) - ? 'https://storipress.dev' - : 'https://stori.press'; + if ( null === $signature ) { + return; + } + + $domain = null; + + switch ( substr( $args['client'], 0, 1 ) ) { + case 'D': + $domain = 'https://storipress.dev'; + break; + case 'S': + $domain = 'https://storipress.pro'; + break; + case 'P': + $domain = 'https://stori.press'; + break; + case 'L': + case 'T': + $domain = 'http://localhost:8000'; + break; + default: + break; + } + + if ( null === $domain ) { + return; + } $body = wp_json_encode( $args ); @@ -82,9 +108,9 @@ public function send( $args ): void { sprintf( '%s/partners/wordpress/events', $domain ), array( 'headers' => array( - 'Content-Type' => 'application/json', - 'Storipress-Signature' => $signature, - 'Storipress-Timestamp' => time(), + 'Content-Type' => 'application/json', + 'X-Storipress-Signature' => $signature, + 'X-Storipress-Timestamp' => time(), ), 'body' => $body, ) diff --git a/src/actions/class-post-deleted.php b/src/actions/class-post-deleted.php index c2aedfe..22810da 100644 --- a/src/actions/class-post-deleted.php +++ b/src/actions/class-post-deleted.php @@ -29,18 +29,20 @@ class Post_Deleted extends Action { * @link https://developer.wordpress.org/reference/hooks/deleted_post/ */ public function register(): void { - add_action( 'deleted_post', array( &$this, 'handle' ), 10, 2 ); + add_action( 'deleted_post', array( &$this, 'handle' ) ); } /** * Hook action. * - * @param int $post_id Post ID. - * @param WP_POST $post Post object. + * @param int $post_id Post ID. * @return void */ - public function handle( $post_id, $post ): void { - if ( 'post' !== $post->post_type ) { + public function handle( $post_id ): void { + // Compatible with versions below 5.4. There will only be one parameter: post id. + $post = get_post( $post_id ); + + if ( ! ( $post instanceof WP_POST ) || 'post' !== $post->post_type ) { return; }