PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 2.4.0
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v2.4.0
4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.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 7 years ago Settings.php 6 years ago index.html 7 years ago
Settings.php
572 lines
1 <?php
2
3 namespace EmbedPress\Ends\Back;
4
5 use EmbedPress\Compatibility;
6
7 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
8
9 /**
10 * Entity that handles the plugin's settings page.
11 *
12 * @package EmbedPress
13 * @subpackage EmbedPress/Ends/Back
14 * @author EmbedPress <help@embedpress.com>
15 * @copyright Copyright (C) 2018 EmbedPress. All rights reserved.
16 * @license GPLv2 or later
17 * @since 1.0.0
18 */
19 class Settings
20 {
21 /**
22 * This class namespace.
23 *
24 * @since 1.0.0
25 * @access private
26 * @static
27 *
28 * @var string $namespace
29 */
30 private static $namespace = '\\EmbedPress\\Ends\\Back\\Settings';
31
32 /**
33 * The plugin's unique identifier.
34 *
35 * @since 1.0.0
36 * @access private
37 * @static
38 *
39 * @var string $identifier
40 */
41 private static $identifier = "plg_embedpress";
42
43 /**
44 * Unique identifier to the plugin's admin settings section.
45 *
46 * @since 1.0.0
47 * @access private
48 * @static
49 *
50 * @var string $sectionAdminIdentifier
51 */
52 private static $sectionAdminIdentifier = "embedpress_options_admin";
53
54 /**
55 * Unique identifier to the plugin's general settings section.
56 *
57 * @since 1.0.0
58 * @access private
59 * @static
60 *
61 * @var string $sectionGroupIdentifier The name of the plugin.
62 */
63 private static $sectionGroupIdentifier = "embedpress";
64
65 /**
66 * Class constructor. This prevents the class being directly instantiated.
67 *
68 * @since 1.0.0
69 */
70 public function __construct()
71 {
72 }
73
74 /**
75 * This prevents the class being cloned.
76 *
77 * @since 1.0.0
78 */
79 public function __clone()
80 {
81 }
82
83 /**
84 * Method that adds an sub-item for EmbedPress to the WordPress Settings menu.
85 *
86 * @since 1.0.0
87 * @static
88 */
89 public static function registerMenuItem()
90 {
91 add_menu_page('EmbedPress Settings', 'EmbedPress', 'manage_options', 'embedpress',
92 [self::$namespace, 'renderForm'], null, 64);
93 }
94
95 /**
96 * Method that configures the EmbedPress settings page.
97 *
98 * @since 1.0.0
99 * @static
100 */
101 public static function registerActions()
102 {
103 $activeTab = isset($_GET['tab']) ? strtolower($_GET['tab']) : "";
104 if ($activeTab !== "embedpress") {
105 $action = "embedpress:{$activeTab}:settings:register";
106 } else {
107 $activeTab = "";
108 }
109
110 if ( ! empty($activeTab) && has_action($action)) {
111 do_action($action, [
112 'id' => self::$sectionAdminIdentifier,
113 'slug' => self::$identifier,
114 ]);
115 } else {
116 register_setting(self::$sectionGroupIdentifier, self::$sectionGroupIdentifier,
117 [self::$namespace, "validateForm"]);
118
119 add_settings_section(self::$sectionAdminIdentifier, '', null, self::$identifier);
120
121 $fieldMap = [];
122 if ( ! Compatibility::isWordPress5() || Compatibility::isClassicalEditorActive()) {
123 $fieldMap = [
124 'enablePluginInAdmin' => [
125 'label' => "Load previews in the admin editor",
126 'section' => "admin",
127 ],
128 'enablePluginInFront' => [
129 'label' => "Load previews in the frontend editor",
130 'section' => "admin",
131 ],
132 'enableEmbedResizeWidth' => [
133 'label' => "Embed Iframe Width",
134 'section' => "admin",
135 ],
136 'enableEmbedResizeHeight' => [
137 'label' => "Embed Iframe Height",
138 'section' => "admin",
139 ]
140 ];
141 }
142
143 $fieldMap['forceFacebookLanguage'] = [
144 'label' => "Facebook embed language",
145 'section' => "admin",
146 ];
147
148 foreach ($fieldMap as $fieldName => $field) {
149 add_settings_field($fieldName, $field['label'], [self::$namespace, "renderField_{$fieldName}"],
150 self::$identifier, self::${"section" . ucfirst($field['section']) . "Identifier"});
151 }
152 }
153 }
154
155 /**
156 * Returns true if the plugin is active
157 *
158 * @param string $plugin
159 *
160 * @return boolean
161 */
162 protected static function is_plugin_active($plugin)
163 {
164 return is_plugin_active("{$plugin}/{$plugin}.php");
165 }
166
167 /**
168 * Returns true if the plugin is installed
169 *
170 * @param string $plugin
171 *
172 * @return boolean
173 */
174 protected static function is_plugin_installed($plugin)
175 {
176 return file_exists(plugin_dir_path(EMBEDPRESS_ROOT) . "{$plugin}/{$plugin}.php");
177 }
178
179 /**
180 * Method that render the settings's form.
181 *
182 * @since 1.0.0
183 * @static
184 */
185 public static function renderForm()
186 {
187 // Add the color picker css file
188 wp_enqueue_style('wp-color-picker');
189 // Include our custom jQuery file with WordPress Color Picker dependency
190 wp_enqueue_script('ep-settings', EMBEDPRESS_URL_ASSETS . 'js/settings.js', ['wp-color-picker'],
191 EMBEDPRESS_VERSION, true);
192
193 $activeTab = isset($_GET['tab']) ? strtolower($_GET['tab']) : "";
194 $settingsFieldsIdentifier = ! empty($activeTab) ? "embedpress:{$activeTab}" : self::$sectionGroupIdentifier;
195 $settingsSectionsIdentifier = ! empty($activeTab) ? "embedpress:{$activeTab}" : self::$identifier;
196 ?>
197 <div id="embedpress-settings-wrapper">
198 <header>
199 <h1 class="pressshack-title">
200 <a href="//wordpress.org/plugins/embedpress" target="_blank" rel="noopener noreferrer"
201 title="EmbedPress">
202 EmbedPress
203 </a>
204 </h1>
205 </header>
206
207 <?php settings_errors(); ?>
208 <div>
209 <h2 class="nav-tab-wrapper">
210 <a href="?page=embedpress"
211 class="nav-tab<?php echo $activeTab === 'embedpress' || empty($activeTab) ? ' nav-tab-active' : ''; ?> ">
212 General settings
213 </a>
214 <?php do_action('embedpress:settings:render:tab', $activeTab); ?>
215 <?php do_action('embedpress_license_tab',$activeTab); ?>
216
217 </h2>
218
219 <?php if ($activeTab !== 'addons') : ?>
220 <form action="options.php" method="POST" style="padding-bottom: 20px;">
221 <?php settings_fields($settingsFieldsIdentifier); ?>
222 <?php do_settings_sections($settingsSectionsIdentifier); ?>
223 <?php if ($activeTab !== 'embedpress_license') : ?>
224 <button type="submit" class="button button-primary embedpress-setting-save">Save changes</button>
225 <?php endif; ?>
226 </form>
227 <?php endif; ?>
228 <?php if ($activeTab == 'embedpress_license') : ?>
229 <?php echo do_action('embedpress_license'); ?>
230 <?php endif; ?>
231 </div>
232
233 <footer>
234 <p>
235 <a href="//wordpress.org/support/plugin/embedpress/reviews/#new-post" target="_blank"
236 rel="noopener noreferrer">If you like <strong>EmbedPress</strong> please leave us a <span
237 class="dashicons dashicons-star-filled"></span><span
238 class="dashicons dashicons-star-filled"></span><span
239 class="dashicons dashicons-star-filled"></span><span
240 class="dashicons dashicons-star-filled"></span><span
241 class="dashicons dashicons-star-filled"></span> rating. Thank you!</a>
242 </p>
243 <hr>
244 <nav>
245 <ul>
246 <li>
247 <a href="//embedpress.com" target="_blank" rel="noopener noreferrer"
248 title="About EmbedPress">About</a>
249 </li>
250 <li>
251 <a href="//embedpress.com/docs/sources-support" target="_blank" rel="noopener noreferrer"
252 title="List of supported sources by EmbedPress">Supported sources</a>
253 </li>
254 <li>
255 <a href="//embedpress.com/docs" target="_blank" rel="noopener noreferrer"
256 title="EmbedPress Documentation">Documentation</a>
257 </li>
258 <li>
259 <a href="//embedpress.com/addons/" target="_blank" rel="noopener noreferrer"
260 title="EmbedPress Add-Ons">Add-Ons</a>
261 </li>
262 <li>
263 <a href="//embedpress.com/contact" target="_blank" rel="noopener noreferrer"
264 title="Contact the EmbedPress team">Contact</a>
265 </li>
266 <li>
267 <a href="//twitter.com/embedpress" target="_blank" rel="noopener noreferrer">
268 <span class="dashicons dashicons-twitter"></span>
269 </a>
270 </li>
271 <li>
272 <a href="//facebook.com/embedpress" target="_blank" rel="noopener noreferrer">
273 <span class="dashicons dashicons-facebook"></span>
274 </a>
275 </li>
276 </ul>
277 </nav>
278 <p>
279 <a href="//embedpress.com" target="_blank" rel="noopener noreferrer">
280 <img width="100" src="//embedpress.com/wp-content/uploads/2018/01/ep-logo-2.png">
281 </a>
282 </p>
283 </footer>
284 </div>
285 <?php
286 }
287
288 /**
289 * Method that validates the form data.
290 *
291 * @since 1.0.0
292 * @static
293 *
294 * @param mixed $freshData Data received from the form.
295 *
296 * @return array
297 */
298 public static function validateForm($freshData)
299 {
300 $data = [
301 'enablePluginInAdmin' => isset($freshData['enablePluginInAdmin']) ? (bool)$freshData['enablePluginInAdmin'] : true,
302 'enablePluginInFront' => isset($freshData['enablePluginInFront']) ? (bool)$freshData['enablePluginInFront'] : true,
303 'enableEmbedResizeHeight' => isset($freshData['enableEmbedResizeHeight']) ? $freshData['enableEmbedResizeHeight'] : 552,
304 'enableEmbedResizeWidth' => isset($freshData['enableEmbedResizeWidth']) ? $freshData['enableEmbedResizeWidth'] : 652,
305 'fbLanguage' => $freshData['fbLanguage'],
306 ];
307
308 return $data;
309 }
310
311 /**
312 * Method that renders the enablePluginInAdmin input.
313 *
314 * @since 1.0.0
315 * @static
316 */
317 public static function renderField_enablePluginInAdmin()
318 {
319 $fieldName = "enablePluginInAdmin";
320
321 $options = get_option(self::$sectionGroupIdentifier);
322
323 $options[$fieldName] = ! isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
324
325 echo '<label><input type="radio" id="' . $fieldName . '_0" name="' . self::$sectionGroupIdentifier . '[' . $fieldName . ']" value="0" ' . (! $options[$fieldName] ? "checked" : "") . ' /> No</label>';
326 echo "&nbsp;&nbsp;";
327 echo '<label><input type="radio" id="' . $fieldName . '_1" name="' . self::$sectionGroupIdentifier . '[' . $fieldName . ']" value="1" ' . ($options[$fieldName] ? "checked" : "") . ' /> Yes</label>';
328 echo '<p class="description">Do you want EmbedPress to run here in the admin area? Disabling this <strong>will not</strong> affect your frontend embeds.</p>';
329 }
330
331 /**
332 * Method that renders the enablePluginInFront input.
333 *
334 * @since 1.6.0
335 * @static
336 */
337 public static function renderField_enablePluginInFront()
338 {
339 $fieldName = "enablePluginInFront";
340
341 $options = get_option(self::$sectionGroupIdentifier);
342
343 $options[$fieldName] = ! isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
344
345 echo '<label><input type="radio" id="' . $fieldName . '_0" name="' . self::$sectionGroupIdentifier . '[' . $fieldName . ']" value="0" ' . (! $options[$fieldName] ? "checked" : "") . ' /> No</label>';
346 echo "&nbsp;&nbsp;";
347 echo '<label><input type="radio" id="' . $fieldName . '_1" name="' . self::$sectionGroupIdentifier . '[' . $fieldName . ']" value="1" ' . ($options[$fieldName] ? "checked" : "") . ' /> Yes</label>';
348 echo '<p class="description">Do you want EmbedPress to run within editors in frontend (if there\'s any)? Disabling this <strong>will not</strong> affect embeds seem by your regular users in frontend.</p>';
349 }
350
351 /**
352 * Method that renders the enableEmbedResizeHeight input.
353 *
354 * @since 2.4.0
355 * @static
356 */
357 public static function renderField_enableEmbedResizeHeight()
358 {
359 $fieldName = "enableEmbedResizeHeight";
360
361 $options = get_option(self::$sectionGroupIdentifier);
362
363 $value = ! isset($options[$fieldName]) ? '552' : $options[$fieldName];
364
365 echo '<input type="number" value="'.absint($value).'" class="regular-text" name="' . self::$sectionGroupIdentifier . '[' . $fieldName . ']">';
366
367 echo '<p class="description">Global Embed Iframe Height</p>';
368 }
369
370 /**
371 * Method that renders the enableEmbedResizeWidth input.
372 *
373 * @since 2.4.0
374 * @static
375 */
376 public static function renderField_enableEmbedResizeWidth()
377 {
378 $fieldName = "enableEmbedResizeWidth";
379 $options = get_option(self::$sectionGroupIdentifier);
380 $value = ! isset($options[$fieldName]) ? '652' : $options[$fieldName];
381
382 echo '<input type="number" value="'.absint($value).'" class="regular-text" name="' . self::$sectionGroupIdentifier . '[' . $fieldName . ']">';
383 echo '<p class="description">Global Embed Iframe Width </p>';
384 }
385
386 /**
387 * Method that renders the forceFacebookLanguage input.
388 *
389 * @since 1.3.0
390 * @static
391 */
392 public static function renderField_forceFacebookLanguage()
393 {
394 $fieldName = "fbLanguage";
395
396 $options = get_option(self::$sectionGroupIdentifier);
397
398 $options[$fieldName] = ! isset($options[$fieldName]) ? "" : $options[$fieldName];
399
400 $facebookLocales = self::getFacebookAvailableLocales();
401
402 echo '<select name="' . self::$sectionGroupIdentifier . '[' . $fieldName . ']">';
403 echo '<option value="0">Automatic (by Facebook)</option>';
404 echo '<optgroup label="Available">';
405 foreach ($facebookLocales as $locale => $localeName) {
406 echo '<option value="' . $locale . '"' . ($options[$fieldName] === $locale ? ' selected' : '') . '>' . $localeName . '</option>';
407 }
408 echo '</optgroup>';
409 echo '</select>';
410
411 echo '<p class="description">Sometimes Facebook can choose the wrong language for embeds. If this happens, choose the correct language here.</p>';
412 }
413
414 /**
415 * Returns a list of locales that can be used on Facebook embeds.
416 *
417 * @since 1.3.0
418 * @static
419 *
420 * @return array
421 */
422 public static function getFacebookAvailableLocales()
423 {
424 $locales = [
425 'af_ZA' => "Afrikaans",
426 'ak_GH' => "Akan",
427 'am_ET' => "Amharic",
428 'ar_AR' => "Arabic",
429 'as_IN' => "Assamese",
430 'ay_BO' => "Aymara",
431 'az_AZ' => "Azerbaijani",
432 'be_BY' => "Belarusian",
433 'bg_BG' => "Bulgarian",
434 'bn_IN' => "Bengali",
435 'br_FR' => "Breton",
436 'bs_BA' => "Bosnian",
437 'ca_ES' => "Catalan",
438 'cb_IQ' => "Sorani Kurdish",
439 'ck_US' => "Cherokee",
440 'co_FR' => "Corsican",
441 'cs_CZ' => "Czech",
442 'cx_PH' => "Cebuano",
443 'cy_GB' => "Welsh",
444 'da_DK' => "Danish",
445 'de_DE' => "German",
446 'el_GR' => "Greek",
447 'en_GB' => "English (UK)",
448 'en_IN' => "English (India)",
449 'en_PI' => "English (Pirate)",
450 'en_UD' => "English (Upside Down)",
451 'en_US' => "English (US)",
452 'eo_EO' => "Esperanto",
453 'es_CL' => "Spanish (Chile)",
454 'es_CO' => "Spanish (Colombia)",
455 'es_ES' => "Spanish (Spain)",
456 'es_LA' => "Spanish",
457 'es_MX' => "Spanish (Mexico)",
458 'es_VE' => "Spanish (Venezuela)",
459 'et_EE' => "Estonian",
460 'eu_ES' => "Basque",
461 'fa_IR' => "Persian",
462 'fb_LT' => "Leet Speak",
463 'ff_NG' => "Fulah",
464 'fi_FI' => "Finnish",
465 'fo_FO' => "Faroese",
466 'fr_CA' => "French (Canada)",
467 'fr_FR' => "French (France)",
468 'fy_NL' => "Frisian",
469 'ga_IE' => "Irish",
470 'gl_ES' => "Galician",
471 'gn_PY' => "Guarani",
472 'gu_IN' => "Gujarati",
473 'gx_GR' => "Classical Greek",
474 'ha_NG' => "Hausa",
475 'he_IL' => "Hebrew",
476 'hi_IN' => "Hindi",
477 'hr_HR' => "Croatian",
478 'ht_HT' => "Haitian Creole",
479 'hu_HU' => "Hungarian",
480 'hy_AM' => "Armenian",
481 'id_ID' => "Indonesian",
482 'ig_NG' => "Igbo",
483 'is_IS' => "Icelandic",
484 'it_IT' => "Italian",
485 'ja_JP' => "Japanese",
486 'ja_KS' => "Japanese (Kansai)",
487 'jv_ID' => "Javanese",
488 'ka_GE' => "Georgian",
489 'kk_KZ' => "Kazakh",
490 'km_KH' => "Khmer",
491 'kn_IN' => "Kannada",
492 'ko_KR' => "Korean",
493 'ku_TR' => "Kurdish (Kurmanji)",
494 'ky_KG' => "Kyrgyz",
495 'la_VA' => "Latin",
496 'lg_UG' => "Ganda",
497 'li_NL' => "Limburgish",
498 'ln_CD' => "Lingala",
499 'lo_LA' => "Lao",
500 'lt_LT' => "Lithuanian",
501 'lv_LV' => "Latvian",
502 'mg_MG' => "Malagasy",
503 'mi_NZ' => "Māori",
504 'mk_MK' => "Macedonian",
505 'ml_IN' => "Malayalam",
506 'mn_MN' => "Mongolian",
507 'mr_IN' => "Marathi",
508 'ms_MY' => "Malay",
509 'mt_MT' => "Maltese",
510 'my_MM' => "Burmese",
511 'nb_NO' => "Norwegian (bokmal)",
512 'nd_ZW' => "Ndebele",
513 'ne_NP' => "Nepali",
514 'nl_BE' => "Dutch (België)",
515 'nl_NL' => "Dutch",
516 'nn_NO' => "Norwegian (nynorsk)",
517 'ny_MW' => "Chewa",
518 'or_IN' => "Oriya",
519 'pa_IN' => "Punjabi",
520 'pl_PL' => "Polish",
521 'ps_AF' => "Pashto",
522 'pt_BR' => "Portuguese (Brazil)",
523 'pt_PT' => "Portuguese (Portugal)",
524 'qc_GT' => "Quiché",
525 'qu_PE' => "Quechua",
526 'rm_CH' => "Romansh",
527 'ro_RO' => "Romanian",
528 'ru_RU' => "Russian",
529 'rw_RW' => "Kinyarwanda",
530 'sa_IN' => "Sanskrit",
531 'sc_IT' => "Sardinian",
532 'se_NO' => "Northern Sámi",
533 'si_LK' => "Sinhala",
534 'sk_SK' => "Slovak",
535 'sl_SI' => "Slovenian",
536 'sn_ZW' => "Shona",
537 'so_SO' => "Somali",
538 'sq_AL' => "Albanian",
539 'sr_RS' => "Serbian",
540 'sv_SE' => "Swedish",
541 'sw_KE' => "Swahili",
542 'sy_SY' => "Syriac",
543 'sz_PL' => "Silesian",
544 'ta_IN' => "Tamil",
545 'te_IN' => "Telugu",
546 'tg_TJ' => "Tajik",
547 'th_TH' => "Thai",
548 'tk_TM' => "Turkmen",
549 'tl_PH' => "Filipino",
550 'tl_ST' => "Klingon",
551 'tr_TR' => "Turkish",
552 'tt_RU' => "Tatar",
553 'tz_MA' => "Tamazight",
554 'uk_UA' => "Ukrainian",
555 'ur_PK' => "Urdu",
556 'uz_UZ' => "Uzbek",
557 'vi_VN' => "Vietnamese",
558 'wo_SN' => "Wolof",
559 'xh_ZA' => "Xhosa",
560 'yi_DE' => "Yiddish",
561 'yo_NG' => "Yoruba",
562 'zh_CN' => "Simplified Chinese (China)",
563 'zh_HK' => "Traditional Chinese (Hong Kong)",
564 'zh_TW' => "Traditional Chinese (Taiwan)",
565 'zu_ZA' => "Zulu",
566 'zz_TR' => "Zazaki",
567 ];
568
569 return $locales;
570 }
571 }
572