$attributes['jobslimit'], 'orderby' => 'id', // 'order' => $attributes['post_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 Gutenberg Block 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 job listings for Gutenberg block with job departments and application deadlines. * * This function: * - Retrieves the padding settings from the block attributes. * - Fetches job data from the external API using `Helpers::get_jobs_from_api()`. * - If successful, decodes the job data and extracts attributes like job departments and deadlines. * - Iterates through the results and formats the job data into an HTML block that includes job title, description, departments, and application deadline. * - Displays the results in a grid layout, and includes a "Load More" button for pagination. * * @param array $attributes Block attributes containing padding and other settings. * * @return string The HTML output for the job listings or error message. */ static function gutenberg($attributes) { $allowed_tags = wp_kses_allowed_html( 'post' ); $padding = $attributes['padding']; $padding_string = $padding['top'] . ' ' . $padding['right'] . ' ' . $padding['bottom'] . ' ' . $padding['left']; $results = Helpers::get_jobs_from_api($attributes); if (is_wp_error($results)) { $error_message = $results->get_error_message(); // Translators: %s is the specific error message returned by the API return esc_html(sprintf(__('Something went wrong: %s', 'ai-job-listing'), $error_message)); } // Start building HTML output $html_output = '