src/Page/Page.php
public function configureSettings()
    {
        // If no settings && sections, return.
        $settings = $this->repository()->getSettings();
        $sections = $this->repository()->getSections();

        if ($settings->isEmpty() && $sections->isEmpty()) {
            return;
        }

        // Configure sections.
        $sections->each(function ($section) {
            /** @var SectionInterface $section */
            add_settings_section($section->getId(), $section->getTitle(), [$this, 'renderSections'], $this->getSlug());
        });

        // Configure settings.
        foreach ($settings->all() as $slug => $fields) {
            foreach ($fields as $setting) {
                $setting = $this->prepareSetting($setting);

                // Display the setting.
                add_settings_field(
                    $setting->getName(),
                    $setting->getOption('label'),
                    [$this, 'renderSettings'],
                    $this->getSlug(),
                    $slug,
                    $setting
                );

                // Validate setting.
                $showInRest = $this->isShownInRest();

                if ($setting->getOption('show_in_rest', false)) {
                    $showInRest = true;
                }

                register_setting($this->getSlug(), $setting->getName(), [
                    'sanitize_callback' => [$this, 'sanitizeSetting'],
                    'default' => $setting->getOption('data', ''),
                    'show_in_rest' => $showInRest,
                    'type' => $setting->getOption('data_type', 'string')
                ]);
            }
        }
    }
public function configureSettings()
    {
        // If no settings && sections, return.
        $settings = $this->repository()->getSettings();
        $sections = $this->repository()->getSections();

        if ($settings->isEmpty() && $sections->isEmpty()) {
            return;
        }

        // Configure sections.
        $sections->each(function ($section) {
            /** @var SectionInterface $section */
            add_settings_section($section->getId(), $section->getTitle(), [$this, 'renderSections'], $this->getSlug());
        });

        // Configure settings.
        foreach ($settings->all() as $slug => $fields) {
            foreach ($fields as $setting) {
                $setting = $this->prepareSetting($setting);

                // Display the setting.
                add_settings_field(
                    $setting->getName(),
                    $setting->getOption('label'),
                    [$this, 'renderSettings'],
                    $this->getSlug(),
                    $slug,
                    $setting
                );

                // Validate setting.
                $showInRest = $this->isShownInRest();

                if ($setting->getOption('show_in_rest', false)) {
                    $showInRest = true;
                }

                register_setting($this->getSlug(), $setting->getName(), [
                    'sanitize_callback' => [$this, 'sanitizeSetting'],
                    'default' => $setting->getOption('data', ''),
                    'show_in_rest' => $showInRest,
                    'type' => $setting->getOption('data_type', 'string')
                ]);
            }
        }
    }
public function configureSettings ( ) { // If no settings && sections, return. $ settings = $ this -> repository ( ) -> getSettings ( ) ; $ sections = $ this -> repository ( ) -> getSections ( ) ; if ( $ settings -> isEmpty ( ) && $ sections -> isEmpty ( ) ) { return ; } // Configure sections. $ sections -> each ( function ( $ section ) { /** @var SectionInterface $section */ add_settings_section ( $ section -> getId ( ) , $ section -> getTitle ( ) , [ $ this , 'renderSections' ] , $ this -> getSlug ( ) ) ; } ) ; // Configure settings. foreach ( $ settings -> all ( ) as $ slug => $ fields ) { foreach ( $ fields as $ setting ) { $ setting = $ this -> prepareSetting ( $ setting ) ; // Display the setting. add_settings_field ( $ setting -> getName ( ) , $ setting -> getOption ( 'label' ) , [ $ this , 'renderSettings' ] , $ this -> getSlug ( ) , $ slug , $ setting ) ; // Validate setting. $ showInRest = $ this -> isShownInRest ( ) ; if ( $ setting -> getOption ( 'show_in_rest' , false ) ) { $ showInRest = true ; } register_setting ( $ this -> getSlug ( ) , $ setting -> getName ( ) , [ 'sanitize_callback' => [ $ this , 'sanitizeSetting' ] , 'default' => $ setting -> getOption ( 'data' , '' ) , 'show_in_rest' => $ showInRest , 'type' => $ setting -> getOption ( 'data_type' , 'string' ) ] ) ; } } }
Configure page settings if any.
Called by the "admin_init" hook.
Configure page settings if any . Called by the admin_init hook .