Interactive
Interactive

Reputation: 1550

Wordpress/PHP call to undefined function error

I get a call to undefined function error but can't see why.

Fatal error: Call to undefined function stringReplace() in ...z

 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'
    );
}

The idea is to replace text. I don't want to repeat myself a couple of times for every instance it is placed. So the function should change that.

What am I missing?

Upvotes: 0

Views: 78

Answers (1)

John Conde
John Conde

Reputation: 219804

stringReplace is not a function. It is a class method. You must refer to it using the $this keyword:

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

Upvotes: 4

Related Questions