Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress-覆盖插件类函数_Php_Wordpress_Class_Object_Extend - Fatal编程技术网

Php Wordpress-覆盖插件类函数

Php Wordpress-覆盖插件类函数,php,wordpress,class,object,extend,Php,Wordpress,Class,Object,Extend,我正在使用一个名为SEO Ultimate的插件,其中包含以下类: class SU_Titles extends SU_Module { function init() { ...... } function change_title_tag($head) { ...... } ...... } 我想覆盖函数change\u title\u tag,并已使用以下代码成功覆盖该函数: Class SU_Titles_Ext

我正在使用一个名为SEO Ultimate的插件,其中包含以下类:

class SU_Titles extends SU_Module {
    function init() {
        ......
    }
    function change_title_tag($head) {
        ......
    }
    ......
}
我想覆盖函数
change\u title\u tag
,并已使用以下代码成功覆盖该函数:

Class SU_Titles_Extended extends SU_Titles
{
    function change_title_tag($head) {

        $title = $this->get_title();
        if (!$title) return $head;
        // Pre-parse the title replacement text to escape the $ ($n backreferences) when followed by a number 0-99 because of preg_replace issue
        $title = preg_replace('/\$(\d)/', '\\\$$1', $title);
        //Replace the old title with the new and return
        $title = do_shortcode($title);
        $title .= "<!--- IF YOU CAN SEE THIS, IT IS WORKING -->";
        return preg_replace('/<title>[^<]*<\/title>/i', '<title>'.$title.'</title>', $head);
    }
}

remove_action( 'after_setup_theme', array( 'SU_Titles', 'change_title_tag' ) );
add_action( 'after_setup_theme', array( 'SU_Titles_Extended', 'change_title_tag' ), 99 );
Class SU\u Titles\u Extended扩展SU\u Titles
{
功能更改\标题\标签($head){
$title=$this->get_title();
如果(!$title)返回$head;
//由于preg_replace问题,当后跟数字0-99时,预分析标题替换文本以转义$($n backreferences)
$title=preg\u replace('/\$(\d)/','\\$$1',$title);
//将旧标题替换为新标题并返回
$title=do_短代码($title);
$title.=”;

return preg_replace('/[^最简单的方法是让插件作者添加一个
apply_filter()
操作原始区域函数的返回值,这样您就可以连接到该函数中。我想您现在的问题是,您正在删除所需的引用。要实现这一点,您需要将
SU_Titles
类型的对象更改为
SU_Titles_Extended
类型的对象,最简单的方法是询问插件作者需要向原始函数的返回值添加一个
apply_filter()
操作,这样您就可以钩住它了。现在的问题是,我想您正在删除所需的引用。要实现这一点,您需要将
SU_Titles
类型的对象更改为
SU_Titles\u Extended