Hi @tgilber007,
This is working now, Also, the YouTube subscription code, It’s very old code, It doesn’t work now.
add_shortcode( 'water_consumption', 'mycredpro_click_for_points' );
function mycredpro_click_for_points( $atts, $content = '' ) {
extract( shortcode_atts( array(
'ref' => '',
'message' => '',
'hours' => 2,
'points' => 10
), $atts ) );
$last_entry = false;
// Must be logged in to see this shortcode
if ( ! is_user_logged_in() ) return;
// Get current time
$now = current_time( 'timestamp' );
$user_id = get_current_user_id();
// Get last entry
$log = new myCRED_Query_Log( array(
'user_id' => $user_id,
'ref' => $ref,
'number' => 1
) );
if ( $log->have_entries() )
$last_entry = $log->results[0];
// Intercept button clicks
if ( isset( $_GET['water-intake'] ) && isset( $_GET['token'] ) && wp_verify_nonce( $_GET['token'], 'new-water-intake' ) ) {
// User clicked on button, award points
if( !$last_entry || ( $last_entry && (int)$last_entry->time + ( $hours * HOUR_IN_SECONDS ) <= $now ) )
{
mycred_add(
$ref,
$user_id,
$points,
'Report of water intake'
);
}
// Show users a message showing they got points or something
return '<p>' . $message . '</p>';
}
// User has an entry
if ( $log->have_entries() ) {
// Make sure enough time has passed by removing x hours from the current time
if ( (int)$last_entry->time + ( $hours * HOUR_IN_SECONDS ) <= $now ) {
// Show the user the button they need to click on
return '<a href="' . add_query_arg( array(
'water-intake' => $now,
'token' => wp_create_nonce( 'new-water-intake' )
) ) . '" class="btn btn-primary">Click to report water intake</a>';
}
}
else
{
// Show the user the button they need to click on
return '<a href="' . add_query_arg( array(
'water-intake' => $now,
'token' => wp_create_nonce( 'new-water-intake' )
) ) . '" class="btn btn-primary">Click to report water intake</a>';
}
// Else just show somethig for users
return '<p>' . $content . '</p>';
}