'edit_roles', 'label' => __('Edit Roles', 'members'), 'callback' => 'members_component_edit_roles', 'requires' => false, 'description' => __('The Edit Roles 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 edit_roles 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 New Roles component allows you to create new roles on your site. To use this component, you must have the create_roles 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 restrict_content 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' => '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 ( $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. * @todo Add the activated state to the $members_components variable instead of making * a completely new global variable with $members_components_active. * * @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; if ( !$component ) return false; if ( !is_array( $members->active_components ) ) $members->active_components = get_option( 'members_settings' ); return $members->active_components[$component]; } /* Default Components */ /** * Manage roles component. This allows you to manage each role's set * of capabilities. * * @since 0.1 */ function members_component_edit_roles() { if ( is_admin() && is_active_members_component( 'edit_roles' ) ) { require_once( MEMBERS_COMPONENTS . '/edit-roles/default.php' ); add_action( 'admin_menu', 'members_component_load_edit_roles' ); } } /** * New roles component. This allows you to create new roles. * * @since 0.1 */ function members_component_new_roles() { if ( is_admin() && is_active_members_component( 'new_roles' ) ) { require_once( MEMBERS_COMPONENTS . '/new-roles/default.php' ); add_action( 'admin_menu', 'members_component_load_new_roles' ); } } /** * 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' ); add_action( 'admin_menu', 'members_content_permissions_create_meta_box' ); add_action( 'save_post', 'members_content_permissions_save_meta', 1, 2 ); } } /** * 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 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' ); } ?>