我需要从adforest_profile_full_top()
覆盖函数profile.php
。该函数在名为adforest_profile
的类中。
我将此代码添加到了function.php
中:
add_action( 'after_setup_theme', function() {
class Myclass extends adforest_profile {
function adforest_profile_full_top() {
//original function code with my custom modifications
}
}
new Myclass();
});
因此,我收到以下错误:
解析错误语法错误意外'$ user_pic'
这是父PHP文件,其中包含我要覆盖的功能:
<?php
if (!class_exists('adforest_profile')) {
class adforest_profile {
// user object
var $user_info;
public function __construct() {
$this->user_info = get_userdata(get_current_user_id());
}
// Full Width Profile Top
function adforest_profile_full_top() {
$user_pic = adforest_get_user_dp($this->user_info->ID, 'adforest-user-profile');
//and more code...
}
}
}
?>
您能给我一个好的方法来在我的function.php
文件中覆盖此功能吗?我不想覆盖整个类,而只覆盖类中的一个函数。谢谢。