24th Door – The WPE Quit Smoking Widget

For the last door in our Advent Calendar I had something special in mind. This year is coming to an end and I'm sure some of our readers want to quit smoking next year. To support their goal, I created a WP Engineer Quit Smoking Widget. ๐Ÿ˜‰


Here a screenshot of all setting possibilities:

WP Engineer Quit Smoking Widget

And this is how it would look like on your blog:

WP Enigineer Quit Smoking Widget Output

Even though, this idea seemed to be easy to realize. It was a piece of work. I don't want you to be bored, so I'm not explaining the whole code, but I just want go in detail on some details, what I had to consider to make this Widget workable.

I check the date if it's valid ( 2009/02/30 doesn't exist). Then I had to avoid division by zero, if the Widget is active but doesn't include any values yet. For the correct formatting of the saved money depending on the language I used the WordPress function number_format_i18n:

$saved = number_format_i18n($packs * $price, 2);

Unfortunately, there is no feature in WordPress, which displays the currencies correctly (but I guess, this is probably not necessary). Therefore, I added a field "Currency position" with the values "before" and "after", so that the currency will be displayed properly, depending on the country. The year field automatically displays the current year minus 5 years, so that the widget is also current in 100 years. ๐Ÿ˜‰
The rest are fields for entering the text output before and after values.

Installation

Unzip file wpe_quit_smoking_widget.zip and copy it to wp-content/plugins/ , then activate it in your backend. After that the Widget will be available in your Widgets area.

Please Note: The Widget needs WordPress Version 2.8 or higher, otherwise it won't be displayed.

Download

Download WPEngineer Quit Smoking Widget

Have fun with the Widget and good luck with your goal to stop smoking! The team of WP Engineer wish you all Happy Holidays!

Comments are closed.

10 comments

  1. Darfuria

    That's a nice little widget - I like it.

    However, it should read "Smoking free since 577 days ago" - not really an issue as you can add your own text in the widget configuration.

  2. Ozh

    Now that's a fun widget ๐Ÿ™‚
    Awesome series you've built here, was very great to follow. Muchas congratulations ๐Ÿ™‚

  3. Michael

    @Ozh: It was a pleasure. Merry Christmas.

  4. Cindy

    Hey klasse! Aber was muss ich tun wenn ich ohne Widgets arbeite?

  5. Michael

    @Cindy: mach dir eine kleine Widgetarea in der Sidebar nur fรผr dieses Widget, sonst gehts nicht.

  6. nik

    โ€žAber was muss ich tun wenn ich ohne Widgets arbeite?โ€œ

    Weiterrauchen : )

  7. Tomรกลก Kapler

    it would be great to have also non-smoker variant
    I'm now 32 and i have never smoked.
    If i would have start smoked at the age of 13 as average in our country and smoked 5 cigarets a day as average in our contry, i would have smoked xy cigarets. I'have not so i have saved XY $ and longer my life for XY years, XY months, XY days.

  8. Zippo Lighters

    I stopped smoking 2 years ago and its the best thing that ive done to date.

  9. Ian

    I can't seem to find the download link. I would love to use this widget as I just quit this past New Years.

  10. Michael

    Sorry, the file is gone after moving to our new server ๐Ÿ™