Skip to content

Instantly share code, notes, and snippets.

@alanpilloud
Last active June 16, 2016 08:02
Show Gist options
  • Save alanpilloud/b4e2524c3ca3295395c49f350b9bc4c9 to your computer and use it in GitHub Desktop.
Save alanpilloud/b4e2524c3ca3295395c49f350b9bc4c9 to your computer and use it in GitHub Desktop.
#wp
<?php
/*
Plugin Name: Bwap Shortcodes
Description: Add shortcodes you write
Version: 0.1
Author: Bwap
*/
defined( 'ABSPATH' ) or die;
/**
* Readme for developers
*
* Shortcodes are by default deactivated. To activate a shortcode, uncomment its name in the $shortcodes array below.
*
* In order to add a new shortcode, add the name you would like your users to use in the $shortcodes array below.
* Then, simply write a new function prefixing it with "my_" and replaceing "-" by "_". Ex : function my_spotify_playlist($atts, $content = null).
*
* I recommend to make this plugin part of the mu-plugins folder.
*/
/**
* Available shortcodes
*/
$shortcodes = array(
//'spotify-playlist',
//'youtube',
);
/**
* spotify-playlist
*
* Display a spotify playlist.
*
* Attributes :
* - playlistid required - indicates the playlist to display
*/
function my_spotify_playlist($atts, $content = null)
{
if (empty($atts['playlistid'])) {
return __FUNCTION__.' shortcode message : playlistid attribute is missing';
}
return '<iframe src="https://embed.spotify.com/?uri=spotify%3Auser%3Aspotify%3Aplaylist%3A'.$atts['playlistid'].'" width="100%" height="600" frameborder="0" allowtransparency="true"></iframe>';
}
/**
* youtube
*
* Displays a single youtube video.
*
* Attributes :
* - videoid required - indicates the video to display
*/
function my_youtube($atts, $content = null)
{
if (empty($atts['videoid'])) {
return __FUNCTION__.' shortcode message : videoid attribute is missing';
}
return '<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item" src="https://www.youtube.com/embed/'.$atts['videoid'].'"></iframe></div>';
}
/**
* Loading available shortcodes
*
* ! Don't edit anything here !
*/
foreach ($shortcodes as $shortcode) {
$functionName = 'my_'.str_replace('-', '_', $shortcode);
if (function_exists($functionName)) {
$name = str_replace('my_', '', $shortcode);
add_shortcode($name, $functionName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment