When trying to activate my plugin, wordpress comes up with this error:
Plugin could not be activated because it triggered a fatal error. Parse error: syntax error, unexpected T_FUNCTION on line 79
The line 79 is the first line of the snippet below, from looking into this I think it is because of a PHP version error, since I have no control over updating php, how would I make it compatible with earlier versions?
add_action('admin_menu', function(){
Plugin_Options::add_menu_page();
});
Most likely, your PHP version is < 5.3. Anonymous functions were added to PHP in 5.3. In order to make use of this, you can pass the function as a callback string like:
function add_menu_callback() {
Plugin_Options::add_menu_page();
}
add_action('admin_menu', 'add_menu_callback');
Your plugin requires PHP version 5.3.x for function
, earlier versions of PHP give you that syntax error message.
Wordpress does not offer a mechanism to make plugins tell which dependency they need so they need to be activated and care on their own (or just fail as in your case).
You can just add it this way instead:
add_action('admin_menu', 'Plugin_Options::add_menu_page');
And done. That's a static class method call (As of PHP 5.2.3, Type 4 callable in the Callback ExampleDocs), PHP 5.2.3 is within the minimum PHP version requirements of wordpress (that's since WordPress 3.1), so this looks like the preferred method.