*/ public function get_categories() { // general = default Elements panel; dadan = custom category group. return array( 'general', 'dadan' ); } /** * @return array */ public function get_keywords() { return array( 'dadan', 'video', 'embed', 'player' ); } /** * Controls. */ protected function register_controls() { $this->start_controls_section( 'content_section', array( 'label' => __( 'Video', 'dadan' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ) ); $this->add_control( 'url', array( 'label' => __( 'Share URL', 'dadan' ), 'type' => \Elementor\Controls_Manager::TEXT, 'input_type' => 'url', 'placeholder' => 'https://app.dadan.io/video/share/…', 'default' => '', 'label_block' => true, ) ); $this->add_control( 'width', array( 'label' => __( 'Width', 'dadan' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => 640, 'min' => 100, 'max' => 2560, ) ); $this->add_control( 'height', array( 'label' => __( 'Height', 'dadan' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => 0, 'min' => 0, 'max' => 2560, 'description' => __( 'Leave 0 for 16:9 from width.', 'dadan' ), ) ); $this->add_control( 'title', array( 'label' => __( 'Iframe title', 'dadan' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => '', 'placeholder' => __( 'Dadan video', 'dadan' ), ) ); $this->end_controls_section(); } /** * Front-end / preview render. */ protected function render() { $settings = $this->get_settings_for_display(); $url = isset( $settings['url'] ) ? trim( (string) $settings['url'] ) : ''; $width = isset( $settings['width'] ) ? absint( $settings['width'] ) : 640; $height = isset( $settings['height'] ) ? absint( $settings['height'] ) : 0; $title = isset( $settings['title'] ) ? (string) $settings['title'] : ''; if ( '' === $url ) { if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { echo '
'; echo esc_html__( 'Add a Dadan share URL (…/video/share/…).', 'dadan' ); echo '
'; } return; } $html = Dadan_Fallback::render_from_url( $url, $width, $height, $title ); if ( '' === $html ) { if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || current_user_can( 'edit_posts' ) ) { echo '
'; echo esc_html__( 'Invalid Dadan URL. Use a share link (…/video/share/…), not a direct /video/{id} page.', 'dadan' ); echo '
'; } return; } echo wp_kses( $html, Dadan_Fallback::kses_player() ); } }