PluginProbe
Depicter — Popup & Slider Builder / 1.3.8
Depicter — Popup & Slider Builder v1.3.8
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / WordPress / Settings / Settings.php

Settings.php in Depicter — Popup & Slider Builder 1.3.8, at app/src/WordPress/Settings/Settings.php

94 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\WordPress\Settings;
4
5 use Depicter\WordPress\Settings\Options\Checkbox;
6 use Depicter\WordPress\Settings\Options\Choices;
7 use Depicter\WordPress\Settings\Options\CodeEditor;
8 use Depicter\WordPress\Settings\Options\Select;
9 use Depicter\WordPress\Settings\Options\SelectMultiple;
10 use Depicter\WordPress\Settings\Options\Text;
11 use Depicter\WordPress\Settings\Options\Textarea;
12 use Depicter\WordPress\Settings\Options\WPEditor;
13 use Jeffreyvr\WPSettings\WPSettings;
14
15 class Settings extends WPSettings
16 {
17
18 public $prefix = 'depicter_';
19
20 public function __construct( $title, $slug = null, $prefix = 'depicter_')
21 {
22 $this->prefix = $prefix;
23 add_filter( 'wp_settings_option_type_map', [ $this, 'change_options_handler' ] );
24
25 parent::__construct( $title, $slug );
26 }
27
28 public function change_options_handler( $types )
29 {
30 return [
31 'text' => Text::class,
32 'checkbox' => Checkbox::class,
33 'choices' => Choices::class,
34 'textarea' => Textarea::class,
35 'wp-editor' => WPEditor::class,
36 'code-editor' => CodeEditor::class,
37 'select' => Select::class,
38 'select-multiple' => SelectMultiple::class
39 ];
40 }
41
42 public function get_url()
43 {
44 if ($this->parent_slug) {
45 return \add_query_arg('page', $this->slug, \admin_url("admin.php?page=" . $this->parent_slug));
46 }
47
48 return \admin_url("admin.php?page=$this->slug");
49 }
50
51 public function save()
52 {
53 if (! isset($_POST['wp_settings_trigger'])) {
54 return;
55 }
56
57 if (! current_user_can($this->capability)) {
58 wp_die(__('What do you think you are doing?'));
59 }
60
61 if (! isset($_POST[$this->option_name]) && !isset($_POST['wp_settings_submitted'])) {
62 return;
63 }
64
65 $new_options = apply_filters('wp_settings_new_options', $_POST[$this->option_name] ?? [] );
66
67 foreach ($new_options as $option => $value) {
68 $_option = $this->find_option($option);
69
70 $valid = $_option->validate($value);
71
72 if (!$valid) {
73 continue;
74 }
75
76 $value = apply_filters( "wp_settings_new_options_$option", $_option->sanitize($value), $_option );
77
78 update_option( $this->prefix . $option, $_option->sanitize( $value ) );
79 }
80
81 // checking unchecked checkbox option
82 foreach ($this->tabs as $tab) {
83 foreach ($tab->sections as $section) {
84 foreach ($section->options as $option) {
85 if ( $option->type == 'checkbox' && !isset( $new_options[ $option->args['name' ] ] ) ) {
86 update_option( $this->prefix . $option->args['name'], '' );
87 }
88 }
89 }
90 }
91
92 $this->flash->set('success', __('Saved changes!'));
93 }
94 }