Files
ultimatemember/core/um-access.php
T

59 lines
1.2 KiB
PHP
Raw Normal View History

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-02-10 02:05:27 +02:00
global $ultimatemember;
2015-01-07 08:37:25 +02:00
do_action('um_access_homepage_per_role');
do_action('um_access_global_settings');
do_action('um_access_post_settings');
2015-02-10 02:05:27 +02:00
if ( $this->redirect_handler && !$this->allow_access ) {
2015-02-11 00:50:38 +02:00
// login page add protected page automatically
if ( strstr( $this->redirect_handler, um_get_core_page('login') ) ){
$curr = $ultimatemember->permalinks->get_current_url();
2015-04-25 21:41:47 +02:00
$this->redirect_handler = esc_url( add_query_arg('redirect_to', $curr, $this->redirect_handler) );
2015-02-11 00:50:38 +02:00
}
2015-01-07 08:37:25 +02:00
exit( 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('');
}
}