/**
 * Registers widgets for the plugin.
 *
 * @since  0.2.0
 * @access public
 * @return void
 */
function members_register_widgets()
{
    // If the login form widget is enabled.
    if (members_login_widget_enabled()) {
        require_once members_plugin()->inc_dir . 'class-widget-login.php';
        register_widget('Members_Widget_Login');
    }
    // If the users widget is enabled.
    if (members_users_widget_enabled()) {
        require_once members_plugin()->inc_dir . 'class-widget-users.php';
        register_widget('Members_Widget_users');
    }
}
Ejemplo n.º 2
0
/**
 * Counts the number of users for all roles on the site and returns this as an array.  If
 * the `$role` parameter is given, the return value will be the count just for that particular role.
 *
 * @since  0.2.0
 * @access public
 * @param  string     $role
 * @return int|array
 */
function members_get_role_user_count($role = '')
{
    // If the count is not already set for all roles, let's get it.
    if (empty(members_plugin()->role_user_count)) {
        // Count users.
        $user_count = count_users();
        // Loop through the user count by role to get a count of the users with each role.
        foreach ($user_count['avail_roles'] as $_role => $count) {
            members_plugin()->role_user_count[$_role] = $count;
        }
    }
    // Return the role count.
    if ($role) {
        return isset(members_plugin()->role_user_count[$role]) ? members_plugin()->role_user_count[$role] : 0;
    }
    // If the `$role` parameter wasn't passed into this function, return the array of user counts.
    return members_plugin()->role_user_count;
}
Ejemplo n.º 3
0
    /**
     * Displays the page content.
     *
     * @since  1.0.0
     * @access public
     * @return void
     */
    public function page()
    {
        require_once members_plugin()->admin_dir . 'class-role-list-table.php';
        ?>

		<div class="wrap">

			<h1>
				<?php 
        esc_html_e('Roles', 'members');
        ?>

				<?php 
        if (current_user_can('create_roles')) {
            ?>
					<a href="<?php 
            echo esc_url(members_get_new_role_url());
            ?>
" class="page-title-action"><?php 
            esc_html_e('Add New', 'members');
            ?>
</a>
				<?php 
        }
        ?>
			</h1>

			<?php 
        settings_errors('members_roles');
        ?>

			<div id="poststuff">

				<form id="roles" action="<?php 
        echo esc_url(members_get_edit_roles_url());
        ?>
" method="post">

					<?php 
        $table = new Members_Role_List_Table();
        ?>
					<?php 
        $table->prepare_items();
        ?>
					<?php 
        $table->display();
        ?>

				</form><!-- #roles -->

			</div><!-- #poststuff -->

		</div><!-- .wrap -->
	<?php 
    }
Ejemplo n.º 4
0
/**
 * Registers custom plugin scripts.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function members_admin_register_styles()
{
    $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
    wp_register_style('members-admin', members_plugin()->css_uri . "admin{$min}.css");
}
Ejemplo n.º 5
0
        $role = get_role('administrator');
        // If the administrator role exists, add required capabilities for the plugin.
        if (!empty($role)) {
            $role->add_cap('list_roles');
            // View roles in backend.
            $role->add_cap('create_roles');
            // Create new roles.
            $role->add_cap('delete_roles');
            // Delete existing roles.
            $role->add_cap('edit_roles');
            // Edit existing roles/caps.
            $role->add_cap('restrict_content');
            // Edit per-post content permissions.
        }
    }
}
/**
 * Gets the instance of the `Members_Plugin` class.  This function is useful for quickly grabbing data
 * used throughout the plugin.
 *
 * @since  1.0.0
 * @access public
 * @return object
 */
function members_plugin()
{
    return Members_Plugin::get_instance();
}
// Let's roll!
members_plugin();
/**
 * Disables the comments template if a user doesn't have permission to view the post the
 * comments are associated with.
 *
 * @since  0.1.0
 * @param  string  $template
 * @return string
 */
function members_content_permissions_comments($template)
{
    // Check if the current user has permission to view the comments' post.
    if (!members_can_current_user_view_post(get_the_ID())) {
        // Look for a 'comments-no-access.php' template in the parent and child theme.
        $has_template = locate_template(array('comments-no-access.php'));
        // If the template was found, use it.  Otherwise, fall back to the Members comments.php template.
        $template = $has_template ? $has_template : members_plugin()->templates_dir . 'comments.php';
        // Allow devs to overwrite the comments template.
        $template = apply_filters('members_comments_template', $template);
    }
    // Return the comments template filename.
    return $template;
}