Giter Club home page Giter Club logo

Comments (2)

rerraw avatar rerraw commented on August 15, 2024

Hi
How i can add Oembed Soundcloud to my Wordpress Widgets?

I Create this widget for loading soundcloud players by using Oembed code

But don't show me soundclud player
How can fix that problem?
`<?php

class YPE_Soundcloud_Widget extends WP_Widget {

    public $sc_oembedtypes = array(
        'Json' => 'json+oembed',
        'Xml'  => 'xml+oembed'
    );

    public $sc_formats = array(
        'json Format'  => 'json',
        'Xml Format'   => 'xml'
    );

    function __construct() {
        parent::__construct(
            'YPE_Soundcloud_Widget',
            __('YALLANPE Soundcloud Widget'),
            array('description' => __('Show Soundcloud Audios'))
        );

        add_action('load-widgets.php', array(&$this, 'YPE_YPE_sc_wpcolorpicker'));
    }

    function YPE_YPE_sc_wpcolorpicker() {    
        wp_enqueue_style('wp-color-picker');        
        wp_enqueue_script('wp-color-picker');
    }

    function widget($args, $instance) {

        extract($args);

        $YPE_sc_widget_title = apply_filters('widget_title', $instance['YPE_sc_widget_title']);
        $YPE_sc_oembedtype   = $instance['YPE_sc_oembedtype'];
        $YPE_sc_format       = $instance['YPE_sc_format'];
        $YPE_sc_username     = $instance['YPE_sc_username'];
        $YPE_sc_soundid      = $instance['YPE_sc_soundid'];
        $YPE_sc_maxwidth     = $instance['YPE_sc_maxwidth'];
        $YPE_sc_maxheight    = $instance['YPE_sc_maxheight'];
        $YPE_sc_color        = $instance['YPE_sc_color'];
        $YPE_sc_autoplay     = $instance['YPE_sc_autoplay'] ? 'true' : 'false';
        $YPE_sc_showcomments = $instance['YPE_sc_showcomments'] ? 'true' : 'false';
        $YPE_sc_iframe       = $instance['YPE_sc_iframe'] ? 'true' : 'false';

        $YPE_sc_modify_color = trim($YPE_sc_color, '#');

        echo $before_widget;

        if($YPE_sc_widget_title) {
            echo $before_title.$YPE_sc_widget_title.$after_title;
        }

        $YPE_sc_url = 'https://soundcloud.com/oembed?url=https://www.soundcloud.com/'.$YPE_sc_username.'/'.$YPE_sc_soundid.'/';

        echo '<a rel="alternate" type="application/'.$YPE_sc_oembedtype.'" href="'.$YPE_sc_url.'&format='.$YPE_sc_format.'&maxwidth='.$YPE_sc_maxwidth.'&maxheight='.$YPE_sc_maxheight.'&color='.$YPE_sc_modify_color.'&auto_play='.$YPE_sc_autoplay.'&show_comments='.$YPE_sc_showcomments.'&iframe='.$YPE_sc_iframe.'"></a>';

        echo $after_widget;
    }

    function update($new_instance, $old_instance) {

        $instance = $old_instance;

        $instance['YPE_sc_widget_title']  = strip_tags($new_instance['YPE_sc_widget_title']);
        $instance['YPE_sc_oembedtype']    = strip_tags($new_instance['YPE_sc_oembedtype']);
        $instance['YPE_sc_format']        = strip_tags($new_instance['YPE_sc_format']);
        $instance['YPE_sc_username']      = strip_tags($new_instance['YPE_sc_username']);
        $instance['YPE_sc_soundid']       = strip_tags($new_instance['YPE_sc_soundid']);
        $instance['YPE_sc_maxwidth']      = strip_tags($new_instance['YPE_sc_maxwidth']);
        $instance['YPE_sc_maxheight']     = strip_tags($new_instance['YPE_sc_maxheight']);
        $instance['YPE_sc_color']         = strip_tags($new_instance['YPE_sc_color']);
        $instance['YPE_sc_autoplay']      = strip_tags($new_instance['YPE_sc_autoplay']);
        $instance['YPE_sc_showcomments']  = strip_tags($new_instance['YPE_sc_showcomments']);
        $instance['YPE_sc_iframe']        = strip_tags($new_instance['YPE_sc_iframe']);

        return $instance;
    }

    function form($instance) {

    ?>
        <script type='text/javascript'>
            jQuery(function() {
                jQuery('.sc_wpcolorpicker').wpColorPicker();
            });
        </script>

        <p>
            <label for="<?php echo $this->get_field_id('YPE_sc_widget_title'); ?>"><?php echo __('Title'); ?></label>
            <input id="<?php echo $this->get_field_id('YPE_sc_widget_title'); ?>" name="<?php echo $this->get_field_name('YPE_sc_widget_title'); ?>" value="<?php echo $instance['YPE_sc_widget_title']; ?>" class="widefat" type="text" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('YPE_sc_oembedtype'); ?>"><?php echo __('Select Your Oembed Code Type'); ?></label>
            <select id="<?php echo $this->get_field_id('YPE_sc_oembedtype'); ?>" name="<?php echo $this->get_field_name('YPE_sc_oembedtype'); ?>" >
                <?php
                foreach ($this->sc_oembedtypes as $sc_oembedtypes_keys => $sc_oembedtype) { ?>
                    <option value="<?php echo $sc_oembedtype; ?>" <?php if($instance['YPE_sc_oembedtype'] == $sc_oembedtype) echo "selected=\"selected\""; else echo ""; ?>><?php echo $sc_oembedtypes_keys; ?></option>
                <?php } ?>
            </select>
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('YPE_sc_format'); ?>"><?php echo __('Select Your Format Code'); ?></label>
            <select id="<?php echo $this->get_field_id('YPE_sc_format'); ?>" name="<?php echo $this->get_field_name('YPE_sc_format'); ?>" >
                <?php
                foreach ($this->sc_formats as $sc_formats_keys => $sc_format) { ?>
                    <option value="<?php echo $sc_format; ?>" <?php if($instance['YPE_sc_format'] == $sc_format) echo "selected=\"selected\""; else echo ""; ?>><?php echo $sc_formats_keys; ?></option>
                <?php } ?>
            </select>
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('YPE_sc_username'); ?>"><?php echo __('Sound Uploader/Username Name'); ?></label>
            <input id="<?php echo $this->get_field_id('YPE_sc_username'); ?>" name="<?php echo $this->get_field_name('YPE_sc_username'); ?>" value="<?php echo $instance['YPE_sc_username']; ?>" class="widefat" type="text" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('YPE_sc_soundid'); ?>"><?php echo __('Sound ID'); ?></label>
            <input id="<?php echo $this->get_field_id('YPE_sc_soundid'); ?>" name="<?php echo $this->get_field_name('YPE_sc_soundid'); ?>" value="<?php echo $instance['YPE_sc_soundid']; ?>" class="widefat" type="text" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('YPE_sc_maxwidth'); ?>"><?php echo __('Sound Maximum Width (%)'); ?>&nbsp;<small>(Default = 100%)</small></label>
            <input id="<?php echo $this->get_field_id('YPE_sc_maxwidth'); ?>" name="<?php echo $this->get_field_name('YPE_sc_maxwidth'); ?>" value="<?php echo $instance['YPE_sc_maxwidth']; ?>" class="widefat" type="text" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('YPE_sc_maxheight'); ?>"><?php echo __('Sound Maximum Height'); ?></label>
            <input id="<?php echo $this->get_field_id('YPE_sc_maxheight'); ?>" name="<?php echo $this->get_field_name('YPE_sc_maxheight'); ?>" value="<?php echo $instance['YPE_sc_maxheight']; ?>" class="widefat" type="text" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('YPE_sc_color'); ?>"><?php echo __('Color Widget'); ?></label>
            <input class="sc_wpcolorpicker" id="<?php echo $this->get_field_id('YPE_sc_color'); ?>" name="<?php echo $this->get_field_name('YPE_sc_color'); ?>" value="<?php echo $instance['YPE_sc_color']; ?>" class="widefat" type="text" />
        </p>
        <p>
          <input class="checkbox" type="checkbox" <?php checked($instance['YPE_sc_autoplay'], 'on'); ?> id="<?php echo $this->get_field_id('YPE_sc_autoplay'); ?>" name="<?php echo $this->get_field_name('YPE_sc_autoplay'); ?>" />
          <label for="<?php echo $this->get_field_id('YPE_sc_autoplay'); ?>"><?php echo __('On/Off Autoplay') ?></label>
        </p>
        <p>
          <input class="checkbox" type="checkbox" <?php checked($instance['YPE_sc_showcomments'], 'on'); ?> id="<?php echo $this->get_field_id('YPE_sc_showcomments'); ?>" name="<?php echo $this->get_field_name('YPE_sc_showcomments'); ?>" />
          <label for="<?php echo $this->get_field_id('YPE_sc_showcomments'); ?>"><?php echo __('Show/Hide Comments') ?>&nbsp;<small>(Default = true)</small></label>
        </p>
        <p>
          <input class="checkbox" type="checkbox" <?php checked($instance['YPE_sc_iframe'], 'on'); ?> id="<?php echo $this->get_field_id('YPE_sc_iframe'); ?>" name="<?php echo $this->get_field_name('YPE_sc_iframe'); ?>" />
          <label for="<?php echo $this->get_field_id('YPE_sc_iframe'); ?>"><?php echo __('HTML5 Iframe-based') ?>&nbsp;<small>(Default = true)</small></label>
        </p>
    <?php
    }
}

function Soundcloud_Widget() {
    register_widget('YPE_Soundcloud_Widget');
}
add_action('widgets_init', 'Soundcloud_Widget');

?>`

from oembed.

iamcal avatar iamcal commented on August 15, 2024

this repo is not for oembed or wordpress support, sorry.

from oembed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.