'page', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => -1, )); $pages = array(); if (!empty($page_list) && !is_wp_error($page_list)) { foreach ($page_list as $page) { $pages[$page->ID] = $page->post_title; } } return $pages; } /** * Registers the widget controls for the "Content" section in Elementor. * * This function defines and registers the various controls (fields) available for the user * in the Elementor panel under the "Content" section. These controls allow the user to * configure settings for the job listings widget such as job ordering, job limit, link text, * and link page selection. * * The controls added here will be reflected in the Elementor editor, allowing the user * to interact with these settings while customizing the widget. * * @return void */ protected function register_controls() { $this->start_controls_section( 'content_section', [ 'label' => esc_html__( 'Content', 'ai-job-listing' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'post_ordering', array( 'label' => __( 'Jobs Ordering', 'ai-job-listing' ), 'type' => \Elementor\Controls_Manager::SELECT2, 'options' => array( 'DESC' => esc_html__( 'Desecending', 'ai-job-listing' ), 'ASC' => esc_html__( 'Ascending', 'ai-job-listing' ), ), 'default' => 'DESC', ) ); $this->add_control( 'job_limit', [ 'label' => esc_html__('Jobs Limit','ai-job-listing'), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => '6', 'title' => esc_html__('Enter Job Limits','ai-job-listing'), ] ); $this->add_control( 'title_link_text', [ 'label' => esc_html__('Link Text','ai-job-listing'), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => 'Load More', 'title' => esc_html__('Enter button text','ai-job-listing'), ] ); $this->add_control( 'title_page_link', [ 'label' => esc_html__('Select Link Page','ai-job-listing'), 'type' => \Elementor\Controls_Manager::SELECT2, 'label_block' => true, 'options' => $this-> axilweb_ai_job_listing_get_pages(), ] ); $this->end_controls_section(); } /** * Render oEmbed widget output on the frontend. * * Written in PHP and used to generate the final HTML. * * @since 0.1.0 * @access protected */ protected function axilweb_ai_job_listing_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['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 Elementor Widget 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 job listings HTML on the front end. * * This method fetches the job listings from the API using the specified settings (e.g., job limit, ordering). * It processes the results, extracting relevant data such as job title, description, departments, and application deadline. * The job listings are displayed in a grid format with each job linking to a detailed job page. * After rendering the job listings, a "Load More" button is added to the page. * * @return void */ protected function render() { $allowed_tags = wp_kses_allowed_html( 'post' ); $settings = $this->get_settings_for_display(); $results = $this->axilweb_ai_job_listing_get_jobs_from_api($settings); if (is_wp_error($results)) { $error_message = $results->get_error_message(); // Translators: %s is the error message returned from the API call $error_text = sprintf(__('Something went wrong: %s', 'ai-job-listing'), $error_message); printf( '