Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing saving of options as theme_mods or options #318

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/class-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ public function register( $wp_customize ) {
$wp_customize->add_setting( $option->getID(), array(
'default' => $option->settings['default'],
'transport' => $transport,
'type' =>$option->settings['save_type']
) );
}

Expand Down
3 changes: 2 additions & 1 deletion lib/class-option-multicheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ public function cleanValueForSaving( $value ) {
return array();
}
if ( is_serialized( $value ) ) {
$value = unserialize($value);
return $value;
}
// CSV
if ( is_string( $value ) ) {
$value = explode( ',', $value );
}
return serialize( $value );
return implode( ',',$value );
}

public function cleanValueForGetting( $value ) {
Expand Down
30 changes: 22 additions & 8 deletions lib/class-option.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class TitanFrameworkOption {
'transport' => '',

'example' => '', // An example value for this field, will be displayed in a <code>

'save_type' => 'option'
);

/**
Expand Down Expand Up @@ -148,9 +150,11 @@ public function getValue( $postID = null ) {
}

if ( $this->type == self::TYPE_ADMIN ) {

$value = $this->getFramework()->getInternalAdminPageOption( $this->settings['id'], $this->settings['default'] );

if($this->settings['save_type'] == 'theme_mod'){
$value = get_theme_mod( $this->getID(), $this->settings['default'] );
}else{
$value = $this->getFramework()->getInternalAdminPageOption( $this->settings['id'], $this->settings['default'] );
}
} else if ( $this->type == self::TYPE_META ) {

if ( empty( $postID ) ) {
Expand All @@ -167,9 +171,11 @@ public function getValue( $postID = null ) {
} else {
$value = $this->settings['default'];
}
} else if ( $this->type == self::TYPE_CUSTOMIZER ) {
} else if ( $this->type == self::TYPE_CUSTOMIZER && $this->settings['save_type'] == 'theme_mod') {
$value = get_theme_mod( $this->getID(), $this->settings['default'] );
}
}else if($this->type == self::TYPE_CUSTOMIZER){
$value = $this->getFramework()->getInternalAdminPageOption( $this->settings['id'], $this->settings['default'] );
}

/**
* Allow others to change the value of the option before it gets cleaned
Expand Down Expand Up @@ -199,8 +205,11 @@ public function setValue( $value, $postID = null ) {
$value = $this->cleanValueForSaving( $value );

if ( $this->type == self::TYPE_ADMIN ) {

if($this->settings['save_type'] == 'theme_mod'){
$value = set_theme_mod( $this->getID(), $value );
}else{
$this->getFramework()->setInternalAdminPageOption( $this->settings['id'], $value );
}

} else if ( $this->type == self::TYPE_META ) {

Expand All @@ -214,11 +223,13 @@ public function setValue( $value, $postID = null ) {

update_post_meta( $postID, $this->getID(), $value );

} else if ( $this->type == self::TYPE_CUSTOMIZER ) {
} else if ( $this->type == self::TYPE_CUSTOMIZER && $this->settings['save_type'] == 'theme_mod' ) {

set_theme_mod( $this->getID(), $value );

}
}else if($this->type == self::TYPE_CUSTOMIZER){
$this->getFramework()->setInternalAdminPageOption( $this->settings['id'], $value );
}

do_action( 'tf_set_value_' . $this->settings['type'] . '_' . $this->getOptionNamespace(), $value, $postID, $this );

Expand Down Expand Up @@ -256,6 +267,9 @@ public function getOptionNamespace() {
}

public function getID() {
if($this->type == self::TYPE_CUSTOMIZER && $this->settings['save_type'] == 'option'){
return $this->getOptionNamespace().'_options['.$this->settings['id'].']';
}
return $this->getOptionNamespace() . '_' . $this->settings['id'];
}

Expand Down
4 changes: 2 additions & 2 deletions lib/class-titan-framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected function getInternalAdminOptions() {

// Put all the available options in our global variable for future checking.
if ( ! empty( $currentOptions ) && ! count( $this->adminOptions ) ) {
$this->adminOptions = unserialize( $currentOptions );
$this->adminOptions = $currentOptions;
}

if ( empty( $this->adminOptions ) ) {
Expand Down Expand Up @@ -305,7 +305,7 @@ public function saveInternalAdminPageOptions() {
// Run this first to ensure that adminOptions carries all our admin page options.
$this->getInternalAdminOptions();

update_option( $this->optionNamespace . '_options', serialize( $this->adminOptions ) );
update_option( $this->optionNamespace . '_options', $this->adminOptions );
do_action( 'tf_save_options_' . $this->optionNamespace );
return $this->adminOptions;
}
Expand Down