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 2.8!

Where can I download it?

Current Version: MyCustomWidget 2.0.3 – » 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.

  1. Marc Says:

    Works great. These filters are nice2have…

  2. Graham Cox Says:

    Janek,

    The download page doesn’t do anything for me. And I don’t understand the German message displayed:-

    Du hast nicht die erforderliche Berechtigung um diese Datei downloaden zu können.

    Can you let me know how to get the plugin please

    Thanks

    Graham

  3. Janek Says:

    My fault! Please try again. It should work now.

  4. Graham Cox Says:

    Got it, thanks

  5. Zets Says:

    License?

  6. Kaz Says:

    Janek, just started to see what your widget will do. First thing, when you click on the link created in the Wordpress Plugin page it takes you to a 404 page on your site.
    Will let you know further.

  7. Janek Says:

    @Zets: GPL – What else?

    @Kaz: It works for me. But I will check if there is a bug in the download-version. Plz let me know if your find any other mistakes.

  8. Kaz Says:

    In the default the URL is “custom-widget”
    Not a big deal, but I have in a “plugins used” page so readers can link to your widget if they want.

    Plugin Name: My Custom Widgets
    Plugin URI: http://www.janek-niefeldt.de/blog/mycustomwidget/
    Description: Define your own widgets and include them into your theme.” (This is post edit to fix)
    Otherwise a hearty well done. I think you posted right after me on another page, so maybe knew at least one of the widgets that does this isn’t working with IE. Shame the attitude is “it works under Foxfire” so it is okay. Even if the huge majority of people use IE.
    Cool Tool.
    Kaz

  9. Janek Says:

    Okay, I changed the URL. (But the wrong one will work as well, now.) …silly mistake…

  10. Third World Engineer Says:

    I tried it on Wordpress 2.3.3 with a custom theme (Customized Technics theme) and my whole site becomes inaccessible once I create the new widget. I haven’t had time to debug yet but I’ll try to find out what’s wrong.

  11. Janek Says:

    When I try to run this side with this theme, I get an error message raised by another plugin I am using called “WP-PageNavi”. But this is an error with this specific plugin and is not raised by MyCustomWidget.
    Fatal error: Cannot redeclare wp_pagenavi() (previously declared in /www/htdocs/blog/wp-content/plugins/pagenavi/pagenavi.php:58) in /www/htdocs/blog/wp-content/themes/technics/functions.php on line 72
    Once I deactivate this buggy plugin everything works fine. I doubt that this has something to do with WP 2.3.3 because it works for me and I do not use some fancy stuff in the coding. Did the same error occured within WP 2.3.2?

    I think there are 2 possible reasons for your error:
    1. MyCustomWidget does not harmonize with another plugin you are using. (maybe an identical function definition, or an identical option name in the database)
    2. The code you are using in your CustomWidget is buggy

    In both cases: Can you please post the error message and the code of your widget? I will see what I can find.

  12. Third World Engineer Says:

    Actually, I had only entered the widget name without any code… I was planning to enter the code right after but after clicking the “save all” link, it only redirected me to a blank page.

    I wasn’t able to try it using 2.3.2 because I only discovered your plugin today… I had already upgraded to 2.3.3

  13. Janek Says:

    Okay, so you did not even arrange the blank widget in your sidebar(s)? Sounds like a conflict with another plugin you are using. Which plugins do you use on your side? Maybe you have somthing like Viper’s Plugins Used to show display your list like I did (click here).
    I will try to simulate this case this evening (or weekend ;o))
    By the way: What was the widgets name? Did you user any special characters?

  14. Third World Engineer Says:

    Wasn’t able to get there… as I said, right after I entered the new widget name and tried to move to the next page, it would only give me a blank page..

    The name of the widget I tried to use was “validationwidget”.

    I was only trying to write some code to show some site validations… a sort of intro to widget building for myself if you get what i mean.

    At first I thought it was the theme I was using that was the problem, but you say you are able to use it properly?

  15. Janek Says:

    Yeah, the theme was no problem for me.
    1. I did everything like you descriped it: No error at all – No blank page. Everything works as designed.
    2. I created a DB-entry, in case another plugin is using the same prefix and name –> No error

    The widgets name should not be a problem. I still believe it has something to do with other plugins you are using. (Or maybe the php-server configuration)

    How do you manage to bring your site back online? Everytime I visit it, there is no blank page or is it just the admin-panel which is affected?

  16. Janek Says:

    Hey Jeffrey, did you try to deactivate some of the other plugins you are using such as “validations widget”? Does the same error occur if you are using another widget name. It is possible to create widgets with the same name as other plugin-specific widgets. But usually this should not result in a blank page.

  17. Third World Engineer Says:

    My site is online right now because the MyCustomWidget plugin is disabled. Everytime I enable it, I can’t get past the plugins page anymore (blank screen).

    I tried it before coding my own validations widget (which is actually nothing compared to your customizable plugin) so I’m pretty sure the validations widget had nothing to do with it. In fact, the reason I coded it was because I couldn’t use yours… :D

    Here’s a list of my currently enabled plugins.
    1. Advanced TinyMCE Editor – http://www.mkbergman.com/advancedTinyMCE
    2. Feedburner Feedsmith – http://www.feedburner.com/fb/a/help/wordpress_quickstart
    3. MaxBlogPress Ping Optimizer – http://www.maxblogpress.com/plugins/mpo/
    4. RSS Footer Plugin – http://www.joostdevalk.nl/wordpress/rss-footer/
    5. StatPress Plugin – http://www.irisco.it/?page_id=28
    6. Validations widget – which I installed after failing to use your plugin successfully.

    If I enter a new custom widget name before setting the options, would that cause this error? I ask because I went to the plugins page before saving the options in the options page (for MyCustomWidget). After I clicked save, Wordpress wouldn’t forward me to the next page anymore.

    How did you know my name was Jeffrey? By the way?

  18. Janek Says:

    Okay, I installed all these plugins and activated them one by one: No blank page. No error. Nothing! I think we don’t get along this way. I did everything I could, but I was not able to reproduce the error.
    So there are some thinks you should test on your side.

    1. Download the current version of the plugin and install it again (overwrite everything). Maybe there was an error during file transfer.
    2. Deactivate all plugins but “MyCustomWidget” –> Does the error still occurs?
    3. Change to another theme (e.g. classic) –> Does the error still occurs?
    4. Delete the plugin-data manually or by using the build in functionality which will delete all plugin relevant table-entries (button is available at http://www.3w-engineer.net/wp-admin/options-general.php?page=my_custom_widget.php ). –> Does the error still occurs (should not be possible)?
    4.1 Then try to create your own widget again. –> Does the error still occurs again?
    5. Can you take a look at your database entries and find all records in table wp_options which option_name-value starts with a “mcw_”?
    There should be 2 entries available. One for the options and one for the widget-content.
    Please post the values if step 1-4 did not help.

    I still don’t really get where the blank page occurs. The admin panel is accessible (otherwise you would not be able to deactivate the plugin, right?).

    PS: I know your name because it is written in …/validations_widget/validations_widget.phpc. I think you should fix that Mr. A. ;)

  19. Third World Engineer Says:

    Hi Janek,
    I’m sorry it’s taken a while to get back to you (3 day vacation).

    I’m at work at the moment so I can’t really check right now but I promise I’ll do it tonigh (around 7 hours time).

    I know I haven’t got your plugin working but the others seem to think it’s great… good job!

  20. Third World Engineer Says:

    Hi again Janek!

    I think I tried deleting and reinstalling the plugin but it failed.

    I think I may have found our problem. My database contains no wp_options table since I changed the default wordpress table prefixes to 3we_.

    Perhaps the get_options call is not returning the right table prefixes?

  21. Third World Engineer Says:

    Sorry… my mistake, it was able to write the data properly.

  22. Kani Says:

    Hello, thank you for a wonderful plugin.

    Thing is will this plugin work with multiple sidebars? I’ve implemented code into my function.php to allow for multiple sidebars as dicussed here: http://wordpress.org/support/topic/111551

    I’ve installed your plugin and can create custom widgets, but when I drag them to my sidebar and save they don’t show up.

    Do i have to change something in the my_custom_widget.php file?

    Any help would be awesome.

    thanks!

  23. Janek Says:

    Hm, I tried it with some 2-sidebar-themes and I just added a second sidebar to my blog like descriped on this page. It worked perfectly.

    Is it possible that you forgot to choose a filter (e.g. the standard filter “all”)? If you do not choose a filter, the widget will not be displayed.

  24. Third World Engineer Says:

    Hi Janek!

    I deleted the database entries and I think I was able to get it to work on another site.

    I’ll try installing it again.

    Thanks for the support!

  25. Janek Says:

    Good to hear that. Let me know how it worked out.

  26. Third World Engineer Says:

    I deleted the database entries and now it’s working fine.

    Here’s how my bug happened…After installing, If you enter a new widget name but don’t proceed to create the widget at administration->Presentation->My Custom Widgets, then click on the save all link, only a blank page will be forwarded and you will be unable to access the site. Even reinstalling the plugin will not help or deleting the folder.

    You need to delete the database entries and then reinstall the plugin for it to work again.

    Hope this helps!

  27. Janek Says:

    Allright: That’s a use-case I was not aware of. I think I will have to fix this. Release 1.2.1 is comming soon… ;)

  28. Janek Says:

    Done!
    Thanks for your support. The bug is now called “Jeffreys-use-case”-bug.

  29. Third World Engineer Says:

    Hahaha! I’ll take that as a compliment… :D

    Thanks! and good job by the way!

  30. Graham Cox Says:

    Hi Janek,

    Quick question. In my custom widget I want to pull in a php include like so:-

    if (rand(0,1)) {
      include("myIncludeFile.php");
    } else {
      include("anotherIncludeFile.php");
    }

    But I get:-
    Warning: Unknown(myIncludeFile.php): failed to open stream: No such file or directory in

    Which directory do I need the include files in for them to be found by my custom widget please.

    Thanks

    Graham

  31. Graham Cox Says:

    Hi Janek,

    Well it seems to work ok if I put the include files in the

    wp-content/plugins/mycustomwidget

    directory, so problem solved.

    Thanks

    Graham

  32. Janek Says:

    That’s exactly what I would have told you.
    Another good way would be to work with the following wordpress-build-in-function:
    get_option("siteurl");

    This function should give you the exact URL of your wordpress-root-directory as it is defined in your options.
    For instance: include(get_option("siteurl")."/IncludeDir/myIncludeFile.php");

  33. Third World Engineer Says:

    Janek I seem to have found something… not sure if it’s a bug though.

    If I enter the following code right before my widget

    Email Digest

    It appends a backslash right before every quotation mark. (This doesn’t happen in default wordpress widgets as far as I’ve checked).

    Perhaps the call to stripslashes after retrieving the code from the database? (Forgive me, I’m new to PHP)

  34. Third World Engineer Says:

    The above code did not render correctly. It’s actually HTML code so I’ll remove the start and end html tags so you can see
    like

    H2 class="widgettitle">Title here</H2

    and a backslash is appended. View page source shows

    class=\"widgettitle\"

    Can you tell me where to look?

  35. Janek Says:

    I am not really familiar with these stripslashes and addslashes. It’s possible that I made a mistake when copying it from… ooops, did I said that? I think I will have to add another stripslashes like you allready wrote.
    Currently I do not know the name of that specific function. If you want to see the code, just search for the “eval”-command which should only be used in a single function of mine. Like all functions it is defined in the plugins mainfile.
    I will take a look at that this evening.

  36. Third World Engineer Says:

    I found it

    in my_custom_widget.php:MCW_eval_code
    look for
    $precode = $MyWidget['beforecode'];
    and add a stripslashes call.

  37. Janek Says:

    Okay, release 1.2.2 is coming soon. But I think this time it will take a little bit longer than 1 hour.
    I am surprised that you use the additional html-code field. I only use it when I have problems with javascript-declarations because of special characters like ” and ‘. Maybe I will find a way to handle this more elegant in the future.
    Thanks for the effort!

  38. Janek Says:

    Done. Release 1.2.2 is now ready for download.

  39. Eduardo Larequi Says:

    I’ve just installed this plugin, but after defining a simple custom widget to insert text in posts belonging to category “Fotos”, I always get this error:

    Parse error: syntax error, unexpected '<' in /xxx/xxx/labitacoradeltigre.com/xxx/xxx/wp-content/plugins/mycustomwidget/my_custom_widget.php(475) : eval()'d code on line 1

    The code of my custom widget is as simple as:

    More photos in Flickr
    These are some of my last photos

    And it is intended to be shown in single post views.

    Any idea? Thanks in advance.

  40. Janek Says:

    Without knowing the code I can only guess what happened
    Can you please post your code or send it to me via mail (Please be carefull when using html. Maybe you use { instead of <.)
    There are several possibilities:
    - wrong php-code:
    –> maybe you forgot to close your php-code by using “?>
    –> maybe you missed a semicolon

    There is still an issue regarding apostrophe and quotation marks when mixing php- and html-code. But I don’t think this will have something to do with your problem. The error mesage just doesn’t fit. Nevertheless I am working on this issue to get it done before starting my vacations next week (This will be release 1.3).

  41. Third World Engineer Says:

    @Eduardo Larequi: Perhaps you clicked the PHP button when entering pure HTML code?

  42. Janek Says:

    Okay, I have a beta-release for 1.3 including the following new features.
    - new code-evaluation-process (There is definitly no apostrophe or quotation marks issue anymore.)
    - debug mode for widget preview (usefull for php-html-mix)
    - you can use php in html code (old) and vice versa (new)

    http://www.janek-niefeldt.de/mcw_beta

    If someone likes to test it…

  43. Eduardo Larequi Says:

    I think there’s some kind of incompatibility between My Custom Widget and Exec-PHP plugin: if I choose HTML instead of PHP when editing a custom widget (even though this custom widget uses PHP code), everything seems to work fine.

    Does it make sense to you?

    Thank you very much for your quick answer and support.

  44. Janek Says:

    Yeah, that’s possible. I will take a look at this plugin. Maybe it is possible to create a workarround to ignore this specific plugin. (I think his/her plugin and mine plugin is doing the same work.) But it is working now?
    How does it work when using the beta-version of 1.3? Without seeing the “exec php”-plugin I would guess that this beta-release would change the problem.
    Bye Janek

  45. Eduardo Larequi Says:

    I haven’t checked 1.3 version, but as I said in my previous comment, everything works fine now.

    Anyway, MyCustom Widget is a fantastic solution. I am going to write a post about it in my blog.

  46. Janek Says:

    Oh boy this EXEC-PHP-plugin is pretty good. I took a look at the code and the amazing documentation. While reading this I found more bugs (or lets say issues) in my code than during the last 3 weeks. Thanks to GPL I allready know how to handle these issues.
    Nevertheless I do not think that there is any incompatibility to this plugin. As far as I can see the plugins should not even affect each other.
    Leason learned: I will have to improve the documentation.

  47. Joe D'Andrea Says:

    Bravo – well done Janek! Using it with a custom-developed theme. No problems.

  48. Third World Engineer Says:

    Yes Janek, I guess the documentation on how to use it is quite sparse. I remember having had to stumble the first few times using it.

    I’ve gotten quite used to it recently though, and use it regularly when I need to integrate a widget into my pages.

    Thanks for this excellent tool!

  49. Third World Engineer Says:

    I was also able to use the plugin on my other site, The Biggest Adventure.

    The subscribe links and the email digest widget were done using this plugin, as well as the advertisements and site validity icons.

  50. Cun Zhang's Blog Says:

    Great Plugin!…

    Hi, great plugin! I have installed it into my wordpress. Thank you for your great work!
    ……

  51. Alex Says:

    BUG: Breaks when quotes are used in the filter definitions: e.g. is_page(‘home’). Nice though, but I don’t think I can find a use for it without a fix… :)

  52. Alex Says:

    Suggestion: making HTML the default form of new widgets- reading the comments I think a lot of people just chuck words in there not realising they have to either use PHP, or explicitly state they want html.

  53. Janek Says:

    @Alex: I will fix that.
    @Alex2: I will introduce another option-flag regarding standard-code-evaluation asap

  54. Janek Says:

    Done!
    Release 1.3 is available now.
    - additional option flag to define the standard code type (default will be html)
    - solving quotes-bug in filter definitions
    - redesign of code evaluation (thanks to Sören who wrote his Exec-PHP plugin)
    - debuging-mode for widget preview

  55. Tom Says:

    Hi Janek,

    Your plugin works great for me but I don’t know how to set up a widget for a specific page. For example I created a widget that I want to display only on page ID “6″, so I put is_page(6) in the filter configuration, that’s fine.
    But if I want a second widget to appear only on page ID “8″, I create it but don’t see where I can apply filter for each widget I create. I must miss soething.

    Thanks.

  56. Janek Says:

    Hi Tom,
    if I get it right you want to create a widget that should only be visible on specific static-pages (not posts).
    Therefore you have added an own filter through WordpressAdmin –> Settings –> MyCustomWidgets. As the php-filter-code you entered a simple is_page(6) – If you would like to define a filter for a specific post you should use is_single(6)… everything else is descriped on this side.
    Instead of adding a new filter you can also change one of the existing filters, but this would mean that you cannot use the original one anymore.

    After you have created a new filter you will see this filter on the widget configuration page for each single CustomWidget. Here you can activate the checkbox. If you have added the widget to your sidebar it should work now.

    I guess you haven’t defined an own filter, yet. Am I right?!

    The whole procedure is a little bit cumbersomely. Maybe I will find a more generic way in the future. Please take a look at the given Link which is also available on the filter-configuration page).

    By the way: If the name of your (lets say) CustomFilter is to long and doesn’t fit into the widged-configuration area you can adjust the filter-width through plugin configuration as well.

    CU

  57. Tom Says:

    Thanks Janek, it works great, I was making things in the reverse order, creating widgets before the filters and then trying to find how to make it work from the configuration menu.

    Everything’s fine now. Thank you, I’ll have a lot of widgets on one of my website soon !

  58. Jon Says:

    Is it possible to use this plugin to make other downloaded widgets “filterable”? In other words, I like the ability to filter a widget in my sidebar. But this is only possible for widgets I create myself – not existing widgets. Specifically, I am using the “Folding Pages Widget” from http://navyroad.com/2007/09/04/folding-pages-widget/. But I do not want that widget to appear on the home page. If I could turn it into a Custom Widget, I could filter it. But I can’t figure out how to do that. I copied the contents of the widget’s PHP file into the details field of the Custom Widget Editor. I have tried setting it to both PHP and HTML but I can’t get anything to work. I hope I am being clear. I am new to PHP. Can you offer any suggestions? Thanks.

  59. Janek Says:

    Of course it is possible to move the whole plugin into a CustomWidget. I just tried it out. With some small moifications it would work. Actually this is a little bit tricky if you are new to php because
    1. You will loose the widget control dialogue. Therefore you will have to declare the plugin-options manualy inside the widget details (code area).
    2. You will have to rename all called functions to make both tools (plugin and CustomWidget) work together.
    I think you should not do that this way. It is like reinventing the wheel if you know what I mean.

    There is another way to make this widget disappear on the “home”-page without using my plugin. You just have to change the coding of the plugin itself. This would be much easier than the solution mentioned above.

    Look for the following parts inside the plugin coding

    ...
    function nrs_folding_pages($args){
    ...
    

    and add the follwong line to the coding of the nrs_folding_pages-function

    ...
    function nrs_folding_pages($args){
    if (is_home()) return;
    ...
    

    Guess what! If there will be another version of the “Folding Pages Widget” plugin you will have to change the coding again.

  60. Jon Says:

    Thanks for that tip. I suppose that is much easier than what I was trying to do. Works great. Still, I think your plugin is great. Makes me wish I could write my own widgets. I think the ability to filter widgets by page should be part of Wordpress by default.

    If I can find any other use for your plugin I definitely will use it. Thanks.

  61. WordPress Plugins: 25 Best/Must Have WordPress Plugins || WordPress Themes, Plugins, etc.. Says:

    [...] Author Description: Define your own widgets and include them into your theme. By Janek Niefeldt. My Comments: Excellent, Excellent, Excellent plugin helps you create your own widgets for sidebar without a problem. This can be used for any code.. HTML or PHP or JavaScript. Convert your Adsense Code to Widget or any other code. Download Page: http://www.janek-niefeldt.de/blog/mycustomwidget/ [...]

  62. The Best Blogging Software (WordPress) + The Top 60 WordPress Plugins | Midas Oracle .ORG Says:

    [...] My Custom Widgets 1.3.1 » Janek Niefeldt (url) Define your own widgets and include them into your theme. [...]

  63. Bee Q Says:

    Excellent! Thank you so much for this cool plugin

  64. Eduardo Larequi Says:

    After an automatic upgrade of MyCustomWidgets plugin to version 1.4, I can’t delete or create any custom widgets.

    I just can edit existing widgets, but not from the plugin interface. Edition is only possible from Design > Widgets.

    Some kind of incompatibility, perhaps? If you are interested in my case, I can send you by email the complete list of my plugins.

  65. Janek Says:

    Uups, I think version 1.4 is a little bit buggy. I will find a way to fix that. Meanwhile you can go to the plugin configuration site (Settings –> MyCustomWidget) and deactivate the JavaScript functionality in the Layout section.
    The plugin will work correctly but without any nice buttons or slide-effects… better than nothing.

    I will hurry up. 1.4.1 is comming soon.

    @all: If you have not updated the plugin yet, please wait for version 1.4.1

  66. Janek Says:

    Okay!
    Thanks to FireBug (I love/recommend this Add-on.) I have found the reason. My editor changed the function statement that I am using to declare the “submit_form”-function into a FUNCTION statement.
    That is why it did not worked anymore. Without JavaScript the submit-request is send directly without using this function.

    Version 1.4.1 should be available now.

    @Eduardo: Thanks for the feedback.

  67. Eduardo Larequi Says:

    Version 1.4.1 works fine.

    Thank you very much, Janek, for your quick answer and excellent support.

  68. SE7EN Says:

    Wow, this is definitely what I’m looking for. Thanks a lot for the great plugin!

  69. 24 Wordpress Plugins I Use on Technology Nerd - Must Have! || Technology Nerd Says:

    [...] Download Page: http://www.janek-niefeldt.de/blog/mycustomwidget/ [...]

  70. kris Says:

    lovely plugin – this has really opened up a lots of possibilities for a site i’m working on. thankyou so much!

    one thing i’d like to do is put a little css wrapper around each custom widget eg so i can space them in my layout correctly. i could put this inside each widget but its a bit messy. where i would i stick this?

  71. Will Abbott Says:

    Really good plug-in, thanks.

    How do I access the $post-> variable? I can’t seem to use it.

    i.e.

    post_title; ?>

    Any help appreciated, thanks. Will.

  72. Mihail Says:

    Hello

    I am so glad I found this plugin. I need it like air :) Still, I encounter one issue when I want to display it only in one category page. Is this correct? is_category(‘ong’) in order to display it in just the category “ong” or I need to write it differently?

    Thanks a lot!

  73. Janek Says:

    @kris: I will see what I can do. Unfortunatly I am very busy at the moment.

    @Will Abbott: You can display the post title of the very first post displayed on a site by just entering the_title(); as a php-code into your widget.
    Please note that the widget is not handled within the loop. Wordpress provides get_ equivalents of the functions used within the loop, which takes the post ID as the parameter, e.g. get_the_title($id); which will return title of the specified post. Take a look at this page to see a list of possible template tags: http://codex.wordpress.org/Template_Tags

    @Mihail: is_category('ong') should be fine. (1. create a new filter or change an existing one, 2. activate it in your widget and make sure it is the only activated filter for this widget, 3. check if the categories name is spelled correctly, 4. do not forget to save) I just tested it and it worked fine. Does your CustomWidget appear all the time or never? For detailed information take a look at this page: http://codex.wordpress.org/Conditional_Tags

  74. Mihail Says:

    Is working now! Thanks so much!! You cannot imagine how much this plugin is helping us!!! :)

  75. Will Abbott Says:

    Thanks for that Janek. The problem I was getting though was that I could not access the current ID variable to use get_the_title($ID).

    On a different note, are you aware if a plug in which allows someone to create their own custom filters. So setting an identifier within create post/page to return a custom bit of code. I.e. use a identifier such as {{custom-filter-id}} to return back some pre-defined HTML?

    Thanks, Will.

  76. stein Says:

    Nice plugin. Unfortunately i don’t get it working. I get this error message (even if there’s no php/html code in the widget)

    Parse error: syntax error, unexpected ‘<’ in /home/2/m/maxliber/www/wp-content/plugins/mycustomwidget/my_custom_widget.php(508) : eval()’d code on line

    Any suggestions.

    All help will be appreciated

    Stein

  77. Janek Says:

    Hi Stein,
    I was not able to reproduce the error.
    It would help if you could tell me the URL of your site (maybe with an example page/post where I can see the problem). I expect that you are running the latest version of the plugin. If you have not entered any widget content, I think there are 2 other possible reasons:
    1. You have changed the filter definitions –> try to use the filter “all” with definition “true”
    2. There is a problem in combination with other plugins. Could you send me a list of the plugins you use at the moment?!

  78. Helpful Wordpress Modification Links | KeyFrame5 Says:

    [...] homepage instead of several categories http://www.wordpressgarage.com (Great website all about wordpress) Custom Widgets Css content center I will have to try this at work. It also scroll on lower resolutions. [...]

  79. Aaron Says:

    I use the mycustomwidget to place amazon books on my front page. The problem I am having is that mycustomwidget does not pass along the title of the widget to the page so. If you look at my site, http://www.backpackfever.com and scroll down. On the right you will see how the amazon book looks out of place because there is no title.

    Is there anyway to pass the title info along so wordpress parses this correctly?

  80. Janek Says:

    Hi Aaron,
    if I get it right you want to put the title of your amazon book beneath the cover-image. Am I right?
    It sounds more like a stylesheet problem rather than a problem with the plugin. Try to add the following attributes float : left;
    margin-right : 5px;

  81. Aaron Says:

    That is what i want to do after I fix this problem. If you see the rest of the page you see that “recent posts” “categories” “pages” are the tiles. That title is set in the widget. My question is that, if this is a custom widget that i have made, of which i have inserted the random amazon book php code. How do i make that widget present its title. So it can display the title “random book”

    thanks

  82. Janek Says:

    Okay. Than just add <?php echo "<h2> Title </h2>"; [amazon-code] ?> to the widget.

    If you want to have it a little bit more generic use the global variables defined in your wp-theme:

    echo $before_widget;
    echo $before_title;
    echo "Title";
    echo $after_title;
    [amazon-code]
    echo $after_widget;

    instead.

  83. Aaron Says:

    it works!! thank you!

  84. Nagita Says:

    Hello,

    I have WP 2.6.3 and I can only get one widget to display.

    Are you having any problems with this version of WP?

    Thanks.

  85. Janek Says:

    Hi Nagita!

    I am using WP2.6.3 and had no problems so far.
    - I guess you are using the oldest version of the plugin (1.4.1).
    - What is the URL of your site?
    - Which theme do you use?
    - What other plugins do you use?
    - Can you send me some screenshots or provide any other information?

  86. Nagita Says:

    Answer via mail:
    I was trying all day and finally found this morning that I was not adding the widget to the sidebar. Once I did this it worked.

  87. Will Says:

    Hello,

    How easy would it to adapt your plugin to search the content for a custom tag i.e. <!–display-form–> ?

    Thanks

    Will

  88. Janek Says:

    I will take a look…

  89. Janek Says:

    Okay, I did it. Version 1.5 is available for download.

    @Will: I had to use the apply_filter()-function. You can activate this optional feature on Settings » My Custom Widget » Miscellaneous. There might be several WP-filters which could be used to convert a custom-tag into real code. That is why you will have to specify it manually. I suggest you try it with: the_content.
    test

    @Kris: I also added the (optional) CSS-Wrapper you requested.

  90. Will Says:

    That is sweet!
    thanks a bunch ;)

  91. Will Says:

    Ok, just having a look now. I am not sure how to use the additional Custom Tag/Filter field.

    I want to be able to specify a custom tag for each widget so when written in the_content will call that particular widget/snippet.

    Have I missed something?

  92. Janek Says:

    Oh, I think I misunderstood your comment. With version 1.5 you will be able to use tags within the CustomWidgets. Creating these Custom Tags is not in the scope of this plugin as it is called MyCustomWidget and not MyCustomWhatever.

    Nevertheless I guess this functionality can be implemented using the add_filter()-function provided by Wordpress. But this will take a while. Maybe next weekend… Maybe an own Plugin…

  93. Janek Says:

    Hi Will,
    I finally made it! Release 1.6 is available. Compared to the benefit it was just a small coding-change.
    Nevertheless it would worth a complete new plugin… …Who cares?! ;)

    You can now insert a widget called “MYWidget” into any post/page/etc. by using a <!--MyWidget-->-Tag.

    PS: You might have to reset/maintain the plugins options first.
    PPS: The filters you define for the widget are still valid.
    PPPS: Each CustomWidget will be available, even if it was not added to any sidebar.

  94. Will Says:

    Janek that sounds absolutely spot on. I will give it a try later today or this weekend and let you know how it goes. I started to build my own ‘MyCustomFilter’ type plugin to do exactly that then discovered yours and realised it was almost what I was after. Yeh who cares, it adds useful functionality in how to display your widgets and how you call them! Very handy.

  95. » My Custom Widgets - WordPress Plugins Catalog Says:

    [...] Plugin Homepage » [...]

  96. marc Says:

    hi janek,

    you wrote the plugin i was searchin for … thx.
    but now i have a problem … the plugin is working to create a widget. i can place the widget in my sidbar but the sidebar block css style does not apply. tried it with different themes. always the same effect, get the content but not the style around. wp version is 2.6.5 even with all plugins deactivated i won´t get the widget with style.

    any idea?

    cheers
    marc

  97. Janek Says:

    Hm, it works for me. Where do you enter your personal css-styles?

    If you want to use individual styling for yor customwidgets you have to activate the css-wrapper in the plugin-settings. Afterwards you will have to add the appropriate css-styles to your theme.
    If you have a widget called mydonation and you want to adjust the fontsize of a h3-headline within this plugin you might enter this:

    #mydonation h3{
    font-size: 20px;
    }

    If you want to adjust the fontsize of each single customwidget you should add:

    .mcw h3{
    font-size: 20px;
    }

    Maybe I get you wrong. What exactly are you want to do?
    Can you give me any code examples or a link where I can find the widget?

  98. marc Says:

    yep you got me wrong ;)
    it´s about the general theme css style that not applies to the mcw widget.
    you got an e-mail with more details.

    thx n cheers
    marc

  99. Janek Says:

    Okay. Finally it was the same issue that Aaron had (>> Link).

    The plugin does not add any content to your widget (such as a widget header or any stylesheets). Consequently all these changes have to be added manually. Wordpress provides some global variables for this purpose.

    example:
    echo $before_widget;
    echo $before_title;
    echo “Title”;
    echo $after_title;
    [amazon-code]
    echo $after_widget;

  100. Mark Says:

    Can the widgets created be copied to another WP installation? Could I for example create the widget on a local test server and upload to a working installation?

    Thanks.

  101. Janek Says:

    Hi Mark,
    Sure you can! By using Ctrl+A, Ctrl+C and Ctrl+V … ;)
    If you want to copy all widgets at once you can take a look at your WP-database in table “wp_options” by using phpMyAdmin or any other tool you prefer. Search for entries whose option_name starts with “mcw_” and you will find 2 maybe 4 entries:
    mcw_mywidgets – contains all custom widgets
    mcw_mywidgets_backup – (optional) contains the backup of your widgets
    mcw_options – contains all settings that are not related to a specific widget
    mcw_options_backup – (optional) contains the backup of mcw_options

    If you copy the option_value of these entries to the corresponding entries of your working installation everything should work like on your test environment. Of course you will have to add the widgets to your sidebars again manually. (Or you copy the value of entry sidebars_widgets in table wp_config as well.)

  102. Mark Says:

    Thanks Janek. I spent the last couple days trying to figure out how to implement an RSS reader class with no luck. I paste the code and php/html to execute and end up with the following error: Parse error: syntax error, unexpected ‘<’ in /home/content/html/abeng/wp-content/plugins/mycustomwidget/my_custom_widget.php(516) : eval()’d code on line 1

    The exact same code executes perfectly standalone: http://www.abengnews.com/test

    This is the code (Ctl A, C, V :-) :

    rssFeeds = array(
    0 => "http://www.jamaica-gleaner.com/feed/rss.xml",
    1 => "http://www.nationnews.com/feed.rss",
    2 => "http://www.trinidadexpress.com/news.rss",
    3 => "http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml",
    );
    }

    function checkCache($rss_url) {

    $ttl = 60*60;// 60 secs/min for 60 minutes = 1 hour(360 secs)
    $cachefilename = md5(md5($rss_url));

    if (file_exists($cachefilename) && (time() - $ttl rssFeeds[$feedid];
    if (!isset($rss_url)) $rss_url = $this->rssFeeds[$feedid];
    $howmany = intval($howmany);

    $this->createHtmlFromRSSUrl( $rss_url, $howmany );

    }

    //
    // Create HTML from an RSS URL
    // it makes $howmany entires
    //
    function createHtmlFromRSSUrl( $rss_url, $howmany )
    {
    // Now we get the feed and cache it if necessary
    $rss_feed = $this->checkCache($rss_url);

    // Now we replace a few things that may cause problems later
    $rss_feed = str_replace("", "", $rss_feed);
    $rss_feed = str_replace("\n", "", $rss_feed);

    // If there is an image node remove it, we aren't going to use
    // it anyway and it often contains a and
    // that we don't want to match on later.
    $rss_feed = preg_replace('#(.*?)#', '', $rss_feed, 1 );

    // Now we get the nodes that we're interested in
    preg_match_all('#(.*?)#', $rss_feed, $title, PREG_SET_ORDER);
    preg_match_all('#(.*?)#', $rss_feed, $link, PREG_SET_ORDER);
    preg_match_all('#(.*?)#', $rss_feed, $description, PREG_SET_ORDER);

    //
    // Now that the RSS/XML is parsed.. Lets Make HTML !
    //

    // If there is not at least one title, then the feed was empty
    // it happens sometimes, so lets be prepared and do something
    // reasonable
    if(count($title) <= 1)
    {
    echo "No news at present, please check back later.";
    }
    else
    {
    // OK Here we go, this is the fun part

    // Well do up the top 3 entries from the feed
    for ($counter = 1; $counter FormatEntry($title[$counter][1],$description[$counter][1],$link[$counter][1]);

    // And now we'll output the new page bit!
    echo $row;
    }
    }
    }
    }

    function FormatEntry($title, $description, $link) {
    return <<<eof


    {$title} Read more...

    eof;
    }

    function GetrssFeeds() {
    return $this->rssFeeds;
    }

    function SetrssFeeds($rssFeeds) {
    $this->rssFeeds = $rssFeeds;
    }

    }// END OF THE CLASS
    ?>

    Today's Headlines
    From Gleaner, Jamaica
    createHtmlFromFeed(0,2); ?>

    From Nation, Barbados
    createHtmlFromFeed(1,2); ?>

    From Express, Trinidad
    createHtmlFromFeed(2,3); ?>

    From BBC
    createHtmlFromFeed(3,2); ?>

  103. Janek Says:

    Can you send me the complete code per mail please? When I add the code into a testwidget I only get the following error:
    Parse error: syntax error, unexpected '=' in /www/htdocs/janekn/blog/wp-content/plugins/mycustomwidget/my_custom_widget.php(516) : eval()'d code on line 1

    You marked the end of a class-definition but I cannot find the start.
    Where do you define the function createHtmlFromFeed?

    Are you sure the right widget kind is marked? If you start your widget with a <?php-statement, you should mark your widget as html instead of php.

  104. Mark Says:

    Hey Janek, that was the problem. I had it as php. Works like a charm now that I set html. Maybe that should be clear somewhere in the docs., as I didn’t come across that info. I’ll send the code to you still as with your programming skills you may be able to make it even more WP friendly (eg allow a user to enter RSS feeds via a form rather than fiddle with code).

    Give thanks brethren.

  105. Janek Says:

    Hi Mark,
    I just released version 1.6.1 because of a small CSS-”bug” with wordpress 2.7.
    I also added the plausibility check which will result in a small note in case of an obvious errors like in your case.

    CU

    PS: I will take a look at your code as soon as possible. But the whole concepts sounds like an own plugin to me. Don’t you think…?

  106. mr_alucas Says:

    your plug is not playing nice with me. I have tried to use it in several themes and it will not play nice, like in my current them located at hodnetwork.com it wont place the text i have in a widgets box.

    head on over to see for your self

  107. Janek Says:

    Sounds like a handling-issue to me.
    1. Please make sure you activated at least one filter.
    2. Add your custom widget to your sidebar like you would do it with any other “normal” widget. (don’t forget to save)
    3. Please make sure your widget has the right widget-kind (in case of a pure text-widget you should choose “html”.

    If it still doesn’t work: Where can in get your theme?

  108. mr_alucas Says:

    OK i had filter set to “is _ Page()”
    widget is paced in the sidebar along with others for references
    code is “html” tags used ” text ”

    Download theme for code checking http://www.hodnetwork.com/hodnetwork_theme.zip

    Site with issue to see what it doing exactly http://www.hodnetwork.com/

  109. Janek Says:

    Hi,

    I just tested the Plugin with your theme and everything worked nice.
    Please try the following:
    1. load default values in the plugin configuration screen
    2. create a test-widget (kind=html, filter=all, content=”foobar”)
    3. add the plugin to your sidebar.

    I am pretty sure the widget will show up. Afterwards you can change your filter setting, your widget content or anything else. I just want to make sure that the content shows up once.

    When I look at your page. I can find a text-snippet in your sidebar called “test the widget“. I don’t know for sure if this text is caused by a custom-widget because you might have deactivated the CSS-wrapper in the plugin configuration

  110. mr_alucas Says:

    Hi

    well i have done what you said i have also tried it in other WP sites that i have and in 2.6 edition of WP and nothing is working i even tried PHP and it worked what it looks like to me is that it is not calling / Placing the class tags “CSS” not even the div tags are placed ex.

    this is a test run of the plug-in
    This is the only thing that get placed on the page nothing else
    i have tried all your options in the con-fig on the off position and on position :(

  111. Janek Says:

    So at least the text appears. This means the widget itself has been added to the sidebar correctly.

    The plugin should not delete any content. In the background everything is handled as php-code and the html-parts are handled as pure text. This means all class tags should appear as well.

    Can you send me the content of your widget via mail (take a look at the impressum)?

  112. Janek Says:

  113. mr_alucas Says:

    yep that is exactly what i do and just like yours mine did the same thing.

    instead of putting the title “example” as the title and putting the text “my test widget” in the body and having it look like your links widget above.

    or did i miss the point for the plug in

  114. Janek Says:

    Okay, here we go: You expect the widgets name to appear as the title automatically.
    Well, that’s not the way the plugin works. The plugin is really stupid or let’s say simple. ;) It “only” adds the content you have defined to the sidebar. The name of the custom widget is not a title but a unique ID that is used within wordpress.

    It would be possible to change the plugin the way that each name/ID will be used as a title, but this would cause several problems whioh would have to be solved first:

    A title would appear even if the user does not need a title at all (for example if the user uses the widget outside of the sidebar (new functionality introduced with release 1.6) or if he simply wants to add a single donate button).

    Each theme works different. That is why I cannot be sure that the title or content would fit into the layout (some themes use <h2>-tags while other themes use <h3>-tags for the title). Wordpress provides some global variables for this purpose which are initialized during the registration process of the sidebar (usually defined in the function.php-file in your theme directory), but that doesn’t work for all themes out there.

    The bottom line is:
    The plugin does not add any content to your widget (such as a widget header, a title or any stylesheets). Consequently all these changes have to be added manually.

    If you like to have a complete widget with title and body you will have to define the content this way. I suggest you try it with the following php-code first (also see this comment)

    echo $before_widget;
    echo $before_title;
    echo "Title";
    echo $after_title;
    echo "content";
    echo $after_widget;

    If that doesn’t work you will have to add the corresponding tags manually. In your case you would have to add the following html-code:

    <div class="Block">
     <div class="Block-body">
      <div class="BlockHeader">
       
    Title
       <div class="l"/>
     <div class="r"><div/></div>
     </div>
     <div class="BlockContent">
      <div class="BlockContent-body">
       
    Content
      </div>
      <div class="BlockContent-tl"/>
      <div class="BlockContent-tr"><div/></div>
      <div class="BlockContent-bl"><div/></div>
      <div class="BlockContent-br"><div/></div>
      <div class="BlockContent-tc"><div/></div>
      <div class="BlockContent-bc"><div/></div>
      <div class="BlockContent-cl"><div/></div>
      <div class="BlockContent-cr"><div/></div>
      <div class="BlockContent-cc"/>
      </div>
     </div>
     <div class="Block-tl"/>
     <div class="Block-tr"><div />
     <div class="Block-bl"><div />
     <div class="Block-br"><div />
     <div class="Block-tc"><div />
     <div class="Block-bc"><div />
     <div class="Block-cl"><div />
     <div class="Block-cr"><div />
     <div class="Block-cc"/>
    </div>

    Maybe I will find a solution for this issue in the future. It comes up quiet often. But not during the next 3 days… Merry X-mas ;)

  115. mr_alucas Says:

    Ok i understand now. it is to be used like the way you used it for the tube video above i will work with the code above but i will tell you now my PHP skills are not that great but like you it will not be for at least 3 to 4 days that will touch it

    MARRY X-MAS :)

  116. Janek Says:

    Okay, I did it. I’ve added another input box for a widget title and released version 1.7. If the field is left empty no tags are added (as it happens in previous versions). If a title is defined it should appear in the sidebar as expected including all necessary styling tags. The title wil not apear if the widget is used outside of the sidebar.

  117. WordPress Plugin Releases for 12/30 | Weblog Tools Collection Says:

    [...] My Custom Widgets [...]

  118. WordPress Plugin Releases for 12/30 | Wordpress Blog NL Says:

    [...] My Custom Widgets [...]

  119. 4webmasters » Top 1000 WordPress Plugin Authors Says:

    [...] My Custom Widgets [...]

  120. En.nicuilie.eu Blogs » Top 1000 WordPress Plugin Authors Says:

    [...] My Custom Widgets [...]

  121. WeblogToolsCollection Español » Archivo del Blog » Novedades Plugins de WordPress 30/12 Says:

    [...] My Custom Widgets [...]

  122. mordaga Says:

    Hi Janek,

    I’m trying out your plug-in for a couple of custom widgets.
    My success rate is 50% so far.

    The code that seems to be problematic is “get_post_meta”.

    I am trying to add an image that is referenced from a post’s custom field: key = “offerimg”.

    Here is a snippet (PHP replaces beginning php tag):

    $recent = new WP_Query("cat=9&showposts=1");
    while($recent->have_posts()) : $recent->the_post();?>

      <b>
        <a href="" rel="bookmark">
          <?php the_title(); ?>
        </a>
      </b>

      <a href="" rel="bookmark">
        <img src=" <?php echo get_post_meta($post->ID, "offerimg", true); ?>" alt="<?php the_title(); ?>" />
      </a>

      <?php the_excerpt(); ?>

    <?php endwhile;

    Everything renders as expected except the image…the img src is blank (“”).

    If I use the same code directly in the template (home.php) the image shows up correctly.

    Any thoughts?

    Thanks,
    Mordaga

  123. Janek Says:

    Hi Mordaga!
    I just tried it out. It took a while but obviously $post->ID doesn’t work for some reason. You should try
    <?php echo get_post_meta(get_the_ID(), "offerimg", true); ?>
    instead.

  124. mordaga Says:

    Thanks Janek!

    That did the trick.

    I’m glad you were able to decipher my comment.
    I negelected to use tags.

    -Mordaga

  125. mordaga Says:

    The pre tag seemed to not work either.

    How do you get the code to render correctly in a comment?

    Thanks again,
    Mordaga

  126. Janek Says:

    Well, if you replace each < with a &lt; in your code, everything should be displayed correctly. (unfortunately you only have one try ;o)

  127. mohammad rashid Says:

    I am getting the following error! I tried unintalling and re-installing the widget, but no luck! Please help.

    wp-content/plugins/mycustomwidget/my_custom_widget.php on line 97

  128. Janek Says:

    Hm, that doesn’t help very much. In line 97 the widgets or filters are loaded to be sorted. What are you doing or what did you do before the error occured. Is there a specific error message?

    If you can, try to delete the entries mcw_mywidgets and mcw_options in your table wp_options by using a tool such as phpmyadmin and install the whole plugin again afterwards (try to download the current version)
    Usually you should be able to delete these entries by using the corresponding button on the settings-screen.

  129. Mohammad Rashid Says:

    I think that did the trick Janek. Thanks

  130. svdasein Says:

    I just want to thank you for the work and the plugin – The plugin counts as a whole fist-full of silver bullets if you ask me. Awesome work. Thanks!

  131. Janek Says:

    @mordaga: I just found a small issue. It’s possible that your comments section gets corrupted when you use a loop in your widgets (e.g. the comments will might show up in the wrong post). The widget does not has even to be added to the sidebar.

    @svdasein: THX – If you like, visit the download page and vote for me. (I only have 2 ratings so far ;o(

  132. Michael Says:

    Great plugin ! It offers a lot of flexibility. No problems so far in a custom theme that I am developing ! You deserve at least a vote.
    Nice work.

  133. Cathy Says:

    First, thanks for this plugin – it’s exactly what I need. However, I’m mostly at a loss when it comes to php. I can understand what it’s doing, but not how to write it.

    So, I don’t understand how to execute php and html in the same widget. I have a widget I want to add a link in (to an interior page) and then execute php underneath that (the output from another plugin). If I put the html in the separate html box, it works great. Whenever I try to put the html in with the php (messing around with various possible php tag combos), I get nothing – the widget doesn’t display anything below the html block.

    Unfortunately, the php for the other plugin doesn’t have the php tags, so I have to set the widget to read php and not html.

    What the proper way I should be doing this?

    I’m just afraid that with an update to the plugin that removes the html block, I’m in trouble and a whole bunch of custom widgets will break.

    Thanks!

  134. Janek Says:

    Hi Cathy,
    As a matter of fact you do not have to use the separate html box, if you want to combine html and php code in your widget.
    Just proceed as follows:
    - create a new html widget
    - enter your html code first
    - followed by a php-start tag <?php
    - enter your php-code afterwards
    - and finish the php part by entering the php-end tag ?>

    In the end your code should look like this:

    <a href='http://asdf.com'>Link</a>
    <?php
    myphpfunction();
    ...
    ?>

    If you want you can also define a php widget. In this case your code should look like this:

    ?>
    <a href='http://asdf.com'>Link</a>
    <?php
    myphpfunction();
    ...

  135. Cathy Says:

    Janek,

    Thanks for getting back to me so fast! After a few stray characters were erased, it worked!

  136. My Custom Widget for Your Custom Blog | Real Estate Blog Lab Says:

    [...] If you’re new here, you may want to subscribe to my RSS feed. Thanks for visiting!My Custom Widget [...]

  137. Bloodhound Scenius in a Widget | Real Estate Blog Lab Says:

    [...] recently ran across another plugin (My Custom Widget) which I decided to try and I like it much better. It is easier to get your Senius widget code up [...]

  138. barcino Says:

    Hello, thanks a lot for the great work, but I still have a question. It might be a stupid one but I’m not a programmer and I’m new to Wordpress.

    Here is my question

    I just created a widget, named “MyFirstWidget” and inserted some html code in it…everything looks good so far, but I don’t know how to call the widget using PHP…I mean I want to insert the widget somewhere between the content and the footer of the main index…

    Can you tell me please what I have to do it?

    Thank for the help

  139. Janek Says:

    Hi barcino.
    I am not sure if I got you right. You said you are new to wordpress so I start from the beginning. Usually you do not call a widget by using php. Widgets are (usually) used within sidebars. As a matter of fact your theme has to support widgets (some old themes do not). If you are not sure, take a look at the appearance-menu in your wordpress administration section. If you click at “appearance->Widgets” all available widgets should be displayed. This includes your new custom-widget “MyFirstWidget”. Just add the widget to the sidebar and everything should work fine.

    If that is not exactly what you want, it might become a little bit tricky – especially if you are not familiar with wordpress.
    If you do not want to add the widget to a sidebar there is another way to make a widget appear that you have created with this plugin. By default you can add the string <!--MyFirstWidget--> to any article where the CustomWidget should appear. This works because the string will be replaced with the content of your widget automatically. But this technique might not work if you put the string outside of your articles.

    Another possibility would be to change your current theme directly and add the following code wherever you want the widget to appear (e.g. between content and footer).
    <?php echo apply_filters('the_content', '<!--MyFirstWidget-->'); ?>

    I do not know which theme you are using so I cannot give you more tips. If you tell me the name of your current theme and/or the url of your blog, can take another look at the problem…

  140. Tiago Ferretti Says:

    Hi!

    I’m trying to create a widget with but it returns blank.

    Help!

  141. Janek Says:

    Hi Tiago!
    I took a look at your site and your custom-widget “parceiros” seems to work fine.

    So my questions would be:
    1. Does the problem still exists?
    2. Do you have any more information? (maybe the code you want to be displayed)
    3. Can you describe what you are doing? (which filters?, html or php?)

  142. Jja Says:

    Hi Janek

    Thanks for the good work. I am new to WP and not a php pro (Im a quick learner though). I’ve been looking for a fix to display some widgets (mainly RSS feeds) in the content area instead of sidebar. I’m convinced this can be done with your MCW but not sure how to proceed. I understand I may need to add the following code (got from your post to barcino on this page) anywhere I need to display it in my theme template (my theme DOES support widgets – I also tested a MCW in the sidebar and it is fine).

    <?php echo apply_filters('the_content', '<!--MyRssWidget-->'); ?>

    If that first step is correct, how can I display the RSS widget in my custom widget ? (i.e. make the RSS widget or any other widget a Custom Widget). Is this possible ? I greatly appreciate any step by step instructions/directions. Would it be a good idea to put the above code in a Page istead? Is this feasible in a page ? Or just make a new template for it ?

    Cheers

  143. Janek Says:

    Hi John,
    So you want to add a normal widget that has not been created with this plugin somewhere outside of the sidebar by using this plugin?
    As long as you did not changed anything within the plugin-settings everything should just work fine for a CustomWidgets created with this plugin.
    BUT: converting another widget into a CustomWidget is a completely different task.

    I think there are 3 possible solutions:
    1. Create a new CustomWidget with that is doing the same work as the original widget. (< – might be difficult)
    2. Extracting the content of the widget from somewhere (I have no idea how that works or if that is even possible) or start the corresponding function-call directly.
    3. Creating a new sidebar and adding the widget by using the wordpress standard functionality.

    I think I have to evaluate solution variant 2 and 3… (but without guarantee ;) )

  144. Janek Says:

    Okay, I finally found a solution that should work…

    To display a foreign widget through a CustomWidget the following code can be used.
    1. create a new CustomWidget that will contain the foreign widget (e.g. “MyRssWidget”)
    2. add the php-code below into the code area of the widget
    3. announce the ID of the foreign widget you want to be displayed (e.g. “RssWidget“)(if you do not know the ID of the widget take a look at the links in the wordpress administration
    4. add the code snipped <?php echo apply_filters('the_content', '<!--MyRssWidget-->'); ?> to your theme or <!--MyRssWidget--> to a post. (That’s your decission and depends on your requirements.)

    Code within MyRssWidget:


    $use_widget ='RssWidget;';

    global $wp_registered_widgets;
    $sidebar = array(
      'before_widget' => $before_widget,
      'after_widget' => $after_widget,
      'before_title' => $before_title,
      'after_title' => $after_title
    );
    $id = $use_widget;
    $params = array_merge(
      array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
      (array) $wp_registered_widgets[$id]['params']
    );
    // Substitute HTML id and class attributes into before_widget
    $classname_ = '';
    foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
      if ( is_string($cn) )
        $classname_ .= '_' . $cn;
      elseif ( is_object($cn) )
        $classname_ .='_' . get_class($cn);
    }
    $classname_ = ltrim($classname_, '_');
    $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
    $params = apply_filters('dynamic_sidebar_params', $params );
    $callback = $wp_registered_widgets[$id]['callback'];
    if ( is_callable($callback) ) {
      call_user_func_array($callback, $params);
    }

    Well, that might be a new feature that would be available in one of the next releases…

  145. Jja Says:

    Thanks Janek for your prompt reply and enthusiasm..

    I found a ready plugin which promises to do the job for me (still having troubles wth it though – Lexi) but I’m still interested in trying to make this work here if you dont mind.

    My questions/confusions are at your third point. I’m not sure about the widget id thing that I need to announce. I’m using the RSS that comes with WP and I’m assuming it is called RssWidget. In the widgets admin I hover over the ADD link and see no id’s at all. I see “key” however http://...... wp-admin/widgets.php?message=updated&sidebar=sidebar-1&key=353767412&base=rss&add=rss-353767412&_wpnonce=f725f9dd7c

    I’m also not sure what you meant by “announce the ID”. I appologise for my perhaps stupid questions but it is all so new to me in WP.

    Cheers

  146. Janek Says:

    That is not a stupid question. I think the entry you have to add to the very top of the code snipped must be $use_widget ='rss-353767412';
    I just tried it on my site but it did not work. Maybe something is special with this particular widget. I will take a look at it tomorrow.

    PS: I am still working on a permanent solution. If it does not work, you might have to wait a couple of days till the new feature is ready.

  147. Janek Says:

    Okay, I finally added the new feature to convert an existing widget into a CustomWidget.
    This means:
    - You can dublicate any* existing widget.
    - You can use the filters for any* other widget as well.
    - You can add any* widget to your site (even outside of the sidebar

    * Unfortunatelly this feature does not work in all cases. For example the wordpress standard widget “RSS” cannot be used… yet(?)

  148. Maarten Says:

    Hi Janek,

    I have the latest version of your plugin and try to use existing widgets with My Custom Widget. They work, but I have problems with the styling. I can use the following for custom widgets:

    echo $before_widget;
    echo $before_title;
    echo “Title”;
    echo $after_title;
    [Existing plugin code]
    echo $after_widget;

    But for existing widgets, how do I refer to the existing plugin code? It would be great if I do not have to look for the original php code for each existing widget and if I can add the $before_widget etc code before existing widgets. Or maybe you can add these in the code so that they are used always.

    Great plugin though!

  149. Maarten Says:

    I looked at your code and you do seem to incorporate the before_widget codes, however, in my case they don’t show up for the event_calendar and the archives widgets.

    I think somewhere they are not passed along correctly.

  150. Janek Says:

    Hi Maarten,
    I’ll take a look at this problem asap. Thanks for the feedback…

  151. Susan Says:

    I’m using the option of front page displays my latest posts. But I would like to add an editable “welcome message” at the top of the home page. I was thinking this would allow that but I am completely as a loss as to how I would implement it. Using WP 2.6.2. Will I be able to accomplish this?

  152. Will Says:

    Hi Janek

    I have just installed htis on wordpress 2.7.2.

    I am using an identifyer, in this case <!–homepageAdRentLegal–> to replace with a widget on the_content. However, when it parses, it adds the widget but leaves the text ‘homepageAdRentLegal’ on the page also?

    Do you know what the problem might be?

    Thanks, Will.

  153. Will Says:

    RESOLVED: Previous post

    There is an unlabelled field above the widget content which I was putting the name of the widget into also. So just removed that.

  154. Janek Says:

    @Maarten: I fixed the bug with version 1.8.1. Thanks again…
    @Susan: This might be possible by creating a new CustomWidget (e.g. my_welcome) and pasting a <?php echo apply_filters('the_content', '<!--my_welcome-->'); ?> into the corresponding theme-file between header and content. (But I am sure that there might be a more elegant way. Maybe by using a seperate plugin.) Which theme are you using? Maybe I can help.
    @Will: I am glad it was not my fault… ;o)

  155. Jip Says:

    Hello,
    Maybe it’s explained in the comments here, but I couldn’t find it.
    My question is, how do I add the code of a different plugin to my widgets?
    This is the code the plugin needs to show the form:
    [contact-form 3 "Newsletter"]

    When I add that to a page, it will show, but when I paste it in the editor of mycustom widget, it just shows the code. I tried some things with <?php and so, but it didn’t work out.
    Or is there another way of making that code a widget?
    I would be very glad if you could help me out. Thanks,
    JiP

  156. Janek Says:

    Hi JiP!
    Well, that’s a feature I added by accident. I am currently having a BBQ at the beach, which means I have no time at the moment ;o)… …but I will post a small tutorial this evening.

  157. Janek Says:

    Well, it’s not realy a tutorial: Simply go to the option page, activate the point “Apply Filter/Tag on Widget” (mark “yes”) for the filter the_content (enter “the_content” into the textbox).
    After activating this option your code should be replaced by the plugins content.

  158. Jip Says:

    Thanks!
    That did help.
    Keep up the bbq’s and plugin work ;)
    Cheers

  159. Will Says:

    Hi Janek

    Is it possible to call a widget from within a template?

    Thanks, Will.

  160. Janek Says:

    I am not sure if I got you right. What do you mean with template? Do you want to integrate a widget into your wordpress theme permanently?

    If so, just enter <?php echo apply_filters('the_content', '<!--my_widget-->'); ?> e.g. between content and footer and the widgets content should show up.

    Cheers, Janek

  161. Will Says:

    I have some sidebar elements throughout the website I am building. So I create them and store them with your plug-in. I then show them by looking up the custom fields for that page. For example I have a telephone number widget. In my template I would do:

    if(get_post_meta($post->ID,'tel-widget',1) == TRUE {

    //Get the telephone widget from mycustomwidgets

    }

    I hope this makes it a little clearer?

    Thanks

  162. Janek Says:

    Hi Will,
    one possible solution might be the following.

    You can add a check to the widgets code or you create an own filter “use_tel” on the settings screen with the following content get_post_meta(get_the_ID(),"tel-widget",1) == TRUE.
    The function get_the_ID() returns the ID of the last post that has been identified within the last loop. For some reason $post->ID does not work.

    The tricky thing is: This does only work if you do not use any other widget wich is using a loop because this could lead to a wrong postID (e.g. a RecentPostsWidget).

    Hope this works for you
    Janek

  163. Will Says:

    Thanks for providing a workaround, however, I think it will be quicker to just seperate the side bar elements into individual php files to inlcude according to the custom fields in each page.

    Thanks anyway, Will.

  164. Craig Says:

    Hi Janek,

    I’d like to know if it is possible to change the style associated with a particular custom widget that is based upon an existing widget (background colour etc) I think this is something to do with the instruction-

    “When activating this functionality an additional each CustomWidget will be surrounded by a <div id="widgetname" class="mcw"> container.
    Use the following selector to specify attributes: #widgetname.mcw

    Could you explain how I might implement this instruction?

    Many thanks!

  165. Janek Says:

    Hi Craig,

    if you activate the CSS-Wrapper-option you can define a style which is used for custom widgets only.
    The style definition itself has to be added to the css-file of your theme (or by using another plugin if you want to).

    This statement would make the background of your CustomWidget “widgetname” green:

    #widgetname.mcw{
      background-color: green;
    }

    This statement would make the background of each CustomWidget yellow:

    .mcw{
      background-color: yellow;
    }

  166. Craig Says:

    Hi Janek,

    I tried adding the code to the stylesheet as you suggested but I’m not getting any change :-( Maybe if I give some background info which might help clarify how I’m trying to do this :

    I’m using the Atahulpha theme within which, there are options to put additional css into the theme. I copied the code you kindly provided into each of these and then all of them but nothing changed. I also tried putting the code directly into the stylesheeet as suggested but nothing again.

    When I view the widget with Firefox and start Firebug, I can inspect the widget and I can see the style (as suggested by yourself) as newly defined in the stylesheet.

    This is a copy of what I can see:-

    A test title

    This is test content

    I’ve also tried moving the widget from the left sidebar to the right in case it was the theme that was limiting in some way.

    Other than that I’m a bit stumped!

    Any futher help would be appreciated,

    Thanks again,

    Craig

  167. Craig Says:

    Hi janek,
    Me again (sorry)

    Just picked up some info from bytesforall who designed the theme and they mention another way of changing widget styles by entering:

    div#pages { background-color: blue;
    }

    into the CSS customisable part of the theme. This works for standard widgets so I wonder if there is a problem with the way I entered your suggested code?

    thanks,

    Craig

  168. Janek Says:

    Well, I just made a test with “Atahualpa 3.3.2″.
    - I created a CustomWidget called “test1
    - I added it to the left sidebar
    - I added the following css-code to the top of /wp-content/themes/atahualpa332/style.css:

    #test1.mcw{
    background-color: green;
    }

    –> et voilà: the background of the widget was green.

    It might be helpfull to know the URL of your site. Maybe another style is overwriting your entries…

  169. Craig Says:

    Hi Janek,

    I’ve managed to change the style at long last – thanks again for your prompt help!

    Craig

  170. Kai Says:

    Thanks for a great plugin, but the plugin is not working for me anymore.

    I have now 28 custom Widgets. When I try to update, add new or do anything else nothing is saved to the database.

    The “plugin options” page is working as normal but not “widget configuration”.

    I can’t turn on the Debug-Mode either.

    I turned the JavaScript off. It worked again for some time. But now it don’t again.

    Maybe there is some limit for how many custom Widgets I can have? Or is it a bug?

  171. Janek Says:

    Hi Kai,

    I did not even know that someone has so many widgets :)

    Usually there should not be a restriction. But on the other side: all widgets are stored in a single database-entry. Maybe this single entry becomes to large after that many widgets.
    I’ll try to create a new version which will store the widgets in seperate entries. But I think this will take a while because I will need an aditional routine for conversion.

  172. Kai Says:

    Thanks for your quick reply. Yes, it will be better when not all widgets is stored in a single database entry. I donate 50 dollar when the new version is finish.

    Thanks again for your great work :)

  173. Janek Says:

    I’ll try to finish the version till next sunday. Hopefully it will solve your problem (and hopefully it will not corrupt your existing widgets ;) ). I am still not able to reproduce the error and deactivating JavaScript shouldn’t helped if it really is a database problem…

    We will find out…

    Update: Let’s say wednesday…

  174. Janek Says:

    Well, finally it’s finished. It was a little bit tricky to assure that the backup-functionality still works downward compatible.

    Hopefully this will solve your problem.

  175. David Says:

    Fantastic plugin.

    Thanks for all of your hard work on keeping this updated!

  176. Antoine Says:

    Hi Janek !

    Thanx for this great plugin.
    It works great, but I have a question :

    I’m working on a multiple sidebars site.
    My problem is that when I affect a widget to one sidebar, it becomes no longer available for the other ones.

    Is it a limit of the plugin or a limit of myself ?
    Is there a way to bypass the problem ?

    ;)

    Antoine (Please, excuse my poor english | Hope it was understandable)

  177. Janek Says:

    Salut Antoine,
    that is a restriction of wordpress itself… and the reason why I implemented the copy functionality some month ago.

    Simply create a new CustomWidget and take a look at the small “copy from widget”-field on the very bottom of the content area. Here you can choose in a list of all widgets that are available on your site. Just choose the widget you want to add a second time and press save. You will see that even though the orginial widget cannot be added twice, the MyCustom-”Copy”-Widget is available.

    Unfortunately this copy feature does not work for all widgets and you will not get access to any customizing dialogues of the original widget (if available).

    Hope this helps.

    Janek

  178. Antoine Says:

    Merci ( ;) ) Janeck,

    In fact, the “copy from widget” function is a very interesting feature, but it finds quickly its limits when you using a lot of widget with à lot of dynamic sidebars…

    I’m looking forward to solve this wordpress limitation.
    I’ll let you know if I manage to find a solution.

    Antoine

  179. sebastien Says:

    Love your plugin. Exactly what I needed.

    Just a quick question regarding sending the set up to another wordpress site using this plugin: I do not want to mess with the db and stuff.

    Is there any way to use the backup function, and upload this backup to another site, and “restore” this backup ?

    Again, thanks!

    Sebastien

  180. sebastien Says:

    Forgot to add:

    - can I use a hardcoded code froma plugin in your widget (ie {wpxxx} ) to call a plugin ?

    - I know there is javascript and html and php. Can I also add flash ?

    S.

  181. Janek Says:

    Salut Sebastien,
    Unfortunately it is not possible to transfer the widgets to another side without getting into the database. So the only way would be to copy each widget manually.

    If another plugin uses a tag ({wpxxx}) as a placeholder for a widget-content you can add this tag to a html-CustomWidget. But you will have to activate the “Apply Filter/Tag on Widget”-feature in the option section and add a filter that affects your sidebar(http://codex.wordpress.org/Plugin_API/Filter_Reference).
    Another solution would be to leave the option section as it is, define a CustomWidget and apply the corresponding filter (e.g. the_sidebar) manually by adding <?php echo apply_filters('the_sidebar', '{wpxxx}'); ?> as the content.

    JavaScript should work without any restrictions.

    Janek

  182. sebastien Says:

    Merci Janek!

    I guess I will just copy paste for now :)

    By the way, what plugin do you use for the math ?

    Sebastien

  183. Janek Says:

    It is called “Math Comment Spam Protection” (http://www.janek-niefeldt.de/blog/plugins)

  184. sebastien Says:

    Encore merci.

    Well the page states for WP 2.2. I just have 2.7.1. Don’t want to risk it (i just did a clean install!)

  185. Janek Says:

    I currently use 2.7.1 for myself and as you can see the plugin works fine. But hey… it’s your decission… :)

  186. Thomen Says:

    Hello.
    Very useful plugin. But help me please to solve a problem :(
    When I creating new widget – all works perfectly. It can be added in Presentation –> Widgets, but not shown on a site page (in widgets body is a simple text, even without any tags).
    But if I simply copying existing widget – it’s shows without any problems with all content (like all standart widgets)
    P.S. sorry for my bad English

  187. Thomen Says:

    Sorry !
    I’m noob !! I wasn’t read a readme and don’t select pages where to show created widget. All works perfectly – tanks !!!

  188. karen Says:

    Jenek; great widget. thanks for providing it to the community. I am wondering if you have any plans to update it for WP 2.8?

    Best,
    Karen

  189. Janek Says:

    Uhhh, this is going to be tricky…
    The good news: All widgets that have been added to the sidebars before upgrading to 2.8 will still be available.
    The bad news: New CustomWidgets will not be displayed in the Widget-menu. Therefore they cannot be added. I’ll take a look at it asap.

    I’ll keep you informed.

  190. Janek Says:

    Well, does anyone now how to generate classes dynamically in php?

  191. Andrew Waegel Says:

    Hello,

    Great plugin, using it a lot.

    The only problem is with using the custom widgets in WP pages – I understand that I should be able to put the widget’s name surrounded by a comment string, like in the content field and then get the Widget content rendered there, but all I get is the comment itself.

    Is there anything special I need to do to activate this feature? I have ‘yes’ and ‘the_content’ entered for ‘Make MCW-Tags available (for specific filter)’ and ‘Apply Filter/Tag on Widget’

    Thanks!

  192. Andrew Waegel Says:

    Hello,

    I do believe I found a bug on line 1068:
    $maxi = count($Widgets_all);
    …should be
    $maxi = count($Widget_IDs_all);

    …otherwise the filters never get added because $maxi == 0.

    - Andrew

  193. Larry Vallely Says:

    Hey!

    Love the plugin! im really looking forward to the 2.8 support and am holding off till it goes functional. This one of the best and most versatile plugs that i use!

  194. Janek Says:

    Well, I am still working on this. I still cannot find out what the developer meant with:

    [...] Widget development has become easier since version 2.8. [...]

  195. Janek Says:

    I think I don’t like Wordpress 2.8. They changed almost everything which makes it realy difficult to keep all features available.

    Here are the facts:

    • WP2.8 requires a class definition for each kind of widget that should be available
    • You can have multible instances of widget (which is actually pretty much what I was doing with my plugin as well)
    • I’ve found a bug regarding these multible widgets
    • [...]

    Until now, I was just able to reimplement the plugin’s basic functionality by using the new API.

    Here is what I was not able to implement, yet (sorted by priority):

    1. using widgets outside of the sidebar
    2. preview (and debugging) functionality
    3. backup-functionality (very tricky)
    4. downward compatibility (very tricky as well)
    5. widget configuration through an additional screen (sub-menu appearance)
    6. copying existing widget (should not be required because multible instances can be created know)

    “Much work! – but not much time!”

    Nevertheless: If you have already upgraded please take a look at this Alpha-Release of MyCustomWidget 2.0.

  196. Scott Kingsley Clark Says:

    Are you aware of any 2.7.1 issues with My Custom Widget showing on sidebars that are on 404 Pages?

  197. Janek Says:

    Hi Scott
    No, I have never seen such a problem (so far). But the problem might might be caused by the code you have defined within your CustomWidgets. Maybe you should start removing your CustomWidgets one by one to pinpoint the source of the problem.
    Please make sure that you have installed the whole plugin including all files.

  198. Marc Aurel Says:

    Your plugin is fantastic! Keep going and adjusting it to WP 2.8!
    All the best!!!

  199. Hannes Says:

    Thank you for this usefull plugin. I use it very often. Now I have problem. I cannot find a solution:

    $q = new WP_Query("category_name=".$cat);
    if ( $q->have_posts() ) {
    echo "";
    while ( $q->have_posts() ) {
    $q->the_post();
    echo "<a href='".get_permalink()."' rel="nofollow">".get_the_title()."</a>";
    }
    echo "";
    }

    It ist working fine. But single Post on the site now has the right title and content but the comment belongs to the last post from the widget and not from the site

    You can find it
    http://livinglines.at/coachit/2009/05/25/perspektivenwechsel/
    Thank you for help!

  200. Janek Says:

    Hi Hannes,

    that is a problem that comes up when using multible loops. But there might be another way to get access to specific posts (» thanks to wozzyozzy).

    foreach(get_posts('category='.$cat) as $q) :
    $id = $q->ID;
    echo "<a href='".get_permalink($id)."' rel='nofollow'>".get_the_title($id)."</a>";
    endforeach; ?>

    Best Regards
    Janek

  201. Hannes Says:

    Thank you for quick and efficiency help! It works very nice!

    Thank you a lot!
    Hannes

  202. mrsnak Says:

    Well, I lucked out with Custom Widget on 2.8. Needed to insert some html easily in the sidebar and I managed to get 2 to work. First one on left showed up in widgets immediately and was able to place. Took a couple times deleting and renaming to get the other one to show.

    Still trying to get one that’s just a Twitter logo with link to show. Don’t know what it’s not liking, but maybe if I keep my fingers crossed. :-)

    Brand new to Wordpress, so not a lot of choice about versions for me.

  203. mrsnak Says:

    Tried the 2.0 beta. Doesn’t work.
    Even deactivating the previous version, it doesn’t show in the Appearance menu, nor do any widgets display in the widget area.
    I guess I was really lucky with getting two to work in your previous version.
    Have not seen any other program that does what I need so easily.
    Have a menu (as a widget) that I need to place, so hope the 2.0 bugs will get worked out.

  204. Janek Says:

    Well, 2.0beta does not have any entry in the appearance menu but a single entry in the WP-widgets menu (look for MCW 2.0).

  205. Janek Says:

    Finally the new version is finished. I had to evaluate several alternatives and chose to make a compromise between the new features introduced with Wordpress 2.8.

    Unfortunately the new version does not work with wordpress <2.7.1. NO PANIC the data model did not changed, which means all widgets that have been created so far should still be available.

    Thanks for your patience…

    To make the plugin works, please chmod the file my_custom_widget_classes.php to 0666 (read/writeable for all).

  206. mrsnak Says:

    Do have to recreate widgets I made in 1.9 for them to work in 2.0?

  207. Janek Says:

    It might be necessary to add the widgets to the sidebars again (I am not sure how wordpress handles the registration in detail now). Nevertheless: the widget-definitions themself will not be changed during upgrade. I recomment to use the backup functionality as a… well, as a backup ;)

  208. David Brewster Says:

    Janek,

    Great plugin. However I have upgraded to MCW2.0 and changed the permissions for my_custom_widget_classes.php, plus deactivated and reactivated the plugin, but still none of my widgets are available. All I can see is an MCW 2.0 Addon widget in the ‘available widgets’ box

  209. Janek Says:

    Hi David

    Obviously the corresponding Widget classes have not been generated, yet.

    Please go to the MyCustomWidget-screen in the appearance menu and double-check if your widgets are available. As soon as you save a single widget or press “save all” the content of my_custom_widget_classes.php will be generated. Your widgets should appear afterwards.

    This workarround should do the trick. Thanks for the feedback. I will adjust the plugin’s coding accordingly later.

  210. Janek Says:

    By the way: Which iPhone-theme-plugin do you use on your site? Looks pretty awesome…

  211. David Brewster Says:

    Janek,

    I did as you suggested and saved one of my widgets. But then I got a syntax error whenever I did anything:

    Parse error: syntax error, unexpected T_STRING, expecting ‘{‘ in /home/davidbre/public_html/blog/wp-content/plugins/mycustomwidget/my_custom_widget_classes.php on line 58

    I managed to track it down – one of my custom widgets had a space in the name. I deleted it in the code and recreated it with an underscore and problem solved. Not sure why it worked in the previous version but no now.

  212. David Brewster Says:

    The iPhone theme plugin I use is WPtouch iPhone Theme

  213. David Brewster Says:

    New problem now. Having worked out the above, my widgets now appear on the widgets page. However, I can’t drag them into the sidebars. Where standard widgets are fine, custom widgets drag slowly and won’t ’stick’. I get a trail of boxes on the page – weird. A widget might look as though it is in place but on refreshing the page it remains where it started.

  214. Janek Says:

    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…

  215. David Brewster Says:

    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

  216. Janek Says:

    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.

  217. Guido Says:

    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

  218. Janek Says:

    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

  219. Jonathan MAyberg Says:

    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

  220. Janek Says:

    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

  221. linus Says:

    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

  222. Janek Says:

    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…

  223. Randy Says:

    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

  224. Janek Says:

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

  225. Janek Says:

    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

  226. Randy Says:

    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

  227. linus Says:

    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>’;

    }?>

  228. linus Says:

    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…

  229. linus Says:

    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.

  230. Janek Says:

    @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.

  231. Janek Says:

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

    Maybe he will change the function you are using…

  232. blogs.uugrn.org » Blog Archive » Update der Plugins Says:

    [...] My Custom Widgets (v. 2.0.3) by Janek Niefeldt. [...]

  233. Debi Says:

    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.

  234. Janek Says:

    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

  235. David Brewster Says:

    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.

  236. Janek Says:

    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

  237. David Brewster Says:

    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

  238. Janek Says:

    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…

  239. Olivier Says:

    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

  240. Olivier Says:

    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

  241. Janek Says:

    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

  242. Olivier Says:

    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

  243. blogs.uugrn.org » Blog Archive » Plugin-Update 2009/08/31 Says:

    [...] My Custom Widgets (v. 2.0.3) by Janek Niefeldt. [...]

  244. blogs.uugrn.org » Blog Archive » Plugin-Update 2009/09/23 Says:

    [...] My Custom Widgets (v. 2.0.3) by Janek Niefeldt. [...]

  245. Randy Says:

    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

  246. blogs.uugrn.org » Blog Archive » Plugin-Updates 2009/10/05 Says:

    [...] My Custom Widgets (v. 2.0.3) by Janek Niefeldt. [...]

  247. Saibot Says:

    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.

  248. RADU Says:

    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

  249. Janek Says:

    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

  250. Leah Says:

    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.

  251. Peter Says:

    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

  252. Janek Says:

    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
    }
    }
    ?>

  253. Peter Says:

    Hey Janek,

    thanks for your quick help.

    But somehow it still doesn´t work…

  254. Sebas Says:

    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

  255. Janek Says:

    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

  256. Top 1000 WordPress Plugin Authors « Metode de promovare Says:

    [...] My Custom Widgets [...]

  257. Magads Says:

    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">

  258. Janek Says:

    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

  259. Magads Says:

    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; ?>

  260. MyCustomWidget | WordPress News Says:

    [...] Visit link: MyCustomWidget [...]

  261. shana Says:

    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.

  262. blogs.uugrn.org » Blog Archive » Plugin-Updates 2009/12/08 Says:

    [...] My Custom Widgets (v. 2.0.3) by Janek Niefeldt. [...]

  263. Leo Says:

    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.

  264. Los plugins más utilizados | Zumo de marketing Says:

    [...] Plugin: My Custom Widgets [...]

  265. MaryAnn Says:

    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!

  266. MaryAnn Says:

    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.

  267. Janek Says:

    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

  268. MaryAnn Says:

    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

  269. Janek Says:

    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?

  270. Mirromaru Says:

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

  271. Ben Says:

    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

  272. Ben Says:

    Oops, looks like it stripped the code – it’s the first example using ‘posts list with offset’

    -b

  273. Janek Says:

    Hi Ben.

    I don’t think I really understood what your widget tries to do or what the problem is. Maybe you can send me the coding via email.
    Nevertheless: This sounds like a very common issueregarding multible loops. If you use a loop inside of your widget the loop that should work for the content area will be affected as well.

    You might want to take a look at this post: http://wordpress.org/support/topic/263448

  274. Ben Says:

    Hi Janek,

    Thanks for getting back to me – that post might be the answer, I’ll check it out and get back to you.

    Cheers,

    Ben

Leave a Reply

10 + 7 ?