如何用插件的自定义版本替换插件中的函数。
插件的原始功能是:
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);
}
我想更改的日期格式
$end_date
. 类似“jS M Y”的东西。
我试过这个:
创建了新文件:custom-date-planner.php
并更改了日期格式。
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);
}
接下来是我的功能。php我做到了:
// 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\' );
}
通过这次跑步,我得到了一个通知:
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
我怎样才能让它工作?