Discussion:
by passing the entire template hierarchy
Haluk Karamete
2014-07-07 09:34:54 UTC
Permalink
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?
Mikael Grön
2014-07-07 12:52:35 UTC
Permalink
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
Post by 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
http://lists.automattic.com/mailman/listinfo/wp-hackers
Mikael Grön
2014-07-07 12:53:14 UTC
Permalink
(sorry about the typo, coding in a gmail compose window is not recommended.)

--
Med vänliga hälsningar
Mikael Grön
Post by Mikael Grön
What are you trying to accomplish?
When I want to run pure code, for cron scripts and stuff, I usually do
<?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
Is there a way to by pass the great system known as the WordPress Template
Post by Haluk Karamete
Hierarchy so that WordPress shoots the ball straight to the last resort
which is index.php?
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
John Blackbourn
2014-07-07 13:39:29 UTC
Permalink
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' );
} );
Post by 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
http://lists.automattic.com/mailman/listinfo/wp-hackers
Haluk Karamete
2014-07-07 15:08:54 UTC
Permalink
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?
Post by John Blackbourn
It's a strange thing to need to do (you might want to re-think what
add_filter( 'template_include', function( $template ) {
return locate_template( 'index.php' );
} );
Post by Haluk Karamete
Is there a way to by pass the great system known as the WordPress
Template
Post by Haluk Karamete
Hierarchy so that WordPress shoots the ball straight to the last resort
which is index.php?
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
John Blackbourn
2014-07-07 15:24:50 UTC
Permalink
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
Post by 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?
Post by John Blackbourn
It's a strange thing to need to do (you might want to re-think what
add_filter( 'template_include', function( $template ) {
return locate_template( 'index.php' );
} );
Post by Haluk Karamete
Is there a way to by pass the great system known as the WordPress
Template
Post by Haluk Karamete
Hierarchy so that WordPress shoots the ball straight to the last resort
which is index.php?
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Walter Ebert
2014-07-07 15:47:44 UTC
Permalink
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
Post by 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?
Post by John Blackbourn
It's a strange thing to need to do (you might want to re-think what
add_filter( 'template_include', function( $template ) {
return locate_template( 'index.php' );
} );
Post by Haluk Karamete
Is there a way to by pass the great system known as the WordPress
Template
Post by Haluk Karamete
Hierarchy so that WordPress shoots the ball straight to the last resort
which is index.php?
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Walter Ebert http://walterebert.com/
Shane Thompson
2014-07-08 01:46:08 UTC
Permalink
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
Post by Haluk Karamete
Post by Haluk Karamete
Is there a way to by pass the great system known as the WordPress
Template
Post by Haluk Karamete
Hierarchy so that WordPress shoots the ball straight to the last resort
which is index.php?
Haluk Karamete
2014-07-08 01:59:37 UTC
Permalink
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 <
Post by Shane Thompson
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
Post by Haluk Karamete
Post by Haluk Karamete
Is there a way to by pass the great system known as the WordPress
Template
Post by Haluk Karamete
Hierarchy so that WordPress shoots the ball straight to the last
resort
Post by Haluk Karamete
Post by Haluk Karamete
which is index.php?
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...