register_hooks(); } private function register_hooks() { foreach ($this->actions as $action) { add_action($this->action_prefix . $action, [$this, $action]); } } public function get_plugin_connected_status() { $settings = Options::get_site_settings(); $response['aw_app_id'] = $settings['alertwise_setting_app_id']; $response['aw_api_key'] = $settings['alertwise_setting_password']; $response['aw_username'] = $settings['alertwise_setting_username']; wp_send_json_success($response, 200); } private function get_post_text($key) { return isset($_POST[$key]) ? sanitize_text_field(wp_unslash($_POST[$key])) : ''; } public function update_onboarding_data() { $settings = Options::get_site_settings(); $settings['alertwise_setting_username'] = $this->get_post_text('aw_username'); $settings['alertwise_setting_password'] = $this->get_post_text('aw_api_key'); $settings['alertwise_setting_access_token'] = $this->get_post_text('access_token'); $settings['alertwise_setting_token_type'] = $this->get_post_text('token_type'); $settings['alertwise_setting_expires_in'] = filter_var($_POST['expires_in'], FILTER_SANITIZE_NUMBER_INT); $settings['alertwise_setting_owner_id'] = $this->get_post_text('owner_id'); $settings['alertwise_setting_app_server_public_key'] = $this->get_post_text('appServerPublicKey'); $settings['alertwise_setting_app_id'] = $this->get_post_text('aw_app_id'); $settings['alertwise_setting_app_name'] = $this->get_post_text('appName'); $settings['alertwise_setting_app_url'] = $this->get_post_text('appUrl'); $settings['alertwise_setting_icon_url'] = $this->get_post_text('iconUrl'); $settings['alertwise_setting_badge_icon_url'] = $this->get_post_text('badgeIconUrl'); $settings['alertwise_setting_created_at'] = gmdate('Y-m-d H:i:s'); error_log("setting----> " . print_r($settings, true)); Options::update_site_settings($settings); Helpers::inject_localstorage_script( $settings['alertwise_setting_app_id'], $settings['alertwise_setting_username'], $settings['alertwise_setting_access_token'] ); $post_page_settings = Options::get_post_page_settings(); $post_page_settings['post_notifications'] = isset($_POST['postNotification']); $post_page_settings['page_notifications'] = isset($_POST['pageNotification']); update_option('alertwise_post_page_settings', $post_page_settings); wp_send_json_success(null, 200); } public function update_post_page_setting_data() { $post_page_settings = Options::get_post_page_settings(); $post_page_settings['post_notifications'] = ($_POST['postNotification'] === 'true'); $post_page_settings['page_notifications'] = ($_POST['pageNotification'] === 'true'); update_option('alertwise_post_page_settings', $post_page_settings); wp_send_json_success($post_page_settings, 200); } public function get_post_page_setting_data() { $post_page_settings = Options::get_post_page_settings(); wp_send_json_success($post_page_settings, 200); } public function get_plugin_data() { $plugin_data = AlertwiseAPI::instance()->get_plugin_info(); if (json_last_error() !== JSON_ERROR_NONE || empty($plugin_data)) { wp_send_json_error(__('Failed to decode plugin data.', 'alertwise'), 400); } $formatted = [ 'name' => html_entity_decode($plugin_data['name']), 'version' => $plugin_data['version'], 'description' => mb_substr(strip_tags($plugin_data['sections']['description']), 0, 387), 'author' => $plugin_data['author'], 'lastUpdated' => ($d = \DateTime::createFromFormat('Y-m-d g:ia T', $plugin_data['last_updated'])) ? $d->format('d F Y') : '', 'wordpress_version' => $plugin_data['requires'], 'php_version' => $plugin_data['requires_php'] . ' or higher', ]; wp_send_json_success($formatted, 200); } }