| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hostinger\Mcp\Handlers; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
class WebsitePageUpdated extends EventHandler { |
| 8 |
|
| 9 |
const ALLOWED_POST_TYPES = array( 'post', 'product', 'page' ); |
| 10 |
|
| 11 |
public function send( array $args = array() ): void { |
| 12 |
if ( ! $this->can_send( $args ) ) { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
$post = get_post( $args['post_id'] ); |
| 17 |
$args['url'] = get_permalink( $post ); |
| 18 |
$this->send_to_proxy( $args ); |
| 19 |
} |
| 20 |
|
| 21 |
public function can_send( array $args = array() ): bool { |
| 22 |
$post_id = $args['post_id'] ?? false; |
| 23 |
|
| 24 |
if ( ! $post_id ) { |
| 25 |
return false; |
| 26 |
} |
| 27 |
|
| 28 |
$post = get_post( $post_id ); |
| 29 |
if ( ! $post ) { |
| 30 |
return false; |
| 31 |
} |
| 32 |
|
| 33 |
return parent::can_send( $args ) && in_array( $post->post_type, self::ALLOWED_POST_TYPES, true ); |
| 34 |
} |
| 35 |
} |
| 36 |
|