• Hi guys,

    This post relates to a project I’m doing for work, so I can’t post any production code… However, it seems pretty straight forward so I think it’s just my lack of PHP knowledge. Maybe one of you WP gurus will be able to point me in the right direction!

    What I’m trying to do is put a PHP class in my parent theme’s functions.php file which will create custom fields, and then create new instances of this class in my child theme’s functions.php files allowing my child themes to have different custom fields from eachother. The problem is when I call the class from the child theme, it is undefined…

    So this is basically what I have in my parent theme:

    if ( !class_exists('myClass') ) {
    	class myClass {
    		/* blah blah blah */
    	}
    }

    Then in my child theme:

    if ( class_exists('myClass') ) {
    	$var1 = 'blah';
    	$var2 = 'blah';
    	$myClassVar = new myClass($var1, $var2);
    }

    But in the child theme, class_exists(‘myClass’) is false… Anybody know what may be going on here?

    Thanks!
    – Adam

  • The topic ‘PHP class in parent theme functions.php…’ is closed to new replies.