register(new \Axilweb_Ajl_Elementor_Ai_Job_Listing_Widget()); } /** * Fetches job listings from an external API based on widget settings. * * @param array $settings Settings for the API request, including job limit and ordering. * * @return array|WP_Error API response or error. */ private function axilweb_ajl_get_jobs_from_api($settings) { $base_url = home_url() . '/wp-json/ai_job_listing/v1/jobs-frontend'; $params = array( 'per_page' => $settings['job_limit'], 'orderby' => 'id', 'order' => $settings['ordering'], ); $url = $base_url . '?' . http_build_query($params); $arguments = array( 'method' => 'GET', 'timeout' => 10, ); $response = wp_remote_get($url, $arguments); if (is_wp_error($response)) { return $response; } $response_code = wp_remote_retrieve_response_code($response); if ($response_code !== 200) { $response_body = wp_remote_retrieve_body($response); error_log('AI Job Listing API Error: Code ' . $response_code . ', Body: ' . $response_body . ', URL: ' . $url); return new \WP_Error('api_error', sprintf(__('Invalid API response (Code: %d). Please check if the plugin is properly activated and the database is set up correctly.', 'ai-job-listing'), $response_code), ['status' => $response_code] ); } return $response; } /** * Renders the HTML for a list of job listings. * * @param object $results The job listings fetched from the API. * * @return string The HTML output for the job listings. */ private function axilweb_ajl_render_jobs_html($results) { $html = '
' . $result->description . '