start_controls_section( 'section_content', array( 'label' => esc_html__( 'Display', 'ai-schema-gen' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ) ); $this->add_control( 'show_schema_type', array( 'label' => esc_html__( 'Show Schema Type', 'ai-schema-gen' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'ai-schema-gen' ), 'label_off' => esc_html__( 'No', 'ai-schema-gen' ), 'return_value' => 'yes', 'default' => 'yes', ) ); $this->add_control( 'show_only_in_editor', array( 'label' => esc_html__( 'Visible in Editor Only', 'ai-schema-gen' ), 'description' => esc_html__( 'Hide this widget on the live site — show it only inside the Elementor editor.', 'ai-schema-gen' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'ai-schema-gen' ), 'label_off' => esc_html__( 'No', 'ai-schema-gen' ), 'return_value' => 'yes', 'default' => 'yes', ) ); $this->end_controls_section(); // Style tab. $this->start_controls_section( 'section_style', array( 'label' => esc_html__( 'Style', 'ai-schema-gen' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ) ); $this->add_control( 'text_color', array( 'label' => esc_html__( 'Text Color', 'ai-schema-gen' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#374151', 'selectors' => array( '{{WRAPPER}} .ai-schema-gen-widget' => 'color: {{VALUE}};', ), ) ); $this->add_control( 'background_color', array( 'label' => esc_html__( 'Background Color', 'ai-schema-gen' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#f0fdf4', 'selectors' => array( '{{WRAPPER}} .ai-schema-gen-widget' => 'background-color: {{VALUE}};', ), ) ); $this->add_control( 'border_color', array( 'label' => esc_html__( 'Border Color', 'ai-schema-gen' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#bbf7d0', 'selectors' => array( '{{WRAPPER}} .ai-schema-gen-widget' => 'border-color: {{VALUE}};', ), ) ); $this->end_controls_section(); } /** * Render the widget HTML on the frontend. */ protected function render() { $settings = $this->get_settings_for_display(); // Hide on live site if the editor-only toggle is on. if ( 'yes' === $settings['show_only_in_editor'] && ! \Elementor\Plugin::$instance->editor->is_edit_mode() ) { return; } $post_id = get_the_ID(); $status = $this->get_schema_status( $post_id ); $active = $status['active']; $types = $status['types']; $show_type = 'yes' === $settings['show_schema_type']; $badge_style = $active ? 'background-color:#f0fdf4;border:1px solid #bbf7d0;color:#15803d;' : 'background-color:#fef9c3;border:1px solid #fde68a;color:#92400e;'; $label = $active ? esc_html__( 'Schema Active', 'ai-schema-gen' ) : esc_html__( 'No Schema', 'ai-schema-gen' ); ?>
false, 'types' => array() ); } global $wpdb; $table = esc_sql( $wpdb->prefix . 'schema_ai_schemas' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Widget render, caching not applicable here. $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ); if ( ! $table_exists ) { return array( 'active' => false, 'types' => array() ); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Widget render, caching not applicable here. $types = $wpdb->get_col( $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name sanitized via esc_sql(). "SELECT schema_type FROM {$table} WHERE post_id = %d AND validation_status != %s", $post_id, 'invalid' ) ); return array( 'active' => ! empty( $types ), 'types' => ! empty( $types ) ? $types : array(), ); } }