Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Importing the Members plugin files and folders.

git-svn-id: http://svn.locallylost.com/plugins/members/trunk@497 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information...
commit 2cf621462ce3c23d219fb95eef59c5bf6d522fc9 0 parents
greenshady authored
Showing with 6,052 additions and 0 deletions.
  1. +250 −0 components.php
  2. +1 −0  components/content-permissions/comments.php
  3. +112 −0 components/content-permissions/content-permissions.php
  4. +116 −0 components/content-permissions/meta-box.php
  5. +28 −0 components/private-blog/default.php
  6. +121 −0 components/role-manager/default.php
  7. +160 −0 components/role-manager/edit-role-form.php
  8. +253 −0 components/role-manager/edit-roles.php
  9. +160 −0 components/role-manager/manage-roles.php
  10. +126 −0 components/role-manager/new-role.php
  11. +162 −0 components/shortcodes/shortcodes.php
  12. +137 −0 components/statistics/default.php
  13. +170 −0 components/statistics/statistics.php
  14. +77 −0 components/statistics/view-stats.php
  15. +88 −0 components/template-tags/template-tags.php
  16. +174 −0 components/widgets/login.php
  17. +113 −0 components/widgets/users.php
  18. +267 −0 functions-admin.php
  19. +174 −0 functions.php
  20. BIN  languages/members-en_EN.mo
  21. +1,309 −0 languages/members-en_EN.po
  22. +1,309 −0 languages/members.pot
  23. +146 −0 members.php
  24. +77 −0 readme.css
  25. +376 −0 readme.html
  26. +63 −0 readme.txt
  27. +83 −0 settings.php
250 components.php
@@ -0,0 +1,250 @@
+<?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( 'init', '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( 'init', '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' );
+}
+
+?>
1  components/content-permissions/comments.php
@@ -0,0 +1 @@
+<?php /* Life is sweet. */ ?>
112 components/content-permissions/content-permissions.php
@@ -0,0 +1,112 @@
+<?php
+/**
+ * The Content Permissions component was created so that access to specific parts of a site
+ * can be granted or denied. This is the component that gives truly fine-grained control over
+ * who can see what content on the front end of the site.
+ *
+ * Current features of the Content Permissions component:
+ * - Block content on a post-by-post (or page) basis according to user role.
+ *
+ * This feature set should eventually include the ability to block access to taxonomies and
+ * attachments to be truly useful.
+ *
+ * @todo Check and test feeds and filter if necessary.
+ * @todo Make sure comments aren't shown anywhere.
+ * @todo Remove pages from wp_list_pages() and wp_page_menu().
+ * @todo Cover ALL the bases. If something's restricted, make sure it stays that way.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/**
+ * Adds the content permissions meta box to the post/page edit screen
+ * if the current user has the 'restrict_content' capability.
+ */
+add_action( 'admin_menu', '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', 1, 2 );
+
+/* Add messages to the components form. */
+add_action( 'members_pre_components_form', 'members_message_no_restrict_content' );
+
+/* Filter the content and exerpts. */
+add_filter( 'the_content', 'members_content_permissions_protect' );
+add_filter( 'get_the_excerpt', 'members_content_permissions_protect' );
+add_filter( 'the_excerpt', 'members_content_permissions_protect' );
+
+/* Filter the comments template to make sure comments aren't shown to users without access. */
+add_filter( 'comments_template', 'members_content_permissions_comments' );
+
+/**
+ * Disables the comments template if the current post has been restricted, unless
+ * the user has the role needed to view the content of the post.
+ *
+ * @todo Allow users to override the "no comments" template if in their theme.
+ *
+ * @since 0.1
+ * @param $template string File URL of the template to display.
+ * @return $template string File URL of the template to display.
+ */
+function members_content_permissions_comments( $template ) {
+ global $wp_query;
+
+ $roles = get_post_meta( $wp_query->post->ID, '_role', false );
+
+ if ( !empty( $roles ) && is_array( $roles ) ) {
+ foreach( $roles as $role ) {
+ if ( !is_feed() && ( current_user_can( $role ) || current_user_can( 'restrict_content' ) ) )
+ return $template;
+ }
+ $template = MEMBERS_COMPONENTS . '/content-permissions/comments.php';
+ }
+ return $template;
+}
+
+/**
+ * Displays a message if the Content Permissions component is active but no role
+ * has been given the capability of 'restrict_content', which is a required capability to
+ * use the component.
+ *
+ * @since 0.1
+ * @uses is_active_members_component() Checks if the content_permissions component is active.
+ * @uses members_check_form_cap() Checks if the restrict_content capability has been given to a role.
+ */
+function members_message_no_restrict_content() {
+ if ( is_active_members_component( 'content_permissions' ) && !members_check_for_cap( 'restrict_content' ) ) {
+ $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');
+ members_admin_message( '', $message );
+ }
+}
+
+/**
+ * Disables content passed through the $content variable given the current user's role. The
+ * function checks for a custom field key of "Role" and loops through its values, checking
+ * if the current user has that particular role.
+ *
+ * Users with the rescrict_content capability should also be able to see the content.
+ *
+ * @since 0.1
+ * @uses get_post_meta() Gets the meta values of the "_role" custom field key.
+ * @uses current_user_can() Checks if the current user has a particular role (capability).
+ * @param $content string The current post's content/excerpt.
+ * @return $content string Either the current post's content/excerpt or a content inaccessible message.
+ */
+function members_content_permissions_protect( $content ) {
+ global $post;
+
+ $roles = get_post_meta( $post->ID, '_role', false );
+
+ if ( !empty( $roles ) && is_array( $roles ) ) {
+ foreach( $roles as $role ) {
+ if ( !is_feed() && ( current_user_can( $role ) || current_user_can( 'restrict_content' ) ) )
+ return $content;
+ }
+ $content = '<p class="restricted alert warning">' . __('Sorry, but you do not have permission to view this content.', 'members') . '</p>';
+ }
+
+ return $content;
+}
+
+?>
116 components/content-permissions/meta-box.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * Adds the meta box for the Content Permissions component. This allows users with
+ * the 'restrict_content' capability to restrict posts/pages on a post/page basis. Roles
+ * with the 'restrict_content' capability should be able to see all content, regardless
+ * of the settings.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/**
+ * Adds the meta box to the post/page edit screen if the current user has
+ * the 'restrict_content' capability.
+ *
+ * @since 0.1
+ * @uses add_meta_box() Creates an additiona meta box.
+ */
+function members_content_permissions_create_meta_box() {
+ if ( current_user_can( 'restrict_content' ) ) {
+ add_meta_box( 'content-permissions-meta-box', 'Content Permissions', 'members_content_permissions_meta_box', 'post', 'advanced', 'high' );
+ add_meta_box( 'content-permissions-meta-box', 'Content Permissions', 'members_content_permissions_meta_box', 'page', 'advanced', 'high' );
+ }
+}
+
+/**
+ * Controls the display of the content permissions meta box. This allows users
+ * to select roles that should have access to an individual post/page.
+ *
+ * @since 0.1
+ * @global $post
+ * @global $wp_roles
+ * @param $object
+ * @param $box
+ */
+function members_content_permissions_meta_box( $object, $box ) {
+ global $post, $wp_roles; ?>
+
+ <input type="hidden" name="content_permissions_meta_nonce" value="<?php echo wp_create_nonce(plugin_basename(__FILE__)); ?>" />
+
+ <p>
+ <label for="roles"><?php _e('<strong>Roles:</strong> Restrict the content to these roles on the front end of the site. If all boxes are left unchecked, everyone can view the content.', 'members'); ?></label>
+ </p>
+
+ <div style="overflow: hidden;">
+
+ <?php
+
+ /* Get the 'Role' meta key. */
+ $meta = get_post_meta( $post->ID, '_role', false );
+
+ /* 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( $meta ) && in_array( $role, $meta ) )
+ $checked = ' checked="checked" '; ?>
+
+ <p style="width: 32%; float: left; margin-right: 0;">
+ <label for="role-<?php echo $role; ?>">
+ <input type="checkbox" name="role[<?php echo $role; ?>]" id="role-<?php echo $role; ?>" <?php echo $checked; ?> value="<?php echo $role; ?>" />
+ <?php echo str_replace( '|User role', '', $name ); ?>
+ </label>
+ </p>
+ <?php } ?>
+
+ </div><?php
+}
+
+/**
+ * Saves the content permissions metabox data to a custom field.
+ *
+ * @since 0.1
+ */
+function members_content_permissions_save_meta( $post_id, $post ) {
+ global $wp_roles;
+
+ /* Only allow users that can edit the current post to submit data. */
+ if ( 'post' == $post->post_type && !current_user_can( 'edit_posts', $post_id ) )
+ return;
+
+ /* Only allow users that can edit the current page to submit data. */
+ elseif ( 'page' == $post->post_type && !current_user_can( 'edit_pages', $post_id ) )
+ return;
+
+ /* Don't save if the post is only a revision. */
+ if ( 'revision' == $post->post_type )
+ return;
+
+ /* Loop through each of the site's available roles. */
+ foreach ( $wp_roles->role_names as $role => $name ) {
+
+ /* Get post metadata for the custom field key 'Role'. */
+ $meta = (array)get_post_meta( $post_id, '_role', false );
+
+ /* Check if the role was selected. */
+ if ( $_POST['role'][$role] ) {
+
+ /* If selected and already saved, continue looping through the roles and do nothing for this role. */
+ if ( in_array( $role, $meta ) )
+ continue;
+
+ /* If the role was seleted and not already saved, add the role as a new value to the 'Role' custom field. */
+ else
+ $add = add_post_meta( $post_id, '_role', $role, false );
+ }
+
+ /* If role not selected, delete. */
+ else
+ $delete = delete_post_meta( $post_id, '_role', $role );
+
+ } // End loop through site's roles.
+}
+
+?>
28 components/private-blog/default.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * The Private Blog component is for making your site completely private to people that are
+ * not logged into the site. If not logged in, it will redirect all people to the 'wp-login.php' page.
+ *
+ * @todo Make sure 'blog_public' is set to true.
+ * @todo Disable content from feeds or add an additional feed component.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/* Redirects users to the login page. */
+add_action( 'template_redirect', 'members_please_log_in' );
+
+/**
+ * Redirects users that are not logged in to the 'wp-login.php' page.
+ *
+ * @since 0.1
+ * @uses is_user_logged_in() Checks if the current user is logged in.
+ * @uses auth_redirect() Redirects people that are not logged in to the login page.
+ */
+function members_please_log_in() {
+ if ( !is_user_logged_in() && !strpos( $_SERVER['SCRIPT_NAME'], 'wp-login.php' ) )
+ auth_redirect();
+}
+
+?>
121 components/role-manager/default.php
@@ -0,0 +1,121 @@
+<?php
+/**
+ * The Role Manager component allows users to create, edit, and delete roles for use on
+ * their site.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/* Add the Edit Roles and New Roles page to the admin. */
+add_action( 'admin_menu', 'members_component_load_role_manager' );
+
+/* 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' );
+
+/**
+ * Loads the settings pages for the Roles and New Roles components. For a logged-in
+ * user to see the New Roles page, they must have the 'create_roles' capability.
+ * In order to gain this capability, one should edit a role to give it this capability
+ *
+ * @since 0.2
+ * @global $members
+ * @uses add_submenu_page() Adds a submenu to the users menu.
+ */
+function members_component_load_role_manager() {
+ global $members;
+
+ /* 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', __('New Role', 'members'), __('New Role', 'members'), 'create_roles', 'new-role', 'members_new_role_page' );
+}
+
+/**
+ * Loads the Manage Roles page.
+ * @since 0.1
+ */
+function members_edit_roles_page() {
+ require_once( MEMBERS_COMPONENTS . '/role-manager/manage-roles.php' );
+}
+
+/**
+ * Loads the New Role page when its needed.
+ *
+ * @since 0.1
+ */
+function members_new_role_page() {
+ require_once( MEMBERS_COMPONENTS . '/role-manager/new-role.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
+ * @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
+ */
+function members_message_role_deleted() {
+ $message = __('Role deleted.', 'members');
+ members_admin_message( '', $message );
+}
+
+/**
+ * Message to show when multiple roles have been deleted (bulk delete).
+ * @since 0.1
+ */
+function members_message_roles_deleted() {
+ $message = __('Selected roles deleted.', 'members');
+ members_admin_message( '', $message );
+}
+
+/**
+ * Message to show when no role has the 'edit_roles' capability.
+ * @since 0.1
+ */
+function members_message_no_edit_roles() {
+ if ( is_active_members_component( 'edit_roles' ) && !members_check_for_cap( 'edit_roles' ) ) {
+ $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');
+ members_admin_message( '', $message );
+ }
+}
+
+/**
+ * Displays a message if the New Roles component is active and no
+ * roles have the 'create_roles' capability.
+ *
+ * @since 0.1
+ */
+function members_message_no_create_roles() {
+ if ( is_active_members_component( 'new_roles' ) && !members_check_for_cap( 'create_roles' ) ) {
+ $message = __('To create new roles, you must give the <code>create_roles</code> capability to at least one role.', 'members');
+ members_admin_message( '', $message );
+ }
+}
+
+?>
160 components/role-manager/edit-role-form.php
@@ -0,0 +1,160 @@
+<?php
+/**
+ * The Edit Role form is for editing individual roles. The role to edit must
+ * have been selected on the Edit Roles page.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/* Get the current role object to edit. */
+$role = get_role( $role );
+
+/* Get all the capabilities */
+$capabilities = members_get_capabilities();
+
+/* Check if the form has been submitted. */
+if ( isset($_POST['edit-role-saved']) && 'Y' == $_POST['edit-role-saved'] ) {
+
+ /* 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
+
+ } // End check for new capabilities
+
+} // End check for form submission ?>
+
+<div class="wrap">
+
+ <h2><?php printf(__('Edit the %1$s role', 'members'), $role->name ); ?></h2>
+
+ <?php if ( isset($role_updated) and $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}" ) ); ?>" style="border:none;background:transparent;">
+
+ <?php wp_nonce_field( members_get_nonce( 'edit-roles' ) ); ?>
+
+ <div class="postbox open">
+
+ <h3><?php printf( __('<strong>Role:</strong> %1$s', 'members'), $role->name ); ?></h3>
+
+ <div class="inside">
+
+ <table class="form-table">
+
+ <tr>
+ <th style="width: 20%;">
+ <strong><?php _e('Capabilities', 'members'); ?></strong>
+ </th>
+
+ <td>
+ <?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'); ?>
+ <br /><br />
+ <?php
+
+ /* Looop through each available capability. */
+ foreach ( $capabilities as $cap ) {
+
+ /* If the role has the capability, set the checkbox to 'checked'. */
+ if ( $role->has_cap( $cap ) )
+ $checked = " checked='checked' ";
+
+ /* If the role doesn't have the the capability, set the checkbox value to false. */
+ else
+ $checked = ''; ?>
+
+ <div style='overflow: hidden; margin: 0 0 5px 0; float:left; width: 32.67%;'>
+ <input name='<?php echo "role-caps[{$role->name}-{$cap}]"; ?>' id='<?php echo "{$role->name}-{$cap}"; ?>' <?php echo $checked; ?> type='checkbox' value='true' />
+ <label for="<?php echo "{$role->name}-{$cap}"; ?>"><?php if ( $checked ) echo "<strong>$cap</strong>"; else echo "<em>$cap</em>"; ?></label>
+ </div>
+
+ <?php } // Endforeach ?>
+ </td>
+ </tr>
+
+ <tr>
+ <th style="width: 20%;">
+ <strong><?php _e('New Capabilities', 'members'); ?></strong>
+ </th>
+
+ <td>
+ <?php _e('Add up to six new capabilities with this form for this role (more can be added later). Please only use letters, numbers, and underscores.', 'members'); ?>
+ <br /><br />
+ <p style="margin: 0 0 5px 0; float:left; width: 32.67%;">
+ <input type="text" id="new-cap-1" name="new-cap[]" value="" size="20" />
+ </p>
+ <p style="margin: 0 0 5px 0; float:left; width: 32.67%;">
+ <input type="text" id="new-cap-2" name="new-cap[]" value="" size="20" />
+ </p>
+ <p style="margin: 0 0 5px 0; float:left; width: 32.67%;">
+ <input type="text" id="new-cap-3" name="new-cap[]" value="" size="20" />
+ </p>
+ <p style="margin: 0 0 5px 0; float:left; width: 32.67%;">
+ <input type="text" id="new-cap-4" name="new-cap[]" value="" size="20" />
+ </p>
+ <p style="margin: 0 0 5px 0; float:left; width: 32.67%;">
+ <input type="text" id="new-cap-5" name="new-cap[]" value="" size="20" />
+ </p>
+ <p style="margin: 0 0 5px 0; float:left; width: 32.67%;">
+ <input type="text" id="new-cap-6" name="new-cap[]" value="" size="20" />
+ </p>
+
+ </td>
+ </tr>
+
+ </table><!-- .form-table -->
+
+ </div><!-- .inside -->
+
+ </div><!-- .postbox .open -->
+
+ <p class="submit" style="clear:both;">
+ <input type="submit" name="Submit" class="button-primary" value="<?php _e('Update Role', 'members') ?>" />
+ <input type="hidden" name="edit-role-saved" value="Y" />
+ </p><!-- .submit -->
+
+ </form>
+
+ </div><!-- #poststuff -->
+
+</div><!-- .wrap -->
253 components/role-manager/edit-roles.php
@@ -0,0 +1,253 @@
+<?php
+/**
+ * The Edit Roles page displays all of the site's roles in an easy-to-read manner. Along with
+ * each role, the number of users and capabilities are displayed. Roles without users are
+ * considered "inactive" roles within this plugin's system.
+ *
+ * All roles can be edited. However, the current user's role and the default role cannot be
+ * deleted. To delete the current user's role, another logged-in user with the 'delete_roles'
+ * capability and a different role must perform this action. To delete the default role, the
+ * default must be changed under the General Options page in the WordPress admin.
+ *
+ * Users of roles that are deleted will be given the default role (typically 'Subscriber'). It
+ * is advisable to not make such a change with a large number of users because a new user
+ * object must be created to change each individual user.
+ *
+ * @todo Test deleting a role with 100s (even 1,000s) of users to see what sort of strain this has.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/* Get the global $members variable. */
+global $members;
+
+/* Current user in the admin. */
+$user = new WP_User( $members->current_user->ID );
+
+/* Set the available roles array.*/
+$avail_roles = array();
+
+/* Get all the users of the current blog. */
+$users_of_blog = get_users_of_blog();
+
+/* Loop through each user. */
+foreach ( (array) $users_of_blog as $blog_user ) {
+
+ $meta_values = unserialize( $blog_user->meta_value );
+
+ foreach ( (array) $meta_values as $role => $value ) {
+ if ( !isset( $avail_roles[$role] ) )
+ $avail_roles[$role] = 0;
+
+ ++$avail_roles[$role];
+ }
+}
+
+/* Destroy the $users_of_blog variable. */
+unset( $users_of_blog );
+
+/* Can the current user delete_roles? */
+if ( current_user_can( 'delete_roles' ) )
+ $delete_roles = true;
+
+/* Get the default role. */
+$default_role = get_option( 'default_role' );
+
+/* Sort out the roles, active roles, and inactive roles. */
+$all_roles = $active_roles = $inactive_roles = 0;
+
+$active_roles_arr = $inactive_roles_arr = array();
+
+/* Loop through all of the roles, adding each role to its respective category (active, inactive). */
+foreach ( $wp_roles->role_names as $role => $name ) {
+ $all_roles++;
+ if ( isset($avail_roles[$role]) ) {
+ $active_roles++;
+ $active_roles_arr[$role] = $name;
+ }
+ else {
+ $inactive_roles++;
+ $inactive_roles_arr[$role] = $name;
+ }
+}
+
+$role_status = isset( $_GET['role_status'] ) ? $_GET['role_status'] : 'all';
+
+/* Set variables for when role_status is active. */
+if ( 'active' == $role_status ) {
+ $roles_loop_array = $active_roles_arr;
+ $title = __('Edit Active Roles', 'members');
+ $current_page = admin_url( esc_url( 'users.php?page=roles&role_status=active' ) );
+}
+
+/* Set variables for when role_status is inactive. */
+elseif ( 'inactive' == $role_status ) {
+ $roles_loop_array = $inactive_roles_arr;
+ $title = __('Edit Inactive Roles', 'members');
+ $current_page = admin_url( esc_url( 'users.php?page=roles&role_status=inactive' ) );
+}
+
+/* Set default variables for when role_status is neither active nor inactive. */
+else {
+ $roles_loop_array = $wp_roles->role_names;
+ $title = __('Edit Roles', 'members');
+ $current_page = admin_url( esc_url( "users.php?page=roles" ) );
+}
+
+/* Sort the roles array into alphabetical order. */
+ksort( $roles_loop_array ); ?>
+
+<div class="wrap">
+
+ <h2><?php echo $title; ?></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 ( $delete_roles ) echo '<option value="delete">' . __('Delete', 'members') . '</option>'; ?>
+ </select>
+ <input type="submit" value="<?php _e('Apply', 'members'); ?>" name="doaction" id="doaction" class="button-secondary action" />
+ </div><!-- .alignleft .actions -->
+
+ <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 Name', 'members'); ?></th>
+ <th><?php _e('Role', '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 Name', '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 ) { ?>
+
+ <?php $name = str_replace( '|User role', '', $name ); ?>
+
+ <tr valign="top" class="<?php if ( isset($avail_roles[$role]) ) echo 'active'; else echo 'inactive'; ?>">
+
+ <th class="manage-column column-cb check-column">
+ <?php if ( $role !== $default_role && !$user->has_cap( $role ) ) { ?>
+ <input name="roles[<?php echo $role; ?>]" id="<?php echo $role; ?>" type="checkbox" value="<?php echo $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 $edit_link; ?>" title="<?php printf( __('Edit the %1$s role', 'members'), $name ); ?>"><strong><?php echo $name; ?></strong></a>
+
+ <div class="row-actions">
+ <a href="<?php echo $edit_link; ?>" title="<?php printf( __('Edit the %1$s role', 'members'), $name ); ?>"><?php _e('Edit', 'members'); ?></a>
+
+ <?php /* Delete role link. */
+ if ( $delete_roles && $role !== $default_role && !$user->has_cap( $role ) ) {
+ $delete_link = admin_url( wp_nonce_url( "users.php?page=roles&amp;action=delete&amp;role={$role}", members_get_nonce( 'edit-roles' ) ) ); ?>
+ | <a href="<?php echo $delete_link; ?>" title="<?php printf( __('Delete the %1$s role', 'members'), $name ); ?>"><?php _e('Delete', 'members'); ?></a>
+ <?php }
+
+ /* Link to change the default role Options General. */
+ if ( $role == $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 }
+
+ /* If there are users, provide a link to the users page of that role. */
+ if ( isset($avail_roles[$role]) ) { ?>
+ | <a href="<?php echo admin_url( esc_url( "users.php?role={$role}" ) ); ?>" title="<?php printf( __('View all users with the %1$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 /* Check if any users are assigned to the role. If so, display a link to the role's users page. */
+ if ( isset($avail_roles[$role]) && 1 < $avail_roles[$role] )
+ echo '<a href="' . admin_url( esc_url( "users.php?role={$role}" ) ) . '" title="' . sprintf( __('View all users with the %1$s role', 'members'), $name ) . '">' . sprintf( __('%1$s Users', 'members'), $avail_roles[$role] ) . '</a>';
+ elseif ( isset($avail_roles[$role]) && 1 == $avail_roles[$role] )
+ echo '<a href="' . admin_url( esc_url( "users.php?role={$role}" ) ) . '" title="' . sprintf( __('View all users with the %1$s role', 'members'), $name ) . '">' . __('1 User', 'members') . '</a>';
+ else
+ echo '<em>' . __('No users have this role.', 'members') . '</em>';
+ ?></p>
+ </td><!-- .desc -->
+
+ <td class="desc">
+ <p>
+ <?php /* Check if the role has any capabilities. */
+
+ $role_2 = get_role( $role );
+
+ if ( is_array( $role_2->capabilities ) ) {
+ $cap_count = count( $role_2->capabilities );
+ if ( 1 < $cap_count ) printf( __('%1$s Capabilities', 'members'), $cap_count );
+ elseif ( 1 == $cap_count ) _e('1 Capability', 'members');
+ }
+ else
+ echo '<em>' . __('This role has no capabilities', 'members') . '</em>'; ?>
+ </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 ( $delete_roles ) echo '<option value="delete">' . __('Delete', 'members') . '</option>'; ?>
+ </select>
+ <input type="submit" value="<?php _e('Apply', 'members'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
+ </div><!-- .alignleft .actions -->
+
+ <br class="clear" />
+
+ </div><!-- .tablenav -->
+
+ </form><!-- #roles -->
+
+ </div><!-- #poststuff -->
+
+</div><!-- .wrap -->
160 components/role-manager/manage-roles.php
@@ -0,0 +1,160 @@
+<?php
+/**
+ * The main file of the Edit Roles component. This is where we run checks to see which page
+ * needs to be loaded. It also checks if actions have been performed on the Edit Roles page.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/* Get the $wp_roles variable and $wpdb. Do we need $wpdb (need to check)? */
+global $wp_roles, $wpdb;
+
+/* 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( 'edit-roles.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 ) {
+
+ /* Get all users with the current role of the loop. */
+ $wp_user_search = new WP_User_Search( '', '', $role );
+ $change_users = $wp_user_search->get_results();
+
+ /* If there are users with the role, let's delete them and give them the default role. */
+ if ( isset( $change_users ) && is_array( $change_users ) ) {
+
+ /* Loop through each of the users we need to change. */
+ 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 role. Do we need this additional check? */
+ if ( $new_user->has_cap( $role ) ) {
+ $new_user->remove_role( $role );
+ $new_user->set_role( $default_role );
+ }
+ }
+ }
+
+ /* Remove the role. */
+ remove_role( $role );
+ }
+
+ /* Load the edit roles page. */
+ require_once( 'edit-roles.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 = $_GET['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 );
+
+ /* Load the edit roles page. */
+ require_once( 'edit-roles.php' );
+ break;
+
+ /* If a role has been updated. Is this needed still? */
+ case 'role-updated' :
+
+ /* Set some default variables. */
+ $title = __('Edit Role', 'members');
+ $role = $_GET['role'];
+
+ /* Load the edit role form. */
+ require_once( 'edit-role-form.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. */
+ $title = __('Edit Role', 'members');
+ $role = $_GET['role'];
+
+ /* Load the edit role form. */
+ require_once( 'edit-role-form.php' );
+
+ break;
+
+ /* The default page is the edit roles page. */
+ default :
+
+ /* Load the edit roles page.*/
+ require_once( 'edit-roles.php' );
+ break;
+}
+
+?>
126 components/role-manager/new-role.php
@@ -0,0 +1,126 @@
+<?php
+/**
+ * Page for creating new roles. Displays the new role form and creates
+ * a new role if a new role has been submitted.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/* Check if the form has been submitted. */
+if ( isset($_POST['new-role-submit']) && 'Y' == $_POST['new-role-submit'] ) {
+
+ /* 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 = $_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">
+
+ <h2><?php _e('Add a new user 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" ); ?>" style="border:none;background:transparent;">
+
+ <?php wp_nonce_field( members_get_nonce( 'new-role' ) ); ?>
+
+ <div class="postbox open">
+
+ <h3><?php _e('Create a new user role', 'members'); ?></h3>
+
+ <div class="inside">
+
+ <table class="form-table">
+ <tr>
+ <th style="width: 20%;">
+ <strong><?php _e('About:', 'members'); ?></strong>
+ </th>
+ <td>
+ <?php printf( __('Here you can create as many new roles as you\'d like. Roles are a way of grouping your users. You can give individual users a role from the <a href="%1$s" title="Manage Users">user management</a> screen. This will allow you to do specific things for users with a specific role. Once you\'ve created a new role, you can manage it with the <em>Edit Roles</em> component.', 'members'), admin_url( 'users.php' ) ); ?>
+ </td>
+ </tr>
+
+ <tr>
+ <th style="width: 20%;">
+ <label for="role-id"><strong><?php _e('Role:', 'members'); ?></strong></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 style="width: 20%;">
+ <label for="role-name"><strong><?php _e('Role Label:', 'members'); ?></strong></label>
+ </th>
+ <td>
+ <?php _e('<strong>Required:</strong> Enter a label your role. This will be the title that is displayed in most cases.', 'members'); ?>
+ <br />
+ <input type="text" id="role-name" name="role-name" value="" size="30" />
+ </td>
+ </tr>
+
+ <tr>
+ <th style="width: 20%;">
+ <strong><?php _e('Capabilities:', 'members'); ?></strong>
+ </th>
+ <td>
+ <?php _e('<strong>Optional:</strong> Select which capabilities your new role should have. These may be changed later using the <em>Edit Roles</em> component.', 'members'); ?>
+ <br /><br />
+ <?php foreach ( members_get_capabilities() as $cap ) : ?>
+ <div style="float: left; width: 32.67%; margin: 0 0 5px 0;">
+ <input name='capabilities[<?php echo $cap; ?>]' id='capabilities-<?php echo $cap; ?>' type="checkbox" value='<?php echo $cap; ?>' <?php if ( in_array( $cap, members_new_role_default_capabilities() ) ) echo "checked='checked'"; ?> />
+ <label for="capabilities-<?php echo $cap; ?>"><?php if ( in_array( $cap, members_new_role_default_capabilities() ) ) echo "<strong>$cap</strong>"; else echo $cap; ?></label>
+ </div>
+ <?php endforeach; ?>
+ </td>
+ </tr>
+
+ </table><!-- .form-table -->
+
+ </div><!-- .inside -->
+
+ </div><!-- .postbox -->
+
+ <p class="submit">
+ <input type="submit" name="Submit" class="button-primary" value="<?php _e('Create Role', 'members') ?>" />
+ <input type="hidden" name="new-role-submit" value="Y" />
+ </p><!-- .submit -->
+
+ </form>
+
+ </div><!-- #poststuff -->
+
+</div><!-- .poststuff -->
162 components/shortcodes/shortcodes.php
@@ -0,0 +1,162 @@
+<?php
+/**
+ * The Shortcodes component provides additional [shortcodes] for use within posts/pages
+ * and any other shortcode-capable area.
+ *
+ * @todo need a [hide] shortcode or allow [access] to do the opposite.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/* Add shortcodes. */
+add_shortcode( 'login-form', 'members_login_form_shortcode' );
+add_shortcode( 'access', 'members_access_check_shortcode' );
+add_shortcode( 'feed', 'members_access_check_shortcode' );
+add_shortcode( 'is_user_logged_in', 'members_is_user_logged_in_shortcode' );
+add_shortcode( 'get_avatar', 'members_get_avatar_shortcode' );
+add_shortcode( 'avatar', 'members_get_avatar_shortcode' );
+
+/**
+ * Displays an avatar for any user. At the very least, an ID or email must
+ * be input. Otherwise, we can't know which avatar to grab.
+ *
+ * Users should input the code as [get_avatar id="30" alt="Justin Tadlock"].
+ *
+ * @since 0.1
+ * @uses get_avatar() Grabs the users avatar.
+ * @param $attr array The shortcode attributes.
+ */
+function members_get_avatar_shortcode( $attr ) {
+
+ /* Set up our default attributes. */
+ $defaults = array(
+ 'id' => '',
+ 'email' => '',
+ 'size' => 96,
+ 'default' => '',
+ 'alt' => ''
+ );
+
+ /* Merge the input attributes and the defaults. */
+ extract( shortcode_atts( $defaults, $attr ) );
+
+ /* If an email was input, use it. */
+ if ( $email )
+ $id_or_email = $email;
+
+ /* If no email was input, use the ID. */
+ else
+ $id_or_email = $id;
+
+ /* Return the avatar. */
+ return get_avatar( $id_or_email, $size, $default, $alt );
+}
+
+/**
+ * Displays content if the user viewing it is currently logged in. This also blocks
+ * content from showing in feeds.
+ *
+ * Content needs to be wrapped with this shortcode like
+ * [is_user_logged_in]This is content.[/is_user_logged_in].
+ *
+ * @todo Provide a filter hook for displaying a "please log in to view" message.
+ *
+ * @since 0.1
+ * @uses is_feed() Checks if the content is currently being shown in a feed.
+ * @uses is_user_logged_in() Checks if the current user is logged in.
+ * @param $attr array Attributes for the shortcode (not usefule here).
+ * @param $content string The content located between the opening and closing of the shortcode.
+ * @return $content string The content to be shown.
+ */
+function members_is_user_logged_in_shortcode( $attr, $content = null ) {
+
+ /* If it is a feed or the user is not logged in, return nothing. */
+ if ( !is_feed() || !is_user_logged_in() )
+ return '';
+
+ /* Return the content. */
+ return do_shortcode( $content );
+}
+
+/**
+ * Content that should only be shown in feed readers. Can be useful for
+ * displaying feed-specific items.
+ *
+ * Content should be wrapped like [feed]This is content.[/feed].
+ *
+ * @since 0.1
+ * @uses is_feed() Checks if the content is currently being shown in a feed.
+ * @uses is_null() Checks if there is any content.
+ * @param $attr array Attributes for the shortcode (not currently useful but may later add a $display/$show parameter).
+ * @param $content string The content located between the opening and closing of the shortcode.
+ * @return $content string The content to be shown.
+ */
+function members_feed_shortcode( $attr, $content = null ) {
+
+ /* If not feed or no content exists, return nothing. */
+ if ( !is_feed() || is_null( $content ) )
+ return '';
+
+ /* Return the content. */
+ return do_shortcode( $content );
+}
+
+/**
+ * Provide/restrict access to specific roles or capabilities. This content should
+ * not be shown in feeds.
+ *
+ * @todo Allow multiple roles and capabilities to be input (comma-separated).
+ *
+ * Content should be wrapped like [access role="editor"]This is content.[/access].
+ *
+ * @since 0.1
+ * @uses current_user_can() Checks if the current user has the role or capability.
+ * @uses is_feed() Checks if we're currently viewing a feed.
+ * @param $attr array The shortcode attributes.
+ * @param $content string The content that should be shown/restricted.
+ * @return $content string The content if it should be shown. Else, return nothing.
+ */
+function members_access_check_shortcode( $attr, $content = null ) {
+
+ /* Set up the default attributes. */
+ $defaults = array(
+ 'capability' => '',
+ 'role' => '',
+ 'feed' => false,
+ );
+
+ /* Merge the input attributes and the defaults. */
+ extract( shortcode_atts( $defaults, $attr ) );
+
+ /* If the current user has the input capability, show the content. */
+ if ( $capability && current_user_can( $capability ) )
+ return do_shortcode( $content );
+
+ /* If the current user has the input role, show the content. */
+ elseif ( $role && current_user_can( $role ) )
+ return do_shortcode( $content );
+
+ /* If $feed was set to true and we're currently displaying a feed, show the content. */
+ elseif ( $feed && 'false' !== $feed && is_feed() )
+ return do_shortcode( $content );
+
+ /* If there is no content, return nothing. */
+ elseif ( !is_null( $content ) )
+ return '';
+
+ /* Return nothing if none of the conditions have been met. */
+ return '';
+}
+
+/**
+ * Displays a login form.
+ *
+ * @since 0.1
+ * @uses members_get_login_form() Displays the login form.
+ */
+function members_login_form_shortcode() {
+ return members_get_login_form();
+}
+
+?>
137 components/statistics/default.php
@@ -0,0 +1,137 @@
+<?php
+/**
+ * Stats package for the plugin. This component displays stats for individual roles. On the main stats
+ * page, each role is listed. Each role then has its own stats page, which lists users by month. Each
+ * month should list all of the users that signed up for that particular month for with that role.
+ *
+ * To view the stats page, a user must have a role with the 'view_stats' capability.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/* Add the stats page to the admin. */
+add_action( 'admin_menu', 'members_component_add_stats_page' );
+
+/* Additional capabilities required by the component. */
+add_filter( 'members_get_capabilities', 'members_component_stats_capabilities' );
+
+/**
+ * Adds the stats page to the admin menu.
+ *
+ * @since 0.2
+ */
+function members_component_add_stats_page() {
+ global $members;
+
+ $members->stats_page = add_submenu_page( 'users.php', __( 'Members Statistics', 'members' ), __( 'Members Stats', 'members' ), 'view_stats', 'stats', 'members_component_stats_page' );
+}
+
+/**
+ * Loads the stats page.
+ *
+ * @since 0.2
+ */
+function members_component_stats_page() {
+
+ $stats = get_option( 'members_statistics' );
+
+ if ( empty( $stats ) )
+ members_component_stats_create_initial_stats();
+
+ require_once( MEMBERS_COMPONENTS . '/statistics/statistics.php' );
+}
+
+/**
+ * Adds additional capabilities required by the stats component.
+ *
+ * @since 0.2
+ */
+function members_component_stats_capabilities( $capabilities ) {
+
+ $capabilities['view_stats'] = 'view_stats';
+
+ return $capabilities;
+}
+
+add_action( 'user_register', 'update_stats_package' );
+
+function update_stats_package( $user_id ) {
+
+ $stats = get_option( 'members_statistics' );
+ $new_user = new WP_User( $user_id );
+
+ if ( is_array( $new_user->roles ) )
+ $role = $new_user->roles[0];
+
+ $stats[$role][$new_user->ID] = array(
+ 'id' => $new_user->ID,
+ 'role' => $role,
+ 'date' => $new_user->user_registered,
+ 'year' => mysql2date( 'Y', $new_user->user_registered ),
+ 'month' => mysql2date( 'm', $new_user->user_registered ),
+ 'day' => mysql2date( 'd', $new_user->user_registered ),
+ );
+
+ update_option( 'members_statistics', $stats );
+}
+
+
+/**
+ * If the stats package was previously unused, this means that prior users stats were
+ * not tracked. So, we're going to create some default stats based on the user registration
+ * date and user role.
+ *
+ * @since 0.2
+ */
+function members_component_stats_create_initial_stats() {
+ global $wp_roles;
+
+ $stats = array();
+
+ foreach ( $wp_roles->role_objects as $key => $role ) {
+
+ $sta = array();
+
+ $search = new WP_User_Search( '', '', $role->name );
+
+ $users = $search->get_results();
+
+ if ( isset( $users ) && is_array( $users ) ) {
+
+ foreach ( $users as $user ) {
+ $new_user = new WP_User( $user );
+
+ $sta[$new_user->ID] = array(
+ 'id' => $new_user->ID,
+ 'role' => $role->name,
+ 'date' => $new_user->user_registered,
+ 'year' => mysql2date( 'Y', $new_user->user_registered ),
+ 'month' => mysql2date( 'm', $new_user->user_registered ),
+ 'day' => mysql2date( 'd', $new_user->user_registered ),
+ );
+
+ }
+ }
+
+ $stats[$role->name] = $sta;
+ }
+
+ add_option( 'members_statistics', $stats );
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+?>
170 components/statistics/statistics.php
@@ -0,0 +1,170 @@
+<?php
+/**
+ * The Stats page displays all of the site's roles and each role's stats.
+ *
+ * To view this page, a user must have a role with the capability of 'view_stats'.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+
+/* Get the current action performed by the user. */
+//$view_role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : false;
+//$view_stats = isset( $_REQUEST['view'] ) ? $_REQUEST['view'] : false;
+
+if ( isset( $_REQUEST['role'] ) && isset( $_REQUEST['view'] ) ) {
+
+ /* Verify the referer. */
+ check_admin_referer( members_get_nonce( 'view-stats' ) );
+
+ /* Set some default variables. */
+ $role = $_REQUEST['role'];
+ $view = $_REQUEST['view'];
+
+ /* Load the edit role form. */
+ require_once( 'view-stats.php' );
+}
+
+else {
+
+
+/* Get the global $members variable. */
+global $members, $wp_roles;
+
+/* Current user in the admin. */
+$user = new WP_User( $members->current_user->ID );
+
+/* Set the available roles array.*/
+$avail_roles = array();
+
+/* Get all the users of the current blog. */
+$users_of_blog = get_users_of_blog();
+
+/* Loop through each user. */
+foreach ( (array) $users_of_blog as $blog_user ) {
+
+ $meta_values = unserialize( $blog_user->meta_value );
+
+ foreach ( ( array) $meta_values as $role => $value ) {
+
+ if ( !isset( $avail_roles[$role] ) )
+ $avail_roles[$role] = 0;
+
+ ++$avail_roles[$role];
+ }
+}
+
+/* Destroy the $users_of_blog variable. */
+unset( $users_of_blog );
+
+/* Sort out the roles, active roles, and inactive roles. */
+$all_roles = $active_roles = $inactive_roles = 0;
+
+/* Loop through all of the roles, adding each role to its respective category (active, inactive). */
+foreach ( $wp_roles->role_names as $role => $name ) {
+ $all_roles++;
+ if ( isset($avail_roles[$role]) ) {
+ $active_roles++;
+ $active_roles_arr[$role] = $name;
+ }
+ else {
+ $inactive_roles++;
+ $inactive_roles_arr[$role] = $name;
+ }
+}
+
+$roles_loop_array = $wp_roles->role_names;
+
+/* Sort the roles array into alphabetical order. */
+ksort( $roles_loop_array ); ?>
+
+<div class="wrap">
+
+ <h2><?php _e( 'Statistics', 'members' ); ?></h2>
+
+ <?php do_action( 'members_pre_stats_form' ); // Available action hook for displaying messages. ?>
+
+ <div id="poststuff">
+
+ <form id="roles" action="<?php echo admin_url( 'users.php?page=stats' ); ?>" method="post">
+
+ <?php wp_nonce_field( members_get_nonce( 'view-stats' ) ); ?>
+
+ <table class="widefat fixed" cellspacing="0">
+ <thead>
+ <tr>
+ <th class='name-column'><?php _e( 'Role', 'members' ); ?></th>
+ <th><?php _e( 'Users', 'members' ); ?></th>
+ <th><?php _e( 'Stats', 'members' ); ?></th>
+ </tr>
+ </thead>
+
+ <tfoot>
+ <tr>
+ <th class='name-column'><?php _e( 'Role', 'members' ); ?></th>
+ <th><?php _e( 'Users', 'members' ); ?></th>
+ <th><?php _e( 'Stats', 'members' ); ?></th>
+ </tr>
+ </tfoot>
+
+ <tbody id="users" class="list:user user-list plugins">
+
+ <?php foreach ( $roles_loop_array as $role => $name ) { ?>
+
+ <?php $name = str_replace( '|User role', '', $name ); ?>
+
+ <tr valign="top" class="<?php if ( isset($avail_roles[$role]) ) echo 'active'; else echo 'inactive'; ?>">
+
+ <td class='plugin-title'>
+ <?php $view_link = admin_url( wp_nonce_url( "users.php?page=stats&amp;role={$role}&amp;view=month", members_get_nonce( 'view-stats' ) ) ); ?>
+
+ <a href="<?php echo $view_link; ?>" title="<?php printf( __( 'View stats for the %1$s role', 'members' ), $name ); ?>"><strong><?php echo $name; ?></strong></a>
+
+ <div class="row-actions">
+ <a href="<?php echo $view_link; ?>" title="<?php printf( __( 'View stats for the %1$s role', 'members' ), $name ); ?>"><?php _e( 'Stats', 'members' ); ?></a>
+
+ <?php
+ /* If there are users, provide a link to the users page of that role. */
+ if ( isset($avail_roles[$role]) ) { ?>
+ | <a href="<?php echo admin_url( esc_url( "users.php?role={$role}" ) ); ?>" title="<?php printf( __( 'View all users with the %1$s role', 'members' ), $name ); ?>"><?php _e( 'View Users', 'members' ); ?></a>
+ <?php } ?>
+
+ </div><!-- .row-actions -->
+
+ </td><!-- .plugin-title -->
+
+ <td class='desc'>
+ <p><?php /* Check if any users are assigned to the role. If so, display a link to the role's users page. */
+ if ( isset($avail_roles[$role]) && 1 < $avail_roles[$role] )
+ echo '<a href="' . admin_url( esc_url( "users.php?role={$role}" ) ) . '" title="' . sprintf( __( 'View all users with the %1$s role', 'members' ), $name ) . '">' . sprintf( __( '%1$s Users', 'members' ), $avail_roles[$role] ) . '</a>';
+ elseif ( isset($avail_roles[$role]) && 1 == $avail_roles[$role] )
+ echo '<a href="' . admin_url( esc_url( "users.php?role={$role}" ) ) . '" title="' . sprintf( __( 'View all users with the %1$s role', 'members' ), $name ) . '">' . __( '1 User', 'members' ) . '</a>';
+ else
+ echo '<em>' . __( 'No users have this role.', 'members' ) . '</em>';
+ ?></p>
+ </td><!-- .desc -->
+
+ <td class='desc'>
+ <p>
+ <a href="#" title="<?php printf( __( 'View the yearly stats for the %1$s role', 'members' ), $name ); ?>"><?php _e( 'Yearly', 'members' ); ?></a> |
+ <a href="#" title="<?php printf( __( 'View the monthly stats for the %1$s role', 'members' ), $name ); ?>"><?php _e( 'Monthly', 'members' ); ?></a> |
+ <a href="#" title="<?php printf( __( 'View the daily stats for the %1$s role', 'members' ), $name ); ?>"><?php _e( 'Daily', 'members' ); ?></a>
+ </p>
+ </td><!-- .desc -->
+
+ </tr><!-- .active .inactive -->
+
+ <?php } // End foreach ?>
+
+ </tbody><!-- #users .list:user .user-list .plugins -->
+
+ </table><!-- .widefat .fixed -->
+
+ </form><!-- #roles -->
+
+ </div><!-- #poststuff -->
+
+</div><!-- .wrap -->
+
+<?php } ?>
77 components/statistics/view-stats.php
@@ -0,0 +1,77 @@
+<?php
+
+
+$stats = get_option( 'members_statistics' );
+
+$stats_view = $stats[$role];
+
+$overall = array();
+
+foreach ( $stats_view as $user ) {
+ //$together = $user['date'];
+
+ $together = $user['year'] . $user['month'];
+//echo $together;
+
+ ++$overall[$together];
+}
+
+ksort( $overall ); ?>
+
+<div class="wrap">
+
+ <h2><?php _e( 'Statistics', 'members' ); ?></h2>
+
+ <?php //do_action( 'members_pre_stats_form' ); // Available action hook for displaying messages. ?>
+
+ <div id="poststuff">
+
+ <?php //wp_nonce_field( members_get_nonce( 'view-stats' ) ); ?>
+
+ <table class="widefat fixed" cellspacing="0">
+ <thead>
+ <tr>
+ <th class='name-column'><?php _e( 'Date', 'members' ); ?></th>
+ <th><?php _e( 'Users', 'members' ); ?></th>
+ </tr>
+ </thead>
+
+ <tfoot>
+ <tr>
+ <th class='name-column'><?php _e( 'Date', 'members' ); ?></th>
+ <th><?php _e( 'Users', 'members' ); ?></th>
+ </tr>
+ </tfoot>
+
+ <tbody id="users" class="list:user user-list plugins">
+
+
+<?php foreach ( $overall as $month => $num ) {
+
+ $date = $month;
+
+ //$date = str_split( $month, 4 ); ?>
+ <tr>
+ <td><?php echo mysql2date( 'F', $date ) . ' ' . mysql2date( 'Y', $date ); ?></td>
+ <td><?php echo $num; ?>
+ </tr>
+
+<?php
+} ?>
+ </tbody>
+ </table>
+ </div>
+</div><?php
+
+
+
+
+
+
+
+
+
+
+
+
+?>
88 components/template-tags/template-tags.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * The Template Tags component is for adding functions that could be useful within the
+ * template files of a WordPress theme.
+ *
+ * @todo Add members_count_users( $role = '' )
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+/**
+ * Use to put an author box at the end/beginning of a post. This template
+ * tag should be used within The Loop.
+ *
+ * @since 0.1
+ * @uses get_avatar() Gets the current author's avatar.
+ * @uses get_the_author_meta() Grabs information about the author.
+ */
+function members_author_profile() { ?>
+ <div class="author-profile vcard">
+ <?php echo get_avatar( get_the_author_meta( 'user_email' ), '100', '', get_the_author_meta( 'display_name' ) ); ?>
+ <h4 class="author-name fn n"><?php the_author_posts_link(); ?></h4>
+ <p class="author-description author-bio">
+ <?php the_author_meta( 'description' ); ?>
+ </p>
+ </div>
+<?php
+}
+
+if ( !function_exists( 'has_role' ) ) {
+
+ /**
+ * Checks if a given ID of a user has a specific role.
+ *
+ * @since 0.1
+ * @uses WP_User() Gets a user object based on an ID.
+ * @param $role string Role to check for against the user.
+ * @param $user_id int The ID of the user to check.
+ * @return true|false bool Whether the user has the role.
+ */
+ function has_role( $role = '', $user_id = '' ) {
+
+ /* If no role or user ID was added, return false. */
+ if ( !$role || !$user_id )
+ return false;
+
+ /* Make sure the ID is an integer. */
+ $user_id = (int)$user_id;
+
+ /* Get the user object. */
+ $user = new WP_User( $user_id );
+
+ /* If the user has the role, return true. */
+ if ( $user->has_cap( $role ) )
+ return true;
+
+ /* Return false if the user doesn't have the role. */
+ return false;
+ }
+}
+
+if ( !function_exists( 'current_user_has_role' ) ) {
+
+ /**
+ * Checks if the currently logged-in user has a specific role.
+ *
+ * @since 0.1
+ * @uses current_user_can() Checks whether the user has the given role.
+ * @param $role string The role to check for.
+ * @return true|false bool Whether the user has the role.
+ */
+ function current_user_has_role( $role = '' ) {
+
+ /* If no role was input, return false. */
+ if ( !$role )
+ return false;
+
+ /* If the current user has the role, return true. */
+ if ( current_user_can( $role ) )
+ return true;
+
+ /* If the current user doesn't have the role, return false. */
+ return false;
+ }
+}
+
+?>
174 components/widgets/login.php
@@ -0,0 +1,174 @@
+<?php
+/**
+ * Creates a widget that allows users to add a login form to a widget area.
+ *
+ * @package Members
+ * @subpackage Components
+ */
+
+class Members_Widget_Login extends WP_Widget {
+
+ function Members_Widget_Login() {
+ $widget_ops = array( 'classname' => 'login', 'description' => __('A widget that allows users to log into your site.', 'widgets-reloaded') );
+ $control_ops = array( 'width' => 700, 'height' => 350, 'id_base' => 'members-widget-login' );
+ $this->WP_Widget( 'members-widget-login', __('Login Form', 'widgets-reloaded'), $widget_ops, $control_ops );
+ }
+
+ function widget( $args, $instance ) {
+ global $user_identity, $user_ID;
+
+ extract( $args );
+
+ $title = apply_filters( 'widget_title', $instance['title'] );
+
+ $username_label = $instance['username_label'];
+ $password_label = $instance['password_label'];
+ $submit_text = $instance['submit_text'];
+ $remember_text = $instance['remember_text'];
+
+ $logged_in_text = apply_filters( 'widget_text', $instance['logged_in_text'] );
+ $logged_out_text = apply_filters( 'widget_text', $instance['logged_out_text'] );
+
+ $show_avatar = isset( $instance['show_avatar'] ) ? $instance['show_avatar'] : false;
+
+ echo $before_widget;
+
+ if ( $title )
+ echo "\n\t\t\t" . $before_title . $title . $after_title;
+
+ if ( is_user_logged_in() ) {
+
+ if ( $show_avatar )
+ echo get_avatar( $user_ID );
+
+ if ( $logged_in_text )
+ echo $logged_in_text;
+
+ }
+ else {
+ if ( $show_avatar )
+ echo get_avatar( $user_ID );
+
+ if ( $logged_out_text )
+ echo $logged_out_text;
+
+ $login = '<div class="clear log-in login-form">';
+
+ $login .= '<form class="log-in" action="' . get_bloginfo( 'wpurl' ) . '/wp-login.php" method="post">';
+
+ $login .= '<p class="text-input">';
+ $login .= '<label class="text" for="log">' . $username_label . '</label>';
+ $login .= '<input class="field" type="text" name="log" id="log" value="' . esc_attr( $user_login ) . '" size="23" />';
+ $login .= '</p>';
+
+ $login .= '<p class="text-input">';
+ $login .= '<label class="text" for="pwd">' . $password_label . '</label>';
+ $login .= '<input class="field" type="password" name="pwd" id="pwd" size="23" />';
+ $login .= '</p>';
+
+ $login .= '<div class="clear">';
+ $login .= '<input type="submit" name="submit" value="' . $submit_text . '" class="log-in" />';
+ $login .= '<label class="remember"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> ' . $remember_text . '</label>';
+ $login .= '<input type="hidden" name="redirect_to" value="' . $_SERVER['REQUEST_URI'] . '"/>';
+ $login .= '</div>';
+
+ $login .= '</form>';
+
+ $login .= '</div>';
+
+ echo $login;
+ }
+
+ echo $after_widget;
+ }
+