Skip to content

Commit

Permalink
chore: apply changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrisbee committed Jan 15, 2024
1 parent 7ddb3d4 commit ac1fbe7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
40 changes: 33 additions & 7 deletions src/actions/class-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ abstract class Action {
* Webhook topic.
*
* @var string
*
* @since 0.0.14
*/
public $topic;

Expand All @@ -44,7 +46,7 @@ public function register() { }
public function unregister() { }

/**
* Send events request.
* Send events to Storipress.
*
* @param array<mixed> $args The request arguments.
* @return void
Expand All @@ -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 );

Expand All @@ -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,
)
Expand Down
12 changes: 7 additions & 5 deletions src/actions/class-post-deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ac1fbe7

Please sign in to comment.