wp-Gallery2 Image Block

This plugin will allow you to put one of the meny Gallery2 Image Blocks on your WordPress site. You are required to have a running Gallery2 install to use this plugin.

This is a complete rewrite of Chris Schierer (aka Lentil) Gallery2 Image Block Plugin 0.1.4. This rewrite uses the new WordPress 2.8 Widget API, so is only compatable with wordpress 2.8+.

All options described in the Gallery 2 Image Block documentation are included. User configuration of Image Block options are available in the Widget configuration panel. Blank (empty) options use the Gallery2 defaults.

As of version 0.5, wp-gallery2-image-block has full localization support, and ships with 5 languages besides English. Please contact me if you would like to translate it into more langages, I would love for as meny peaple as posible to be able to use this plugin.

Fully Translated into:

  • Dutch (0.5.1)
  • French
  • English
  • German
  • Italian (0.6.1)
  • Polish (0.6.1)
  • Portuguese (0.5.1)
  • Spanish

Note: This widget was written using wp_http to increase compatibility with more sites (version 0.6).


Latest version: Download wp-Gallery2 Image Block v0.6.4 [zip]


Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.

Screen Shots

  1. Dashboard Wiget Screen

    Dashboard Wiget Screen

  2. Shown on main page

    Shown on main page


Q. Q: Will this plugin work without Gallery2?
A. A: Sorry No, Gallery2 is required.

Q. Q: Will I be able to add a random image to a page with this plugin?
A. A: Sorry, this plugin will only work in the wiget sidebar.

Q. Q: Recived “SECURITY VIOLATION The action you attempted is not permitted” error on page load
A. A: make sure the Gallery2 plugin “Image Block” is installed and active on your Gallery2 install. You should be able to see the random image by going to: http://--gallery2url--/main.php?g2_view=imageblock.External Where –gallery2url– is the value you put in the widget’s URL field. You should
see the random image with the default options.


Version 0.6.4

  • Tested with WordPress 3.3 – no code changes

Version 0.6.3

  • Tested with WordPress 2.9 – no code changes

Version 0.6.2

  • Tested with WordPress 2.8.6 – no code changes

Version 0.6.1

  • Tested with WordPress 2.8.5 – no code changes
  • Added Italian Translation
  • Added Polish Translation

Version: 0.6

Version: 0.5.2

  • Tested with wordpress 2.8.3 & 2.8.4 – no code change
  • Corrected URL’s
  • Updated README

Version: 0.5.1

  • Tested with WordPress 2.8.2 – no code changes
  • Updated POT file do to typo
  • Added Dutch translation
  • Added Portuguese translation

Version: 0.5

  • Added full localization support
  • Added French translation
  • Added Spanish translation

Version: 0.4

  • Corrcted typo in $gallery_linktarget

Version: 0.3

  • Corrected missing Header text tag

Version: 0.1

  • Initial Release

29 thoughts on “wp-Gallery2 Image Block

  1. I’ve tried installation on WP 2.8.3 but got error:

    Fatal error: Class ‘WP_Widget’ not found in /path/to/wordpress/roaming/wp-content/plugins/wp-gallery2-image-block/wp-gallery2-image-block.php on line 11

    Any idea why?

    • WP-Widget is part of the core of the 2.8 branch, so you should defiantly have it. What’s the state of your install? I mean, is your blog fully functional?

      If I look at your home page, it looks like your running 2.7, you should try to upgrade your site to version 2.8.4 again.

          • WP updated and plugin works. However there’s two things I don’t like that much:

            – fields display inline (not your fault, I know, but it’s not nice)
            – the plugin generates in fact a widget which is stuff I don’t use on my WP (hard to handle)

            Anyhow, thanks for your support.

  2. Hi Matt,
    I have some difficulties installing your great widget on my wordpress page. Somehow I keep getting the message: “SECURITY VIOLATION The action you attempted is not permitted”. Any help is appreciated.

    • What version of WordPress are you using, what version of the plugin? What security “role” do you have on the WordPress install?
      Are you receiving this error while on the widget admin page, or on your webpage?

      If it is on your main webpage, what do you get when you point your browser to?
      Where –gallery2url– is the value you put in the widget’s URL field. You should see the random image with the default options.

      • I am using WordPress 2.8.5 and plugin version 0.6.1
        I am receiving the error on my webpage.
        What do you mean with security “role” on the WordPress install?
        When using the URL I get a screen with the same error message: Security violation… etc.

        • 2.8.5, good. 0.6.1, good.

          Since you receive the same error when using the URL, that makes me think that it’s a problem with your Gallery2 install. Do you have the “Image Block” plugin installed on your Gallery2 install? You should see the option on the left hand side of your gallery2 admin page.

          • That was the solution. I didn’t install the “image block” plugin in Gallery2. Now I did and it is working great. Super!! Many thanks for your prompt support!!

  3. For some reason this plugin isn’t working with my installation.

    Well, it works just fine, but it is inserting a special character code which is causing my images to not be shown.

    When configured in the widget, it will trying to display the following:

    When I remove the “amp;” and paste manually it works. What causes this plugin to insert that? The “amp;” is showing up after the “&” in the URL.

    • Im sorry your having problems. ‘& amp;’ is the HTML code for ‘&’ so I can see why that may happen, but it shouldn’t. Who is your host? What version of Apache and PHP are you running? I’m wondering if you host has some extra security running on your site that is changing the ‘&’ to ‘& amp;’. I have played around a bit with, but I’m unable to reproduce your problems.

      • Same problem but with an other version. But I solved it.


        Goto line 65

        $url = $urlGenerator->generateUrl(array(‘view’ => ‘core.ShowItem’, ‘itemId’ => $child->getId()), array(‘forceFullUrl’ => true)); // HTML page URL

        $url = str_replace(‘amp;’,””,$url);

    • Unfortunately, a picture or album that isn’t public to the world, will not show up as a random image. This I have always seen this as more of a feature over a bug/problem. But im actually in the same place with my old Gallery 2 photo gallery as im replacing it with a new, but not yet stable Gallery 3 site.

      At this point I really don’t know what you should do. If you open the site back up to the world so the plugin will work, then the world will see your gallery, but it will not work with it locked down.

      • So my blog is locked too and there is no problem to show a random image to the blog users. I think I can use a loging from G2 in your plugin to get the picture out of the closed gallery.


  4. Hi,

    I have your plugin up and working on http://www.redseasnapper.com/blog i have tried to do the same for another site http://www.thetavernbar.com/blog but it just brings up a block in the sidebar with the Title and adds no code to actually load a picture? I have them both configured the same. Image block is configured in Gallery and putting http://www.thetavernbar.com/gallery/main.php?g2_view=imageblock.External in browser brings up a random image…wordpress version is 2.9.1 on thetavernbar.com but 2.9 on redseasnapper.com this is the only difference I can see.

    Please help….

  5. It looks like these two sites are on different systems (they have different IP addresses). First confirm curl is installed on the server as WordPress uses that to download anything not hosts on the same server. Also, what happens if you put the thetavernbar.com’s IP address into instead of the DNS name? or even the loop back ( Looking at the source on http://www.thetavernbar.com/blog/, it look like it’s not seeing the page.

    Please let me know.

    • Hi Matt,

      Sorry for any confusion. Yes redseasnapper and thetavernbar are on different systems. However, the tavernbar blog is trying to point to thetavern bar gallery which are both on the same server so WP does not need to contact an outside server. I only mentioned redseasnapper as I had no problems with that implementation. I will try the ip address and let you know what happens. By the way what is curl and how will I know if it is installed??

      Many thanks


      • curl is a lib that WordPress uses to download all files, if your having other problem downloading from WordPress, (like plugins or themes) that may be your problem, if your not, then it’s not.

        • So I was thinking of your problem a bit more. Do you have SSH or other shell access to your host? If you do, can you try downloading the output from your Gallery2 random Image block so something like this:

          wget http://www.thetavernbar.com/gallery/main.php?g2_view=imageblock.External

          Just to confirm it’s able to get the needed info from the server.

        • Something else to try.

          If edit the plugin (wither threw WordPress or some other editer) at around line 41 you should fine

          // Output the wigget to the browser
          echo $before_widget.$before_title.$title.$after_title;
          echo $file_contents;
          echo $after_widget;

          After “echo $file_contents;” add
          echo $result;

          so it looks like this:

          // Output the wigget to the browser
          echo $before_widget.$before_title.$title.$after_title;
          echo $file_contents;
          echo $result;
          echo $after_widget;

          That should display the URL of the page the plugin is trying to display, you should be able to copy and past that into your browser address bar. This way you can confirm that the plugin is giving WordPress the correct URL when asked.

          If you have problems or break the plugin, you may always just delete it and redownload/install, so you mite as well have some fun.

          Let me know how it goes.

  6. Hi Matt, great plugin, thanks!
    I want to know if it’s possible to use a variable in one of the option fields for configuring the widget.

    Basically, I have a site that showcases a bunch of products, each on its own page. In G2, each product also has its own album.

    So what I want is for the widget to use the ID of the appropriate album on each product page, possibly from a custom field on the page called ‘ID’ or GalleryID or something.

    Is there any way this could be possible?

  7. Hi,
    would like to be able to have the random image open as a new window when clicked – can’t quite figure out how to do that ?


  8. Hi Matt!

    First I’ve gotta say I love this plugin. I’ve been using it for about 6 months now, and I like how, it a completely automated way, it encourages my blog readers to check out my gallery.

    I updated to wordpress 3.2.1 yesterday, and I was wondering, does all of its code work fine in WP 3.2 and above? It seems to work alright so far, but I’d appreciate you taking a look at it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.