Samsarin PHP Widget

If you are not familiar with Wordpress widgets, take a look at Automattic’s Widget plugin. The plugin makes it easy to reconfigure your Wordpress sidebar by dragging and dropping widgets into place on a sidebar menu.

The Samsarin PHP Widget adds a new text widget that allows PHP to be included inline.

Installation

  1. Download the Samsarin PHP Widget and unzip it.
  2. Copy samsarin-php-widget.php to the /wp-content/plugins directory.
  3. Login to your admin console, go to Plugins, and enable the Samsarin PHP Widget.

Recent Changes

  • Now hosted at the Wordpress plugin directory. This should allow you to get notifications when the plugin is updated.
  • 1.3.2 - Added an option to reset a widget or to reset all widgets
  • 1.2 - Increased max # of widgets to 25
  • 1.1 - Fixed a widget API incompatibility in Wordpress 2.2
  • 1.0 - Initial release

Known Issues

  • Editing widgets does not currently work in Internet Explorer. A short term workaround is to use another browser, such as Firefox or Safari. This will be addressed in an upcoming release.

Usage

The Samsarin PHP Widget can be used like the default text widget. In addition, you can add PHP to the Samsarin PHP Widget by enclosing PHP code as follows:

<?php your_code_here... ?>
  1. In your admin console, go to Presentation, and then go to Sidebar Widgets
  2. Select the number of PHP Widgets you want in the “Samsarin PHP Widgets” window. By default, 1 will be available.
  3. Drag one of the Samsarin PHP Widgets to your sidebar.
  4. Click the window button on the Widget to edit its title and body.

Frequently Asked Questions

What versions of Wordpress are supported?

This plugin has been tested with Wordpress 2.2, 2.3, and 2.5.1.

My Samsarin PHP Widget does not show up in the widget admin console

First, make sure that the plugin is enabled.

  1. Log in to the admin console
  2. Go to Plugins
  3. Verify that “Samsarin PHP Widget” is in the list. If it is not, then wordpress doesn’t see the plugin. Is it in your plugin directory (wp-content/plugins)?
  4. Verify that the plugin is enabled

If it is enabled and you can see it on the left hand side of the Design | Widgets page, then it is possible that the content of one of the widgets is causing a problem. With Samsarin PHP Widget version 1.3.2 you can reset the widgets.

  1. Backup your database.
  2. Go to Settings | Samsarin PHP
  3. If you know the name of the widget that is not working, use the “Reset” option. If you do not know which widget is failing, use the “Reset All” option. This will reset the widget to its initial, empty state.

Warning

This widget provides great flexibility in customizing your sidebar. It achieves this by automatically evaluating any included PHP included in the title or the body of the widget. Care should be taken when including PHP code in the sidebar, as with anywhere else in the Wordpress system.

License

This Wordpress widget is available to use and redistribute as you wish. If you redistribute this plugin, please include the original copyright and license information. I would be happy to hear how others are using this plugin and I would also appreciate enhancement requests.

Comments

Add a Comment
  1. [...] numerous requests for the Samsarin PHP Widget, so I am happy to announce that is now available here. This widget makes it easy to add PHP code into the sidebar while using Automattic’s Widget [...]

  2. [...] just posted Samsarin PHP Widget 1.1. If you are using Wordpress 2.2, please upgrade to this version. Wordpress 2.2 introduced an [...]

  3. [...] second one was much easier. The Samsarin PHP Widget which has been upgraded for WP 2.2. When I upgraded this blog to WP 2.2 I lost my King Text Widgets [...]

  4. [...] Widgets WordPress widgets - the jewel in the WordPress crown. Widgets remove the need to hack individual files, inserting snippets of code here and there to get extra features and functionality. Before widgets, upgrading your WordPress installation could be a tricky manoeuvre, fraught with danger - you upgraded and lo and behold you lost all those little snippets of code. However, the great thing about Widgets is that not only can you download hundreds of them, you can also take all those little snippets of code and widgetize them. You can create your own “Text Widgets” and use text and JavaScipt inside them. If you want to include PHP code inside of them, then just download the Samsarin PHP Widget. [...]

  5. [...] Samsarin PHP Widget As written, one cannot include PHP calls in a WordPress widget. This plug-in promises to do just that. (tags: blog Plugin php wordpress Widget) [...]

  6. [...] Visit [...]

  7. [...] new version of Samsarin PHP Widget increases the number of widgets available from 9 to 25. [...]

  8. [...] run PHP in widgets, you need a PHP widget plugin, such as this one from Samsarin. To learn more about the parameters you can add to the wp_list_categories template call, see this [...]

  9. [...] Samsarin PHP Widget: I love this! Since I’ve integrated widgets (thank you UP!), this has been a designing timesaver. The writer allowed HTML to be used in the title field as well and this saved me from so many design issues. [...]

  10. [...] 2. Samsarin PHP Widget [...]

  11. [...] WordPress dispone de un potente sistema de “widgets” (o pluggins) que permiten añadir nuevas funcionalidades a las barras laterales. Si nunca has hecho uno, pero conoces el lenguaje PHP, puedes utilizar un widget de texto compatible con PHP que se encuentra disponible en samsarin blog. [...]

  12. [...] to the (top) contributers of this blog. In order to use this plugin, I recommend you to install the Samsarin PHP Widget in order to be able to include PHP in your [...]

  13. [...] The plugin is based on the Samsarin PHP Widget [...]

  14. [...] when I found this plug-in. It allows you to add PHP code to your widgets. It’s called the Samsarin PHP Widget [...]

  15. [...] Samsarin PHP Widget [...]

  16. [...] Samsarin php widget [...]

  17. [...] 99) Samsarin PHP Widget [...]

  18. [...] 99) Samsarin PHP Widget [...]

  19. [...] 99) Samsarin PHP Widget [...]

  20. [...] 99) Samsarin PHP Widget [...]

  21. [...] Visit [...]

  22. [...] with a widgetized theme that wants to be able to execute php functions from their widgets. You can download it here. Scroll to the bottom of your widget page after you install and activate the Samsarin PHP Widget [...]

  23. [...] Markuz, mi permetto di suggerirti di utilizzare questo plugin. Fammi sapere come è [...]

  24. [...] any issues using PHP includes within a widget. Rogue had the answer: use this WordPress Plugin - Samsarin » Samsarin PHP Widget [POSTED IN] Adult Webmasters Main Forum [LINK] [...]

  25. [...] el plugin Sansarin.php el hecho de tener que modificar su plantilla bajo el pretexto que los Widgets no interpretan el [...]

  26. [...] Samsarin PHP Widget 1.2 Works well in Firefox 2. Problems in IE. [...]

  27. [...] 插件地址:Samsarin PHP Widget [...]

  28. [...] going to look into hosting options for the Samsarin PHP Widget. If you have any suggestions, I’d be happy to hear [...]

  29. [...] run php, plug the search code into it, and move it around like any other widget. I use Samsarin PHP Samsarin PHP Widget ? Samsarin and find it does a nice job. Hope it works this [...]

  30. [...] More: Samsarin PHP Widget Plugin [...]

  31. [...] Samsarin PHP Widget The Samsarin PHP Widget adds a new text widget that allows PHP to be included inline. (tags: wordpress plugin) [...]

  32. hi,

    can you tell me where the samsarin widget (and probably all the other widgets) content is saved? cause… i got an error and i really do not want to delete the whole plugin to get rid of it. thx in advance. (i played too much with the code)

  33. sorry to disturbed you. i fixed it. the php i used was a standard php function for displaying entries of a special category. i just reseted the specific samsarin widget.

  34. I love your plugin! and it’s working like a charm. I have one question/request though. I’m using xlanguage to make my blog bilingual. The only problem is related to widget title localization. I’m using some normal text widgets on my sidebar but the don’t get the title translated. I’m thinking about change them for your samsarin php widget because HelloSam the creator of xlanguage provides some instructions to localize plugins using a simple instruction in the code of the widget. He claims that instruction doesn’t break the code even if you’re not using his plugin. The problem is…I don’t know where to add this funtion in your plugin’s code, and I dont like to modify other’s work without permission. Could you take a look at his instructions and let my know if it’s possible and where to add it?

    These are the instructions:
    1. Open the php file that contains the widget code
    2. locate the widget code responsible for rendering, usually the handling function is specified by the wp_register_sidebar_widget invoked in the code.
    3. In the rendering function found, locate the $before_title variable.
    4. Wrap the title variable with the apply_filters: localization, so it might look like this: apply_filters(’localization’, $title)
    5. Done

    And this is the page: http://hellosam.net/lang/en/project/xlanguage/4

    Thank you so much in advance.

  35. Hello Dibujor,

    My widget is free to change as you like. You don’t even need to publish the changes to me, though I’d definitely be happy if you did, and I will credit you in the changelog.

    I haven’t done any localization work yet on the plugin, but it would certainly be a nice feature to add.

    It looks like you need to change line 81 (of version 1.3.2) from:

    $title = $options[$number]['title'];

    to:

    $title = apply_filters('localization', $options[$number]['title']);
  36. THANK YOU!. It works like a charm. If you go see my blog, in the sidebar, the sections Subscribe, Link me and Take a look (you should click the union jack flag first of course, as my blog native language is spanish) are made with your plugin after changing that line as you said. And you can see the translation shows perfectly. I have not the abilities to change your amazing work (as you can see by my prior question). Just trying to make my blog FULLY bilingual. The xlanguage plugin is perfect for that matter and, with the adition of your php plugin for some parts, they make a killer combo. If that line doesn’t affect the php plugins inside work when you’re not using the xlanguage I recommend you add it definitely (HelloSam claims so but, as I’m not a php master…I don’t know. Hellosam proposes to define that function as a standard for the widget and translation plugins. This way every plugin developer can add the funtion to their work and users can localize that plugins without touching the code.

    Anyway, I must thank you again, and again……..thank you so much

  37. [...] Copy this code to your PHP widget. [...]

  38. [...] php-Befehle in den Widgets nur ab und zu richtig dar. Hier half dann eigentlich nur das Plugin Samsarin PHP - damit war die Implementierung des Movierating-Plugins wie gewünscht möglich. Bis ich aber mal [...]

  39. I just wanted to thank you for taking the time to develop this extremely useful plugin. It’s folks like you that make Wordpress such a breeze. Cheers!

  40. [...] Samsarin PHP Widget Un plugin gratuit pour Wordpress qui permet d’ajouter des widget qui exécute le code PHP (tags: PHP Widget Wordpress Plugin) [...]

  41. [...] Samsarin PHP Widget [...]

  42. This is a great plug in :)

  43. very good plugin。thanks!

  44. I would like to include a php file in the applet.
    Although whenever I try I get… errors

    eg putting in

    Returns the error.
    “URL file-access is disabled in the server configuration…”
    I’m guessing something is wrong on my server?

  45. HGWells:

    Maybe this will help: http://wordpress.org/support/topic/159129.

  46. Fantastic, thank you Chris.
    You made my day that little be better :)

  47. [...] 记得图中的代码么?在中文 WordPress 工具箱 里面介绍过的哦~~ 出生地:Samsarin PHP Widget 居住地:WPLAND小区 & [...]

  48. [...] Samsarin PHP widget plugin If you’re using a theme that doesn’t support PHP in its sidebar widgets (which would be [...]

  49. [...] have it where I can put it into a sidebar with a widget, but any post plugins around to add js? Samsarin PHP Widget — Samsarin but i’ve been having problems with this plug-in and the latest WP, try it and see [...]

  50. [...] have it where I can put it into a sidebar with a widget, but any post plugins around to add js? Samsarin PHP Widget — Samsarin but i’ve been having problems with this plug-in and the latest WP, try it and see [...]

  51. If you are using Internet Explorer with this plugin, and are experiencing trouble when trying to move the Widget from the available widgets list (left) to the Sidebar list (right), try using FireFox. Worked for me!

  52. [...] you either must have access to edit the current theme or have a plugin installed (Exec-PHP Plugin, Samsarin PHP Widget) which allows widgets to accept php [...]

  53. [...] -> Download [...]

  54. Whups… I apparently entered the wrong php code, and now I can’t delete the widget… Help!

  55. Hi Jeff,

    To fix that:

    1. Go to your admin console (/wp-admin)
    2. Go to Settings
    3. Select the Samsarin PHP Widget tab

    Now you can choose either “reset all”, which will erase all of the Samsarin widgets, or you can choose a specific widget to delete from the drop down.

    - Chris

  56. @Chris:
    Ah! Thanks much!!!

  57. [...] 二、使用了Widgets,这种情况下你可以: 1、下载这个插件:Samsarin PHP Widget,Samsarin PHP [...]

  58. [...] 1、下载这个插件:Samsarin PHP Widget,Samsarin PHP Widget(via)的功能是让Widgets支持PHP代码,下载解压并上传到wp-content/plugins/目录下启用插件即可,之后在外观-可用Widgets下增加了Samsarin PHP Widgets。 [...]

  59. This is a great plugin

  60. I have just upgraded my WP 2.2.1 site to 2.7 and can confirm that the Samsarin PHP Widget (v1.3.2) plugin works fine.

    Hope this helps anyone thinking of upgrading to 2.7!

  61. I’m trying to build a Featured Posts widget and I can’t seem to get it to execute the PHP code of any of the featured posts widgets. If I use them in templates they work fine, but not inside the PHP widget.

    Is there some call I have to make first or something?

  62. @Scott Somehow I missed your comment, but saw your tweet on twitter. You shouldn’t need to do anything special to use the plugin. I tested the Alex King articles plugin on WP 2.7.0 with the Samsarin PHP widget successfully (inserting <?php aka_show_articles(); ?>). I was also able to get the plugin working with Thematic.

    Assuming you’re testing in a staging environment, what happens if you put <?php phpinfo(); ?> in the widget? Does it still display nothing? Also, what happens if you put something like this in the widget:

    BEFORE
    <?php aka_show_articles(); ?>
    AFTER

    The fact that no error is getting displayed makes this a little trickier, but these two tests may give us more insight into the problem.

  63. Go figure. I uninstalled and reinstalled the plugins, and now at least the Alex King Articles plugin works. Needs tweaking to look like I want it to, but it’s a starting point. I swear it wasn’t working yesterday after several attempts.

    The Featured Post plugin isn’t working, but never mind. And Those Were the Days works partially, but it’s its own widget, so I’ll take it up with the author.

    Thanks so much for your help, Chris.

  64. OK - I tweaked it and got it working like I want…mostly. See http://ScottSocialMediaAllen.com.

    Only problem is… get_the_excerpt() is only working if there’s a manual excerpt - not pulling the first 55 chars otherwise. Any ideas?

  65. Hi,
    My Samsarin PHP widget is no longer functioning. The changes I’ve made today are upgrading to WP 2.7.1 and upgrading my server from php 4.x to 5.x. Here is the error I’m seeing.

    %BEG_OF_TITLE% Latest Review %END_OF_TITLE%

    Warning: require_once() [function.require-once]: URL file-access is disabled in the server configuration in /home/content/i/a/n/iancowpar/html/blog/wp-content/plugins/samsarin-php-widget/samsarin-php-widget.php(96) : eval()’d code on line 5

    Warning: require_once(http://www.2beerguys.com/mysql_connect.php) [function.require-once]: failed to open stream: no suitable wrapper could be found in /home/content/i/a/n/iancowpar/html/blog/wp-content/plugins/samsarin-php-widget/samsarin-php-widget.php(96) : eval()’d code on line 5

    Fatal error: require_once() [function.require]: Failed opening required ‘http://www.2beerguys.com/mysql_connect.php’ (include_path=’.:/usr/local/php5/lib/php’) in /home/content/i/a/n/iancowpar/html/blog/wp-content/plugins/samsarin-php-widget/samsarin-php-widget.php(96) : eval()’d code on line 5

    Can you help?

  66. [...] php widget (plugin homepage) allows me to use my own code in the sidebar, such as the random photo. [...]

  67. Muy bueno, gracias

  68. Hi,

    I have tried three different php code excution widgets and can’t get any of them to process a case or if statment properly. I am sure that it is something I am doing wrong but I can figure it out.

    I am try to select an image based on the post number.

    <img src=”/wp-content/image/sidebar_img_.jpg>

    if the value of the_ID() is 1 I get 11. It seems that the default option is always echoed.

    If I remove the default value, I get the correct value for the current page and I get the correct image name, but I would like to be able set the default value.

    I have also tried changing this to an if statement and have the same problem.

    I don’t get it. php can’t be this hard.

    Please help.

  69. So I didn’t mark the PHP code correctly in the last post. With out the Php tags it was

    Sorry.

  70. ok, this is too hard.

    switch (this_ID()) {
    case 2:
    case 3: echo the_ID();
    default: echo “1″; }

  71. @David

    the_ID() doesn’t return the id but prints it straight out to the page (see http://tr.im/i8VZ). You probably want to use $post->ID (see http://tr.im/i8WJ for examples). Also, this requires you to be in the loop, which wouldn’t be available in the sidebar. If you’re on a single page, you could save the value in a global variable and use it from the sidebar.

  72. Thanks, I get it. I don’t have much PHP experience, but I am learning.

  73. [...] mendukung text biasa, html dan java script. Untuk itu kita memerlukan sebuah plugis lagi yaitu Samsarin PHP Widget. Dengan widget ini kita bisa menyisipkan kode - kode PHP pada widget sidebar kita. Kecuali kalau [...]

  74. [...] menampilkan di sidebar kita perlu menggunakan Samsarin PHP Widget karena widget text biasa tidak mendukung coding [...]

  75. [...] Download the Samsarin PHP widget wordpress plugin from author homepage and upload it on your plugin folder. [...]

  76. Hi there. Love the widget but have one question. I want to hide your Samsarin PHP widget on certain pages. Widget Logic doesn’t work with your widget. Is there code for hiding/showing Samsarin PHP widget on particular pages? I know what the conditional statements should be, but not the “hide/show” or “visible/invisible” statement. (I saw something about register/unregister, but would like an alternative. That seems too dramatic.)

    Thanks.

  77. [...] Samsarin php widgets [...]

  78. Hello, thank you very much for the plugin!

    I’m trying to order posts in a list by meta_value (because I want to use another order than chronological) in the sidebar with it. The meta_key is called “Order”. I’ve entered this:

    =”);
    //Reset Query
    wp_reset_query();
    ?>

    But I guess it won’t work because it’s not in the loop? Does anyone know how I can code this? Maybe show me a forum where I can get an answer? Thanks!! :)

    Bala

  79. Sorry, the code was cut in my message.

    */

  80. Here it is, without the // I also would like to show them as a list but don’t know how. ;)

    //

  81. [...] menampilkan di sidebar kita perlu menggunakan Samsarin PHP Widget karena widget text biasa tidak mendukung coding [...]

  82. [...] mendukung text biasa, html dan java script. Untuk itu kita memerlukan sebuah plugis lagi yaitu Samsarin PHP Widget. Dengan widget ini kita bisa menyisipkan kode - kode PHP pada widget sidebar kita. Kecuali kalau [...]

  83. [...] if you’re running the Samsarin PHP widget, you can use PHP codes (and any other custom PHP) in your sidebar with very little [...]

  84. This widget doesn’t seem to be working with wordpress 2.8

    It appears to only show 1 widget and there is no ability to create more, I can click how every many I want but it still only shows 1

  85. Looking for the update to 2.8?

    / T

  86. same problem as Breigh and Thav

  87. Thanks for the heads up. I’ll take a look at the API changes tonight and scope the work (hopefully should be small). I’ll follow up when I’ve had some time to look at it.

  88. It looks like the new scheme requires a rewrite of the plugin. I’ll work on a 2.0 version that will be compatible with WP 2.8+ but will no longer work all the way back to WP 2.1. The benefit is that the plugin will look and act more like more modern widgets.

    I expect to have the new version done this weekend.

  89. Awesome Chris! Looking forward to it :)

  90. Hello Chris,

    I have been using your Samsarin WP plugin for over a year. It was working pefectly until I upgraded to WordPress 2.8.

    Now, I can’t get additional Samsarin widgets to appear at the Widgets Dashboard after the upgrade to WP 2.8.

    I hope that you can have your revised plugin published soon because I have some php scripts that need your invaluable Plugin.

    Thank you for this wonderful plugin that you have conceived.

    Windy

  91. Nice! Cant wait. I really love your plugin but i need to have more than one, and i just upgraded to 2.8 :-)

    Will it be upgradable from the admim inteface or do we need to manually DL and install the new one?

  92. New plugin with WP 2.8 support is up (in beta): http://www.samsarin.com/blog/2009/06/20/samsarin-php-widget-20-beta-1/

  93. Thank You Chris,

    Sliding over to download the beta version for WP2.8

  94. First, thanks for this great plug-in.

    Second, I just upgraded to Wordpress 2.8.2 and discovered that I cannot get new instances of the widget to show up in the available widgets area. Is anyone having a similar problem?

    Thanks,

    DLH

  95. I’m having the same problem requesting multiple instances but only getting one. - Great Plugin. Hope you can find a solution to this soon. Can’t wait to use it and give it a review on my blog!
    Thanx!

  96. @dlhitzeman, @richard

    Are you guys running Samsarin PHP Widget 2.0 beta 1?

    If not, this should resolve your issue. More info here:
    http://www.samsarin.com/blog/2009/06/20/samsarin-php-widget-20-beta-1/

  97. Cool. Thanks for the info.

  98. [...] sätt peka om sidor och inlägg.RSS Cloud Skickar ut en notis om att bloggen har blivit uppdaterad.Samsarin PHP Widget Samsarin PHP Widget lägger till en ny text widget där du har möjligheten att använda dig av [...]

  99. Got it working right away with 2.8.4

    It helped me get around a problem using the Custom Widgets plugin which allows widgets to show on certain pages.

    I needed to show a PLUGIN on certain pages and Samsarin allowed me to effectively call the plugin php code as a widget thus allowing me to use it with the Custom Widget plugin - phew!

    Hope that makes sense and thank you!

  100. [...] a div and style to your liking. If you would like to use it as a widget I recommend downloading the Samsarin PHP Widget, which allows you to add PHP to certain [...]

  101. Hello,

    Great plugin.

    Anyone found a way to use shortcodes with this plugin? my shortcodes work with all other widgets, except this one. You can see for yourself on the sidebar of http://shipkifarm.com/dev. The last widget “image of the week” is powered by Samsarin.

    Many thanks!

    Jacob

  102. I’ve posted a new version of Samsarin PHP Widget (version 2.1) to the wordpress widgets page that should fix the shortcode for you. Please let me know how it goes.

  103. Hi

    I have installed your widget it does exactly what it says it does, but I have one small problem I can only see one copy in my widget section of my admin page in wordpress. I have selected more copies and saved but they still do not appear. What am I doing wrong.

    Thanks

    John

  104. John,

    Are you using Wordpress 2.8.x? If so, the 2.1.1 plugin allows you to add multiple widgets. You can get it here: http://wordpress.org/extend/plugins/samsarin-php-widget/download/

  105. [...] этого нам нужен плагин Samsarin PHP Widget, который позволяет вставлять виджеты как с html, так и php [...]

  106. Does this work with WP 2.9.1? I tried using it, but it doesn’t seem to be working right. I am not able to drag the widget into my sidebar to use it.

  107. running 2.9.2. - only one instance of widget being diplayd, although multiple are selected. Same with Daikos widget. Any comments on this?

  108. I’m having problems being able to edit my existing PHP Widget since upgrading to WP 2.9.2. Please help! Also, cannot seem to see any new PHP widgets I add to the widget library. Any estimate on when this plugin will be updated to work with WP 2.9.2? Any help is greatly appreciated.

  109. Hi,

    I want it to display 2 columns of image, how can this be possible. Thanks.

  110. got it! using the new version! thnx

  111. Using Wordpress 2.9.2… Widget works, but only get one instance. I have it set to 5 and tried 10. Can’t get more instances and really need more. Please help if possible..

    Great Plugin/Widget!!!
    Thanks.

  112. Update - Plugin Version 2.1.1 works.. I’ll use this one until a newer version comes out for WP 2.9.2

    Again Thanks, and great Plugin!

Comment on this Article