예제 #1
0
<?php

namespace ZeroWP\AdminForm;

zerowp_admin_form_register_field('textarea', __NAMESPACE__ . '\\Textarea');
class Textarea extends Field
{
    public function defaultSettings()
    {
        return array('rows' => 5, 'size' => 'large', 'allow_html' => true);
    }
    public function render()
    {
        //Nuber of rows
        $rows = absint($this->getSetting('rows'));
        $rows = $rows > 0 ? $rows : 5;
        // Input width
        $size = $this->getSetting('size');
        $size_attr = '';
        if (!empty($size) && ($size = trim($size))) {
            if (in_array($size, array('wide', 'widefat', 'large'))) {
                $size_attr = ' class="widefat"';
            } elseif (is_numeric($size)) {
                $size_attr = ' cols="' . absint($size) . '"';
            }
        }
        return '<textarea name="' . $this->getName() . '"' . $size_attr . ' rows="' . $rows . '">' . esc_textarea($this->getValue()) . '</textarea>';
    }
    public function sanitize($value)
    {
        $allow_html = $this->getSetting('allow_html');
예제 #2
0
<?php

namespace ZeroWP\AdminForm;

zerowp_admin_form_register_field('input', __NAMESPACE__ . '\\Input');
class Input extends Field
{
    public function defaultSettings()
    {
        return array('allow_safe_html' => false, 'size' => 'regular', 'type_attr' => 'text', 'text_before' => false, 'text_after' => false);
    }
    public function render()
    {
        // Input type
        $type_attr = $this->getSetting('type_attr');
        $type = 'text';
        if (!empty($type_attr)) {
            if (in_array($type_attr, array('text', 'password', 'email', 'number', 'url'))) {
                $type = $type_attr;
            }
        }
        // Input width
        $size = $this->getSetting('size');
        $size_class = 'regular-text';
        if (!empty($size)) {
            if (in_array($size, array('wide', 'widefat', 'large'))) {
                $size_class = 'widefat';
            } elseif (in_array($size, array('small', 'small-text', 'mini'))) {
                $size_class = 'small-text';
            } elseif ('none' == $size) {
                $size_class = '';