Advertisement
verygoodplugins

Untitled

Feb 28th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. class Elementor_oEmbed_Widget extends \Elementor\Widget_Base {
  2.  
  3.     /**
  4.      * Get widget name.
  5.      *
  6.      * Retrieve oEmbed widget name.
  7.      *
  8.      * @since 1.0.0
  9.      * @access public
  10.      *
  11.      * @return string Widget name.
  12.      */
  13.     public function get_name() {
  14.         return 'oembed';
  15.     }
  16.  
  17.     /**
  18.      * Get widget title.
  19.      *
  20.      * Retrieve oEmbed widget title.
  21.      *
  22.      * @since 1.0.0
  23.      * @access public
  24.      *
  25.      * @return string Widget title.
  26.      */
  27.     public function get_title() {
  28.         return __( 'oEmbed', 'plugin-name' );
  29.     }
  30.  
  31.     /**
  32.      * Get widget icon.
  33.      *
  34.      * Retrieve oEmbed widget icon.
  35.      *
  36.      * @since 1.0.0
  37.      * @access public
  38.      *
  39.      * @return string Widget icon.
  40.      */
  41.     public function get_icon() {
  42.         return 'fa fa-code';
  43.     }
  44.  
  45.     /**
  46.      * Get widget categories.
  47.      *
  48.      * Retrieve the list of categories the oEmbed widget belongs to.
  49.      *
  50.      * @since 1.0.0
  51.      * @access public
  52.      *
  53.      * @return array Widget categories.
  54.      */
  55.     public function get_categories() {
  56.         return [ 'general' ];
  57.     }
  58.  
  59.     /**
  60.      * Register oEmbed widget controls.
  61.      *
  62.      * Adds different input fields to allow the user to change and customize the widget settings.
  63.      *
  64.      * @since 1.0.0
  65.      * @access protected
  66.      */
  67.     protected function _register_controls() {
  68.  
  69.         $this->start_controls_section(
  70.             'content_section',
  71.             [
  72.                 'label' => __( 'Content', 'plugin-name' ),
  73.                 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
  74.             ]
  75.         );
  76.  
  77.         $this->add_control(
  78.             'url',
  79.             [
  80.                 'label' => __( 'URL to embed', 'plugin-name' ),
  81.                 'type' => \Elementor\Controls_Manager::TEXT,
  82.                 'input_type' => 'url',
  83.                 'placeholder' => __( 'https://your-link.com', 'plugin-name' ),
  84.             ]
  85.         );
  86.  
  87.         $this->end_controls_section();
  88.  
  89.     }
  90.  
  91.     /**
  92.      * Render oEmbed widget output on the frontend.
  93.      *
  94.      * Written in PHP and used to generate the final HTML.
  95.      *
  96.      * @since 1.0.0
  97.      * @access protected
  98.      */
  99.     protected function render() {
  100.  
  101.         $settings = $this->get_settings_for_display();
  102.  
  103.         $html = wp_oembed_get( $settings['url'] );
  104.  
  105.         echo '<div class="oembed-elementor-widget">';
  106.  
  107.         echo ( $html ) ? $html : $settings['url'];
  108.  
  109.         echo '</div>';
  110.  
  111.     }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement