您可以尝试以下操作:
/**
* Is the current user registred for more than x days ago?
*
* Based on the compare idea in this answer:
* http://stackoverflow.com/a/7130744/2078474
*
* @link http://wordpress.stackexchange.com/a/143597/26350
* @param int $reg_days_ago
* @return bool
*/
function is_user_reg_matured( $reg_days_ago = 30 )
{
$cu = wp_get_current_user();
return ( isset( $cu->data->user_registered ) && strtotime( $cu->data->user_registered ) < strtotime( sprintf( \'-%d days\', $reg_days_ago ) ) ) ? TRUE : FALSE;
}
这应该会返回
TRUE
对于注册超过
x
几天前,以及
FALSE
针对访客(未登录)和其他用户。
用法示例:
if( is_user_reg_matured( 30 ) )
{
// show content
}
快捷码:例如,您可以将其添加为快捷码:
[is_user_reg_matured reg_days_ago="30 ]
Content for register matured users only
[/is_user_reg_matured]
使用:
add_shortcode( \'is_user_reg_matured\', \'is_user_reg_matured_shortcode\' );
/**
* Shortcode [is_user_reg_matured] to show content to register matured users only
*
* @link http://wordpress.stackexchange.com/a/143597/26350
* @param array $atts
* @param string $content
* @return string $content
*/
function is_user_reg_matured_shortcode( $atts = array(), $content = \'\' )
{
$atts = shortcode_atts(
array(
\'reg_days_ago\' => \'30\',
), $atts, \'is_user_matured\' );
if ( function_exists( \'is_user_reg_matured\' ) )
if( is_user_reg_matured( (int) $atts[\'reg_days_ago\'] ) )
return $content;
return \'\';
}