/** * Callback function for handling forum role changes. Note that we needed to execute this function * on a different hook, `profile_update`. Using the normal hooks on the edit user screen won't work * because WP will wipe out the role. * * @since 1.0.0 * @access public * @param int $user_id * @return void */ public function role_update($user_id) { /* If the current user can't promote users or edit this particular user, bail. */ if (!current_user_can('promote_users') || !current_user_can('edit_user', $user_id)) { return; } /* Is this a forum role change? */ if (!isset($_POST['mb_forum_role'])) { return; } /* Get keymaster variables. */ $is_keymaster = mb_is_user_keymaster(get_current_user_id()); $keymaster_role = mb_get_keymaster_role(); /* Get role variables. */ $forum_role = mb_get_user_role($user_id); $new_role = sanitize_key($_POST['mb_forum_role']); /* Only keymasters can promote/demote other keymasters. */ if ($is_keymaster && ($keymaster_role === $forum_role || $keymaster_role === $new_role)) { return; } /* If there's a new role and it doesn't match the old one, set it. */ if ($forum_role !== $new_role && !empty($new_role)) { mb_set_user_role($user_id, $new_role); } elseif ($forum_role !== $new_role && empty($new_role)) { mb_remove_user_role($user_id, $new_role); } }
/** * Makes sure the current user has a forum role. * * @since 1.0.0 * @access public * @return void */ function mb_set_current_user_role() { /* If user is not logged in, bail. */ if (!is_user_logged_in()) { return; } /* Get the current user ID. */ $user_id = get_current_user_id(); /* Get the user's forum role. */ $forum_role = mb_get_user_role($user_id); /* If the user already has a forum role, bail. */ if ($forum_role) { return; } /* Set the user forum role. */ mb_add_user_role($user_id); }
mb_get_template_part('loop-reply'); ?> <?php } else { ?> <?php echo get_avatar(mb_get_user_id()); ?> <div class="mb-user-info"> <ul> <li><?php printf(__('Forum role: %s', 'message-board'), mb_get_role_link(mb_get_user_role())); ?> </li> <li><?php printf(__('Forums created: %s', 'message-board'), mb_get_user_forum_count()); ?> </li> <li><?php printf(__('Topics started: %s', 'message-board'), mb_get_user_topic_count()); ?> </li> <li><?php printf(__('Replies posted: %s', 'message-board'), mb_get_user_reply_count()); ?> </li> <li><?php
/** * Callback function for handling post status changes. * * @since 1.0.0 * @access public * @return void */ public function handler() { /* If the current user can't promote users or there are no users, bail. */ if (!current_user_can('promote_users') || empty($_REQUEST['users'])) { return; } /* Is this a forum role change request? */ if (empty($_REQUEST['mb_forum_role']) || empty($_REQUEST['mb_change_role'])) { return; } /* Get the new role. */ $new_role = sanitize_key($_REQUEST['mb_forum_role']); /* Get an array of the allowed forum roles. */ $dynamic_roles = mb_get_dynamic_roles(); /* If the new role isn't one of our forum roles, bail. */ if (!isset($dynamic_roles[$new_role])) { return; } /* Get some variables we need. */ $current_user_id = get_current_user_id(); $keymaster_role = mb_get_keymaster_role(); $is_keymaster = mb_is_user_keymaster($current_user_id); /* Only keymasters can make new keymasters. */ if ($keymaster_role === $new_role && false === $is_keymaster) { return; } /* Loop through each user and change their forum role. */ foreach ((array) $_REQUEST['users'] as $user_id) { /* You can't go changing your own role, silly! */ if ($current_user_id === $user_id) { continue; } /* Get the user's current forum role. */ $forum_role = mb_get_user_role($user_id); /* Only keymasters can demote other keymasters. */ if (false === $is_keymaster && $keymaster_role === $forum_role) { continue; } /* If the new role doesn't match the user's current role, let's set it. */ if ($new_role !== $forum_role) { mb_set_user_role($user_id, $new_role); } } /* Remove some query args and build the redirect URL. */ $url = remove_query_arg(array('s', 'action', 'new_role', 'mb_forum_role', 'mb_change_role', 'action2', 'users')); /* Redirect back to the users screen. */ wp_safe_redirect($url); }
<tr> <td class="mb-col-title"> <?php echo get_avatar(mb_get_user_id()); ?> <?php mb_user_link(); ?> <div class="mb-user-description"> <?php the_author_meta('description', mb_get_user_id()); ?> </div><!-- .mb-user-description --> </td> <td class="mb-col-role"><?php mb_role_link(mb_get_user_role()); ?> </td> <td class="mb-col-count"><a href="<?php mb_user_topics_url(); ?> "><?php mb_user_topic_count(); ?> </a></td> <td class="mb-col-count"><a href="<?php mb_user_replies_url(); ?> "><?php mb_user_reply_count(); ?>
</a> </header> <div class="mb-author-box"> <?php echo get_avatar(mb_get_reply_author_id()); ?> <div class="mb-author-info"> <?php mb_reply_author_link(); ?> <br /> <?php mb_role_link(mb_get_user_role(mb_get_reply_author_id())); ?> <?php if (get_the_author_meta('url')) { ?> <br /> <a href="<?php echo esc_url(get_the_author_meta('url'), mb_get_reply_author_id()); ?> "><?php _e('Web Site', 'message-board'); ?> </a> <?php } ?>
</a> </header> <div class="mb-author-box"> <?php echo get_avatar(mb_get_topic_author_id()); ?> <div class="mb-author-info"> <?php mb_topic_author_profile_link(); ?> <br /> <?php mb_role_link(mb_get_user_role(mb_get_topic_author_id())); ?> <?php if (get_the_author_meta('url')) { ?> <br /> <a href="<?php echo esc_url(get_the_author_meta('url'), mb_get_topic_author_id()); ?> "><?php _e('Web Site', 'message-board'); ?> </a> <?php } ?>