Please note this is all "working" - the question is about the best practice and to try and work out why I need to include the PHP file which contains the class in two places for it to work correctly.
I'm working on a simple parent theme to speed up my own development cycle - and have got to the point of testing a simple child theme.
I understand that the
functions.php file for the child is called up before the parent
functions.php - which includes all the PHP functions and a class for adding CPT's.
I would like to build the CPT from the child theme - I want the parent to contain all the reusable and update-able functionality - but not to pre-build added features into each WP install it's used on.
To the code question:
I tried to include the class (which is in a separate PHP file) in the child
functions.php and then instantiate an instance - for example:
require_once TEMPLATEPATH."/library/cpt/cpt.php"; // CPT class ## $cpt_tree = new Custom_Post_Type( "tree" ); // New CPT - "tree" ##
Reloading the page gives an error:
Fatal error: Class 'Custom_Post_Type' not found in C:\xampp\htdocs\site\wordpress\wp-content\themes\child\functions.php on line 14
So, then I included the same PHP file in the parent
functions.php file - and it all works - as an experiment I removed the class from the child theme - and it gives the same error.
I know this question is lacking lots of code examples - I'm hoping it will ring a bell with someone - or someone who understands more about using Classes will be able to give me some pointers - seems silly to require this file in two places and I'll like to keep the
functions.php file as clean as possible.