Please or Register to create posts and topics.

Ranks on the forum

PreviousPage 2 of 3Next

yeah it only shows admins as moderators and then nothing for anyone else 🙁

I re-coded it for now with:

function my_asgarosforum_after_post_administration($author_id, $author_posts) {
  $user_info = get_userdata($author_id);
if (user_can( $user_info, 'administrator')) {
    echo '<div class="icon-status-admin">'.__('Admin','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  		} else {
    if (user_can( $user_info, 'moderator')) {
    echo '<div class="icon-status-moderator">'.__('Moderator','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  				} else {
  if(user_can( $user_info, 'contributor')) {
  echo '<div class="icon-status-contributor">'.__('Contributor','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  						} else {
  if(user_can( $user_info, 'author')) {
  echo '<div class="icon-status-author">'.__('Author','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  								} else {
  if(user_can( $user_info, 'editor')) {
  echo '<div class="icon-status-editor">'.__('Editor','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';  
  										} else {
    if(user_can( $user_info, 'subscriber')) {
  echo '<div class="icon-status-editor">'.__('N00B','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>'; 
  												
  }
  } 
         } }
      }
    }
  }

 

Quote from Yworld on January 18, 2017, 6:52 am

Add the the rank to the forum:

  1. administrator
  2. moderator
  3. contributor
  4. author
  5. editor

To do this you just have to add this code to your themes functions.php file:

add_action('asgarosforum_after_post_author', 'my_asgarosforum_after_post_administration', 10, 2);
function getUserRoles($id) { 
    $user = new WP_User((int)$id); 
    return implode(' and ', $user->roles); 
}
function my_asgarosforum_after_post_administration($author_id, $author_posts) {
if (getUserRoles($author_id)=='administrator') {
    echo '<div class="icon-status-admin">'.__('Admin','rcl-asgaros').'&nbsp;<i class="fa fa-info-circle"></i></div>';
  } else {
    if (AsgarosForumPermissions::isModerator($author_id)) {
    echo '<div class="icon-status-moderator">'.__('Moderator','rcl-asgaros').'&nbsp;<i class="fa fa-info-circle"></i></div>';
  } else {
  if(getUserRoles($author_id)=='contributor') {
  echo '<div class="icon-status-contributor">'.__('Contributor','rcl-asgaros').'&nbsp;<i class="fa fa-info-circle"></i></div>';
  } else {
  if(getUserRoles($author_id)=='author') {
  echo '<div class="icon-status-author">'.__('Author','rcl-asgaros').'&nbsp;<i class="fa fa-info-circle"></i></div>';
} else {
  if(getUserRoles($author_id)=='editor') {
  echo '<div class="icon-status-editor">'.__('Editor','rcl-asgaros').'&nbsp;<i class="fa fa-info-circle"></i></div>';};	
           }	
         }
      }
    }
  }
  1. add_action('asgarosforum_after_post_author', 'my_asgarosforum_after_post_administration', 10, 2);
  2. function getUserRoles($id) {
  3. $user = new WP_User((int)$id);
  4. return implode(' and ', $user->roles);
  5. }
  6. function my_asgarosforum_after_post_administration($author_id, $author_posts) {
  7. if (getUserRoles($author_id)=='administrator') {
  8. echo '<div class="icon-status-admin">'.__('Admin','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  9. } else {
  10. if (AsgarosForumPermissions::isModerator($author_id)) {
  11. echo '<div class="icon-status-moderator">'.__('Moderator','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  12. } else {
  13. if(getUserRoles($author_id)=='contributor') {
  14. echo '<div class="icon-status-contributor">'.__('Contributor','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  15. } else {
  16. if(getUserRoles($author_id)=='author') {
  17. echo '<div class="icon-status-author">'.__('Author','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  18. } else {
  19. if(getUserRoles($author_id)=='editor') {
  20. echo '<div class="icon-status-editor">'.__('Editor','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';};
  21. }
  22. }
  23. }
  24. }
  25. }
add_action('asgarosforum_after_post_author', 'my_asgarosforum_after_post_administration', 10, 2);
function getUserRoles($id) { 
    $user = new WP_User((int)$id); 
    return implode(' and ', $user->roles); 
}
function my_asgarosforum_after_post_administration($author_id, $author_posts) {
if (getUserRoles($author_id)=='administrator') {
    echo '<div class="icon-status-admin">'.__('Admin','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  } else {
    if (AsgarosForumPermissions::isModerator($author_id)) {
    echo '<div class="icon-status-moderator">'.__('Moderator','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  } else {
  if(getUserRoles($author_id)=='contributor') {
  echo '<div class="icon-status-contributor">'.__('Contributor','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
  } else {
  if(getUserRoles($author_id)=='author') {
  echo '<div class="icon-status-author">'.__('Author','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';
} else {
  if(getUserRoles($author_id)=='editor') {
  echo '<div class="icon-status-editor">'.__('Editor','rcl-asgaros').' <i class="fa fa-info-circle"></i></div>';};	
           }	
         }
      }
    }
  }

Names can be changed  🙂

 

Hi

Where exactly is the file functions.php?

Its in the folder of the actual WordPress theme which you are using.

Example: wp-content/themes/my-theme/functions.php

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Does the functions.php file get overwritten when a theme is updated? If so, all the changes made to it have to be made again?

Yes, when you update the theme, all changes to it are gone. So the best way is basically to create an own plugin which consists of one file only where you can place all your stuff.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

The safest is, except for a plugin, ALWAYS a direct backup of the changed files, by date, on an external hdd, something can always happen, logically, also, depending on the amount of data, always an incremental backup.

Quote from Asgaros on November 3, 2017, 5:00 pm

Yes, when you update the theme, all changes to it are gone. So the best way is basically to create an own plugin which consists of one file only where you can place all your stuff.

What if you save the code and when you update, upload the saved copy after you have updated it?

Hello @karmarpgs

If you update a theme and made changes to its functions.php file before, you should make a backup before and apply your changes again after it.

As an alternative you could create your own plugin-file and add your code there - but this is a little bit advanced for most of the users.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Thank you.

Karma.

PreviousPage 2 of 3Next