• Resolved tgilber007

    (@tgilber007)


    Hi the code not work to me if anything want to change in this code
    thanks in advance

    https://pastebin.com/LZykvxeY

    [water_consumption ref=”track_water” message=”Congrats. Your water intake is tracked” hours=1 points=5]You have already tracked your water intake![/water_consumption]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter tgilber007

    (@tgilber007)

    A.Tariq

    (@arsalantariq)

    Hi @tgilber007,

    Thank you for contacting us, we have forwarded the details to the technical team we will get back to you once we heard back from them.

    A.Tariq

    (@arsalantariq)

    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>';
     
    }
    Thread Starter tgilber007

    (@tgilber007)

    Thank you the code is working well

    1.another how to disable the video after it watched by the user

    2. Allow users to gain points for watching the same video every 24 hours https://pastebin.com/h9wdkZpX This code is not work for me

    I tried this one also its not work https://mycred.me/support/forums/topic/seem-to-have-lost-video-watching-points/

    
    add_action( 'mycred_has_entry', 'mycred_pro_unlimited_video_points', 10, 6 );
    function mycred_pro_unlimited_video_points( $has_entry, $reference, $ref_id, $user_id, $data, $type ) {
    
    	if ( $reference == 'watching_video' )
    		return false;
    
    	return $has_entry;
    
    }
    • This reply was modified 3 years, 1 month ago by tgilber007.
    A.Tariq

    (@arsalantariq)

    @tgilber007,

    Our QA Team is looking into it will get back to you soon.

    A.Tariq

    (@arsalantariq)

    @tgilber007,

    This code is working perfectly fine Daily Video View Points – Pastebin.com , Make sure you used this code in current theme’s functions.php file.
    And hook should be enabled Points for viewing Videos.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Only click every 2 hours’ is closed to new replies.