Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Created February 13, 2014 13:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gabrielmerovingi/8975067 to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/8975067 to your computer and use it in GitHub Desktop.
Updated version of the mycred_lottery_results shortcode with added option to use user related template tags for each row.
/**
* [mycred_lottery_results] Shortcode Render
* @since 1.0
* @version 1.2
*/
if ( ! function_exists( 'mycred_lotto_render_draws' ) ) :
function mycred_lotto_render_draws( $atts, $content = NULL )
{
extract( shortcode_atts( array(
'id' => NULL,
'title_draw' => __( 'Past Winners', 'mycred_lotto' ),
'title_pick' => __( 'Drawn Numbers', 'mycred_lotto' ),
'user_row' => '%display_name%'
), $atts ) );
// Make sure lottery exists
$lottery_id = $id;
$lottery = new myCRED_Lottery( $lottery_id );
if ( ! $lottery->lottery_exists() )
return __( 'Could not find lottery.', 'mycred_lotto' );
$content = '<div class="mycred-lotto-results">';
$past_winners = get_post_meta( $lottery_id, 'lottery_winners', true );
if ( ! empty( $past_winners ) ) {
krsort( $past_winners );
ob_start(); ?>
<table style="width: 100%;">
<thead>
<?php switch ( $lottery->get_type() ) {
case 'draw' : ?>
<tr>
<th id="mycred-lottery-result-date" class="lottery-result-date"><?php _e( 'Date', 'mycred_lotto' ); ?></th>
<th id="mycred-lottery-result-winner" class="lottery-result-winner"><?php _n( 'Winner', 'Winners', count( $past_winners ), 'mycred_lotto' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $past_winners as $time => $numbers ) { ?>
<tr>
<td class="lottery-result-date"><?php echo $lottery->get_time_formated( $time ); ?></td>
<td class="lottery-result-winner">
<ol>
<?php foreach ( $numbers as $num => $entry ) {
$ticket = explode( '|', $entry );
$user = get_userdata( $ticket[1] ); ?>
<li><?php echo $lottery->mycred->template_tags_user( $user_row, false, $user ); ?></li>
<?php } ?>
</ol>
</td>
</tr>
<?php }
break;
case 'pick' : ?>
<tr>
<th id="mycred-lottery-result-date" class="lottery-result-date"><?php _e( 'Date', 'mycred_lotto' ); ?></th>
<th id="mycred-lottery-result-draw" class="lottery-result-drawno"><?php _e( 'Draw', 'mycred_lotto' ); ?></th>
<th id="mycred-lottery-result-winner" class="lottery-result-winner"><?php _e( 'Winning Numbers', 'mycred_lotto' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $past_winners as $time => $numbers ) { ?>
<tr>
<td class="lottery-result-date"><?php echo $lottery->get_time_formated( $time ); ?></td>
<td class="lottery-result-drawno">#<?php echo $lottery->get_draw_number(); ?></td>
<td class="lottery-result-winner"><span><?php echo implode( '</span> <span>', $numbers ); ?></span></td>
</tr>
<?php }
break;
} ?>
</tbody>
</table>
<?php
$content = ob_get_contents();
ob_end_clean();
}
$content .= '</div>';
return apply_filters( 'mycred_lotto_render_draws', $content, $atts, $lottery );
}
endif;
@ed1226
Copy link

ed1226 commented Oct 5, 2020

MyCred website not selling this lottery plugin anymore... do still have this plugin... i would like to purchase from you if you have it?

@gabrielmerovingi
Copy link
Author

I sold myCRED in 2018 so I don't own the lottery script I wrote.

@ed1226
Copy link

ed1226 commented Oct 6, 2020

Since the plugin no longer available for sell on their website... do you have the last 2018 version I can purchase from you?

@gabrielmerovingi
Copy link
Author

I don't have the rights to it anymore, even if they are not selling it anymore, they might be working on a new version. Either way, they own the code. The only thing you can do is to write a completely new one to suit your needs.

@ed1226
Copy link

ed1226 commented Oct 7, 2020

Okay.. thanks for the advice, have a great day 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment