Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add filter to customize which subscription options will be displayed #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JuliaNeumann
Copy link

Thanks for another great buddypress plugin!! This is a suggestion to make it possible to control which of the different subscription options will be displayed with a filter. I found this to be a request at the site I'm working on, as we only have very similar groups with very similar requirements, and wanted to keep the interface for the users as small and simple as possible, so we wanted to limit down the subscription options to only "None" or "All". I think this feature might probably benefit others as well.

I'm quite new to WP plugin development, so if this is not the correct approach or I made some mistakes here, I'd be happy to improve it :)

@boonebgorges
Copy link
Owner

Hi @JuliaNeumann - Thanks for the PR!

This is a great feature request, though I have two concerns: one about the specifics of the PR, and one about the more general architecture of the plugin.

First: A few suggestions for making the suggestion more "WordPress-y" in format. Let's introduce a new function that can be used to fetch the list of subscription settings, a function that will return an associative array containing information about the settings. Something like:

function bp_ges_get_subscription_levels() {
    $defaults = array(
        'supersub' => array(
            'label' => __( 'All Email', 'bp-ass' ),
            'label_long' => __( 'All Email (send emails about everything - recommended only for working groups)', 'bp-ass' ),
            'description' => __( 'Send all group activity as it arrives', 'bp-ass' ),
        ),
        // etc
    );

    return apply_filters( 'bp_ges_get_subscription_levels', $defaults );
}

This is closer to the convention used elsewhere in the WordPress world for this sort of thing, and has a couple of advantages. First, it gives us some infrastructure for introducing more properties of subscription levels in the future. Second, it lets us use foreach loops when building markup etc, rather than referencing an "on/off" function like you've suggested in your PR. Third, it allows plugin devs to add settings, in addition to removing/modifying existing ones.

More generally, this change will require a closer look through much of the plugin logic to ensure that there are appropriate filters in all of the send/subscribe functions. Right now, many of the "level" checks are hardcoded. See eg

. In order to make the new filter genuinely useful - especially for adding new levels - there needs to be new do_action() and apply_filters() calls that will allow plugins to register custom actions for their new levels. (In the linked example, this might mean a default clause at the end of the switch statement: )

If you'd like to have a closer look at this, I'd strongly suggest you start with the 3.9.x branch, which will become the next major release. https://github.com/boonebgorges/buddypress-group-email-subscription/tree/3.9.x This branch contains an overhaul of much of the logic for both the subscription process and the email/digest sending process, and it's likely that some of the new actions/filters I've described above would be affected by these upcoming changes.

If this is all a bit much (I know you said you're new to the WP development world!), you might start with a bit of refactoring along the lines of my first set of suggestions, and push them to your PR branch; I can then take a closer look and make suggestions about the second half of my comments.

Thanks again for your interest and contributions!

@JuliaNeumann
Copy link
Author

Thanks a lot for the valuable feedback, @boonebgorges!! Looks like a good opportunity for me to get better acquainted with WP plugin development, so I'll try to follow up on your suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants