PluginProbe
Block Editor Colors / 1.2.1
Block Editor Colors v1.2.1
1.2.7 1.2.4 1.2.5 1.2.6 trunk 1.2.0 1.2.1 1.2.2 1.2.3
block-editor-colors / includes / OptionsService.php

OptionsService.php in Block Editor Colors 1.2.1, at includes/OptionsService.php

57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BlockEditorColors;
4
5
6 class OptionsService {
7
8 private $option_class_prefix = 'bec_css_prefix';
9 private static $_instance = null;
10
11 public static function getInstance() {
12 if ( is_null( self::$_instance ) ) {
13 self::$_instance = new self();
14 }
15
16 return self::$_instance;
17 }
18
19 public function __construct() {
20 $this->boot_general_options();
21
22 add_action( 'admin_post_update_general_options', array( $this, 'update_general_options' ) );
23 }
24
25 public function boot_general_options() {
26 add_option( $this->get_class_prefix_option_name(), ':root' );
27 }
28
29 public function get_style_classes_prefix() {
30
31 return get_option( $this->get_class_prefix_option_name() );
32
33 }
34
35 public function get_class_prefix_option_name() {
36 return $this->option_class_prefix;
37 }
38
39 public function update_general_options() {
40
41 if ( ! isset( $_POST['update_general_options_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['update_general_options_nonce'] ) ), 'update_general_options' ) ) {
42 wp_die( esc_html__( 'Denied', 'block-editor-colors' ) );
43 }
44
45 $prefix_option_name = $this->get_class_prefix_option_name();
46 if ( isset( $_POST[ $prefix_option_name ] ) ) {
47 $option_value = sanitize_text_field( wp_unslash( $_POST[ $prefix_option_name ] ) );
48 update_option( $prefix_option_name, $option_value );
49 }
50
51 wp_redirect( SettingsPage::getAdminUrl() );
52 exit;
53 }
54
55 }
56
57 OptionsService::getInstance();