WP Gallery Custom Links - Version 1.3.0

Version Description

  • Added support for the "ignore_gallery_link_urls" gallery shortcode attribute to ignore custom links on a gallery and use the normal file/attachment setting.
  • Added support for IDs in the "include" gallery shortcode attribute that aren't directly attached to the post.
Download this release

Release Info

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

Code changes from version 1.2.2 to 1.3.0

Files changed (2) hide show
  1. readme.txt +19 -3
  2. wp-gallery-custom-links.php +17 -7
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.4.1
7
- Stable tag: 1.2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -18,7 +18,11 @@ to link them to other pages but couldn't, this plugin is for you!
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 is also an option
21
- to open gallery images in a new window.
 
 
 
 
22
 
23
  It's designed to work even if customizations have been made via the
24
  post_gallery filter; instead of replacing the entire post_gallery function, it
@@ -55,6 +59,12 @@ that function outside of the WordPress [gallery] shortcode.
55
 
56
  == Changelog ==
57
 
 
 
 
 
 
 
58
  = 1.2.2 =
59
  * Moved javascript to a separate file so jquery could be required as a dependency.
60
 
@@ -95,6 +105,12 @@ that function outside of the WordPress [gallery] shortcode.
95
 
96
  == Upgrade Notice ==
97
 
 
 
 
 
 
 
98
  = 1.2.2 =
99
  * Moved javascript to a separate file so jquery could be required as a dependency.
100
 
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.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
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 is also an option
21
+ to open gallery images in a new window. If you want to use the same images in a
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
  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
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.
65
+ * Added support for IDs in the "include" gallery shortcode attribute that aren't
66
+ directly attached to the post.
67
+
68
  = 1.2.2 =
69
  * Moved javascript to a separate file so jquery could be required as a dependency.
70
 
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.
111
+ * Added support for IDs in the "include" gallery shortcode attribute that aren't
112
+ directly attached to the post.
113
+
114
  = 1.2.2 =
115
  * Moved javascript to a separate file so jquery could be required as a dependency.
116
 
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.2.2
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
@@ -94,9 +94,6 @@ class WPGalleryCustomLinks {
94
  public static function apply_filter_post_gallery( $output, $attr ) {
95
  global $post;
96
 
97
- // Get the shortcode attributes
98
- extract( shortcode_atts( array(), $attr ) );
99
-
100
  // Determine what our postID for attachments is - either
101
  // from our shortcode attr or from $post->ID. If we don't
102
  // have one from either of those places...something weird
@@ -109,7 +106,12 @@ class WPGalleryCustomLinks {
109
  return ' ';
110
  }
111
 
112
- if( self::$first_call ) {
 
 
 
 
 
113
  // Our first run, so the gallery function thinks it's being
114
  // overwritten. Set the variable to prevent actual endless
115
  // overwriting later.
@@ -134,11 +136,19 @@ class WPGalleryCustomLinks {
134
  // default, theme-specified or whatever
135
  $output = call_user_func( $gallery_shortcode_function, $attr );
136
 
137
- // Get the attachments for this post
138
  $attachments = get_children( array( 'post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
139
- foreach ( $attachments as $attachment_id => $attachment ) {
 
 
 
 
 
 
 
140
  $link = '';
141
  $target = '';
 
142
 
143
  // See if we have a custom url for this attachment image
144
  $attachment_meta = get_post_meta( $attachment_id, '_gallery_link_url', 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.3.0
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
94
  public static function apply_filter_post_gallery( $output, $attr ) {
95
  global $post;
96
 
 
 
 
97
  // Determine what our postID for attachments is - either
98
  // from our shortcode attr or from $post->ID. If we don't
99
  // have one from either of those places...something weird
106
  return ' ';
107
  }
108
 
109
+ if( isset( $attr['ignore_gallery_link_urls'] ) && trim( $attr['ignore_gallery_link_urls'] ) === 'true' ) {
110
+ // If the user has passed in a parameter to ignore the custom link
111
+ // URLs for this gallery, just skip over this whole plugin and
112
+ // return what was passed in
113
+ return $output;
114
+ } else if( self::$first_call ) {
115
  // Our first run, so the gallery function thinks it's being
116
  // overwritten. Set the variable to prevent actual endless
117
  // overwriting later.
136
  // default, theme-specified or whatever
137
  $output = call_user_func( $gallery_shortcode_function, $attr );
138
 
139
+ // Get the attachment ids for this post, as well as any "include"d attachments
140
  $attachments = get_children( array( 'post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
141
+ $attachment_ids = array();
142
+ if( count( $attachments ) > 0 ) {
143
+ $attachment_ids = array_merge( $attachment_ids, array_keys( $attachments ) );
144
+ }
145
+ if( isset( $attr['include'] ) ) {
146
+ $attachment_ids = array_merge( $attachment_ids, explode( ',', $attr['include'] ) );
147
+ }
148
+ foreach ( $attachment_ids as $attachment_id ) {
149
  $link = '';
150
  $target = '';
151
+ $attachment_id = intval( $attachment_id );
152
 
153
  // See if we have a custom url for this attachment image
154
  $attachment_meta = get_post_meta( $attachment_id, '_gallery_link_url', true );