offbeatwp/acf-sitesettings

Use ACF for OffbeatWP's site settings

Installs: 10 291

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:offbeatwp-service

1.2.0 2024-05-22 09:54 UTC

README

Install by running this command from the root of your OffbeatWP Theme:

composer require offbeatwp/acf-sitesettings

Next add the following line to your config/services.php file:

OffbeatWP\AcfSiteSettings\Service::class,

Adding a page

A page is an subpage with settings.

You can register a page by injecting the SiteSetting contract to your service and run the addPage method, like:

<?php
namespace OffbeatWP\Services;

use OffbeatWP\Contracts\SiteSettings;

class ServiceScripts extends AbstractService
{
    protected $settings;

    public function register(SiteSettings $settings)
    {
        $settings->addPage(\OffbeatWP\SiteSettings\SettingsScripts::class);
    }
}

The addPage method accepts a class. A Settings class looks like this:

<?php
namespace OffbeatWP\SiteSettings;

class SettingsScripts
{
    const ID = 'scripts';
    const PRIORITY = 90;

    public function title()
    {
        return __('Scripts', 'raow');
    }

    public function form()
    {
        $form = new \OffbeatWP\Form\Form();

        $form ->addField(\OffbeatWP\Form\Fields\TextArea::make('scripts_head', 'Head'));
        $form ->addField(\OffbeatWP\Form\Fields\TextArea::make('scripts_open_body', 'Body open'));
        $form ->addField(\OffbeatWP\Form\Fields\TextArea::make('scripts_footer', 'Footer'));

        return $form;
    }
}

Read more about Forms