I am overriding a function in a parent theme by placing the below code in my child theme's functions.php
file.
The function works, but it is throwing this error:
Warning: Use of undefined constant THEME_HOOK_PREFIX - assumed 'THEME_HOOK_PREFIX' (this will throw an Error in a future version of PHP) in /Users/myuser/Local Sites/storytime/app/public/wp-content/themes/buddyboss-theme-child/functions.php on line 82
This is the code in my child theme functions.php
:
//Removing the comments section
if ( ! function_exists( 'bjg_buddyboss_theme_single_template_part_content' ) ) {
function bjg_buddyboss_theme_single_template_part_content( $post_type ) {
if ( wp_job_manager_is_post_type() ) :
get_template_part( 'template-parts/content', 'resume' );
elseif ( gamipress_is_post_type() ) :
get_template_part( 'template-parts/content', 'gamipress' );
else :
get_template_part( 'template-parts/content', $post_type );
endif;
}
add_action( THEME_HOOK_PREFIX . '_single_template_part_content', 'bjg_buddyboss_theme_single_template_part_content' );
}
function change_buddyboss_theme_single_template_part_content() {
remove_filter( THEME_HOOK_PREFIX . '_single_template_part_content', 'buddyboss_theme_single_template_part_content' );
add_filter( THEME_HOOK_PREFIX . '_single_template_part_content', 'bjg_buddyboss_theme_single_template_part_content' );
}
add_action( 'after_setup_theme', 'change_buddyboss_theme_single_template_part_content' );
I know that the error is telling me the constant THEME_HOOK_PREFIX
is undefined, but I'm not sure why because I copied (and then slightly modified) the bjg_buddyboss_theme_single_template_part_content
function from the parent theme. So THEME_HOOK_PREFIX
must be defined in the parent theme somewhere because it doesn't throw this error if I remove this code from the child theme.
This is where the constant is defined in the parent theme. The path to this code in the parent theme is buddyboss-theme/inc/init.php
:
/**
* Setup config/global/constants etc variables
*/
private function _setup_globals() {
// Get theme path
$this->_tpl_dir = get_template_directory();
// Get theme url
$this->_tpl_url = get_template_directory_uri();
// Get includes path
$this->_inc_dir = $this->_tpl_dir . '/inc';
if ( !defined( 'BUDDYBOSS_DEBUG' ) ) {
define( 'BUDDYBOSS_DEBUG', false );
}
if ( !defined( 'THEME_TEXTDOMAIN' ) ) {
define( 'THEME_TEXTDOMAIN', $this->lang_domain );
}
if ( !defined( 'THEME_HOOK_PREFIX' ) ) {
define( 'THEME_HOOK_PREFIX', 'buddyboss_theme_' );
}
}
if ( ! defined( 'CONSTANT' ) ) define( CONSTANT, 'value' );