PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.0.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.0.0
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Plugins / Html / Field.php
embedpress / EmbedPress / Plugins / Html Last commit date
Field.php 5 years ago index.html 7 years ago
Field.php
183 lines
1 <?php
2
3 namespace EmbedPress\Plugins\Html;
4
5 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
6
7 /**
8 * Entity responsible to generating and rendering html fields to the settings page.
9 *
10 * @package EmbedPress
11 * @author EmbedPress <help@embedpress.com>
12 * @copyright Copyright (C) 2020 WPDeveloper. All rights reserved.
13 * @license GPLv3 or later
14 * @since 1.4.0
15 */
16 class Field
17 {
18 /**
19 * Generates a number type input.
20 *
21 * @param $value
22 *
23 * @return string
24 * @since 2.7.5
25 * @access protected
26 * @static
27 */
28 protected static function number($value)
29 {
30 return '<input type="number" name="embedpress:{{slug}}[{{name}}]" class="{{classes}}" placeholder="{{placeholder}}" value="' . (int)$value . '">';
31
32 }
33
34 /**
35 * Generates a url type input.
36 *
37 * @param $value
38 *
39 * @return string
40 * @since 2.7.5
41 * @access protected
42 * @static
43 */
44 protected static function url($value)
45 {
46 return '<input type="url" name="embedpress:{{slug}}[{{name}}]" class="{{classes}}" placeholder="{{placeholder}}" value="' . (string)$value . '">';
47
48 }
49 /**
50 * Generates a text type input.
51 *
52 * @since 1.4.0
53 * @access protected
54 * @static
55 *
56 * @return string
57 */
58 protected static function text($value)
59 {
60 return '<input type="text" name="embedpress:{{slug}}[{{name}}]" class="{{classes}}" placeholder="{{placeholder}}" value="' . (string)$value . '">';
61 }
62
63 /**
64 * Generates a textarea input.
65 *
66 * @since 1.4.0
67 * @access protected
68 * @static
69 *
70 * @return string
71 */
72 protected static function textarea($value)
73 {
74 return '<textarea name="embedpress:{{slug}}[{{name}}]" class="{{classes}}" placeholder="{{placeholder}}">' . (string)$value . '</textarea>';
75 }
76
77 /**
78 * Generates a radio type input.
79 *
80 * @since 1.4.0
81 * @access protected
82 * @static
83 *
84 * @return string
85 */
86 protected static function radio($options, $value = null)
87 {
88 $html = [];
89
90 foreach ((array)$options as $optionValue => $optionLabel) {
91 $html[] = '<label>';
92 $html[] = '<input type="radio" name="embedpress:{{slug}}[{{name}}]" class="{{classes}}" value="' . $optionValue . '"' . ($value === $optionValue ? ' checked' : '') . '>';
93 $html[] = '&nbsp;' . $optionLabel;
94 $html[] = '</label>&nbsp;&nbsp;';
95 }
96
97 return implode('', $html);
98 }
99
100 /**
101 * Generates a select input.
102 *
103 * @since 1.4.0
104 * @access protected
105 * @static
106 *
107 * @return string
108 */
109 protected static function select($options, $value = null)
110 {
111 $html = ['<select name="embedpress:{{slug}}[{{name}}]" class="{{classes}}">'];
112
113 foreach ((array)$options as $optionValue => $optionLabel) {
114 $html[] = '<option value="' . $optionValue . '"' . ($value === (string)$optionValue ? ' selected' : '') . '>' . $optionLabel . '</option>';
115 }
116
117 $html[] = '</select>';
118
119 return implode('', $html);
120 }
121
122 /**
123 * Render a field based on a field schema.
124 *
125 * @since 1.4.0
126 * @static
127 *
128 * @param array $params There's two available keys: 'field' which holds the field schema; and 'pluginSlug' which
129 * represents the slug of the plugin where the field belongs to.
130 *
131 * @return void
132 */
133 public static function render($params)
134 {
135 $field = json_decode(json_encode($params['field']));
136
137 $pluginSlug = "embedpress:{$params['pluginSlug']}";
138
139 $options = (array)get_option($pluginSlug);
140
141 $field->type = strtolower($field->type);
142
143 if ($field->slug === "license_key") {
144 $value = isset($options['license']['key']) ? (string)$options['license']['key'] : "";
145 } else {
146 $value = isset($options[$field->slug]) ? $options[$field->slug] : (isset($field->default) ? $field->default : '');
147 }
148
149 if (in_array($field->type, ['bool', 'boolean'])) {
150 $html = self::radio([
151 0 => 'No',
152 1 => 'Yes',
153 ], (int)$value);
154 } elseif (isset($field->options)) {
155 $html = self::select((array)$field->options, (string)$value);
156 } elseif (in_array($field->type, ['textarea'])) {
157 $html = self::textarea((string)$value);
158 } elseif (in_array($field->type, ['number', 'NUMBER'])) {
159 $html = self::number((int)$value);
160 } elseif (in_array($field->type, ['url', 'link'])) {
161 $html = self::url($value);
162 } else {
163 $html = self::text((string)$value);
164 }
165
166 $html = str_replace('{{slug}}', $params['pluginSlug'], $html);
167 $html = str_replace('{{name}}', $field->slug, $html);
168 $html = str_replace('{{classes}}', implode(' ', (! empty($field->classes) ? (array)$field->classes : [])),
169 $html);
170 $html = str_replace('{{placeholder}}', (! empty($field->placeholder) ? (string)$field->placeholder : ""),
171 $html);
172
173 $html .= wp_nonce_field("{$pluginSlug}:nonce", "{$pluginSlug}:nonce");
174
175 if ( ! empty($field->description)) {
176 $html .= '<br/>';
177 $html .= '<p class="description">' . $field->description . '</p>';
178 }
179
180 echo $html;
181 }
182 }
183