I have something similar as here.
In a third party plugin class we have a function that I want to override by extending that class.
The original class function:
class Import_Facebook_Events_Facebook {
public function get_location( $facebook_event ) {
if ( !isset( $facebook_event->place->id ) ) {
return null;
}
//other code here
}
What I tried, but this didn't work (no effect):
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?
The original Import_Facebook_Events_Facebook()
class is instantiated from another class:
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;
}
}
And the above class is instantiated from a separate function:
function run_import_facebook_events() {
return Import_Facebook_Events::instance();
}
Import_Facebook_Events::$instance = Import_Facebook_Events_Ext::instance();
... otherwise you'd have to keep going back to what runsrun_import_facebook_events
to see if you can override at that top level.This page isn’t working. infopsi.md is currently unable to handle this request. HTTP ERROR 500
screen.