Hi OnPoint,
I’m need to hide items in the ASM-menu containing Posts in specific Categories, that the current (logged in) user doesn’t have access through via Member plugin. Similar as required in this post: https://onpointplugins.com/plugin-support/hide-pages-if-user-doesnt/
But instead of Advanced Sidebar Menu PRO – Pages it regards Advanced Sidebar Menu PRO – Categories.
Is this possible?
Thanks in advance!
Best regards,
Fredric
OnPoint Plugins
Hi Fredric,
You may exclude posts from the “Advanced Sidebar – Categories” menus by adding the following custom filters to your active theme’s functions.php file.
Have a great day!
P.S. I’ve added a new
advanced-sidebar-menu-pro/walker/display-posts/children
filter to the Advanced Sidebar Menu PRO plugin which will simplify this type of adjustment in the future. It will be available in the next version (not yet scheduled).Fredric Ollerstam
Dear OnPoint,
I tried the code, but I got an error, see the private info.
//Fredric
OnPoint Plugins
Hi Fredric,
I see what happened. The
Category
class is not inuse
.Here is a version which does not require it.
Fredric Ollerstam
Hi,
Thanks! That worked just fine!
Though, sorry, I have a follow up question.
Is it possible to hide the parent categories if it doesn’t contain any post the users has rights to access?
I’ve tried different settings in the backend without success.
Thanks!
Cheers,
Fredric
OnPoint Plugins
Hi Fredric,
I have updated the above filter to also exclude categories which do not have any posts to display. It is a bit heavy to check for available posts during the display of each category but I did what I could to reuse the results and reduce the number of queries.
I’m guessing a bit on context so here is what the filter will do:
Have a great day!
Fredric Ollerstam
Hi!
Great thanks!!
Though I could see it wouldn’t handle Parents with Parents correctly aka handling the scenario where a parent/parent category has child categories but no accessible posts due to user permissions.
I did some testing myself and with a little help with AI I ended with an adjustment that also hide the Parents with Parents.
I’ve added the adjustment to the private info since it might not be 100% and might generate unwanted loops or excessive recursive calls if used in a different setup. Maybe that could be solved with memoization/caching.
Again, thanks!!
Cheers,
Fredric