Giter VIP home page Giter VIP logo

Comments (2)

gruentee avatar gruentee commented on June 25, 2024 2

I noticed the same thing. I modified the class to return a Singleton and adapted the corresponding part in my plugin file:

class.settings-api.php:

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

myplugin.php:

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 WeDevs_Settings_API::getInstance() in the options_page() function because otherwise the initial data from init function is not used.

from wordpress-settings-api-class.

sanderdewijs avatar sanderdewijs commented on June 25, 2024

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
private static $instance;

from wordpress-settings-api-class.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.