static function init()
 {
     self::$post_stati = array('' => __('Don‘t change', 'wp-access-areas'), 'publish' => __('Public'), 'private' => __('Private'), 'draft' => __('Draft'), 'pending' => __('Pending Review'));
     self::$role_caps = array('wpaa_set_view_cap' => __('Change View Access', 'wp-access-areas'), 'wpaa_set_edit_cap' => __('Change Edit Access', 'wp-access-areas'), 'wpaa_set_comment_cap' => __('Change Comment Access', 'wp-access-areas'));
     add_option('wpaa_default_behavior', '404');
     add_option('wpaa_fallback_page', 0);
     add_option('wpaa_default_caps', array());
     add_option('wpaa_default_post_status', 'publish');
     add_option('wpaa_enable_assign_cap', 0);
     add_action('update_option_wpaa_enable_assign_cap', array(__CLASS__, 'enable_assign_cap'), 10, 2);
     add_filter('pre_update_option_wpaa_enable_assign_cap', array(__CLASS__, 'assign_role_cap'), 10);
     add_action('admin_menu', array(__CLASS__, 'create_menu'));
     add_action('admin_init', array(__CLASS__, 'register_settings'));
     add_action('load-settings_page_wpaa_settings', array(__CLASS__, 'load_style'));
 }
Exemplo n.º 2
0
/**
 * Activation hook
 */
function accessareas_activate()
{
    UndisclosedInstall::activate();
}
/**
 * Deactivation hook
 */
function accessareas_deactivate()
{
    UndisclosedInstall::deactivate();
}
/**
 * Uninstall hook
 */
function accessareas_uninstall()
{
    UndisclosedInstall::uninstall();
}
// access area data model
if (is_admin()) {
    UndisclosedCaps::init();
    UndisclosedUsers::init();
    UndisclosedEditPost::init();
    UndisclosedSettings::init();
}
register_activation_hook(__FILE__, 'accessareas_activate');
register_deactivation_hook(__FILE__, 'accessareas_deactivate');
register_uninstall_hook(__FILE__, 'accessareas_uninstall');
 private static function _delete_userlabel_from_blog(&$userlabel)
 {
     global $wpdb;
     $post_status_sql = '';
     $default_post_status = get_option('wpaa_default_post_status');
     if ($default_post_status && in_array($default_post_status, UndisclosedSettings::get_post_stati())) {
         $post_status_sql = $wpdb->prepare(" , post_status=%s ", $default_post_status);
     }
     // delete everything from posts and restore usefull default values
     $query = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_view_cap='exist' {$post_status_sql} WHERE post_view_cap=%s", $userlabel->capability));
     $query = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_edit_cap='exist' WHERE post_edit_cap=%s", $userlabel->capability));
     // back to default
     $query = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_comment_cap='exist',comment_status='closed' WHERE post_comment_cap=%s", $userlabel->capability));
     // back to default
     // set back options
     if (get_option('wpaa_default_view_cap') == $userlabel->capability) {
         update_option('wpaa_default_view_cap', 'exist');
     }
     if (get_option('wpaa_default_edit_cap') == $userlabel->capability) {
         update_option('wpaa_default_edit_cap', 'exist');
     }
     if (get_option('wpaa_default_comment_cap') == $userlabel->capability) {
         update_option('wpaa_default_comment_cap', 'exist');
     }
     if (is_multisite()) {
         $current_blog_id = get_current_blog_id();
     }
     // remove all caps from users
     $users = get_users();
     foreach ($users as $user) {
         if (is_multisite()) {
             $user->for_blog($current_blog_id);
         }
         $user->remove_cap($userlabel->capability);
     }
     self::_clear_cache();
 }