3v4l.org

run code in 300+ PHP versions simultaneously
<?php function restrict_posting_points( $user_id, $activity_value, $activity_id, $activity_type ) { $max_posts_per_day = 2; $user_id = $user_id; $key = 'daily_post_count'; $single = true; $daily_post_count = get_user_meta($user_id, $key, $single); // create the meta data for the user's first post // *TODO* should this be added to the user creation step? if ( $daily_post_count == '' ) { $values = array( 'post_count' => 0, 'expiry_date' => strtotime( 'tomorrow' ), ); add_user_meta( $user_id, $key, $values ); $daily_post_count = get_user_meta($user_id, $key, $single); } $num_posts = $daily_post_count['post_count']; // a new day has passed, reset the daily post count if ( time() > $daily_post_count['expiry_date'] ) { $num_posts = 0; $daily_post_count['expiry_date'] = strtotime('tomorrow'); } // full points are awarded for the first two posts of the day if ( $num_posts < $max_posts_per_day ) { $num_posts ++; $values = array( 'post_count' => $num_posts, 'expiry_date' => strtotime( 'tomorrow' ), ); update_user_meta($user_id, $key, $values); return $activity_value; } return 0; } ?>
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0

preferences:
201.56 ms | 404 KiB | 322 Q