Skip to content

Commit

Permalink
minor code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Jul 21, 2017
1 parent 0b88e7e commit 9d6026b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
10 changes: 4 additions & 6 deletions core/class-kirki-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ final class Kirki_Config {
* Use the get_instance() static method to get the instance you need.
*
* @access private
*
* @param string $config_id @see Kirki_Config::get_instance().
* @param array $args @see Kirki_Config::get_instance().
*/
Expand All @@ -108,9 +107,10 @@ private function __construct( $config_id = 'global', $args = array() ) {
}
}

$this->config_final = $args;
$this->config_final['id'] = $config_id;

$this->config_final = wp_parse_args(
array( 'id' => $config_id ),
$args
);
}

/**
Expand Down Expand Up @@ -152,12 +152,10 @@ public static function get_instance( $id = 'global', $args = array() ) {
* Returns the $config_final property
*
* @access public
*
* @return array
*/
public function get_config() {

return $this->config_final;

}
}
22 changes: 18 additions & 4 deletions core/class-kirki.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class Kirki extends Kirki_Init {
public static function get_option( $config_id = '', $field_id = '' ) {

return Kirki_Values::get_value( $config_id, $field_id );

}

/**
Expand All @@ -116,7 +115,6 @@ public static function add_config( $config_id, $args = array() ) {
$config = Kirki_Config::get_instance( $config_id, $args );
$config_args = $config->get_config();
self::$config[ $config_args['id'] ] = $config_args;

}

/**
Expand All @@ -139,7 +137,6 @@ public static function add_panel( $id = '', $args = array() ) {
}

self::$panels[ $args['id'] ] = $args;

}

/**
Expand All @@ -163,7 +160,6 @@ public static function add_section( $id, $args ) {
}

self::$sections[ $args['id'] ] = $args;

}

/**
Expand Down Expand Up @@ -199,4 +195,22 @@ public static function add_field( $config_id, $args ) {
new Kirki_Field( $config_id, $args );

}

/**
* Gets a parameter for a config-id.
*
* @static
* @access public
* @since 3.0.10
* @param string $id The config-ID.
* @param string $param The parameter we want.
* @return string
*/
public static function get_config_param( $id, $param ) {

if ( ! isset( self::$config[ $id ] ) || ! isset( self::$config[ $id ][ $param ] ) ) {
return '';
}
return self::$config[ $id ][ $param ];
}
}
13 changes: 3 additions & 10 deletions modules/css/class-kirki-output.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,9 @@ protected function apply_value_pattern( $output, $value ) {
}
}
if ( isset( $output['pattern_replace'] ) && is_array( $output['pattern_replace'] ) ) {
$option_type = 'theme_mod';
$option_name = false;
if ( isset( Kirki::$config[ $this->config_id ] ) ) {
$config = Kirki::$config[ $this->config_id ];
$option_type = ( isset( $config['option_type'] ) ) ? $config['option_type'] : 'theme_mod';
if ( 'option' === $option_type || 'site_option' === $option_type ) {
$option_name = ( isset( $config['option_name'] ) ) ? $config['option_name'] : false;
}
}
$options = array();
$option_type = ( '' !== Kirki::get_config_param( $this->config_id, 'option_type' ) ) ? Kirki::get_config_param( $this->config_id, 'option_type' ) : 'theme_mod';
$option_name = Kirki::get_config_param( $this->config_id, 'option_name' );
$options = array();
if ( $option_name ) {
$options = ( 'site_option' === $option_type ) ? get_site_option( $option_name ) : get_option( $option_name );
}
Expand Down

0 comments on commit 9d6026b

Please sign in to comment.