Custom block plugin for registered logged in users only

Hello,
I have a couple of custom block plugins for a journal.
I want these available to only those who are registered with the journal (I don’t want these custom blocks to be seen by ‘reader’ or any other web visitor).
Any suggestions on how can I achieve that?
Thanks in advance.
Miranda

Hi @miranda,

[EDITED, see below]

In OJS 2.4.6, one way to do want you want to do might be to modify the block.tpl file in plugins/generic/customBlockManager folder. But you will have to keep track of your modifications for future upgrades.

You can change the code to something like this:

{if $isUserLoggedIn && $customBlockId ==‘customblock-nameoftheblock’}

<div class=“block custom” id="{$customBlockId}">
{$customBlockContent}
</div>

{elseif !$isUserLoggedIn && $customBlockId !=‘customblock-nameoftheblock’}

<div class=“block custom” id="{$customBlockId}">
{$customBlockContent}
</div>

{/if}

Just change nameoftheblock with your block’s name.

This is just an idea, because I know it not suits exactly what you want, it’s quite an ugly piece of code and a more stable solution will need more changes on the plugin files. But it seems to work on my local tests.

Regards,
Andy


EDIT :

This solution above wasn’t good enough (blocks visible for not logged users were not displayed for logged users). So I went ahead and modified the original plugin files to include the feature that @miranda asked for.
Here is the stand-alone plugin: GitHub - relaciones-internacionales-journal/customBlockManager: Modified customBlockManager OJS plugin

Just replace your plugin files with these ones. In fact, because there’s not a lot of changes you can also replicate this following this github commit:
https://github.com/pkp/ojs/commit/aa0ce730e7d0e93f4639f8ac4932acf1f5917a3b

Great, now my Github avatar is showed…

Anyway, locale changes are only in english and spanish. Hope it helps,

Andy

2 Likes

Thanks for coding this out. I put a couple of comments on the commit.

Was this pushed directly against pkp/ojs (without a branch) rather than your plugin, or is that just an illusion of github?

1 Like

Thanks @Andy
Will try it out and I am sure it will work for me. Btw, ur avatar looks kewl…
Ciao

Thanks @miranda! I’ve changed the code following @ctgraham comments (thanks a lot!) and pushed it to github. Now you can choose which roles will be allowed to see the block. Just leave the checkboxes empty to make it public for everyone.

Regarding pushing against pkp/ojs repo, I’m a Github noob who uses Github for Windows so I think was pushing against both repos (origin and pkp). I’m sorry for that :smile:! I think this last commit was just pushed against our repo:
https://github.com/relaciones-internacionales-journal/ojs/commit/103e99c2e80b83381cccf8de5e7869de28eda14e

1 Like