-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The procedural example does not work. #79
Comments
I noticed the same thing. I modified the class to return a Singleton and adapted the corresponding part in my plugin file:
protected function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
return self::$instance;
}
public static function getInstance() {
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
function myplugin_options_page() {
$settings_api = WeDevs_Settings_API::getInstance();
echo '<div class="wrap">';
settings_errors();
$settings_api->show_navigation();
$settings_api->show_forms();
echo '</div>';
}
// in admin_init() function
function myplugin_admin_init() {
// ...
$settings_api = WeDevs_Settings_API::getInstance();
$settings_api->set_sections($sections);
$settings_api->set_fields($fields);
$settings_api->admin_init();
} One has to use |
Thanks for this addition. Using the class in this manner resulted in a fatal error : Fatal error: Uncaught Error: Access to undeclared static property: WeDevs_Settings_API::$instance Which was solved by declaring the property in the class first like |
I cloned this repo and replaced the oop-example include with the procedural file and it does not work.
The way that you just create a new instance make no sense to me but I have not looked at now the class works.
You should actually test it and include a test that is executed by default for it.
The text was updated successfully, but these errors were encountered: