Forum Replies Created

Viewing 15 replies - 16 through 30 (of 214 total)
  • @stellaa

    I’ve updated the code here below.
    I’ve wrapped the “Admin” word in <span>-tags with a class – you should be able to play around with that.

    <?php

    /** Add User Role to Comments. */
    if ( ! class_exists( 'Comment_Author_Role_Label' ) ) :
    class Comment_Author_Role_Label {

    public function __construct() {
    add_filter( 'get_comment_author', array( $this, 'get_comment_author_role' ), 10, 3 );
    add_filter( 'get_comment_author_link', array( $this, 'comment_author_role' ) );
    }

    function get_comment_author_role($author, $comment_id, $comment) {
    $authoremail = get_comment_author_email( $comment );

    if (email_exists($authoremail)) {
    $comment_user = get_user_by( 'email', $authoremail );
    $comment_user_role = $comment_user->roles[0];

    switch ($comment_user_role) {
    case 'administrator':
    $this->comment_user_role = ' <span class="comment-admin">Admin</span>';
    break;
    default:
    $this->comment_user_role = ' ' . ucfirst($comment_user_role);
    break;
    }
    } else {
    $this->comment_user_role = '';
    }

    return $author;
    }

    function comment_author_role($author) {
    return $author .= $this->comment_user_role;
    }

    }

    new Comment_Author_Role_Label;
    endif;
    Forum: Fixing WordPress
    In reply to: Can’t edit pages

    @freddyeee

    Wow! That’s a lot of errors!
    Have you updated all your plugins, themes and WP Core?

    @stellaa

    I would suggest you look into some CSS.
    If the label does not have a CSS-class, you can add it in the code above.
    But from what I can see in the screenshot, you should have a different class, based on userroles.

    /A

    Forum: Fixing WordPress
    In reply to: Can’t edit pages

    Hi @freddyeee

    If you check your console in the inspector tools, do you see any JS errors here?
    This could help identify the problem.

    /A

    Hi @ruslanbay

    Looking at their GitHub, they’re aware of this problem.
    You can read more about the issue here

    Long story short, they recommend you to update Carbon Fields to the newest version.

    /A

    Hi @herifa

    Just following up on this thread – did you manage to resolve the issue?

    /A

    Thread Starter kuckovic

    (@kuckovic)

    Thanks a lot, Justin ??

    Hi @stellaa

    I assume you want to change “Administrator” to something else – and not the name “peter”.
    In the code you’ve provided, it fetches the userrole here:

    $comment_user_role = $commet_user_role->roles[0];

    And then it sets the first letter to capital here (ucfirst):

    $this->comment_user_role = ' ' . ucfirst($comment_user_role) . '';

    If you want to change the administrator role so something else – let’s say you would like it to say “Admin” instead – then I would change the code to look something like this:

    /** Add User Role to Comments. */
    if ( ! class_exists( 'Comment_Author_Role_Label' ) ) :
    class Comment_Author_Role_Label {

    public function __construct() {
    add_filter( 'get_comment_author', array( $this, 'get_comment_author_role' ), 10, 3 );
    add_filter( 'get_comment_author_link', array( $this, 'comment_author_role' ) );
    }

    function get_comment_author_role($author, $comment_id, $comment) {
    $authoremail = get_comment_author_email( $comment );

    if (email_exists($authoremail)) {
    $comment_user = get_user_by( 'email', $authoremail );
    $comment_user_role = $comment_user->roles[0];

    switch ($comment_user_role) {
    case 'administrator':
    $this->comment_user_role = ' Admin';
    break;
    default:
    $this->comment_user_role = ' ' . ucfirst($comment_user_role);
    break;
    }
    } else {
    $this->comment_user_role = '';
    }

    return $author;
    }

    function comment_author_role($author) {
    return $author .= $this->comment_user_role;
    }

    }

    new Comment_Author_Role_Label;
    endif;

    Please note, I’m checking if the user is an “administrator”, before changing the name to “Admin” – you should also check for “Editor”, “Author”, “Contributor” and “Subscriber”. If you ONLY want to apply a custom label for the “administrator” userrole, then you can set the “default” (in the switch case) to an empty string, like this:

    default:
    $this->comment_user_role = '';
    break;

    Hope this helps ??

    /A

    • This reply was modified 7 months, 4 weeks ago by kuckovic. Reason: Corrected copy/pasted part of code

    Hi @juanwp22

    Well – it might be one of 2 possible problems.
    Do you have WP Rocket installed? If so, it might be the issue, since they’ve had som problems with the plugin exhausting the CPU (huge talk in their Facebook group about this) – here’s a link, where they provide some troubleshooting on this. I think this has been patched though – but if you’re running an older version, the issue might still be there.

    The other thing – which I personally think is causing the issue, is Cloudways.
    I don’t have anything against them personally – I’ve never used them TBH – but I’ve read SO MANY posts on CPU issues with Cloudways. Here’s a thread on the exact same issue as you’re experiencing. Again, I’m not familiar with Cloudways myself – but I’m active in a lot of WordPress groups on Facebook – and they’ve been bashed quite a lot by people experiencing issues with high CPU usage.

    Hope this clears it a bit.

    Best regards
    Aris

    kuckovic

    (@kuckovic)

    @candell

    Glad it’s working ??
    Good luck with the project.

    /A

    kuckovic

    (@kuckovic)

    Hi @robbiemendez

    Yes, that clarifies it a lot.
    Looks like you’ve exhausted all memory on your hosting plan.
    You can do something yourself – please have a look at this article – but if your not familiar with coding – or just don’t feel safe about editing files yourself, please reach out to your hostingprovider, and let them know what the error is.

    You can actually just copy/paste the error message in the support-ticket – and they can tell you what options you have. Most often, this error occurs if you’re using a cheap hostingprovider – or maybe the hosting-package is “too small”, and you’ll need to upgrade in order to avoid this error again.

    From what I can see, you should reach out to Mijndomein.nl(?)
    I hope they can help you with the error – it’s an annoying one.

    /A

    kuckovic

    (@kuckovic)

    @robbiemendez

    I would assume it’s in the controlpanel wherever you’re hosting your website.
    Alternatively you can have a look at the WP Debugging plugin – when you install and activate the plugin, you should be able to see a more detailed error when navigationg to the “Customize” page.

    kuckovic

    (@kuckovic)

    Hi @candell

    I would start by creating a function, that retrieves all the users, who has a published post within your custom post type. Now, I don’t know what your CPT is called, so I’ve filled it out with “YOUR_CPT” in the code below:

    function get_users_with_published_posts() {
    $args = array(
    'post_type' => 'YOUR_CPT',
    'post_status' => 'publish', // Only get the posts with "published" status
    'numberposts' => -1,
    );

    $posts = get_posts($args);
    $users_with_published_posts = array();

    foreach ($posts as $post) {
    $user_id = $post->post_author;
    $user = get_userdata($user_id);

    if (in_array('authority', $user->roles)) { // I assume "authority" is your userrole
    $users_with_published_posts[$user_id] = $user->display_name;
    }
    }

    return $users_with_published_posts;
    }

    Please make sure the function name is unique – I’ve just added something for the sake of providing some code. Now, in order to show the authors, you can use the function above like this:

    $users = get_users_with_published_posts();
    foreach ($users as $user_id => $display_name) {
    echo $display_name . '<br>';
    }

    The code above only gives you an user-id and “display_name” – if you need any other info, you should put it in the “$users_with_published_posts”-array. I haven’t tested the code above – it’s just “on the fly” – so naming is also a bit fluffy. Please adjust for your needs.

    Best regards
    Aris

    kuckovic

    (@kuckovic)

    Hi @robbiemendez

    Do you have any error-logs yuo can access? It might be in the host controlpanel.
    The error on the customize page is caused by something – and first step might be to fix that – and hopefully you can recover your old colors.

    kuckovic

    (@kuckovic)

    @ungowp

    Ah I see – then i’m not sure how you should approach this.
    I can only think of “Search and replace” – but that requires you knowing the exact URL match (or at least parts of it). I would highly recommend testing this on a local or staging-environment.

    Manually, it might take some time, yes ??

Viewing 15 replies - 16 through 30 (of 214 total)