Search

Other Sites

Email

  • Memphis, TN 38103 U.S.A. Otto 240cf86e-5cad-11dc-8314-0800200c9a66

Buy Otto a Beer

Currency:

Amount:

Website(Optional):

Amazon Honor System Click Here to Pay Learn More

Get Otto a Gift

My Amazon.com Wish List
Text

9 Apr 2006-04-09 20:14

Fun with Widgets

Note: The ExecPHP widget does not work in the upcoming WordPress 2.5. Therefore, if you upgrade to 2.5, you will need to install the updated version of this widget. It can be found here, now and forever more: http://wordpress.org/extend/plugins/php-code-widget/

A new plugin for Wordpress came out that’s kinda cool. It’s called Widgets, and the general idea of it is to make the sidebars on your blog a bit more configurable, a bit more easily.

So, I decided to spend an hour or so converting my sidebars to Widgets so I could manage them a bit simpler. Editing PHP code is easy but time consuming, while dragging stuff and dropping it to rearrange the blog, well, that’s quick and easy.

Few things I learned:

  1. The Widgets Plugin does not like Windows. Since I run this site on a Windows box (edit: I did then, I don’t anymore, and anyway, they have fixed this problem since then), it needed some tweaking to make it work. For those who want to know, the problem is in the sidebar_admin_setup() function in widgets.php. More info on this problem is in the comments of this post.
  2. Text boxes are extremely useful when converting from your existing customized webpage to a widgets based one, as you can simply cut and paste chunks of HTML into them and voila, you’ve got a sidebar widget. However, there’s not a lot of text widgets available. If you need more text widgets, you will need to edit these functions: widget_text_setup(), widget_text_page(), and widget_text_register(). As it turned out, I didn’t need but 4 text widgets because:
  3. Despite how useful text boxes were for a quick migration, they were not enough.

So, I ended up writing two plugins of my own.

The first one is a Google AdSense plugin. You can download it here: gadsense.zip. It’s exactly the same as the Text widgets, but with (very) minor tweaks specifically for inserting Google Ads in the sidebars. Also, it shows a name of “Google AdSense” in the widgets panel, which is nice. Like the Text widget, you can have more than 1 of them, but unlike the Text widget, you can only have 4 of them, since Google’s TOS only allows 3 ads and 1 link block on a page.

The next one is also like the Text plugin, however it will also let you put PHP code into the text and have it actually work. Here’s the download: execphp.zip. Like the Text plugin, you can have up to 9 of them (more if you want to tweak the code). Note that any PHP code you put into the widget MUST be surrounded by <?php and ?> tags, just like writing PHP normally. Also note that this is isn’t exactly safe, as it’s just doing an eval() on whatever you put in there, so you have complete and full access, as does anybody else who can get to your admin screen. Still, it’s very useful.

Both of those are plugins. Just drop them in the widgets folder under the plugins folder, and activate them on the plugins screen. Then the widgets will be available for you to use on the widgets screen.

Hope these help somebody. They sure helped me. )

Tags: , , , , ,

Posted in Geekery, Hackery, Programmery |

197 Responses

Latest 5 Trackbacks/Pingbacks

  1. WordPress 2.5 : Broken Plugins at STCFX - Web Everything Says:

    [...] ExecPHP Widget 1.0 - Does not work with 2.5 widgets, upgrade to the PHP Code Widget. Same widget and author, new version and name. [...]

  2. Mise en place des conseils de John Chow | Scan-X’s Blog [french] Says:

    [...] Executable PHP widget : nécessaire pour Text Link Ads : pas encore mis en place. [...]

  3. Shylock Adsense Plugin - Hack To Avoid Smart Pricing | The Coupon Cruncher Says:

    [...] do this, you need to have a widget with can execute php code. I use Otto’s ExecPHP plugin, but there are others [...]

  4. How to Decide Where to Put Widgets on Your Blog | Stephan Miller Says:

    [...] I could use a browse to the post an use a bookmarklet.  It’s running inside the Executable PHP Widget, which is using this [...]

  5. PopDo’s Blog » Blog Archive » WordPress 2.x Plugins - Show Top Commentators Says:

    [...] there is a simple solution available thanks to the author of ExecPHP, another plugin that gives plugins like Show Top Commentators widget support. Here is the direct [...]

Latest 10 Comments

  1. gary storm Says:

    Cheers Otto! Fantastic! I had problems getting WordTube to work as a widget (wanted multiple songs listed, not just one), and couldn’t get the multi-version to go into a sidebox. Your widget did the trick :) Now I just have to figure out why anything under the widget is way out of alignment (like off the bottom).
    Cheers!

  2. Steve Says:

    I am trying to use Vincent Prat’s Enhanced Categories plugin with your PHPExec plugin. On his site, he mentions using this code to call his plugin through your plugin -
    Categories

    When I try that, i get the following error -
    Fatal error: Call to undefined function enh_cats_insert_categories() in /home/.venus/XXXXXX/domain/wp-content/plugins/execphp.php(24) : eval()’d code on line 3
    Any suggestions on how to properly call this function would be a big help.
    TIA

  3. Steve Says:

    ok, I’m just a goober at this, so here is a link to the code http://www.thecosmeticcounter.com/code.txt

  4. Otto Says:

    If the function is coming up as undefined like that, then either the other plugin is not activated, or it’s misspelled…

  5. Trevor Nash-Keller Says:

    Thanks, I had no clue a plugin like execphp existed but have wished one did for quite some time now.

  6. Yana Says:

    OMG thanks soooo much!!
    I’ve been trying to find a plugin like this for days now :)

  7. absolut-desing Says:

    thanks soooo much for this great plugin

  8. Flash Blog Says:

    Awesome script, thank you for the resource…perfect size!

  9. Hikari Says:

    http://codex.wordpress.org/Plu.....bility/2.5 says this plugin is not compatible with 2.5, do you plan to update it?

  10. Hellows Says:

    That is a great plug in. It is working perfect. I am using it to get the latest posts from my phpBB forum. However, I had to re-install the forum and the widget went crazy. I cannot access my php code in the widget as the code corrupted my widget section in the admin panel. Is there a .php file where my code I entered in the widget is stored, so that I can edit it. As I have no more access to the widget/code from WP-Admin. I can deactivate the plug-in an all is working again but I would like to use it. I tried to override the execphp with a fresh file but the plugin still remembers my code. Where can I edit it ?

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>