Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
174 views
in Plugins by

Hi all,

I followd the suggestion in that question

how-to-disable-the-viewing-of-user-profiles

to show user profiles to registered users only.

I'm on 1.8.5 and it seem that the plugin is not fully functional (any more?).

I allready put an issue on github but wanted to place the question here too.

What is working:

  • The navigaion entry "users" is hidden as desired.
  • User names in questions are shown as "user.hidden" as desired
  • avatars are replaced with none as desired

What ist not working:

  • I can still click on an avatar or view the link when mouse-over -> link is clickable an user page shows up
  • I can manually navigate to ../users/ and the page will show up

I guess the error is in function qa_page_routing(). $l_routing does not (or: no longer?) have entries 'users' or 'user/' so overriting has no effect.

Any idea how to fix that issue?

Thanks!

Q2A version: 1.8.5
by
Comment to my own question: I guess the plugin should overrite qa_controller_routing in qa-include/app/routing.php ???

But I'm net experienced enough to do so. Any hint?
by
> I can still click on an avatar or view the link when mouse-over -> link is clickable an user page shows up

This is unclear. You mentioned the avatar was not showing up.

1. How did you make the avatar not to show?
2. What did you change to show "user.hidden"?

Either the plugin or my answer won't fix those to issues, as they are.

> I can manually navigate to ../users/ and the page will show up

I answered a question that was about letting only Administrators access that page.

3. What user level does "I" have in your sentence above?
by
Thank you very much for your replay!

The avatar that the user selected for himself ist not shown (https://github.com/pedjas/q2a-hide-users-list/blob/a546a6f78b432e96fdf35c5ed16fe0f2eadc016a/users-overrides.php#L64) but the link to the user profile ist still present. From the delivered source:

<span class="qa-q-item-avatar">
<a href="./user/xxxxx" class="qa-avatar-link"><img src="" width="60" height="60" class="qa-avatar-image" alt=""></a>
</span>

where 'xxxx' ist the user name. This link is clickable. The profile will show up.

> 1. How did you make the avatar not to show?
> 2. What did you change to show "user.hidden"?
I installed an activated the plugin ;-)

> 3. What user level does "I" have in your sentence above?

A unregistered user.

I still think that this plugin is not compatible with q2q > 1.8!?

Probably the code here https://github.com/pedjas/q2a-hide-users-list/blob/a546a6f78b432e96fdf35c5ed16fe0f2eadc016a/users-overrides.php#L34 has be changed to work with the new qa_controller_routing.

I'm willing to put some effort in exploring this, but I'm very unexperienced with php.

So any hint ist still very welcome!
by
One step forward. I hacked qa-src/Controllers/User/UserProfile.php around line 72 (function profile($handle)) and added

if (!$loginuserid) {
                   throw new PageNotFoundException();
                }

With that hack user profiles are invisivble for not registered users as I wanted.

How can this be achieved in a plugin?

1 Answer

0 votes
by
selected by
 
Best answer

There are a few things to note.

1. The plugin that is linked in the link you posted in your question is this one: https://github.com/Kuddus95/lock-user-profile. The link you are posting in your comment is this one: https://github.com/pedjas/q2a-hide-users-list. That's why I said the behavior you mentioned in the question can't be achieved with the original plugin.

2. You seem to be using an unreleased version of Q2A. You downloaded the code from the dev branch in the repository. You should use either the master branch or navigate to https://github.com/q2a/question2answer/releases and download the latest one.

Download the right version of Q2A and install it again. Then make all tests again.

3. I believe you will still face one more issue. I'd remove function qa_get_avatar_blob_url() and replace it with the function below:

function qa_get_user_avatar_source($flags, $email, $blobId) {
    return qac_approved_user()
        ? qa_get_user_avatar_source_base($flags, $email, $blobId)
        : null;
}
by
+1
Great. Don't know how I came up with a dev version. Changing to the newest master worked like a charm. The two plugins are literaly nearly identical - I tried them both - sorry for that confusion. And Yes, you are right with the function mentioned above.

Problem solved!
...