Support » Plugin: NextGEN Gallery - WordPress Gallery Plugin » [Plugin: NextGEN Gallery] Suggestion: wp_get_attachment_url() filter for "ngg-#" image IDs

Viewing 3 replies - 1 through 3 (of 3 total)
  • Sigh. Won’t work, if I’m reading it right. wp_get_attachment_url() tries to do a get_post() on the ID, and when that fails it returns false… without running the filters on the function. So code which does the proper lookup for NGG can’t be inserted.

    Themes which need to handle NGG images might be able to be patched with a child theme which uses something similar to this:

    	 * Function which returns the URL for a NextGen Gallery (NGG) image.  It was inspired by a theme which uses a line similar to:
    	 * 	$image_url = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
    	 * The above can be fixed to work with NGG by adding the following line after it:
    	 * 	if( function_exists( 'ngg_a_theme_child_theme_thumbnail_id_url' ) ) $image_url = ngg_a_theme_child_theme_thumbnail_id_url( $image_url, get_post_thumbnail_id( $post->ID ) );
    	 * The first parameter, $image_url, must be FALSE or empty() in order for the function to look up the NGG image ID.  If the first parameter has anything in it, that value is returned.
    	 * This function is needed because wp_get_attachment_url() does not invoke its filters when it does not recognize the NGG image IDs (ie, "ngg-1"), thus NGG cannot insert similar code.
    	function ngg_a_theme_child_theme_thumbnail_id_url( $url='', $attachment_id='' ) {
    		$return_url = $url;	// Default value is whatever was passed in for the URL.
    		if( $url === false || empty($url) ) {
    			if( is_string($attachment_id) ) {
    				$attachment_id = trim($attachment_id);
    				if( substr($attachment_id, 0, 4) == 'ngg_' ) {
    					$numeric_id = substr($attachment_id, 4);	// Get the number after 'ngg-'
    					if( is_numeric($numeric_id) ) {
    						if( class_exists('nggdb') ) {
    							$ngg_image = nggdb::find_image($numeric_id);	// Find the image info in NGG's database
    							if( $ngg_image ) {
    								$ngg_url = $ngg_image->thumbURL;
    								if( ! empty($ngg_url) ) {
    									$return_url = $ngg_url;	// found the needed URL
    								} // if NGG gave us a URL
    							} // if ngg_image not null
    						} // if NGG DB call exists
    					} // if ends with numeric
    				} // if ID starts with 'ngg-'
    			} // if is_string
    		} // if no URL defined
    		// Return the result
    		return $return_url;

    Nope, I don’t know how ‘ngg-‘ got changed to ‘ngg_’. Used to be ‘ngg-‘, as it should be.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: NextGEN Gallery] Suggestion: wp_get_attachment_url() filter for "ngg-#" image IDs’ is closed to new replies.