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

Turn off comment subscriptions on specific custom post types #149

Closed
bonest opened this issue Oct 20, 2015 · 21 comments
Closed

Turn off comment subscriptions on specific custom post types #149

bonest opened this issue Oct 20, 2015 · 21 comments
Labels
Milestone

Comments

@bonest
Copy link

bonest commented Oct 20, 2015

Hi.

If you use Woocommerce, then Comment-mail subscription form is shown on the reviews tab.
If you use any other plugin that creates a custom post type, and uses comments you have the same problem.

I have a big issue with this, and I own a PRO license, I really need a way to disable the subscription form for comments to specific post types.

I really need a quick fix for this because I have a plugin that has to go live, that use comments, and it has its own notification system. And I have to put this plugin live today.. Tomorrow at the very latest. :-(

@raamdev
Copy link
Contributor

raamdev commented Oct 21, 2015

@jaswsinc Correct me if I'm wrong, but I don't believe there's currently a way to do this, correct? I was looking for a filter that we could hook into to hide the subscription options for certain post types, but I wasn't able to find any. Do you agree that adding the following filter to this function would be a good idea?

if(apply_filters(__NAMESPACE__.'_disable_subscription_options', FALSE))
     return; // Disabled by filter

In the longer-term, I do agree with @bonest that we should have a way of disabling Comment Subscriptions for certain Post Types, as Comment Subscriptions won't be applicable for many Custom Post Types.

@raamdev raamdev added the bug label Oct 21, 2015
@raamdev raamdev added this to the Next Release milestone Oct 21, 2015
@jaswrks
Copy link

jaswrks commented Oct 21, 2015

@bonest You can do this by editing the template file in advanced mode.

See: Dashboard → Comment Mail → Site Templates

2015-10-20_17-53-32

Referencing: https://codex.wordpress.org/Function_Reference/get_post_type

@jaswrks
Copy link

jaswrks commented Oct 21, 2015

2015-10-20_17-53-06

@jaswrks
Copy link

jaswrks commented Oct 21, 2015

Do you agree that adding the following filter to this function would be a good idea?

Yes, I agree!

@raamdev
Copy link
Contributor

raamdev commented Oct 21, 2015

@jaswsinc My feeling is that Comment Mail should only be showing Comment Subscriptions on post Post Types and excluding all other posts types by default. Then there should be some way to enable Comment Subscriptions on other post types where a site owner might have a specific Custom Post Type that they wish to show the Comment Subscriptions options on.

@jaswrks
Copy link

jaswrks commented Oct 21, 2015

Hmm. Well, I'm not sure.

This actually comes as a surprise to me. I didn't realize there were a lot of plugins that used WordPress comments in a way that would make coupling them with subscriptions undesirable. If a particular type of Post is configured to use comments, then Comment Mail will be enabled along with the comments. If comments are not used, then they will not be; i.e., Comment Mail rides on comments in WordPress core.

only be showing Comment Subscriptions on post Post Types and excluding all other posts types by default.

I don't really have any problem with this. However, it seems to me that if I have a Post Type that uses comments then I would expect Comment Mail to be enabled there without any further configuration. So disabling them for anything other than the post Post Type by default seems unintuitive to me at the moment. Either way though, it seems like it should be easily configurable.

@raamdev
Copy link
Contributor

raamdev commented Oct 21, 2015

it seems to me that if I have a Post Type that uses comments then I would expect Comment Mail to be enabled there

That seems to assume that any Custom Post Types that allow comments are designed for the same type of comments as Posts (i.e., discussion), which in my mind seems rather unlikely.

Think about what scenarios you would create a Custom Post Type that supports comments: The example that @bonest gave us above is a good one. A CPT that allows comments (i.e., makes use of the WordPress comment system) to create a "reviews" section that allows visitors to leave short reviews for a Product CPT. In that scenario, having a full-fledged comment subscription system makes no sense at all.

Likewise, I can't imagine many reasons a CPT would use comments and also expect something like Comment Mail to enable comment subscriptions on it. The only place Comment Subscriptions makes sense is on Posts where discussions take place. There may be some CPTs that use Comments for something that falls into the category of "discussions", but I'm willing to bet that most implementations do not.

@jaswrks
Copy link

jaswrks commented Oct 21, 2015

Great points. Thank you. I'm fine with them being enabled for post types only by default then.

@raamdev
Copy link
Contributor

raamdev commented Oct 21, 2015

I'm fine with them being enabled for post types only by default then.

Cool. :-) So we should add a new option in Comment Mail → Config. Options → Comment Form towards the bottom called Enable Comment Form for Custom Post Types (Comma-Delimited) that allows supplying a comma-delimited list of CPTs (just like Comment Mail → Config. Options → Auto-Subscribe Settings → Auto-Subscribe Post Types (Comma-Delimited)) and the field should include only post by default, correct?

@bonest
Copy link
Author

bonest commented Oct 21, 2015

Thank you for including me in your discussion. I can tell by reading the communication that you understand the issue.

Jason you suggested that I could remove the form in Advanced mode.

But this is not quit enough, since the plugin also hooks into the comment_post action which is fired after the comment has been inserted.
I guess this adds the subscription to the notification queue.

So even if the form is not shown, I have to be sure that comment_mail does not send notifications.

I tried last night to see if I could find a way to remove the actions on specific post types that the comment_mail is triggered from.

comment_form_must_log_in_after
comment_form_top
comment_post
comment_form

But I did not manage to get it to work, so I am hoping for a quick fix from you guys.

Kind Regards

Henrik

Den 21/10/2015 kl. 04.58 skrev Raam Dev notifications@github.com:

I'm fine with them being enabled for post types only by default then.

Cool. :-) So we should add a new option in Comment Mail → Config. Options → Comment Form towards the bottom called Enable Comment Form for Custom Post Types (Comma-Delimited) that allows supplying a comma-delimited list of CPTs (just like Comment Mail → Config. Options → Auto-Subscribe Settings → Auto-Subscribe Post Types (Comma-Delimited)) and the field should include only post by default, correct?


Reply to this email directly or view it on GitHub #149 (comment).

@jaswrks
Copy link

jaswrks commented Oct 21, 2015

So even if the form is not shown, I have to be sure that comment_mail does not send notifications.

@bonest If the markup is not there, the actions will not fire, because the form data that triggers Comment Mail will not be there. So if you exclude the Comment Form additions presented by Comment Mail, that should fix you up in the short term.

@jaswrks
Copy link

jaswrks commented Oct 21, 2015

By "exclude", I mean #149 (comment)

@bonest
Copy link
Author

bonest commented Oct 25, 2015

Hi guys.

I tried to remove filters, because I would like to avoid switching to advanced template. Because I have spend hours styling and translating the simple templates. It takes time testing as you know.

But I can tell that it is impossible to remove the filters, to remove the form.

Do you have an ETA for when this could be fixed?

@raamdev
Copy link
Contributor

raamdev commented Oct 26, 2015

@bonest You can modify includes/classes/comment-form-after.php and add the following code after this line:

if(apply_filters(__NAMESPACE__.'_disable_subscription_options', FALSE))
     return; // Disabled by filter

Then you can create an MU-Plugin (create this file and directory: wp-content/mu-plugins/maby-disable-comment-mail-form.php):

<?php
/*
Plugin Name: Maybe Disable Comment Mail Subscription Options
Description: Disables Comment Mail Subscription Options for certain post types
Author: WebSharks, Inc.
Version: 1.0
Author URI: http://www.websharks-inc.com
*/

add_filter('comment_mail_disable_subscription_options', '__cm_maybe_disable_sub_opts', 10, 0);

function __cm_maybe_disable_sub_opts() {
    if(get_post_type() !== 'post') {
        return TRUE; // Yes, disable Comment Mail Subscription Options
    }
    else {
        return FALSE;
    }
}

We will be adding the above filter to includes/classes/comment-form-after.php in the next Comment Mail release, so the above method will continue to work after the next update.

@jaswrks
Copy link

jaswrks commented Oct 27, 2015

Next Actions (Pro Version)

  • New feature branch in the websharks/comment-mail-pro repo.

  • After this line add a new option key.

    'enabled_post_types' => 'post',
  • Replace these lines of code with the following:

    $post_type = strtolower((string)$post_type);
    
    $enabled_post_types = strtolower($this->options['enabled_post_types']);
    $enabled_post_types = preg_split('/[\s;,]+/', $enabled_post_types, NULL, PREG_SPLIT_NO_EMPTY);
    
    if($enabled_post_types && !in_array($post_type, $enabled_post_types, TRUE))
      return; // Ignore; not enabled for this post type.
    
    $excluded_post_types = strtolower($this->options['excluded_meta_box_post_types']);
    $excluded_post_types = preg_split('/[\s;,]+/', $excluded_post_types, NULL, PREG_SPLIT_NO_EMPTY);
    
    if(in_array($post_type, $excluded_post_types, TRUE))
      return; // Ignore; this post type excluded.
  • After this line add the following:

    $post_type = $GLOBALS['post']->post_type; // Current post type.
  • After this line add the following:

    $enabled_post_types = strtolower($this->plugin->options['enabled_post_types']);
    $enabled_post_types = preg_split('/[\s;,]+/', $enabled_post_types, NULL, PREG_SPLIT_NO_EMPTY);
    
    if($enabled_post_types && !in_array($post_type, $enabled_post_types, TRUE))
      return; // Ignore; not enabled for this post type.
  • After this line add the following:

    if(empty($GLOBALS['post']) || !($GLOBALS['post'] instanceof \WP_Post))
      return; // Not possible here.
    
    $post_id   = $GLOBALS['post']->ID; // Current post ID.
    $post_type = $GLOBALS['post']->post_type; // Current post type.
    
    $enabled_post_types = strtolower($this->plugin->options['enabled_post_types']);
    $enabled_post_types = preg_split('/[\s;,]+/', $enabled_post_types, NULL, PREG_SPLIT_NO_EMPTY);
    
    if($enabled_post_types && !in_array($post_type, $enabled_post_types, TRUE))
      return; // Ignore; not enabled for this post type.
  • After this line add the following:

    'include_post_types' => array(),
  • After this line add the following:

    'include_post_types' => array(),
  • After this line add the following:

    'include_post_types' => array(),
  • After this line add the following:

    'include_post_types' => array(),
  • After this line add the following:

    $include_post_types = (array)$args['include_post_types'];
  • After this line add the following:

    $include_post_types = (array)$args['include_post_types'];
  • After this line add the following:

    $include_post_types = (array)$args['include_post_types'];
  • After this line add the following:

    $include_post_types = (array)$args['include_post_types'];
  • Replace this line with the following:

    $post_types = $include_post_types ? $include_post_types : get_post_types(array('exclude_from_search' => FALSE));
  • Replace this line with the following:

    $post_types = $include_post_types ? $include_post_types : get_post_types(array('exclude_from_search' => FALSE));
  • After this line add the following:

    if($include_post_types && !in_array($post->post_type, $include_post_types, TRUE))
      return ($total = 0); // Post type not included; automatic zero.
  • After this line add the following:

    if($include_post_types && !in_array($post->post_type, $include_post_types, TRUE))
      return ($comments = array()); // Post type not included; automatic empty.
  • After this line add the following:

    'include_post_types' => array(),
  • After this line add the following:

    $args['include_post_types'] = (array)$args['include_post_types'];
    if ($this->plugin->options['enabled_post_types']) {
      $enabled_post_types = strtolower($this->plugin->options['enabled_post_types']);
      $enabled_post_types = preg_split('/[\s;,]+/', $enabled_post_types, NULL, PREG_SPLIT_NO_EMPTY);
      $args['include_post_types'] = array_unique(array_merge($args['include_post_types'], $enabled_post_types));
    }
  • After this line add the following:

    'include_post_types' => array(),
  • After this line add the following:

    $args['include_post_types'] = (array)$args['include_post_types'];
    if ($this->plugin->options['enabled_post_types']) {
      $enabled_post_types = strtolower($this->plugin->options['enabled_post_types']);
      $enabled_post_types = preg_split('/[\s;,]+/', $enabled_post_types, NULL, PREG_SPLIT_NO_EMPTY);
      $args['include_post_types'] = array_unique(array_merge($args['include_post_types'], $enabled_post_types));
    }
    
    $args['exclude_post_types'] = (array)$args['exclude_post_types'];
    if(!$this->plugin->options['post_select_options_media_enable'])
      $args['exclude_post_types'][] = 'attachment';
  • Replace this line with the following:

    'auto_subscribe_post_types' => 'post', // Comma-delimited post types.
  • After this line add the following:

    $enabled_post_types = strtolower($this->plugin->options['enabled_post_types']);
    $enabled_post_types = preg_split('/[;,\s]+/', $enabled_post_types, NULL, PREG_SPLIT_NO_EMPTY);
    
    if ($enabled_post_types && $this->post_types) {
      foreach($this->post_types as $_key => $_post_type) {
        if (!in_array($_post_type, $enabled_post_types, true)) {
          unset($this->post_types[$_key]);
        }
      }
      unset($_key, $_post_type); // Housekeeping.
    }
  • After this line add a new UI config. option.

    ' <hr />'.
    ' <table>'.
    '    <tbody>'.
    $form_fields->input_row(
      array(
        'label'           => __('Enabled for Post Types', $this->plugin->text_domain),
        'placeholder'     => __('e.g., post,page,article', $this->plugin->text_domain),
        'name'            => 'enabled_post_types',
        'current_value'   => $current_value_for('enabled_post_types'),
        'notes_after'     => '<p>'.__('Enter a comma-delimited list of WordPress Post Types. Leave this empty to enable for all Post Types where comments apply.', $this->plugin->text_domain).'</p>',
      )).
    '    </tbody>'.
    ' </table>'.

    You should find that it shows up here.

    2015-10-27_02-16-42

  • Submit PR.

Next Actions (Lite Version)

  • New feature branch in the websharks/comment-mail repo.

  • Repeat all of the above steps in the lite version, with the following exceptions.

    • The comment-form-login.php file does nothing in the lite version, so whenever you attempt duplicate this step in the lite version, please feel free to skip over it. See: empty file here for a quick reference. In short, there is no SSO integration in the lite version. Therefore, nothing in the comment-form-login.php file to change.
    • You can skip the last step when working on the lite version. The menu-page.php file is identical for both the lite and pro versions. It will automatically adapt accordingly. So whenever you reach the very last step where you are making changes to the menu-page.php file, you can simply delete the existing menu-page.php in the lite version, and replace it with an exact copy of what you worked on as a part of the pro version—which should now include a text box where you can enter a comma-delimited list of Post Types that Comment Mail should be enabled for.

    You should find that it shows up here.

    2015-10-27_02-16-42

  • Submit PR.

@bonest
Copy link
Author

bonest commented Oct 27, 2015

Thanks Raam

That worked perfectly.

Kind Regards

Henrik

Den 27/10/2015 kl. 00.12 skrev Raam Dev notifications@github.com:

add_filter('comment_mail_disable_subscription_options', '__cm_maybe_disable_sub_opts', 10, 0);

function __cm_maybe_disable_sub_opts() {
if(get_post_type() !== 'post') {
return TRUE; // Yes, disable Comment Mail Subscription Options
}
else {
return FALSE;
}
}

@raamdev
Copy link
Contributor

raamdev commented Oct 28, 2015

@jaswsinc I'm tweaking the note underneath the new "Enabled for Post Types" field a bit:

2015-10-27_22-27-01

raamdev added a commit to wpsharks/comment-mail-pro that referenced this issue Oct 28, 2015
raamdev added a commit to wpsharks/comment-mail-pro that referenced this issue Oct 28, 2015
- Enable only for default post type by default

See wpsharks/comment-mail#149
@jaswrks
Copy link

jaswrks commented Oct 28, 2015

I'm tweaking the note underneath the new "Enabled for Post Types" field a bit

Cool. That is much better.

raamdev added a commit that referenced this issue Oct 28, 2015
- Enable only for default post type by default

See #149
@raamdev raamdev mentioned this issue Oct 28, 2015
@raamdev
Copy link
Contributor

raamdev commented Oct 28, 2015

Next Pro Release Changelog:

  • Enhancement: Comment Mail is now only enabled for the standard post Post Type by default and there's a new "Enable for Post Types" option inside Comment Mail → Config. Options → Enable/Disable that allows you to specify a comma-delimited list of Post Types that Comment Mail should be enabled for. It's also possible to enable Comment Mail on all Post Types that support comments by leaving the field empty (this was the previous behavior). Props to @bonest. See Issue #149.

@raamdev
Copy link
Contributor

raamdev commented Oct 28, 2015

Next Lite Release Changelog:

  • Enhancement: Comment Mail is now only enabled for the standard post Post Type by default and there's a new "Enable for Post Types" option inside Comment Mail → Config. Options → Enable/Disable that allows you to specify a comma-delimited list of Post Types that Comment Mail should be enabled for. It's also possible to enable Comment Mail on all Post Types that support comments by leaving the field empty (this was the previous behavior). Props to @bonest. See Issue #149.

@raamdev raamdev closed this as completed Oct 28, 2015
@wpsharks wpsharks locked and limited conversation to collaborators Dec 24, 2015
@raamdev
Copy link
Contributor

raamdev commented Dec 24, 2015

Comment Mail v151224 has been released and includes changes from this GitHub Issue: See the v151224 announcement for further details.


This issue will now be locked to further updates. If you have something to add related to this GitHub Issue, please open a new GitHub Issue and reference this one (#149).

@raamdev raamdev removed their assignment Apr 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants