繁体   English   中英

覆盖Wordpress管理功能?

[英]Override Wordpress admin function?

我想覆盖get_sample_permalink_html从可湿性粉剂管理员/ post.php中。 如果我直接修改文件,则更改有效。 但是,我想以一种更简洁的方式来执行此操作,这意味着在插件内进行操作,以确保其面向未来。 这是我在PHP插件文件中尝试过的方法:

add_filter('get_sample_permalink_html', 'custom_get_sample_permalink_html', 1, 3);
function custom_get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
    (...)
}

它在不显示错误的情况下中断了页面,我该怎么办?

好吧,该函数具有一个过滤器,您可以使用它,而不是“覆盖”该函数,而是操纵其输出:

$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);

因此,您需要以下内容:

add_filter( 'get_sample_permalink_html', 'custom_get_sample_permalink_html', 15, 4 );

function custom_get_sample_permalink_html( $return, $id, $new_title, $new_slug )
{
    // Manipulate the $return as you wish, using your own stuff and the passed variables:
    // $id, $new_title, $new_slug

    return $return;
}

15是优先级,表示:“将其放在最后一个可能的位置”,如有必要,可以增加它。
4是函数接收的参数数量,已在原始apply_filters调用中检查。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM