Skip to content

Instantly share code, notes, and snippets.

@wplit
Created December 16, 2020 03:50
Show Gist options
  • Select an option

  • Save wplit/6f263523da9131ca81b8c1bc42abafc0 to your computer and use it in GitHub Desktop.

Select an option

Save wplit/6f263523da9131ca81b8c1bc42abafc0 to your computer and use it in GitHub Desktop.
user registration date
<?php
if ( function_exists( 'oxygen_vsb_register_condition' ) ) {
oxygen_vsb_register_condition(
'User Registration',
array('custom' => true, 'placeholder' => 'MM/DD/YYYY'),
array(
'==',
'is after',
'is before',
'== (month)',
'is after (month)',
'is before (month)',
),
'user_registration_date_callback',
'User'
);
}
function user_registration_date_callback( $value, $operator ) {
$user_info = wp_get_current_user();
$registered_time = strtotime($user_info->user_registered);
$registered_time_month = strtotime(date('Y-m-01', $registered_time));
$date = strtotime($value);
$date_month = strtotime(date('Y-m-01', $date));
if ($date === false) {
return false;
}
$diff = $registered_time - $date;
$diff = round($diff / (60 * 60 * 24));
$month_diff = $registered_time_month - $date_month;
$month_diff = round($month_diff / (60 * 60 * 24));
if ($operator == '==') {
return ($diff == 0);
}
elseif($operator == 'is after') {
return ($diff > 0);
}
elseif($operator == 'is before') {
return ($diff < 0);
}
elseif ($operator == '== (month)') {
return ($month_diff == 0);
}
elseif($operator == 'is after (month)') {
return ($month_diff > 0);
}
else {
return ($month_diff < 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment