Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/215528126124531713
Added rationale for why I think themes need to be able to override pluggable.php
Source Link
Tom Auger
  • 7.1k
  • 9
  • 62
  • 84

All the documentation I've encountered discusses overriding pluggable function via your plugin.

What if you're doing theme development instead?

My functions.php requires another file that overrides the get_user_by() function, defined in pluggable.php.

If I omit the if( function_exists() ) call I get the "Cannot redeclare..." error.

If I include the if( function exists() ) call, then I get no error, but of course my function is then ignored, since the pluggable version exists.

Based on Dominic's awesome post on the WordPress startup order, it's clear that pluggable.php is loaded before your theme's functions.php and so forth, so that explains the error.

So the question is - how can you take advantage of that nice pluggable architecture from within a theme, without resorting to writing plugins which then must be bundled or installed with the theme?

Further notes: So it appears that the argument is that themes should not be trying to do what plugins do. But that argument is over four years old (according to the 4-digit trac number). I'd love to hear from some heavy hitters whether this philosophy still applies, given the complex topology of today's theme development landscape. I'd like to believe we've evolved since then.

Context: I'm developing a one-off CMS solution for a customer, with a lot of custom metadata, customization of the Admin back-end, the login/authentication process, the works. And of course, there's the design component - that's where the theme part comes in. Fact is, these are simply not reusable components - they will never apply to another client, they will never be put under GPL and open sourced, and they are most certainly not to be distributed / installed on other WordPress deployments. At best there are some best practices I will leverage on future projects, but that will be strictly a reference / copy-paste job.

This does not sound like a use case for plugins to me. The theme is installed, maybe a child theme of Twenty Eleven, maybe a standalone, its functions.php calls in a boatload of includes, each handling a different aspect of the CMS in question. Then the theme template files use custom 'template tags' that are defined in the includes. I don't want to have theme files with dependencies on some plugin or other being activated, etc. It just doesn't make sense to build complexity into the system. Sure, I can put it in the must-use plugins folder, but that still feels like a hack - right now, everything that has to do with the customizations made for this project are contained in wp-content/themes/my-theme/. I don't also want to have to consider searching for stuff in some plugins folders as well.

Don't get me wrong. I love plugins and I use them and write them. And I do use plugins in conjunction with this sort of highly customized theme development when the plugin is third-party and represents best practices far beyond what I could possibly roll out in a reasonable timeframe. But when I need to modify core functionality for a one-off scenario, I turn to action hooks, filter hooks, and I'd like to be able to rely on pluggable functions for the user and authentication side of things too.

All the documentation I've encountered discusses overriding pluggable function via your plugin.

What if you're doing theme development instead?

My functions.php requires another file that overrides the get_user_by() function, defined in pluggable.php.

If I omit the if( function_exists() ) call I get the "Cannot redeclare..." error.

If I include the if( function exists() ) call, then I get no error, but of course my function is then ignored, since the pluggable version exists.

Based on Dominic's awesome post on the WordPress startup order, it's clear that pluggable.php is loaded before your theme's functions.php and so forth, so that explains the error.

So the question is - how can you take advantage of that nice pluggable architecture from within a theme, without resorting to writing plugins which then must be bundled or installed with the theme?

Further notes: So it appears that the argument is that themes should not be trying to do what plugins do. But that argument is over four years old (according to the 4-digit trac number). I'd love to hear from some heavy hitters whether this philosophy still applies, given the complex topology of today's theme development landscape. I'd like to believe we've evolved since then.

All the documentation I've encountered discusses overriding pluggable function via your plugin.

What if you're doing theme development instead?

My functions.php requires another file that overrides the get_user_by() function, defined in pluggable.php.

If I omit the if( function_exists() ) call I get the "Cannot redeclare..." error.

If I include the if( function exists() ) call, then I get no error, but of course my function is then ignored, since the pluggable version exists.

Based on Dominic's awesome post on the WordPress startup order, it's clear that pluggable.php is loaded before your theme's functions.php and so forth, so that explains the error.

So the question is - how can you take advantage of that nice pluggable architecture from within a theme, without resorting to writing plugins which then must be bundled or installed with the theme?

Further notes: So it appears that the argument is that themes should not be trying to do what plugins do. But that argument is over four years old (according to the 4-digit trac number). I'd love to hear from some heavy hitters whether this philosophy still applies, given the complex topology of today's theme development landscape. I'd like to believe we've evolved since then.

Context: I'm developing a one-off CMS solution for a customer, with a lot of custom metadata, customization of the Admin back-end, the login/authentication process, the works. And of course, there's the design component - that's where the theme part comes in. Fact is, these are simply not reusable components - they will never apply to another client, they will never be put under GPL and open sourced, and they are most certainly not to be distributed / installed on other WordPress deployments. At best there are some best practices I will leverage on future projects, but that will be strictly a reference / copy-paste job.

This does not sound like a use case for plugins to me. The theme is installed, maybe a child theme of Twenty Eleven, maybe a standalone, its functions.php calls in a boatload of includes, each handling a different aspect of the CMS in question. Then the theme template files use custom 'template tags' that are defined in the includes. I don't want to have theme files with dependencies on some plugin or other being activated, etc. It just doesn't make sense to build complexity into the system. Sure, I can put it in the must-use plugins folder, but that still feels like a hack - right now, everything that has to do with the customizations made for this project are contained in wp-content/themes/my-theme/. I don't also want to have to consider searching for stuff in some plugins folders as well.

Don't get me wrong. I love plugins and I use them and write them. And I do use plugins in conjunction with this sort of highly customized theme development when the plugin is third-party and represents best practices far beyond what I could possibly roll out in a reasonable timeframe. But when I need to modify core functionality for a one-off scenario, I turn to action hooks, filter hooks, and I'd like to be able to rely on pluggable functions for the user and authentication side of things too.

added 387 characters in body
Source Link
Tom Auger
  • 7.1k
  • 9
  • 62
  • 84

All the documentation I've encountered discusses overriding pluggable function via your plugin.

What if you're doing theme development instead?

My functions.php requires another file that overrides the get_user_by() function, defined in pluggable.php.

If I omit the if( function_exists() ) call I get the "Cannot redeclare..." error.

If I include the if( function exists() ) call, then I get no error, but of course my function is then ignored, since the pluggable version exists.

Based on Dominic's awesome post on the WordPress startup order, it's clear that pluggable.php is loaded before your theme's functions.php and so forth, so that explains the error.

So the question is - how can you take advantage of that nice pluggable architecture from within a theme, without resorting to writing plugins which then must be bundled or installed with the theme?

Further notes: So it appears that the argument is that themes should not be trying to do what plugins do. But that argument is over four years old (according to the 4-digit trac number). I'd love to hear from some heavy hitters whether this philosophy still applies, given the complex topology of today's theme development landscape. I'd like to believe we've evolved since then.

All the documentation I've encountered discusses overriding pluggable function via your plugin.

What if you're doing theme development instead?

My functions.php requires another file that overrides the get_user_by() function, defined in pluggable.php.

If I omit the if( function_exists() ) call I get the "Cannot redeclare..." error.

If I include the if( function exists() ) call, then I get no error, but of course my function is then ignored, since the pluggable version exists.

Based on Dominic's awesome post on the WordPress startup order, it's clear that pluggable.php is loaded before your theme's functions.php and so forth, so that explains the error.

So the question is - how can you take advantage of that nice pluggable architecture from within a theme, without resorting to writing plugins which then must be bundled or installed with the theme?

All the documentation I've encountered discusses overriding pluggable function via your plugin.

What if you're doing theme development instead?

My functions.php requires another file that overrides the get_user_by() function, defined in pluggable.php.

If I omit the if( function_exists() ) call I get the "Cannot redeclare..." error.

If I include the if( function exists() ) call, then I get no error, but of course my function is then ignored, since the pluggable version exists.

Based on Dominic's awesome post on the WordPress startup order, it's clear that pluggable.php is loaded before your theme's functions.php and so forth, so that explains the error.

So the question is - how can you take advantage of that nice pluggable architecture from within a theme, without resorting to writing plugins which then must be bundled or installed with the theme?

Further notes: So it appears that the argument is that themes should not be trying to do what plugins do. But that argument is over four years old (according to the 4-digit trac number). I'd love to hear from some heavy hitters whether this philosophy still applies, given the complex topology of today's theme development landscape. I'd like to believe we've evolved since then.

Understand the nature of things. Need to know the workaround.
Source Link
Tom Auger
  • 7.1k
  • 9
  • 62
  • 84

Can't How to override pluggable function in theme?

All the documentation I've encountered discusses overriding pluggable function via your plugin.

What if you're doing theme development instead?

My functions.php requires another file that overrides the get_user_by() function, defined in pluggable.php.

If I omit the if( function_exists() ) call I get the "Cannot redeclare..." error.

If I include the if( function exists() ) call, then I get no error, but of course my function is then ignored, since the pluggable version exists.

What floors me isBased on Dominic's awesome post on the WordPress startup order, it's clear that pluggable.php seems to be running pluggable.php is loaded before myyour theme's functions.php which goes against everything I thought I knew about WP load order and so forth, so that explains the way themes workerror.

Can someone clear me upSo the question is - how can you take advantage of that nice pluggable architecture from within a theme, without resorting to writing plugins which then must be bundled or installed with the theme?

Can't override pluggable function in theme?

All the documentation I've encountered discusses overriding pluggable function via your plugin.

What if you're doing theme development instead?

My functions.php requires another file that overrides the get_user_by() function, defined in pluggable.php.

If I omit the if( function_exists() ) call I get the "Cannot redeclare..." error.

If I include the if( function exists() ) call, then I get no error, but of course my function is then ignored, since the pluggable version exists.

What floors me is that pluggable.php seems to be running before my functions.php which goes against everything I thought I knew about WP load order and the way themes work.

Can someone clear me up?

How to override pluggable function in theme?

All the documentation I've encountered discusses overriding pluggable function via your plugin.

What if you're doing theme development instead?

My functions.php requires another file that overrides the get_user_by() function, defined in pluggable.php.

If I omit the if( function_exists() ) call I get the "Cannot redeclare..." error.

If I include the if( function exists() ) call, then I get no error, but of course my function is then ignored, since the pluggable version exists.

Based on Dominic's awesome post on the WordPress startup order, it's clear that pluggable.php is loaded before your theme's functions.php and so forth, so that explains the error.

So the question is - how can you take advantage of that nice pluggable architecture from within a theme, without resorting to writing plugins which then must be bundled or installed with the theme?

Source Link
Tom Auger
  • 7.1k
  • 9
  • 62
  • 84
Loading