php - Is there any downside to making a theme fully pluggable?

admin2025-05-31  0

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 2 days ago.

Improve this question
if ( !function_exists( 'my_function' ) ) {
    // do function
}

I'm not sure why, but it never occurred to me before to make a theme fully pluggable so that it's easier for people to customize with a child theme.

That's obviously an upside, but are there any downsides, other than more code? Does it make loading noticeably slower? Does it break anything or cause any other quirks? Are there any functions that can't or shouldn't be made pluggable?

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 2 days ago.

Improve this question
if ( !function_exists( 'my_function' ) ) {
    // do function
}

I'm not sure why, but it never occurred to me before to make a theme fully pluggable so that it's easier for people to customize with a child theme.

That's obviously an upside, but are there any downsides, other than more code? Does it make loading noticeably slower? Does it break anything or cause any other quirks? Are there any functions that can't or shouldn't be made pluggable?

Share Improve this question asked May 25 at 11:47 WPdummyWPdummy 235 bronze badges 3
  • 2 if a parent themes functions.php loads first, then you can't "plug" those functions in a child theme, pluggable functions is something core used in the earlier days but is kept for back-compat, newer development relies on actions and filters instead. Keep in mind as well this is a QA site, not a discussion forum, you need the question to be fully answerable, not just a dicussion of opinions but the factually correct answer – Tom J Nowell Commented May 25 at 12:07
  • The problem with making a theme fully pluggable, regardless of what method you use, is that you're now committed to supporting compatibility for any extensions somebody has made. Did you change how a function works? Well now you've broken any site that replaced that function assuming that it worked the old way. – Jacob Peattie Commented May 26 at 8:34
  • @TomJNowell I considered that, but I feel this question has a more objective answer than subjective, so better to ask and be wrong than to not even try at all. In any case, I do feel like I got a definitive answer: yes, there are downsides, especially if not implemented/maintained correctly. – WPdummy Commented May 26 at 17:35
Add a comment  | 

1 Answer 1

Reset to default 2

The right way to do this would be

function my_function() {
  
  $my_data = apply_filters('my_filter', $my_data);

  return $my_data;

}

Anyone who wants to override your function can then do so by hooking to my_filter without having to worry about whether their file is executed before yours.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748626338a313621.html

最新回复(0)