first commit
This commit is contained in:
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of WordPress Settings UI.
|
||||
*
|
||||
* Copyright 2017-2018 Peter Putzer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* ***
|
||||
*
|
||||
* @package mundschenk-at/wp-settings-ui
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
namespace Avatar_Privacy\Vendor\Mundschenk\UI\Controls;
|
||||
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\Data_Storage\Options;
|
||||
/**
|
||||
* HTML <input> element.
|
||||
*/
|
||||
class Checkbox_Input extends Input
|
||||
{
|
||||
/**
|
||||
* Create a new input control object.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Optional. Section ID. Default Tab ID.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* @type array $outer_attributes Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public function __construct(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
$args['input_type'] = 'checkbox';
|
||||
$args['sanitize_callback'] = 'boolval';
|
||||
parent::__construct($options, $options_key, $id, $args);
|
||||
}
|
||||
/**
|
||||
* Retrieves the value markup for this input.
|
||||
*
|
||||
* @param mixed $value The input value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_value_markup($value)
|
||||
{
|
||||
return 'value="1" ' . \checked($value, \true, \false);
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of WordPress Settings UI.
|
||||
*
|
||||
* Copyright 2018 Peter Putzer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* ***
|
||||
*
|
||||
* @package mundschenk-at/wp-settings-ui
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
namespace Avatar_Privacy\Vendor\Mundschenk\UI\Controls;
|
||||
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Abstract_Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\Data_Storage\Options;
|
||||
/**
|
||||
* A control displaying read-only text.
|
||||
*/
|
||||
class Display_Text extends Abstract_Control
|
||||
{
|
||||
const ALLOWED_ATTRIBUTES = ['id' => [], 'name' => [], 'class' => [], 'aria-describedby' => []];
|
||||
const ALLOWED_HTML = ['div' => self::ALLOWED_ATTRIBUTES, 'span' => self::ALLOWED_ATTRIBUTES, 'p' => self::ALLOWED_ATTRIBUTES, 'ul' => self::ALLOWED_ATTRIBUTES, 'ol' => self::ALLOWED_ATTRIBUTES, 'li' => self::ALLOWED_ATTRIBUTES, 'a' => ['class' => [], 'href' => [], 'rel' => [], 'target' => []], 'code' => [], 'strong' => [], 'em' => [], 'sub' => [], 'sup' => []];
|
||||
/**
|
||||
* The HTML elements to display.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $elements;
|
||||
/**
|
||||
* Create a new input control object.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $input_type HTML input type ('checkbox' etc.). Required.
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Optional. Section ID. Default Tab ID.
|
||||
* @type array $elements The HTML elements to display (including the outer tag). Required.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* @type array $outer_attributes Optional. Default [],
|
||||
* @type array $settings_args Optional. Default [],
|
||||
* }
|
||||
*/
|
||||
protected function __construct(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
$args = $this->prepare_args($args, ['elements']);
|
||||
$this->elements = $args['elements'];
|
||||
$sanitize = function () {
|
||||
return '';
|
||||
};
|
||||
parent::__construct($options, $options_key, $id, $args['tab_id'], $args['section'], '', $args['short'], null, $args['help_text'], $args['inline_help'], $args['attributes'], $args['outer_attributes'], $args['settings_args'], $sanitize);
|
||||
}
|
||||
/**
|
||||
* Retrieves the current value for the control. In this case, the method always returns ''.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
* Retrieves the control-specific HTML markup.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected function get_element_markup()
|
||||
{
|
||||
return \wp_kses(\implode('', $this->elements), self::ALLOWED_HTML);
|
||||
}
|
||||
/**
|
||||
* Creates a new input control, provided the concrete subclass constructors follow
|
||||
* this methods signature.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Section ID. Required.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type array $option_values The allowed values. Required.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @return Control
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public static function create(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
return new static($options, $options_key, $id, $args);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of WordPress Settings UI.
|
||||
*
|
||||
* Copyright 2017-2018 Peter Putzer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* ***
|
||||
*
|
||||
* @package mundschenk-at/wp-settings-ui
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
namespace Avatar_Privacy\Vendor\Mundschenk\UI\Controls;
|
||||
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\Data_Storage\Options;
|
||||
/**
|
||||
* HTML <input> element.
|
||||
*/
|
||||
class Hidden_Input extends Input
|
||||
{
|
||||
/**
|
||||
* Create a new input control object.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Optional. Section ID. Default Tab ID.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* @type array $outer_attributes Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public function __construct(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
$args['input_type'] = 'hidden';
|
||||
$args['label'] = null;
|
||||
$args['help_text'] = null;
|
||||
$args['inline_help'] = \false;
|
||||
parent::__construct($options, $options_key, $id, $args);
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of WordPress Settings UI.
|
||||
*
|
||||
* Copyright 2017-2018 Peter Putzer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* ***
|
||||
*
|
||||
* @package mundschenk-at/wp-settings-ui
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
namespace Avatar_Privacy\Vendor\Mundschenk\UI\Controls;
|
||||
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Abstract_Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\Data_Storage\Options;
|
||||
/**
|
||||
* HTML <input> element.
|
||||
*/
|
||||
abstract class Input extends Abstract_Control
|
||||
{
|
||||
/**
|
||||
* The input type ('checkbox', ...).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $input_type;
|
||||
/**
|
||||
* Create a new input control object.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $input_type HTML input type ('checkbox' etc.). Required.
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Optional. Section ID. Default Tab ID.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* @type array $outer_attributes Optional. Default [],
|
||||
* @type array $settings_args Optional. Default [],
|
||||
* }
|
||||
*/
|
||||
protected function __construct(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
$args = $this->prepare_args($args, ['input_type', 'tab_id', 'default']);
|
||||
$this->input_type = $args['input_type'];
|
||||
$sanitize = isset($args['sanitize_callback']) ? $args['sanitize_callback'] : 'sanitize_text_field';
|
||||
parent::__construct($options, $options_key, $id, $args['tab_id'], $args['section'], $args['default'], $args['short'], $args['label'], $args['help_text'], $args['inline_help'], $args['attributes'], $args['outer_attributes'], $args['settings_args'], $sanitize);
|
||||
}
|
||||
/**
|
||||
* Retrieves the value markup for this input.
|
||||
*
|
||||
* @param mixed $value The input value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_value_markup($value)
|
||||
{
|
||||
return $value ? 'value="' . \esc_attr($value) . '" ' : '';
|
||||
}
|
||||
/**
|
||||
* Retrieves the control-specific HTML markup.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected function get_element_markup()
|
||||
{
|
||||
return '<input type="' . \esc_attr($this->input_type) . '" ' . "{$this->get_id_and_class_markup()} {$this->get_value_markup($this->get_value())}/>";
|
||||
}
|
||||
/**
|
||||
* Creates a new input control, provided the concrete subclass constructors follow
|
||||
* this methods signature.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Section ID. Required.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type array $option_values The allowed values. Required.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @return Control
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public static function create(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
return new static($options, $options_key, $id, $args);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of WordPress Settings UI.
|
||||
*
|
||||
* Copyright 2017-2018 Peter Putzer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* ***
|
||||
*
|
||||
* @package mundschenk-at/wp-settings-ui
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
namespace Avatar_Privacy\Vendor\Mundschenk\UI\Controls;
|
||||
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\Data_Storage\Options;
|
||||
/**
|
||||
* HTML <input> element.
|
||||
*/
|
||||
class Number_Input extends Input
|
||||
{
|
||||
/**
|
||||
* Create a new input control object.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Optional. Section ID. Default Tab ID.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* @type array $outer_attributes Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public function __construct(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
$args['input_type'] = 'number';
|
||||
$args['sanitize_callback'] = function ($value) {
|
||||
return $value + 0;
|
||||
};
|
||||
parent::__construct($options, $options_key, $id, $args);
|
||||
}
|
||||
/**
|
||||
* Render the value markup for this input.
|
||||
*
|
||||
* @param mixed $value The input value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_value_markup($value)
|
||||
{
|
||||
// Include 0 values.
|
||||
return 'value="' . \esc_attr($value) . '" ';
|
||||
}
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of WordPress Settings UI.
|
||||
*
|
||||
* Copyright 2017-2018 Peter Putzer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* ***
|
||||
*
|
||||
* @package mundschenk-at/wp-settings-ui
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
namespace Avatar_Privacy\Vendor\Mundschenk\UI\Controls;
|
||||
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Abstract_Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\Data_Storage\Options;
|
||||
/**
|
||||
* HTML <select> element.
|
||||
*/
|
||||
class Select extends Abstract_Control
|
||||
{
|
||||
/**
|
||||
* The selectable values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $option_values;
|
||||
/**
|
||||
* Create a new select control object.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Optional. Section ID. Default Tab ID.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type array $option_values The allowed values. Required.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* @type array $outer_attributes Optional. Default [],
|
||||
* @type array $settings_args Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public function __construct(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
$args = $this->prepare_args($args, ['tab_id', 'default', 'option_values']);
|
||||
$sanitize = $args['sanitize_callback'] ?: 'sanitize_text_field';
|
||||
$this->option_values = $args['option_values'];
|
||||
parent::__construct($options, $options_key, $id, $args['tab_id'], $args['section'], $args['default'], $args['short'], $args['label'], $args['help_text'], $args['inline_help'], $args['attributes'], $args['outer_attributes'], $args['settings_args'], $sanitize);
|
||||
}
|
||||
/**
|
||||
* Set selectable options.
|
||||
*
|
||||
* @param array $option_values An array of VALUE => DISPLAY.
|
||||
*/
|
||||
public function set_option_values(array $option_values)
|
||||
{
|
||||
$this->option_values = $option_values;
|
||||
}
|
||||
/**
|
||||
* Retrieve the current value for the select control.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
$config = $this->options->get($this->options_key);
|
||||
$value = $config[$this->id];
|
||||
// Make sure $value is in $option_values if $option_values is set.
|
||||
if (isset($this->option_values) && !isset($this->option_values[$value])) {
|
||||
$value = null;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
/**
|
||||
* Retrieves the control-specific HTML markup.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_element_markup()
|
||||
{
|
||||
$select_markup = "<select {$this->get_id_and_class_markup()}>";
|
||||
$value = $this->get_value();
|
||||
foreach ($this->option_values as $option_value => $display) {
|
||||
$select_markup .= '<option value="' . \esc_attr($option_value) . '" ' . \selected($value, $option_value, \false) . '>' . \esc_html($display) . '</option>';
|
||||
}
|
||||
$select_markup .= '</select>';
|
||||
return $select_markup;
|
||||
}
|
||||
/**
|
||||
* Sanitizes an option value.
|
||||
*
|
||||
* @param mixed $value The unslashed post variable.
|
||||
*
|
||||
* @return string The sanitized value.
|
||||
*/
|
||||
public function sanitize_value($value)
|
||||
{
|
||||
return \sanitize_text_field($value);
|
||||
}
|
||||
/**
|
||||
* Creates a new select control
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Section ID. Required.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type array $option_values The allowed values. Required.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @return Control
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public static function create(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
return new static($options, $options_key, $id, $args);
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of WordPress Settings UI.
|
||||
*
|
||||
* Copyright 2017-2018 Peter Putzer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* ***
|
||||
*
|
||||
* @package mundschenk-at/wp-settings-ui
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
namespace Avatar_Privacy\Vendor\Mundschenk\UI\Controls;
|
||||
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\Data_Storage\Options;
|
||||
/**
|
||||
* HTML <input> element.
|
||||
*/
|
||||
class Submit_Input extends Input
|
||||
{
|
||||
/**
|
||||
* Optional HTML class for buttons.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $button_class;
|
||||
/**
|
||||
* Optional button label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $button_label;
|
||||
/**
|
||||
* Create a new input control object.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Optional. Section ID. Default Tab ID.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type string $button_class Required.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. The actual button label. Default null (browser dependant).
|
||||
* @type array $attributes Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public function __construct(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
// Ensure that there is a button class argument.
|
||||
$args = $this->prepare_args($args, ['button_class']);
|
||||
// Ensure proper button label handling.
|
||||
$this->button_label = $args['label'];
|
||||
$args['label'] = null;
|
||||
// Force these addtional arguments.
|
||||
$args['input_type'] = 'submit';
|
||||
// Store button class attribute.
|
||||
$this->button_class = $args['button_class'];
|
||||
// Call parent.
|
||||
parent::__construct($options, $options_key, $id, $args);
|
||||
}
|
||||
/**
|
||||
* Retrieve the current button name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
return $this->button_label;
|
||||
}
|
||||
/**
|
||||
* Markup ID and class(es).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_id_and_class_markup()
|
||||
{
|
||||
return parent::get_id_and_class_markup() . ' class="' . \esc_attr($this->button_class) . '"';
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of WordPress Settings UI.
|
||||
*
|
||||
* Copyright 2019 Peter Putzer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* ***
|
||||
*
|
||||
* @package mundschenk-at/wp-settings-ui
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
namespace Avatar_Privacy\Vendor\Mundschenk\UI\Controls;
|
||||
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\Data_Storage\Options;
|
||||
/**
|
||||
* HTML <input> element.
|
||||
*/
|
||||
class Text_Input extends Input
|
||||
{
|
||||
/**
|
||||
* Create a new input control object.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Optional. Section ID. Default Tab ID.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* @type array $outer_attributes Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public function __construct(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
$args['input_type'] = 'text';
|
||||
parent::__construct($options, $options_key, $id, $args);
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of WordPress Settings UI.
|
||||
*
|
||||
* Copyright 2017-2018 Peter Putzer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* ***
|
||||
*
|
||||
* @package mundschenk-at/wp-settings-ui
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
namespace Avatar_Privacy\Vendor\Mundschenk\UI\Controls;
|
||||
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\UI\Abstract_Control;
|
||||
use Avatar_Privacy\Vendor\Mundschenk\Data_Storage\Options;
|
||||
/**
|
||||
* HTML <textarea> element.
|
||||
*/
|
||||
class Textarea extends Abstract_Control
|
||||
{
|
||||
/**
|
||||
* Create a new textarea control object.
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Optional. Section ID. Default Tab ID.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type string $short Optional. Short label.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* @type array $outer_attributes Optional. Default [],
|
||||
* @type array $settings_args Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public function __construct(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
$args = $this->prepare_args($args, ['tab_id', 'default']);
|
||||
$sanitize = 'sanitize_textarea_field';
|
||||
parent::__construct($options, $options_key, $id, $args['tab_id'], $args['section'], $args['default'], $args['short'], $args['label'], $args['help_text'], \false, $args['attributes'], $args['outer_attributes'], $args['settings_args'], $sanitize);
|
||||
}
|
||||
/**
|
||||
* Retrieves the control-specific HTML markup.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected function get_element_markup()
|
||||
{
|
||||
$value = $this->get_value();
|
||||
$value = !empty($value) ? \esc_textarea($value) : '';
|
||||
return "<textarea class=\"large-text\" {$this->get_id_and_class_markup()}>{$value}</textarea>";
|
||||
}
|
||||
/**
|
||||
* Creates a new textarea control
|
||||
*
|
||||
* @param Options $options Options API handler.
|
||||
* @param string $options_key Database key for the options array. Passing '' means that the control ID is used instead.
|
||||
* @param string $id Control ID (equivalent to option name). Required.
|
||||
* @param array $args {
|
||||
* Optional and required arguments.
|
||||
*
|
||||
* @type string $tab_id Tab ID. Required.
|
||||
* @type string $section Section ID. Required.
|
||||
* @type string|int $default The default value. Required, but may be an empty string.
|
||||
* @type array $option_values The allowed values. Required.
|
||||
* @type string|null $short Optional. Short label. Default null.
|
||||
* @type string|null $label Optional. Label content with the position of the control marked as %1$s. Default null.
|
||||
* @type string|null $help_text Optional. Help text. Default null.
|
||||
* @type bool $inline_help Optional. Display help inline. Default false.
|
||||
* @type array $attributes Optional. Default [],
|
||||
* }
|
||||
*
|
||||
* @return Control
|
||||
*
|
||||
* @throws \InvalidArgumentException Missing argument.
|
||||
*/
|
||||
public static function create(Options $options, $options_key, $id, array $args)
|
||||
{
|
||||
return new static($options, $options_key, $id, $args);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user