PluginProbe
Quill Forms | Conversational Multi Step Forms, Surveys & quizzes / trunk
Quill Forms | Conversational Multi Step Forms, Surveys & quizzes vtrunk
5.7.3 5.7.2 5.7.1 1.8.1 1.8.10 1.8.11 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 2.0.0 2.1.0 2.10.0 2.11.0 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 All 146 releases
quillforms / includes / class-settings.php

class-settings.php in Quill Forms | Conversational Multi Step Forms, Surveys & quizzes trunk, at includes/class-settings.php

116 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Settings
4 *
5 * @since 1.6.0
6 * @package QuillForms
7 */
8
9 namespace QuillForms;
10
11 /**
12 * Settings Class
13 *
14 * @since 1.6.0
15 */
16 class Settings {
17
18 /**
19 * Option name where to store all settings
20 *
21 * @since 1.6.0
22 */
23 const OPTION_NAME = 'quillforms_settings';
24
25 /**
26 * Get a setting
27 *
28 * @since 1.6.0
29 *
30 * @param string $key Key.
31 * @param mixed $default Default value.
32 * @return mixed
33 */
34 public static function get( $key, $default = false ) {
35 $settings = self::get_all();
36 return isset( $settings[ $key ] ) ? $settings[ $key ] : $default;
37 }
38
39 /**
40 * Update a setting
41 *
42 * @since 1.6.0
43 *
44 * @param string $key Key.
45 * @param mixed $value Value.
46 * @return boolean
47 */
48 public static function update( $key, $value ) {
49 return self::update_many( array( $key => $value ) );
50 }
51
52 /**
53 * Delete a setting
54 *
55 * @since 1.6.0
56 *
57 * @param string $key Key.
58 * @return boolean
59 */
60 public static function delete( $key ) {
61 $settings = self::get_all();
62 unset( $settings[ $key ] );
63 return self::update_all( $settings );
64 }
65
66 /**
67 * Get all settings
68 *
69 * @since 1.6.0
70 *
71 * @return array
72 */
73 public static function get_all() {
74 return get_option( self::OPTION_NAME, array() );
75 }
76
77 /**
78 * Update many settings
79 *
80 * @since 1.6.0
81 *
82 * @param array $new_settings New settings.
83 * @return boolean
84 */
85 public static function update_many( $new_settings ) {
86 $old_settings = self::get_all();
87 $settings = array_replace( $old_settings, $new_settings );
88 return self::update_all( $settings );
89 }
90
91 /**
92 * Update all settings
93 *
94 * @since 1.6.0
95 *
96 * @param array $settings Settings.
97 * @return boolean
98 */
99 public static function update_all( $settings ) {
100 update_option( 'quillforms-flush-rewrite-rules', 1 );
101 return update_option( self::OPTION_NAME, $settings );
102 }
103
104 /**
105 * Delete all settings
106 *
107 * @since 1.6.0
108 *
109 * @return boolean
110 */
111 public static function delete_all() {
112 return delete_option( self::OPTION_NAME );
113 }
114
115 }
116