2014-12-15 22:38:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class UM_Admin_Access {
|
|
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
|
|
|
|
|
|
$this->slug = 'ultimatemember';
|
|
|
|
|
|
|
|
|
|
add_action( 'load-post.php', array(&$this, 'add_metabox'), 9 );
|
|
|
|
|
add_action( 'load-post-new.php', array(&$this, 'add_metabox'), 9 );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @add a helper tooltip
|
|
|
|
|
***/
|
|
|
|
|
function tooltip( $text, $e = false ){
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
<span class="um-admin-tip">
|
|
|
|
|
<?php if ($e == 'e' ) { ?>
|
|
|
|
|
<span class="um-admin-tipsy-e" title="<?php echo $text; ?>"><i class="dashicons dashicons-editor-help"></i></span>
|
|
|
|
|
<?php } else { ?>
|
|
|
|
|
<span class="um-admin-tipsy-w" title="<?php echo $text; ?>"><i class="dashicons dashicons-editor-help"></i></span>
|
|
|
|
|
<?php } ?>
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @Checks core post type
|
|
|
|
|
***/
|
|
|
|
|
function core_post_type( $post_type ){
|
2015-01-26 16:58:31 +02:00
|
|
|
|
|
|
|
|
if ( strstr($post_type, 'um_') )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if ( !class_exists('UM_bbPress_API') && in_array($post_type,array('forum','topic','reply')) )
|
2014-12-15 22:38:07 +02:00
|
|
|
return true;
|
2015-01-26 16:58:31 +02:00
|
|
|
|
2014-12-15 22:38:07 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @Init the metaboxes
|
|
|
|
|
***/
|
|
|
|
|
function add_metabox() {
|
|
|
|
|
global $current_screen;
|
|
|
|
|
|
|
|
|
|
add_action( 'add_meta_boxes', array(&$this, 'add_metabox_form'), 1 );
|
|
|
|
|
add_action( 'save_post', array(&$this, 'save_metabox_form'), 10, 2 );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @load a form metabox
|
|
|
|
|
***/
|
|
|
|
|
function load_metabox_form( $object, $box ) {
|
|
|
|
|
global $ultimatemember, $post;
|
2015-01-27 01:52:11 +02:00
|
|
|
|
|
|
|
|
$box['id'] = str_replace('um-admin-access-','', $box['id']);
|
|
|
|
|
|
|
|
|
|
if ( $box['id'] == 'builder' ) {
|
|
|
|
|
$UM_Builder = new UM_Admin_Builder();
|
|
|
|
|
$UM_Builder->form_id = get_the_ID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
preg_match('#\{.*?\}#s', $box['id'], $matches);
|
|
|
|
|
|
|
|
|
|
if ( isset($matches[0]) ){
|
|
|
|
|
$path = $matches[0];
|
|
|
|
|
$box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] );
|
|
|
|
|
} else {
|
|
|
|
|
$path = um_path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$path = str_replace('{','', $path );
|
|
|
|
|
$path = str_replace('}','', $path );
|
|
|
|
|
|
|
|
|
|
include_once $path . 'admin/templates/access/'. $box['id'] . '.php';
|
2014-12-15 22:38:07 +02:00
|
|
|
wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_access_nonce' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @add form metabox
|
|
|
|
|
***/
|
|
|
|
|
function add_metabox_form() {
|
2015-02-05 02:18:20 +02:00
|
|
|
global $ultimatemember;
|
2014-12-15 22:38:07 +02:00
|
|
|
|
2015-02-05 02:18:20 +02:00
|
|
|
$types = $ultimatemember->query->get_post_types;
|
2014-12-15 22:38:07 +02:00
|
|
|
foreach($types as $post_type) {
|
2015-01-27 01:52:11 +02:00
|
|
|
|
2015-02-05 02:18:20 +02:00
|
|
|
if ( !$this->core_post_type( $post_type ) ) {
|
|
|
|
|
|
|
|
|
|
add_meta_box('um-admin-access-settings', __('Access Control'), array(&$this, 'load_metabox_form'), $post_type, 'side', 'default');
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 01:52:11 +02:00
|
|
|
do_action('um_admin_custom_access_metaboxes');
|
2015-02-05 02:18:20 +02:00
|
|
|
|
2014-12-15 22:38:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @save form metabox
|
|
|
|
|
***/
|
|
|
|
|
function save_metabox_form( $post_id, $post ) {
|
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
|
|
// validate nonce
|
|
|
|
|
if ( !isset( $_POST['um_admin_save_metabox_access_nonce'] ) || !wp_verify_nonce( $_POST['um_admin_save_metabox_access_nonce'], basename( __FILE__ ) ) ) return $post_id;
|
|
|
|
|
|
|
|
|
|
// validate user
|
|
|
|
|
$post_type = get_post_type_object( $post->post_type );
|
|
|
|
|
if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id;
|
|
|
|
|
|
|
|
|
|
// save
|
2015-01-27 01:52:11 +02:00
|
|
|
$multi_choice_keys = apply_filters('um_admin_multi_choice_keys', array() );
|
|
|
|
|
if ( $multi_choice_keys ) {
|
|
|
|
|
foreach( $multi_choice_keys as $k ) {
|
|
|
|
|
delete_post_meta( $post_id, $k );
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-15 22:38:07 +02:00
|
|
|
foreach( $_POST as $k => $v ) {
|
|
|
|
|
if (strstr($k, '_um_')){
|
|
|
|
|
update_post_meta( $post_id, $k, $v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|