WP Gallery Custom Links - Version 1.0.4

Version Description

  • The "id" attribute of the gallery shortcode is now supported
Download this release

Release Info

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

Code changes from version 1.0.3 to 1.0.4

Files changed (2) hide show
  1. readme.txt +7 -1
  2. wp-gallery-custom-links.php +18 -11
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.3.2
7
- Stable tag: 1.0.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -38,6 +38,9 @@ As soon as someone asks me something. :)
38
 
39
  == Changelog ==
40
 
 
 
 
41
  = 1.0.3 =
42
  * Added a check to return a simple space in the event $post is undefined
43
 
@@ -52,6 +55,9 @@ As soon as someone asks me something. :)
52
 
53
  == Upgrade Notice ==
54
 
 
 
 
55
  = 1.0.3 =
56
  * Added a check to return a simple space in the event $post is undefined
57
 
4
  Tags: gallery links, gallery link, gallery
5
  Requires at least: 3.3.2
6
  Tested up to: 3.3.2
7
+ Stable tag: 1.0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
38
 
39
  == Changelog ==
40
 
41
+ = 1.0.4 =
42
+ * The "id" attribute of the gallery shortcode is now supported
43
+
44
  = 1.0.3 =
45
  * Added a check to return a simple space in the event $post is undefined
46
 
55
 
56
  == Upgrade Notice ==
57
 
58
+ = 1.0.4 =
59
+ * The "id" attribute of the gallery shortcode is now supported
60
+
61
  = 1.0.3 =
62
  * Added a check to return a simple space in the event $post is undefined
63
 
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.0.3
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
@@ -72,10 +72,6 @@ class WPGalleryCustomLinks {
72
  public static function apply_filter_post_gallery( $output, $attr ) {
73
  global $post;
74
 
75
- // Apparently there's weird cases where $post may not be set?
76
- // Adding this check just in case...
77
- if ( ! $post ) return ' ';
78
-
79
  if( self::$first_call ) {
80
  // Our first run, so the gallery function thinks it's being
81
  // overwritten. Set the variable to prevent actual endless
@@ -91,6 +87,21 @@ class WPGalleryCustomLinks {
91
  self::$first_call = true;
92
  return $output;
93
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  // Get the normal gallery shortcode function
96
  if ( isset( $GLOBALS['shortcode_tags'] ) && isset( $GLOBALS['shortcode_tags']['gallery'] ) ) {
@@ -99,13 +110,9 @@ class WPGalleryCustomLinks {
99
 
100
  // Run whatever gallery shortcode function has been set up,
101
  // default, theme-specified or whatever
102
- $output = call_user_func( $gallery_shortcode_function, $attr );
103
-
104
- // Get the shortcode attributes - really we just need "link"
105
- extract( shortcode_atts( array(), $attr ) );
106
 
107
  // Get the attachments for this post
108
- $post_id = intval( $post->ID );
109
  $attachments = get_children( array( 'post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
110
  foreach ( $attachments as $id => $attachment ) {
111
  $link = '';
@@ -159,6 +166,6 @@ class WPGalleryCustomLinks {
159
  } // End foreach post attachment
160
 
161
  return $output;
162
- } // End function apply_custom_links()
163
 
164
  } // End class WPGalleryCustomLinks
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.0.4
7
  Author: Four Lights Web Development
8
  Author URI: http://www.fourlightsweb.com
9
  License: GPL2
72
  public static function apply_filter_post_gallery( $output, $attr ) {
73
  global $post;
74
 
 
 
 
 
75
  if( self::$first_call ) {
76
  // Our first run, so the gallery function thinks it's being
77
  // overwritten. Set the variable to prevent actual endless
87
  self::$first_call = true;
88
  return $output;
89
  }
90
+
91
+ // Get the shortcode attributes
92
+ extract( shortcode_atts( array(), $attr ) );
93
+
94
+ // Determine what our postID for attachments is - either
95
+ // from our shortcode attr or from $post->ID. If we don't
96
+ // have one from either of those places...something weird
97
+ // is going on, so just bail.
98
+ if( isset( $attr['id'] ) ) {
99
+ $post_id = intval( $attr['id'] );
100
+ } else if( $post ) {
101
+ $post_id = intval( $post->ID );
102
+ } else {
103
+ return ' ';
104
+ }
105
 
106
  // Get the normal gallery shortcode function
107
  if ( isset( $GLOBALS['shortcode_tags'] ) && isset( $GLOBALS['shortcode_tags']['gallery'] ) ) {
110
 
111
  // Run whatever gallery shortcode function has been set up,
112
  // default, theme-specified or whatever
113
+ $output = call_user_func( $gallery_shortcode_function, $attr );
 
 
 
114
 
115
  // Get the attachments for this post
 
116
  $attachments = get_children( array( 'post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
117
  foreach ( $attachments as $id => $attachment ) {
118
  $link = '';
166
  } // End foreach post attachment
167
 
168
  return $output;
169
+ } // End function apply_filter_post_gallery()
170
 
171
  } // End class WPGalleryCustomLinks