myCRED Lottery Add-on 1.2 Beta is now available!

Home / Blog / myCRED Lottery Add-on 1.2 Beta is now available!

After re-writing most of the code, I am proud to announce the next version of the Lottery add-on plugin for myCRED! This new version will bring you the most requested features along with huge improvements “under the hood”.

This post is a bit long, but includes a detailed summary of all new features and changes coming to 1.2.

Existing license holders can download the beta from your profile by visiting the “Store Purchases” page in the sub-menu of your myCRED.me profile. It’s not recommended to be used on live sites where you have existing lotteries currently running. Instead it should be used on development or test sites where you can afford to lose existing lottery details should an error occur.

Important.

The 1.2 version will draft all lotteries when you update from previous versions! For this reason it is very important that you do not update until the lottery has reached the “Pay” state or if you choose to fast forward to this position. The reason for this is the new schedule mechanism which now allows you to set the exact time of each lottery states.

Remember to post your findings in the Premium Support Forum to receive your Tokens for helping me out!

Installation & Upgrade

Installation

Version 1.2 is installed just like any other plugin with no special setup. Once the plugin has been activated, 1.2 will install the two new database tables that will be used from now on to store users entries and the history of each lottery.

This will allow much quicker db queries to calculate winners and to store lottery entries.

The two new tables are:

  • wp_myCRED_lottery_entries – responsible for keeping track of lottery entries.
  • wp_myCRED_lottery_results – responsible for keeping track of lottery history.

I have added two new constants that you can define in your wp-config.php file which you can use to customize the table names. These are:

  • MYCRED_LOTTERY_ENTRY_TABLE
  • MYCRED_LOTTERY_RESULTS_TABLE

A quick example to change this would be:

define( 'MYCRED_LOTTERY_ENTRY_TABLE', 'wp_lottery_entries' );

Updating from previous versions

When you update the Lottery add-on from a previous versions, on update the add-on will go though all your lotteries and transfer their current history to the new database table. It is highly recommended that you do the update when all your current lotteries are in the “Pay” state waiting to start (if they are recurring) or once they are finished.

As always, make sure you backup your database before updating to prevent any data from being lost and DO NOT install and activate both the beta and the current version on the same website!

Displaying Lotteries

Out of a visual perspective, 1.2 does not bring any major changes to how lotteries are displayed. Any custom CSS styling you have added to your lottery up-until now should still work. There are two minor changes made though:

  1. An extra DIV element has been added to the form to help resolve issues with floating elements not being properly cleared.
  2. The “My Entries” button will now return a table element to present a users entries both for “Draw” and “Pick Numbers” lotteries. Make sure your results are presented properly when you click on this button.

Managing Lotteries

Just like in previous versions, once the plugin has been installed you will find all your lotteries in your myCRE menu or your main point type menu if you use multiple point types.

No changes have been made to this page and you can still add entries manually for lotteries that are in the “Start” position.

New Schedules

As of 1.2 you can now create “Manual” lotteries where you yourself select when a lottery is to start, close, draw the winners / numbers and payout. Adding in this manual option caused me to completely rewrite the schedule mechanism because now, you can also set the exact time each states to be run.

Furthermore, as you might have spotted in the above screenshot, you can also create monthly schedules now and you no longer need to reload the editor each time you want to change the schedule. I have added in a AJAX script which will reload the schedule when you select which one you want to use, presenting you with the information required.

Remember to make sure you have setup your timezone in your main WordPress Settings for correct schedule times.

New Winnings

In previous versions you could only award a set amount of points, but now, in 1.2 you can select to award a set amount or an amount based on a formula. I also wanted to add in the option to award store products but this turned out to be way to complicated right now. Instead this will be added in upcoming versions.

By editing your lottery you will now have a new option called “Winners get” where you can select if you want to award a set amount or use a formula. For formulas, I have added a few constants that you can use. To help test your fomula, you will find a new “Evaluate” button next to each formula field. Use this button to evaluate your formula and make sure you are getting the results you want. You can do this even on new lottereies that does not yet have any values in which case the editor will provide you with some default values.

The following constants are avaiable for formulas:

  • PAYMENTS – the total amount of points paid to play this lottery. If no payments have been made, the test evaluation will use 10 as value for this constant.
  • ENTRIES – the total number of entries in the current draw. If no entries have been made, the test evaluation will use 10 as value for this constant.
  • REFUNDS – the total amount of points refunded for this lottery. If no refunds have been made, the test evaluation will use 10 as value for this constant.
  • POINTTYPE – the winners balance at the time of payout in the selected point type. So if your point type (in plural form) is set to be “Points” the constant will be POINTS (always uppercase) or if it’s called “Credits” the constant will be CREDITS. Note that plural names that uses space or multiple words like My Credit will not work. In testing this constant your balance will be used for testing. If you are excluded from using points, the test evaluation will use 100 as value .
  • JACKPOT – the current jackpot amount if this is a “Pick Numbers” lottery and the Jackpot is enabled. If no jackpot exist, the test evaluation will use 1000 as value for this constant.

New Fast Forward

Draft Lotteries
Published Lottery pending start
Lottery is open to players
Lottery Closed
Winners / Winning Numbers Drawn
Winners Paid

With the introduction of “Manual Schedules” the fast forward system has been re-writen. If your lottery has a schedule that is anything but “Manual”, fast forwarding will re-schedule the Cron job for the lottery! So if your lottery is scheduled, the fast forward feature should only be used if a Cron job failed or the scheduled event simply never happened. If you want to have 100% control over when lotteries start, close etc. please use the “Manual” schedule!

Depending on which state the lottery is in, you are also presented different options. For example when you close a lottery, you are given the option to cancel and refund all entries. This is only available when the lottery has been closed. Once the winners / numbers are drawn, refunds are no longer possible.

The “Refresh Page” button will not save any changes you might have made, it will only refresh the current page to update the totals. If you make any changes that you want to save, please use the blue “Update Lottery” button.

New Pick Number Process

By storing all the users log entries in a separate table, I was able to drastically reduce the processing time the plugin needs to run though all entries and find matches.

I have also updated the random pick script to improve how randomness of drawn winners and numbers.

New & Improved Widgets

(myCRED) Lottery Winners

This new widget allows you to show the winning users of a particular lottery.

  • Title – Optional widget title.
  • Lottery – The lottery for which you want to show the results for. Note that only “Activated” lotteries will show up here. Draft lotteries or trashed lotteries will not!
  • Number of Draws – The number of draws you want to show if the lottery is recurring or you have manually run the lottery multiple times. Use -1 to show all.
  • Order – The order of the results being presented.
  • Result Template – This is the main template used for each draw. In this template you can use %date% to show the draw date, %time% to show the time and %winners% to show the list of winners for this draw. You can also use general template tags here but not user related!
  • Users Template – The template for each user that is returned by the above %winners% template tag. This is where you can use user related template tags or %ticket% to show the ticket ID.
  • No Draws Message – Message to show users for new lotteries that have not had any results.

(myCRED) Lottery Winning Numbers

This widget allows you to show the winning numbers drawn by a particular lottery.

  • Title – Optional widget title.
  • Lottery – The lottery for which you want to show the results for. Note that only “Activated” lotteries will show up here. Draft lotteries or trashed lotteries will not!
  • Number of Draws – The number of draws you want to show if the lottery is recurring or you have manually run the lottery multiple times. Use -1 to show all.
  • Order – The order of the results being presented.
  • Result Template – This is the main template used for each draw. In this template you can use %date% to show the draw date, %time% to show the time and %numbers% to show the list of winning numbers. You can also use general template tags here.
  • No Draws Message – Message to show users for new lotteries that have not had any results.

New Shortcode

1.2 comes with a new shortcode called mycred_lottery_winnings which allows you to show what a user can win if they have correctly picked the winning numbers of a particular lottery. Each time the lottery draws these numbers, the shortcode will show how many users have made correct picks.

In the above screenshot I am using a demo lottery where 1 correct pick gives nothing so that row is not shown in the shortcode. Note that if you are using a formula, the formulas result will show up here and dynamically update if you are using a constant.

Once the lottery has been re-started, the winners count will reset to zero as all old entries are deleted.

New Price

Version 1.2 of the Lottery add-on will be available from $ 35.

Existing license holders can update previous versions to 1.2 free of charge!

Last edited July 16, 2014