Weak hands cannot be planted, meager skills have no foundation. Shallow wisdom is futile, how can one hope for a good name?扰扰从役倦，屑屑身事微。少壮轻年月，迟暮惜光辉。
<html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><?php

namespace Hostinger\Mcp\Handlers;

use Hostinger\Admin\Proxy;
use Hostinger\Mcp\EventHandlerFactory;

defined( 'ABSPATH' ) || exit;

abstract class EventHandler {

    public Proxy $proxy;

    public function __construct( Proxy $proxy ) {
        $this->proxy = $proxy;
    }

    protected function send_to_proxy( array $args = array() ): bool {
        if ( ! $this->can_send( $args ) ) {
            $this->debug_mcp( 'Event failed: User is not opted in' . ' -- ' . print_r( $args, true ) );
            return false;
        }

        $event   = $args['event'];
        $request = $this->proxy->trigger_event( $event, $args );
        if ( is_wp_error( $request ) ) {
            $this->debug_mcp( 'Event failed: ' . $event . $request->get_error_message() . ' -- ' . print_r( $args, true ) );
            return false;
        }

        $response_code = wp_remote_retrieve_response_code( $request );
        if ( $response_code < 300 ) {
            $this->debug_mcp( 'Event sent: ' . $event . ' -- ' . print_r( $args, true ) );
            return true;
        }

        $this->debug_mcp( 'Event failed: ' . $event . ' --' . $response_code . ' -- ' . print_r( $args, true ) );
        return false;
    }

    public function can_send( array $args = array() ): bool {
        return isset( $args['event'] ) && ( $this->is_optin_event( $args['event'] ) || $this->is_opted_in() );
    }

    p