'
',
'before_item' => '',
'after_item' => '',
'image_size' => 'large-image',
);
/**
* Adds action hooks
*/
function __construct() {
// Scripts and styles
add_action( 'admin_enqueue_scripts', array( $this, 'admin_head' ) );
// Meta box
add_action( 'add_meta_boxes', array( $this, 'add_gallery_meta_box' ), 1 );
// Save gallery
add_action( 'wp_ajax_array_save_custom_gallery_meta', array( $this, 'save_gallery' ) );
}
/**
* Enqueues admin scripts and styles
*
* @since 1.0.0
*/
function admin_head( $hook ) {
global $post;
if( $hook != 'post.php' && $hook != 'post-new.php' )
return;
// add js vars
echo '';
wp_enqueue_script( 'array-admin', plugin_dir_url(__FILE__) . '/gallery-admin.js', array( 'jquery' ), true );
wp_enqueue_style( 'gallery-admin-styles', plugin_dir_url(__FILE__) . '/array-gallery.css', array(), '1.0.0', 'screen' );
}
/**
* Adds the Array Gallery meta box to supported post edit screens
*
* @since 1.0.0
*/
function add_gallery_meta_box() {
$screens = array( 'post', 'array-portfolio' );
foreach ( $screens as $screen ) {
add_meta_box(
'array_gallery_meta_box', // $id
__( 'Featured Gallery', 'array-toolkit' ), // $title
array( $this, 'show_gallery_meta_box' ), // $callback
$screen, // $page
'normal', // $context
'high'); // $priority
}
}
/**
* Outputs the markup for the Array Gallery meta box
*
* @since 1.0.0
*/
function show_gallery_meta_box() {
global $post;
$meta = get_post_meta( $post->ID, '_gallery_image_ids', true ); ?>
' . wp_get_attachment_image( $thumb, array(125,125) ) . '';
}
}
echo $thumbs_output; ?>
' . wp_get_attachment_image( $thumb, array( 125, 125 ) ) . '';
}
}
echo $thumbs_output;
die();
}
/**
* Template tag for displaying the gallery
*
* @since 1.0.0
*/
public static function array_gallery( $args = NULL ) {
// Merge any passed markup with the defaults stored in self::$defaults
$args = wp_parse_args( $args, self::$defaults );
global $post;
// Get our image IDs
$image_ids = get_post_meta( $post->ID, '_gallery_image_ids', true );
$images = explode( ',', $image_ids );
if ( $images ) {
echo $args['before'];
foreach ( $images as $image ) {
if ( is_single() ) {
// Set the link to the image file on single views
echo $args['before_item'] . '';
} else {
// Set the link to the post
echo $args['before_item'] . '';
}
// Display the image
echo wp_get_attachment_image( $image, $args['image_size'], false, false );
echo '' . $args['after_item'];
}
echo $args['after'];
}
}
}// class
$array_toolkit_gallery = new Array_Toolkit_Gallery;
/**
* Displays a post's gallery
*/
function array_gallery( $args = NULL ) {
return Array_Toolkit_Gallery::array_gallery( $args );
}