PluginProbe
Disable Comments & Delete All Comments / trunk
Disable Comments & Delete All Comments vtrunk
1.3.3 1.3.2 trunk 1.0.0 1.0.4 1.0.5 1.0.8 1.0.9 1.1.1 1.1.3 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.3.0 1.3.1
comments-plus / libs / factory / forms / includes / providers / options-value-provider.class.php

options-value-provider.class.php in Disable Comments & Delete All Comments trunk, at libs/factory/forms/includes/providers/options-value-provider.class.php

98 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file contains the class of Factory Option Value Provider.
4 *
5 * @author Alex Kovalev <[email protected]>
6 * @copyright (c) 2018, Webcraftic Ltd
7 *
8 * @package factory-forms
9 * @since 1.0.0
10 */
11 // Exit if accessed directly
12 if( !defined('ABSPATH') ) {
13 exit;
14 }
15
16 if( !class_exists('Wbcr_FactoryForms480_OptionsValueProvider') ) {
17
18 /**
19 * Factory Options Value Provider
20 *
21 * This provide stores form values in the wordpress options.
22 *
23 * @since 1.0.0
24 */
25 class Wbcr_FactoryForms480_OptionsValueProvider implements Wbcr_IFactoryForms480_ValueProvider {
26
27 /**
28 * A prefix that will be added to all option names.
29 *
30 * @since 1.0.0
31 * @var string
32 */
33 public $scope;
34
35 public $plugin;
36
37 /**
38 * Values to save $optionName => $optionValue
39 *
40 * @since 1.0.0
41 * @var mixed[]
42 */
43 private $values = array();
44
45 /**
46 * Creates a new instance of an options value provider.
47 */
48 public function __construct(Wbcr_Factory480_Plugin $plugin)
49 {
50 $this->plugin = $plugin;
51 }
52
53 /**
54 * @since 1.0.0
55 */
56 public function init()
57 {
58 // nothing to do
59 }
60
61 /**
62 * @since 1.0.0
63 */
64 public function saveChanges()
65 {
66 foreach((array)$this->values as $option_name => $option_value) {
67 $this->plugin->updatePopulateOption($option_name, $option_value);
68 }
69 }
70
71 public function getValue($name, $default = null, $multiple = false)
72 {
73 $value = $this->plugin->getPopulateOption($name, $default);
74
75 if( $value === 'true' || $value === true ) {
76 $value = 1;
77 }
78 if( $value === 'false' || $value === false ) {
79 $value = 0;
80 }
81
82 return $value;
83 }
84
85 /**
86 * @param string $name
87 * @param mixed $value
88 */
89 public function setValue($name, $value)
90 {
91 $value = empty($value)
92 ? $value
93 : stripslashes($value);
94
95 $this->values[$name] = $value;
96 }
97 }
98 }