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 ("
" . __( '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`='published'"; if( ! current_user_can( 'manage_options' ) ){ $sql .= " AND author_id = ". absint( $current_user ) ." "; } $results = $wpdb->get_results( $sql, 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`='published'"; if( ! current_user_can( 'manage_options' ) ){ $sql .= " AND author_id = ". absint( $current_user ) ." "; } $sql .= " LIMIT 1;"; $id = $wpdb->get_var( $sql ); return intval($id); } protected function content_template() {} public function render_plain_content( $instance = array() ) {} }