| Conditions | 13 |
| Paths | 64 |
| Total Lines | 56 |
| Code Lines | 24 |
| 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 |
||
| 30 | public static function get_value( $config_id = '', $field_id = '' ) { |
||
| 31 | |||
| 32 | // Make sure value is defined. |
||
| 33 | $value = ''; |
||
| 34 | |||
| 35 | // This allows us to skip the $config_id argument. |
||
| 36 | // If we skip adding a $config_id, use the 'global' configuration. |
||
| 37 | if ( ( '' === $field_id ) && '' !== $config_id ) { |
||
| 38 | $field_id = $config_id; |
||
| 39 | $config_id = 'global'; |
||
| 40 | } |
||
| 41 | |||
| 42 | // If $config_id is empty, set it to 'global'. |
||
| 43 | $config_id = ( '' === $config_id ) ? 'global' : $config_id; |
||
| 44 | |||
| 45 | // Fallback to 'global' if $config_id is not found. |
||
| 46 | if ( ! isset( Kirki::$config[ $config_id ] ) ) { |
||
| 47 | $config_id = 'global'; |
||
| 48 | } |
||
| 49 | |||
| 50 | if ( 'theme_mod' === Kirki::$config[ $config_id ]['option_type'] ) { |
||
| 51 | |||
| 52 | // We're using theme_mods so just get the value using get_theme_mod. |
||
| 53 | $default_value = null; |
||
| 54 | if ( isset( Kirki::$fields[ $field_id ] ) && isset( Kirki::$fields[ $field_id ]['default'] ) ) { |
||
| 55 | $default_value = Kirki::$fields[ $field_id ]['default']; |
||
| 56 | } |
||
| 57 | $value = get_theme_mod( $field_id, $default_value ); |
||
| 58 | |||
| 59 | } elseif ( 'option' === Kirki::$config[ $config_id ]['option_type'] ) { |
||
| 60 | |||
| 61 | // We're using options. |
||
| 62 | if ( '' !== Kirki::$config[ $config_id ]['option_name'] ) { |
||
| 63 | |||
| 64 | // Options are serialized as a single option in the db. |
||
| 65 | // We'll have to get the option and then get the item from the array. |
||
| 66 | $options = get_option( Kirki::$config[ $config_id ]['option_name'] ); |
||
| 67 | |||
| 68 | if ( ! isset( Kirki::$fields[ $field_id ] ) && isset( Kirki::$fields[ Kirki::$config[ $config_id ]['option_name'] . '[' . $field_id . ']' ] ) ) { |
||
| 69 | $field_id = Kirki::$config[ $config_id ]['option_name'] . '[' . $field_id . ']'; |
||
| 70 | } |
||
| 71 | $setting_modified = str_replace( ']', '', str_replace( Kirki::$config[ $config_id ]['option_name'] . '[', '', $field_id ) ); |
||
| 72 | |||
| 73 | $value = ( isset( $options[ $setting_modified ] ) ) ? $options[ $setting_modified ] : Kirki::$fields[ $field_id ]['default']; |
||
| 74 | $value = maybe_unserialize( $value ); |
||
| 75 | } else { |
||
| 76 | |||
| 77 | // Each option separately saved in the db. |
||
| 78 | $value = get_option( $field_id, Kirki::$fields[ $field_id ]['default'] ); |
||
| 79 | |||
| 80 | } // End if(). |
||
| 81 | } // End if(). |
||
| 82 | |||
| 83 | return apply_filters( 'kirki/values/get_value', $value, $field_id ); |
||
| 84 | |||
| 85 | } |
||
| 86 | |||
| 115 |