PHP Code Widget
Plugin: PHP Code Widget
Version: 2.4
Last updated: 3 years ago.
Downloaded: 0 times.
Overview
The normal Text widget allows you to insert arbitrary Text and/or HTML code. This allows that too, but also parses any inserted PHP code and executes it. This makes it easier to migrate to a widget-based theme.
Download Now
Requirements
WordPress 2.8 or higher.
Features
- Like a Text widget, but works with PHP code.
- PHP Code must be in tags to function.
Installation Instructions
- Upload the files to the `/wp-content/plugins/php-code-widget/` directory
- Activate the plugin through the ‘Plugins’ menu in WordPress
Licensing
This plugin is licensed under the GPL Version 2 only.
Method to get support
You are free to email me, however I am also a moderator at the WordPress.org support forums, so you’ll find me there as well.
I was looking for something like this. I was so noob when I try to put php int text/html widget box and that doesnt works. Thanks for this.
I am a WP newbie, so I just followed the instructions and uploaded the execphp.php file and activated it thru the Plugins screen. So far, so good.
When I make a new post thru
1. VISUAL mode, is just printed on the screen (as text)
2. HTML mode, it becomes
Neither way is getting parsed, what am I doing wrong?
Thanks
This plugin doesn’t execute code in posts. It creates a sidebar widget which will run PHP code.
Oh okay, thanks for the quick reply, Otto!
Thank you for yr plugin. I had it installed fine on one site. I cloned that site, but on the cloned site none of the widgets are copied over. I copied ALL the files and SQLed the whole database. The ONLY file I changed was wp-config.php, pointing to the new database. Everything else works fine. I don’t know if the “problem” is with your widget, or with wordpress cloning widgets. I took special care with wp-options, ID=195. Since EVERYTHING is cloned except pointing to the new database, I’m at a loss to understand why 1 installation would show the widgets, and the other not.
The new installation had all the plugins correctly installed, also.
anyway thank you again, for yr nice widget, as wp itself is very php, it’s kind of strange that it is not built in into the source code.
Moving blogs around is finicky in WordPress in general. If the URL is different between the two sites, search through for where that URL might be in the database. Some of the rows of the options table incorporate it in as a hash or plaintext in the key names.
Will this plug-in let me add html to a widget _title_?
Thanks.
No, it won’t. It only processes code in the body of the widget. Titles get stripped of tags in the core code.
Bummer. Thanks for responding at least.
I am completely new to WP and might I say, completely lost too. After 3 years of blogger, this is a very new playing ground. My feeds are wrong, my stats are wrong, and I need to fix a few things.
Was trying to customise my feedburner feed to include images and make it pretty, but I cannot find a custom feed php in the theme I have installed. It’s the pixel happy child theme. Should I be looking somewhere else. Code is scary for me, but I would love some direction. Many thanks for reading this…
Cheers,
Deeba
vindee@airtelmail.in
Themes don’t control the feed.
Look for plugins to add on the changes and features you want, instead of trying to code them yourself: http://wordpress.org/extend/plugins/
I have used your plugin for quite some time maybe more than a year. I am happy with it, thanks, i use it to get weather data from my weather station that publish data in xml. Since aprox 2 days ago my site (http://climaya.com) became unresponsive, it was slow and was not able to deliver the data, I found out after disabling your plugin it became responsive again, wp-admin site and other sites in server loaded ok.
What could be the problem or where to check, ? I implemented same in other wp site, for the same purpose and there is working fine.
Norman
You’d have to look in your own code. The PHP Code widget is basically identical to the normal text widget, with an eval that makes it run the PHP code. There’s nothing special about it. Any errors you encounter with it happen from your own code in it, not from the widget itself.
Otto, I’m from Brazil, there are days I have been looking for a way of NET to decode a
code, so I thought, you are one of the fastest decode … I know here where
I’m posting has nothing to do with it, but if you can help me
decode it, stay grateful. http://pastebin.com/j9L9zrxQ and forward to email
flaviounai@gmail.com
Use the decoders: http://wordpress.org/support/topic/how-to-decrypt-an-encoded-theme
Getting this after recent WP upgrades
Fatal error: Call to undefined method WP_Error::get_item_quantity() in /public_html/2011/wp-content/plugins/php-code-widget/execphp.php(44) : eval()'d code on line 8
Could you please you fix the widget plugin code? That will be worth a beer definitely 😉
There’s nothing wrong with the widget. The error lies in whatever code you put in the widget. That’s what the “eval()’d code” bit means.
Hi Otto, I love this widget; I’ve been using it for 6 months on my website above to fetch my Twitter feed with no problems.
Now after the most recent WP upgrade, I am also getting a similar error to @ommunist above is getting. (Warning: file_get_contents(http://search.twitter.com/search.atom?q=from:ChicSteals&rpp=1) [function.file-get-contents]: failed to open stream: Connection timed out in /public_html/wp-content/plugins/php-code-widget/execphp.php(44) : eval()’d code on line 26
Are you sure there’s no issue with the widget?
I haven’t changed anything in the widget’s code at all or installed any new plugins that could account for this error, but now it’s not fetching my Twitter feed as it used to after the WP upgrade to 3.2.1. (Which is the only thing that I could think of to account for this behavior)
Thank you for all your work on this!
Yes, nothing is wrong with the widget. Your own error says so.
Whenever you see “eval()’d code”, that’s telling you that the error is in the code you have put into the widget. Your code is what is being “eval()’d” here.
So the error is in your own code, not in the widget itself.
Your specific error is occurring because your site can’t get a response back from Twitter. Nothing to do with the widget or with WordPress.
Carly, if your PHP code stopped getting a response from Twitter at the end of August, then was due to Twitter’s shutdown of the API-type that your code used (details, http://mashable.com/2010/06/17/oauthcalypse-delayed/)
Since Code-Widget just runs the PHP you feed it, you’ll have to update your PHP to match. An easier method might be to find a Twitter widget in the WP plugin directory that was updated.
Thank you so much Mike! After posting on here, I spent about 4 hours of Googling the issue and I finally figured out that Twitter had shut that API-type down and that’s why the PHP code widget wasn’t fetching the feed.
Unfortunately I couldn’t find any other PHP code that would work with Twitter, so finally had to abandon the PHP code widget. I installed a standard Twitter widget through WordPress, but am still lamenting my old one as I was displaying the Twitter feed inside a speech bubble coming from my Twitter avatar, which I really liked.:-(
Thanks for your info!
After moving my site to another server, your fantastic plugin stopped executing the php-code. All other text workd fine. Not the php. Even a simple code like
I’ve tried other php-executable-widgets, but it’s the same result – so it’s not your plugin it’s server related.
Do you have any experience about this and perhaps a solution? 🙂
/Raffe Bergwall
The plugin uses eval() to run the code. Some PHP setups have eval() disabled.
How can we use this to display Contact Form 7 in widget. I mean the Shortcode doesnt work by default in “Text Widget”
Hello Otto,
Thank you for wonderful plugin !
I noticed that the php code widgets disappear when I move my website to another server. They’re not visible anymore in the widgets section of WordPress.
I still can add new php widget but the old ones are deleted.
Have you a suggestion ?
Thank you for your help.
Best regards.
Widgets of any sort don’t migrate between servers. They’re not part of the export/import process.
Thank you for your quick reply Otto !
All other widgets are present except php code widgets…
Widgets of any kind are not included in a WordPress export/import operation. The PHP Code widget is not special in this respect. NO widgets will be preserved in moving a site from one server to another. It simply doesn’t work that way.
If you migrate the database as a whole, then yes, widgets will be preserved in such a transfer. However, if you don’t activate the plugin on the new site before doing that, then any widgets made by plugins will get removed on the first load of the page, because the code for them isn’t active on the new site yet.
The PHP Code widget is almost exactly identical to the built in Text widget, with only one minor change to allow PHP Code to work.
O i think i didn’t explain very well.
I didn’t export, i made a copy of my site in order to install it to another server…
“Made a copy of the site” is so vague as to be useless. What do you mean by “made a copy”, exactly?
If you copied the database, then widgets would indeed get transferred, but widgets created by plugins would be removed on the first load of the new site because the plugins on the new site were not activated yet. If the plugin is inactive then the widget is missing and so WP will remove the widget from the sidebar when it sees that.
I made a copy of the DB and of the files.
All the plugins are active. All the widgets appear on the transfered site except the PHP code widget.
I needn’t to active php code widget because its code is written in functions.php.
Could it be the problem ?
thank you for your help Otto !
Well, if you’re not using the plugin and have put code in functions.php instead, then I have no idea what you’re doing or why you’re having trouble.
Regardless of this, this is not a problem with the plugin. It is not a bug. It will not be “fixed”.
Ok, thank you anyway
thanks for your plugin
I’m trying to use toggles in the php widget but the tricky part is that they are loaded from a php file called as an includes.
in the functions.php I added
add_filter(‘widget_text’, ‘do_shortcode’);
add_filter(‘widget_execphp’, ‘do_shortcode’);
Loading the php file works. Manually entering the toggle in the widget works (text widget and php widget). but the toggle doesn’t work if it is included in a file. any idea why, and how to resolve that? I know it isn’t really a ‘problem’ with your plugin but I thought you might know. regards,
Do blogspot have same gadget like this plugin where I can paste my php code.
[…] none Options All -Indexes -LiensLe site de l’auteur du compteur NotoonLe site d’Otto PHP Code WidgetPage de téléchargement-Je vous recommande aussi la lecture des sujets suivants :Extension Contact […]
Do you know a similar script that allows placing the original php code in posts or pages. Just like yours.
Ty
Wow.. thank you for sharing this plugin.. php code widget is better for me..
I inherited Admin on a site, looking to do some PHP.
We have your plugin installed and even an empty widget positioned in a sidebar.
I had a page with short PHP script via Exec-PHP plugin but that caused problems with my Editors’ ability to edit all posts, so I took down the page and Deactivated Exec-PHP
My page presented a form to gather an author’s name, then built shortcode for another plugin to display links to the last 10 posts by the author.
The form specified action=”” method=”post”, which is okay, since each page has it’s own URI to satisfy the Action target.
If I coded this in a your widget, would it work?
Thanks,
RayS
[…] cookie to display an appropriate message on your website. I used this somewhat hectic code within a PHP Code widget, which works reasonably well. You can visit this blog’s old address to see it in action. Line […]
Hello Otto,
Thanks for your perfect plugin. I’d like to use it to include our address information on all our sites. However PHP Include doet not seem to work. It still is blank.
The code I use is:
Any idea?
Thanks in advance…
You can’t include HTTP addresses. That isn’t what include does.
I want to use a function to pull out (&style) all contributing authors
I have the function code ready, but dont know how to execute it via this widget, so that i can see the author list in the sidebar
Function : list of authors
http://homepreneur-online.com/author/deepagovind
Scroll down you should see list of other authors
I want a simiar list (one below the other, list ready) on the sidebar
How do i get the widget to call a function in my theme/stylesheet directory
or
write the function within the phpcode widget’s text-code-area
i got question:
dose your plugin suport jquery scripts, javascripts!?
Hi Otto,
I tried to include a simple, external php file, but nothing happens. I used this code:
File.php refers to a (working!) php file on a different website. The file does one thing only: it retrieves the sum from a database table. The code looks like this:
So, quite simple actually. What could be wrong?
Your code didn’t post. As it says in the comments, use the php tags for posting code here.
Most likely, the problem is that your code uses global variables somehow and doesn’t declare them as such. Code in a widget will run in a function context, not in the global context.
I have tried it personally, this code is fully functional in widget section. But i want to use it in post and pages. Can you tell me, how to do it or email me the way to do it.
You don’t. It’s a widget.
Is there any way but without plugin, i can execute the php code in post and pages.
You can use some other plugin for that, this plugin does not do that.
Do you have any plans to include syntax highlighting and line numbering in a future version? Perhaps something like the settings panel shown here: https://wordpress.org/plugins/syntaxhighlighter/screenshots/ but for use in the widgets edit view, not in a public post or page.
[…] PHP Code Widget » Otto on WordPress – Plugin: PHP Code Widget Version: 2.2 Last updated: 2 months ago. Downloaded: 432,488 times. Overview. The normal Text widget allows you to insert arbitrary Text …… […]
Otto, thanks for a terrific widget. Other solutions permit use of shortcodes, but what I really like best about your plugin is that I can use my php code right in the widget. The shortcoming is that this only works in widgets, not posts or pages. Do you have, or know of, a similar plugin that will work on posts and pages?
Great plugin, but on multisite, only works with network administrator role. Otherwise, when you save the widget, you lose the php codes. Administrator role are insufficient.
Hi, Thanks for the great widget, i was wondering if its possible or what’s the right way to use required_once() function, my aim is to code inside a code editor for more flexibility, but when i used requiered_once() function wordpress doesnt identify its own functions
Hello Otto, great plugin! I’m having a problem where the php code works just fine while logged in as admin but when I run it logged out then it stops working, maybe doing something wrong but here´s what I’m doing: I have a form (Get) on one page where the user inputs a number, then on the next page I’m using that number to display some info; I can see the number get passed from one page to the other and when I’m logged in as admin everything works OK and the echo shows the correct response but then when logged out I try again and instead of runing the if/else, it echoes the responses in both cases. Hope you can help me, thanks.
Hi, thank you for your plugin. Very, very useful. I’m using it to add next and previous post php snippets on blog pages (using Elementor page builder).
But I’m having a problem…
If I am viewing the page while logged in, I can view the next/previous links. They work great. But when I’m not logged in, the next/previous links don’t display on the page.
I realise the problem could be caused by a variety of things, but have you heard this problem before? Do you know of any reason or any fix?
By the way, this is a multisite installation.
Best wishes
Ian
Most likely, you’re using a caching plugin of some sort, and so you see the cached version of the page when you’re not logged in. Clear the cache.
Hi Otto
i have e error in my wordpress installation
Deprecated: Function create_function() is deprecated in /var/www/clients/client37/web67/web/wp-content/plugins/php-code-widget/execphp.php on line 62
Can you help? Thanks
Turn off the PHP display_errors setting.
seriously…?
– add_action(‘widgets_init’, create_function(….));
+ add_action(‘widgets_init’, function() {….});
No, that will not be happening.
1. Changing to an anonymous function would render the plugin incompatible with PHP 5.2.
2. This plugin will receive no further updates. You should not use the PHP Code Widget. You should actively stop using it, in fact. I wrote a whole post on how to stop using this widget: http://ottopress.com/2017/on-the-topic-of-that-pesky-widget/
I am able to include some php files like:
But when I make a copy of the folder and try this statement, the include does not work.
Any clue?
I am able to include some php files like:
But when I make a copy of the folder and try this statement, the include does not work (blank screen).
Any clue?
[…] 版本 2.3 | 作者:Otto | 造訪外掛站台 […]
This plugin has a problem now with the latest version of wordpress. Adding php code in widget section with code is no longer saving. Saving button keeps animating, but nothing happens. If we remove code then its saves. Therefore we can not add any php code. Please fix this bug.
I’m using your plugin but also need to run a shortcode to display certain content for a period of time. Is there the ability to parse the shortcodes in your plugin?
Is there any plans to fix this plug in so it will work with WP5.7?
The plugin works fine with WP 5.7. However, it is not recommended that you use this, and instead consider an alternative for your needs. Running PHP code from the database is not a particularly good idea.
This plugin is not working with PHP 8.0
thrown in /var/www/skatox/htdocs/wp-content/plugins/php-code-widget/execphp.php on line 62
Fatal error: Uncaught Error: Call to undefined function create_function() in /var/www/skatox/htdocs/wp-content/plugins/php-code-widget/execphp.php:62
Stack trace:
Lots of things don’t work on PHP 8.0 yet. I have no plans to fix it anytime soon.
Stick to PHP 7.4 for now. PHP 8.0 is too new and untested all around to be usable in production at the moment.
This plugin is not working with PHP 8.0
PHP Deprecated: Function create_function() is deprecated in wp-content/plugins/php-code-widget/execphp.php on line 62
p.s. PHP 8.1.0 – just released
Correct, and I have no plans to update it.
Stop using this plugin. I wrote about how to stop using it almost 4 years ago now: http://ottopress.com/2017/on-the-topic-of-that-pesky-widget/
This plugin made sense back when migrating theme sidebars to widgets was a new thing, but that hasn’t been since WordPress 2.5 or so. Everybody should stop using executable PHP code stored in the database. Either write a custom plugin, or just switch to using blocks instead, which is much saner, safer, and a solid path forward.