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!


Posted

in

by

Comments

10 responses to “24th Door – The WPE Quit Smoking Widget”

  1. Darfuria Avatar
    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 Avatar

    Now that’s a fun widget 🙂
    Awesome series you’ve built here, was very great to follow. Muchas congratulations 🙂

  3. Michael Avatar

    @Ozh: It was a pleasure. Merry Christmas.

  4. Cindy Avatar

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

  5. Michael Avatar

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

  6. nik Avatar
    nik

    „Aber was muss ich tun wenn ich ohne Widgets arbeite?“

    Weiterrauchen : )

  7. Tomáš Kapler Avatar

    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 Avatar

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

  9. Ian Avatar

    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 Avatar

    Sorry, the file is gone after moving to our new server 🙁