PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 1.0.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v1.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 / Ends / Back / Settings.php
embedpress / EmbedPress / Ends / Back Last commit date
Handler.php 9 years ago Settings.php 9 years ago index.html 9 years ago
Settings.php
225 lines
1 <?php
2 namespace EmbedPress\Ends\Back;
3
4 use \EmbedPress\Plugin;
5
6 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
7
8 /**
9 * Entity that handles the plugin's settings page.
10 *
11 * @package EmbedPress
12 * @subpackage EmbedPress/Ends/Back
13 * @author PressShack <help@pressshack.com>
14 * @copyright Copyright (C) 2016 Open Source Training, LLC. All rights reserved.
15 * @license GPLv2 or later
16 * @since 1.0
17 */
18 class Settings
19 {
20 /**
21 * This class namespace.
22 *
23 * @since 1.0
24 * @access private
25 * @static
26 *
27 * @var string $namespace
28 */
29 private static $namespace = '\EmbedPress\Ends\Back\Settings';
30
31 /**
32 * The plugin's unique identifier.
33 *
34 * @since 1.0
35 * @access private
36 * @static
37 *
38 * @var string $identifier
39 */
40 private static $identifier = "plg_embedpress";
41
42 /**
43 * Unique identifier to the plugin's admin settings section.
44 *
45 * @since 1.0
46 * @access private
47 * @static
48 *
49 * @var string $sectionAdminIdentifier
50 */
51 private static $sectionAdminIdentifier = "embedpress_options_admin";
52
53 /**
54 * Unique identifier to the plugin's general settings section.
55 *
56 * @since 1.0
57 * @access private
58 * @static
59 *
60 * @var string $sectionGroupIdentifier The name of the plugin.
61 */
62 private static $sectionGroupIdentifier = "embedpress_options";
63
64 /**
65 * Map to all settings.
66 *
67 * @since 1.0
68 * @access private
69 * @static
70 *
71 * @var string $fieldMap
72 */
73 private static $fieldMap = array(
74 'enablePluginInAdmin' => array(
75 'label' => "Enable EmbedPress in the admin area",
76 'section' => "admin"
77 ),
78 'displayPreviewBox' => array(
79 'label' => "Display Preview Box inside editor",
80 'section' => "admin"
81 )
82 );
83
84 /**
85 * Class constructor. This prevents the class being directly instantiated.
86 *
87 * @since 1.0
88 */
89 public function __construct()
90 {}
91
92 /**
93 * This prevents the class being cloned.
94 *
95 * @since 1.0
96 */
97 public function __clone()
98 {}
99
100 /**
101 * Method that adds an sub-item for EmbedPress to the WordPress Settings menu.
102 *
103 * @since 1.0
104 * @static
105 */
106 public static function registerMenuItem()
107 {
108 add_options_page('EmbedPress Settings', 'EmbedPress', 'manage_options', 'embedpress', array(self::$namespace, 'renderForm'));
109 }
110
111 /**
112 * Method that configures the EmbedPress settings page.
113 *
114 * @since 1.0
115 * @static
116 */
117 public static function registerActions()
118 {
119 register_setting(self::$sectionGroupIdentifier, self::$sectionGroupIdentifier, array(self::$namespace, "validateForm"));
120
121 add_settings_section(self::$sectionAdminIdentifier, 'Admin Section Settings', array(self::$namespace, 'renderHelpText'), self::$identifier);
122
123 foreach (self::$fieldMap as $fieldName => $field) {
124 add_settings_field($fieldName, $field['label'], array(self::$namespace, "renderField_{$fieldName}"), self::$identifier, self::${"section". ucfirst($field['section']) ."Identifier"});
125 }
126 }
127
128 /**
129 * Method that render the settings's form.
130 *
131 * @since 1.0
132 * @static
133 */
134 public static function renderForm()
135 {
136 ?>
137 <div>
138 <h2>EmbedPress Settings Page</h2>
139 <form action="options.php" method="POST">
140 <?php settings_fields(self::$sectionGroupIdentifier); ?>
141 <?php do_settings_sections(self::$identifier); ?>
142
143 <input name="Submit" type="submit" value="Save changes" />
144 </form>
145 </div>
146 <?php
147 }
148
149 /**
150 * Method that validates the form data.
151 *
152 * @since 1.0
153 * @static
154 *
155 * @param mixed $freshData Data received from the form.
156 *
157 * @return array
158 */
159 public static function validateForm($freshData)
160 {
161 $data = array(
162 'displayPreviewBox' => (bool)$freshData['displayPreviewBox'],
163 'enablePluginInAdmin' => (bool)$freshData['enablePluginInAdmin']
164 );
165
166 return $data;
167 }
168
169 /**
170 * Method that prints help info for the form.
171 *
172 * @since 1.0
173 * @static
174 *
175 * @return string
176 */
177 public static function renderHelpText()
178 {
179 return "";
180 }
181
182 /**
183 * Method that renders the displayPreviewBox input.
184 *
185 * @since 1.0
186 * @static
187 */
188 public static function renderField_displayPreviewBox()
189 {
190 $fieldName = "displayPreviewBox";
191
192 $options = get_option(self::$sectionGroupIdentifier);
193
194 $activeOptions = Plugin::getSettings();
195 if (isset($activeOptions->enablePluginInAdmin) && (bool)$activeOptions->enablePluginInAdmin === false) {
196 $options[$fieldName] = false;
197 } else {
198 $options[$fieldName] = !isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
199 }
200 unset($activeOptions);
201
202 echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
203 echo "&nbsp;&nbsp;";
204 echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
205 }
206
207 /**
208 * Method that renders the enablePluginInAdmin input.
209 *
210 * @since 1.0
211 * @static
212 */
213 public static function renderField_enablePluginInAdmin()
214 {
215 $fieldName = "enablePluginInAdmin";
216
217 $options = get_option(self::$sectionGroupIdentifier);
218
219 $options[$fieldName] = !isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
220
221 echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
222 echo "&nbsp;&nbsp;";
223 echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
224 }
225 }