Conditions | 15 |
Paths | 160 |
Total Lines | 57 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
68 | public static function get_value( $config_id = '', $field_id = '' ) { |
||
69 | |||
70 | // Make sure value is defined. |
||
71 | $value = ''; |
||
72 | |||
73 | // This allows us to skip the $config_id argument. |
||
74 | // If we skip adding a $config_id, use the 'global' configuration. |
||
75 | if ( ( '' === $field_id ) && '' !== $config_id ) { |
||
76 | $field_id = $config_id; |
||
77 | $config_id = 'global'; |
||
78 | } |
||
79 | |||
80 | // If $config_id is empty, set it to 'global'. |
||
81 | $config_id = ( '' === $config_id ) ? 'global' : $config_id; |
||
82 | |||
83 | // Fallback to 'global' if $config_id is not found. |
||
84 | if ( ! isset( Kirki::$config[ $config_id ] ) ) { |
||
85 | $config_id = 'global'; |
||
86 | } |
||
87 | |||
88 | if ( 'theme_mod' === Kirki::$config[ $config_id ]['option_type'] ) { |
||
89 | |||
90 | // We're using theme_mods so just get the value using get_theme_mod. |
||
91 | $default_value = null; |
||
92 | if ( isset( Kirki::$fields[ $field_id ] ) && isset( Kirki::$fields[ $field_id ]['default'] ) ) { |
||
93 | $default_value = Kirki::$fields[ $field_id ]['default']; |
||
94 | } |
||
95 | $value = get_theme_mod( $field_id, $default_value ); |
||
96 | return apply_filters( 'kirki_values_get_value', $value, $field_id ); |
||
97 | } |
||
98 | |||
99 | if ( 'option' === Kirki::$config[ $config_id ]['option_type'] ) { |
||
100 | |||
101 | // We're using options. |
||
102 | if ( '' !== Kirki::$config[ $config_id ]['option_name'] ) { |
||
103 | |||
104 | // Options are serialized as a single option in the db. |
||
105 | // We'll have to get the option and then get the item from the array. |
||
106 | $options = get_option( Kirki::$config[ $config_id ]['option_name'] ); |
||
107 | |||
108 | if ( ! isset( Kirki::$fields[ $field_id ] ) && isset( Kirki::$fields[ Kirki::$config[ $config_id ]['option_name'] . '[' . $field_id . ']' ] ) ) { |
||
109 | $field_id = Kirki::$config[ $config_id ]['option_name'] . '[' . $field_id . ']'; |
||
110 | } |
||
111 | $setting_modified = str_replace( ']', '', str_replace( Kirki::$config[ $config_id ]['option_name'] . '[', '', $field_id ) ); |
||
112 | |||
113 | $default_value = ( isset( Kirki::$fields[ $field_id ] ) && isset( Kirki::$fields[ $field_id ]['default'] ) ) ? Kirki::$fields[ $field_id ]['default'] : ''; |
||
114 | $value = ( isset( $options[ $setting_modified ] ) ) ? $options[ $setting_modified ] : $default_value; |
||
115 | $value = maybe_unserialize( $value ); |
||
116 | return apply_filters( 'kirki_values_get_value', $value, $field_id ); |
||
117 | } |
||
118 | |||
119 | // Each option separately saved in the db. |
||
120 | $value = get_option( $field_id, Kirki::$fields[ $field_id ]['default'] ); |
||
121 | return apply_filters( 'kirki_values_get_value', $value, $field_id ); |
||
122 | |||
123 | } |
||
124 | return apply_filters( 'kirki_values_get_value', $value, $field_id ); |
||
125 | } |
||
153 |