Changeset 1117650
- Timestamp:
- 03/21/2015 09:05:39 PM (11 years ago)
- Location:
- gallery-shortcode-style-to-head/trunk
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
gallery-shortcode-style-to-head.php (modified) (11 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gallery-shortcode-style-to-head/trunk
-
Property
svn:ignore
set to
.buildpath
.project
.settings
-
Property
svn:ignore
set to
-
gallery-shortcode-style-to-head/trunk/gallery-shortcode-style-to-head.php
r678538 r1117650 2 2 /* 3 3 Plugin Name: Gallery Shortcode Style to Head 4 Plugin URI: http://www. scottbradford.us/software/gallery-shortcode-style-to-head/5 Description: Moves the gallery shortcode styles to the head so it doesn't break XHTML validation; allows disabling or modifying the default gallery styles. 6 Author: Scott Bradford7 Author URI: http://www. scottbradford.us/8 Version: 2.3 4 Plugin URI: http://www.intersanity.com/software/ 5 Description: Moves the gallery shortcode styles to the head so it doesn't break XHTML validation; allows disabling or modifying the default gallery styles. 6 Author: Intersanity Enterprises 7 Author URI: http://www.intersanity.com/ 8 Version: 2.3.1 9 9 10 10 Copyright (c) 2008 Matt Martz (http://sivel.net) (original author) 11 Copyright (c) 2009-201 2 Scott Bradford (http://www.scottbradford.us) (current maintainer)12 11 Copyright (c) 2009-2015 Intersanity Enterprises (Scott Bradford) (http://www.intersanity.com/software/) (current maintainer) 12 13 13 Gallery Shortcode Style to Head is released under the GNU General Public License (GPL) 14 14 http://www.gnu.org/licenses/gpl-2.0.txt 15 15 */ 16 16 17 add_action('init', 'gssth_init');18 19 function gssth_init () {17 add_action('init', 'gssth_init'); 18 19 function gssth_init () { 20 20 // define the default styles 21 21 global $defStyle; … … 31 31 32 32 // initialize the settings variables 33 add_action('admin_init', 'add_gssth_setting' );34 function add_gssth_setting () {35 register_setting( 'media', 'gssth_disable_gallery_style');36 register_setting( 'media', 'gssth_override_gallery_style');37 add_settings_section('gssth', 'Gallery CSS Styles','display_gssth_description','media');38 add_settings_field('gssth_disable_gallery_style', 'Disable gallery CSS in \'head\'','build_disable_gallery_styles','media','gssth');39 add_settings_field('gssth_override_gallery_style', 'Modify gallery CSS style','build_override_gallery_styles','media','gssth');33 add_action('admin_init', 'add_gssth_setting'); 34 function add_gssth_setting () { 35 register_setting('media', 'gssth_disable_gallery_style'); 36 register_setting('media', 'gssth_override_gallery_style'); 37 add_settings_section('gssth', 'Gallery CSS Styles', 'display_gssth_description', 'media'); 38 add_settings_field('gssth_disable_gallery_style', 'Disable gallery CSS in \'head\'', 'build_disable_gallery_styles', 'media', 'gssth'); 39 add_settings_field('gssth_override_gallery_style', 'Modify gallery CSS style', 'build_override_gallery_styles', 'media', 'gssth'); 40 40 } 41 41 42 42 // display the GSSTH description 43 function display_gssth_description () {43 function display_gssth_description () { 44 44 echo "<p>Override or disable the default WordPress gallery styles. To reset to default styles, un-check the disable option, clear out the style code (so it is completely empty), and save the changes.</p>"; 45 45 } 46 46 47 47 // handle the disable/enable check box 48 function build_disable_gallery_styles () {48 function build_disable_gallery_styles () { 49 49 $checked = ""; 50 if (get_option('gssth_disable_gallery_style')) 50 if (get_option('gssth_disable_gallery_style')) { 51 51 $checked=" checked='checked'"; 52 } 52 53 echo "<fieldset><legend class=\"screen-reader-text\"><span>Disable the default gallery CSS styles</span></legend> 53 54 <label for=\"disable_gallery_styles\"><input name=\"gssth_disable_gallery_style\" type=\"checkbox\" id=\"gssth_disable_gallery_style\" value=\"1\"" . $checked . " /> Disable the default gallery CSS styles (so you can handle it in your template stylesheets)</label> … … 56 57 57 58 // handle the style override field 58 function build_override_gallery_styles () {59 function build_override_gallery_styles () { 59 60 global $defStyle; 60 if (get_option('gssth_override_gallery_style')) 61 if (get_option('gssth_override_gallery_style')) { 61 62 $content = get_option('gssth_override_gallery_style'); 62 else63 } else { 63 64 $content = $defStyle; 65 } 64 66 echo "<textarea style='font-size: 90%; width:95%;' name='gssth_override_gallery_style' id='gssth_override_gallery_style' rows='15' >" . $content . "</textarea>"; 65 67 } 66 68 67 69 68 // This function is largely taken from media.php with manual patches based off of 70 // This function is largely taken from media.php with manual patches based off of 69 71 // http://trac.wordpress.org/attachment/ticket/6380/6380-style.diff 70 72 71 function gallery_shortcode_style_out ( $attr) {73 function gallery_shortcode_style_out ($attr) { 72 74 global $post, $wp_locale; 73 75 74 76 static $instance = 0; 75 77 $instance++; 76 77 if ( ! empty( $attr['ids'] )) {78 79 if (!empty( $attr['ids'])) { 78 80 // 'ids' is explicitly ordered, unless you specify otherwise. 79 if ( empty( $attr['orderby'] ) )81 if (empty($attr['orderby'])) { 80 82 $attr['orderby'] = 'post__in'; 83 } 81 84 $attr['include'] = $attr['ids']; 82 85 } … … 84 87 // Allow plugins/themes to override the default gallery template. 85 88 $output = apply_filters('post_gallery', '', $attr); 86 if ( $output != '' )89 if ($output != '') { 87 90 return $output; 91 } 88 92 89 93 // We're trusting author input, so let's at least make sure it looks like a valid orderby statement 90 if ( isset( $attr['orderby'] )) {91 $attr['orderby'] = sanitize_sql_orderby( $attr['orderby']);92 if ( !$attr['orderby'] )94 if (isset($attr['orderby'])) { 95 $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); 96 if (!$attr['orderby']) { 93 97 unset( $attr['orderby'] ); 98 } 94 99 } 95 100 … … 108 113 109 114 $id = intval($id); 110 if ( 'RAND' == $order )115 if ('RAND' == $order) { 111 116 $orderby = 'none'; 112 113 if ( !empty($include)) {114 $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));117 } 118 if (!empty($include)) { 119 $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); 115 120 116 121 $attachments = array(); 117 foreach ( $_attachments as $key => $val) {122 foreach ($_attachments as $key => $val) { 118 123 $attachments[$val->ID] = $_attachments[$key]; 119 124 } 120 } elseif ( !empty($exclude)) {121 $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));125 } elseif (!empty($exclude)) { 126 $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); 122 127 } else { 123 $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));124 } 125 126 if ( empty($attachments) )128 $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); 129 } 130 131 if (empty($attachments)) { 127 132 return ''; 128 129 if ( is_feed() ) { 133 } 134 135 if (is_feed()) { 130 136 $output = "\n"; 131 foreach ( $attachments as $att_id => $attachment )137 foreach ($attachments as $att_id => $attachment) { 132 138 $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; 139 } 133 140 return $output; 134 141 } … … 140 147 141 148 $selector = "gallery-{$instance}"; 142 143 $size_class = sanitize_html_class( $size, '');149 150 $size_class = sanitize_html_class($size, ''); 144 151 $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>"; 145 $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div);152 $output = apply_filters('gallery_style', $gallery_style . "\n\t\t" . $gallery_div); 146 153 147 154 $i = 0; 148 foreach ( $attachments as $id => $attachment) {155 foreach ($attachments as $id => $attachment) { 149 156 $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); 150 157 … … 154 161 $link 155 162 </{$icontag}>"; 156 if ( $captiontag && trim($attachment->post_excerpt)) {163 if ($captiontag && trim($attachment->post_excerpt)) { 157 164 $output .= " 158 165 <{$captiontag} class='wp-caption-text gallery-caption'> … … 161 168 } 162 169 $output .= "</{$itemtag}>"; 163 if ( $columns > 0 && ++$i % $columns == 0 )170 if ($columns > 0 && ++$i % $columns == 0) { 164 171 $output .= '<div style="clear: both"></div>'; 172 } 165 173 } 166 174 … … 174 182 // Default gallery style taken from media.php with .gallery-item width removed 175 183 // .gallery-item width applied inline in gallery_shortcode_style_out(). 176 function gallery_style () { 184 function gallery_style () { 177 185 global $defStyle; 178 186 $output = " … … 180 188 <style type='text/css'> 181 189 "; 182 if (get_option('gssth_override_gallery_style')) { // if the style is saved, export the saved style 183 $output .= get_option('gssth_override_gallery_style'); 184 } else { // if we don't have any styles set right now 190 if (get_option('gssth_override_gallery_style')) { 191 // if the style is saved, export the saved style 192 $output .= get_option('gssth_override_gallery_style'); 193 } else { 194 // if we don't have any styles set right now 185 195 $output .= $defStyle; 186 196 } … … 189 199 </style>"; 190 200 echo $output; 191 } 201 } 192 202 193 203 // Look ahead to check if any posts contain the [gallery] shortcode 194 204 // if true then add default gallery style to head 195 function gallery_scan () { 196 global $posts; 197 198 if ( !is_array ( $posts ) ) 199 return; 200 201 foreach ( $posts as $post ) { 202 if ( false !== strpos ( $post->post_content, '[gallery' ) ) { 203 add_action ( 'wp_head', 'gallery_style' ); 204 break; 205 } 206 } 207 } 205 function gallery_scan () { 206 global $posts; 207 208 if (!is_array($posts)) { 209 return; 210 } 211 212 foreach ($posts as $post) { 213 if (false !== strpos($post->post_content, '[gallery')) { 214 add_action('wp_head', 'gallery_style'); 215 break; 216 } 217 } 218 } 208 219 209 220 // Tell WordPress what to do 210 remove_shortcode ( 'gallery_shortcode' );// Remove included WordPress [gallery] shortcode function211 add_shortcode ( 'gallery' , 'gallery_shortcode_style_out' );// Add new [gallery] shortcode function212 if (!get_option('gssth_disable_gallery_style')) { // don't do the look-ahead if styles are disabled213 add_action ( 'template_redirect' , 'gallery_scan' ); // Add look ahead for [gallery] shortcode214 } 215 ?> 221 remove_shortcode('gallery_shortcode'); // Remove included WordPress [gallery] shortcode function 222 add_shortcode('gallery', 'gallery_shortcode_style_out'); // Add new [gallery] shortcode function 223 if (!get_option('gssth_disable_gallery_style')) { 224 // don't do the look-ahead if styles are disabled 225 add_action('template_redirect', 'gallery_scan'); // Add look ahead for [gallery] shortcode 226 } -
gallery-shortcode-style-to-head/trunk/readme.txt
r678539 r1117650 3 3 Tags: gallery, shortcode, style, css, xhtml, head, validation 4 4 Requires at least: 3.0 5 Tested up to: 3.55 Tested up to: 4.1 6 6 Stable tag: 2.3 7 7 8 8 Moves the gallery shortcode styles to the head so it doesn't break XHTML 9 validation; allows disabling or modifying the default gallery styles. 9 validation; allows disabling or modifying the default gallery styles. 10 10 11 11 == Description == … … 71 71 == Changelog == 72 72 73 = 2.3.1 (2015-02-xx): = 74 * Plugin is now translateable. 75 * Code cleanup and support for latest WordPress. 76 73 77 = 2.3 (2013-03-08): = 74 78 * Corrected 'undefined varibale' notice and RTL language detection.
Note: See TracChangeset
for help on using the changeset viewer.