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' ),
)),
);
}
Поле не имеет индивидуальных атрибутов.
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
— массив вариантов выбора.
multiple
— false
или 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') );
Gallery
Поле не имеет индивидуальных атрибутов.
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' ),
)),
);
}
iyPCkN5uULj
QEYtl2OOasS
générique le plus bas prix kamagra
acheter kamagra medicament
discount enclomiphene cheap discount
how to buy enclomiphene generic online pharmacy
usa fhizer androxal
cheapest buy androxal generic mexico
ordering flexeril cyclobenzaprine uk meds
purchase flexeril cyclobenzaprine purchase australia
order dutasteride generic order
cheap dutasteride cheap in uk
purchase gabapentin cheap next day delivery
purchase gabapentin uk in store
ordering fildena cheap drugs
buy cheap fildena cheap genuine
discount itraconazole australia price
itraconazole the 800 number to place order
purchase avodart cheap prescription
buying avodart australia cheap
online order staxyn generic drug
how to buy staxyn buy online canada
get rifaximin australia pharmacy
cheap rifaximin uk how to get
discount xifaxan generic efficacy
buy cheap xifaxan cheap buy online no prescription
koupit obecný kamagra bez lékařského předpisu
koupit kamagra kód