=') ) { $this->register_controls(); } else { $this->_register_controls(); } } protected function _register_controls() { $this->wpvr_shortcode_controls(); } protected function register_controls() { $this->wpvr_shortcode_controls(); } /** * Register shortcode Controls. * * @access protected */ protected function wpvr_shortcode_controls(){ /** * * get all tour info and store in $wpvr_post */ $the_posts = get_posts(array('post_type' => 'wpvr_item', 'posts_per_page' => -1)); $wpvr_post = array(); foreach($the_posts as $post){ if($post->post_title){ $wpvr_post[$post->ID] = $post->post_title.' : '.$post->ID; }else{ $wpvr_post[$post->ID] = 'No title' .' : '.$post->ID; } } $this->start_controls_section( 'section_content', [ 'label' => __( 'WPVR Setup', 'wpvr' ), ] ); /** * * add a select type field instead of text field */ $this->add_control( 'vr_id', [ 'label' => __( 'Select Tour:', 'wpvr' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => $wpvr_post ] ); $this->add_control( 'vr_width', [ 'label' => __( 'Width:', 'wpvr' ), 'type' => Controls_Manager::TEXT, 'input_type' => 'text', 'placeholder' => __( 'Put value in PX', 'wpvr' ), ] ); $this->add_control( 'vr_height', [ 'label' => __( 'Height:', 'wpvr' ), 'type' => Controls_Manager::TEXT, 'input_type' => 'text', 'placeholder' => __( 'Put value in PX', 'wpvr' ), ] ); $this->add_control( 'vr_radius', [ 'label' => __( 'Radius:', 'wpvr' ), 'type' => Controls_Manager::TEXT, 'input_type' => 'text', 'placeholder' => __( 'Put value in PX', 'wpvr' ), ] ); $this->add_control( 'vr_mobile', [ 'label' => __('Mobile Height', 'wpvr'), 'type' => Controls_Manager::TEXT, 'placeholder' => __( 'Put value in PX', 'wpvr' ), ] ); $this->end_controls_section(); } /** * Render the widget output on the frontend. * * Written in PHP and used to generate the final HTML. * * @since 1.0.0 * * @access protected */ protected function render() { $settings = $this->get_settings_for_display(); $id = $settings['vr_id'] ?? 0; $width = $settings['vr_width'] ?? "600px"; $height = $settings['vr_height'] ?? "400px"; $radius = $settings['vr_radius'] ?? "0px"; $mobile_height = $settings['vr_mobile'] ?? "300px"; // Ensure dimensions have 'px' if missing foreach (['width', 'height', 'radius', 'mobile_height'] as $key) { if (!empty($$key) && strpos($$key, 'px') === false) { $$key .= 'px'; } } if ($id) { echo do_shortcode('[wpvr id="'.$id.'" width="'.$width.'" height="'.$height.'" radius="'.$radius.'" mobile_height="'.$mobile_height.'"]'); } } /** * Print element template. * * Used to generate the element template on the editor. * * @since 2.0.0 * @access public */ public function print_template() { ob_start(); if ( version_compare(ELEMENTOR_VERSION, '3.1.0', '>=') ) { $this->content_template(); } else { $this->_content_template(); } $template_content = ob_get_clean(); $element_type = $this->get_type(); /** * Template content. * * Filters the controls stack template content before it's printed in the editor. * * The dynamic portion of the hook name, `$element_type`, refers to the element type. * * @since 1.0.0 * * @param string $content_template The controls stack template in the editor. * @param Controls_Stack $this The controls stack. */ $template_content = apply_filters( "elementor/{$element_type}/print_template", $template_content, $this ); if ( empty( $template_content ) ) { return; } ?>