2014-12-15 22:38:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class UM_Access {
|
|
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
$this->redirect_handler = false;
|
|
|
|
|
$this->allow_access = false;
|
2014-12-15 22:38:07 +02:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
add_action('template_redirect', array(&$this, 'template_redirect'), 1000 );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @do actions based on priority
|
|
|
|
|
***/
|
|
|
|
|
function template_redirect() {
|
2015-11-05 19:51:31 +08:00
|
|
|
global $post, $ultimatemember;
|
|
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
do_action('um_access_homepage_per_role');
|
|
|
|
|
|
|
|
|
|
do_action('um_access_global_settings');
|
|
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
do_action('um_access_category_settings');
|
|
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
do_action('um_access_post_settings');
|
|
|
|
|
|
2015-11-25 20:38:20 +08:00
|
|
|
if ( $this->redirect_handler && !$this->allow_access && ! um_is_core_page('login') ) {
|
2015-02-11 00:50:38 +02:00
|
|
|
|
|
|
|
|
// login page add protected page automatically
|
2015-11-25 20:38:20 +08:00
|
|
|
|
2015-02-11 00:50:38 +02:00
|
|
|
if ( strstr( $this->redirect_handler, um_get_core_page('login') ) ){
|
|
|
|
|
$curr = $ultimatemember->permalinks->get_current_url();
|
2016-03-03 22:04:23 +08:00
|
|
|
$this->redirect_handler = add_query_arg('redirect_to', urlencode_deep($curr), $this->redirect_handler);
|
2016-03-02 21:50:18 +08:00
|
|
|
$this->redirect_handler = esc_url( $this->redirect_handler );
|
2015-02-11 00:50:38 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 21:50:18 +08:00
|
|
|
wp_redirect( $this->redirect_handler );
|
|
|
|
|
|
2015-02-10 02:05:27 +02:00
|
|
|
}
|
2014-12-15 22:38:07 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @get meta
|
|
|
|
|
***/
|
2015-01-24 23:39:43 +02:00
|
|
|
function get_meta( $post_id ) {
|
2014-12-15 22:38:07 +02:00
|
|
|
global $post;
|
|
|
|
|
$meta = get_post_custom( $post_id );
|
2015-02-07 01:39:29 +02:00
|
|
|
if ( isset( $meta ) && is_array( $meta ) ) {
|
|
|
|
|
foreach ($meta as $k => $v){
|
|
|
|
|
if ( strstr($k, '_um_') ) {
|
|
|
|
|
$k = str_replace('_um_', '', $k);
|
|
|
|
|
$array[$k] = $v[0];
|
|
|
|
|
}
|
2014-12-15 22:38:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $array ) )
|
|
|
|
|
return (array)$array;
|
|
|
|
|
else
|
|
|
|
|
return array('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|