forked from WordPress/two-factor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-core-style-plugin.php
99 lines (87 loc) · 2.05 KB
/
class-core-style-plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* Initalize plugin
*/
class Core_Style_Plugin {
/**
* Set up filters and actions.
*
* @since 0.1-dev
*/
public static function add_hooks() {
add_action( 'plugins_loaded', array( __CLASS__, 'load_textdomain' ) );
}
/**
* Loads the plugin's text domain.
*
* Sites on WordPress 4.6+ benefit from just-in-time loading of translations.
*/
public static function load_textdomain() {
load_plugin_textdomain( 'core-style-plugin' );
}
/**
* Sanitizes the plugin's setting.
*
* @since 1.0.0
*
* @param array $values Setting value.
* @return array Sanitized modules setting value.
*/
public static function sanitize_settings( $values ) {
if ( ! is_array( $values ) ) {
$values = array();
}
$data = array();
$defaults = self::settings_default();
foreach ( $defaults as $key => $default ) {
if ( ! array_key_exists( $key, $values ) ) {
$data[ $key ] = $default;
} else {
$data[ $key ] = $values[ $key ];
}
}
return $data;
}
/**
* Get the default settings for the plugin.
*
* @return array
*/
public static function settings_default() {
$defaults = array(
'api_key' => '',
);
return $defaults;
}
/**
* Get the settings for the plugin.
*
* @return array
*/
public static function get_settings() {
$settings = get_option( CORE_STYLE_PLUGIN_SETTING, self::settings_default() );
/**
* Filter the settings for the plugin.
*
* @param array $settings Array of settings.
*/
return apply_filters( 'core_style_plugin_settings', $settings );
}
/**
* Save the settings for the plugin.
*
* Important: does not sanitize data or merge with defaults.
*
* @param array $update Array of settings to update.
* @return bool
*/
public static function save_settings( array $update ) {
/**
* Chnage the settings for the plugin before they are saved.
*
* @param array $update Array of settings to be saved.
*/
$update = apply_filters( 'core_style_plugin_pre_save_settings', $update );
return update_option( CORE_STYLE_PLUGIN_SETTING, $update );
}
}