TipOfDayService = $TipOfDayService; $this->TipOfDayRepository = $TipOfDayRepository; add_action( sprintf('wp_ajax_%s', self::AJAX_METHOD_TIP_OF_DAY), [$this, 'ajaxHide'] ); add_action( sprintf('wp_ajax_%s', self::AJAX_METHOD_DISABLE_TIPS), [$this, 'ajaxDisable'] ); } public function ajaxDisable(): void { $this->verifyNonceAjax(); if (!PageGuardHelper::canAccessPage( Pages::SETTINGS)) { $result = ResultBuilder::buildError($this->getErrorTextNoPermissions()); echo wp_json_encode($result); wp_die(); } a2wl_init_error_handler(); $this->TipOfDayService->disableTips(); $result = ResultBuilder::buildOk(); echo wp_json_encode($result); wp_die(); } public function ajaxHide(): void { $this->verifyNonceAjax(); if (!PageGuardHelper::canAccessPage( Pages::SETTINGS)) { $result = ResultBuilder::buildError($this->getErrorTextNoPermissions()); echo wp_json_encode($result); wp_die(); } $id = sanitize_text_field(wp_unslash($_POST[self::PARAM_ID] ?? '')); a2wl_init_error_handler(); $result = ResultBuilder::buildOk(); try { $TipOfDay = $this->TipOfDayRepository->getOne($id); if (!$TipOfDay) { throw new RepositoryException( _x( "Tip of the day with given ID doesn't exist", 'error text', 'ali2woo' ) ); } $this->TipOfDayService->hideTip($TipOfDay); restore_error_handler(); } catch (RepositoryException $RepositoryException) { $result = ResultBuilder::buildError($RepositoryException->getMessage()); } catch (Exception $Exception) { a2wl_print_throwable($Exception); $result = ResultBuilder::buildError($Exception->getMessage()); } echo wp_json_encode($result); wp_die(); } }