WP Gallery Custom Links - Version 1.7.1

Version Description

  • A few performance increases
Download this release

Release Info

Developer fourlightsweb
Plugin Icon wp plugin WP Gallery Custom Links
Version 1.7.1
Comparing to
See all releases

Code changes from version 1.7.0 to 1.7.1

Files changed (2) hide show
  1. readme.txt +7 -1
  2. wp-gallery-custom-links.php +30 -14
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.fourlightsweb.com/wordpress-plugins/wp-gallery-custom-li
4
  Tags: gallery links, gallery link, gallery
5
  Requires at least: 3.3.2
6
  Tested up to: 3.5.1
7
- Stable tag: 1.7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -83,6 +83,9 @@ Check your HTML and CSS for these changes and adjust accordingly.
83
 
84
  == Changelog ==
85
 
 
 
 
86
  = 1.7.0 =
87
  * By popular demand, added support for the "open_all_in_new_window" and "open_all_in_same_window"
88
  gallery shortcode attributes to set all images in a gallery to open in a new/the same window, respectively.
@@ -158,6 +161,9 @@ directly attached to the post.
158
 
159
  == Upgrade Notice ==
160
 
 
 
 
161
  = 1.7.0 =
162
  * By popular demand, added support for the "open_all_in_new_window" and "open_all_in_same_window"
163
  gallery shortcode attributes to set all images in a gallery to open in a new/the same window, respectively.
4
  Tags: gallery links, gallery link, gallery
5
  Requires at least: 3.3.2
6
  Tested up to: 3.5.1
7
+ Stable tag: 1.7.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
83
 
84
  == Changelog ==
85
 
86
+ = 1.7.1 =
87
+ * A few performance increases
88
+
89
  = 1.7.0 =
90
  * By popular demand, added support for the "open_all_in_new_window" and "open_all_in_same_window"
91
  gallery shortcode attributes to set all images in a gallery to open in a new/the same window, respectively.
161
 
162
  == Upgrade Notice ==
163
 
164
+ = 1.7.1 =
165
+ * A few performance increases
166
+
167
  = 1.7.0 =
168
  * By popular demand, added support for the "open_all_in_new_window" and "open_all_in_same_window"
169
  gallery shortcode attributes to set all images in a gallery to open in a new/the same window, respectively.
wp-gallery-custom-links.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Gallery Custom Links
4
  Plugin URI: http://www.fourlightsweb.com/wordpress-plugins/wp-gallery-custom-links/
5
  Description: Specifiy custom links for WordPress gallery images (instead of attachment or file only).
6
- Version: 1.7.0
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
@@ -151,18 +151,25 @@ class WPGalleryCustomLinks {
151
  // default, theme-specified or whatever
152
  $output = call_user_func( $gallery_shortcode_function, $attr );
153
 
154
- // Get the attachment ids for this post, as well as any "include"d attachments
155
- $attachments = get_children( array( 'post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
156
  $attachment_ids = array();
157
- if( count( $attachments ) > 0 ) {
158
- $attachment_ids = array_merge( $attachment_ids, array_keys( $attachments ) );
159
- }
 
 
 
 
 
 
 
 
160
  if( isset( $attr['include'] ) ) {
161
  $attachment_ids = array_merge( $attachment_ids, explode( ',', $attr['include'] ) );
162
  }
163
- if( isset( $attr['ids'] ) ) { // Added in WP 3.5
164
- $attachment_ids = array_merge( $attachment_ids, explode( ',', $attr['ids'] ) );
165
- }
 
166
  foreach ( $attachment_ids as $attachment_id ) {
167
  $link = '';
168
  $target = '';
@@ -262,7 +269,6 @@ class WPGalleryCustomLinks {
262
  } // End if we have attachment sizes
263
  } // End if we have attachment metadata (specifically sizes)
264
  } // End if we have a link to swap in or a target to add
265
-
266
  } // End foreach post attachment
267
 
268
  return $output;
@@ -274,6 +280,8 @@ class WPGalleryCustomLinks {
274
  $needle = str_replace( '/', '\/', $needle );
275
  $needle = '/href\s*=\s*["\']' . $needle . '["\']/';
276
  if( preg_match( $needle, $output ) > 0 ) {
 
 
277
  // Remove Link
278
  if( $remove_link ) {
279
  // Break the output up into two parts: everything before this href
@@ -313,21 +321,29 @@ class WPGalleryCustomLinks {
313
  // javascript later (only if we're opening it in a new window -
314
  // don't want to auto-unbind lightbox if it's the same window)
315
  if( $target == '_blank' ) {
316
- $output = self::add_class( $default_link, 'set-target', $output );
317
  }
318
  }
319
 
320
- // Custom Link
321
- if( $custom_link != '' && ! $remove_link ) {
322
  // Add a class to the link so we can manipulate it with
323
  // javascript later.
324
  // Doing this first in case we have the same custom link
325
  // on multiple items, in which case that class would be added
326
  // to the first item/all items multiple times.
327
  if( $preserve_click != 'preserve' ) {
328
- $output = self::add_class( $default_link, 'no-lightbox', $output );
329
  }
 
330
 
 
 
 
 
 
 
 
331
  // If we found the href to swap out, perform the href replacement,
332
  // and add some javascript to prevent lightboxes from kicking in
333
  $output = preg_replace( $needle, 'href="' . $custom_link . '"', $output );
3
  Plugin Name: WP Gallery Custom Links
4
  Plugin URI: http://www.fourlightsweb.com/wordpress-plugins/wp-gallery-custom-links/
5
  Description: Specifiy custom links for WordPress gallery images (instead of attachment or file only).
6
+ Version: 1.7.1
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
151
  // default, theme-specified or whatever
152
  $output = call_user_func( $gallery_shortcode_function, $attr );
153
 
 
 
154
  $attachment_ids = array();
155
+ if( isset( $attr['ids'] ) ) {
156
+ // WP 3.5+:
157
+ $attachment_ids = array_merge( $attachment_ids, explode( ',', $attr['ids'] ) );
158
+ } else {
159
+ // < WP 3.5:
160
+ // Get the attachment ids for this post, as well as any "include"d attachments
161
+ $attachments = get_children( array( 'post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
162
+ if( count( $attachments ) > 0 ) {
163
+ $attachment_ids = array_merge( $attachment_ids, array_keys( $attachments ) );
164
+ }
165
+ } // End if it's the "ids" attribute way of specifying images or not
166
  if( isset( $attr['include'] ) ) {
167
  $attachment_ids = array_merge( $attachment_ids, explode( ',', $attr['include'] ) );
168
  }
169
+
170
+ // Make sure we don't replace the same one multiple times
171
+ $attachment_ids = array_unique( $attachment_ids );
172
+
173
  foreach ( $attachment_ids as $attachment_id ) {
174
  $link = '';
175
  $target = '';
269
  } // End if we have attachment sizes
270
  } // End if we have attachment metadata (specifically sizes)
271
  } // End if we have a link to swap in or a target to add
 
272
  } // End foreach post attachment
273
 
274
  return $output;
280
  $needle = str_replace( '/', '\/', $needle );
281
  $needle = '/href\s*=\s*["\']' . $needle . '["\']/';
282
  if( preg_match( $needle, $output ) > 0 ) {
283
+ $classes_to_add = '';
284
+
285
  // Remove Link
286
  if( $remove_link ) {
287
  // Break the output up into two parts: everything before this href
321
  // javascript later (only if we're opening it in a new window -
322
  // don't want to auto-unbind lightbox if it's the same window)
323
  if( $target == '_blank' ) {
324
+ $classes_to_add .= 'set-target ';
325
  }
326
  }
327
 
328
+ // Pre-custom link class
329
+ if( $custom_link != '' && ! $remove_link ) { // Same criteria as "custom link" block below
330
  // Add a class to the link so we can manipulate it with
331
  // javascript later.
332
  // Doing this first in case we have the same custom link
333
  // on multiple items, in which case that class would be added
334
  // to the first item/all items multiple times.
335
  if( $preserve_click != 'preserve' ) {
336
+ $classes_to_add .= 'no-lightbox ';
337
  }
338
+ } // End if we have a custom link to swap in
339
 
340
+ // Add any classes, if needed (saves on some regexes to do it all at once)
341
+ if( $classes_to_add != '' ) {
342
+ $output = self::add_class( $default_link, trim( $classes_to_add ), $output );
343
+ }
344
+
345
+ // Custom Link
346
+ if( $custom_link != '' && ! $remove_link ) {
347
  // If we found the href to swap out, perform the href replacement,
348
  // and add some javascript to prevent lightboxes from kicking in
349
  $output = preg_replace( $needle, 'href="' . $custom_link . '"', $output );