Version Description
- By popular demand, added the ability to remove links from individual images or an entire gallery.
Download this release
Release Info
Developer | fourlightsweb |
Plugin | WP Gallery Custom Links |
Version | 1.6.0 |
Comparing to | |
See all releases |
Code changes from version 1.5.1 to 1.6.0
- readme.txt +38 -17
- wp-gallery-custom-links.php +48 -12
readme.txt
CHANGED
@@ -3,39 +3,41 @@ Contributors: fourlightsweb
|
|
3 |
Donate link: http://www.fourlightsweb.com/wordpress-plugins/wp-gallery-custom-links/#donate
|
4 |
Tags: gallery links, gallery link, gallery
|
5 |
Requires at least: 3.3.2
|
6 |
-
Tested up to: 3.5
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
-
|
12 |
|
13 |
== Description ==
|
14 |
|
|
|
|
|
15 |
If you've ever had a WordPress gallery of staff, product, or other images and needed
|
16 |
to link them to other pages but couldn't, this plugin is for you!
|
17 |
|
18 |
This plugin adds a "Gallery Link URL" field when editing post images. If the image
|
19 |
is included in a gallery, the "Gallery Link URL" value will be used as the link on
|
20 |
-
the image instead of the raw file or the attachment post. There
|
21 |
-
|
22 |
-
different gallery but not use the custom links, you can add
|
23 |
-
'ignore_gallery_link_urls="true"' to the [gallery] shortcode:
|
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
|
36 |
-
output.
|
37 |
-
|
|
|
|
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
== Installation ==
|
41 |
|
@@ -59,12 +61,31 @@ designed for use with 1) WordPress's [gallery] shortcode and 2) images
|
|
59 |
attached to the post/page. NextGen galleries uses its own [nggallery] etc. shortcodes
|
60 |
that function outside of the WordPress [gallery] shortcode.
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
== Screenshots ==
|
63 |
|
64 |
1. The additional WP Gallery Custom Link fields.
|
65 |
|
66 |
== Changelog ==
|
67 |
|
|
|
|
|
|
|
|
|
68 |
= 1.5.1 =
|
69 |
* Fixed a possible error with an undefined "preserve_click" variable.
|
70 |
|
3 |
Donate link: http://www.fourlightsweb.com/wordpress-plugins/wp-gallery-custom-links/#donate
|
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.6.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
+
Specify custom links for WordPress gallery images (instead of attachment or file only).
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
+
= Overview =
|
16 |
+
|
17 |
If you've ever had a WordPress gallery of staff, product, or other images and needed
|
18 |
to link them to other pages but couldn't, this plugin is for you!
|
19 |
|
20 |
This plugin adds a "Gallery Link URL" field when editing post images. If the image
|
21 |
is included in a gallery, the "Gallery Link URL" value will be used as the link on
|
22 |
+
the image instead of the raw file or the attachment post. There are also several
|
23 |
+
additional options (see "Usage" below).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
It's designed to work even if customizations have been made via the
|
26 |
post_gallery filter; instead of replacing the entire post_gallery function, it
|
27 |
calls the normal function and simply replaces the link hrefs in the generated
|
28 |
+
output. By default, any Lightbox or other onClick events on custom links
|
29 |
+
will be removed to allow them to function as regular links.
|
30 |
+
|
31 |
+
= Usage =
|
32 |
|
33 |
+
* See the custom fields added in the screenshots section at http://wordpress.org/extend/plugins/wp-gallery-custom-links/screenshots/.
|
34 |
+
* For each gallery image, you can specify a custom Gallery Link URL.
|
35 |
+
* Use "[none]" as the Gallery Link URL to remove the link for that gallery image.
|
36 |
+
* For each gallery image, you can select a Gallery Link Target ("Same Window" or "New Window").
|
37 |
+
* For each gallery image, you can select how to handle Lightbox and other onClick events ("Remove" or "Keep").
|
38 |
+
* Use [gallery ignore_gallery_link_urls="true"] to ignore the custom links on an entire gallery.
|
39 |
+
* Use [gallery preserve_click_events="true"] to keep Lightbox or other onClick events on all custom-linked images in an entire gallery.
|
40 |
+
* Use [gallery remove_links="true"] to remove links on all images in an entire gallery.
|
41 |
|
42 |
== Installation ==
|
43 |
|
61 |
attached to the post/page. NextGen galleries uses its own [nggallery] etc. shortcodes
|
62 |
that function outside of the WordPress [gallery] shortcode.
|
63 |
|
64 |
+
= I've set my gallery to remove Lightbox effects, but they are still coming up. Why? =
|
65 |
+
|
66 |
+
Your Lightbox javascript may be running after the WP Gallery Custom Links javascript.
|
67 |
+
This may cause the Lightbox effect to be applied after the WP Gallery Custom Links
|
68 |
+
script attempts to remove it. Try moving your Lightbox javascript above the
|
69 |
+
WP Gallery Custom Links javascript. Note that you may need to add your Lightbox
|
70 |
+
script as a dependency for WP Gallery Custom Links to make sure WP Gallery Custom Links
|
71 |
+
runs after it.
|
72 |
+
|
73 |
+
= When I enable the plugin, the styling on my gallery changes. Why? =
|
74 |
+
|
75 |
+
The way the plugin works requires the gallery generation code to be run twice. This
|
76 |
+
may result in it being labeled as "#gallery-2" instead of "#gallery-1."
|
77 |
+
Check your HTML and CSS for these changes and adjust accordingly.
|
78 |
+
|
79 |
== Screenshots ==
|
80 |
|
81 |
1. The additional WP Gallery Custom Link fields.
|
82 |
|
83 |
== Changelog ==
|
84 |
|
85 |
+
= 1.6.0 =
|
86 |
+
* By popular demand, added the ability to remove links from individual images
|
87 |
+
or an entire gallery.
|
88 |
+
|
89 |
= 1.5.1 =
|
90 |
* Fixed a possible error with an undefined "preserve_click" variable.
|
91 |
|
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 |
Author: Four Lights Web Development
|
8 |
Author URI: http://www.fourlightsweb.com
|
9 |
License: GPL2
|
@@ -120,7 +120,7 @@ class WPGalleryCustomLinks {
|
|
120 |
return ' ';
|
121 |
}
|
122 |
|
123 |
-
if( isset( $attr['ignore_gallery_link_urls'] ) && trim( $attr['ignore_gallery_link_urls'] ) === 'true' ) {
|
124 |
// If the user has passed in a parameter to ignore the custom link
|
125 |
// URLs for this gallery, just skip over this whole plugin and
|
126 |
// return what was passed in
|
@@ -163,6 +163,7 @@ class WPGalleryCustomLinks {
|
|
163 |
$link = '';
|
164 |
$target = '';
|
165 |
$preserve_click = '';
|
|
|
166 |
$attachment_id = intval( $attachment_id );
|
167 |
|
168 |
// See if we have a custom url for this attachment image
|
@@ -181,19 +182,24 @@ class WPGalleryCustomLinks {
|
|
181 |
if( $attachment_meta ) {
|
182 |
$preserve_click = $attachment_meta;
|
183 |
}
|
184 |
-
if( isset( $attr['preserve_click_events'] ) && trim( $attr['preserve_click_events'] ) === 'true' ) {
|
185 |
// Override the individual setting if the gallery shortcode says to preserve on all
|
186 |
$preserve_click = 'preserve';
|
187 |
}
|
188 |
|
189 |
-
if
|
|
|
|
|
|
|
|
|
|
|
190 |
// Replace the attachment href
|
191 |
$needle = get_attachment_link( $attachment_id );
|
192 |
-
$output = self::replace_link( $needle, $link, $target, $preserve_click, $output );
|
193 |
|
194 |
// Replace the file href
|
195 |
list( $needle ) = wp_get_attachment_image_src( $attachment_id, '' );
|
196 |
-
$output = self::replace_link( $needle, $link, $target, $preserve_click, $output );
|
197 |
// Also, in case of jetpack photon with tiled galleries...
|
198 |
if( function_exists( 'jetpack_photon_url' ) ) {
|
199 |
// The CDN url currently is generated with "$subdomain = rand( 0, 2 );",
|
@@ -209,7 +215,7 @@ class WPGalleryCustomLinks {
|
|
209 |
$needle_part_1 = preg_replace( '/\d+$/', '', $needle_parts[0] );
|
210 |
$needle_part_2 = '.wp.com' . $needle_parts[1];
|
211 |
$needle_reassembled = $needle_part_1 . $j . $needle_part_2;
|
212 |
-
$output = self::replace_link( $needle_reassembled, $link, $target, $preserve_click, $output );
|
213 |
}
|
214 |
}
|
215 |
}
|
@@ -222,7 +228,7 @@ class WPGalleryCustomLinks {
|
|
222 |
if( is_array( $attachment_sizes ) && count( $attachment_sizes ) > 0 ) {
|
223 |
foreach( $attachment_sizes as $attachment_size => $attachment_info ) {
|
224 |
list( $needle ) = wp_get_attachment_image_src( $attachment_id, $attachment_size );
|
225 |
-
$output = self::replace_link( $needle, $link, $target, $preserve_click, $output );
|
226 |
} // End of foreach attachment size
|
227 |
} // End if we have attachment sizes
|
228 |
} // End if we have attachment metadata (specifically sizes)
|
@@ -233,14 +239,44 @@ class WPGalleryCustomLinks {
|
|
233 |
return $output;
|
234 |
} // End function apply_filter_post_gallery()
|
235 |
|
236 |
-
private static function replace_link( $default_link, $custom_link, $target, $preserve_click, $output ) {
|
237 |
// Build the regex for matching/replacing
|
238 |
$needle = preg_quote( $default_link );
|
239 |
$needle = str_replace( '/', '\/', $needle );
|
240 |
$needle = '/href\s*=\s*["\']' . $needle . '["\']/';
|
241 |
-
if( preg_match( $needle, $output ) > 0 ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
// Custom Target
|
243 |
-
if( $target != '' ) {
|
244 |
// Replace the link target
|
245 |
$output = self::add_target( $default_link, $target, $output );
|
246 |
|
@@ -250,7 +286,7 @@ class WPGalleryCustomLinks {
|
|
250 |
}
|
251 |
|
252 |
// Custom Link
|
253 |
-
if( $custom_link != '' ) {
|
254 |
// If we found the href to swap out, perform the href replacement,
|
255 |
// and add some javascript to prevent lightboxes from kicking in
|
256 |
$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.6.0
|
7 |
Author: Four Lights Web Development
|
8 |
Author URI: http://www.fourlightsweb.com
|
9 |
License: GPL2
|
120 |
return ' ';
|
121 |
}
|
122 |
|
123 |
+
if( isset( $attr['ignore_gallery_link_urls'] ) && strtolower( trim( $attr['ignore_gallery_link_urls'] ) ) === 'true' ) {
|
124 |
// If the user has passed in a parameter to ignore the custom link
|
125 |
// URLs for this gallery, just skip over this whole plugin and
|
126 |
// return what was passed in
|
163 |
$link = '';
|
164 |
$target = '';
|
165 |
$preserve_click = '';
|
166 |
+
$remove_link = false;
|
167 |
$attachment_id = intval( $attachment_id );
|
168 |
|
169 |
// See if we have a custom url for this attachment image
|
182 |
if( $attachment_meta ) {
|
183 |
$preserve_click = $attachment_meta;
|
184 |
}
|
185 |
+
if( isset( $attr['preserve_click_events'] ) && strtolower( trim( $attr['preserve_click_events'] ) ) === 'true' ) {
|
186 |
// Override the individual setting if the gallery shortcode says to preserve on all
|
187 |
$preserve_click = 'preserve';
|
188 |
}
|
189 |
|
190 |
+
// See if we need to remove the link for this image or not
|
191 |
+
if( strtolower( trim( $link ) ) === '[none]' || ( isset( $attr['remove_links'] ) && strtolower( trim( $attr['remove_links'] ) ) === 'true' ) ) {
|
192 |
+
$remove_link = true;
|
193 |
+
}
|
194 |
+
|
195 |
+
if( $link != '' || $target != '' || $remove_link ) {
|
196 |
// Replace the attachment href
|
197 |
$needle = get_attachment_link( $attachment_id );
|
198 |
+
$output = self::replace_link( $needle, $link, $target, $preserve_click, $remove_link, $output );
|
199 |
|
200 |
// Replace the file href
|
201 |
list( $needle ) = wp_get_attachment_image_src( $attachment_id, '' );
|
202 |
+
$output = self::replace_link( $needle, $link, $target, $preserve_click, $remove_link, $output );
|
203 |
// Also, in case of jetpack photon with tiled galleries...
|
204 |
if( function_exists( 'jetpack_photon_url' ) ) {
|
205 |
// The CDN url currently is generated with "$subdomain = rand( 0, 2 );",
|
215 |
$needle_part_1 = preg_replace( '/\d+$/', '', $needle_parts[0] );
|
216 |
$needle_part_2 = '.wp.com' . $needle_parts[1];
|
217 |
$needle_reassembled = $needle_part_1 . $j . $needle_part_2;
|
218 |
+
$output = self::replace_link( $needle_reassembled, $link, $target, $preserve_click, $remove_link, $output );
|
219 |
}
|
220 |
}
|
221 |
}
|
228 |
if( is_array( $attachment_sizes ) && count( $attachment_sizes ) > 0 ) {
|
229 |
foreach( $attachment_sizes as $attachment_size => $attachment_info ) {
|
230 |
list( $needle ) = wp_get_attachment_image_src( $attachment_id, $attachment_size );
|
231 |
+
$output = self::replace_link( $needle, $link, $target, $preserve_click, $remove_link, $output );
|
232 |
} // End of foreach attachment size
|
233 |
} // End if we have attachment sizes
|
234 |
} // End if we have attachment metadata (specifically sizes)
|
239 |
return $output;
|
240 |
} // End function apply_filter_post_gallery()
|
241 |
|
242 |
+
private static function replace_link( $default_link, $custom_link, $target, $preserve_click, $remove_link, $output ) {
|
243 |
// Build the regex for matching/replacing
|
244 |
$needle = preg_quote( $default_link );
|
245 |
$needle = str_replace( '/', '\/', $needle );
|
246 |
$needle = '/href\s*=\s*["\']' . $needle . '["\']/';
|
247 |
+
if( preg_match( $needle, $output ) > 0 ) {
|
248 |
+
// Remove Link
|
249 |
+
if( $remove_link ) {
|
250 |
+
// Break the output up into two parts: everything before this href
|
251 |
+
// and everything after
|
252 |
+
$output_parts = explode( $default_link, $output );
|
253 |
+
if( count( $output_parts ) == 2 ) {
|
254 |
+
$output_part_1 = $output_parts[0];
|
255 |
+
$output_part_2 = $output_parts[1];
|
256 |
+
|
257 |
+
// Take out the <a> from the end of part 1
|
258 |
+
$output_part_1 = preg_replace( '/<\s*a\s+.*$/', '', $output_part_1 );
|
259 |
+
|
260 |
+
// And then take out everything up through the first > that comes after that
|
261 |
+
// (which would be the closing angle bracket of <a>)
|
262 |
+
$pos = strpos( $output_part_2, '>' );
|
263 |
+
if( $pos !== false ) {
|
264 |
+
$output_part_2 = substr( $output_part_2, $pos+1 );
|
265 |
+
}
|
266 |
+
|
267 |
+
// And then take out the first </a> that comes after that
|
268 |
+
$pos = strpos( $output_part_2, '</a>' );
|
269 |
+
if( $pos !== false ) {
|
270 |
+
$output_part_2 = substr( $output_part_2, 0, $pos ) . substr( $output_part_2, $pos+4 );
|
271 |
+
}
|
272 |
+
|
273 |
+
// And then stitch them back together again, without the link parts
|
274 |
+
$output = $output_part_1 . $output_part_2;
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
// Custom Target
|
279 |
+
if( $target != '' && ! $remove_link ) {
|
280 |
// Replace the link target
|
281 |
$output = self::add_target( $default_link, $target, $output );
|
282 |
|
286 |
}
|
287 |
|
288 |
// Custom Link
|
289 |
+
if( $custom_link != '' && ! $remove_link ) {
|
290 |
// If we found the href to swap out, perform the href replacement,
|
291 |
// and add some javascript to prevent lightboxes from kicking in
|
292 |
$output = preg_replace( $needle, 'href="' . $custom_link . '"', $output );
|