我有一些类似于here.
在第三方插件类中,我们有一个函数,我想通过扩展该类来覆盖它。
原始类函数:
class Import_Facebook_Events_Facebook {
public function get_location( $facebook_event ) {
if ( !isset( $facebook_event->place->id ) ) {
return null;
}
//other code here
}
我尝试了什么,但没有成功(没有效果):
class Import_Facebook_Events_Facebook_Ext extends Import_Facebook_Events_Facebook {
public function get_location( $facebook_event ) {
if ( !isset( $facebook_event->place->id ) ) {
$facebook_event->place->id = \'\'; //added this line
//return null;
}
//other code here
}
new Import_Facebook_Events_Facebook_Ext();
What\'s wrong here? How can I get the desired effect?
原件
Import_Facebook_Events_Facebook()
类是从另一个类实例化的:
class Import_Facebook_Events{
private static $instance;
public static function instance() {
if( ! isset( self::$instance ) && ! (self::$instance instanceof Import_Facebook_Events ) ) {
self::$instance = new Import_Facebook_Events;
self::$instance->facebook = new Import_Facebook_Events_Facebook();
}
return self::$instance;
}
}
上述类是从单独的函数实例化的:
function run_import_facebook_events() {
return Import_Facebook_Events::instance();
}