Skip to:
Content

BuddyPress.org

Opened 2 years ago

Closed 23 months ago

#7434 closed enhancement (fixed)

BP Email Template Hierarchy

Reported by: espellcaste Owned by: DJPaul
Milestone: 3.0 Priority: normal
Severity: normal Version:
Component: Emails Keywords: has-patch 2nd-opinion
Cc:

Description

Currently, the order of the BP Email template hierarchy is as follow:

  • Look for the template on the theme folder: (single-bp-email-slug-title.php)
  • Look for the template on the theme folder without slug on it (single-bp-email.php)
  • Look for the template on buddypress/assets/emails/single-bp-email.php

That's fine until you need to customize the templates so that they are almost completely different from one another. I have a scenario where I have "components" on the site. Each component has its own email, with different styling.

So for me, it is easier to create a custom single-bp-email-slug-here.php and customize to the way I want. But creating specific template for each email is adding up to the theme folder, together with others single-custom-posttypes.php and page-custom-template.php, etc.

So I'd like to suggest that the priority of the folder to fetch the templates from, should be BuddyPress and not the theme's.

Here follows the order I believe would be better:

  • Look for the template on buddypress/assets/emails/single-bp-emails-slug-title.php
  • Look for the template on the theme folder: single-bp-emails.php
  • Look for the template on buddypress/assets/emails/single-bp-emails.php)

Maybe single-bp-emails-ID.php would also be an option. I created a patch with the example above.

Attachments (2)

single-email-order.patch (1.2 KB) - added by espellcaste 2 years ago.
7434.02.patch (463 bytes) - added by r-a-y 2 years ago.

Download all attachments as: .zip

Change History (10)

#1 @DJPaul
2 years ago

I think you left "assets" off the path of the first line changed in your patch, based on what you wrote above.
If you want to look up what WordPress' post template hierarchy looks like as far as slugs and IDs go, we can ensure consistency with that.

This ticket was mentioned in Slack in #buddypress by slaffik. View the logs.


2 years ago

#3 @slaFFik
2 years ago

  • Milestone changed from 2.8 to 2.9

@r-a-y
2 years ago

#4 @r-a-y
2 years ago

@espellcaste - Based on what you wrote here:

 Here follows the order I believe would be better:

    Look for the template on buddypress/assets/emails/single-bp-emails-slug-title.php
    Look for the template on the theme folder: single-bp-emails.php
    Look for the template on buddypress/assets/emails/single-bp-emails.php)

I added another patch based on your suggestions. The problem with single-email-order.patch is you would break existing template checks for /single-bp-email-POST_SLUG.php.

You could also use the provided 'bp_email_get_template' filter to add in your extra template to the beginning of the array.

Last edited 2 years ago by r-a-y (previous) (diff)

This ticket was mentioned in Slack in #buddypress by espellcaste. View the logs.


2 years ago

#6 @espellcaste
2 years ago

Hi! Sorry, but I noticed now I uploaded the wrong patch... :( I'll take extra care next time. Anyway!

@r-a-y Yes! You are right. But my objective was to change this behavior from BuddyPress masquerading it with my personal needs.

Putting the bp-emails templates in the theme main folder didn't seem the right place for them.

In the scenario I described, putting the templates in the BP email folder seems organized, or "right". :)

#7 @hnla
2 years ago

  • Milestone changed from 2.9 to 3.0

#8 @djpaul
23 months ago

  • Resolution set to fixed
  • Status changed from new to closed

In 11664:

Emails: support email-specific templates in assets folder.

Mirrors existing support for the same outside the assets folder.

Fixes #7434

Props espellcaste, r-a-y.

Note: See TracTickets for help on using tickets.