@@ -27,26 +27,32 @@ abstract class Settings_Controller extends Controller {
27
27
protected static $ default_settings = array ();
28
28
29
29
/**
30
- * @param string $key
30
+ * @param string $id
31
31
* @return array|mixed|WP_Error|null
32
32
*/
33
- public function get_settings ( string $ key ) {
34
- $ method_name = 'get_ ' . $ key . '_settings ' ;
33
+ public function get_settings ( string $ id ) {
34
+ $ method_name = 'get_ ' . $ id . '_settings ' ;
35
+
35
36
if ( method_exists ( $ this , $ method_name ) ) {
36
37
return $ this ->$ method_name ();
37
- } else {
38
- return new WP_Error ( 'cant-get ' , __ ( 'message ' , 'woocommerce-pos ' ), array ( 'status ' => 400 ) );
39
38
}
39
+
40
+ return new WP_Error (
41
+ 'woocommerce_pos_settings_error ' ,
42
+ /* translators: %s: Settings group id, ie: 'general' or 'checkout' */
43
+ sprintf ( __ ( 'Settings with id %s not found ' , 'woocommerce-pos ' ), $ id ),
44
+ array ( 'status ' => 400 )
45
+ );
40
46
}
41
47
42
48
/**
43
- * @param string $key
49
+ * @param string $id
44
50
* @param array $settings
45
51
* @return array|mixed|WP_Error|null
46
52
*/
47
- protected function save_settings ( string $ key , array $ settings ) {
53
+ protected function save_settings ( string $ id , array $ settings ) {
48
54
$ success = update_option (
49
- static ::$ db_prefix . $ key ,
55
+ static ::$ db_prefix . $ id ,
50
56
array_merge (
51
57
$ settings ,
52
58
array ( 'date_modified_gmt ' => current_time ( 'mysql ' , true ) )
@@ -55,9 +61,14 @@ protected function save_settings( string $key, array $settings ) {
55
61
);
56
62
57
63
if ( $ success ) {
58
- return $ this ->get_settings ( $ key );
64
+ return $ this ->get_settings ( $ id );
59
65
}
60
66
61
- return new WP_Error ( 'cant-save ' , __ ( 'message ' , 'woocommerce-pos ' ), array ( 'status ' => 400 ) );
67
+ return new WP_Error (
68
+ 'woocommerce_pos_settings_error ' ,
69
+ /* translators: %s: Settings group id, ie: 'general' or 'checkout' */
70
+ sprintf ( __ ( 'Can not save settings with id %s ' , 'woocommerce-pos ' ), $ id ),
71
+ array ( 'status ' => 400 )
72
+ );
62
73
}
63
74
}
0 commit comments