-
Notifications
You must be signed in to change notification settings - Fork 0
/
show-member-content.php
53 lines (39 loc) · 1.49 KB
/
show-member-content.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/*
Plugin Name: Show Member Content Shortcode
Plugin URI: http://www.ameliabriscoe.com/
Version: 1.0
Author: Amelia Briscoe
Description: Show content if a member has a specific capability and was registered X days ago.
*/
/**
* Is the current user registred for more than x days ago?
* @param int $delay
* @return bool
*/
function acab_is_user_member( $delay = '' ){
$cu = wp_get_current_user();
return( isset( $cu->data->user_registered ) && (strtotime( $cu->data->user_registered ) < strtotime( sprintf( '-%d days', $delay ) )) );
}
add_shortcode( 'member_show', 'acab_member_shortcode' );
/**
* Shortcode [member_show] to show content to registered members only after X amount of days
*
* @param array $atts
* @param string $content
* @return string $content
*/
function acab_member_shortcode( $atts = array(), $content = '' ){
$atts = shortcode_atts(
array(
'delay' => '1',
'capability' => 'read',
'message' => 'Slow down partner, you don\'t have access to this content yet!'
), $atts, 'member_show' );
if ( function_exists( 'acab_is_user_member' ) )
if( is_user_member( (int) $atts['delay'] ) && current_user_can( $atts['capability'] ) )
return $content;
elseif( !is_user_member( (int) $atts['delay'] ) && current_user_can( $atts['capability'] ) )
return $atts['message'];
return 'This content is for members only.';
}