Adds [um_loggedin] shortcode to protect content

This commit is contained in:
Ultimate Member
2016-01-02 01:36:11 +02:00
parent fac38c09c6
commit eab1e87e34
5 changed files with 81 additions and 1 deletions
+17
View File
@@ -88,4 +88,21 @@
animation-timing-function: linear;
-webkit-animation-iteration-count: 1;
animation-iteration-count: 1;
}
/* content lockers */
.um-locked-content {
width: 100%;
box-sizing: border-box;
border: 2px dotted #cc3000;
color: #333;
background: #fff;
font-size: 14px;
padding: 20px;
border-radius: 4px;
margin-bottom: 20px;
}
.um-locked-content a {
border: none !important;
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+16
View File
@@ -42,12 +42,26 @@
$s = strlen($s) > $length ? substr($s,0,$length)."..." : $s;
return $s;
}
/***
*** @Convert urls to clickable links
***/
function um_clickable_links($s) {
return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" class="um-link" target="_blank">$1</a>', $s);
}
/***
*** @Get where user should be headed after logging
***/
function um_dynamic_login_page_redirect( $redirect_to = '' ) {
global $ultimatemember;
$uri = um_get_core_page( 'login' );
if ( ! $redirect_to ) {
$redirect_to = $ultimatemember->permalinks->get_current_url();
}
$uri = add_query_arg( 'redirect_to', $redirect_to, $uri );
return $uri;
}
/***
*** @convert template tags
@@ -63,6 +77,7 @@
'{email}',
'{password}',
'{login_url}',
'{login_referrer}',
'{site_name}',
'{site_url}',
'{account_activation_link}',
@@ -85,6 +100,7 @@
um_user('user_email'),
um_user('_um_cool_but_hard_to_guess_plain_pw'),
um_get_core_page('login'),
um_dynamic_login_page_redirect(),
um_get_option('site_name'),
get_bloginfo('url'),
um_user('account_activation_link'),
+42
View File
@@ -9,6 +9,8 @@ class UM_Shortcodes {
$this->loop = '';
add_shortcode('ultimatemember', array(&$this, 'ultimatemember'), 1);
add_shortcode('um_loggedin', array(&$this, 'um_loggedin') );
add_filter( 'body_class', array(&$this, 'body_class'), 0 );
@@ -175,6 +177,38 @@ class UM_Shortcodes {
return $classes;
}
/***
*** @Logged-in only content
***/
function um_loggedin( $args = array(), $content = "" ) {
global $ultimatemember;
ob_start();
$defaults = array(
'lock_text' => __('This content has been restricted to logged in users only. Please <a href="{login_referrer}">login</a> to view this content.','ultimatemember' ),
'show_lock' => 'yes'
);
$args = wp_parse_args( $args, $defaults );
$args['lock_text'] = $this->convert_locker_tags( $args['lock_text'] );
if ( !is_user_logged_in() ) {
if ( $args['show_lock'] == 'no' ) {
echo '';
} else {
$ultimatemember->shortcodes->set_args = $args;
$ultimatemember->shortcodes->load_template( 'login-to-view' );
}
} else {
echo do_shortcode( $this->convert_locker_tags( $content ) );
}
$output = ob_get_contents();
ob_end_clean();
return $output;
}
/***
*** @Shortcode
***/
@@ -369,6 +403,14 @@ class UM_Shortcodes {
$shortcode = '[ultimatemember form_id='.$post_id.']';
return $shortcode;
}
/***
*** @convert access lock tags
***/
function convert_locker_tags( $str ) {
$str = um_convert_tags( $str );
return $str;
}
/***
*** @convert user tags in a string
+5
View File
@@ -0,0 +1,5 @@
<div class="um-locked-content">
<div class="um-locked-content-msg"><?php echo $lock_text; ?></div>
</div>