WP Gallery Custom Links - Version 1.4.0

Version Description

  • By popular demand, added an option to remove or keep Lightbox and other OnClick events ("remove" by default).
  • Added support for the "preserve_click_events" gallery shortcode attribute to set all custom-linked images in a gallery to "preserve" its OnClick events.
Download this release

Release Info

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

Code changes from version 1.3.0 to 1.4.0

Files changed (3) hide show
  1. readme.txt +20 -2
  2. screenshot-1.png +0 -0
  3. wp-gallery-custom-links.php +32 -6
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
7
- Stable tag: 1.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -24,6 +24,12 @@ different gallery but not use the custom links, you can add
24
 
25
  [gallery ignore_gallery_link_urls="true"]
26
 
 
 
 
 
 
 
27
  It's designed to work even if customizations have been made via the
28
  post_gallery filter; instead of replacing the entire post_gallery function, it
29
  calls the normal function and simply replaces the link hrefs in the generated
@@ -55,10 +61,16 @@ that function outside of the WordPress [gallery] shortcode.
55
 
56
  == Screenshots ==
57
 
58
- 1. The added "Gallery Link URL" field.
59
 
60
  == Changelog ==
61
 
 
 
 
 
 
 
62
  = 1.3.0 =
63
  * Added support for the "ignore_gallery_link_urls" gallery shortcode attribute to
64
  ignore custom links on a gallery and use the normal file/attachment setting.
@@ -105,6 +117,12 @@ directly attached to the post.
105
 
106
  == Upgrade Notice ==
107
 
 
 
 
 
 
 
108
  = 1.3.0 =
109
  * Added support for the "ignore_gallery_link_urls" gallery shortcode attribute to
110
  ignore custom links on a gallery and use the normal file/attachment setting.
4
  Tags: gallery links, gallery link, gallery
5
  Requires at least: 3.3.2
6
  Tested up to: 3.5
7
+ Stable tag: 1.4.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
24
 
25
  [gallery ignore_gallery_link_urls="true"]
26
 
27
+ If you want all the custom-linked images in a gallery to keep their Lightbox or
28
+ other OnClick events, you can add 'preserve_click_events="true"' to the [gallery]
29
+ shortcode:
30
+
31
+ [gallery preserve_click_events="true"]
32
+
33
  It's designed to work even if customizations have been made via the
34
  post_gallery filter; instead of replacing the entire post_gallery function, it
35
  calls the normal function and simply replaces the link hrefs in the generated
61
 
62
  == Screenshots ==
63
 
64
+ 1. The additional WP Gallery Custom Link fields.
65
 
66
  == Changelog ==
67
 
68
+ = 1.4.0 =
69
+ * By popular demand, added an option to remove or keep Lightbox and other OnClick
70
+ events ("remove" by default).
71
+ * Added support for the "preserve_click_events" gallery shortcode attribute to
72
+ set all custom-linked images in a gallery to "preserve" its OnClick events.
73
+
74
  = 1.3.0 =
75
  * Added support for the "ignore_gallery_link_urls" gallery shortcode attribute to
76
  ignore custom links on a gallery and use the normal file/attachment setting.
117
 
118
  == Upgrade Notice ==
119
 
120
+ = 1.4.0 =
121
+ * By popular demand, added an option to remove or keep Lightbox and other OnClick
122
+ events ("remove" by default).
123
+ * Added support for the "preserve_click_events" gallery shortcode attribute to
124
+ set all custom-linked images in a gallery to "preserve" its OnClick events.
125
+
126
  = 1.3.0 =
127
  * Added support for the "ignore_gallery_link_urls" gallery shortcode attribute to
128
  ignore custom links on a gallery and use the normal file/attachment setting.
screenshot-1.png CHANGED
Binary file
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.3.0
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
@@ -78,6 +78,17 @@ class WPGalleryCustomLinks {
78
  <option value="_blank"'.($target_value == '_blank' ? ' selected="selected"' : '').'>New Window</option>
79
  </select>'
80
  );
 
 
 
 
 
 
 
 
 
 
 
81
  return $form_fields;
82
  } // End function apply_filter_attachment_fields_to_edit()
83
 
@@ -88,6 +99,9 @@ class WPGalleryCustomLinks {
88
  if( isset( $attachment['gallery_link_target'] ) ) {
89
  update_post_meta( $post['ID'], '_gallery_link_target', $attachment['gallery_link_target'] );
90
  }
 
 
 
91
  return $post;
92
  } // End function apply_filter_attachment_fields_to_save()
93
 
@@ -160,15 +174,25 @@ class WPGalleryCustomLinks {
160
  if( $attachment_meta ) {
161
  $target = $attachment_meta;
162
  }
 
 
 
 
 
 
 
 
 
 
163
 
164
  if( $link != '' || $target != '' ) {
165
  // Replace the attachment href
166
  $needle = get_attachment_link( $attachment_id );
167
- $output = self::replace_link( $needle, $link, $target, $output );
168
 
169
  // Replace the file href
170
  list( $needle ) = wp_get_attachment_image_src( $attachment_id, '' );
171
- $output = self::replace_link( $needle, $link, $target, $output );
172
 
173
  // Replace all possible file sizes - some themes etc.
174
  // may use sizes other than the full version
@@ -178,7 +202,7 @@ class WPGalleryCustomLinks {
178
  if( is_array( $attachment_sizes ) && count( $attachment_sizes ) > 0 ) {
179
  foreach( $attachment_sizes as $attachment_size => $attachment_info ) {
180
  list( $needle ) = wp_get_attachment_image_src( $attachment_id, $attachment_size );
181
- $output = self::replace_link( $needle, $link, $target, $output );
182
  } // End of foreach attachment size
183
  } // End if we have attachment sizes
184
  } // End if we have attachment metadata (specifically sizes)
@@ -189,7 +213,7 @@ class WPGalleryCustomLinks {
189
  return $output;
190
  } // End function apply_filter_post_gallery()
191
 
192
- private static function replace_link( $default_link, $custom_link, $target, $output ) {
193
  // Build the regex for matching/replacing
194
  $needle = preg_quote( $default_link );
195
  $needle = str_replace( '/', '\/', $needle );
@@ -213,7 +237,9 @@ class WPGalleryCustomLinks {
213
 
214
  // Add a class to the link so we can manipulate it with
215
  // javascript later
216
- $output = self::add_class( $custom_link, 'no-lightbox', $output );
 
 
217
  } // End if we have a custom link to swap in
218
  } // End if we found the attachment to replace in the output
219
 
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.4.0
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
78
  <option value="_blank"'.($target_value == '_blank' ? ' selected="selected"' : '').'>New Window</option>
79
  </select>'
80
  );
81
+ $preserve_click_value = get_post_meta( $post->ID, '_gallery_link_preserve_click', true );
82
+ $form_fields['gallery_link_preserve_click'] = array(
83
+ 'label' => __( 'Gallery Link OnClick Effect' ),
84
+ 'input' => 'html',
85
+ 'html' => '
86
+ <select name="attachments['.$post->ID.'][gallery_link_preserve_click]" id="attachments['.$post->ID.'][gallery_link_preserve_click]">
87
+ <option value="remove">Remove</option>
88
+ <option value="preserve"'.($preserve_click_value == 'preserve' ? ' selected="selected"' : '').'>Keep</option>
89
+ </select>',
90
+ 'helps' => 'Lightbox and other OnClick events are removed by default.'
91
+ );
92
  return $form_fields;
93
  } // End function apply_filter_attachment_fields_to_edit()
94
 
99
  if( isset( $attachment['gallery_link_target'] ) ) {
100
  update_post_meta( $post['ID'], '_gallery_link_target', $attachment['gallery_link_target'] );
101
  }
102
+ if( isset( $attachment['gallery_link_preserve_click'] ) ) {
103
+ update_post_meta( $post['ID'], '_gallery_link_preserve_click', $attachment['gallery_link_preserve_click'] );
104
+ }
105
  return $post;
106
  } // End function apply_filter_attachment_fields_to_save()
107
 
174
  if( $attachment_meta ) {
175
  $target = $attachment_meta;
176
  }
177
+
178
+ // See how to handle click events for this attachment image
179
+ $attachment_meta = get_post_meta( $attachment_id, '_gallery_link_preserve_click', true );
180
+ if( $attachment_meta ) {
181
+ $preserve_click = $attachment_meta;
182
+ }
183
+ if( isset( $attr['preserve_click_events'] ) && trim( $attr['preserve_click_events'] ) === 'true' ) {
184
+ // Override the individual setting if the gallery shortcode says to preserve on all
185
+ $preserve_click = 'preserve';
186
+ }
187
 
188
  if( $link != '' || $target != '' ) {
189
  // Replace the attachment href
190
  $needle = get_attachment_link( $attachment_id );
191
+ $output = self::replace_link( $needle, $link, $target, $preserve_click, $output );
192
 
193
  // Replace the file href
194
  list( $needle ) = wp_get_attachment_image_src( $attachment_id, '' );
195
+ $output = self::replace_link( $needle, $link, $target, $preserve_click, $output );
196
 
197
  // Replace all possible file sizes - some themes etc.
198
  // may use sizes other than the full version
202
  if( is_array( $attachment_sizes ) && count( $attachment_sizes ) > 0 ) {
203
  foreach( $attachment_sizes as $attachment_size => $attachment_info ) {
204
  list( $needle ) = wp_get_attachment_image_src( $attachment_id, $attachment_size );
205
+ $output = self::replace_link( $needle, $link, $target, $preserve_click, $output );
206
  } // End of foreach attachment size
207
  } // End if we have attachment sizes
208
  } // End if we have attachment metadata (specifically sizes)
213
  return $output;
214
  } // End function apply_filter_post_gallery()
215
 
216
+ private static function replace_link( $default_link, $custom_link, $target, $preserve_click, $output ) {
217
  // Build the regex for matching/replacing
218
  $needle = preg_quote( $default_link );
219
  $needle = str_replace( '/', '\/', $needle );
237
 
238
  // Add a class to the link so we can manipulate it with
239
  // javascript later
240
+ if( $preserve_click != 'preserve' ) {
241
+ $output = self::add_class( $custom_link, 'no-lightbox', $output );
242
+ }
243
  } // End if we have a custom link to swap in
244
  } // End if we found the attachment to replace in the output
245