0

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?

2
  • 2
    It should be $this->stringReplace instead of just calling stringReplace. Commented Mar 19, 2018 at 13:25
  • 1
    @nickb That was it. Big Thnx Commented Mar 19, 2018 at 13:26

1 Answer 1

4

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'
    );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.