public
Created

Add Photobox support to WordPress galleries

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
<?php
 
class Gallery_Javascript {
private $link;
 
function __construct() {
add_filter( 'post_gallery', array( $this, 'enqueue_script' ), 20, 2 );
add_filter( 'gallery_style', array( $this, 'add_class' ) );
}
 
function enqueue_script( $output, $attr ) {
global $wp_styles;
 
if( $output )
return $output;
 
$this->link = isset( $attr['link'] ) && 'file' == $attr['link'] ? true : false;
 
if( $this->link ) {
wp_enqueue_script(
'jquery-photobox',
plugins_url( '/gallery/photobox/photobox.js', __FILE__ ),
array( 'jquery' ),
'1.4.5'
);
 
wp_enqueue_style(
'jquery-photobox',
plugins_url( '/gallery/photobox/photobox.css', __FILE__ ),
array(),
'1.4.5',
'all'
);
 
wp_enqueue_style(
'jquery-photobox-ie8',
plugins_url( '/gallery/photobox/photobox.ie.css', __FILE__ ),
array(),
'1.4.5',
'all'
);
 
$wp_styles->add_data( 'jquery-photobox-ie8', 'conditional', 'lt IE 9' );
}
 
return $output;
}
 
function add_class( $output ) {
if( $this->link ) {
$output = substr_replace( $output, "", -2 );
$output .= " gallery-link-file'>";
}
 
return $output;
}
}
new Gallery_Javascript;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.