Skip to content

Commit

Permalink
Added moderator functionality
Browse files Browse the repository at this point in the history
Added moderator functionality. Moderators can be added via their user
profiles in the user edit screen of the WordPress administration
interface.

References #33.
  • Loading branch information
Asgaros committed Feb 7, 2016
1 parent 09c2d97 commit cf5ff9e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
26 changes: 26 additions & 0 deletions admin/admin.php
Expand Up @@ -20,6 +20,32 @@ function __construct() {
add_action('create_asgarosforum-category', array($this, 'save_category_form_fields'));
add_action('edit_asgarosforum-category', array($this, 'save_category_form_fields'));
add_action('delete_asgarosforum-category', array($this, 'delete_category'), 10, 3);

// Moderator stuff
add_action('edit_user_profile', array($this, 'moderator_profile_fields'));
add_action('edit_user_profile_update', array($this, 'moderator_profile_fields_update'));
}

function moderator_profile_fields($user) {
if (!current_user_can('manage_options')) {
return false;
}

echo '<h3>'.__('Forum', 'asgaros-forum').'</h3>';
echo '<table class="form-table">';
echo '<tr>';
echo '<th><label for="asgarosforum_moderator">'.__('Forum Moderator', 'asgaros-forum').'</label></th>';
echo '<td>';
echo '<input type="checkbox" name="asgarosforum_moderator" id="asgarosforum_moderator" value="1" '.checked(get_the_author_meta('asgarosforum_moderator', $user->ID ), '1', false).' />';
echo '</td></tr></table>';
}

function moderator_profile_fields_update($user_id) {
if (!current_user_can('manage_options')) {
return false;
}

update_usermeta(absint($user_id), 'asgarosforum_moderator', wp_kses_post($_POST['asgarosforum_moderator']));
}

function set_current_menu($parent_file) {
Expand Down
2 changes: 1 addition & 1 deletion admin/views/options.php
Expand Up @@ -25,7 +25,7 @@
</p>
<p>
<input type="checkbox" name="highlight_admin" id="highlight_admin" <?php checked(!empty($asgarosforum->options['highlight_admin'])); ?> />
<label for="highlight_admin"><?php _e('Highlight administrator names', 'asgaros-forum'); ?></label>
<label for="highlight_admin"><?php _e('Highlight administrator/moderator names', 'asgaros-forum'); ?></label>
</p>
<p>
<input type="checkbox" name="show_edit_date" id="show_edit_date" <?php checked(!empty($asgarosforum->options['show_edit_date'])); ?> />
Expand Down
11 changes: 9 additions & 2 deletions includes/forum.php
Expand Up @@ -525,7 +525,14 @@ function get_username($user_id, $wrap = false, $widget = false) {

if ($user) {
$username = ($wrap) ? wordwrap($user->display_name, 22, "-<br/>", true) : $user->display_name;
$username = ($this->options['highlight_admin'] && user_can($user_id, 'manage_options') && !$widget) ? '<span class="highlight-admin">'.$username.'</span>' : $username;

if ($this->options['highlight_admin'] && !$widget) {
if (user_can($user_id, 'manage_options')) {
$username = '<span class="highlight-admin">'.$username.'</span>';
} else if (get_user_meta($user_id, 'asgarosforum_moderator', true) == 1) {
$username = '<span class="highlight-moderator">'.$username.'</span>';
}
}

return $username;
} else {
Expand Down Expand Up @@ -627,7 +634,7 @@ function count_posts_in_forum($forum_id) {
function is_moderator() {
global $user_ID;

if ($user_ID && is_super_admin($user_ID)) {
if ($user_ID && (is_super_admin($user_ID) || get_user_meta($user_ID, 'asgarosforum_moderator', true) == 1)) {
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Expand Up @@ -14,6 +14,7 @@ Asgaros Forum is the perfect WordPress plugin for you if you want to extend your

= Features =
* Topic/post management (Remove/Edit/Close/Sticky/Move)
* Moderators
* Powerful editor
* File uploads
* Recent Forum Posts Widget
Expand All @@ -31,6 +32,7 @@ Asgaros Forum is the perfect WordPress plugin for you if you want to extend your
* Hungarian
* Italian
* Russian
* Spanish

== Installation ==
* Download Asgaros Forum.
Expand All @@ -42,6 +44,8 @@ Asgaros Forum is the perfect WordPress plugin for you if you want to extend your
* Done!

== Frequently Asked Questions ==
= Where can I add moderators? =
Moderators can be added via the user edit screen in the WordPress administration interface.
= I want help to translate Asgaros Forum =
You can help to translate Asgaros Forum on this site:
[https://translate.wordpress.org/projects/wp-plugins/asgaros-forum](https://translate.wordpress.org/projects/wp-plugins/asgaros-forum)
Expand All @@ -55,6 +59,8 @@ You can help to translate Asgaros Forum on this site:
6. Manage general options.

== Changelog ==
* Added: Moderator functionality
* Added: Spanish translation (thanks to QuqurUxcho)
= 1.0.7 =
* Fixed: Prevent the creation of empty content
* Fixed: Hide widget for guests when access is limited to logged in users
Expand Down
3 changes: 3 additions & 0 deletions skin/style.css
Expand Up @@ -23,6 +23,9 @@
#af-wrapper .highlight-admin {
color: #e00000;
}
#af-wrapper .highlight-moderator {
color: #099922;
}

/* EDITOR */
#af-wrapper .editor-row {
Expand Down
1 change: 1 addition & 0 deletions uninstall.php
Expand Up @@ -15,6 +15,7 @@

// Delete user meta data
delete_metadata('user', 0, 'asgarosforum_lastvisit', '', true);
delete_metadata('user', 0, 'asgarosforum_moderator', '', true);

// Delete terms
$terms = $wpdb->get_results('SELECT t.term_id FROM '.$wpdb->terms.' AS t INNER JOIN '.$wpdb->term_taxonomy.' AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = "asgarosforum-category";');
Expand Down

0 comments on commit cf5ff9e

Please sign in to comment.