簡體   English   中英

Wordpress / PHP調用未定義函數錯誤

[英]Wordpress/PHP call to undefined function error

我收到call to undefined function錯誤的call to undefined function但看不到原因。

致命錯誤:在... z中調用未定義的函數stringReplace()

 public function stringReplace($newName){
    strtolower(preg_replace('/-+/', '-', preg_replace('/[^\wáéíóú]/', '-', $newName)));
}

public function add(){
    add_meta_box(
        stringReplace($this->CMB_Name),
        __( $this->CMB_Name, 'plugin' ),
        array( $this, 'display' ),
        'page',
        'normal',
        'low'
    );
}

這個想法是要替換文本。 對於每個放置的實例,我都不想重復幾次。 因此,該功能應對此進行更改。

我想念什么?

stringReplace不是函數。 這是一個類方法 您必須使用$this關鍵字引用它:

public function add(){
    add_meta_box(
        $this->stringReplace($this->CMB_Name),
        __( $this->CMB_Name, 'plugin' ),
        array( $this, 'display' ),
        'page',
        'normal',
        'low'
    );
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM