How can I replace a function from a plugin with a custom version of it.
The original function of the plugin is:
function sep_get_the_event_end_date($post = NULL) {
$post = get_post($post);
if ($post->post_type !== 'event_listing') {
return;
}
$event_xml = get_post_meta(get_the_ID(), 'event_meta', TRUE);
$xml_object = new SimpleXMLElement($event_xml);
$end_date = isset($xml_object->end_date) ? $xml_object->end_date : '';
$event_date = isset($xml_object->event_date) ? $xml_object->event_date : '';
if (isset($end_date) and '' $end_date and 'checked' $event_date) {
$end_date = isset($xml_object->end_date) ? $xml_object->end_date : '';
$end_date = new DateTime($end_date);
$end_date = date_format($end_date, 'F d, Y');
} else {
$end_date = '';
}
return apply_filters('sep_the_event_end_date', $end_date, $post);
}
I want to change the date format of $end_date. Something like 'jS M Y'.
I tried this:
Created a new file: custom-date-planner.php and changed the date format.
function custom_sep_get_the_event_end_date($post = NULL) {
$post = get_post($post);
if ($post->post_type !== 'event_listing') {
return;
}
$event_xml = get_post_meta(get_the_ID(), 'event_meta', TRUE);
$xml_object = new SimpleXMLElement($event_xml);
$end_date = isset($xml_object->end_date) ? $xml_object->end_date : '';
$event_date = isset($xml_object->event_date) ? $xml_object->event_date : '';
if (isset($end_date) and '' $end_date and 'checked' $event_date) {
$end_date = isset($xml_object->end_date) ? $xml_object->end_date : '';
$end_date = new DateTime($end_date);
$end_date = date_format($end_date, 'd M, Y');
} else {
$end_date = '';
}
return apply_filters('custom_sep_the_event_end_date', $end_date, $post);
}
Next in my functions.php I did this:
// Add file
require_once(get_stylesheet_directory() . '/public/partials/custom-date-planner.php');
add_action( 'after_setup_theme', 'child_theme_setup', 100 );
function child_theme_setup() {
remove_action( 'sep_the_event_end_date', 'sep_get_the_event_end_date' );
add_action( 'sep_the_event_end_date', 'custom_sep_get_the_event_end_date' );
}
With this running, I get the notice:
Notice: Trying to get property of non-object in /private/var/www/fashion/data/web/public/wp-content/themes/furnde-child/public/partials/custom-date-planner.php on line 4
How can I get this to work?