by passing the entire template hierarchy

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

by passing the entire template hierarchy

Haluk Karamete
Is there a way to by pass the great system known as the  WordPress Template
Hierarchy so that WordPress shoots the ball straight to the last resort
which is index.php?
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: by passing the entire template hierarchy

Mikael Grön
What are you trying to accomplish?

When I want to run pure code, for cron scripts and stuff, I usually do
something like this:

<?php

// in plugin or theme
add_action('get_header', function(){
    if (strstr($_SERVER['REQUEST_URI'], '/cron/trigger_word')
    {
        // My code
        exit;
    }
});

?>

--
Regards
Mikael Grön


2014-07-07 11:34 GMT+02:00 Haluk Karamete <[hidden email]>:

> Is there a way to by pass the great system known as the  WordPress Template
> Hierarchy so that WordPress shoots the ball straight to the last resort
> which is index.php?
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: by passing the entire template hierarchy

Mikael Grön
(sorry about the typo, coding in a gmail compose window is not recommended.)

--
Med vänliga hälsningar
Mikael Grön


2014-07-07 14:52 GMT+02:00 Mikael Grön <[hidden email]>:

> What are you trying to accomplish?
>
> When I want to run pure code, for cron scripts and stuff, I usually do
> something like this:
>
> <?php
>
> // in plugin or theme
> add_action('get_header', function(){
>     if (strstr($_SERVER['REQUEST_URI'], '/cron/trigger_word')
>     {
>         // My code
>         exit;
>     }
> });
>
> ?>
>
> --
> Regards
> Mikael Grön
>
>
> 2014-07-07 11:34 GMT+02:00 Haluk Karamete <[hidden email]>:
>
> Is there a way to by pass the great system known as the  WordPress Template
>> Hierarchy so that WordPress shoots the ball straight to the last resort
>> which is index.php?
>> _______________________________________________
>> wp-hackers mailing list
>> [hidden email]
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: by passing the entire template hierarchy

John Blackbourn
In reply to this post by Haluk Karamete
It's a strange thing to need to do (you might want to re-think what
exactly it is you're doing) but it's simple enough:

add_filter( 'template_include', function( $template ) {
    return locate_template( 'index.php' );
} );

On 7 July 2014 10:34, Haluk Karamete <[hidden email]> wrote:
> Is there a way to by pass the great system known as the  WordPress Template
> Hierarchy so that WordPress shoots the ball straight to the last resort
> which is index.php?
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: by passing the entire template hierarchy

Haluk Karamete
Thank you guys for your input.. I appreciate it.

John, I've built a new infustructure where things work differently and in
this infrustructure, the whole theme is done by a single index.php. And
that's always the case - which nullifies the need for the concept known as
template-hiearachy.

So there will never-ever be a need to say category.php.
I do not wish to get into the details here as to why I]ve built a framework
as such , and why I should or should not have done so etc.

Please note that this is not about overwriting the template hierarchy.

It's about totally by passing it
- which I have a feeling is not possible.

In the case of hooking into the "template_include" (or "template_redirect"
for that matter), it's an overwrite.

As you know, those hooks are run after wordpress core deployed the
template-hierarchy and in some cases 7 or 8 files have already been probed
for their existence. - which is exactly the process I'm trying to prevent
from taking place.

and as to the get_header option, Mikael, it's the same situation. By the
time, get_header hook sees the world, all the file_exists operations have
already been performed.

Let me put it this way, we all know index.php is the last resort in the
template-hierarchy.

Is there a hook that I can turn index.php being the first-resort?





On Mon, Jul 7, 2014 at 6:39 AM, John Blackbourn <[hidden email]>
wrote:

> It's a strange thing to need to do (you might want to re-think what
> exactly it is you're doing) but it's simple enough:
>
> add_filter( 'template_include', function( $template ) {
>     return locate_template( 'index.php' );
> } );
>
> On 7 July 2014 10:34, Haluk Karamete <[hidden email]> wrote:
> > Is there a way to by pass the great system known as the  WordPress
> Template
> > Hierarchy so that WordPress shoots the ball straight to the last resort
> > which is index.php?
> > _______________________________________________
> > wp-hackers mailing list
> > [hidden email]
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: by passing the entire template hierarchy

John Blackbourn
It sounds like you're trying to do something that doesn't belong as a
theme, but whatever. This should do the trick:

add_action( 'template_redirect', function() {
    locate_template( 'index.php', true );
    exit;
} );

Note that this will also affect feeds and things, so you might want to
add some `!is_feed()` logic in there if you still want feeds to work.

John

On 7 July 2014 16:08, Haluk Karamete <[hidden email]> wrote:

> Thank you guys for your input.. I appreciate it.
>
> John, I've built a new infustructure where things work differently and in
> this infrustructure, the whole theme is done by a single index.php. And
> that's always the case - which nullifies the need for the concept known as
> template-hiearachy.
>
> So there will never-ever be a need to say category.php.
> I do not wish to get into the details here as to why I]ve built a framework
> as such , and why I should or should not have done so etc.
>
> Please note that this is not about overwriting the template hierarchy.
>
> It's about totally by passing it
> - which I have a feeling is not possible.
>
> In the case of hooking into the "template_include" (or "template_redirect"
> for that matter), it's an overwrite.
>
> As you know, those hooks are run after wordpress core deployed the
> template-hierarchy and in some cases 7 or 8 files have already been probed
> for their existence. - which is exactly the process I'm trying to prevent
> from taking place.
>
> and as to the get_header option, Mikael, it's the same situation. By the
> time, get_header hook sees the world, all the file_exists operations have
> already been performed.
>
> Let me put it this way, we all know index.php is the last resort in the
> template-hierarchy.
>
> Is there a hook that I can turn index.php being the first-resort?
>
>
>
>
>
> On Mon, Jul 7, 2014 at 6:39 AM, John Blackbourn <[hidden email]>
> wrote:
>
>> It's a strange thing to need to do (you might want to re-think what
>> exactly it is you're doing) but it's simple enough:
>>
>> add_filter( 'template_include', function( $template ) {
>>     return locate_template( 'index.php' );
>> } );
>>
>> On 7 July 2014 10:34, Haluk Karamete <[hidden email]> wrote:
>> > Is there a way to by pass the great system known as the  WordPress
>> Template
>> > Hierarchy so that WordPress shoots the ball straight to the last resort
>> > which is index.php?
>> > _______________________________________________
>> > wp-hackers mailing list
>> > [hidden email]
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>> _______________________________________________
>> wp-hackers mailing list
>> [hidden email]
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: by passing the entire template hierarchy

Walter Ebert
In reply to this post by Haluk Karamete
Hi,

you could try to use a custom front controller and use .htaccess to map
to that file, for example:

index2.php
<?php
require 'wp-load.php';
require get_template_directory() . '/index.php';


.htaccess
DirectoryIndex index2.php index.php index.html

Cheers,
Walter

On 07/07/2014 05:08 PM, Haluk Karamete wrote:

> Thank you guys for your input.. I appreciate it.
>
> John, I've built a new infustructure where things work differently and in
> this infrustructure, the whole theme is done by a single index.php. And
> that's always the case - which nullifies the need for the concept known as
> template-hiearachy.
>
> So there will never-ever be a need to say category.php.
> I do not wish to get into the details here as to why I]ve built a framework
> as such , and why I should or should not have done so etc.
>
> Please note that this is not about overwriting the template hierarchy.
>
> It's about totally by passing it
> - which I have a feeling is not possible.
>
> In the case of hooking into the "template_include" (or "template_redirect"
> for that matter), it's an overwrite.
>
> As you know, those hooks are run after wordpress core deployed the
> template-hierarchy and in some cases 7 or 8 files have already been probed
> for their existence. - which is exactly the process I'm trying to prevent
> from taking place.
>
> and as to the get_header option, Mikael, it's the same situation. By the
> time, get_header hook sees the world, all the file_exists operations have
> already been performed.
>
> Let me put it this way, we all know index.php is the last resort in the
> template-hierarchy.
>
> Is there a hook that I can turn index.php being the first-resort?
>
>
>
>
>
> On Mon, Jul 7, 2014 at 6:39 AM, John Blackbourn <[hidden email]>
> wrote:
>
>> It's a strange thing to need to do (you might want to re-think what
>> exactly it is you're doing) but it's simple enough:
>>
>> add_filter( 'template_include', function( $template ) {
>>     return locate_template( 'index.php' );
>> } );
>>
>> On 7 July 2014 10:34, Haluk Karamete <[hidden email]> wrote:
>>> Is there a way to by pass the great system known as the  WordPress
>> Template
>>> Hierarchy so that WordPress shoots the ball straight to the last resort
>>> which is index.php?
>>> _______________________________________________
>>> wp-hackers mailing list
>>> [hidden email]
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> _______________________________________________
>> wp-hackers mailing list
>> [hidden email]
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


--
Walter Ebert http://walterebert.com/
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: by passing the entire template hierarchy

Shane Thompson
In reply to this post by Haluk Karamete
Hi Haluk,

Although it is possible, as already described, I don't think it would be a
very good idea to circumvent this. If you must, template_include is
probably better for this than template_redirect, as template_redirect (my
understanding) is purely for doing redirects. ie. I want /courses/ to
redirect to /courses/medical so I would do this with template_redirect.

If you are trying to circumvent it for performance reasons, you're not
making much of a performance benefit at all. We can discuss ways to get the
best performance out of WP here, if that is what you are after.

Shane Thompson

>> On 7 July 2014 10:34, Haluk Karamete <[hidden email]> wrote:
>> > Is there a way to by pass the great system known as the  WordPress
>> Template
>> > Hierarchy so that WordPress shoots the ball straight to the last resort
>> > which is index.php?
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: by passing the entire template hierarchy

Haluk Karamete
Thank you Shane for your comment..

There currently is no way in WordPress that I know of to prevent the
behaviour I described.

Wordpress has to do its chores and check those files one by one - following
the template hierarchy  - no matter what the case be.
Neither the template_redirect , nor the template_include would prevent that
from happening.

I was strictly approaching the matter from a performance point of view as
you've correctly sensed.

But sometime during the afternoon today, I just let go of that. :)

It's OK for the template hierarchy  to take its course - checking all those
files even thought, in my case 100% of the time, index.php will prevail at
the end of those look ups. Since the PHP's "file_exists" function is
failrly fast, there is no need for me to worry about that.

I'm just moving on...





On Mon, Jul 7, 2014 at 6:46 PM, Shane Thompson <
[hidden email]> wrote:

> Hi Haluk,
>
> Although it is possible, as already described, I don't think it would be a
> very good idea to circumvent this. If you must, template_include is
> probably better for this than template_redirect, as template_redirect (my
> understanding) is purely for doing redirects. ie. I want /courses/ to
> redirect to /courses/medical so I would do this with template_redirect.
>
> If you are trying to circumvent it for performance reasons, you're not
> making much of a performance benefit at all. We can discuss ways to get the
> best performance out of WP here, if that is what you are after.
>
> Shane Thompson
>
> >> On 7 July 2014 10:34, Haluk Karamete <[hidden email]> wrote:
> >> > Is there a way to by pass the great system known as the  WordPress
> >> Template
> >> > Hierarchy so that WordPress shoots the ball straight to the last
> resort
> >> > which is index.php?
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers