Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Hooks - Actions and Filters An Overview of Hooks in WordPress Working with $wp_filter

Lewis Cowles
Lewis Cowles
74,902 Points

Could you please put forward this alternative way of including different php files in our functions.php?

So basically at my business we use a similar method to your require_once, but it's a little easier to manage for site-managers who cannot code. we use the glob function to match "{$path}/*.inc.php", so if we want to de-activate or turn off a feature we can simply re-name the feature.

The other benefit of this is you can specify a priority by appending a priority number to the file so

  • 01-something.inc.php
  • 03-something-not-needed.php
  • 05-something-needs-something.inc.php

would inculde 01 & 05. This is inspired by unix priorities initially from init-scripts, but now used with many apache, php, and other systems extensions on ubuntu and debian

Finally using this structure you can then build $path from an array of locations, such as the below

  • {$themedir}/ext/theme_support
  • {$themedir}/ext/helpers
  • {$themedir}/lib/deps

It's very helpful for non PHP wordpressers and can also be hugely helpful to PHP programmers, I suppose the only downside being a slight lack of control if the server is vulnerable to uploads (which it shouldn't be anyway)