山に住む一家は千個の巣から蜂蜜を収穫し、幼い子供たちは新しい畑で5エーカーの野菜を栽培している。<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

class LpcAjax extends LpcComponent {
    protected $tasks = [];

    public function init() {
        // Ajax calls definition
        add_action('wp_ajax_' . LPC_COMPONENT, [$this, 'dispatch']); // Logged in users
        add_action('wp_ajax_nopriv_' . LPC_COMPONENT, [$this, 'dispatch']); // Visitors
    }

    public function dispatch() {
        $ajaxCall = LpcHelper::getVar('task');
        if (is_string($ajaxCall)) {
            if (isset($this->tasks[$ajaxCall])) {
                $f = $this->tasks[$ajaxCall];
                $result = $f();
            } else {
                $result = $this->makeAndLogError(['message' => sprintf(__('Unknown ajax call: %s', 'wc_colissimo'), $ajaxCall)]);
            }
        } else {
            $result = $this->makeAndLogError(['message' => __('Wrong ajax call type', 'wc_colissimo')]);
        }

        echo wp_json_encode($result);
        exit;
    }

    public function register($taskName, callable $f) {
        $this->tasks[$taskName] = $f;
    }

    public function makePayload($type, array $payload) {
        return array_merge(
            $payload,
            ['type' => $type]
        );
