Skip to:
Content

BuddyPress.org

Opened 13 years ago

Closed 13 years ago

Last modified 8 years ago

#2956 closed enhancement (duplicate)

Use get_template_part instead of locate_template in BP Default

Reported by: sorich87's profile sorich87 Owned by: sorich87's profile sorich87
Milestone: 1.5 Priority: normal
Severity: normal Version:
Component: Templates Keywords:
Cc: sorich87

Description

BP Default uses locate_template which cannot be filtered. Let's use get_template_part instead and benefit of all the advantages of that function.

Change History (12)

#1 @sorich87
13 years ago

I will submit a patch for this.

#2 @sbrajesh
13 years ago

Is there any real benefit of using get_template_part instead of locate_template. get_template_part too, does not allow filtering and does nothing other than using locate_template.

Further, It is not flexible enough to allow you load the files from sub directory ?

#3 follow-up: @sorich87
13 years ago

get_template_part too, does not allow filtering and does nothing other than using locate_template.

This is not true. There is an action in get template part 'get_template_part_{$slug}' which allows filtering.

Further, It is not flexible enough to allow you load the files from sub directory ?

No, it is not flexible at all. What if don't want to load files from sub directories but from locations other than the theme directory?
locate_template can't do that. See the following ticket on the WordPress trac #WP13239.

#4 in reply to: ↑ 3 @sbrajesh
13 years ago

Replying to sorich87:

get_template_part too, does not allow filtering and does nothing other than using locate_template.

This is not true. There is an action in get template part 'get_template_part_{$slug}' which allows filtering.

I absolutely agree that there is an action hook but the action and filter hooks are different. Yes you can load other files with the action but will you be able to do anything to prevent locating the original file? other than not supplying the file to be located in the theme and that subdues the purpose. I checked the discussion and that is about locate_template. I too look forward to implementation of one of the patch(It seems to be in wp 3.2 hopefully) but in current scenario , the change is not going to have any effect imho.

Further, It is not flexible enough to allow you load the files from sub directory ?

No, it is not flexible at all. What if don't want to load files from sub directories but from locations other than the theme directory?
locate_template can't do that. See the following ticket on the WordPress trac #WP13239.

In that case, we will have a bunch of mixed code for locate_template as well as get_template_part as the current bp theme structure requires you to load files from sub folders. And hopefully, the developers will like to maintain uniformity and won't be ready to change much in the structure of current theme structure for bp-default.

#5 @sorich87
13 years ago

Yes you can load other files with the action but will you be able to do anything to prevent locating the original file?

Yes, I can hook into it with a custom function which will load the file from my custom location using a modified version of locate_template, then die() so that locate_template is never used.

In that case, we will have a bunch of mixed code for locate_template as well as get_template_part as the current bp theme structure requires you to load files from sub folders.

get_template_part also allows loading files from sub folders.
The equivalent of 'locate_template( 'dir/file.php' ) is get_template_part( 'dir/file' ). So uniformity will be maintained.

#6 @sorich87
13 years ago

See #WP15086 where you can read more details about usage of get_template_part.

#7 @sbrajesh
13 years ago

As per #WP15086 , It is not yet officially supported and should be sometimes in the 3.2. Further, the loading of files from subdirectory is just a hacks as of now using get_template_part()(please see the php doc, it specifically mentions the file should be in the theme directory(until that ticket makes it into 3.2).
From php doc for get_template_part()

Includes the named template part for a theme or if a name is specified then a

  • specialised part will be included. If the theme contains no {slug}.php file
  • then no template will be included.

Also, since all these tickets you have specified are candidates for wp 3.2, including them at the time when bp 1.3 is supposed to be working with wp 3.1 is not a very good idea.

And as you say, If you want to hack using the die() and custom load function, I don't see anything which will stop you from applying a patch to locate_template for your install to allow you do it easily until they get it in 3.2.
And just to clear my intentions, I am not advocating locate_template, It is just that currently, It suits better than get_template_part.

#8 @DJPaul
13 years ago

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

Using that action and then terminating execution is a messy workaround. We have ticket #2649 which covers this (and see #WP13239) that will let us add template hierarchy support into BuddyPress, that's not going to make it in until WordPrsss 3.2.

Replying to sorich87:

Yes you can load other files with the action but will you be able to do anything to prevent locating the original file?

Yes, I can hook into it with a custom function which will load the file from my custom location using a modified version of locate_template, then die() so that locate_template is never used.

#9 @sorich87
13 years ago

Replying to sbrajesh:

I don't see anything which will stop you from applying a patch to locate_template for your install to allow you do it easily until they get it in 3.2.

The solution I am working on will not be used on one install but thousands of installs, and these are installs of not tech savvy users.

Replying to DJPaul:

Using that action and then terminating execution is a messy workaround.

I assure you, the other solutions I have now are far messier than this.

that's not going to make it in until WordPress? 3.2.

Too bad! I suppose I have to wait at least 6 months. :(

#10 @sorich87
13 years ago

Replying to sbrajesh:

It is just that currently, It suits better than get_template_part.

I still don't understand why it suits better? (honest question)

#11 @johnjamesjacoby
13 years ago

  • Milestone changed from Awaiting Review to 1.5
  • Severity set to normal
  • Version 1.5 deleted

get_template_part() is going to get love in a future WordPress release. Until then I'm closing this and moving it to 1.5 milestone.

#12 @DJPaul
8 years ago

  • Component changed from Appearance - Template Parts to Templates
Note: See TracTickets for help on using tickets.