WP Gallery Custom Links - Version 1.8.0

Version Description

  • By popular demand, added a new filter on each link value: wpgcl_filter_raw_gallery_link_url
Download this release

Release Info

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

Code changes from version 1.7.1 to 1.8.0

Files changed (2) hide show
  1. readme.txt +101 -24
  2. wp-gallery-custom-links.php +16 -6
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.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
 
@@ -35,10 +35,18 @@ will be removed to allow them to function as regular links.
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 open_all_in_new_window="true"] and [gallery open_all_in_same_window="true"] to open all images in an entire gallery in a new window/the same window, respectively.
40
- * Use [gallery preserve_click_events="true"] to keep Lightbox or other onClick events on all custom-linked images in an entire gallery.
41
- * Use [gallery remove_links="true"] to remove links on all images in an entire gallery.
 
 
 
 
 
 
 
 
42
 
43
  == Installation ==
44
 
@@ -47,42 +55,108 @@ will be removed to allow them to function as regular links.
47
 
48
  == Frequently Asked Questions ==
49
 
50
- = Will this plugin work with my theme's galleries? =
51
 
52
  Possibly. WP Gallery Custom Links plugin was designed for use with
53
- 1) WordPress's [gallery] shortcode and 2) images
54
- attached to the post/page. Some themes use these features, and others
55
  have their own proprietary way of saving gallery images and drawing out the gallery.
56
- Provided your theme meets the criteria above, the plugin *should* work with it.
57
 
58
- = Will this plugin work with NextGen galleries? =
59
 
60
- No, this plugin is *not* compatible with NextGen galleries. WP Gallery Custom Links was
61
- designed for use with 1) WordPress's [gallery] shortcode and 2) images
62
- attached to the post/page. NextGen galleries uses its own [nggallery] etc. shortcodes
63
  that function outside of the WordPress [gallery] shortcode.
64
 
65
- = I've set my gallery to remove Lightbox effects, but they are still coming up. Why? =
66
-
67
- Your Lightbox javascript may be running after the WP Gallery Custom Links javascript.
68
- This may cause the Lightbox effect to be applied after the WP Gallery Custom Links
69
- script attempts to remove it. Try moving your Lightbox javascript above the
70
- WP Gallery Custom Links javascript. Note that you may need to add your Lightbox
71
- script as a dependency for WP Gallery Custom Links to make sure WP Gallery Custom Links
72
- runs after it.
73
-
74
- = When I enable the plugin, the styling on my gallery changes. Why? =
75
 
76
  The way the plugin works requires the gallery generation code to be run twice. This
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
  == Screenshots ==
81
 
82
  1. The additional WP Gallery Custom Link fields.
83
 
84
  == Changelog ==
85
 
 
 
 
86
  = 1.7.1 =
87
  * A few performance increases
88
 
@@ -161,6 +235,9 @@ directly attached to the post.
161
 
162
  == Upgrade Notice ==
163
 
 
 
 
164
  = 1.7.1 =
165
  * A few performance increases
166
 
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
 
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 open_all_in_new_window="true"]` and `[gallery open_all_in_same_window="true"]` to open all images in an entire gallery in a new window/the same window, respectively.
40
+ * Use `[gallery preserve_click_events="true"]` to keep Lightbox or other onClick events on all custom-linked images in an entire gallery.
41
+ * Use `[gallery remove_links="true"]` to remove links on all images in an entire gallery.
42
+
43
+ = Hooks =
44
+
45
+ * Use "wpgcl_filter_raw_gallery_link_url" to filter the custom gallery link URLs as they come out of the database. Note that this may
46
+ include the value "[none]" if it has been entered to remove the link later on. Example:
47
+
48
+ `add_filter( 'wpgcl_filter_raw_gallery_link_url', 'my_gallery_link_url_filter', 10, 3 );
49
+ function my_gallery_link_url_filter( $link, $attachment_id, $post_id ) { return '/en/' . $link; }`
50
 
51
  == Installation ==
52
 
55
 
56
  == Frequently Asked Questions ==
57
 
58
+ = #1) Will this plugin work with my theme's galleries? =
59
 
60
  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
 
68
+ No, this plugin is not compatible with NextGen galleries. WP Gallery Custom Links was
69
+ designed for use with 1) WordPress's [gallery] shortcode and 2) images uploaded through the
70
+ WordPress media manager. NextGen galleries uses its own [nggallery] etc. shortcodes
71
  that function outside of the WordPress [gallery] shortcode.
72
 
73
+ = #3) 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
+ = #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
 
153
  1. The additional WP Gallery Custom Link fields.
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
+
160
  = 1.7.1 =
161
  * A few performance increases
162
 
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
+
241
  = 1.7.1 =
242
  * A few performance increases
243
 
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.1
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
@@ -34,19 +34,20 @@ class WPGalleryCustomLinks {
34
  // [gallery] ->
35
  // $GLOBALS['shortcode_tags']['gallery'] ->
36
  // apply_filter('post_gallery') *
37
- // apply_filter('post_gallery') (first call) ->
38
  // $GLOBALS['shortcode_tags']['gallery'] ->
39
  // apply_filter('post_gallery') *
40
  // apply_filter('post_gallery') (second call, simply returns output passed in)
41
- // return "filter" $output to original $GLOBALS['shortcode_tags']['gallery'] call
 
42
  private static $first_call = true;
43
 
44
  public static function init() {
45
  // Add the filter for editing the custom url field
46
- add_filter( 'attachment_fields_to_edit', array( 'WPGalleryCustomLinks', 'apply_filter_attachment_fields_to_edit' ), null, 2);
47
 
48
  // Add the filter for saving the custom url field
49
- add_filter( 'attachment_fields_to_save', array( 'WPGalleryCustomLinks', 'apply_filter_attachment_fields_to_save' ), null , 2);
50
 
51
  // Add the filter for when the post_gallery is written out
52
  add_filter( 'post_gallery', array( 'WPGalleryCustomLinks', 'apply_filter_post_gallery' ), 999, 2 );
@@ -62,12 +63,14 @@ class WPGalleryCustomLinks {
62
  } // End function init()
63
 
64
  public static function apply_filter_attachment_fields_to_edit( $form_fields, $post ) {
 
65
  $form_fields['gallery_link_url'] = array(
66
  'label' => __( 'Gallery Link URL' ),
67
  'input' => 'text',
68
  'value' => get_post_meta( $post->ID, '_gallery_link_url', true ),
69
  '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.'
70
  );
 
71
  $target_value = get_post_meta( $post->ID, '_gallery_link_target', true );
72
  $form_fields['gallery_link_target'] = array(
73
  'label' => __( 'Gallery Link Target' ),
@@ -79,6 +82,7 @@ class WPGalleryCustomLinks {
79
  </select>',
80
  'helps' => 'This setting will be applied to this image in galleries regardless of whether or not a Gallery Link URL has been specified.'
81
  );
 
82
  $preserve_click_value = get_post_meta( $post->ID, '_gallery_link_preserve_click', true );
83
  $form_fields['gallery_link_preserve_click'] = array(
84
  'label' => __( 'Gallery Link OnClick Effect' ),
@@ -94,6 +98,7 @@ class WPGalleryCustomLinks {
94
  } // End function apply_filter_attachment_fields_to_edit()
95
 
96
  public static function apply_filter_attachment_fields_to_save( $post, $attachment ) {
 
97
  if( isset( $attachment['gallery_link_url'] ) ) {
98
  update_post_meta( $post['ID'], '_gallery_link_url', $attachment['gallery_link_url'] );
99
  }
@@ -157,12 +162,13 @@ class WPGalleryCustomLinks {
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
  }
@@ -181,6 +187,10 @@ class WPGalleryCustomLinks {
181
  $attachment_meta = get_post_meta( $attachment_id, '_gallery_link_url', true );
182
  if( $attachment_meta ) {
183
  $link = $attachment_meta;
 
 
 
 
184
  }
185
  // See if we have a target for this attachment image
186
  $attachment_meta = get_post_meta( $attachment_id, '_gallery_link_target', true );
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
34
  // [gallery] ->
35
  // $GLOBALS['shortcode_tags']['gallery'] ->
36
  // apply_filter('post_gallery') *
37
+ // apply_filter('post_gallery') (first call, will include second recursive call, and then does actual link replacing) ->
38
  // $GLOBALS['shortcode_tags']['gallery'] ->
39
  // apply_filter('post_gallery') *
40
  // apply_filter('post_gallery') (second call, simply returns output passed in)
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 );
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' ),
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' ),
98
  } // End function apply_filter_attachment_fields_to_edit()
99
 
100
  public static function apply_filter_attachment_fields_to_save( $post, $attachment ) {
101
+ // Save our custom meta fields
102
  if( isset( $attachment['gallery_link_url'] ) ) {
103
  update_post_meta( $post['ID'], '_gallery_link_url', $attachment['gallery_link_url'] );
104
  }
162
  $attachment_ids = array_merge( $attachment_ids, explode( ',', $attr['ids'] ) );
163
  } else {
164
  // < WP 3.5:
165
+ // Get the attachment ids for this post
166
  $attachments = get_children( array( 'post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
167
  if( count( $attachments ) > 0 ) {
168
  $attachment_ids = array_merge( $attachment_ids, array_keys( $attachments ) );
169
  }
170
  } // End if it's the "ids" attribute way of specifying images or not
171
+ // Add in any "include"d attachmentIDs
172
  if( isset( $attr['include'] ) ) {
173
  $attachment_ids = array_merge( $attachment_ids, explode( ',', $attr['include'] ) );
174
  }
187
  $attachment_meta = get_post_meta( $attachment_id, '_gallery_link_url', true );
188
  if( $attachment_meta ) {
189
  $link = $attachment_meta;
190
+
191
+ // Apply filters to the custom link (e.g. the case of prefixing internal
192
+ // links with /en/ or /fr/ etc. for languages on the fly)
193
+ $link = apply_filters( 'wpgcl_filter_raw_gallery_link_url', $link, $attachment_id, $post_id );
194
  }
195
  // See if we have a target for this attachment image
196
  $attachment_meta = get_post_meta( $attachment_id, '_gallery_link_target', true );