nf/option

1.5.0 2018-10-31 04:52 UTC

This package is auto-updated.

Last update: 2024-08-29 03:58:13 UTC


README

它是我们主题 https://github.com/hieu-pv/nf-theme 的扩展

安装

步骤 1:通过 Composer 安装
composer require nf/option
步骤 2:添加服务提供者

打开 config/app.php 并注册所需的服务提供者。

  'providers'  => [
        // .... Others providers 
        \NightFury\Option\ThemeOptionServiceProvider::class,
    ],
步骤 3:注册选项方案

{提示} 您可以将选项方案添加到 functions.php

{提示} 对于您添加的每个方案,在主题配置页面创建一个新的部分。

use NightFury\Option\Abstracts\Input;
use NightFury\Option\Facades\ThemeOptionManager;

ThemeOptionManager::add([
    'name'   => 'General',
    'fields' => [
        [
            'label'    => 'Text',
            'name'     => 'theme_option_text', // the key of option
            'type'     => Input::TEXT,
            'required' => true,
        ],
        [
            'label'    => 'Textarea',
            'name'     => 'theme_option_text',
            'type'     => Input::TEXTAREA,
            'required' => true,
        ],
        [
            'label'    => 'Email',
            'name'     => 'theme_option_email',
            'type'     => Input::EMAIL,
            'required' => true,
        ],
        [
            'label'       => 'Gallery',
            'name'        => 'theme_option_gallery',
            'type'        => Input::GALLERY,
            'description' => 'We can select multi file. Drag and Drop to re-order content'
        ],
        [
            'label'       => 'Gallery With Meta Field',
            'name'        => 'theme_option_gallery_with_meta',
            'type'        => Input::GALLERY,
            'description' => 'Gallery with meta field, for now we support text and textarea on meta field.',
            'meta'        => [
                [
                    'label' => 'Text',
                    'name'  => 'meta_text',
                    'type'  => Input::TEXT,
                ],
                [
                    'label' => 'Textarea',
                    'name'  => 'meta_textarea',
                    'type'  => Input::TEXTAREA,
                ],
            ],
        ], [
            'label'       => 'Image',
            'name'        => 'theme_option_image',
            'type'        => Input::IMAGE,
            'description' => 'Choose your image by clicking the button bellow',
        ],
        [
            'label'   => 'Select',
            'name'    => 'theme_option_select',
            'type'    => Input::SELECT,
            'options' => [
                [
                    'value'    => 'first',
                    'label'    => 'First Value',
                    'selected' => true,
                ],
                [
                    'value'    => 'second',
                    'label'    => 'Second Value',
                    'selected' => false,
                ],
            ],
        ],
    ],
]);
步骤 4:获取选项值

我们可以通过 get_option 函数通常获取选项的值

{提示} 对于相册值,它是一个解码后的字符串

get_option('{option_name}');