start_controls_section('section_content', ['label' => 'Settings', ]); $this->add_control( 'feature_article', [ 'label' => __( 'Feature article', 'plugin-name' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => [ 'manual' => __( 'Manual', 'plugin-name' ), 'auto' => __( 'Auto', 'plugin-name' ), ], 'default' => 'manual', ] ); $this->add_control( 'post_select', [ 'label' => __( 'Post select', 'plugin-name' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => $this->getPublishedPosts(), 'placeholder' => 'Select post', 'condition' => [ 'feature_article' => 'manual' ] ] ); $this->add_control( 'swap_day', [ 'label' => __( 'Swap day', 'plugin-name' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => [ '0' => 'Sunday', '1' => 'Monday', '2' => 'Tuesday', '3' => 'Wednesday', '4' => 'Thursday', '5' => 'Friday', '6' => 'Saturday' ], 'default' => '1', 'condition' => [ 'feature_article' => 'auto' ] ] ); $this->end_controls_section(); $this->start_controls_section( 'style_section', [ 'label' => __( 'Style', 'plugin-name' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'title_color', [ 'label' => __( 'Title Color', 'plugin-domain' ), 'type' => \Elementor\Controls_Manager::COLOR, 'scheme' => [ 'type' => \Elementor\Scheme_Color::get_type(), 'value' => \Elementor\Scheme_Color::COLOR_1, ], 'selectors' => [ '{{WRAPPER}} .title' => 'color: {{VALUE}}', ], 'default' => '#FFFFFF' ] ); $this->add_control( 'divider_color', [ 'label' => __( 'Divider Color', 'plugin-domain' ), 'type' => \Elementor\Controls_Manager::COLOR, 'scheme' => [ 'type' => \Elementor\Scheme_Color::get_type(), 'value' => \Elementor\Scheme_Color::COLOR_1, ], 'selectors' => [ '{{WRAPPER}} .divider' => 'border-top: 2px solid {{VALUE}}', ], 'default' => '#FFFFFF' ] ); $this->add_control( 'article_meta_color', [ 'label' => __( 'Meta Color', 'plugin-domain' ), 'type' => \Elementor\Controls_Manager::COLOR, 'scheme' => [ 'type' => \Elementor\Scheme_Color::get_type(), 'value' => \Elementor\Scheme_Color::COLOR_1, ], 'selectors' => [ '{{WRAPPER}} .article-meta' => 'color: {{VALUE}}', ], 'default' => '#FFFFFF' ] ); $this->add_control( 'read_more_color', [ 'label' => __( 'Read More Color', 'plugin-domain' ), 'type' => \Elementor\Controls_Manager::COLOR, 'scheme' => [ 'type' => \Elementor\Scheme_Color::get_type(), 'value' => \Elementor\Scheme_Color::COLOR_1, ], 'selectors' => [ '{{WRAPPER}} .read-more' => 'color: {{VALUE}}; border: 1px solid {{VALUE}};', ], 'default' => '#FFFFFF' ] ); $this->end_controls_section(); } protected function render() { global $wpdb; $settings = $this->get_settings_for_display(); $post_id = null; if ($settings['feature_article'] === 'auto') { $article_setting = $wpdb->get_results( ' SELECT * FROM wp_feature_article LIMIT 1 ' )[0]; if (empty($article_setting)) { $wpdb->insert( 'wp_feature_article', [ 'post_id' => $this->getRandomPostID(), 'swap_day' => $settings['swap_day'], 'last_swap' => date('Y-m-d H:i:s') ] ); } else { if ($settings['swap_day'] === $article_setting->swap_day && date('Y-m-d') > date('Y-m-d', strtotime($article_setting->last_swap)) && date('w') === $article_setting->swap_day) { $wpdb->update( 'wp_feature_article', [ 'post_id' => $this->getRandomPostID(), 'swap_day' => $settings['swap_day'], 'last_swap' => date('Y-m-d H:i:s') ], [ 'swap_day' => $settings['swap_day'] ] ); } if ($settings['swap_day'] !== $article_setting->swap_day) { $wpdb->update( 'wp_feature_article', [ 'post_id' => $this->getRandomPostID(), 'swap_day' => $settings['swap_day'], 'last_swap' => date('Y-m-d H:i:s') ], [ 'swap_day' => $article_setting->swap_day, ] ); } } $article_setting = $wpdb->get_results( ' SELECT * FROM wp_feature_article LIMIT 1 ' )[0]; $post_id = $article_setting->post_id; } else { $post_id = $settings['post_select']; } $query = new WP_Query(['p' => $post_id]); $post = $query->posts[0]; $html = '