WP Gallery Custom Links - Version 1.9.0

Version Description

  • By popular demand, moved the help notes under each field into tooltips so the form won't be so tall.
  • The javascript that attempts to disable lightboxes now runs in window.onload in addition to document.ready. Hopefully this will cut down on some of the issues where lightboxes keep popping up without having to mess with javascript dependencies at the code level. Any other window.onload function should be preserved.
  • Added a javascript function detect for jQuery's off() function, since it only came into existence in 1.7. If off() isn't defined, unbind() is called instead.
  • Resolved an issue where making an image have no link occasionally resulted in all previous images in the gallery disappearing from the display.
  • Added a translation for Polish, courtesy of Przemyslaw Trawicki (thanks!)
Download this release

Release Info

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

Code changes from version 1.8.0 to 1.9.0

languages/wp-gallery-custom-links-pl_PL.mo ADDED
Binary file
languages/wp-gallery-custom-links-pl_PL.po ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: wp-gallery-custom-links\n"
4
+ "POT-Creation-Date: 2013-08-09 16:41+0100\n"
5
+ "PO-Revision-Date: 2013-08-09 16:41+0100\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: \n"
8
+ "Language: pl_PL\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.5.7\n"
13
+ "X-Poedit-KeywordsList: _;gettext;gettext_noop;__\n"
14
+ "X-Poedit-Basepath: .\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-SearchPath-0: .\n"
17
+
18
+ #: wp-gallery-custom-links.php:68
19
+ msgid "Gallery Link URL"
20
+ msgstr "URL odnośnika"
21
+
22
+ #: wp-gallery-custom-links.php:71
23
+ msgid ""
24
+ "Will replace \"Image File\" or \"Attachment Page\" link for this image in "
25
+ "galleries. Use [none] to remove the link from this image in galleries."
26
+ msgstr "Podaj adres odnośnika. Wpisanie [none] daje brak odnośnika."
27
+
28
+ #: wp-gallery-custom-links.php:76
29
+ msgid "Gallery Link Target"
30
+ msgstr "Okno docelowe"
31
+
32
+ #: wp-gallery-custom-links.php:80
33
+ msgid "Same Window"
34
+ msgstr "To samo okno"
35
+
36
+ #: wp-gallery-custom-links.php:81
37
+ msgid "New Window"
38
+ msgstr "Nowe okno"
39
+
40
+ #: wp-gallery-custom-links.php:83
41
+ msgid ""
42
+ "This setting will be applied to this image in galleries regardless of "
43
+ "whether or not a Gallery Link URL has been specified."
44
+ msgstr " "
45
+
46
+ #: wp-gallery-custom-links.php:88
47
+ msgid "Gallery Link OnClick Effect"
48
+ msgstr "Efekt po kliknięciu"
49
+
50
+ #: wp-gallery-custom-links.php:92
51
+ msgid "Remove"
52
+ msgstr "Usuń"
53
+
54
+ #: wp-gallery-custom-links.php:93
55
+ msgid "Keep"
56
+ msgstr "Utrzymaj"
57
+
58
+ #: wp-gallery-custom-links.php:95
59
+ msgid ""
60
+ "Lightbox and other OnClick events are removed by default from this image in "
61
+ "galleries. This setting will only be applied to this image in galleries if "
62
+ "this image has a Gallery Link URL specified."
63
+ msgstr "Domyślnie brak"
languages/wp-gallery-custom-links.pot ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: wp-gallery-custom-links\n"
4
+ "POT-Creation-Date: 2013-08-09 16:39+0100\n"
5
+ "PO-Revision-Date: 2013-08-09 16:39+0100\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: \n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "X-Generator: Poedit 1.5.7\n"
12
+ "X-Poedit-KeywordsList: _;gettext;gettext_noop;__\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "X-Poedit-SourceCharset: UTF-8\n"
15
+ "X-Poedit-SearchPath-0: .\n"
16
+
17
+ #: wp-gallery-custom-links.php:68
18
+ msgid "Gallery Link URL"
19
+ msgstr ""
20
+
21
+ #: wp-gallery-custom-links.php:71
22
+ msgid ""
23
+ "Will replace \"Image File\" or \"Attachment Page\" link for this image in "
24
+ "galleries. Use [none] to remove the link from this image in galleries."
25
+ msgstr ""
26
+
27
+ #: wp-gallery-custom-links.php:76
28
+ msgid "Gallery Link Target"
29
+ msgstr ""
30
+
31
+ #: wp-gallery-custom-links.php:80
32
+ msgid "Same Window"
33
+ msgstr ""
34
+
35
+ #: wp-gallery-custom-links.php:81
36
+ msgid "New Window"
37
+ msgstr ""
38
+
39
+ #: wp-gallery-custom-links.php:83
40
+ msgid ""
41
+ "This setting will be applied to this image in galleries regardless of "
42
+ "whether or not a Gallery Link URL has been specified."
43
+ msgstr ""
44
+
45
+ #: wp-gallery-custom-links.php:88
46
+ msgid "Gallery Link OnClick Effect"
47
+ msgstr ""
48
+
49
+ #: wp-gallery-custom-links.php:92
50
+ msgid "Remove"
51
+ msgstr ""
52
+
53
+ #: wp-gallery-custom-links.php:93
54
+ msgid "Keep"
55
+ msgstr ""
56
+
57
+ #: wp-gallery-custom-links.php:95
58
+ msgid ""
59
+ "Lightbox and other OnClick events are removed by default from this image in "
60
+ "galleries. This setting will only be applied to this image in galleries if "
61
+ "this image has a Gallery Link URL specified."
62
+ msgstr ""
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  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.6.0
7
- Stable tag: 1.8.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -17,7 +17,7 @@ Specify custom links for WordPress gallery images (instead of attachment or file
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).
@@ -61,7 +61,8 @@ Possibly. WP Gallery Custom Links plugin was designed for use with
61
  1) WordPress's [gallery] shortcode and 2) images uploaded through the
62
  WordPress media manager. Some themes use these features, and others
63
  have their own proprietary way of saving gallery images and drawing out the gallery.
64
- Provided your theme meets the criteria above, the plugin should work with it.
 
65
 
66
  = #2) Will this plugin work with NextGen galleries? =
67
 
@@ -76,77 +77,54 @@ The way the plugin works requires the gallery generation code to be run twice.
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
- = #4) I'm not using the [gallery] shortcode, but I'd still like to use the custom link in my own gallery code. How can I get the custom link? =
80
 
81
  The custom links are stored as meta values for images, and can be accessed with the following:
82
 
83
  `$custom_url = get_post_meta( $attachment_id, '_gallery_link_url', true );`
84
 
 
 
 
85
  = #5) I've set my gallery to remove Lightbox effects, but they are still coming up, possibly with nothing in them. Why? =
86
 
87
- There are many, many different themes and plugins that all have different
88
- ways of doing Lightboxes, Shadowboxes, etc. - your site may need
89
- some minor adjustments to how its javascripts are set up/ordered before it will be compatible.
90
-
91
- It's likely your Lightbox javascript is running after the WP Gallery Custom Links javascript.
92
- This may cause the Lightbox effect to be applied after the WP Gallery Custom Links
93
- script attempts to remove it.
94
-
95
- To fix this, first try checking your footer.php theme file and see if you find the
96
- Lightbox <script> tag(s) to relocate to inside the <head> tags of header.php. Since
97
- the WP Gallery Custom Links javascript is set to go into the footer, this will help ensure the
98
- other script runs first (and then WP Gallery Custom Links can turn off what it has turned on).
99
- You will also want to double-check that your Lightbox still works in the places it needs to.
100
-
101
- If the above script-moving solution doesn't look like an option, you can tell
102
- WP Gallery Custom Links which Lightbox script it needs to wait to load before it can load (i.e. declare
103
- a dependency). It gets a little programmy, but you can follow these steps to do this:
104
-
105
- * Google for "What's my ip?" to find your IP address
106
- * Drop the following code into your theme's functions.php file (this will be temporary), replacing 111.111.111.111 with your own IP address (to help ensure only you see its output):
107
- `if($_SERVER['REMOTE_ADDR'] == '111.111.111.111') {
108
- add_action('wp_footer', 'see_enqueued');
109
- }
110
- function see_enqueued( $handles = array() ) {
111
- global $wp_scripts;
112
-
113
- // scripts
114
- foreach ( $wp_scripts -> registered as $registered )
115
- $script_urls[ $registered -> handle ] = $registered -> src;
116
-
117
- // output of values
118
- $output = '';
119
- foreach ( $wp_scripts -> queue as $handle ) {
120
- if ( ! empty( $script_urls[ $handle ] ) )
121
- $output .= 'Handle: ' . $handle . ' - Script: ' . $script_urls[ $handle ] . '<br />';
122
- }
123
- echo $output;
124
- }`
125
- * Reload a page on your site and look near the bottom for the handle of your Lightbox script (I'll use "my-lightbox-js-handle" as an example), copy it, and remove the code from your functions.php file
126
- * Open up wp-gallery-custom-links.php in the WP Gallery Custom Links plugin folder and look for this line:
127
-
128
- `array( 'jquery' ),`
129
 
130
- * Add your Lightbox script(s) handle to this line, so it now looks like:
131
-
132
- `array( 'jquery', 'my-lightbox-js-handle' ),`
133
 
134
- * Note that any updates to the plugin you do from this point on will need to have this change maintained.
135
- * If you reload your gallery and view the page source, you should now see that the WP Gallery Custom Links javascript file comes after your Lightbox javascript file, and the Lightbox effect should now be removed from the gallery.
136
 
137
- = #6) When I enable the plugin, nothing in my gallery changes, even though I have custom links set. Why? =
138
 
139
- The first thing you probably want to check is that the hook that this plugin uses (the "post_gallery" filter) is being called.
140
  Some themes and gallery plugins have code that replaces the default WordPress gallery code, and the post_gallery
141
  filter gets left out, which means this plugin never gets called to do anything. If you do a "View Source" on your gallery page
142
  and see a javascript file named "wp-gallery-custom-links.js" being included, but items you know have custom links are not
143
  using the custom links, try looking around in your theme/gallery plugin to see if the gallery shortcode is
144
  being replaced, and if that function doesn't contain a reference to post_gallery, try adding this near the top of
145
- the function (assumes the attributes variable passed to the shortcode function is named $attr):
146
 
147
  `$output = apply_filters('post_gallery', '', $attr);
148
  if ( $output != '' )
149
  return $output;`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  == Screenshots ==
152
 
@@ -154,6 +132,17 @@ if ( $output != '' )
154
 
155
  == Changelog ==
156
 
 
 
 
 
 
 
 
 
 
 
 
157
  = 1.8.0 =
158
  * By popular demand, added a new filter on each link value: wpgcl_filter_raw_gallery_link_url
159
 
@@ -235,6 +224,17 @@ directly attached to the post.
235
 
236
  == Upgrade Notice ==
237
 
 
 
 
 
 
 
 
 
 
 
 
238
  = 1.8.0 =
239
  * By popular demand, added a new filter on each link value: wpgcl_filter_raw_gallery_link_url
240
 
2
  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.1
6
+ Tested up to: 3.8.0
7
+ Stable tag: 1.9.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
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 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).
61
  1) WordPress's [gallery] shortcode and 2) images uploaded through the
62
  WordPress media manager. Some themes use these features, and others
63
  have their own proprietary way of saving gallery images and drawing out the gallery.
64
+ Provided your theme meets the criteria above, the plugin should work with it. You
65
+ might also want to see #6 below.
66
 
67
  = #2) Will this plugin work with NextGen galleries? =
68
 
77
  may result in it being labeled as "#gallery-2" instead of "#gallery-1."
78
  Check your HTML and CSS for these changes and adjust accordingly.
79
 
80
+ = #4) I'd like to use the custom link in my own gallery code or in a different custom layout. How can I get the custom link? =
81
 
82
  The custom links are stored as meta values for images, and can be accessed with the following:
83
 
84
  `$custom_url = get_post_meta( $attachment_id, '_gallery_link_url', true );`
85
 
86
+ Please note that "$attachment_id" is a variable for the post ID of the image - you will need to have already defined and set this variable
87
+ in your own code and use your variable in this spot. "$attachment_id" is just an example of what it could be named.
88
+
89
  = #5) I've set my gallery to remove Lightbox effects, but they are still coming up, possibly with nothing in them. Why? =
90
 
91
+ Version 1.9 (hopefully) resolves most of these issues, but if you're still having this problem,
92
+ see #5 in the old version's readme file here: http://plugins.svn.wordpress.org/wp-gallery-custom-links/tags/1.8.0/readme.txt.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
+ = #6) When I enable the plugin, nothing in my gallery changes, even though I have custom links set. Why? =
 
 
95
 
96
+ Thing to try #1: make sure your gallery is set to use either attachment or file links. If the gallery is set to link to "none" there
97
+ will be no links to match on, thus this plugin won't be able to swap in custom values.
98
 
99
+ Thing to try #2: make sure you have the onclick effect set to "remove" if you continue to have undesired lightbox/carousel popups.
100
 
101
+ Thing to try #3: make sure the hook that this plugin uses (the "post_gallery" filter) is being called.
102
  Some themes and gallery plugins have code that replaces the default WordPress gallery code, and the post_gallery
103
  filter gets left out, which means this plugin never gets called to do anything. If you do a "View Source" on your gallery page
104
  and see a javascript file named "wp-gallery-custom-links.js" being included, but items you know have custom links are not
105
  using the custom links, try looking around in your theme/gallery plugin to see if the gallery shortcode is
106
  being replaced, and if that function doesn't contain a reference to post_gallery, try adding this near the top of
107
+ the function (assumes the attributes variable passed to the shortcode function is named "$attr"):
108
 
109
  `$output = apply_filters('post_gallery', '', $attr);
110
  if ( $output != '' )
111
  return $output;`
112
+
113
+ You may want to see http://wordpress.org/support/topic/wont-work-syntax-error for an example of adding this code.
114
+
115
+ This thing to try is a bit on the programmy side, so if you're having trouble, my suggestion would be to contact your theme author
116
+ and ask that they support the "post_gallery" filter in their gallery shortcode function. This would not only fix it for your theme most thoroughly,
117
+ but would also fix it for any future users also using that same theme. Otherwise, any WordPress developer should be able to help you
118
+ with the code changes to customize your theme to support the post_gallery filter like WordPress core (not something I consider in the realm of free support, sorry).
119
+
120
+ = #7) The custom links are working fine, but I need help changing the formatting/styling on my gallery, such as spacing between images, aligning images, or changing image size. =
121
+
122
+ This plugin just changes links, plus a bit of auxiliary functionality to help with changing the links. It
123
+ doesn't alter layout or styling - that's something you'd need to change in your theme or whatever
124
+ plugin you may be using to display the gallery. Note: if you're using [none] to remove links from gallery
125
+ images, it may affect the styling, depending on whether your stylesheet is expecting all gallery images
126
+ to have `<a>` tags around them, in which case you would need to modify your stylesheet to also apply
127
+ the same styles to `<img>` tags without a link around them.
128
 
129
  == Screenshots ==
130
 
132
 
133
  == Changelog ==
134
 
135
+ = 1.9.0 =
136
+ * By popular demand, moved the help notes under each field into tooltips so the form won't be so tall.
137
+ * The javascript that attempts to disable lightboxes now runs in window.onload in addition to document.ready.
138
+ Hopefully this will cut down on some of the issues where lightboxes keep popping up without having to mess
139
+ with javascript dependencies at the code level. Any other window.onload function should be preserved.
140
+ * Added a javascript function detect for jQuery's off() function, since it only came into existence in 1.7.
141
+ If off() isn't defined, unbind() is called instead.
142
+ * Resolved an issue where making an image have no link occasionally resulted in all previous images in the gallery
143
+ disappearing from the display.
144
+ * Added a translation for Polish, courtesy of Przemyslaw Trawicki (thanks!)
145
+
146
  = 1.8.0 =
147
  * By popular demand, added a new filter on each link value: wpgcl_filter_raw_gallery_link_url
148
 
224
 
225
  == Upgrade Notice ==
226
 
227
+ = 1.9.0 =
228
+ * By popular demand, moved the help notes under each field into tooltips so the form won't be so tall.
229
+ * The javascript that attempts to disable lightboxes now runs in window.onload in addition to document.ready.
230
+ Hopefully this will cut down on some of the issues where lightboxes keep popping up without having to mess
231
+ with javascript dependencies at the code level. Any other window.onload function should be preserved.
232
+ * Added a javascript function detect for jQuery's off() function, since it only came into existence in 1.7.
233
+ If off() isn't defined, unbind() is called instead.
234
+ * Resolved an issue where making an image have no link occasionally resulted in all previous images in the gallery
235
+ disappearing from the display.
236
+ * Added a translation for Polish, courtesy of Przemyslaw Trawicki (thanks!)
237
+
238
  = 1.8.0 =
239
  * By popular demand, added a new filter on each link value: wpgcl_filter_raw_gallery_link_url
240
 
wp-gallery-custom-links.js CHANGED
@@ -1,11 +1,45 @@
1
  jQuery(document).ready(function () {
2
- jQuery('a.no-lightbox').unbind('click');
3
- jQuery('a.no-lightbox').off('click');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  jQuery('a.no-lightbox').click(wp_gallery_custom_links_click);
5
- jQuery('a.set-target').unbind('click');
6
- jQuery('a.set-target').off('click');
 
 
 
 
 
 
7
  jQuery('a.set-target').click(wp_gallery_custom_links_click);
8
- });
 
9
  function wp_gallery_custom_links_click() {
10
  if(!this.target || this.target == '' || this.target == '_self')
11
  window.location = this.href;
1
  jQuery(document).ready(function () {
2
+ // Unbind on document ready so it will still at least try
3
+ // to be functional while the page may still be loading
4
+ wp_gallery_custom_links_setup();
5
+
6
+ // Do unbinding, etc. again in window.onload to help reduce
7
+ // the number of conflicting lightboxes etc. without
8
+ // making the user have to declare js dependencies
9
+ function addLoadEvent(func) {
10
+ var oldOnload = window.onload;
11
+ if(typeof window.onload != 'function') {
12
+ window.onload = func;
13
+ } else {
14
+ window.onload = function() {
15
+ oldOnload();
16
+ func();
17
+ }
18
+ }
19
+ }
20
+ addLoadEvent(wp_gallery_custom_links_setup);
21
+ });
22
+
23
+ function wp_gallery_custom_links_setup() {
24
+ if(jQuery.fn.off) {
25
+ // jQuery 1.7+
26
+ jQuery('.no-lightbox, .no-lightbox img').off('click');
27
+ } else {
28
+ // < jQuery 1.7
29
+ jQuery('.no-lightbox, .no-lightbox img').unbind('click');
30
+ }
31
  jQuery('a.no-lightbox').click(wp_gallery_custom_links_click);
32
+
33
+ if(jQuery.fn.off) {
34
+ // jQuery 1.7+
35
+ jQuery('a.set-target').off('click');
36
+ } else {
37
+ // < jQuery 1.7
38
+ jQuery('a.set-target').unbind('click');
39
+ }
40
  jQuery('a.set-target').click(wp_gallery_custom_links_click);
41
+ }
42
+
43
  function wp_gallery_custom_links_click() {
44
  if(!this.target || this.target == '' || this.target == '_self')
45
  window.location = this.href;
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.8.0
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
@@ -41,58 +41,77 @@ class WPGalleryCustomLinks {
41
  // return same content passed in to this second recursive call
42
  // return "filter" $output with replaced links to original $GLOBALS['shortcode_tags']['gallery'] call
43
  private static $first_call = true;
 
 
44
 
45
  public static function init() {
46
  // Add the filter for editing the custom url field
47
- add_filter( 'attachment_fields_to_edit', array( 'WPGalleryCustomLinks', 'apply_filter_attachment_fields_to_edit' ), null, 2 );
48
 
49
  // Add the filter for saving the custom url field
50
- add_filter( 'attachment_fields_to_save', array( 'WPGalleryCustomLinks', 'apply_filter_attachment_fields_to_save' ), null , 2 );
51
 
52
  // Add the filter for when the post_gallery is written out
53
- add_filter( 'post_gallery', array( 'WPGalleryCustomLinks', 'apply_filter_post_gallery' ), 999, 2 );
54
 
55
  // Require the javascript to disable lightbox
56
  wp_enqueue_script(
57
  'wp-gallery-custom-links-js',
58
  plugins_url( '/wp-gallery-custom-links.js', __FILE__ ),
59
  array( 'jquery' ),
60
- '1.0',
61
  true
62
  );
 
 
 
63
  } // End function init()
64
 
65
  public static function apply_filter_attachment_fields_to_edit( $form_fields, $post ) {
 
 
66
  // Gallery Link URL field
67
  $form_fields['gallery_link_url'] = array(
68
- 'label' => __( 'Gallery Link URL' ),
 
 
 
 
 
69
  'input' => 'text',
70
- 'value' => get_post_meta( $post->ID, '_gallery_link_url', true ),
71
- 'helps' => 'Will replace "Image File" or "Attachment Page" link for this image in galleries. Use [none] to remove the link from this image in galleries.'
72
  );
73
  // Gallery Link Target field
74
  $target_value = get_post_meta( $post->ID, '_gallery_link_target', true );
75
  $form_fields['gallery_link_target'] = array(
76
- 'label' => __( 'Gallery Link Target' ),
 
 
 
 
 
77
  'input' => 'html',
78
  'html' => '
79
  <select name="attachments['.$post->ID.'][gallery_link_target]" id="attachments['.$post->ID.'][gallery_link_target]">
80
- <option value="">Same Window</option>
81
- <option value="_blank"'.($target_value == '_blank' ? ' selected="selected"' : '').'>New Window</option>
82
- </select>',
83
- 'helps' => 'This setting will be applied to this image in galleries regardless of whether or not a Gallery Link URL has been specified.'
84
  );
85
  // Gallery Link OnClick Effect field
86
  $preserve_click_value = get_post_meta( $post->ID, '_gallery_link_preserve_click', true );
87
  $form_fields['gallery_link_preserve_click'] = array(
88
- 'label' => __( 'Gallery Link OnClick Effect' ),
 
 
 
 
 
89
  'input' => 'html',
90
  'html' => '
91
  <select name="attachments['.$post->ID.'][gallery_link_preserve_click]" id="attachments['.$post->ID.'][gallery_link_preserve_click]">
92
- <option value="remove">Remove</option>
93
- <option value="preserve"'.($preserve_click_value == 'preserve' ? ' selected="selected"' : '').'>Keep</option>
94
- </select>',
95
- 'helps' => 'Lightbox and other OnClick events are removed by default from this image in galleries. This setting will only be applied to this image in galleries if this image has a Gallery Link URL specified.'
96
  );
97
  return $form_fields;
98
  } // End function apply_filter_attachment_fields_to_edit()
@@ -295,26 +314,37 @@ class WPGalleryCustomLinks {
295
  // Remove Link
296
  if( $remove_link ) {
297
  // Break the output up into two parts: everything before this href
298
- // and everything after
299
- $output_parts = explode( $default_link, $output );
 
 
 
 
300
  if( count( $output_parts ) == 2 ) {
301
  $output_part_1 = $output_parts[0];
302
  $output_part_2 = $output_parts[1];
303
 
304
- // Take out the <a> from the end of part 1
305
- $output_part_1 = preg_replace( '/<\s*a\s+.*$/', '', $output_part_1 );
 
 
 
 
306
 
307
  // And then take out everything up through the first > that comes after that
308
  // (which would be the closing angle bracket of <a>)
309
  $pos = strpos( $output_part_2, '>' );
310
  if( $pos !== false ) {
311
  $output_part_2 = substr( $output_part_2, $pos+1 );
 
 
312
  }
313
 
314
  // And then take out the first </a> that comes after that
315
  $pos = strpos( $output_part_2, '</a>' );
316
  if( $pos !== false ) {
317
- $output_part_2 = substr( $output_part_2, 0, $pos ) . substr( $output_part_2, $pos+4 );
 
318
  }
319
 
320
  // And then stitch them back together again, without the link parts
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.9.0
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
41
  // return same content passed in to this second recursive call
42
  // return "filter" $output with replaced links to original $GLOBALS['shortcode_tags']['gallery'] call
43
  private static $first_call = true;
44
+ private static $textdomain_id = 'wp-gallery-custom-links';
45
+ private static $class_name = 'WPGalleryCustomLinks';
46
 
47
  public static function init() {
48
  // Add the filter for editing the custom url field
49
+ add_filter( 'attachment_fields_to_edit', array( self::$class_name, 'apply_filter_attachment_fields_to_edit' ), null, 2 );
50
 
51
  // Add the filter for saving the custom url field
52
+ add_filter( 'attachment_fields_to_save', array( self::$class_name, 'apply_filter_attachment_fields_to_save' ), null , 2 );
53
 
54
  // Add the filter for when the post_gallery is written out
55
+ add_filter( 'post_gallery', array( self::$class_name, 'apply_filter_post_gallery' ), 999, 2 );
56
 
57
  // Require the javascript to disable lightbox
58
  wp_enqueue_script(
59
  'wp-gallery-custom-links-js',
60
  plugins_url( '/wp-gallery-custom-links.js', __FILE__ ),
61
  array( 'jquery' ),
62
+ '1.1',
63
  true
64
  );
65
+
66
+ // Load translations
67
+ load_plugin_textdomain( self::$textdomain_id, false, basename( dirname( __FILE__ ) ) . '/languages' );
68
  } // End function init()
69
 
70
  public static function apply_filter_attachment_fields_to_edit( $form_fields, $post ) {
71
+ $help_css = 'display:none;position:absolute;background-color:#ffffe0;text-align:left;border:1px solid #dfdfdf;padding:10px;width:75%;font-weight:normal;border-radius:3px;';
72
+
73
  // Gallery Link URL field
74
  $form_fields['gallery_link_url'] = array(
75
+ 'label' => __( 'Gallery Link URL', self::$textdomain_id ) .
76
+ ' <a href="#" onclick="jQuery(\'#wpgcl_gallery_link_url_help\').show(); return false;" onblur="jQuery(\'#wpgcl_gallery_link_url_help\').hide();">[?]</a>' .
77
+ '<div id="wpgcl_gallery_link_url_help" style="'.$help_css.'">' .
78
+ __( 'Will replace "Image File" or "Attachment Page" link for this image in galleries. Use [none] to remove the link from this image in galleries.', self::$textdomain_id ) .
79
+ ' <a href="#" onclick="jQuery(\'#wpgcl_gallery_link_url_help\').hide(); return false;">[X]</a>' .
80
+ '</div>',
81
  'input' => 'text',
82
+ 'value' => get_post_meta( $post->ID, '_gallery_link_url', true )
 
83
  );
84
  // Gallery Link Target field
85
  $target_value = get_post_meta( $post->ID, '_gallery_link_target', true );
86
  $form_fields['gallery_link_target'] = array(
87
+ 'label' => __( 'Gallery Link Target', self::$textdomain_id ) .
88
+ ' <a href="#" onclick="jQuery(\'#wpgcl_gallery_link_target_help\').show(); return false;" onblur="jQuery(\'#wpgcl_gallery_link_target_help\').hide();">[?]</a>' .
89
+ '<div id="wpgcl_gallery_link_target_help" style="'.$help_css.'">' .
90
+ __( 'This setting will be applied to this image in galleries regardless of whether or not a Gallery Link URL has been specified.', self::$textdomain_id ) .
91
+ ' <a href="#" onclick="jQuery(\'#wpgcl_gallery_link_target_help\').hide(); return false;">[X]</a>' .
92
+ '</div>',
93
  'input' => 'html',
94
  'html' => '
95
  <select name="attachments['.$post->ID.'][gallery_link_target]" id="attachments['.$post->ID.'][gallery_link_target]">
96
+ <option value="">'.__( 'Same Window', self::$textdomain_id ).'</option>
97
+ <option value="_blank"'.($target_value == '_blank' ? ' selected="selected"' : '').'>'.__( 'New Window', self::$textdomain_id ).'</option>
98
+ </select>'
 
99
  );
100
  // Gallery Link OnClick Effect field
101
  $preserve_click_value = get_post_meta( $post->ID, '_gallery_link_preserve_click', true );
102
  $form_fields['gallery_link_preserve_click'] = array(
103
+ 'label' => __( 'Gallery Link OnClick Effect', self::$textdomain_id ) .
104
+ ' <a href="#" onclick="jQuery(\'#wpgcl_gallery_link_preserve_click_help\').show(); return false;" onblur="jQuery(\'#wpgcl_gallery_link_preserve_click_help\').hide();">[?]</a>' .
105
+ '<div id="wpgcl_gallery_link_preserve_click_help" style="'.$help_css.'">' .
106
+ __( 'Lightbox and other OnClick events are removed by default from this image in galleries. This setting will only be applied to this image in galleries if this image has a Gallery Link URL specified.', self::$textdomain_id ) .
107
+ ' <a href="#" onclick="jQuery(\'#wpgcl_gallery_link_preserve_click_help\').hide(); return false;">[X]</a>' .
108
+ '</div>',
109
  'input' => 'html',
110
  'html' => '
111
  <select name="attachments['.$post->ID.'][gallery_link_preserve_click]" id="attachments['.$post->ID.'][gallery_link_preserve_click]">
112
+ <option value="remove">'.__( 'Remove', self::$textdomain_id ).'</option>
113
+ <option value="preserve"'.($preserve_click_value == 'preserve' ? ' selected="selected"' : '').'>'.__( 'Keep', self::$textdomain_id ).'</option>
114
+ </select>'
 
115
  );
116
  return $form_fields;
117
  } // End function apply_filter_attachment_fields_to_edit()
314
  // Remove Link
315
  if( $remove_link ) {
316
  // Break the output up into two parts: everything before this href
317
+ // and everything after. Note: sometimes the image url will
318
+ // appear multiple times in the source (e.g. "data-orig-file" in
319
+ // jetpack), so use the regex needle to find the href first, then break
320
+ // up the link.
321
+ $output_parts = preg_replace( $needle, '^^^HREF^^^', $output );
322
+ $output_parts = explode( '^^^HREF^^^', $output_parts );
323
  if( count( $output_parts ) == 2 ) {
324
  $output_part_1 = $output_parts[0];
325
  $output_part_2 = $output_parts[1];
326
 
327
+ // Take out the <a> from the end of part 1, from its
328
+ // opening angle bracket
329
+ $pos = strrpos( $output_part_1, '<' );
330
+ if( $pos !== false ) {
331
+ $output_part_1 = substr( $output_part_1, 0, $pos );
332
+ }
333
 
334
  // And then take out everything up through the first > that comes after that
335
  // (which would be the closing angle bracket of <a>)
336
  $pos = strpos( $output_part_2, '>' );
337
  if( $pos !== false ) {
338
  $output_part_2 = substr( $output_part_2, $pos+1 );
339
+ // Add in a span where the link used to be, just in case
340
+ $output_part_2 = '<span class="no-link'. ( $preserve_click != 'preserve' ? ' no-lightbox' : '' ) . '">' . $output_part_2;
341
  }
342
 
343
  // And then take out the first </a> that comes after that
344
  $pos = strpos( $output_part_2, '</a>' );
345
  if( $pos !== false ) {
346
+ // Also close out the span where the link used to be
347
+ $output_part_2 = substr( $output_part_2, 0, $pos ) . '</span>' . substr( $output_part_2, $pos+4 );
348
  }
349
 
350
  // And then stitch them back together again, without the link parts