• Resolved islp

    (@islp)


    Hello, I’m using a simple plugin for web push notifications.

    Just like any other plugin, it asks the user consent before starting sending notifications.

    Problem is I want to display this popup only to registered users, not ANY user of my website (so, my idea is on the first login the popup is displayed).

    The plugin lacks such functionality.

    Is it possible, eg. using a filter, to make the plugin work only for registered users?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    what plugin? Have you asked the author(s)?

    Thread Starter islp

    (@islp)

    @sterndata

    This, and unfortunately they hadn’t the time to answer questions in months.

    But, generally speaking, if this is possible with this plugin I suppose it is possible with any plugin, so the question can even be more generic: eg. can I pevent non-registered users to load plugins?

    I thought I could check if user is logged in before running the plugin but I wanted to do this without altering the code of the plugin itself.

    • This reply was modified 1 year, 3 months ago by islp.
    • This reply was modified 1 year, 3 months ago by islp.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    You’ll need to see if the plugin has a hook that enables/disables it and write some code in a private plugin (or functions.php of your child theme) to use it.

    Thread Starter islp

    (@islp)

    It has both (activation and disactivation) hooks. But how should I code it? That is, I can create a plugin, but what should I code in my plugin?

    My initial idea was to check if user is logged in and only in that case execute the plugin initialization (!= activation), but I don’t know if this eventually works.

    • This reply was modified 1 year, 3 months ago by islp.

    So first to your question:
    Plugins, once activated, will run for everyone. You can’t restrict that either. It would therefore be important for your request that the plugin developer provides a filter for your request. Unfortunately, looking at the source code, I found only one filter and it won’t help you. The developer also has quite detailed documentation on github: https://github.com/perfectyorg/perfecty-push-wp

    And here for the plugin: https://docs.perfecty.org

    I just had an idea: the question in the frontend is controlled via JavaScript, which is integrated into wp_head with an action hook. The one here: https://github.com/perfectyorg/perfecty-push-wp/blob/master/includes/class-perfecty-push.php#L343 – you could try removing this for users who are not logged in.

    Thread Starter islp

    (@islp)

    Ok, for sure the popup, its logic and maybe a little bell displayed in the front end are managed by JS client code. Are you suggesting not to enqueue the JS code for users that are not logged in?

    That’s exactly what I described above, yes. As a result, users who are not logged in would not see the popup and therefore would not be able to subscribe.

    Thread Starter islp

    (@islp)

    @threadi

    Ok, my first attempt was to directly operate on that github file: I don’t know why, but doing so blocks the entire website (I suspect I can’t use is_user_logged_in in that context, but I’m not sure). Same thing if I try to prevent the plugin from working by editing the init in its main file.

    The thing that seems to work, but I’m still investigating (and I’m a little perplexed), is edit three function bodies from here: https://github.com/perfectyorg/perfecty-push-wp/blob/master/public/class-perfecty-push-public.php

    Another thing I wonder is the following: without directly editing the plugin, isn’t there the possibility to dequeue a script/style from elsewhere, eg. functions.php or a custom private plugin? Would it eventually work?

    • This reply was modified 1 year, 3 months ago by islp.
    • This reply was modified 1 year, 3 months ago by islp.

    I meant the latter. With https://developer.www.ads-software.com/reference/functions/remove_action/ you can remove action filters that were previously set. Without having to adjust the plugin yourself.

    The challenge with the plugin is you this

    $this->loader->add_action( 'wp_head', $plugin_public, 'print_head' );

    would have to disable. They use their own function to set all hooks together and add them to their own loader class beforehand using “add_action”. I haven’t debugged this yet as I don’t have the time for it, but I suspect the actual call is

    add_action( 'wp_head', array( 'Perfecty_Push_Public', 'print_head' ) );

    The challenge is that a class of the plugin is used here that you do not have and have not referenced. So remove_action() doesn’t work that easily.

    There are various tips on the net on how to deal with something like this. For example, look at this: https://wordpress.stackexchange.com/questions/36013/remove-action-or-remove-filter-with-external-classes

    Overall, however, it is very complex. I would question whether you want to go to that expense. If you need help, you can also ask at https://jobs.wordpress.net. Or you wait until the developer answers your question. Or you are looking for another plugin for your wish ..

    Thread Starter islp

    (@islp)

    @threadi I’m a developer myself, even if I don’t do any WP professionally. ?? Anyway, in the meantime I found wp_dequeue_script and wp_dequeue_style and they’re quite promising, solving 80% of the issues. The remaining part, a JS directly printed in the html page, can stay there or can easily be removed.

    I wouldn’t want to change this plugin because it has some advantages (no third party services, etc.)

    • This reply was modified 1 year, 3 months ago by islp.

    Glad you found a way. I was unsure if this one works, that in the template “perfecty-push-public-head.php” a <script>-tag is directly output. You can’t remove that at all via the functions you mentioned.

    If it works for you then, you can still write to their support as an answer so that others who are looking for it can also find it.

    Thread Starter islp

    (@islp)

    @threadi That one is exactly the 20% I can’t remove without editing the plugin itself, but 1. that code doesn’t really matter, 2. it can be removed with basic effort.

    That said, I need something working now, so my idea is to use a bad “patch”, avoid the automatic updates of the plugin and ask for a feature request to the plugin authors.

    • This reply was modified 1 year, 3 months ago by islp.
Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Plugin that works only for registered users’ is closed to new replies.