[Subscribe by Email] Let users select the categories they wish to receive notifications for

I see many threads in the support forum requesting for the user to select the categories he wishes to receive notifications for. Like the description of the plugin says: "Your users can easily unsubscribe from automatic notifications of any post type, or subscribe to a new one, simply by selecting from the list."

I see many of these requests, and I see them for already 5 years.

Any idea when this will come available?

  • James Morris
    • WordPress Enthusiast

    Hello mpress

    I hope you are well today. I’m afraid this feature request still hasn’t quite made it into the roadmap for this plugin at this time. But, what I can do is flag our SLS Team and ask them to take a look and see if there’s anything we can do as a quick workaround for you regarding this issue.

    Best regards,

    James Morris

  • mpress
    • Code Wrangler

    That would be great. This issue has been reported many times by many people for over 5 years.

    When I search the support forum for "subscribe by email categories", all items on the first page are on this issue, as well as a couple on the 2nd page.

    The current options in this respect given to the subscriber on the Subscribers Management Page look silly: they can only check/uncheck posts. That looks like cancellation rather than management of the settings.

    I call it an issue rather than feature request, as the description of the plugin mentions this as one of the (many) good things. But I fail to see how to do it.

    So any help in this respect would be very beneficial, to many people I believe.

  • Ivan
    • Developer

    Hi mpress !

    Usually, we don’t recommend to change any plugin code because you lose all changes after updating this plugin but in this case, there’s no easy workaround there.

    So, first of all, open {wordpress_folder}/wp-content/plugins/subscribe-by-email/inc/classes/class-queue-item.php file via FTP, find get_subscriber_posts function and replace it to the following one

    public function get_subscriber_posts() {
    $subscriber = incsub_sbe_get_subscriber( $this->subscriber_email );

    $settings = incsub_sbe_get_settings();
    $posts = array();
    if ( $subscriber ) {
    $user_terms = get_post_meta( $subscriber->ID, 'subscription_terms', true );
    foreach ( $this->get_queue_item_posts() as $post ) {
    $post_types = $subscriber->subscription_post_types;
    if ( false === $post_types )
    $post_types = $settings['post_types'];

    if ( in_array( $post->post_type, $post_types ) ) {
    $post_type_taxonomies = get_object_taxonomies( $post->post_type );
    $subscr_term = true;
    foreach ( $post_type_taxonomies as $tax ) {
    // $terms = get_terms( $tax, array( "hide_empty" => false, 'fields' => 'ids' ) );
    $post_terms = wp_get_post_terms( $post->ID, $tax, array("fields" => "ids"));
    if ( $user_terms && !empty( $user_terms[ $tax ] ) && is_array( $user_terms[ $tax ] ) && !array_intersect( $post_terms, $user_terms[ $tax ] ) ) {
    $subscr_term = false;
    }
    }
    if ( $subscr_term ) {
    $posts[] = $post;
    }
    }
    }

    }

    return $posts;
    }

    Secondly, open {wordpress_folder}/wp-content/plugins/subscribe-by-email/front/manage-subscription.php file, find set_the_content function and replace to the following one

    public function set_the_content( $content ) {
    $new_content = $content;

    $post_id = get_the_ID();

    if ( ! empty( $this->settings['manage_subs_page'] ) && $this->settings['manage_subs_page'] == $post_id ) {
    $model = Incsub_Subscribe_By_Email_Model::get_instance();
    $settings_handler = Incsub_Subscribe_By_Email_Settings_Handler::get_instance();

    if ( ! isset( $_REQUEST['sub_key'] ) ) {
    ob_start();
    ?>
    <div id="manage_subscription_wrap">
    <h4><?php _e( 'This page will show details of your email subscriptions. To see the options available to you, click the link in any newsletter email you have received from us', INCSUB_SBE_LANG_DOMAIN ); ?></h4>
    </div>
    <?php
    return $new_content . ob_get_clean();
    }

    $key = $_REQUEST['sub_key'];
    $subscriber = incsub_sbe_get_subscriber_by_key ( $key );
    if ( ! $subscriber )
    return $new_content;

    $updated = false;

    if ( ! empty( $_POST['sub_submit'] ) ) {
    $terms = empty( $_POST['terms'] ) || !is_array( $_POST['terms'] ) ? array() : $_POST['terms'];
    update_post_meta( $subscriber->ID, 'subscription_terms', $terms );
    $submitted = empty( $_POST['sub_post_types'] ) ? array() : $_POST['sub_post_types'];
    if ( ! is_array( $submitted ) )
    $submitted = false;

    $subscriber->set_post_types( $submitted );
    $updated = true;
    }

    $user_post_types = $subscriber->subscription_post_types;
    if ( false === $user_post_types ) {
    // If is false, the subscriber is subscribed to everything
    $user_post_types = incsub_sbe_get_subscriptions_post_types();
    }

    $post_types = incsub_sbe_get_subscriptions_post_types();

    $user_terms = get_post_meta( $subscriber->ID, 'subscription_terms', true );
    if ( !isset( $user_terms ) ) {
    $user_terms = null;
    }

    //TEST

    ob_start();
    ?>
    <div id="manage_subscription_wrap">

    <?php if ( $updated ): ?>
    <p class="sbe-saved"><?php _e( 'Settings saved', INCSUB_SBE_LANG_DOMAIN ); ?></p>
    <?php endif; ?>

    <form action="" method="POST">

    <input type="hidden" name="sub_key" value="<?php echo $key; ?>">

    <?php if ( ! empty( $post_types ) ): ?>

    <h3><?php _e( 'Please select which post types you wish to be notified about.', INCSUB_SBE_LANG_DOMAIN ); ?></h3>

    <?php foreach ( $post_types as $post_type ): ?>
    <?php
    $_post_type = get_post_type_object( $post_type );
    if ( ! $_post_type )
    continue;
    ?>

    <div class="post-type-box">
    <label class="sub_post_type_label" for="sub_post_type-<?php echo $post_type; ?>">
    <input type="checkbox" class="sub_post_types" <?php checked( in_array( $post_type, $user_post_types ) ); ?> id="sub_post_type-<?php echo $post_type; ?>" name="sub_post_types[]" value="<?php echo $post_type; ?>">
    <?php echo $_post_type->label; ?>
    </label><br/>
    <?php
    $post_type_taxonomies = get_object_taxonomies( $post_type, 'objects' );
    if ( ! empty( $post_type_taxonomies ) ) {
    foreach ( $post_type_taxonomies as $taxonomy_slug => $taxonomy ) {
    $terms = get_terms( $taxonomy_slug, array( "hide_empty" => false ) );
    if ( 'category' !== $taxonomy_slug ) continue;
    if ( isset( $this->settings['taxonomies'][ $post_type ][ $taxonomy_slug ] )
    && array( 'all' ) !== $this->settings['taxonomies'][ $post_type ][ $taxonomy_slug ] ) {
    $allowed_terms = $this->settings['taxonomies'][ $post_type ][ $taxonomy_slug ];
    } else {
    unset( $allowed_terms );
    }
    ?>
    <?php echo $taxonomy->label; ?>
    <?php if ( $terms ) { ?>
    <?php foreach( $terms as $term ) { ?>
    <?php if ( isset( $allowed_terms ) && !in_array( $term->term_id, $allowed_terms ) ) continue; ?>
    <div class="">
    <label class="sub_post_type_label">
    <input type="checkbox" class="sub_post_types" <?php checked( is_null( $user_terms ) || !isset( $user_terms[ $taxonomy_slug ] ) || in_array( $term->term_id, $user_terms[ $taxonomy_slug ] ) ); ?> name="terms[<?php echo $taxonomy_slug ?>][]" value="<?php echo $term->term_id; ?>">
    <?php echo $term->name; ?>
    </label>
    </div>
    <?php }
    } else {
    echo '<br>';
    }
    }
    }
    ?>
    </div>
    <?php endforeach; ?>

    <?php endif; ?>

    <p><input type="submit" name="sub_submit" value="<?php _e( 'Submit settings', INCSUB_SBE_LANG_DOMAIN ); ?>"></p>

    </form>
    </div>
    <?php
    $new_content .= ob_get_clean();
    }
    return $new_content;
    }

    NOTE: if you want use it not only for POST CATEGORIES – you should change this condition in the code above

    if ( 'category' !== $taxonomy_slug ) continue;

    Best,

    Ivan.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.