Skip to content
Browse files

Members v.0.2. Beta.

git-svn-id: http://svn.locallylost.com/plugins/members/trunk@744 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information...
1 parent 99c5bc1 commit ed4bd90735db47579c2b6198c504c799ceef3310 greenshady committed
View
242 admin/admin.php
@@ -0,0 +1,242 @@
+<?php
+/**
+ * @todo Fix all messages and make sure they're working correctly.
+ *
+ * @package Members
+ * @subpackage Admin
+ */
+
+/* Set up the administration functionality. */
+add_action( 'admin_menu', 'members_admin_setup' );
+
+/* Add message when no role has the 'create_roles' capability. */
+add_action( 'members_pre_components_form', 'members_message_no_create_roles' );
+add_action( 'members_pre_new_role_form', 'members_message_no_create_roles' );
+
+/* Actions added by the Edit Roles component. */
+add_action( 'members_pre_components_form', 'members_message_no_edit_roles' );
+add_action( 'members_pre_edit_role_form', 'members_message_no_edit_roles' );
+add_action( 'members_pre_edit_roles_form', 'members_message_no_edit_roles' );
+
+/* Add messages to the components form. */
+add_action( 'members_pre_components_form', 'members_message_no_restrict_content' );
+
+/**
+ * Sets up any functionality needed in the admin.
+ *
+ * @since 0.2.0
+ */
+function members_admin_setup() {
+ global $members;
+
+ /* If the role manager feature is active, add its admin pages. */
+ if ( members_get_setting( 'role_manager' ) ) {
+
+ /* Capability to manage roles. Users need to change this on initial setup by giving at least one role the 'edit_roles' capability. */
+ if ( members_check_for_cap( 'edit_roles' ) )
+ $edit_roles_cap = 'edit_roles';
+ else
+ $edit_roles_cap = 'edit_users';
+
+ /* Create the Manage Roles page. */
+ $members->edit_roles_page = add_submenu_page( 'users.php', __( 'Roles', 'members' ), __( 'Roles', 'members' ), $edit_roles_cap, 'roles', 'members_edit_roles_page' );
+
+ /* Create the New Role page. */
+ $members->new_roles_page = add_submenu_page( 'users.php', __( 'Add New Role', 'members' ), __( 'Add New Role', 'members' ), 'create_roles', 'new-role', 'members_new_role_page' );
+ }
+
+ /* Load post meta boxes on the post editing screen. */
+ add_action( 'load-post.php', 'members_admin_load_post_meta_boxes' );
+
+ add_action( 'admin_enqueue_scripts', 'members_admin_enqueue_style' );
+ add_action( 'admin_enqueue_scripts', 'members_admin_enqueue_scripts' );
+}
+
+/**
+ * @since 0.2.0
+ */
+function members_admin_enqueue_style( $hook_suffix ) {
+
+ $pages = array(
+ 'users_page_roles',
+ 'users_page_new-role',
+ 'settings_page_members-settings'
+ );
+
+ if ( in_array( $hook_suffix, $pages ) )
+ wp_enqueue_style( 'members-admin', trailingslashit( MEMBERS_URI ) . 'css/admin.css', false, '20110525', 'screen' );
+}
+
+/**
+ * @since 0.2.0
+ */
+function members_admin_enqueue_scripts( $hook_suffix ) {
+
+ $pages = array(
+ 'users_page_roles',
+ 'users_page_new-role'
+ );
+
+ if ( in_array( $hook_suffix, $pages ) )
+ wp_enqueue_script( 'members-admin', trailingslashit( MEMBERS_URI ) . 'js/admin.js', array( 'jquery' ), '20110525', true );
+}
+
+/**
+ * Loads meta boxes for the post editing screen.
+ *
+ * @since 0.2.0
+ */
+function members_admin_load_post_meta_boxes() {
+
+ /* If the content permissions component is active, load its post meta box. */
+ if ( members_get_setting( 'content_permissions' ) )
+ require_once( MEMBERS_ADMIN . 'meta-box-post-content-permissions.php' );
+}
+
+/**
+ * Loads the role manager main page (Roles).
+ *
+ * @since 0.1.0
+ */
+function members_edit_roles_page() {
+ require_once( MEMBERS_ADMIN . 'roles.php' );
+}
+
+/**
+ * Loads the New Role page.
+ *
+ * @since 0.1.0
+ */
+function members_new_role_page() {
+ require_once( MEMBERS_ADMIN . 'role-new.php' );
+}
+
+/**
+ * Returns an array of capabilities that should be set on the New Role admin screen. By default, the only
+ * capability checked is 'read' because it's fairly common.
+ *
+ * @since 0.1.0
+ * @return $capabilities array Default capabilities for new roles.
+ */
+function members_new_role_default_capabilities() {
+
+ $capabilities = array( 'read' );
+
+ /* Filters should return an array. */
+ return apply_filters( 'members_new_role_default_capabilities', $capabilities );
+}
+
+/**
+ * Message to show when a single role has been deleted.
+ *
+ * @since 0.1.0
+ */
+function members_message_role_deleted() {
+ members_admin_message( '', __( 'Role deleted.', 'members' ) );
+}
+
+/**
+ * Message to show when multiple roles have been deleted (bulk delete).
+ *
+ * @since 0.1.0
+ */
+function members_message_roles_deleted() {
+ members_admin_message( '', __( 'Selected roles deleted.', 'members' ) );
+}
+
+/**
+ * Message to show when no role has the 'edit_roles' capability.
+ *
+ * @since 0.1.0
+ */
+function members_message_no_edit_roles() {
+
+ if ( members_get_setting( 'role_manager' ) && !members_check_for_cap( 'edit_roles' ) )
+ members_admin_message( '', __( 'No role currently has the <code>edit_roles</code> capability. Please add this to each role that should be able to manage/edit roles. If you do not change this, any user that has the <code>edit_users</code> capability will be able to edit roles.', 'members' ) );
+}
+
+/**
+ * Displays a message if the New Roles component is active and no roles have the 'create_roles' capability.
+ *
+ * @since 0.1.0
+ */
+function members_message_no_create_roles() {
+
+ if ( members_get_setting( 'role_manager' ) && !members_check_for_cap( 'create_roles' ) )
+ members_admin_message( '', __( 'To create new roles, you must give the <code>create_roles</code> capability to at least one role.', 'members' ) );
+}
+
+/**
+ * @since 0.1.0
+ */
+function members_message_no_restrict_content() {
+
+ if ( members_get_setting( 'content_permissions' ) && !members_check_for_cap( 'restrict_content' ) )
+ members_admin_message( '', __( 'No role currently has the <code>restrict_content</code> capability. To use the <em>Content Permissions</em> component, at least one role must have this capability.', 'members' ) );
+}
+
+/**
+ * A function for displaying messages in the admin. It will wrap the message in the appropriate <div> with the
+ * custom class entered. The updated class will be added if no $class is given.
+ *
+ * @since 0.1.0
+ * @param $class string Class the <div> should have.
+ * @param $message string The text that should be displayed.
+ */
+function members_admin_message( $class = 'updated', $message = '' ) {
+
+ echo '<div class="' . ( !empty( $class ) ? esc_attr( $class ) : 'updated' ) . '"><p><strong>' . $message . '</strong></p></div>';
+}
+
+/**
+ * Members plugin nonce function. This is to help with securely making sure forms have been processed
+ * from the correct place.
+ *
+ * @since 0.1.0
+ * @param $action string Additional action to add to the nonce.
+ */
+function members_get_nonce( $action = '' ) {
+ if ( $action )
+ return "members-component-action_{$action}";
+ else
+ return "members-plugin";
+}
+
+/**
+ * @since 0.2.0
+ */
+function members_delete_role( $role ) {
+
+ /* Get all users with the role to be deleted. */
+ $wp_user_search = new WP_User_Search( '', '', $role );
+ $change_users = $wp_user_search->get_results();
+
+ /* If there are users with the role we're deleting, loop through them, remove the role, and set the default role. */
+ if ( isset( $change_users ) && is_array( $change_users ) ) {
+ foreach( $change_users as $move_user ) {
+ $new_user = new WP_User( $move_user );
+
+ /* If the user has the role, remove it and set the default. Do we need this check? */
+ if ( $new_user->has_cap( $role ) ) {
+ $new_user->remove_role( $role );
+ $new_user->set_role( $default_role );
+ }
+ }
+ }
+
+ /* Remove the role. */
+ remove_role( $role );
+}
+
+/**
+ * @since 0.2.0
+ */
+function members_get_user_meta_keys() {
+ global $wpdb;
+
+ $keys = $wpdb->get_col( "SELECT meta_key FROM $wpdb->usermeta GROUP BY meta_key ORDER BY meta_key" );
+
+ return $keys;
+}
+
+?>
View
181 admin/meta-box-plugin-settings.php
@@ -0,0 +1,181 @@
+<?php
+/**
+ * Creates and adds the meta boxes to the Members Settings page in the admin.
+ *
+ * @package Members
+ * @subpackage Admin
+ */
+
+/* Add the meta boxes for the settings page on the 'add_meta_boxes' hook. */
+add_action( 'add_meta_boxes', 'members_settings_page_create_meta_boxes' );
+
+/**
+ * Adds the meta boxes to the Members plugin settings page.
+ *
+ * @since 0.2.0
+ */
+function members_settings_page_create_meta_boxes() {
+ global $members;
+
+ /* Add the 'About' meta box. */
+ add_meta_box( 'members-about', __( 'About', 'members' ), 'members_meta_box_display_about', $members->settings_page, 'side', 'default' );
+
+ /* Add the 'Donate' meta box. */
+ add_meta_box( 'members-donate', __( 'Like this plugin?', 'members' ), 'members_meta_box_display_donate', $members->settings_page, 'side', 'high' );
+
+ /* Add the 'Support' meta box. */
+ add_meta_box( 'members-support', __( 'Support', 'members' ), 'members_meta_box_display_support', $members->settings_page, 'side', 'low' );
+
+ /* Add the 'Role Manager' meta box. */
+ add_meta_box( 'members-role-manager', __( 'Role Manager', 'members' ), 'members_meta_box_display_role_manager', $members->settings_page, 'normal', 'high' );
+
+ /* Add the 'Content Permissions' meta box. */
+ add_meta_box( 'members-content-permissions', __( 'Content Permissions', 'members' ), 'members_meta_box_display_content_permissions', $members->settings_page, 'normal', 'high' );
+
+ /* Add the 'Sidebar Widgets' meta box. */
+ add_meta_box( 'members-widgets', __( 'Sidebar Widgets', 'members' ), 'members_meta_box_display_widgets', $members->settings_page, 'normal', 'high' );
+
+ /* Add the 'Private Site' meta box. */
+ add_meta_box( 'members-private-site', __( 'Private Site', 'members' ), 'members_meta_box_display_private_site', $members->settings_page, 'normal', 'high' );
+}
+
+/**
+ * Displays the about plugin meta box.
+ *
+ * @since 0.2.0
+ */
+function members_meta_box_display_about( $object, $box ) {
+
+ $plugin_data = get_plugin_data( MEMBERS_DIR . 'members.php' ); ?>
+
+ <p>
+ <strong><?php _e( 'Version:', 'members' ); ?></strong> <?php echo $plugin_data['Version']; ?>
+ </p>
+ <p>
+ <strong><?php _e( 'Description:', 'members' ); ?></strong>
+ </p>
+ <p>
+ <?php echo $plugin_data['Description']; ?>
+ </p>
+<?php }
+
+/**
+ * Displays the donation meta box.
+ *
+ * @since 0.2.0
+ */
+function members_meta_box_display_donate( $object, $box ) { ?>
+
+ <p><?php _e( "Here's how you can give back:", 'members' ); ?></p>
+
+ <ul>
+ <li><a href="http://wordpress.org/extend/plugins/members" title="<?php _e( 'Members on the WordPress plugin repository', 'members' ); ?>"><?php _e( 'Give the plugin a good rating.', 'members' ); ?></a></li>
+ <li><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=3687060" title="<?php _e( 'Donate via PayPal', 'members' ); ?>"><?php _e( 'Donate a few dollars.', 'members' ); ?></a></li>
+ <li><a href="http://amzn.com/w/31ZQROTXPR9IS" title="<?php _e( "Justin Tadlock's Amazon Wish List", 'members' ); ?>"><?php _e( 'Get me something from my wish list.', 'members' ); ?></a></li>
+ </ul>
+<?php
+}
+
+/**
+ * Displays the support meta box.
+ *
+ * @since 0.2.0
+ */
+function members_meta_box_display_support( $object, $box ) { ?>
+ <p>
+ <?php printf( __( 'Support for this plugin is provided via the support forums at %1$s. If you need any help using it, please ask your support questions there.', 'members' ), '<a href="http://themehybrid.com/support" title="' . __( 'Theme Hybrid Support Forums', 'members' ) . '">' . __( 'Theme Hybrid', 'members' ) . '</a>' ); ?>
+ </p>
+<?php }
+
+/**
+ * Displays the role manager meta box.
+ *
+ * @since 0.2.0
+ */
+function members_meta_box_display_role_manager( $object, $box ) {
+ $options = get_option( 'members_settings' ); ?>
+
+ <p>
+ <?php _e( 'The <em>Role Manager</em> component allows you to manage roles on your site by giving you the ability to create, edit, and delete any role. Note that any changes to roles literally changes data in WordPress. This plugin merely provides an interface for you to make these changes. Your roles and capabilities will not revert back to their previous settings after deactivating or uninstalling this plugin, so use this feature wisely.', 'members' ); ?>
+ </p>
+
+ <p>
+ <input type="checkbox" name="members_settings[role_manager]" id="members_settings-role_manager" value="1" <?php checked( 1, $options['role_manager'] ); ?> />
+ <label for="members_settings-role_manager"><?php _e( 'Enable the role manager.', 'members' ); ?></label>
+ </p>
+
+<?php }
+
+/**
+ * Displays the content permissions meta box.
+ *
+ * @since 0.2.0
+ */
+function members_meta_box_display_content_permissions( $object, $box ) {
+ $options = get_option( 'members_settings' ); ?>
+
+ <p>
+ <?php _e( 'Adds a meta box on the post edit screen that allows you to grant permissions for who can read the content based on the the user\'s capabilities or role. Only roles with the <code>restrict_content</code> capability will be able to use this component.', 'members' ); ?>
+ </p>
+
+ <p>
+ <input type="checkbox" name="members_settings[content_permissions]" id="members_settings-content_permissions" value="1" <?php checked( 1, $options['content_permissions'] ); ?> />
+ <label for="members_settings-content_permissions"><?php _e( 'Enable the content permissions meta box.', 'members' ); ?></label>
+ </p>
+
+ <p>
+ <label for="members_settings-content_permissions_error"><?Php _e( 'Default post error message:', 'members' ); ?></label>
+ <textarea name="members_settings[content_permissions_error]" id="members_settings-content_permissions_error"><?php echo esc_textarea( $options['content_permissions_error'] ); ?></textarea>
+ <label for="members_settings-content_permissions_error"><?php _e( 'You can use <abbr title="Hypertext Markup Language">HTML</abbr> and/or shortcodes to create a custom error message for users that don\'t have permission to view posts.', 'members' ); ?></label>
+ </p>
+
+<?php }
+
+/**
+ * Displays the widgets meta box.
+ *
+ * @since 0.2.0
+ */
+function members_meta_box_display_widgets( $object, $box ) {
+ $options = get_option( 'members_settings' ); ?>
+
+ <p>
+ <input type="checkbox" name="members_settings[login_form_widget]" id="members_settings-login_form_widget" value="1" <?php checked( 1, $options['login_form_widget'] ); ?> />
+ <label for="members_settings-login_form_widget"><?php _e( 'Enable the login form widget.', 'members' ); ?></label>
+ </p>
+
+ <p>
+ <input type="checkbox" name="members_settings[users_widget]" id="members_settings-users_widget" value="1" <?php checked( 1, $options['users_widget'] ); ?> />
+ <label for="members_settings-users_widget"><?php _e( 'Enable the users widget.', 'members' ); ?></label>
+ </p>
+
+<?php }
+
+/**
+ * Displays the private site meta box.
+ *
+ * @since 0.2.0
+ */
+function members_meta_box_display_private_site( $object, $box ) {
+ $options = get_option( 'members_settings' ); ?>
+
+ <p>
+ <input type="checkbox" name="members_settings[private_blog]" id="members_settings-private_blog" value="1" <?php checked( 1, $options['private_blog'] ); ?> />
+ <label for="members_settings-private_blog"><?php _e( 'Redirect all logged-out users to the login page before allowing them to view the site.', 'members' ); ?></label>
+ </p>
+
+ <p>
+ <input type="checkbox" name="members_settings[private_feed]" id="members_settings-private_feed" value="1" <?php checked( 1, $options['private_feed'] ); ?> />
+ <label for="members_settings-private_feed"><?php _e( 'Show error message for feed items.', 'members' ); ?></label>
+ </p>
+
+ <p>
+ <label for="members_settings-private_feed_error"><?php _e( 'Feed error message:', 'members' ); ?></label>
+ <textarea name="members_settings[private_feed_error]" id="members_settings-private_feed_error"><?php echo esc_textarea( $options['private_feed_error'] ); ?></textarea>
+ <br />
+ <label for="members_settings-private_feed_error"><?php _e( 'You can use <abbr title="Hypertext Markup Language">HTML</abbr> and/or shortcodes to create a custom error message to display instead of feed item content.', 'members' ); ?></label>
+ </p>
+
+<?php }
+
+?>
View
155 admin/meta-box-post-content-permissions.php
@@ -0,0 +1,155 @@
+<?php
+/**
+ * @todo Add inline styles the the admin.css stylesheet.
+ *
+ * @package Members
+ * @subpackage Admin
+ */
+
+/* Adds the content permissions meta box to the 'add_meta_boxes' hook. */
+add_action( 'add_meta_boxes', 'members_content_permissions_create_meta_box' );
+
+/* Saves the content permissions metabox data to a custom field. */
+add_action( 'save_post', 'members_content_permissions_save_meta', 10, 2 );
+
+/**
+ * @since 0.1.0
+ */
+function members_content_permissions_create_meta_box() {
+
+ /* Only add the meta box if the current user has the 'restrict_content' capability. */
+ if ( current_user_can( 'restrict_content' ) ) {
+
+ /* Get all available public post types. */
+ $post_types = get_post_types( array( 'public' => true ), 'objects' );
+
+ /* Loop through each post type, adding the meta box for each type's post editor screen. */
+ foreach ( $post_types as $type )
+ add_meta_box( 'content-permissions-meta-box', __( 'Content Permissions', 'members' ), 'members_content_permissions_meta_box', $type->name, 'advanced', 'high' );
+ }
+}
+
+/**
+ * @since 0.1.0
+ */
+function members_content_permissions_meta_box( $object, $box ) {
+ global $wp_roles;
+
+ /* Get the roles saved for the post. */
+ $roles = get_post_meta( $object->ID, '_members_access_role', false );
+
+ /* Convert old post meta to the new system if no roles were found. */
+ if ( empty( $roles ) )
+ $roles = members_convert_old_post_meta( $object->ID );
+ ?>
+
+ <input type="hidden" name="content_permissions_meta_nonce" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
+
+ <div style="overflow: hidden; margin-left: 5px;">
+
+ <p>
+ <?php _e( 'Limit access to this post to only users of the selected roles.', 'members' ); ?>
+ </p>
+
+ <?php
+
+ /* Loop through each of the available roles. */
+ foreach ( $wp_roles->role_names as $role => $name ) {
+ $checked = false;
+
+ /* If the role has been selected, make sure it's checked. */
+ if ( is_array( $roles ) && in_array( $role, $roles ) )
+ $checked = ' checked="checked" '; ?>
+
+ <div style="width: 32%; float: left; margin: 0 0 5px 0;">
+ <label for="members_access_role-<?php echo $role; ?>">
+ <input type="checkbox" name="members_access_role[<?php echo $role; ?>]" id="members_access_role-<?php echo $role; ?>" <?php echo $checked; ?> value="<?php echo $role; ?>" />
+ <?php echo esc_html( $name ); ?>
+ </label>
+ </div>
+ <?php } ?>
+
+ </div>
+
+ <p style="clear: left;">
+ <span class="howto"><?php _e( 'If no roles are selected, everyone can view the content and the post author can view the content regardless of role.', 'members' ); ?></span>
+ </p>
+
+ <p>
+ <label for="members_access_error"><?php _e( 'Custom error messsage:', 'members' ); ?></label>
+ <textarea id="members_access_error" name="members_access_error" cols="60" rows="2" tabindex="30" style="width: 99%;"><?php echo esc_html( get_post_meta( $object->ID, '_members_access_error', true ) ); ?></textarea>
+ <br />
+ <span class="howto"><?php _e( 'Message shown to users that do no have permission to view the post.', 'members' ); ?></span>
+ </p>
+
+<?php
+}
+
+/**
+ * @since 0.1.0
+ */
+function members_content_permissions_save_meta( $post_id, $post ) {
+ global $wp_roles;
+
+ /* Verify the nonce. */
+ if ( !isset( $_POST['content_permissions_meta_nonce'] ) || !wp_verify_nonce( $_POST['content_permissions_meta_nonce'], plugin_basename( __FILE__ ) ) )
+ return false;
+
+ if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
+ if ( defined('DOING_AJAX') && DOING_AJAX ) return;
+ if ( defined('DOING_CRON') && DOING_CRON ) return;
+
+ /* Get the post type object. */
+ $post_type = get_post_type_object( $post->post_type );
+
+ /* Check if the current user has permission to edit the post. */
+ if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
+ return $post_id;
+
+ /* Don't save if the post is only a revision. */
+ if ( 'revision' == $post->post_type )
+ return;
+
+ $meta_values = get_post_meta( $post_id, '_members_access_role', false );
+
+ if ( isset( $_POST['members_access_role'] ) && is_array( $_POST['members_access_role'] ) ) {
+
+ foreach ( $_POST['members_access_role'] as $role ) {
+ if ( !in_array( $role, $meta_values ) )
+ add_post_meta( $post_id, '_members_access_role', $role, false );
+ }
+
+ foreach ( $wp_roles->role_names as $role => $name ) {
+ if ( !in_array( $role, $_POST['members_access_role'] ) && in_array( $role, $meta_values ) )
+ delete_post_meta( $post_id, '_members_access_role', $role );
+ }
+ }
+ elseif ( !empty( $meta_values ) ) {
+ delete_post_meta( $post_id, '_members_access_role' );
+ }
+
+ $meta = array(
+ '_members_access_error' => esc_html( $_POST['members_access_error'] )
+ );
+
+ foreach ( $meta as $meta_key => $new_meta_value ) {
+
+ /* Get the meta value of the custom field key. */
+ $meta_value = get_post_meta( $post_id, $meta_key, true );
+
+ /* If a new meta value was added and there was no previous value, add it. */
+ if ( $new_meta_value && '' == $meta_value )
+ add_post_meta( $post_id, $meta_key, $new_meta_value, true );
+
+ /* If the new meta value does not match the old value, update it. */
+ elseif ( $new_meta_value && $new_meta_value != $meta_value )
+ update_post_meta( $post_id, $meta_key, $new_meta_value );
+
+ /* If there is no new meta value but an old value exists, delete it. */
+ elseif ( '' == $new_meta_value && $meta_value )
+ delete_post_meta( $post_id, $meta_key, $meta_value );
+ }
+
+}
+
+?>
View
145 admin/role-edit.php
@@ -0,0 +1,145 @@
+<?php
+/**
+ * @todo Add inline styles the the admin.css stylesheet.
+ *
+ * @package Members
+ * @subpackage Admin
+ */
+
+/* Get the current role object to edit. */
+$role = get_role( esc_attr( strip_tags( $_GET['role'] ) ) );
+
+/* Get all the capabilities */
+$capabilities = members_get_capabilities();
+
+/* Check if the form has been submitted. */
+if ( isset( $_POST['role-caps'] ) || isset( $_POST['new-cap'] ) ) {
+
+ /* Verify the nonce. */
+ check_admin_referer( members_get_nonce( 'edit-roles' ) );
+
+ /* Set the $role_updated variable to true. */
+ $role_updated = true;
+
+ /* Loop through all available capabilities. */
+ foreach ( $capabilities as $cap ) {
+
+ /* Get the posted capability. */
+ $posted_cap = isset($_POST['role-caps']["{$role->name}-{$cap}"]) ? $_POST['role-caps']["{$role->name}-{$cap}"] : false;
+
+ /* If the role doesn't have the capability and it was selected, add it. */
+ if ( !$role->has_cap( $cap ) && $posted_cap )
+ $role->add_cap( $cap );
+
+ /* If the role has the capability and it wasn't selected, remove it. */
+ elseif ( $role->has_cap( $cap ) && !$posted_cap )
+ $role->remove_cap( $cap );
+
+ } // End loop through existing capabilities
+
+ /* If new caps were added and are in an array, we need to add them. */
+ if ( !empty( $_POST['new-cap'] ) && is_array( $_POST['new-cap'] ) ) {
+
+ /* Loop through each new capability from the edit roles form. */
+ foreach ( $_POST['new-cap'] as $new_cap ) {
+
+ /* Sanitize the new capability to remove any unwanted characters. */
+ $new_cap = strip_tags( $new_cap );
+ $new_cap = str_replace( array( '-', ' ', '&nbsp;' ) , '_', $new_cap );
+ $new_cap = preg_replace('/[^A-Za-z0-9_]/', '', $new_cap );
+ $new_cap = strtolower( $new_cap );
+
+ /* Run one more check to make sure the new capability exists. Add the cap to the role. */
+ if ( $new_cap && !$role->has_cap( $new_cap ) )
+ $role->add_cap( $new_cap );
+
+ } // End loop through new capabilities
+
+ /* If new caps are added, we need to reset the $capabilities array. */
+ $capabilities = members_get_capabilities();
+
+ } // End check for new capabilities
+
+} // End check for form submission ?>
+
+<div class="wrap">
+
+ <?php screen_icon(); ?>
+
+ <h2>
+ <?php _e( 'Edit Role', 'members' ); ?>
+ <?php if ( current_user_can( 'create_roles' ) ) echo '<a href="' . admin_url( 'users.php?page=new-role' ) . '" class="add-new-h2">' . __( 'Add New', 'members' ) . '</a>'; ?>
+ </h2>
+
+ <?php if ( !empty( $role_updated ) ) members_admin_message( '', __( 'Role updated.', 'members' ) ); ?>
+
+ <?php do_action( 'members_pre_edit_role_form' ); //Available pre-form hook for displaying messages. ?>
+
+ <div id="poststuff">
+
+ <form name="form0" method="post" action="<?php echo admin_url( esc_url( "users.php?page=roles&amp;action=edit&amp;role={$role->name}" ) ); ?>">
+
+ <?php wp_nonce_field( members_get_nonce( 'edit-roles' ) ); ?>
+
+ <table class="form-table">
+
+ <tr>
+ <th>
+ <?php _e( 'Role Name', 'members' ); ?>
+ </th>
+ <td>
+ <input type="text" disabled="disabled" readonly="readonly" value="<?php echo esc_attr( $role->name ); ?>" />
+ </td>
+ </tr>
+
+ <tr>
+ <th>
+ <?php _e( 'Capabilities', 'members' ); ?>
+ </th>
+
+ <td>
+ <p>
+ <?php _e( 'Select which capabilities this role should have. Make sure you understand what the capability does before giving it to just any role. This is a powerful feature, but it can cause you some grief if you give regular ol\' Joe more capabilities than yourself.', 'members' ); ?>
+ </p>
+
+ <?php $i = -1; foreach ( $capabilities as $cap ) { ?>
+
+ <div class="members-role-checkbox <?php if ( ++$i % 3 == 0 ) echo 'clear'; ?>">
+ <?php $has_cap = ( $role->has_cap( $cap ) ? true : false ); ?>
+ <input type="checkbox" name="<?php echo esc_attr( "role-caps[{$role->name}-{$cap}]" ); ?>" id="<?php echo esc_attr( "{$role->name}-{$cap}" ); ?>" <?php checked( true, $has_cap ); ?> value="true" />
+ <label for="<?php echo esc_attr( "{$role->name}-{$cap}" ); ?>" class="<?php echo ( $has_cap ? 'has-cap' : 'has-cap-not' ); ?>"><?php echo $cap; ?></label>
+ </div>
+
+ <?php } // Endforeach ?>
+ </td>
+ </tr>
+
+ <tr>
+ <th>
+ <?php _e( 'New Capabilities', 'members' ); ?>
+ </th>
+
+ <td>
+ <p>
+ <?php _e( 'Add custom capabilities to this role. Please only use letters, numbers, and underscores.', 'members' ); ?>
+ </p>
+
+ <p class="new-cap-holder">
+ <input type="text" class="new-cap" name="new-cap[]" value="" size="20" />
+ </p>
+
+ <p class="clear hide-if-no-js">
+ <a id="members-add-new-cap"><?php _e( 'Add New Capability &rarr;', 'members' ); ?></a>
+ </p>
+ </td>
+ </tr>
+
+ </table><!-- .form-table -->
+
+ <?php submit_button( __( 'Update Role', 'members' ) ); ?>
+
+ </form>
+
+ </div><!-- #poststuff -->
+
+</div><!-- .wrap -->
View
110 admin/role-new.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * @todo Add inline styles the the admin.css stylesheet.
+ *
+ * @package Members
+ * @subpackage Admin
+ */
+
+/* Check if the form has been submitted. */
+if ( isset( $_POST['role-id'] ) && isset( $_POST['role-name'] ) ) {
+
+ /* Verify the nonce. */
+ check_admin_referer( members_get_nonce( 'new-role' ) );
+
+ /* Check if any capabilities were selected. */
+ if ( !empty( $_POST['capabilities'] ) && is_array( $_POST['capabilities'] ) )
+ $new_user_caps = array_map( 'esc_attr', $_POST['capabilities'] );
+
+ /* If no capabilities were selected, set the variable to null. */
+ else
+ $new_user_caps = null;
+
+ /* Check if both a role name and role were submitted. */
+ if ( isset($_POST['role-name']) && isset($_POST['role-id']) ) {
+
+ /* Sanitize the new role, removing any unwanted characters. */
+ $new_role = strip_tags( $_POST['role-id'] );
+ $new_role = str_replace( array( '-', ' ', '&nbsp;' ) , '_', $new_role );
+ $new_role = preg_replace('/[^A-Za-z0-9_]/', '', $new_role );
+ $new_role = strtolower( $new_role );
+
+ /* Sanitize the new role name/label. We just want to strip any tags here. */
+ $new_role_name = strip_tags( $_POST['role-name'] ); // Should we use something like the WP user sanitation method?
+
+ /* Add a new role with the data input. */
+ $new_role_added = add_role( $new_role, $new_role_name, $new_user_caps );
+
+ } // End check for role and role name
+
+} // End check for form submit ?>
+
+<div class="wrap">
+
+ <?php screen_icon(); ?>
+
+ <h2><?php _e( 'Add New Role', 'members' ); ?></h2>
+
+ <?php if ( isset($new_role_added) and $new_role_added ) members_admin_message( '', sprintf( __('The %1$s role has been created.', 'members'), $_POST['role-name'] ) ); ?>
+
+ <?php do_action( 'members_pre_new_role_form' ); // Available action hook for displaying messages. ?>
+
+ <div id="poststuff">
+
+ <form name="form0" method="post" action="<?php echo admin_url( "users.php?page=new-role" ); ?>">
+
+ <?php wp_nonce_field( members_get_nonce( 'new-role' ) ); ?>
+
+
+ <table class="form-table">
+
+ <tr>
+ <th>
+ <label for="role-id"><?php _e( 'Role Name', 'members' ); ?></label>
+ </th>
+ <td>
+ <?php _e( "<strong>Required:</strong> Enter the name of your role. This is a unique key that should only contain numbers, letters, and underscores. Please don't add spaces or other odd characters.", 'members' ); ?>
+ <br />
+ <input type="text" id="role-id" name="role-id" value="" size="30" />
+ </td>
+ </tr>
+
+ <tr>
+ <th>
+ <label for="role-name"><?php _e( 'Role Label', 'members' ); ?></label>
+ </th>
+ <td>
+ <?php _e( '<strong>Required:</strong> Enter a label your role. This is the label used for the role in the WordPress admin.', 'members' ); ?>
+ <br />
+ <input type="text" id="role-name" name="role-name" value="" size="30" />
+ </td>
+ </tr>
+
+ <tr>
+ <th>
+ <?php _e( 'Role Capabilities', 'members' ); ?>
+ </th>
+ <td>
+ <p>
+ <?php _e( '<strong>Optional:</strong> Select the capabilities this role should have. These may be updated later.', 'members' ); ?>
+ </p>
+
+ <?php $i = -1; foreach ( members_get_capabilities() as $cap ) : ?>
+
+ <div class="members-role-checkbox <?php if ( ++$i % 3 == 0 ) echo 'clear'; ?>">
+ <input type="checkbox" name="capabilities[<?php echo esc_attr( $cap ); ?>]" id="capabilities-<?php echo esc_attr( $cap ); ?>" <?php checked( true, in_array( $cap, members_new_role_default_capabilities() ) ); ?> value="true" />
+ <label for="capabilities-<?php echo esc_attr( $cap ); ?>" class="<?php echo ( in_array( $cap, members_new_role_default_capabilities() ) ? 'has-cap' : 'has-cap-not' ); ?>"><?php echo $cap; ?></label>
+ </div>
+ <?php endforeach; ?>
+ </td>
+ </tr>
+
+ </table><!-- .form-table -->
+
+ <?php submit_button( __( 'Add Role', 'members' ) ); ?>
+
+ </form>
+
+ </div><!-- #poststuff -->
+
+</div><!-- .poststuff -->
View
205 admin/roles-list-table.php
@@ -0,0 +1,205 @@
+<?php
+/**
+ * @todo Add inline styles the the admin.css stylesheet.
+ *
+ * @package Members
+ * @subpackage Admin
+ */
+
+/* Get the global $wp_roles variable. */
+global $wp_roles;
+
+/* Sort out the roles, active roles, and inactive roles. */
+$all_roles = members_count_roles();
+$active_roles_arr = members_get_active_roles();
+$inactive_roles_arr = members_get_inactive_roles();
+$active_roles = count( $active_roles_arr );
+$inactive_roles = count( $inactive_roles_arr );
+
+if ( !isset( $_GET['role_status'] ) ) {
+ $role_status = 'all';
+ $roles_loop_array = $wp_roles->role_names;
+ $current_page = admin_url( esc_url( "users.php?page=roles" ) );
+} elseif ( 'active' == $_GET['role_status'] ) {
+ $role_status = 'active';
+ $roles_loop_array = $active_roles_arr;
+ $current_page = admin_url( 'users.php?page=roles&role_status=active' );
+} elseif ( 'inactive' == $_GET['role_status'] ) {
+ $role_status = 'inactive';
+ $roles_loop_array = $inactive_roles_arr;
+ $current_page = admin_url( 'users.php?page=roles&role_status=inactive' );
+}
+
+/* Sort the roles array into alphabetical order. */
+ksort( $roles_loop_array ); ?>
+
+<div class="wrap">
+
+ <?php screen_icon(); ?>
+
+ <h2>
+ <?php _e( 'Roles', 'members' ); ?>
+ <?php if ( current_user_can( 'create_roles' ) ) echo '<a href="' . admin_url( 'users.php?page=new-role' ) . '" class="add-new-h2">' . __( 'Add New', 'members' ) . '</a>'; ?>
+ </h2>
+
+ <?php do_action( 'members_pre_edit_roles_form' ); // Available action hook for displaying messages. ?>
+
+ <div id="poststuff">
+
+ <form id="roles" action="<?php echo $current_page; ?>" method="post">
+
+ <?php wp_nonce_field( members_get_nonce( 'edit-roles' ) ); ?>
+
+ <ul class="subsubsub">
+ <li><a <?php if ( 'all' == $role_status ) echo 'class="current"'; ?> href="<?php echo admin_url( esc_url( 'users.php?page=roles' ) ); ?>"><?php _e( 'All', 'members' ); ?> <span class="count">(<span id="all_count"><?php echo $all_roles; ?></span>)</span></a> | </li>
+ <li><a <?php if ( 'active' == $role_status ) echo 'class="current"'; ?> href="<?php echo admin_url( esc_url( 'users.php?page=roles&amp;role_status=active' ) ); ?>"><?php _e( 'Active', 'members' ); ?> <span class="count">(<span id="active_count"><?php echo $active_roles; ?></span>)</span></a> | </li>
+ <li><a <?php if ( 'inactive' == $role_status ) echo 'class="current"'; ?> href="<?php echo admin_url( esc_url( 'users.php?page=roles&amp;role_status=inactive' ) ); ?>"><?php _e( 'Inactive', 'members' ); ?> <span class="count">(<span id="inactive_count"><?php echo $inactive_roles; ?></span>)</span></a></li>
+ </ul><!-- .subsubsub -->
+
+ <div class="tablenav">
+
+ <div class="alignleft actions">
+
+ <select name="action">
+
+ <option value="" selected="selected"><?php _e( 'Bulk Actions', 'members' ); ?></option>
+
+ <?php if ( current_user_can( 'delete_roles' ) ) { ?>
+ <option value="delete"><?php esc_html_e( 'Delete', 'members' ); ?></option>
+ <?php } ?>
+
+ </select>
+
+ <?php submit_button( __( 'Apply', 'members' ), 'button-secondary action', 'doaction', false ); ?>
+
+ </div><!-- .alignleft .actions -->
+
+ <div class='tablenav-pages one-page'>
+ <span class="displaying-num"><?php printf( _n( '%s item', '%s items', count( $roles_loop_array ), 'members' ), count( $roles_loop_array ) ); ?></span>
+ </div>
+
+ <br class="clear" />
+
+ </div><!-- .tablenav -->
+
+ <table class="widefat fixed" cellspacing="0">
+
+ <thead>
+ <tr>
+ <th class='check-column'><input type='checkbox' /></th>
+ <th class='name-column'><?php _e( 'Role Label', 'members' ); ?></th>
+ <th><?php _e( 'Role Name', 'members' ); ?></th>
+ <th><?php _e( 'Users', 'members' ); ?></th>
+ <th><?php _e( 'Capabilities', 'members' ); ?></th>
+ </tr>
+ </thead>
+
+ <tfoot>
+ <tr>
+ <th class='check-column'><input type='checkbox' /></th>
+ <th class='name-column'><?php _e( 'Role Label', 'members' ); ?></th>
+ <th><?php _e( 'Role', 'members' ); ?></th>
+ <th><?php _e( 'Users', 'members' ); ?></th>
+ <th><?php _e( 'Capabilities', 'members' ); ?></th>
+ </tr>
+ </tfoot>
+
+ <tbody id="users" class="list:user user-list plugins">
+
+ <?php foreach ( $roles_loop_array as $role => $name ) { ?>
+
+ <tr valign="top" class="<?php echo ( isset( $active_roles_arr[$role] ) ? 'active' : 'inactive' ); ?>">
+
+ <th class="manage-column column-cb check-column">
+
+ <?php if ( !current_user_can( $role ) && $role !== get_option( 'default_role' ) ) { ?>
+ <input type="checkbox" name="roles[<?php echo esc_attr( $role ); ?>]" id="<?php echo esc_attr( $role ); ?>" value="<?php echo esc_attr( $role ); ?>" />
+ <?php } ?>
+
+ </th><!-- .manage-column .column-cb .check-column -->
+
+ <td class="plugin-title">
+
+ <?php $edit_link = admin_url( wp_nonce_url( "users.php?page=roles&amp;action=edit&amp;role={$role}", members_get_nonce( 'edit-roles' ) ) ); ?>
+
+ <a href="<?php echo esc_url( $edit_link ); ?>" title="<?php printf( esc_attr__( 'Edit the %s role', 'members' ), $name ); ?>"><strong><?php echo $name; ?></strong></a>
+
+ <div class="row-actions">
+
+ <a href="<?php echo esc_url( $edit_link ); ?>" title="<?php printf( esc_attr__( 'Edit the %s role', 'members' ), $name ); ?>"><?php _e( 'Edit', 'members' ); ?></a>
+
+ <?php if ( current_user_can( 'delete_roles' ) && $role !== get_option( 'default_role' ) && !current_user_can( $role ) ) { ?>
+ | <a href="<?php echo admin_url( wp_nonce_url( "users.php?page=roles&amp;action=delete&amp;role={$role}", members_get_nonce( 'edit-roles' ) ) ); ?>" title="<?php printf( esc_attr__( 'Delete the %s role', 'members' ), $name ); ?>"><?php _e( 'Delete', 'members' ); ?></a>
+ <?php } ?>
+
+ <?php if ( current_user_can( 'manage_options' ) && $role == get_option( 'default_role' ) ) { ?>
+ | <a href="<?php echo admin_url( ( 'options-general.php' ) ); ?>" title="<?php _e( 'Change default role', 'members' ); ?>"><?php _e( 'Default Role', 'members' ); ?></a>
+ <?php } ?>
+
+ <?php if ( current_user_can( 'list_users' ) ) { ?>
+ | <a href="<?php echo admin_url( esc_url( "users.php?role={$role}" ) ); ?>" title="<?php printf( esc_attr__( 'View all users with the %s role', 'members' ), $name ); ?>"><?php _e( 'View Users', 'members' ); ?></a>
+ <?php } ?>
+
+ </div><!-- .row-actions -->
+
+ </td><!-- .plugin-title -->
+
+ <td class="desc">
+ <p><?php echo $role; ?></p>
+ </td><!-- .desc -->
+
+ <td class="desc">
+ <p>
+ <?php if ( current_user_can( 'list_users' ) ) { ?>
+ <a href="<?php echo admin_url( esc_url( "users.php?role={$role}" ) ); ?>" title="<?php printf( __( 'View all users with the %s role', 'members' ), $name ); ?>"><?php printf( _n( '%s User', '%s Users', members_get_role_user_count( $role ), 'members' ), members_get_role_user_count( $role ) ); ?></a>
+ <?php } else { ?>
+ <?php printf( _n( '%s User', '%s Users', members_get_role_user_count( $role ), 'members' ), members_get_role_user_count( $role ) ); ?>
+ <?php } ?>
+ </p>
+ </td><!-- .desc -->
+
+ <td class="desc">
+ <p>
+ <?php
+ $role_object = get_role( $role );
+ $cap_count = count( $role_object->capabilities );
+ printf( _n( '%s Capability', '%s Capabilities', $cap_count, 'members' ), $cap_count );
+ ?>
+ </p>
+ </td><!-- .desc -->
+
+ </tr><!-- .active .inactive -->
+
+ <?php } // End foreach ?>
+
+ </tbody><!-- #users .list:user .user-list .plugins -->
+
+ </table><!-- .widefat .fixed -->
+
+ <div class="tablenav">
+
+ <div class="alignleft actions">
+
+ <select name="action2">
+
+ <option value="" selected="selected"><?php _e( 'Bulk Actions', 'members' ); ?></option>
+
+ <?php if ( current_user_can( 'delete_roles' ) ) { ?>
+ <option value="delete"><?php _e( 'Delete', 'members' ); ?></option>
+ <?php } ?>
+
+ </select>
+
+ <?php submit_button( __( 'Apply', 'members' ), 'button-secondary action', 'doaction2', false ); ?>
+
+ </div><!-- .alignleft .actions -->
+
+ <br class="clear" />
+
+ </div><!-- .tablenav -->
+
+ </form><!-- #roles -->
+
+ </div><!-- #poststuff -->
+
+</div><!-- .wrap -->
View
116 admin/roles.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * @package Members
+ * @subpackage Admin
+ */
+
+/* Get the current action performed by the user. */
+$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : false;
+
+/* If a role has been updated, set the action to 'role-updated'. */
+if ( isset($_POST['edit-role-saved']) and $_POST['edit-role-saved'] == 'Y' )
+ $action = 'role-updated';
+
+/* If the bulk delete (first submit) has been selected. */
+elseif ( 'delete' == $action && ( isset( $_POST['doaction'] ) && __('Apply', 'members') == $_POST['doaction']) )
+ $action = 'bulk-delete';
+
+/* If the bulk delete (second submit) has been selected. */
+elseif ( 'delete' == $action && ( isset($_POST['doaction2']) && __('Apply', 'members') == $_POST['doaction2']) )
+ $action = 'bulk-delete';
+
+/* Choose which actions to perform and pages to load according to the $action variable. */
+switch( $action ) {
+
+ /* If the bulk delete was selected. */
+ case 'bulk-delete' :
+
+ /* Get the default role (we don't want to delete this). */
+ $default_role = get_option( 'default_role' );
+
+ /* Get all roles checked for deletion. */
+ $delete_roles = $_POST['roles'];
+
+ /* If no roles were selected, break. Just load up the edit roles page. */
+ if ( !is_array( $delete_roles ) ) {
+ require_once( MEMBERS_ADMIN . 'roles-list-table.php' );
+ break;
+ }
+
+ /* If roles were selected, let's delete some roles. */
+ else {
+
+ /* Verify the nonce. */
+ check_admin_referer( members_get_nonce( 'edit-roles' ) );
+
+ /* Send through roles deleted message. */
+ add_action( 'members_pre_edit_roles_form', 'members_message_roles_deleted' );
+
+ /* Loop through each of the selected roles. */
+ foreach ( $delete_roles as $role ) {
+
+ /* Delete the role and move its users to the default role. */
+ members_delete_role( esc_attr( strip_tags( $role ) ) );
+ }
+
+ /* Load the edit roles page. */
+ require_once( MEMBERS_ADMIN . 'roles-list-table.php' );
+ break;
+ }
+ break;
+
+ /* If a single role has been chosen to be deleted. */
+ case 'delete' :
+
+ /* Verify the referer. */
+ check_admin_referer( members_get_nonce( 'edit-roles' ) );
+
+ /* Send role deleted message. */
+ add_action( 'members_pre_edit_roles_form', 'members_message_role_deleted' );
+
+ /* Get the default role. */
+ $default_role = get_option( 'default_role' );
+
+ /* Get the role we want to delete. */
+ $role = esc_attr( strip_tags( $_GET['role'] ) );
+
+ /* Delete the role and move its users to the default role. */
+ members_delete_role( $role );
+
+ /* Load the edit roles page. */
+ require_once( MEMBERS_ADMIN . 'roles-list-table.php' );
+ break;
+
+ /* If a role has been updated. Is this needed still? */
+ case 'role-updated' :
+
+ /* Set some default variables. */
+ $role = $_GET['role'];
+
+ /* Load the edit role form. */
+ require_once( MEMBERS_ADMIN . 'role-edit.php' );
+ break;
+
+ /* If a role has been selected to be edited. */
+ case 'edit' :
+
+ /* Verify the referer. */
+ check_admin_referer( members_get_nonce( 'edit-roles' ) );
+
+ /* Set some default variables. */
+ $role = $_GET['role'];
+
+ /* Load the edit role form. */
+ require_once( MEMBERS_ADMIN . 'role-edit.php' );
+
+ break;
+
+ /* The default page is the edit roles page. */
+ default :
+
+ /* Load the edit roles page.*/
+ require_once( MEMBERS_ADMIN . 'roles-list-table.php' );
+ break;
+}
+
+?>
View
191 admin/settings.php
@@ -0,0 +1,191 @@
+<?php
+/**
+ * Long description.
+ *
+ * @package Members
+ */
+
+/* Set up the administration functionality. */
+add_action( 'admin_menu', 'members_settings_page_setup' );
+
+/**
+ * @since 0.2.0
+ */
+function members_settings_page_setup() {
+ global $members;
+
+ /* If no settings are available, add the default settings to the database. */
+ if ( false === get_option( 'members_settings' ) )
+ add_option( 'members_settings', members_get_default_settings(), '', 'yes' );
+
+ /* Register the plugin settings. */
+ add_action( 'admin_init', 'members_register_settings' );
+
+ /* Add Members settings page. */
+ $members->settings_page = add_submenu_page( 'options-general.php', __( 'Members Settings', 'members' ), __( 'Members Settings', 'members' ), apply_filters( 'members_settings_capability', 'manage_options' ), 'members-settings', 'members_settings_page' );
+
+ /* Add media for the settings page. */
+ add_action( 'admin_enqueue_scripts', 'members_admin_enqueue_style' );
+ add_action( "load-{$members->settings_page}", 'members_settings_page_media' );
+ add_action( "admin_head-{$members->settings_page}", 'members_settings_page_scripts' );
+
+ /* Load the meta boxes. */
+ add_action( "load-{$members->settings_page}", 'members_settings_page_load_meta_boxes' );
+
+ /* Create a hook for adding meta boxes. */
+ add_action( "load-{$members->settings_page}", 'members_settings_page_add_meta_boxes' );
+}
+
+/**
+ * @since 0.2.0
+ */
+function members_register_settings() {
+ register_setting( 'members_settings', 'members_settings', 'members_validate_settings' );
+}
+
+/**
+ * Returns an array of the default plugin settings. These are only used on initial setup.
+ *
+ * @since 0.2.0
+ */
+function members_get_default_settings() {
+
+ /* Set up the default plugin settings. */
+ $settings = array(
+ 'role_manager' => 1,
+ 'content_permissions' => 1,
+ 'private_blog' => 0,
+ 'private_feed' => 0,
+ 'login_form_widget' => 0,
+ 'users_widget' => 0,
+ 'content_permissions_error' => '<p class="restricted">' . __( 'Sorry, but you do not have permission to view this content.', 'members' ) . '</p>',
+ 'private_feed_error' => '<p class="restricted">' . __( 'You must be logged into the site to view this content.', 'members' ) . '</p>'
+ );
+
+ /* Return the default settings. */
+ return $settings;
+}
+
+/**
+ * Executes the 'add_meta_boxes' action hook because WordPress doesn't fire this on custom admin pages.
+ *
+ * @since 0.2.0
+ */
+function members_settings_page_add_meta_boxes() {
+ global $members;
+ $plugin_data = get_plugin_data( MEMBERS_DIR . 'members.php' );
+ do_action( 'add_meta_boxes', $members->settings_page, $plugin_data );
+}
+
+/**
+ * Loads the plugin settings page meta boxes.
+ *
+ * @since 0.2.0
+ */
+function members_settings_page_load_meta_boxes() {
+ require_once( MEMBERS_ADMIN . 'meta-box-plugin-settings.php' );
+}
+
+/**
+ * Function for validating the settings input from the plugin settings page.
+ *
+ * @since 0.2.0
+ */
+function members_validate_settings( $input ) {
+
+ /* Check if the role manager is active. */
+ $settings['role_manager'] = ( isset( $input['role_manager'] ) ? 1 : 0 );
+
+ /* Check if the content permissions feature is active. */
+ $settings['content_permissions'] = ( isset( $input['content_permissions'] ) ? 1 : 0 );
+
+ /* Set the content permissions error text and kill evil scripts. */
+ if ( current_user_can( 'unfiltered_html' ) && isset( $input['content_permissions_error'] ) )
+ $settings['content_permissions_error'] = stripslashes( wp_filter_post_kses( addslashes( $input['content_permissions_error'] ) ) );
+ elseif ( isset( $input['content_permissions_error'] ) )
+ $settings['content_permissions_error'] = $input['content_permissions_error'];
+
+ /* Check if the login form and users widgets are active. */
+ $settings['login_form_widget'] = ( isset( $input['login_form_widget'] ) ? 1 : 0 );
+ $settings['users_widget'] = ( isset( $input['users_widget'] ) ? 1 : 0 );
+
+ /* Check if the private blog and private feed features are active. */
+ $settings['private_blog'] = ( isset( $input['private_blog'] ) ? 1 : 0 );
+ $settings['private_feed'] = ( isset( $input['private_feed'] ) ? 1 : 0 );
+
+ /* Set the private feed error text and kill evil scripts. */
+ if ( current_user_can( 'unfiltered_html' ) && isset( $input['private_feed_error'] ) )
+ $settings['private_feed_error'] = stripslashes( wp_filter_post_kses( addslashes( $input['private_feed_error'] ) ) );
+ elseif ( isset( $input['private_feed_error'] ) )
+ $settings['private_feed_error'] = $input['private_feed_error'];
+
+ /* Return the validated/sanitized settings. */
+ return $settings;
+}
+
+/**
+ * Displays the HTML and meta boxes for the plugin settings page.
+ *
+ * @since 0.2.0
+ */
+function members_settings_page() {
+ global $members; ?>
+
+ <div class="wrap">
+
+ <?php screen_icon(); ?>
+
+ <h2><?php _e( 'Members Plugin Settings', 'members' ); ?></h2>
+
+ <div id="poststuff">
+
+ <form method="post" action="options.php">
+
+ <?php settings_fields( 'members_settings' ); ?>
+ <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
+ <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
+
+ <div class="metabox-holder">
+ <div class="post-box-container column-1 normal"><?php do_meta_boxes( $members->settings_page, 'normal', null ); ?></div>
+ <div class="post-box-container column-2 side"><?php do_meta_boxes( $members->settings_page, 'side', null ); ?></div>
+ </div>
+
+ <?php submit_button( esc_attr__( 'Update Settings', 'members' ) ); ?>
+
+ </form>
+
+ </div><!-- #poststuff -->
+
+ </div><!-- .wrap --><?php
+}
+
+/**
+ * Loads needed JavaScript files for handling the meta boxes on the settings page.
+ *
+ * @since 0.2.0
+ */
+function members_settings_page_media() {
+ wp_enqueue_script( 'common' );
+ wp_enqueue_script( 'wp-lists' );
+ wp_enqueue_script( 'postbox' );
+}
+
+/**
+ * Loads JavaScript for handling the open/closed state of each meta box.
+ *
+ * @since 0.2.0
+ * @global $members The path of the settings page.
+ */
+function members_settings_page_scripts() {
+ global $members; ?>
+ <script type="text/javascript">
+ //<![CDATA[
+ jQuery(document).ready( function($) {
+ $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
+ postboxes.add_postbox_toggles( '<?php echo $members->settings_page; ?>' );
+ });
+ //]]>
+ </script>
+<?php }
+
+?>
View
250 components.php
@@ -1,250 +0,0 @@
-<?php
-/**
- * Members Components API. This file contains everything you need to build custom components.
- * Rather than limiting the plugin to self-contained settings, the Components API was created so
- * that it could be extended by other plugins and themes. Registering a component is as simple as
- * using the registration function and creating a custom callback function for the component.
- *
- * To register a component, use the register_component() function. When registering a custom
- * component, your registration function should be hooked to 'members_register_components'.
- *
- * @package Members
- * @subpackage Components
- */
-
-/* Register the default components shippedd with the plugin. */
-add_action( 'after_setup_theme', 'members_create_default_components', 0 );
-
-/* Load the callback functions for each of the registered components. Components should be registered on 'init' with a priority less than '10'. */
-add_action( 'after_setup_theme', 'members_load_components', 5 );
-
-/**
- * Registers the initial components packaged with the plugin.
- * @uses register_members_component() Registers a component.
- *
- * @since 0.1
- */
-function members_create_default_components() {
- register_members_component( array( 'name' => 'role_manager', 'label' => __( 'Role Manager', 'members' ), 'callback' => 'members_component_role_manager', 'requires' => false, 'description' => __('The <em>Role Manager</em> component allows you to manage roles on your site by giving you the ability to create, edit, and delete any role.', 'members' ) ) );
- //register_members_component( array( 'name' => 'edit_roles', 'label' => __('Edit Roles', 'members'), 'callback' => 'members_component_edit_roles', 'requires' => false, 'description' => __('The <em>Edit Roles</em> component allows you to manage all roles on your site. You can change which capabilities individual roles have. Once you\'ve selected this component, you should immediately give at least one role the <code>edit_roles</code> capability. This makes sure only the roles you select can edit roles.', 'members') ) );
- //register_members_component( array( 'name' => 'new_roles', 'label' => __('New Roles', 'members'), 'callback' => 'members_component_new_roles', 'requires' => false, 'description' => __('The <em>New Roles</em> component allows you to create new roles on your site. To use this component, you must have the <code>create_roles</code> capability. This makes sure only the roles you select can create new roles.', 'members') ) );
- register_members_component( array( 'name' => 'content_permissions', 'label' => __('Content Permissions', 'members'), 'callback' => 'members_component_content_permissions', 'requires' => false, 'description' => __('Adds an additional meta box for the post/page editor that allows you to grant permissions for who can read the content based on the the user\'s capabilities or role. Only roles with the <code>restrict_content</code> capability will be able to use this component.', 'members') ) );
- register_members_component( array( 'name' => 'shortcodes', 'label' => __('Shortcodes', 'members'), 'callback' => 'members_component_shortcodes', 'requires' => false, 'description' => __('Provides a set of shortcodes that may be used to restrict or provide access to certain areas of your site from within the post editor (or other areas where shortcodes are allowed).', 'members') ) );
- register_members_component( array( 'name' => 'template_tags', 'label' => __('Template Tags', 'members'), 'callback' => 'members_component_template_tags', 'requires' => false, 'description' => __('Provides additional template tags for use within your WordPress theme for restricting or providing access to certain content.', 'members') ) );
- register_members_component( array( 'hook' => 'widgets_init', 'name' => 'widgets', 'label' => __('Widgets', 'members'), 'callback' => 'members_component_widgets', 'requires' => false, 'description' => __('Creates additional widgets for use in any widget area on your site. The current widgets are Login Form and Users.', 'members') ) );
- register_members_component( array( 'name' => 'private_blog', 'label' => __('Private Blog', 'members'), 'callback' => 'members_component_private_blog', 'requires' => false, 'description' => __('Forces all users to log into the site before viewing it. It will always redirect users to the login page. Note that this component does not block public access to your feeds.', 'members') ) );
- //register_members_component( array( 'name' => 'stats', 'label' => __( 'Statistics', 'members' ), 'callback' => 'members_component_stats', 'requires' => false, 'description' => __( 'Adds statistics for user signups based on role.', 'members' ) ) );
- //register_members_component( array( 'name' => 'user_fields', 'label' => __('User Fields', 'members'), 'callback' => 'members_component_user_fields', 'requires' => false, 'description' => __('Provides an interface for building additional user profile fields. Users will then be able provide this additional information when editing their profile', 'members') ) );
-
- do_action( 'members_register_components' ); // Available hook to register components.
-}
-
-/**
- * Function for registering an additional component for the plugin, which the user
- * may choose to use. Note that you should add in all the arguments to properly register
- * your component. The exception is $requires.
- *
- * Your callback function should make use of the is_active_members_component() function
- * as soon as it fires. This allows you to check if the user has activated the component before
- * loading all of your code. Please use this system as it keeps the plugin as light as possible.
- *
- * @since 0.1
- * @global $members object The global members object.
- *
- * @param $args array Arguments for registering a custom component.
- * @param $args[$name] string Name of the component (only letters, numbers, and spaces).
- * @param $args[$label] string Display name of the component.
- * @param $args[$description] string Description of the component.
- * @param $args[$callback] string Function that will be called when the components system is loaded.
- * @param $args[$requires] array|bool Names of other components that are required to run this component.
- */
-function register_members_component( $args = array() ) {
- global $members;
-
- $name = $args['name'];
-
- $members->registered_components[$name] = (object) $args;
-}
-
-/**
- * Loops through the registered components and load the necessary callback function.
- * If a $component->hook is added and a $component->callback function, the plugin
- * will add the function to the action hook automatically. Else if the $component->callback
- * function exists but not $component->hook, the function will simply be called.
- *
- * @since 0.2
- * @global $members object The global members object.
- */
-function members_load_components() {
- global $members;
-
- /* Check if there are any registered components. If not, return false. */
- if ( !is_array( $members->registered_components ) )
- return false;
-
- /* Loop through each of the registered components and execute the desired action. */
- foreach ( $members->registered_components as $component ) {
-
- /* If a callback function has been input, continue the process. */
- if ( $component->callback && function_exists( $component->callback ) ) {
-
- /* If a hook has been input, add the component callback function to the action hook. */
- if ( isset($component->hook) )
- add_action( $component->hook, $component->callback );
-
- /* Call the function directly if there is no hook. */
- else
- call_user_func( $component->callback, $component );
- }
- }
-}
-
-/**
- * Function for getting a specific component object from the list of registered
- * plugin components.
- *
- * @since 0.1
- * @global $members object The global members object.
- * @param $component string Required. The name of the component.
- * @return $members->registered_components[$component] object
- */
-function get_members_component( $component ) {
- global $members;
- return $members->registered_components[$component_name];
-}
-
-/**
- * Checks if a component has been activated by the user. If it has, return true. If not,
- * return false.
- *
- * @since 0.1
- * @global $members object The global members object.
- * @param $component string Name of the component to check for.
- * @return true|false bool
- */
-function is_active_members_component( $component = '' ) {
- global $members;
-
- return (bool) isset( $members->active_components[$component] );
-}
-
-/* Default Components */
-
-/**
- * Mange roles component. This allows you to create, edit, and delete roles
- * and each role's capabilities.
- *
- * @since 0.2
- */
-function members_component_role_manager() {
- if ( is_admin() && is_active_members_component( 'role_manager' ) )
- require_once( MEMBERS_COMPONENTS . '/role-manager/default.php' );
-}
-
-/**
- * Manage roles component. This allows you to manage each role's set
- * of capabilities.
- *
- * @since 0.1
- * @deprecated 0.2
- */
-function members_component_edit_roles() {
- if ( is_admin() && is_active_members_component( 'edit_roles' ) )
- require_once( MEMBERS_COMPONENTS . '/edit-roles/default.php' );
-}
-
-/**
- * New roles component. This allows you to create new roles.
- *
- * @since 0.1
- * @deprecated 0.2
- */
-function members_component_new_roles() {
- if ( is_admin() && is_active_members_component( 'new_roles' ) )
- require_once( MEMBERS_COMPONENTS . '/new-roles/default.php' );
-}
-
-/**
- * Loads the content permissions component.
- *
- * @since 0.1
- */
-function members_component_content_permissions() {
- if ( is_active_members_component( 'content_permissions' ) ) {
- require_once( MEMBERS_COMPONENTS . '/content-permissions/content-permissions.php' );
- require_once( MEMBERS_COMPONENTS . '/content-permissions/meta-box.php' );
- }
-}
-
-/**
- * Loads the shortcodes component.
- *
- * @since 0.1
- */
-function members_component_shortcodes() {
- if ( !is_admin() && is_active_members_component( 'shortcodes' ) )
- require_once( MEMBERS_COMPONENTS . '/shortcodes/shortcodes.php' );
-}
-
-/**
- * Loads the template tags component.
- *
- * @since 0.1
- */
-function members_component_template_tags() {
- if ( is_active_members_component( 'template_tags' ) )
- require_once( MEMBERS_COMPONENTS . '/template-tags/template-tags.php' );
-}
-
-/**
- * Loads the widgets component.
- *
- * @since 0.1
- */
-function members_component_widgets() {
- if ( is_active_members_component( 'widgets' ) ) {
-
- /* Load each of the widget files. */
- require_once( MEMBERS_COMPONENTS . '/widgets/login.php' );
- require_once( MEMBERS_COMPONENTS . '/widgets/users.php' );
-
- /* Register each widget. */
- register_widget( 'Members_Widget_Login' );
- register_widget( 'Members_Widget_Users' );
- }
-}
-
-/**
- * Loads the private blog component.
- *
- * @since 0.1
- */
-function members_component_private_blog() {
- if ( is_active_members_component( 'private_blog' ) )
- require_once( MEMBERS_COMPONENTS . '/private-blog/default.php' );
-}
-
-/**
- * Loads the stats component.
- *
- * @since 0.2
- */
-function members_component_stats() {
- if ( is_admin() && is_active_members_component( 'stats' ) )
- require_once( MEMBERS_COMPONENTS . '/statistics/default.php' );
-}
-
-/**
- * Loads the user fields component.
- *
- * @internal Do not use this function. The component isn't ready.
- * @todo Pretty much everything.
- *
- * @since 0.1
- */
-function members_component_user_fields() {
- if ( is_admin() && is_active_members_component( 'user_fields' ) )
- require_once( MEMBERS_COMPONENTS . '/user-fields/default.php' );
-}
-
-?>
View
86 css/admin.css
@@ -0,0 +1,86 @@
+/**
+ * CSS for the plugin settings page.
+ */
+.settings_page_members-settings .form-table th {
+ width: 20%;
+ font-weight: bold;
+ }
+.settings_page_members-settings .metabox-holder .column-1 {
+ float: left;
+ width: 66%;
+ }
+.settings_page_members-settings .metabox-holder .column-2 {
+ float: right;
+ width: 32%;
+ }
+.settings_page_members-settings .hook-editor {
+ overflow: hidden;
+ }
+.settings_page_members-settings p.submit {
+ clear: both;
+ }
+.settings_page_members-settings textarea {
+ width: 99.5%;
+ }
+.settings_page_members-settings .postbox .inside p,
+.settings_page_members-settings .postbox .inside label,
+.settings_page_members-settings .postbox .inside li,
+.settings_page_members-settings .postbox .inside a,
+.settings_page_members-settings .postbox .inside label {
+ font-size: 11px;
+ line-height: 175%;
+ }
+.settings_page_members-settings .postbox form {
+ line-height: 150%;
+ }
+.settings_page_members-settings div.inside ul {
+ margin-left: 20px;
+ }
+.settings_page_members-settings div.inside ul li {
+ list-style: square;
+ line-height:16px;
+ }
+.settings_page_members-settings div.inside .alignleft {
+ width: 45%;
+ float: left;
+ }
+.settings_page_members-settings div.inside .alignright {
+ width: 45%;
+ float: right;
+ text-align: right;
+ }
+
+
+.users_page_roles .members-role-checkbox,
+.users_page_new-role .members-role-checkbox {
+ overflow: hidden;
+ margin: 0 0 5px 0;
+ float: left;
+ width: 32.67%;
+ }
+.users_page_roles .clear,
+.users_page_new-role .clear {
+ clear: both;
+ }
+.users_page_roles .members-role-checkbox .has-cap,
+.users_page_new-role .members-role-checkbox .has-cap {
+ font-weight: bold;
+ }
+.users_page_roles a#members-add-new-cap {
+ cursor: pointer;
+ }
+.users_page_roles input.new-cap {
+ float: left;
+ width: 20%;
+ margin: 0 5% 10px 0;
+ }
+
+.users_page_roles .hide-if-no-js {
+ display: none;
+ }
+
+
+
+
+
+
View
0 readme.css → docs/readme.css
File renamed without changes.
View
0 readme.html → docs/readme.html
File renamed without changes.
View
73 functions.php
@@ -1,73 +0,0 @@
-<?php
-/**
- * Functions that may be used across a variety of components, so they should always
- * be loaded for use on the front end of the site.
- *
- * @todo Decide whether Template Tags is a useful enough component to stand alone.
- * The Widgets and Shortcodes components both require the use of these functions here,
- * which should be template tags.
- *
- * @package Members
- */
-
-/**
- * Displays the login form.
- *
- * @since 0.1.0
- * @deprecated 0.2.0 Use wp_login_form() instead.
- */
-function members_login_form() {
- wp_login_form( array( 'echo' => true ) );
-}
-
-/**
- * Creates the login form.
- *
- * @since 0.1.0
- * @deprecated 0.2.0 Use wp_login_form() instead.
- */
-function members_get_login_form( $args = array() ) {
- wp_login_form( array( echo => 'false' ) );
-}
-
-/**
- * Function for listing users like the WordPress function currently uses for authors.
- *
- * Eventually, I hope to remove this function in favor of wp_list_users():
- * @link http://core.trac.wordpress.org/ticket/15145
- *
- * @since 0.1
- * @uses get_users()
- */
-function members_list_users( $args = array() ) {
-
- $output = '';
- $users = get_users( $args );
-
- if ( !empty( $users ) ) {
-
- $output .= '<ul class="xoxo members-list-users">';
-
- foreach ( $users as $user ) {
-
- $url = get_author_posts_url( $author->ID, $author->user_nicename );
-
- $class = "user-{$user->ID}";
- if ( is_author( $user->ID ) )
- $class .= ' current-user';
-
- $output .= "<li class='{$class}'><a href='{$url}' title='" . esc_attr( $user->display_name ) . "'>{$user->display_name}</a></li>\n";
- }
-
- $output .= '</ul>';
- }
-
- $output = apply_filters( 'members_list_users', $output );
-
- if ( empty( $args['echo'] ) )
- return $output;
-
- echo $output;
-}
-
-?>
View
491 functions-admin.php → includes/capabilities.php
@@ -1,267 +1,226 @@
-<?php
-/**
- * Functions that may be used across a variety of components, so they should always
- * be loaded for use in the admin. Many of the functions here deal with setting up, getting,
- * and checking for capabilities. Since the management of capabilities is at the heart of this
- * entire plugin, these are probably the plugin functions you'll use most when developing
- * a custom component for the plugin.
- *
- * @package Members
- */
-
-/* Disables the old levels from being seen. If you need them, use remove_filter() to add display back. */
-add_filter( 'members_get_capabilities', 'members_remove_old_levels' );
-
-/**
- * The function that makes this plugin what it is. It returns all of our capabilities
- * in a nicely-formatted, alphabetized array with no duplicate capabilities. It pulls
- * from three different functions to make sure we get all of the capabilities that
- * we need for use in the plugin components.
- *
- * @since 0.1
- * @uses members_get_default_capabilities() Gets an array of WP's default capabilities.
- * @uses members_get_role_capabilities() Gets an array of all the capabilities currently mapped to a role.
- * @uses members_get_additional_capabilities() Gets an array of capabilities added by the plugin.
- * @return $capabilities array An array containing all of the capabilities.
- */
-function members_get_capabilities() {
-
- /* Capabilities array. */
- $capabilities = array();
-
- /* Grab the default capabilities (these are set by the plugin so the user doesn't lose them). */
- $default_caps = members_get_default_capabilities();
-
- /* Get the user capabilities that are already set. */
- $role_caps = members_get_role_capabilities();
-
- /* Gets capabilities added by the plugin. */
- $plugin_caps = members_get_additional_capabilities();
-
- /* Merge all the capability arrays (current role caps, plugin caps, and default WP caps) together. */
- $capabilities = array_merge( $default_caps, $role_caps, $plugin_caps );
-
- /* Apply filters to the array of capabilities. Devs should respect the available capabilities and return an array. */
- $capabilities = apply_filters( 'members_get_capabilities', $capabilities );
-
- /* Sort the capabilities by name so they're easier to read when shown on the screen. */
- sort( $capabilities );
-
- /* Return the array of capabilities, making sure we have no duplicates. */
- return array_unique( $capabilities );
-}
-
-/**
- * Gets an array of capabilities according to each user role. Each role will return its caps,
- * which are then added to the overall $capabilities array.
- *
- * Note that if no role has the capability, it technically no longer exists. Since this could be
- * a problem with folks accidentally deleting the default WordPress capabilities, the
- * members_default_capabilities() will return those all the defaults.
- *
- * @since 0.1
- * @return $capabilities array All the capabilities of all the user roles.
- * @global $wp_roles array Holds all the roles for the installation.
- */
-function members_get_role_capabilities() {
- global $wp_roles;
-
- $capabilities = array();
-
- /* Loop through each role object because we need to get the caps. */
- foreach ( $wp_roles->role_objects as $key => $role ) {
-
- /* Roles without capabilities will cause an error, so we need to check if $role->capabilities is an array. */
- if ( is_array( $role->capabilities ) ) {
-
- /* Loop through the role's capabilities and add them to the $capabilities array. */
- foreach ( $role->capabilities as $cap => $grant )
- $capabilities[$cap] = $cap;
- }
- }
-
- /* Return the capabilities array. */
- return $capabilities;
-}
-
-/**
- * Additional capabilities provided by the plugin that gives users permissions
- * to handle certain components of the plugin.
- *
- * @todo Integrate 'edit_roles' into the settings. It should be a priority on initial setup.
- * @todo Move each capability within its component. Use the 'members_get_capabilities' filter hook to add them.
- *
- * @since 0.1
- */
-function members_get_additional_capabilities() {
-
- $capabilities = array(
- 'create_roles', // Ability to create new roles
- 'delete_roles', // Ability to delete roles
- 'edit_roles', // Ability to edit a role's caps
- 'restrict_content' // Ability to restrict content (content permissions component)
- );
-
- return $capabilities;
-}
-
-/**
- * Make sure we keep the default capabilities in case users screw 'em up. A user could
- * easily remove a useful WordPress capability from all roles. When this happens, the capability
- * is no longer stored in any of the roles, so it basically doesn't exist. This function will house
- * all of the default WordPress capabilities in case this scenario comes into play.
- *
- * For those reading this note, yes, I did "accidentally" remove all capabilities from my administrator
- * account when developing this plugin. And yes, that was fun putting back together. ;)
- *
- * The Codex has a list of all the defaults:
- * @link http://codex.wordpress.org/Roles_and_Capabilities#Capabilities
- *
- * @since 0.1
- * @return $defaults array All the default WordPress capabilities.
- */
-function members_get_default_capabilities() {
-
- /* Create an array of all the default WordPress capabilities so the user doesn't accidentally get rid of them. */
- $defaults = array(
- 'activate_plugins',
- 'add_users',
- 'create_users',
- 'delete_others_pages',
- 'delete_others_posts',
- 'delete_pages',
- 'delete_plugins',
- 'delete_posts',
- 'delete_private_pages',
- 'delete_private_posts',
- 'delete_published_pages',
- 'delete_published_posts',
- 'delete_users',
- 'edit_dashboard',
- 'edit_files',
- 'edit_others_pages',
- 'edit_others_posts',
- 'edit_pages',
- 'edit_plugins',
- 'edit_posts',
- 'edit_private_pages',
- 'edit_private_posts',
- 'edit_published_pages',
- 'edit_published_posts',
- 'edit_theme_options',
- 'edit_themes',
- 'edit_users',
- 'import',
- 'install_plugins',
- 'install_themes',
- 'list_users',
- 'manage_categories',
- 'manage_links',
- 'manage_options',
- 'moderate_comments',
- 'promote_users',
- 'publish_pages',
- 'publish_posts',
- 'read',
- 'read_private_pages',
- 'read_private_posts',
- 'remove_users',
- 'switch_themes',
- 'unfiltered_html',
- 'unfiltered_upload',
- 'update_core',
- 'update_plugins',
- 'update_themes',
- 'upload_files'
- );
-
- /* Return the array of default capabilities. */
- return $defaults;
-}
-
-/**
- * Checks if a specific capability has been given to at least one role. If it has,
- * return true. Else, return false.
- *
- * @since 0.1
- * @uses members_get_role_capabilities() Checks for capability in array of role caps.
- * @param $cap string Name of the capability to check for.
- * @return true|false bool Whether the capability has been given to a role.
- */
-function members_check_for_cap( $cap = '' ) {
-
- /* Without a capability, we have nothing to check for. Just return false. */
- if ( !$cap )
- return false;
-
- /* Gets capabilities that are currently mapped to a role. */
- $caps = members_get_role_capabilities();
-
- /* If the capability has been given to at least one role, return true. */
- if ( in_array( $cap, $caps ) )
- return true;
-
- /* If no role has been given the capability, return false. */
- return false;
-}
-
-/**
- * Old WordPress levels system. This is mostly useful for filtering out the
- * levels when shown in admin screen. Plugins shouldn't rely on these levels
- * to create permissions for users. They should move to the newer system of
- * checking for a specific capability instead.
- *
- * @since 0.1
- * @return array Old user levels.
- */
-function members_get_old_levels() {
- return array( 'level_0', 'level_1', 'level_2', 'level_3', 'level_4', 'level_5', 'level_6', 'level_7', 'level_8', 'level_9', 'level_10' );
-}
-
-/**
- * Get rid of levels since these are mostly useless in newer versions of WordPress.
- *
- * To remove this filter:
- * remove_filter( 'members_get_capabilities', 'members_remove_old_levels' );
- *
- * @since 0.1
- * @param $capabilities array All of the combined capabilities.
- * @return $capabilities array Capabilities with old user levels removed.
- */
-function members_remove_old_levels( $capabilities ) {
- return array_diff( $capabilities, members_get_old_levels() );
-}
-
-/**
- * A function for displaying messages in the admin. It will wrap the message
- * in the appropriate <div> with the custom class entered. The updated class
- * will be added if no $class is given.
- *
- * @since 0.1
- * @param $class string Class the <div> should have.
- * @param $message string The text that should be displayed.
- */
-function members_admin_message( $class = '', $message = '' ) {
- if ( !$class )
- $class = 'updated fade below-h2';
-
- echo "<div class='{$class}' style='padding: 5px 10px;'>";
- echo $message;
- echo '</div>';
-}
-
-/**
- * Members plugin nonce function. This is to help with securely making sure
- * forms have been processed from the correct place.
- *
- * @since 0.1
- * @param $action string Additional action to add to the nonce.
- */
-function members_get_nonce( $action = '' ) {
- if ( $action )
- return "members-component-action_{$action}";
- else
- return "members-plugin";
-}
-
+<?php
+
+/* Disables the old levels from being seen. If you need them, use remove_filter() to add display back. */
+add_filter( 'members_get_capabilities', 'members_remove_old_levels' );
+
+/**
+ * The function that makes this plugin what it is. It returns all of our capabilities
+ * in a nicely-formatted, alphabetized array with no duplicate capabilities. It pulls
+<