Site Options plugin

WP Site Options  – это простой и бесплатный инструмент для быстрого программного создания настроек для вашего сайта. Настройки располагаются в меню Настройки – Чтение.

Используйте следующий код, чтобы увидеть работу плагина. Добавьте это в файл функций темы.

    add_action( 'init', 'custom_site_options', 10 );
    function custom_site_options(){
        global $wpto;
	if ( $wpto )
	$wpto->fields = array ( 
	  'section_one'	=> array( array( 'First Settings', 'here description' ), array(
		'f_number' => array( 'number', 'A Number' ),
		'f_text'   => array( 'text', 'Simple text' ),
	  )),
	  'section_two'	=> array( array( 'Additional settings', 'here wow description' ), array(
		'f_gallery' => array( 'gallery', 'Awesome gallery' ),
		'f_chbox'   => array( 'checkbox', 'Are u checked?' ),
	  )),
	);
    }

Вы можете использовать другой хук для подключения настроек вплоть до ‘admin_init’. В случае использования ‘admin_init’ максимальный приоритет подключения к хуку – 49.

Доступ к настройкам в шаблоне

        global $wpto;
        echo $wpto->getOption( 'section_one::f_text' ) ;

Поддерживаемые типы данных

Вам доступны следующие типы:

Значение по умолчанию

Для еще не установленных значений (или значений, равных пустой строке) вы можете определить значение по умолчанию.

$wpto->fields = array ( 
  'section_one'	=> array( array( 'First Settings', 'here description' ), array(
       'f_number'	   => array( 'number', 'A Number', array( 'default' => 100 ) ),
   ))
);

Дополнительные свойства

Для полей, требующих дополнительные параметры, вы можете их указать.

Например, параметр step для поля типа number.

$wpto->fields = array ( 
  'section_one'	=> array( array( 'First Settings', 'here description' ), array(
       'f_number'	   => array( 'number', 'A Number', array( 'step' => 10 ) ),
   ))
);

Для каждого вашего поля, выводимого в администраторской части, вы можете задать общие дополнительные параметры. Например, задать свой css-класс.

$wpto->fields = array ( 
  'section_one'	=> array( array( 'First Settings', 'here description' ), array(
       'f_text'	   => array( 'text', 'Simple text', array( 'default' => 'FooFoo', 'class' => 'custom_class' ) ), )) );

Кроме того, вы можете задать любые особые атрибуты тега input для вывода на странице настроек. Например, зададим текстовому полю дополнительный атрибут ‘data-foo’ со значением ‘bar’. Используем для этого элемент ‘attrs’:

$wpto->fields = array ( 
  'section_one'	=> array( array( 'First Settings', 'here description' ), array(
       'f_text'	   => array( 'text', 'Simple text', array( 'default' => 'FooFoo', 'class' => 'custom_class', 'attrs' => array( 'data-foo' => 'bar' ) ) ), )) );

Теперь поле input выглядит так:

< input type="text"     name="wpto_options[section_one][f_text]"      type="text"      value="FooFoo"      class="section_one-f_text wpto-input custom_class"      id="section_one-f_text"      oninvalid="setCustomValidity( 'Please, check' )"      data-foo="bar"  />  

Однако, используя параметр ‘attrs’, вы не можете переопределять уже заданные атрибуты.

Нет подходящего типа

Используйте фильтр ‘wpto_echo_custom_field’, если вы хотите определить свой собственный тип данных и задать вывод соответствующего тега input.

Text

Поле не имеет индивидуальных атрибутов.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_text'    => array( 'text', 'Simple text' ),
            )),

        );    
    }

E-mail

Поле не имеет индивидуальных атрибутов.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_email'    => array( 'email', 'Your email' ),
            )),

        );    
    }

Wysiwyg

Поле не имеет индивидуальных атрибутов.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_wys'    => array( 'wysiwyg', 'WisualEdit text' ),
            )),

        );    
    }

Checkbox

Поле не имеет индивидуальных атрибутов.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_chb'    => array( 'checkbox', 'Checked?' ),
            )),

        );    
    }

Textarea

Поле не имеет индивидуальных атрибутов.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_ta'    => array( 'textarea', 'Textarea text' ),
            )),

        );    
    }

Number

Поле имеет индивидуальный атрибут step.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_number'    => array( 'number', 'Any digits', array( 'step' => 0.1 ) ),
            )),

        );    
    }

Select

Поле имеет индивидуальные атрибуты.

options — массив вариантов выбора.

multiplefalse или true.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_select'    => array( 'select', 'Selector', array( 
                    'options' => array(
                        array( 'value' => '', 'text' => 'Choose', 'attrs' => array( 'disabled' => 'disabled' ) ),
                        array( 'value' => 'one', 'text' => 'First' ), 
                        array( 'value' => 'two', 'text' => 'Second' ), 
                        array( 'value' => 'three', 'text' => 'Third' )
                    ),
                    'multiple' => true,
                    'default' => 'two'
                ) ),
            )),

        );    
    }

Также как и для всех типов полей, здесь доступен атрибут default.

Photo

Поле не имеет индивидуальных атрибутов.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_photo'    => array( 'photo', 'Select image' ),
            )),

        );    
    }

Доступ к значению поля

            global $wpto;
            echo wp_get_attachment_image( $wpto->getOption('section_two::f_photo') );

Поле не имеет индивидуальных атрибутов.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_gallery'    => array( 'gallery', 'Select images' ),
            )),

        );    
    }

Доступ к значению поля

            global $wpto;
            $gallery = $wpto->getOption('section_two::f_gallery');
            foreach ( $gallery as $one )
                echo wp_get_attachment_image( $one );

Colorpicker

Поле не имеет индивидуальных атрибутов.

    add_action( 'init', 'custom__site_options', 10 );
    function custom__site_options(){
        global $wpto;
        if ( $wpto )
        $wpto->fields = array ( 
            'section_one'    =>    array( array( 'First Settings', 'here description' ), array(
                'f_color'    => array( 'color', 'Select color' ),
            )),

        );    
    }

 

0 0 голоса
Article Rating
Share this post



19 Comments
Сначала старые
Сначала новые По рейтингу
Межтекстовые Отзывы
Посмотреть все комментарии
https://newwavefoods.com/
https://newwavefoods.com/
11 месяцев назад

iyPCkN5uULj

milf ਪੋਰਨ
milf ਪੋਰਨ
11 месяцев назад

QEYtl2OOasS

trackback

générique le plus bas prix kamagra

acheter kamagra medicament

trackback

discount enclomiphene cheap discount

how to buy enclomiphene generic online pharmacy

trackback
5 месяцев назад

usa fhizer androxal

cheapest buy androxal generic mexico

trackback
5 месяцев назад

ordering flexeril cyclobenzaprine uk meds

purchase flexeril cyclobenzaprine purchase australia

trackback
5 месяцев назад

order dutasteride generic order

cheap dutasteride cheap in uk

trackback
5 месяцев назад

purchase gabapentin cheap next day delivery

purchase gabapentin uk in store

trackback
5 месяцев назад

ordering fildena cheap drugs

buy cheap fildena cheap genuine

trackback
5 месяцев назад

discount itraconazole australia price

itraconazole the 800 number to place order

trackback
5 месяцев назад

purchase avodart cheap prescription

buying avodart australia cheap

trackback
5 месяцев назад

online order staxyn generic drug

how to buy staxyn buy online canada

trackback
5 месяцев назад

get rifaximin australia pharmacy

cheap rifaximin uk how to get

trackback
5 месяцев назад

discount xifaxan generic efficacy

buy cheap xifaxan cheap buy online no prescription

trackback
5 месяцев назад

koupit obecný kamagra bez lékařského předpisu

koupit kamagra kód

phlwinph
phlwinph
1 месяц назад

Smart bankroll management is key with any online gaming, honestly. Seeing platforms like phlwin ph app download apk cater to local preferences is interesting – verification steps are a good sign of security, too. Play responsibly!

rubycasino
rubycasino
1 месяц назад

Interesting analysis! The blend of tradition & tech in modern online casinos, like ruby casino app download apk, is fascinating. It’s not just about games, but building a community-something Ruby Casino seems to prioritize!

jilibbbbet
jilibbbbet
12 дней назад

Interesting analysis! Seeing localized platforms like jilibbb bet app casino thrive in the Philippines shows how important tailored experiences are. The focus on both slots and sports is smart – caters to wider tastes!

Kim1332
Kim1332
2 дней назад

Fast indexing of website pages and backlinks on Google https://is.gd/r7kPlC

19
0
Оставьте комментарий! Напишите, что думаете по поводу статьи.x