Limit Reset For Reward For Clicking On Links
-
Hello
I have enabled the reward for clicking on link and it works great however its only once for a link, and there are no limits. Does it reset every 24 hours? Meaning users can click on the link once everyday?
-
Hello Morchi,
Thanks for contacting us. Hope you are doing well.
The user will get points only once for clicking on a unique link. If you want to use multiple shortcodes you will have to provide either a unique url or unique ID for every shortcode.
For more information please go through the documentation.Let me know if you have any questions. We will help you out.
Thanks & Regards,
WP Experts Support TeamHey, thank you for your reply. Is there a way to reset every 24 hours? I have a single page where users get a reward for visiting it, but currently, it’s only possible once. I want to make it so that users can visit that page every day to collect their coins and not just once
You can try using the shortcode and function below.
Custom WordPress shortcode:
Try using the below code snippet and let us know if it works for you:
add_shortcode( ‘mycred_max_link’, ‘mycred_render_max_link’ );
function mycred_render_max_link( $atts, $content ) { // Make sure myCRED is installed // Not applicable for visitors if ( ! is_user_logged_in() ) { return ''; } $atts = shortcode_atts( array( // ... (your existing attributes) 'max_click_interval' => 24 * 60 * 60, // 24 hours in seconds ), $atts ); $mycred = mycred( $atts['ctype'] ); global $wpdb; $user_id = get_current_user_id(); // Check max click requirement and time interval if ( $atts['max_clicks'] > 0 ) { $last_click_time = get_user_meta( $user_id, 'last_click_time', true ); if ( $last_click_time && ( time() - $last_click_time ) < $atts['max_click_interval'] ) { // Clicks are limited to once every 24 hours, and the time hasn't elapsed return ''; } $wpdb->insert( $mycred->log_table, array( 'user_id' => $user_id, 'ref' => 'link_click', 'data' => $atts['href'], 'time' => current_time( 'mysql' ), ) ); // Update the last click time in user meta update_user_meta( $user_id, 'last_click_time', time() ); } // Let myCRED run the mycred_link shortcode. return mycred_render_shortcode_link( $atts, $content ); }
Let me know if you have any questions.
Thanks
Should i add the function in functions.php ?
can you give me an example on how i would go about it, if the link i want to share is “example.com/page1” and reward 100 coins
Sorry for asking too many questions, and thanks.
- This reply was modified 1 year ago by morshi.
Yes add this code snippet in your active theme’s functions.php file.
Refer to the myCred Link clicks documentation. It will run in the same way. Functionality will remain the same. We have just created a custom shortcode for you.
add_shortcode( ‘mycred_max_link’, ‘mycred_render_max_link’ );
function mycred_render_max_link( $atts, $content ) { // Make sure myCRED is installed if ( ! function_exists( 'mycred' ) ) { return 'myCRED is not installed'; } // Not applicable for visitors if ( ! is_user_logged_in() ) { return ''; } $atts = shortcode_atts( array( 'id' => '', 'rel' => '', 'class' => '', 'href' => '', 'title' => '', 'target' => '', 'style' => '', 'amount' => 0, 'ctype' => 'mycred_default', 'max_clicks' => 0, 'hreflang' => '', // for advanced users 'media' => '', // for advanced users 'type' => '' // for advanced users 'max_click_interval' => 24 * 60 * 60, // 24 hours in seconds ), $atts ); $mycred = mycred( $atts['ctype'] ); global $wpdb; $user_id = get_current_user_id(); // Check max click requirement and time interval if ( $atts['max_clicks'] > 0 ) { $last_click_time = get_user_meta( $user_id, 'last_click_time', true ); if ( $last_click_time && ( time() - $last_click_time ) < $atts['max_click_interval'] ) { // Clicks are limited to once every 24 hours, and the time hasn't elapsed return ''; } $wpdb->insert( $mycred->log_table, array( 'user_id' => $user_id, 'ref' => 'link_click', 'data' => $atts['href'], 'time' => current_time( 'mysql' ), ) ); // Update the last click time in user meta update_user_meta( $user_id, 'last_click_time', time() ); } // Let myCRED run the mycred_link shortcode. return mycred_render_shortcode_link( $atts, $content ); }
Let me know if you have any questions/confusion. We will help you out.
Thanks
Thanks i have implemented as mentioned above. I have to wait now to test, is there anyway i can confirm if its working withou waiting for 24 hours?
Sorry but we need to wait 24 hours to execute this process.
There is no option for now.
Thanks
ok thanks, i will let you know then ??
Sure.
We are here to help you. Let me know.
Thanks
i dont seem to get coins, i pasted the code in functions.php and added this on the page – [mycred_link amount=100 id=”4508″ href=”mypagelink” target=”_blank”] YOUR COINS[/mycred_link] and it doesnt work.
- This reply was modified 1 year ago by morshi.
Sorry for the inconvenience.
Our team is checking on this. We will update you soon.
Thanks
Use the shortcode as follows:
[mycred_max_link ctype=”mycred_default” amount=1 href=”https://www.mycred.me” target=”_blank”]View portfolio[/mycred_max_link]
Here is the modified version of the code:
add_shortcode( 'mycred_max_link', 'mycred_render_max_link' ); function mycred_render_max_link( $atts, $content ) { // Make sure myCRED is installed if ( ! function_exists( 'mycred' ) ) { return 'myCRED is not installed'; } // Not applicable for visitors if ( ! is_user_logged_in() ) { return ''; } $atts = shortcode_atts( array( 'id' => '', 'rel' => '', 'class' => '', 'href' => '', 'title' => '', 'target' => '', 'style' => '', 'amount' => 0, 'ctype' => 'mycred_default', 'max_clicks' => 0, 'hreflang' => '', // for advanced users 'media' => '', // for advanced users 'type' => '', // for advanced users 'max_click_interval' => 24 * 60 * 60 // 24 hours in seconds ), $atts ); $mycred = mycred( $atts['ctype'] ); global $wpdb; $user_id = get_current_user_id(); if (!is_user_logged_in()) { return ''; } $transient_key = 'mycred_id_' . $user_id; // Check if 'id' is not set or if 24 hours have passed if (empty($atts['id']) || get_transient($transient_key) === false) { // Assign a new unique identifier to 'id' $atts['id'] = uniqid(); // Save the new 'id' and timestamp to a transient set_transient($transient_key, time(), 24 * 60 * 60); } // Check max click requirement and time interval if ( $atts['max_clicks'] > 0 ) { $last_click_time = get_user_meta( $user_id, 'last_click_time', true ); if ( $last_click_time && ( time() - $last_click_time ) < $atts['max_click_interval'] ) { // Clicks are limited to once every 24 hours, and the time hasn't elapsed return ''; } $wpdb->insert( $mycred->log_table, array( 'user_id' => $user_id, 'ref' => 'link_click', 'data' => $atts['href'], 'time' => current_time( 'mysql' ), ) ); // Update the last click time in user meta update_user_meta( $user_id, 'last_click_time', time() ); } // Let myCRED run the mycred_link shortcode. return mycred_render_shortcode_link( $atts, $content ); }
Please try with this code and let me know if it works fine for you.
Hope to hear from you soon.
Thanks
let me try and i will get back, thanks alot ??
Sure, Let me know if you have any question/issue.
Hello, thank you very much for your help. It works now ??
- The topic ‘Limit Reset For Reward For Clicking On Links’ is closed to new replies.