MyCustomWidget

What does this Plugin do?

Download MyCustomWidget“MyCustomWidgets” provides a powerful alternative to the wordpress standard “text”-widget-template. After activating this plugin you will be able to create own widgets and to include them into your wordpress theme by using the wordpress administration interface. Inside of your CustomWidgets you can use html- and php-code. By using filters (which you can define freely as well) you can define where your CustomWidgets should show up.

UPDATE: It is now possible to place “CustomWidgets” outside of the sidebar by using custom tags.

Update: The plugin was tested up to WP 3.0!

Where can I download it?

Current Version: MyCustomWidget 2.0.5 – » download latest version

Why is there so much text below?

Because the author of another cool widget hates cool plugins that are badly documented. ;)
In addition to that, there have been some questions how to use the plugin. Therefore I added this documentation. If you have a question about the plugin please first make sure you refer to the latest version of the plugin and the question is not answered on this page or in the comments section of the plugin homepage.

Table of Content

  1. Introduction
    1. Motivation
    2. Features
    3. Concept of MyCustomWidget
    4. Registering Widgets with WP 2.8
    5. Tutorial
  2. Installation
    1. Requirements
    2. Installing the Plugin
    3. Upgrade from previous versions
    4. Deactivating the Plugin
    5. Uninstalling the Plugin
  3. Usage
    1. Using MyCustomWidget
    2. Configuration
      1. Filter Section
      2. Miscellaneous Section
      3. Layout Section
      4. Administration Section
    3. Create CustomWidget
      1. Add/Change
      2. Preview
      3. Debugging mode
      4. Assign Plugin
  4. About Security
  5. Troubleshooting
    1. Incompatibilities to other Plugins or Themes
    2. Limitations
    3. Reporting Bugs
    4. Test to assert Plugin functionality
  6. FAQ – Frequently Asked Questions
    1. Why does the plugin fail with an eval() error when executing my code?
    2. How can I just print out PHP code and don’t execute it?
    3. How can I include PHP files?
    4. Whole site crashes because of error in my_custom_widget_classes.php

Introduction

Motivation

While building up my WordPress blog I changed the code of my sidebar several times. Whenever I used a new plugin that should offers content in a sidebar I had to change the coding again. When WordPress offers the ability of widgets I liked to use this functionality as well. Unfortunatelly this would have meant to loose all changes I had made in the past. Of course there is the WordPress build-in text-widgets and several plugins that you can use to create own widgets. Nevertheless I was not happy with these solutions because:

  • I’d like to put php- and html-code in my widgets
  • I’d like to define own names for my widgets (Who want’s to use widgets like „Text Widget 1“ to „Text Widget 99“?)
  • I’d like to use filters because not all widgets should be available on all pages

Back in 2007 I decided to write a small plugin that allows me to put these additions in small widget-pieces. Long story short: I improved this pugin and decided to release it under GNU Public Licence (GPL).

Features

  • Define own widgets through powerfull widget-configuration-panel
  • Define filters through plugin-option-page
  • Deinstallation routine to delete all data that has been created by this plugin
  • Backup routine for widget data and plugin options
  • Preview functionality for all CustomWidgets
  • Debugging functionality to locate coding errors (beta-version)
  • apply_filter-functionality can now be activated within CustomWidgets
  • Widgets are also available through custom tags such as <!–MyWidget–> and can therefore be used outside of the sidebar as well (apply filter)
  • Dublicate/copy existing widgets

Concept of MyCustomWidget

Technically MyCustomWidget executes code inside of <?php ?> tags by just wrapping your whole text into ?> <?php tags and hand it over to the PHP eval() function. By that no parsing of your code needs to be done by the plugin itself. It is not recommended to use the plugin in WordPress installations with untrusted users.
All widget-data is stored in the wordpress option table.

Registering Widgets with WP 2.8

In general a widget has to be registered/announced before it can be added to a sidebar. With WP 2.8 the concept of creating and registering widgets changed. Instead of registering a single function that generates the widget content, the developer of a widget has to declare a class (that extends a predefined class of WP2.8) that represents the widget.

While WP 2.7.X added the widget to a sidebar, WP 2.8 generates an new instance of the widget-class whenever a widget is added to a sidebar. This means: Within WP 2.8 the same kind of widget can be added several times.

If you take a look at the Widget “MCW 2.0 Addon” (the code is located in file my_custom_widget_addon.php) you will find a pure WP2.8-Widget as it has to be (according to the WP-developers).
Unfortunatelly it was not possible (yet/for me) to re-implement all functionalities of MCW 1.9 by using this new technique (e.g. Backup, Preview, making widgets available outside of a sidebar, downward compatibility).

That’s why the plugin just generates the class definitions on-the-fly whenever the widgets are saved. The result is stored in file my_custom_widget_classes.php.

Other plugins
Nowadays there are a lot of similar plugins around which are doing similar work as this plugin. If MyCustomWidgets functionality does miss some feature you are desperatly seeking, you may want to take a look on one of the various WordPress plugin databases or drop a feature request.

Tutorial

Creating a simple widget:

Installation

Requirements

You need the following software to be installed on your webserver in order to run the Exec-PHP plugin:

  • A running installation of WordPress 2.0 or higher
  • A WordPress theme that allows to use widgets.*
  • The MyCustomWidget plugin

* If your theme does not support widgets yet, you can adjust your theme like described here »

Installing the Plugin

If you have ever installed a WordPress plugin, then installation will be pretty easy:

  • Download the MyCustomWidget plugin archive and extract the files.
  • Copy the mycustomwidget directory into /wp-content/plugins/
  • Activate the plugin through the ‘Plugins’ menu of WordPress

Upgrade from previous versions

Usually if not specifically mentioned on this page you can upgrade from a previous version of this plugin by simply deactivating the plugin through the ‘Plugins’ menu of WordPress, replacing the content of /wp-content/plugins/mycustomwidget and reactivating the plugin again. An upgrade should not migrate settings of an older plugin version.

Deactivating the Plugin

Deactivating the plugin will cause your CustomWidgets to disappear. Don’t panic! Your widget content will not be erased until you deinstalled the plugin.

Uninstalling the Plugin

deinstallation For uninstalling the plugin you should start the deinstallation routine on the plugin-option screen and simply delete the MyCustomWidget directory from the /wp-content/plugins/directory afterwards. You even don’t need to deactivate the plugin in the WordPress admin menu.

Usage

Using MyCustomWidget

With MyCustomWidget you can create widgets that contain php and html-code. All other features are listed in the correspondend section written above. The following section will descripe how to use these features.

Configuration

The plugin comes with its own option menu that is accessible through ‘Options / My Custom Widget’s. The option menu is only accessible for users that do have the ‘edit_plugins’ capability. This is usually only assigned to the Blog Administrator. If you have disabled Javascript you will not see or only see parts of the Plugin Option menu.
The option menu is divided into four parts:

  • the filter section
  • the miscellaneous
  • the layout section and
  • the administration section

Filter Section

filters In this section you can define filters which you can use in your CustomWidgets.
You will have to define at least one filter to make your widget visible. Therefore several default values have been defined. The most important filter should be ‘all’.
The whole filter-handling is quite easy. A filter is defined by a name and a php-code snipped which can be interpreted as a bool-value (true or false). Please visit the official WordPress-side (Conditional Tags) if you want to know which values can be entered here. If you have added a new filter the filter will be available for all CustomWidgets immediately.

If you are new to PHP and you do not even know what I am writing you should use the default filters and leave this section as it is.

Miscellaneous Section

Misc-Settings 1.6
In this section you can define several default values that will be used by the plugin. Currently there are 4 options available:
With release 1.1 I added information which should explain the options that are available. These information become visible when you click on the small question sign on the very left.
The addition HTML-code option will give you access to an additional code-box. All code in this area will be interpreted as pure html code. This box is a legacy from a former version of this plugin. If you do not have to you should deactivate this option. I think I will delete this additional code-box within one of the next releases. The other options are improvements suggested by wordpress-users.

To save any changes in this section you will have to press the save-all-button which is situated under the layout section.

Layout Section

layout In this section you can define several layout parameters. As always I added a short description of the functionality inside the plugin. Therefore I think these options are self-explanatory.

Administration Section

administration In this section you can Reset the default plugin settings, create or restore a backup and start the deinstallation routine. Due to the fact that these buttons should be used very carefully there is an additional checkbox which should be ticked to commit any actions.

A backup will create a new database record in the WordPress option-table.

Create CustomWidget

To create an own CustomWidget is quite easy. Just proceed as follows…configuration

Create/Change Widget

First you should ask yourself what the widget should do.

  1. What should be the widgets name?
  2. Do you want to add HTML or PHP code?
  3. Where should the widget be available?

1. The widgets name should be unique. If the widget has the same name as another existing one the custom or the other widget will not be shown. The plugin checks wether the name is unique regarding other widgets created with MyCustomWidgets. (I did not want do force a prefix like “mcw_”. Nevertheless you should think about that and use a name which is not used by another plugin-specific widget.

2. You can use both: HTML and PHP code. You can even combine both kinds by using the normal php-tags <?php and ?>. If a code works somewhere else on your side it should works within your CustomWidget as well. Just choose if your code should be interpreted as HTML or PHP-code.

3. Not all widgets should show up on each page. Below the code area all available filters are listed. If you do not know what these filters will mean or if you need to create your own filters you should visit the filter section of the plugin option page. Please keep in mind: You have to create the filter first and tick it afterwards. You can tick several filters. The widget will be displayed if one (or more) of the selected filters is true.

Preview Widget

Once you created and saved the plugin you will be able to start the preview by clicking on the lens-symbol.
The widget-code and the widget-content will show up on the very bottom. Please be aware that the stylesheets that are used inside of the admin panel is different to the one used on your WordPress blog. Therefore the layout can be different.

Debugging mode (beta)

debug The debugging mode works as follows: It splits the widget code into HTML- and PHP-pieces and lists this code. As a matter of fact if-statement that include html-code will not interpreted correctly. Therefore the debugging-mode is not a all-in-one device suitable for every purpose. To start the debugging mode you will have to tick the debugging-checkbox and click on the preview icon (the lens) afterwards.

Assign Widget

Once you saved the widget a new widget entry will appear under Presentation –> Widgets. Just add the widget to your sidebar via Drag’n'Drop.

About Security

By using this plugin a user can use the full PHP API and WordPress API. There are no restrictions to execute only certain subsets of functionality. Allowing your users to create or change CustomWidgets will mean to allow executing PHP code and will expose your WordPress installation in specific and your server installation in general. By that a user can easily take over your blog and your server. If in doubt do not install this plugin as long as there are no additional security features available.

Troubleshooting

Incompatibilities to other Plugins or Themes

Currently there are no known incompatibilities to other plugins or themes.

Limitations

Most likely the debugging functionality will not work if you are using if-statements. Apart from this there are no known issues.

Reporting Bugs

You can post bug reports to the comments. Before doing this make sure your PHP script is running properly in a separate file. If it does, assure that you did not hit the “Globals” issue. If you still think it’s a bug, keep in mind that WordPress’ commenting system is not build to write unescaped code, so better convert it to the correct XHTML entities before commenting here, point to the code using an external link or get in contact with me by email (wordpress@this-domain-name.de).

Test to assert Plugin functionality

Following is a list of tests that were made by the author of the EXEC-PHP-Plugin to assert his plugins functionality. On the left side the PHP code taken directly from the tests is written. On the right side the live output generated by the Exec-PHP plugin is shown. If you view this documentation as a static HTML file obviously the PHP code isn’t executed and will look messy. Because of the content of this test, this page will not verify as XHTML. If you think, your favorite PHP plugin is better than this one, try out all the tests below and see if this works correctly.

# Code Output
1
<?php ?>
2
<?php echo "a?>1"; ?>
a?>1
3
<?php echo 'b?>1'; ?>
b?>1
4
<?php echo "a?>2"; ?>
a?>2
5
<?php echo 'b?>2'; ?>
b?>2
6
<?php?>
7
<?php echo"a?>3";?>
a?>3
8
<?php echo'b?>3';?>
b?>3
9
<?php echo"a?>4";?>
a?>4
10
<?php echo'b?>4';?>
b?>4
11
<?php echo "c";?>1";?>
c1″;?>
12
<?php echo 'd';?>1';?>
d1′;?>
13
<?php echo "c';?>2";?>
c’;?>2
14
<?php echo 'd";?>3';?>
d”;?>3
15
<?php
echo "impressive\n '";
echo 'string\' "';
echo "\n\thandling\"";
?>
impressive
’string’ ”
handling”
16
<?php if (1) { ?>
<b>Handle THIS!</b>
<?php } else { ?>
<i>Handle THAT!</i>
<?php } ?>
Handle THIS!

FAQ – Frequently Asked Questions

Why does the plugin fail with an eval() error when executing my code?
If you experience a PHP error message like ‘Parse error: syntax error, unexpected '?' in /www/htdocs/wp-content/plugins/mycustomwidget/my_custom_widget.php(504) : eval()'d code on line 1 ‘ then it’s time to repair your PHP code. If you are unsure where your code breaks you can use the debugging functionality or run it in a separate file to punch out all bugs and afterwards copy the code into your article or widget.

How can I just print out PHP code and don’t execute it?
If you just want to print out code and don’t want to execute it, e.g. like it is done here on this page, you have to make sure to convert your code to the correct XHTML representation. To do so you have to escape your whole code or at least change your tags from <?php ?> to &lt;?php ?&gt;.

How can I include PHP files?
If you want to include a php-file you should be aware of the fact that each relative path will start in the root directory of this plugin which is ‘/wp-content/plugins/mycustomwidget/’.
instead of using a relative path you should use a statement like
<?php require_once(get_option(‘home’). ‘/example.php’); ?>

How can I support this plugin?
First of all you can rate this plugin on wordpress.com. But of course you can also make a donation.

Whole site crashes because of error in my_custom_widget_classes.php
If you receive an error such as Parse error: syntax error, unexpected T_STRING, expecting ‘{’ in /wp-content/plugins/mycustomwidget/my_custom_widget_classes.php on line 10 there was an error
during the generation of the widget-specific classes. This might happen when you use prohibited characters in your widget name. Please delete the content of my_custom_widget_classes.php and rename you CustomWidget. Of course you should contact me (e.g. by leaving a comment). Usually I try to catch all prohibited characters.

Donation

309 Comments

  1. Hi David,

    the first issue is a very silly bug. This is because widgets now have to be defined as classes (and as you might know, class names cannot work with spaces). I will release the bugfix on friday or saturday.

    I am not sure what the second issue is about. Adding widgets to a sidebar works fine for me. I’ll take a look at it tomorrow.

    Sorry for the trouble…

  2. Janek,

    I was able to successfully drag and drop the widgets in Safari. I usually use Firefox, which is where I was having the trouble.

    David

  3. Hi David,
    thanks again for the feedback. I fixed both bugs and the upgrade issue with release 2.0.1 that has just been released.

  4. Guido

    Hi,

    Great plugin which I have just installed and am using WP 2.8.

    I am curious why the option ‘use copy feature’ says it is no longer needed for WP 2.8?

    Thanks

  5. Hi,

    Thanks… ;o)

    In general a widget has to be registered/announced before it can be added to a sidebar. With WP 2.8 the concept of creating and registering widgets changed. Instead of registering a single function that generates the widget content, the developer of a widget has to declare a class (that extends a predefined class of WP2.8) that represents the widget.

    While WP 2.7.X added the widget to a sidebar, WP 2.8 generates an new instance of the widget-class whenever a widget is added to a sidebar.

    This means: Within WP 2.8 the same kind of widget can be added several times. All WP has to do, is generating another instance of the widget class). If you take a look at the widget menu of WP 2.8 you will see that widgets do not disappear from the “widget-repository” when you add them to a sidebar.
    Consequently a widget does not have to be copied anymore!

    The only use case I can imagine is the need to make a “non-custom” widget appear outside of a sidebar. That’s why the feature is still available.

    In Case you want to know how the plugin works:
    If you take a look at the Widget “MCW 2.0 Addon” (the code is located in file my_custom_widget_addon.php) you will find a pure WP2.8-Widget as it has to be (according to the WP-developers).
    Unfortunatelly it was not possible (yet/for me) to re-implement all functionalities of MCW 1.9 by using this new technique (e.g. Backup, Preview, making widgets available outside of a sidebar, downward compatibility).

    That’s why the plugin just generates the class definitions on-the-fly whenever the widgets are saved. The result is stored in file my_custom_widget_classes.php.

    Cheers

  6. I can’t update because I keep on getting the following errors:

    rning: eregi_replace() [function.eregi-replace]: Invalid preceding regular expression in /hermes/bosweb/web219/b2190/sl.dpoverlord/public_html/wp-content/plugins/mycustomwidget/my_custom_widget_functions.php on line 882

    Warning: eregi_replace() [function.eregi-replace]: Invalid preceding regular expression in /hermes/bosweb/web219/b2190/sl.dpoverlord/public_html/wp-content/plugins/mycustomwidget/my_custom_widget_functions.php on line 882

    Warning: eregi_replace() [function.eregi-replace]: Invalid preceding regular expression in /hermes/bosweb/web219/b2190/sl.dpoverlord/public_html/wp-content/plugins/mycustomwidget/my_custom_widget_functions.php on line 882

  7. I was not able to reproduce your error. Might have something to do with your character set or the php version. Nevertheless I changed the involved function. I hope release 2.0.3 will solve your problem.

    Best Regards
    Janek

  8. linus

    Hi Janek , a really nice plug you have in the MCW.

    I upgraded to wp 2.8.1 and the plug won’t allow me to post comments? I’m not sure this has anything to do with your plug, but I am able to post comments if MCW is deactivated, and not, if it is activated. it’s like turning on and of comments at the same time… just wanted to give you a heads up. if it is a real problem.

    /Linus

  9. Hi Linus,

    I just upgraded as well. As when you can see (hopefully you can see this comment ;) ) everything works fine. Consequently I would assume that your problem is caused by a specific CustomWidget of yours. Have you tried to remove your customwidgets one by one?

    Maybe you can post the code…

  10. Randy

    Janek,

    I’ve used your widget and 2.8.1 and it works fine with my html code. I’m trying to use your code as a basis for my own widget and after uploading it, I’m getting the error ‘plugin does not have a valid header’ when I try to activate it. Do you know what this is? Many people are asking about this error on other plugins.

    -Randy

  11. And as you can see in this second comment, adding comments does also work when you are not logged in as an administrator…

  12. Hi Randy,
    without having a look at your plugin I cannot be sure, but the error message sounds like you forgot to add the header information to the main-file of your widget.

    <?php
    /*
    Plugin Name: My Plugin
    Plugin URI: http://www.mydomain.com/myplugin/
    Description: Short description of the plugin's functionality
    Author: Homer Simpson
    Version: 1.0.0
    Author URI: http://www.mydomain.com/
    */
    ?>

    Did you take a look at the official WP-page? http://codex.wordpress.org/Writing_a_Plugin

  13. Randy

    Janek,

    That was the problem. This is a widespread problem with people trying to load older widgets. Doesn’t 2.8 have the capability for downward compatibility?

    Thanks,
    -Randy

  14. linus

    Thanks Janek! Your absolutely right. I guess even the noob can sometime make giants fall ;)

    I hope this is not to embarrassing on my part since it’s just a ‘Recent post’ widget I found somewhere, but here is the code that caused the problem, when i removed it everything worked fine – the problem for me is that it worked fine alongside with 5 other scripts in ‘sidebar.php’ that I ported to MCW, and that’s why I just assumed it would work in MCW. I guess I just prolly ‘ugly’ hack it back in the sidebar.php and everything will be fine… :)


    get_results(“SELECT ID, post_title FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_date_gmt
    post_title == ”)
    $post->post_title = sprintf(__(‘Post #%s’), $post->ID);
    echo “<a>ID).”‘>”;
    the_title();
    echo ‘</a>’;

    }?>

  15. linus

    ok, small update on the issue of not being able to commenting. There seems to be a conflict between your plugin and the WP-Postviews plugin in wp 2.8.1

    I had them both up and running before in 2.7 and 2.8) , and now they don’t seem to work together.
    I posted at his forum http://forums.lesterchan.net/index.php/topic,3901.0.html

    Lester seems to be very ‘threaded’ so I hold my thumbs if he can do something. and he has done some amazing work, but to be honest I’ve already started looking for another postview plugin. is it realistic that he can keep track of 18 plugins? I don’t know. it’s so messy in wordpress…

  16. linus

    sorry to bother you again, I guess the problem was that I did a get_most_viewed() function call from Lesters plugin within the MCW. Once that call was remove, they where best friends again.

    Sorry for any inconvenience and once again thanks for a great plugin.

  17. @Randy: In my eyes, this has nothing to do with downward compatibility. As far as I know plugins that have been distributed through the wordpress.org. But we will never know for sure… ;)

    @linus: I took a quick look at the PostViews-Plugin. This seems to be the old problem with the loop. Whenever someone creates an own loop within a widget or change global variables that are used within the loop, it will have an effect on the comment section (which is generated after the sidebar content). I’ll take a closer look at the plugin. Maybe there is a way to avoid this effect. For now, I am glad that everything works for you.

  18. Okay,
    I left a post in the forum you were talking about.

    Maybe he will change the function you are using…

  19. I have not ever written php code before. I have MCW installed & activated, but I don’t know how to write the code I need for what I’m trying to do.

    I have 18 different categories in my store website. I want each page to be associated with a corresponding category. For example, I have categories named start-up, opportunities, financial, forms, and marketing. I want a page for each of these, separately.

    I want each page to contain the last 25 posts to that category…I am using the WP e-commerce plug-in

    Can you tell me what I need to write..maybe write just one for me, and then I could use it as an example to do the rest?

    As I am reading on this subject, I see something about having to write a php file…do I need to do that as well as customizing the widget, or will it be automatically created when I customize the widget?

    Thank you for any help you may be able to offer.

  20. Hi Debi,
    I am not sure if I understand what you are trying to do. It sounds to me like you are mixing some problems.

    I also have to admit that I have never used the e-commerce-plugin so far and I am not sure if you are trying to solve a specific problem with the e-commerce-plugin or with wordpress or with the MyCustomWidget-plugin.

    Maybe you can specify your problem or provide an example.

    Creating categories should not be a problem in wordpress. Each post can be added to these categories.
    –> http://www.howintheweb.com/store/wp-admin/categories.php

    The number of posts that are displayed can be defined in the corresponding wordpress setting section as well
    –> http://www.howintheweb.com/store/wp-admin/options-reading.php

    I you are trying to create a widget with MyCustomWidget that only appears in specific categories you might want to give me a specific example. e.g. you can use the filter functionality
    –> http://www.howintheweb.com/store/wp-admin/options-general.php?page=my_custom_widget_functions.php

    If you are looking for support for the e-commerce-plugin I would ask you to open a thread in the coresponding forum. (http://www.instinct.co.nz/forums/)
    You might also take another look at the existing widgets. I am sure that the plugin provides some valueable widgets out-of-the-box.

    Best Regards
    Janek

  21. Unfortunately MyCustomWidget – or one of my widgets – is breaking my blog. For some strange reason, when the widget is activated, the tags, feed and bio for a post are confused (i.e. not the right tags, feed and bio attached to the post). When I deactivate the plugin, all is well.

    Any thoughts what could be causing this.

  22. Hi David,

    I do not believe that the plugin itself breaks your blog. Please try to remove the CustomWidgets you added one by one.

    I guess one of these widgets contains code that effects the loop… and the tags, feed and bio are steered by this loop. You might want to take a look at this comment I wrote some time ago: click here

    Janek

  23. That makes sense Janek, and was my first thought. However, even if I remove all my MCW widgets from the sidebars, the problem remains until I deactivate MCW altogether. If I then include the same code as text widgets, and one PHP widget (using the Executable PHP Widget) everything works.

    Any ideas what could be going on. I do like MCW and would like to use it.

    David

  24. Janek

    Hi David,
    Sounds strange to me. Can you give me the list of the plugins you are using and maybe the php-code that you are using. You can send it to my e-mail-adresse which is available in the impressum.

    I will take a look at it as soon as possible.

    PS: Did you tried to delete the CustomWidgets one by one? I am still pretty sure it has something to do with the code you are using…

  25. Hi Janek,

    Thanks for a lovely plugin, which I just started to test on my beta blog site. I am encoutering a PHP issue. To test the plugin, I am using a simple php call, which is currently located in the loop and works well on my home page. So, I set up the plugin to php code for the default, created a simple widget and dragged the new widget into a wigetised area on my home page; and pasted the php code into the edit field in the My Custom Widgets admin panel. The php radio button is selected. The code is:

    [PHP]
    Syndicated from:
    <a href="” target=”_blank”>.
    [PHP]

    But I get 2 errors with that code:

    1 – “Code did not pass the plausibility check. Please review!
    (You should not use in php-code. Please select html or remove these tags.)” Hummmm… what wrong with that php code…? Or am I missing something? It works fine when it’s hard-coded into my home.php. Why wouldn’t I be able to use in a php code environment? If no, what else then?

    2 – which leads to a parse error on the prevue and home page: “Parse error: syntax error, unexpected ‘<' in /data/15/1/118/15/1444341/user/1551955/htdocs/blog/wp-content/plugins/mycustomwidget/my_custom_widget_functions.php(2611) : eval()'d code on line 1"

    So, can you give me some guidance, please? All advice would be most appreciated. I will leave the code in as is, so if you have the time, you can look at the page to see that 1) the php code is working when hard-coded in home.php and the error message generated by the plugin in the widgetised area below.

    Many thanks for your feedback.

    Cheers,

    Olivier

  26. Hi Janek,

    Sent you a message via this forum a few days ago. But I cannot see the question being posted, therefore not sure if you saw it and be able to reply. Please let me know.

    Cheers,

    Olivier

  27. Hi Olivier,
    I just found your comment in my spam-folder.
    I think you have to change the kind of your widget. Just change the radio-button on the top. If the error still occurs you might want to post the complete code. The code you have posted in your comment is HTML and not PHP.

    Cheers Janek

  28. Hi Janek,

    Thanks for this. Happy to see that my original post didn’t disappeared. Interestingly enough, that’s not the code I inserted in my original note; the one I inserted was for sure php code and not html. I suspect, the spam filter did its job by stripping the php tags… Anyway, it looks like your suggestion is working :) so, I’ll keep on trying and see how it goes.

    Thanks for the advice.

    Cheers,

    Olivier

  29. Randy

    Janek,

    Some of the widget documentation recommends using get_field_id() and get_field_name() to help store the $instance array members. Do you know what these functions do?

    Thanks

  30. Hi Janek, I cant thank you enough for Version 2.0.3. This makes my life so much easier. I have tested it using html and PHP and both worked great.. Thanks again for sharing.

  31. WHY I GET THIS ERROR?

    Code did not pass the plausibility check. Please review!
    (You should not use <?php before ?> in php-code. Please select html or remove these tags.)
    http://xs744.xs.to/xs744/09433/error787.gif

  32. Hi Radu,

    2 possible solutions:

    1. Change the widget type from “php” to “html”
    2. Remove the first an the last php-tag (“>?php” and “?<”)

    Background: MCW differentiate widgets by the code you want to enter. If you choose “php”, you do not have to enter any php-tags because the plugin already knows. If you choose “html”, the plugin expects these tags in order to parse the code correctly.
    I would recommend solution 1, because it is much easier… ;)

    Another point (also mentioned in the FAQ on this page): Due to the fact that the plugins source code is situated in wordpress’s plugin-folder you will have to define the full path of the file you want to include.
    Example:

    <?php include(get_option(’home’). ‘/sponsors.php’); ?>

    Cheers – Janek

  33. This plugin is fantastic!! I was trying to modify a pre WP 2.8 widget to use the WP 2.8 hooks, so I could have the widget appear in the sidebar of only certain pages. I was getting very frustrated, but then I found your plugin. Now I can use a copy of the widget to control its appearance. I still want to re-code the widget, but at least I can have it working the way I want it now. Thanks again.

  34. Peter

    Hey Janek,

    sorry, I am not so great with php…

    I want a customwidget with a banner to be shown on a single post with a certain tag. I found this conditional tag: is_tag()

    How does this work?

    Can I add php to the html of the banner?

    Let´s say the tag=love and the banner html is

    Would be great if you could help me with this!

    Thanks, Peter

  35. Hi Peter,

    the tag “is_tag(‘love’)” would return true if you are watching the archive entry for the love tag (usually by clicking on “love” in your tag cloud).

    So this will not work for single posts. To get a list of all tags that are assigned to a post, you should use the get_the_tags function (function reference: http://codex.wordpress.org/Function_Reference/get_the_tags)

    This means that the filters provided by this plugin will not help you. But you can use this code (simply add it to your html-widget)


    <?php
    if (is_single());
    $all_post_tags = get_the_tags();
    foreach($all_post_tags as $this_tag) {
    if ($this_tag->name == "love" ) {
    ?>
    <!-- insert your html-content here -->
    <?php
    }
    }
    ?>

  36. Peter

    Hey Janek,

    thanks for your quick help.

    But somehow it still doesn´t work…

  37. Sebas

    Hi,

    I’ve installed your plugin, i can create custom widgets but they do not show up under Apperance>Widget, i have all the standard WP widgets listed there but not my custom widgets, do you know what I’m doing wrong?
    Thanks in advance

  38. All custom widgets should show up under Appearance->Widget. The name should start with “MCW: ” followed by the technical name you defined when creating your widget.

    If the widgets are not available, there might have been a problem during installation. Try to re-upload the source files, re-activate the plugin and see if it works afterwards.

    Hope this helps – Janek

  39. Hi Janek. I have tried your plugin and I think is awesome, I was trying to find a way to create custom widgets and this really helps me.

    I only have a question… well the thing is that I made a widget to show the latest posts from a specific category to show it in a sidebar, it works well in the sidebar just as I wanted, but when I open a post, the content of the post also does the same as the plugin. I let you the code of the plugin. Thank you.


    <a href="" rel="bookmark">

  40. Hi Magads,
    I did not fully understand what your post is doing and as you can see code is not displayed as expected. Can you send me the code via mail to webmaster@janek-niefeldt.de ?

    I believe it has something to do with the loop you are using within your widget. There have been several comments regarding this topic. You might want to take a look at a comment I wrote back in June (click here) as a response to a similar (or maybe the same) issue.

    Cheers – Janek

  41. Thank you for your answer Janek and I already send you the email with the code of the plugin.
    Again Thanks for the help.

    As you can see, what I want to do is that the widget must show the latest posts from a category and it does, but somehow when I want to see a page, it shows me in the content of the page, the content plus the posts of the widget.

    <?php if (have_posts()) : ?>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("category_name=blog&paged=$paged&showposts=5"); ?>
    <ul>
    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    <?php else : ?>
    <?php endif; ?>

  42. shana

    Hi…

    I love this plugin and have been using it a lot. Everything was working great, and then a few days ago, many pages that use this plugin stopped working.

    Here is what happens: The page loads all the way to the point where is called, and then nothing else displays. When I deactivate MyCustomWidget plugin, all is well again.

    I have a hunch that it has something to do with my various querys that I am doing, but I am not sure. Do you have any advice? If I can’t fix this, my alternative will have to be to not us MCW and instead create a ton of different sidebar files. I guess not the end of the world but I’d rather use this plugin.

    Thanks.

  43. Leo

    Hi, great widget program. Even a neophyte like myself was able to get around ok and setup a widget.

    However, just wondering how i can get my weather widget to centre in the sidebar? Any ideas? I’ve tried a few things to no avail.

  44. I’m using WP2.9.1

    I’ve successfully created a custom widget and put it into a theme-defined widget zone. I would like to insert it into a content area.

    Your instructions to other posters above say “By default you can add the string <!–MyFirstWidget–> to any article where the CustomWidget should appear.”

    It’s not working, so I’m wondering whether I’m doing it correctly or not.

    I ADD a new page. In the content area, I type <!–members–>. And, since this is just a test, I add just a couple words before and after. I PUBLISH the page, then view it, and the content on the page is either the words before/after the tag and the text of the tag, or the words and no tag text, but not the widget contents. I tried it in both the visual and the HTML editors.

    Is the syntax correct?

    thanks!

  45. I am using the theme Mystique with WP2.91.

    Other shortcodes do work, so I have the syntax and the method correct (found out I need to add the shortcode in the htms view, not the visual view).

    The shortcode for MyCustomWidget does not work – still.

  46. Hi MaryAnn,

    I will take a look at it asap. It definitely worked for previous WP-versions and all themes I found so far. I will need to upgrade and doublecheck afterwards.

    The widget you created should be called “members”.
    Please make sure that the option “Make MCW-Tags available (for specific filter)” in the Miscellaneous section of the configuration screen is activated and “the_content” is entered in the corresponding text field.
    http://www.team2449.com/wp2010/wp-admin/options-general.php?page=my_custom_widget_functions.php

    Best Regards – Janek

  47. Thank you, Janek.

    The widget is called “members” andn the “make MCW-Tags available” option is activated and configured as you indicate.

    I look forward to being able to make use of this feature as it is THE feature I’ve been searching for.

    –Mary Ann

  48. Hi Mary Ann,
    I updated my WP and installed your theme. The feature worked for me, so i give it another try:
    - Have you marked the filter “all” in your widget definition?
    - Is the filter “all” defined as “true” in the filter definition on the plugin’s configuration page?

  49. Mirromaru

    Wow, this is a really neat plugin! Thank you so much! :)

  50. Ben

    Hi Janek,

    Great plugin. Having a weird issue though. I have a some code to list the last 3 posts from a category in the sidebar. It displays correctly, but somehow changes what categories each post ‘thinks’ they’re in. They still behave correctly, but a post in ‘events’ will show (at the bottom) ‘posted in featured, menus’ or something like that.

    The code is straight from the get_posts example in the wp codex:
    http://codex.wordpress.org/Template_Tags/get_posts

    <a href="">

    Any ideas? Thanks!
    -b

Leave a Reply

Your email address will not be published.
Required fields are marked:*

*

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