start_controls_section( 'section_chart_builder', array( 'label' => esc_html__( 'Chart Builder', 'chart-builder' ), ) ); $this->add_control( 'important_note', array( 'label' => '', 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => ' '.esc_html__( 'Chart Builder', 'chart-builder' ), 'content_classes' => 'chart-elementor-widget-logo-wrap', ) ); $this->add_control( 'chart_selector', array( 'label' => __( 'Select chart', 'chart-builder' ), 'type' => Controls_Manager::SELECT, 'default' => $this->get_default_chart(), 'options' => $this->get_active_charts() ) ); $this->end_controls_section(); } protected function render( $instance = array() ) { if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { echo ''; } $settings = $this->get_settings_for_display(); echo '
'; echo esc_html( "[ays_chart id=" . $settings['chart_selector'] . "]" ); echo '
'; if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { echo ("

" . esc_html__( 'Note: The chart will be visible on the front end of your website.', "chart-builder" ) . "

"); } } public function get_active_charts(){ global $wpdb; $current_user = get_current_user_id(); $charts_table = $wpdb->prefix . CHART_BUILDER_DB_PREFIX . 'charts'; $sql = "SELECT id, title FROM {$charts_table} WHERE `status` = %s"; $params = ['published']; if (!current_user_can('manage_options')) { $sql .= " AND author_id = %d"; $params[] = absint($current_user); } $sql .= " ORDER BY id DESC "; // phpcs:ignore $results = $wpdb->get_results($wpdb->prepare($sql, ...$params), ARRAY_A); $options = array(); foreach ( $results as $result ){ $options[$result['id']] = $result['title']; } return $options; } public function get_default_chart(){ global $wpdb; $current_user = get_current_user_id(); $charts_table = $wpdb->prefix . CHART_BUILDER_DB_PREFIX . 'charts'; $sql = "SELECT id FROM {$charts_table} WHERE `status` = %s"; $params = ['published']; if (!current_user_can('manage_options')) { $sql .= " AND author_id = %d"; $params[] = absint($current_user); } $sql .= " ORDER BY id DESC LIMIT 1"; // phpcs:ignore $id = $wpdb->get_var($wpdb->prepare($sql, ...$params)); return intval($id); } protected function content_template() {} public function render_plain_content( $instance = array() ) {} }