Discussion:
prevent theme's functions.php from loading in wp-settings
Paul Menard
2014-05-03 23:19:29 UTC
Permalink
Greetings. I custom processing loop outside of WordPress. This is a custom
AJAX handler and depending on the POST arguments I do some stuff outside of
WordPress or as in this case I load WP via the following.

define( 'SHORTINIT', false );
define( 'WP_USE_THEMES', false );
define( 'WP_DEBUG', false );

// Load in WP core.
require( $configs_array['ABSPATH'] .'wp-load.php' );

So as anyone knows wp-load.php then calls wp-config.php which in turn calls
wp-settings.php

Within wp-settings.php line 324 begins the logic and my issue.

if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) {
if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH .
'/functions.php' ) )
include( STYLESHEETPATH . '/functions.php' );
if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
include( TEMPLATEPATH . '/functions.php' );
}

Seems I had always thought setting the define 'WP_USER_THEME' as false
would prevent the theme from loading. I guess I was wrong.

What I'm really trying to prevent is a query used within the TwentyFourteen
theme in twentyfourteen/inc/featured-content.php where registers an action
for when 'wp_load' action hits. This in turn causes a get_option call for
featured content in line 471 Not that this is a big query.

$saved = (array) get_option( 'featured-content' );

Just bugs me that I can't stop it from being called.
Andrew Nacin
2014-05-03 23:24:10 UTC
Permalink
Well, you could stop it from being called. But trying to prevent
functions.php from loading just to stop a single get_option() call is like
amputating a limb because of a paper cut.

If you're seeing that query, then the featured-content option isn't
initialized. Just add that option manually (something the theme probably
does upon save or something) and you'll avoid the SQL query. Example:
add_option( 'featured-content', array() );
Post by Paul Menard
Greetings. I custom processing loop outside of WordPress. This is a custom
AJAX handler and depending on the POST arguments I do some stuff outside of
WordPress or as in this case I load WP via the following.
define( 'SHORTINIT', false );
define( 'WP_USE_THEMES', false );
define( 'WP_DEBUG', false );
// Load in WP core.
require( $configs_array['ABSPATH'] .'wp-load.php' );
So as anyone knows wp-load.php then calls wp-config.php which in turn calls
wp-settings.php
Within wp-settings.php line 324 begins the logic and my issue.
if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) {
if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH .
'/functions.php' ) )
include( STYLESHEETPATH . '/functions.php' );
if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
include( TEMPLATEPATH . '/functions.php' );
}
Seems I had always thought setting the define 'WP_USER_THEME' as false
would prevent the theme from loading. I guess I was wrong.
What I'm really trying to prevent is a query used within the TwentyFourteen
theme in twentyfourteen/inc/featured-content.php where registers an action
for when 'wp_load' action hits. This in turn causes a get_option call for
featured content in line 471 Not that this is a big query.
$saved = (array) get_option( 'featured-content' );
Just bugs me that I can't stop it from being called.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Paul Menard
2014-05-03 23:29:04 UTC
Permalink
This post might be inappropriate. Click to display it.
Nicholas Ciske
2014-05-05 14:56:12 UTC
Permalink
Tried define( 'SHORTINIT', true ); ? That keeps wp-settings.php from loading in the first place.

What if you define 'WP_INSTALLING' to something? That would seem to preclude the loading of functions.php -- but feels hacky.

See also:
http://wordpress.org/support/topic/load-wp-core-in-another-framework-shortinit-wp_query

Or perhaps you need to reframe the problem and just use a WP Ajax handler instead?

_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Post by Paul Menard
Thanks Andrew. But my point was more about the theme functions.php being
loaded at all from wp-settings.php. Sure I can figure out a way to short
circuit the get_options call but that is for TwentyFourteen. What is there
is another theme used and the functions.php does many other queries I
really don't want? Just seems less efficient not being able to control this
via the WP_USE_THEMES define.
P-
Paul Menard
2014-05-05 15:57:02 UTC
Permalink
Nick,

I'm using SHORTINIT in another area of the AJAX handler when I don't need
to load the entire WP environment. So yes, I'm aware of how this works.
Have not tried WP_INSTALLING. And agree it seems hack-ish. But might just
work.

To restate when I define WP_USE_THEMES as false I would expect no part of
the theme to be loaded including the theme functions.php. This is
regardless of using my own AJAX handler. What if I were just side-loading
WordPress and needed WP core functionality but not the theme?

Not a big issues. I'm already gaining a large efficiency using the
SHORTINIT and bypassing loading all the plugins for each request.


Nikola,

Correct. When using the WP admin-ajax handler it loads all plugins into the
environment before servicing the specific ajax handler. This is expected.
And this is where I'm using my own handler. Then I can decide what parts of
WP I needed to load.

Paul
WP Ajax handlers(the one at /wp-admin/admin-ajax.php) load all plugins and
themes as well(since themes can also register AJAX action handlers).
Post by Nicholas Ciske
Tried define( 'SHORTINIT', true ); ? That keeps wp-settings.php from
loading in the first place.
What if you define 'WP_INSTALLING' to something? That would seem to
preclude the loading of functions.php -- but feels hacky.
http://wordpress.org/support/topic/load-wp-core-in-another-framework-shortinit-wp_query
Post by Nicholas Ciske
Or perhaps you need to reframe the problem and just use a WP Ajax handler instead?
_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Post by Paul Menard
Thanks Andrew. But my point was more about the theme functions.php
being
Post by Nicholas Ciske
Post by Paul Menard
loaded at all from wp-settings.php. Sure I can figure out a way to
short
Post by Nicholas Ciske
Post by Paul Menard
circuit the get_options call but that is for TwentyFourteen. What is
there
Post by Paul Menard
is another theme used and the functions.php does many other queries I
really don't want? Just seems less efficient not being able to control
this
Post by Paul Menard
via the WP_USE_THEMES define.
P-
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Nikola Nikolov
2014-05-05 15:07:32 UTC
Permalink
WP Ajax handlers(the one at /wp-admin/admin-ajax.php) load all plugins and
themes as well(since themes can also register AJAX action handlers).
Post by Nicholas Ciske
Tried define( 'SHORTINIT', true ); ? That keeps wp-settings.php from
loading in the first place.
What if you define 'WP_INSTALLING' to something? That would seem to
preclude the loading of functions.php -- but feels hacky.
http://wordpress.org/support/topic/load-wp-core-in-another-framework-shortinit-wp_query
Or perhaps you need to reframe the problem and just use a WP Ajax handler instead?
_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Post by Paul Menard
Thanks Andrew. But my point was more about the theme functions.php being
loaded at all from wp-settings.php. Sure I can figure out a way to short
circuit the get_options call but that is for TwentyFourteen. What is
there
Post by Paul Menard
is another theme used and the functions.php does many other queries I
really don't want? Just seems less efficient not being able to control
this
Post by Paul Menard
via the WP_USE_THEMES define.
P-
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...