How to allow audio files with GET parameters in the audio shortcode?

There’s an interesting question on WordPress Stackexchange regarding the audio shortcode .

It looks like it doesn’t support sources with GET parameters.

Here are two examples:

1) Without GET parameters the audio player displays:


where the shortcode is:

[audio src="http://s.w.org/images/core/3.9/JellyRollMorton-BuddyBoldensBlues.mp3"]

2) With GET parameters it only shows the audio link:

http://s.w.org/images/core/3.9/JellyRollMorton-BuddyBoldensBlues.mp3?play=1


where the shortcode is:

[audio src="http://s.w.org/images/core/3.9/JellyRollMorton-BuddyBoldensBlues.mp3?play=1"]

I managed to work around it with the following code snippet:

/**
 * Allow unrecognize audio sources hosted on 's.w.org'.
 *
 * @see http://wordpress.stackexchange.com/a/152352/26350
 */

add_filter( 'wp_audio_shortcode_override',
    function( $html, $atts )
    {
        if( 's.w.org' === parse_url( $atts['src'], PHP_URL_HOST ) )
        {
            add_filter( 'wp_audio_extensions', 'wpse_152316_wp_audio_extensions' );
        }
        return $html;
    }
, PHP_INT_MAX, 2 );

function wpse_152316_wp_audio_extensions( $ext )
{
    remove_filter( current_filter(), __FUNCTION__ );
    $ext[] = '';
    return $ext;
}

A simple plugin to run JetPack locally

We don’t need to modify the wp-config.php file as before with:

define ('JETPACK_DEV_DEBUG', true);

to run JetPack in the development mode.

By using the jetpack_development_mode filter described here, we can construct this simple plugin:

<?php
/**
 * Plugin Name: Run JetPack locally
 * Plugin URI:  https://github.com/birgire/run-jetpack-locally
 * Author:      birgire
 * Version:     0.0.3
 */

// Activate the development mode:
add_filter( 
    'jetpack_development_mode', 
    '__return_true', 
    PHP_INT_MAX 
);

to make your life easier ;-) and it’s available on GitHub.

This class method of the JetPack class contains the filter:

 
	/**
	 * Is Jetpack in development (offline) mode?
	 */
	public static function is_development_mode() {
		$development_mode = false;

		if ( defined( 'JETPACK_DEV_DEBUG' ) ) {
			$development_mode = JETPACK_DEV_DEBUG;
		}

		elseif ( site_url() && false === strpos( site_url(), '.' ) ) {
			$development_mode = true;
		}

		return apply_filters( 'jetpack_development_mode', $development_mode );
	}

WordPress: Playlist shortcode with external audio or video files

The new [playlist] shortcode  in WordPress 3.9 is great, but you can’t use it for external  files.

Here’s a solution I wrote on WPSE to use it for external files.

The plugin is hosted on GitHub.

Here’s a version for those who use PHP 5.1.x or PHP 5.2.x.

Example 1

This audio playlist:

is generated by the following shortcode:

[wpse_playlist type="audio" tracklist="true" tracknumbers="true" images="true" artist="true"]
    [wpse_trac title="Ain't Misbehavin'" src="//s.w.org/images/core/3.9/AintMisbehavin.mp3" type="audio/mpeg" caption="" description="" image="" meta_artist="Louis Armstrong and His Orchestra" meta_album="78 RPMs and Cylinder Recordings" meta_genre="" meta_length_formatted="3:21" image_src="//s.w.org/images/core/3.9/louis.jpg" image_width="308" image_height="240" thumb_src="//s.w.org/images/core/3.9/louis.jpg" thumb_width="308" thumb_height="240"]
    [wpse_trac title="Buddy Bolden's Blues" src="//s.w.org/images/core/3.9/JellyRollMorton-BuddyBoldensBlues.mp3" type="audio/mpeg" caption="" description="" image="" meta_artist="Jelly Roll Morten" meta_album="78 RPMs and Cylinder Recordings" meta_genre="Jazz" meta_length_formatted="2:09"]
[/wpse_playlist]

 

Example 2

Here’s the vanilla version of the above audio playlist:

generated from the shortcode:
 

[wpse_playlist type="audio" current="no" tracklist="yes" tracknumbers="no" images="no" artist="no"]
    [wpse_trac title="Davenport Blues" src="//s.w.org/images/core/3.9/DavenportBlues.mp3"]
    [wpse_trac title="Dixie Blues" src="//s.w.org/images/core/3.9/Louisiana_Five-Dixie_Blues-1919.mp3"]
[/wpse_playlist]

Example 3

Here’s a video playlist:

from

[wpse_playlist type="video"]
    [wpse_trac caption="Live widgets previews in WordPress 3.9" src="//s.w.org/images/core/3.9/widgets.mp4" image_src="/projects/wp-content/uploads/2014/04/widgets_screen.gif"]
[/wpse_playlist]

Happy listening!

WordPress developer links

Here are some useful links:

WordPress Codex:
http://codex.wordpress.org/Main_Page

Plugin API/Action Reference:
http://codex.wordpress.org/Plugin_API/Action_Reference

WordPress.org Forums:
http://wordpress.org/support/

WordPress Planet:
http://planet.wordpress.org/

Plugin Directory:
http://wordpress.org/extend/plugins/

Make WordPress:
http://make.wordpress.org/

WordPress TV:
http://wordpress.tv/

WordPress Answers:
http://wordpress.stackexchange.com/

Why is my WordPress so slow? How to identify the problems

Image from  http://en.wikipedia.org/wiki/SnailIt’s difficult to give an answer to this kind of question, so I will list general things that have helped me to identify problems of this kind:

Profile everything you can:

The P3 Profiler plugin will profile your plugins:

http://wordpress.org/extend/plugins/p3-profiler/

I also recommend the `Debug bar` (and it’s extensions)

http://wordpress.org/extend/plugins/debug-bar/

and the `Blackbox` debug bar to profile your *problematic?* queries:

http://wordpress.org/extend/plugins/blackbox-debug-bar/

Memory viewer for your hooks:

http://wordpress.org/extend/plugins/memory-viewer/

If you have lot’s of comment’s that are constantly refreshing the cache,
you might also consider using comment services like Facebook / Intense Debate / Disqus / LiveFyre

Use WordPress cache plugins, many good out there.

Test your site with online performance services:

Here is one:

http://www.webpagetest.org/

New Relic:

http://newrelic.com/

View the log files:

Check all log files you have (php, apache, nginx, mysql, …)

If you have ssh access:

Also consider using `Nginx` instead of `Apache`

You should also check what process is using your resources via ps/top/htop/… (i.e. is it apache or mysql or something else) if you have access to a Linux console

If it’s mysql there is a great script called tuning-primer.sh that can give you hints how to configure it (if you have access to ssh, you can check it with top or htop)

Use APC cache for php

(this article is a work in progress)

Countdown between two unix timestamps


Here is a way to display the day/hour/min difference between two unix timestamps, fx

6 days 6 hours 37 minutes

Here is the above example

<?php 
$future_time=1353628800; 
$current_time=time(); 
echo countdown($current_time,$future_time); 
?>

and here is the function where you can translate/change the labels:

<?php 
/**  
* Calculates the number of days, hours and minutes 
* between two Unix timestamps.  
*  
* The Unix timestamp $t2 should be greater than $t1  
*  
* @param integer $t1 Date with Unix timestamp format.  
* @param integer $t2 Date with Unix timestamp format.  
* @return string Formatted string 
* fx: 3 days 5 hours 23 minutes  
*/ 
function countdown($t1,$t2){         
        // t2 > t1

        // setup
        $out ="";
        $days_label=" days ";
        $day_label=" day ";
        $hours_label=" hours ";
        $hour_label=" hour ";
        $mins_label=" minutes ";
        $min_label=" minute "i
        $timeup_label=" ho ho - the time is up";

        // calculate
        $diff=$t2-$t1;
        $d=$diff/86400;
        $days=(int)$d;
        $h=($d-$days)*24;
        $hours=(int)$h;
        $m=($h-$hours)*60;
        $mins=(int)$m;

        // find out the labels (singular/plural)
        $d_label=($days==1)?$day_label:$days_label;
        $h_label=($hours==1)?$hour_label:$hours_label;
        $m_label=($mins==1)?$min_label:$mins_label;

        // output
        if($days>0){
                $out.= $days.$d_label;
        }
        if($hours>0){
                $out.= $hours.$h_label;
        }
        if($mins>0){
                $out.= $mins.$m_label;
        }
        if($days+$hous+$mins <= 0 ){
                $out=$timeup_label;
        }

        return $out;
}
?>

Pizza order time – content with weekly opening hours

This wordpress.org forum thread:

http://wordpress.org/support/topic/how-to-close-pizza-order-site-or-page-outside-business-hours

gave me an idea of a shortcode that can display content during given opening hours in the week and can handle shortcodes inside it.

Maybe this will grow into a plugin in the near future ;-)

The shortcode is

[openinghours] ... some content only available during opening hours ... [/openinghours]

and here is an example of the supported (optional) attributes:

sun="11:00-22:30" // the opening hours every sunday
mon="09:00-23:00" 
tue="09:00-15:00" 
wed="09:00-23:00" 
thu="10:15-14:59" 
fri="09:00-23:00" 
sat="09:00-24:00" 
debug="0" // debug="1" will display debug information
sorry="Sorry, we are closed now. Try again during the opening hours." // text to display when it's closed
holidays="2012-07-04,2012-12-24"  // YYYY-MM-DD, YYYY-MM-DD,...

Here is a full working example (closed every sunday and saturday and open from 09-17 mon-fri. Holidays are 2012-07-04 and 2012-12-24):

[openinghours mon="09:00-17:00" tue="09:00-17:00" wed="09:00-17:00" thu="09:00-17:00" fri="09:00-17:00"  debug="0" holidays="2012-07-04,2012-12-24" sorry="Sorry, we are closed now. Try again during the opening hours."] please order now! [foobar]
[/openinghours]

Here is the code to paste into the functions.php file:

//
// shortcode to display content only on given weekly opening hours
// usage: [openinghours][/openinghours]
// author: Birgir E.
// url: http://xlino.com
// created: 2012-10-18
// version: 1.1
//
function my_openinghours($atts,$content=""){
        extract( shortcode_atts( array(
                'sun' => '', // the opening hours every sunday
                'mon' => '', // the opening hours every monday
                'tue' => '', 
                'wed' => '',
                'thu' => '',
                'fri' => '',
                'sat' => '',
                'sorry' => '', // text to display when it's closed
                'debug' => '0', // debug="1" will display debug information
                'holidays' => '', // fx: holidays="2012-07-04,2012-12-24", the format is YYYY-MM-DD, YYYY-MM-DD,...
        ), $atts ) );

        // current time
        $currT=time();
        $currYMD=date("Y-m-d",$currT);
        $currYMDHIS=date("Y-m-d H:i:s",$currT);
        $currWD=date("w",$currT);

        // get the opening hours for today
        switch ($currWD){
                case 0:
                        $s=$sun;
                        break;
                case 1:
                        $s=$mon;
                        break;
                case 2:
                        $s=$tue;
                        break;
                case 3:
                        $s=$wed;
                        break;
                case 4:
                        $s=$thu;
                        break;
                case 5:
                        $s=$fri;
                        break;
                case 6:
                        $s=$sat;
                        break;
                default:
                        $s="";
        }

        // format input
        $out=esc_attr($sorry);
        $holidays=esc_attr($holidays);
        $s=esc_attr(trim($s));
        $debug=(int)$debug;
 
        // do the time checks
        if(strlen($s)>0){
                $a=explode("-",$s);
                if(count($a)==2){
                        $from = $currYMD." ".$a[0].":00";
                        $to = $currYMD." ".$a[1].":00";
                        $fromT = strtotime($from);
                        $toT = strtotime($to);
                        if($currT>$fromT && $currT<$toT && strpos($holidays,$currYMD)===false){
                                $out=do_shortcode($content);
                        }
                }
        }
        // check if we have debug mode on
        if($debug=="1"){
                $out.="<div style='background-color:#ccc;padding:10px;border:1px solid #333;margin:10px;'>Debug: <br/>";
                $out.="from:".$from."<br/> current:".$currYMDHIS."<br/> to:".$to."</div>";
        }
        return $out;
}

add_shortcode("openinghours","my_openinghours");

bon appetit ;-)

changelog:

version 1.1
added holidays

version 1.0
inital version (Props: @lemonadejoex, @keesiemeijer)

YouList – Youtube playlist shortcode – wordpress plugin

Download the plugin here:
http://wordpress.org/extend/plugins/youlist/

Support Open Source developement:




The plugin supports both single and multi site WordPress installs.

Reviews:

How to use this plugin?
When you have installed it, you can for example start by pasting this shortcode into your WordPress post editor:

[youlist pid="PL3FF15AA7ED356D9F"]

like this:

yl

and preview the post. Then you can change the pid value to match your own playlist.

The above pid value is taken from this playlist url:

http://www.youtube.com/playlist?list=PL3FF15AA7ED356D9F

You can then try out the usage examples given below or here:

http://wordpress.org/extend/plugins/youlist/

There is a small playlist icon in the bottom right corner

Showcases
http://cjgrasso.com/world16 (responsive and with hd playback)

Few usage examples:

Example: Adele YouTube playlist with thumbnails

[youlist pid="PL3FF15AA7ED356D9F"]


Example: Adele YouTube playlist with custom styling

[youlist pid="PL3FF15AA7ED356D9F" style="width:400px;height:300px;z-index:1;border:2px solid gold;background-color:orange;padding:10px;"]


Example: Playlist from the search string “higgs boson”

[youlist search="higgs boson"]


Example: Playlist for uploaded videos by the user “mismag822″

[youlist uid="mismag822" listtype="user_uploads"]


Example: Playlist for favorite videos of the user “mismag822″

[youlist uid="mismag822" listtype="user_favorites"]


Example: Three YouTube videos with thumbnails

[youlist vid="ZF_K8D414-Y,sFHXWoawnt0,E2uOGOqIyC4"]


Example: Three YouTube videos without thumbnails

[youlist vid="ZF_K8D414-Y,sFHXWoawnt0,E2uOGOqIyC4" showinfo="0" ]