Beispiel #1
0
    function pp_only_roles_ui($default)
    {
        $support_pp_only_roles = defined('PPC_VERSION') || version_compare(PP_VERSION, '1.0-beta1.4', '>=');
        ?>

		
		<?php 
        if ($support_pp_only_roles && !in_array($default, array('administrator'))) {
            ?>

		<div style="float:right">
			<?php 
            pp_refresh_options();
            $pp_only = (array) pp_get_option('supplemental_role_defs');
            $checked = in_array($default, $pp_only) ? 'checked="checked"' : '';
            ?>

			<label for="pp_only_role" title="<?php 
            _e('Make role available for supplemental assignment to Permission Groups only', 'capsman');
            ?>
"><input type="checkbox" name="pp_only_role" id="pp_only_role" value="1" <?php 
            echo $checked;
            ?>
> <?php 
            _e('hidden role', 'capsman');
            ?>
 </label>
		</div>
		<?php 
        }
        ?>

	<?php 
        return $support_pp_only_roles;
    }
function _cme_update_pp_usage()
{
    static $updated;
    if (!empty($updated)) {
        return true;
    }
    if (!current_user_can('pp_manage_settings')) {
        return false;
    }
    if (!empty($_REQUEST['update_filtered_types'])) {
        // update Press Permit "Filtered Post Types".  This determines whether type-specific capability definitions are forced
        $options = array('enabled_post_types', 'enabled_taxonomies');
        foreach ($options as $option_basename) {
            if (!isset($_POST["{$option_basename}-options"])) {
                continue;
            }
            $unselected = array();
            $value = array();
            foreach ($_POST["{$option_basename}-options"] as $key) {
                if (empty($_POST["{$option_basename}-{$key}"])) {
                    $unselected[$key] = true;
                } else {
                    $value[$key] = true;
                }
            }
            if ($current = pp_get_option($option_basename)) {
                if ($current = array_diff_key($current, $unselected)) {
                    $value = array_merge($current, $value);
                }
                // retain setting for any types which were previously enabled for filtering but are currently not registered
            }
            $value = stripslashes_deep($value);
            pp_update_option($option_basename, $value);
            $updated = true;
        }
        if (pp_wp_ver('3.5')) {
            pp_update_option('define_create_posts_cap', !empty($_REQUEST['pp_define_create_posts_cap']));
        }
    }
    if (!empty($_REQUEST['SaveRole'])) {
        if (!empty($_REQUEST['role'])) {
            $pp_only = (array) pp_get_option('supplemental_role_defs');
            if (empty($_REQUEST['pp_only_role'])) {
                $pp_only = array_diff($pp_only, array($_REQUEST['role']));
            } else {
                $pp_only[] = $_REQUEST['role'];
            }
            pp_update_option('supplemental_role_defs', array_unique($pp_only));
            _cme_pp_default_pattern_role($_REQUEST['role']);
        }
    }
    if ($updated) {
        pp_refresh_options();
    }
    return $updated;
}
Beispiel #3
0
 function handle_submission($action)
 {
     $args = apply_filters('pp_handle_submission_args', array());
     if (empty($_POST['pp_submission_topic'])) {
         return;
     }
     if ('options' == $_POST['pp_submission_topic']) {
         $method = "{$action}_options";
         if (method_exists($this, $method)) {
             call_user_func(array($this, $method), $args);
         }
         do_action('pp_handle_submission', $action, $args);
         pp_refresh_options();
     }
 }
 function processAdminGeneral($post)
 {
     global $wp_roles;
     // Create a new role.
     if (!empty($post['CreateRole'])) {
         if ($newrole = $this->createRole($post['create-name'])) {
             ak_admin_notify(__('New role created.', $this->cm->ID));
             $this->cm->current = $newrole;
         } else {
             if (empty($post['create-name']) && (!defined('WPLANG') || !WPLANG)) {
                 ak_admin_error('Error: No role name specified.', $this->cm->ID);
             } else {
                 ak_admin_error(__('Error: Failed creating the new role.', $this->cm->ID));
             }
         }
         // Copy current role to a new one.
     } elseif (!empty($post['CopyRole'])) {
         $current = get_role($post['current']);
         if ($newrole = $this->createRole($post['copy-name'], $current->capabilities)) {
             ak_admin_notify(__('New role created.', $this->cm->ID));
             $this->cm->current = $newrole;
         } else {
             if (empty($post['copy-name']) && (!defined('WPLANG') || !WPLANG)) {
                 ak_admin_error('Error: No role name specified.', $this->cm->ID);
             } else {
                 ak_admin_error(__('Error: Failed creating the new role.', $this->cm->ID));
             }
         }
         // Save role changes. Already saved at start with self::saveRoleCapabilities().
     } elseif (!empty($post['SaveRole'])) {
         if (MULTISITE) {
             global $wp_roles;
             if (method_exists($wp_roles, 'reinit')) {
                 $wp_roles->reinit();
             }
         }
         $this->saveRoleCapabilities($post['current'], $post['caps'], $post['level']);
         if (defined('PP_ACTIVE')) {
             // log customized role caps for subsequent restoration
             // for bbPress < 2.2, need to log customization of roles following bbPress activation
             $plugins = function_exists('bbp_get_version') && version_compare(bbp_get_version(), '2.2', '<') ? array('bbpress.php') : array();
             // back compat
             if (!($customized_roles = get_option('pp_customized_roles'))) {
                 $customized_roles = array();
             }
             $customized_roles[$post['role']] = (object) array('caps' => array_map('boolval', $post['caps']), 'plugins' => $plugins);
             update_option('pp_customized_roles', $customized_roles);
             global $wpdb;
             $wpdb->query("UPDATE {$wpdb->options} SET autoload = 'no' WHERE option_name = 'pp_customized_roles'");
         }
         // Create New Capability and adds it to current role.
     } elseif (!empty($post['AddCap'])) {
         if (MULTISITE) {
             global $wp_roles;
             if (method_exists($wp_roles, 'reinit')) {
                 $wp_roles->reinit();
             }
         }
         $role = get_role($post['current']);
         $role->name = $post['current'];
         // bbPress workaround
         if ($newname = $this->createNewName($post['capability-name'])) {
             $role->add_cap($newname['name']);
             $this->cm->message = __('New capability added to role.');
             // for bbPress < 2.2, need to log customization of roles following bbPress activation
             $plugins = function_exists('bbp_get_version') && version_compare(bbp_get_version(), '2.2', '<') ? array('bbpress.php') : array();
             // back compat
             if (!($customized_roles = get_option('pp_customized_roles'))) {
                 $customized_roles = array();
             }
             $customized_roles[$post['role']] = (object) array('caps' => array_merge($role->capabilities, array($newname['name'] => 1)), 'plugins' => $plugins);
             update_option('pp_customized_roles', $customized_roles);
             global $wpdb;
             $wpdb->query("UPDATE {$wpdb->options} SET autoload = 'no' WHERE option_name = 'pp_customized_roles'");
         } else {
             $this->cm->message = __('Incorrect capability name.');
         }
     } elseif (!empty($post['update_filtered_types'])) {
         if (cme_update_pp_usage()) {
             ak_admin_notify(__('Capability settings saved.', $this->cm->ID));
         } else {
             ak_admin_error(__('Error saving capability settings.', $this->cm->ID));
         }
     } else {
         // TODO: Implement exceptions. This must be a fatal error.
         ak_admin_error(__('Bad form received.', $this->cm->ID));
     }
     if (!empty($newrole) && defined('PP_ACTIVE')) {
         if (!empty($post['CreateRole']) && !empty($_REQUEST['new_role_pp_only']) || !empty($post['CopyRole']) && !empty($_REQUEST['copy_role_pp_only'])) {
             $pp_only = (array) pp_get_option('supplemental_role_defs');
             $pp_only[] = $newrole;
             pp_update_option('supplemental_role_defs', $pp_only);
             _cme_pp_default_pattern_role($newrole);
             pp_refresh_options();
         }
     }
 }
Beispiel #5
0
$dir = dirname(__FILE__);
require_once "{$dir}/lib/agapetry_lib.php";
require_once "{$dir}/api_pp.php";
require_once "{$dir}/defaults_pp.php";
require_once "{$dir}/defaults_ppx.php";
require_once "{$dir}/db-config_pp.php";
if (PP_MULTISITE) {
    $func = "require('" . dirname(__FILE__) . "/db-config_pp.php');";
    add_action('switch_blog', create_function('', $func));
}
add_action('set_current_user', '_pp_act_set_current_user', 99);
add_action('init', '_pp_act_on_init', 50);
global $pp_plugin_page, $pp_default_options, $pp_netwide_options, $pp_role_defs;
// ensure plugin_page is available immediately
$pp_plugin_page = is_admin() && isset($_GET['page']) ? pp_sanitize_key($_GET['page']) : '';
pp_refresh_options();
// retrieve stored options
$pp_default_options = pp_default_options();
if (PP_MULTISITE) {
    $pp_netwide_options = apply_filters('pp_netwide_options', array('support_key', 'beta_updates'));
}
pp_register_group_type('pp_group', is_admin() ? array('labels' => (object) array('name' => __('Groups', 'pp'), 'singular_name' => __('Group', 'pp'))) : array());
if (defined('SSEO_VERSION')) {
    require_once dirname(__FILE__) . '/eyes-only-helper_pp.php';
}
if (is_admin()) {
    require_once $dir . '/admin/admin-load_pp.php';
} else {
    add_action('pp_pre_init', '_pp_enable_attachment_metacap_workaround');
}
$pp_role_defs = new PP_Role_Defs();
function _cme_new_blog($new_blog_id)
{
    if ($autocreate_roles = get_site_option('cme_autocreate_roles')) {
        global $wp_roles, $blog_id;
        $restore_blog_id = $blog_id;
        switch_to_blog(1);
        $wp_roles->reinit();
        $main_site_caps = array();
        $role_captions = array();
        $admin_role = $wp_roles->get_role('administrator');
        $main_admin_caps = $admin_role->capabilities;
        if (defined('PP_ACTIVE')) {
            $main_pp_only = (array) pp_get_option('supplemental_role_defs');
        }
        //$pp_only[]= $newrole;
        foreach ($autocreate_roles as $role_name) {
            if ($role = get_role($role_name)) {
                $main_site_caps[$role_name] = $role->capabilities;
                $role_captions[$role_name] = $wp_roles->role_names[$role_name];
            }
        }
        switch_to_blog($new_blog_id);
        $wp_roles->reinit();
        if (defined('PP_ACTIVE')) {
            pp_refresh_options();
            $blog_pp_only = (array) pp_get_option('supplemental_role_defs');
        }
        foreach ($main_site_caps as $role_name => $caps) {
            if ($blog_role = $wp_roles->get_role($role_name)) {
                $stored_role_caps = !empty($blog_role->capabilities) && is_array($blog_role->capabilities) ? array_intersect($blog_role->capabilities, array(true, 1)) : array();
                // Find caps to add and remove
                $add_caps = array_diff_key($caps, $stored_role_caps);
                $del_caps = array_intersect_key(array_diff_key($stored_role_caps, $caps), $main_admin_caps);
                // don't mess with caps that are totally unused on main site
                // Add new capabilities to role
                foreach ($add_caps as $cap => $grant) {
                    $blog_role->add_cap($cap);
                }
                // Remove capabilities from role
                foreach ($del_caps as $cap => $grant) {
                    $blog_role->remove_cap($cap);
                }
            } else {
                $wp_roles->add_role($role_name, $role_captions[$role_name], $caps);
            }
            if (defined('PP_ACTIVE')) {
                if (in_array($role_name, $main_pp_only)) {
                    _cme_pp_default_pattern_role($role_name);
                    $blog_pp_only[] = $role_name;
                } else {
                    array_diff($blog_pp_only, array($role_name));
                }
            }
        }
        if (defined('PP_ACTIVE')) {
            pp_update_option('supplemental_role_defs', $blog_pp_only);
        }
        switch_to_blog($restore_blog_id);
        $wp_roles->reinit();
        if (defined('PP_ACTIVE')) {
            pp_refresh_options();
        }
    }
}