You can add custom scratch card templates via your theme or plugin. Registered templates are then selectable when you create a new card set. A custom template can contain just the images used or also game setup or winning payouts.
Template information is stored in an associative array where each template has a unique key and an array of setup.
Template array structure:
|Key||Type||Can be empty?||Description|
||string||No||The official name of the template. This is the name shown in the dropdown menu.|
||int||No||The minimum scratch percentage required for the card to considered "scratched".|
||int||No||The diameter of the "brush" in pixels.|
||int||No||The cards width in pixels.|
||int||No||The cards height in pixels.|
||string or int||No||Either the URL to the cover image or the attachment ID of the image.|
||string or int||Yes||Either the URL to the coin image or the attachment ID of the image. The default coin image is used if this is left empty.|
||string||Yes||The log template to use when users buy this card set. Leave empty to use the value set in the editor.|
||string||Yes||The log template to use when users get paid from a winning card. Leave empty to use the value set in the editor.|
||string||Yes||Optional message to use when a user wins.|
||array||No||The card payout setup. This needs to be an array where each payout row is represented. It must contain at least one payout row, which will be considered the "no win" row.|
The setup array is used by the “Winnings” metabox and controls the number of cards we want to create for each possible payout a card set can have. The first row in this array must always be the “No Win” row. This is represented by the value field which must be set to zero! You can add as many rows as you want as long as each one contains a payout value and an array of either image URLs or attachment IDs.
The number of cards we want to generate for each row should be suggestive. These values can always be changed once the template has loaded. The most important part if the background images that are used for each row.
The Fireworks template structure as an example.
'fireworks' => array( 'label' => __( 'Fireworks', 'mycred' ), 'minimum_scratch' => 75, 'brush_diameter' => 15, 'card_width' => 300, 'card_height' => 400, 'coin_image' => '', // optional 'cover_image' => plugins_url( 'assets/images/templates/fireworks/fireworks-cover.png', MYCRED_SCRATCH ), 'buy_log' => '', // optional 'win_log' => '', // optional 'win_message' => '', // optional 'setup' => array( array( 'number' => 100, 'value' => 0, 'attachment_ids' => array( plugins_url( 'assets/images/templates/fireworks/fireworks-nowin.png', MYCRED_SCRATCH ) ) ), array( 'number' => 10, 'value' => 10, 'attachment_ids' => array( plugins_url( 'assets/images/templates/fireworks/fireworks-win.png', MYCRED_SCRATCH ) ) ) ) )
I have created two skeleton functions for you as examples of how you can add a custom template from a theme or a plugin.
In this example, we assume the images are stored in an image folder inside our theme.
In this example, we assume the images are stored in an image folder inside our plugin.