0

I have a problem with php 7 syntax. I installed this plugin called simple table manager https://wordpress.org/plugins/simple-table-manager/

and upon activation I got these warnings

Warning: Use of undefined constant list_all - assumed 'list_all' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\wp2\wp-content\plugins\simple-table-manager\controller.php on line 52

Warning: Use of undefined constant add_new - assumed 'add_new' (this will throw an Error in a future version of PHP) ....

Warning: Use of undefined constant settings - assumed 'settings' (this will throw an Error.....

Warning: Use of undefined constant edit - assumed 'edit' (this will throw an Error.....

the code looks something like this

class Controller {
....

public function add_menu() {
        add_menu_page('Simple Table Manager - List', 'Simple Table Manager', 'manage_options', $this->slug['list'], array($this, list_all ));
        add_submenu_page(null, 'Simple Table Manager - Add New', 'Add New', 'manage_options', $this->slug['add'], array($this, add_new));
        add_submenu_page($this->slug['list'], 'Simple Table Manager - Settings', 'Settings', 'manage_options', $this->slug['settings'], array($this, settings));
        add_submenu_page(null, 'Simple Table Manager - Edit', 'Edit', 'manage_options', $this->slug['edit'], array($this, edit));
    }
public function list_all() {....}
public function add_new() {...}
public function edit() {...}
public function settings() {...}

}

I have php 7, I'm assuming the syntax used by the developer of the plugin is obsolete

so basically the 4 variables giving errors are actually other functions(methods) of the class itself. what is the correct way to call these methods? I tried array($this, $this->add_new) but it didn't work

I will appreciate it if can help with this.

Thanks in advance

1 Answer 1

2

There is a bug in this code:

    add_menu_page('Simple Table Manager - List', 'Simple Table Manager', 'manage_options', $this->slug['list'], array($this, list_all ));

The part array($this, list_all ) is a function callback, but there should be name of a function passed as string as second item in the array. So it should be:

array($this, 'list_all' )

PS. It should have been a problem with earlier versions of PHP too...

1
  • I don't know how to thank you enough! I'm new to php, I thought I should just add () since it was a function, but I was wrong. Thanks a lot
    – user206904
    Commented Jan 28, 2019 at 20:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.