Created
July 31, 2014 13:07
-
-
Save pommiegranit/739019f4d8494ec965c2 to your computer and use it in GitHub Desktop.
Better Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Better Images | |
Plugin URI: http://premium.wpmudev.org/ | |
Description: Better images | |
Author: Chris Knowles | |
Version: 1.0 | |
Author URI: http://twitter.com/ChrisKnowles | |
*/ | |
function bi_img_caption_shortcode( $output, $attr, $content ) { | |
extract(shortcode_atts(array( | |
'id' => '', | |
'align' => 'alignnone', | |
'width' => '', | |
'caption' => '', | |
), $attr)); | |
if ( 1 > (int) $width || empty($caption) ) | |
return $content; | |
// Grab ID to query post_content [description] field for image | |
preg_match('/([\d]+)/', $id, $matches); | |
$description = ''; | |
// Do we need to get description? | |
if ( strpos( $content , 'data-desc-style' ) ) { | |
if ($matches[0]) { | |
global $wpdb; | |
$custom_description = $wpdb->get_row("SELECT post_content FROM $wpdb->posts WHERE ID = {$matches[0]};"); | |
if ($custom_description->post_content) { | |
$description = '<div class="wp-image-description">' . apply_filters('the_content', $custom_description->post_content) . '</div><div class="wp-desc-placeholder"></div>'; | |
} | |
} | |
if ( $id ) $id = 'id="' . esc_attr($id) . '" '; | |
} | |
return '<div ' . $id . ' class="wp-caption ' . esc_attr($align) . '">' | |
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p>' . $description . '</div>'; | |
} | |
add_filter( 'img_caption_shortcode', 'bi_img_caption_shortcode', 1, 3 ); | |
function bi_enqueue_scripts() { | |
wp_enqueue_style( 'bimages-style', plugins_url() . '/better-images/better-images.css' ); | |
wp_enqueue_script( 'bimages-script', plugins_url() . '/better-images/better-images.js', array(), null, true ); | |
wp_enqueue_script( 'inview', plugins_url() . '/better-images/jquery.inview.js', array(), null, true ); | |
} | |
add_action( 'wp_enqueue_scripts' , 'bi_enqueue_scripts' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment