HameezExE With some effort, it might be possible to achieve this using JS + CSS, but I wouldn't recommend it. Users can still view profile pages using the developer console.
Comments from a member are fetched on the profile page using an API like "GET /api/posts?filter%5Bauthor%5D=USERNAME&filter%5Btype%5D=comment&page%5Boffset%5D=0&page%5Blimit%5D=20&sort=-createdAt"
. Perhaps if you manage to restrict access to this API for users other than moderators and administrators, you could get closer to what you're looking for. Additionally, in cases where users cannot access the API on profile pages, you could potentially use a function to display a full-screen error message, completely hiding the profile from users who cannot access the API.
This is currently just a theory.
ChatGPT provided a plugin like this. You might want to try it.
Extension (ChatGPT)
- ExtensionΔ±:
your-extension/
βββ js/
β βββ app.js
βββ composer.json
βββ bootstrap.php
composer.json
:
{
"name": "your-username/your-extension",
"type": "flarum-extension",
"require": {
"flarum/core": "^1.0"
},
"autoload": {
"psr-4": {
"Your\\Namespace\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "Your Extension",
"icon": {
"name": "fas fa-lock",
"backgroundColor": "#007bff",
"color": "#ffffff"
}
}
}
}
bootstrap.php
:
<?php
use Flarum\Extend;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\User\User;
return [
(new Extend\Middleware('api'))->add(
new class {
public function handle($request, $next)
{
// API
if ($request->is('api/posts')) {
$username = $request->input('filter.author');
// User
if ($request->user() && ($request->user()->isAdmin() || $request->user()->isModerator() || $request->user()->username === $username)) {
return $next($request);
}
// Error
return response()->json([
'error' => [
'status' => 403,
'title' => 'Forbidden',
'detail' => 'You do not have permission to view this page.'
]
], 403);
}
return $next($request);
}
}
),
];
app.js
:
import app from 'flarum/app';
app.initializers.add('your-username-your-extension', () => {
// AJAX error show
app.store.models.posts.prototype.apiUrl = function () {
return '/api/posts?filter[author]=' + this.attributes.authorId + '&filter[type]=comment&page[offset]=0&page[limit]=20&sort=-createdAt';
};
app.request.get(app.store.models.posts.prototype.apiUrl()).catch((error) => {
if (error.response && error.response.status === 500) {
// Show error
app.alerts.show({ type: 'error' }, 'You do not have permission to view this page.');
}
});
});
I'm sure this code won't work and there are tons of errors. I just wanted to create such a template as an example