mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
Adds [um_loggedin] shortcode to protect content
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -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'),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<div class="um-locked-content">
|
||||
|
||||
<div class="um-locked-content-msg"><?php echo $lock_text; ?></div>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user