Beispiel #1
0
/**
 * Get Access Area object.
 *
 * @param string|int $identifier Capability name or numeric ID.
 * @return object
 */
function wpaa_get_access_area($identifier)
{
    if (is_numeric($identifier)) {
        return UndisclosedUserlabel::get_userlabel($identifier);
    } else {
        if (wpaa_is_access_area($identifier)) {
            return UndisclosedUserlabel::get_userlabel_by_cap($identifier);
        }
    }
}
        static function ajax_add_access_area()
        {
            if (wp_verify_nonce(@$_POST['_wp_ajax_nonce'], 'userlabel-new') && current_user_can('promote_users')) {
                $cap_title = trim($_POST['cap_title']);
                if (!$_POST['blog_id'] && !is_super_admin() || $_POST['blog_id'] && $_POST['blog_id'] != get_current_blog_id()) {
                    ?>
<span class="disclosure-label-item error"><?php 
                    _e('Insufficient privileges.', 'wp-access-areas');
                    ?>
</span><?php 
                    // throw_error: insufficient privileges
                } else {
                    if (empty($cap_title)) {
                        ?>
<span class="disclosure-label-item error"><?php 
                        _e('Empty name.', 'wp-access-areas');
                        ?>
</span><?php 
                        // throw_error: empty name
                    } else {
                        $create_id = UndisclosedUserlabel::create_userlabel(array('cap_title' => $_POST['cap_title'], 'blog_id' => $_POST['blog_id']));
                        if ($create_id) {
                            $label = UndisclosedUserlabel::get_userlabel($create_id);
                            self::_select_label_formitem($label, true);
                        } else {
                            switch (UndisclosedUserlabel::what_went_wrong()) {
                                case 4:
                                    // Error: area exists
                                    ?>
<span class="disclosure-label-item error"><?php 
                                    _e('Access Area exists.', 'wp-access-areas');
                                    ?>
</span><?php 
                                    // throw_error: insufficient privileges
                                    break;
                            }
                        }
                    }
                }
            } else {
                ?>
<span class="disclosure-label-item error"><?php 
                _e('Insufficient privileges.', 'wp-access-areas');
                ?>
</span><?php 
                // throw_error: insufficient privileges
            }
            die;
        }
        static function edit_userlabels_screen($userlabel_id = 0)
        {
            global $wpdb;
            if ($userlabel_id) {
                $userlabel = UndisclosedUserlabel::get_userlabel($userlabel_id);
            } else {
                $userlabel = (object) array('cap_title' => '', 'blog_id' => get_current_blog_id());
            }
            $cap_title = $userlabel->cap_title;
            if (!$cap_title && isset($_REQUEST['cap_title'])) {
                $cap_title = $_REQUEST['cap_title'];
            }
            ?>
<div class="wrap"><?php 
            ?>
<div id="icon-undisclosed-userlabel" class="icon32"><br></div><?php 
            ?>
<h2><?php 
            if ($userlabel_id) {
                _e('Edit Access Area', 'wp-access-areas');
            } else {
                _e('Create Access Area', 'wp-access-areas');
            }
            ?>
</h2>
		<?php 
            self::_put_message();
            ?>
		<?php 
            ?>
<form id="create-user-label" method="post" action="<?php 
            echo $_SERVER['REQUEST_URI'];
            ?>
">
				<!-- Now we can render the completed list table -->
			<?php 
            if ($userlabel_id) {
                ?>
				<input type="hidden" name="id" value="<?php 
                echo $userlabel_id;
                ?>
" />
			<?php 
            }
            ?>

			<?php 
            wp_nonce_field('userlabel-' . ($userlabel_id ? 'edit' : 'new'));
            ?>
				<table class="form-table">
					<tbody>
						<tr>
							<th scope="row"><label for="title"><?php 
            _e('Access Area', 'wp-access-areas');
            ?>
</label></th>
							<td><input class="regular-text" maxlength="64" type="text" name="cap_title" value="<?php 
            echo $cap_title;
            ?>
" id="cap_title" placeholder="<?php 
            _e('New Access Area', 'wp-access-areas');
            ?>
" autocomplete="off" /></td>
						</tr>
					</tbody>
				</table>
				
				<button type="submit" class="button button-primary button-large"><?php 
            if ($userlabel_id) {
                _e('Save changes', 'wp-access-areas');
            } else {
                _e('Create Access Area', 'wp-access-areas');
            }
            ?>
</button>
			</form><?php 
            ?>
</div><?php 
        }
 function process_bulk_action()
 {
     //Detect when a bulk action is being triggered...
     $action = $this->current_action();
     $nonce = isset($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : false;
     if (!$nonce) {
         return;
     }
     if (-1 !== $action && wp_verify_nonce($nonce, 'bulk-' . $this->_args['plural'])) {
         switch ($action) {
             case 'delete':
                 foreach ($_REQUEST[$this->_args['plural']] as $ul_id) {
                     if ($ul = UndisclosedUserlabel::get_userlabel(intval($ul_id))) {
                         UndisclosedUserlabel::delete_userlabel(intval($ul_id));
                     }
                 }
                 return wp_redirect(add_query_arg(array('page' => 'user_labels', 'message' => 3, 'deleted' => count($_REQUEST[$this->_args['plural']])), $_SERVER['SCRIPT_NAME']));
             default:
         }
     }
 }