Save Same Options In Builder and Customizer
Is there a way to save the same option in page-builder and customizer? Or can you direct me to which methods are responsible for saving in page-builder and customizer?
Do you mean to have an option in page-builder, when it's value is updated to update another option value in customizer options, and vice versa?
Yes. Are there fw methods or hooks to alter save_post and customize_save_after to conditionally update both options?
There is fw-storage option parameter. But at the moment it doesn't work with customizer options (only with post options), I will fix that soon.
https://github.com/ThemeFuse/Unyson/issues/1352#issuecomment-196378312
It already works:
-
Add in Theme Settings options
'customizer-option-id' => array( 'type' => 'switch', ), -
Add in Post options
'post-option-id' => array( 'type' => 'switch', 'fw-storage' => array( 'type' => 'wp-option', 'wp-option' => 'theme_mods_'. get_option( 'stylesheet' ), 'key' => 'fw_options/customizer-option-id', ), ),
I'm unable to get this working in 2.5.0.
- Added in customizer.php
'customizer-option-id' => array(
'type' => 'switch',
),
- Added in shortcode options.php tried {theme}/framework-customizations/theme/options/post.php and page.php
'post-option-id' => array(
'type' => 'switch',
'fw-storage' => array(
'type' => 'wp-option',
'wp-option' => 'theme_mods_'. get_option( 'stylesheet' ),
'key' => 'fw_options/customizer-option-id',
),
),
I get a switch that doesn't update in customizer. The switch also doesn't show the ON and OFF values in customizer, which is odd since they are the defaults.
Can you give me admin access to your site? (my email moldcraft[at]email.com)
Also, does this fw-storage feature work for shortcode options #838?
For example: If the option_id is the same whether you put the option in customizer, shortcode option, page, post it will write the value data to all relevant db tables?
So, If I have save the same option id in customizer it will save it any place that option_id is used?
I'm testing this locally and I don't believe I have the ability to give admin access.
https://github.com/ThemeFuse/Unyson/issues/1388#issuecomment-202479776
Yes
https://github.com/ThemeFuse/Unyson/issues/1388#issuecomment-202481705
Then I don't know how to help. I tested the above code on my localhost and it works.
Does this feature work on a multi site?
I'm getting really odd behavior where saving in page-builder is completely deleting the theme_mods option_value. Sometimes it replaces the option_value column with just the switch value of 1 (not json encoded).
Then I have to clear theme_mods in wp_options for anything to write to that row.
If I save the switch in customizer it will save in theme_mods json encoded with key fw_option, but if I check postmeta fw_options post-option-id doesn't change for the current post_id or the last revision.
I haven't tested it on multisite
Ok. I'm duplicating this behavior on a single site with 2015 theme. Are we 100% sure fw-storage in 2.5.0 is stable?
Here are the steps I produced the issue.
- Stock WP single site
- 2015 Theme
- Added {theme}/inc/init.php
- Added {theme}/options/customizer.php
$options = array(
'customizer-option-id' => array(
'type' => 'switch',
),
);
- Added {theme}/options/posts/page.php
$options = array(
'post-option-id' => array(
'type' => 'switch',
'fw-storage' => array(
'type' => 'wp-option',
'wp-option' => 'theme_mods_'. get_option( 'stylesheet' ),
'key' => 'fw_options/customizer-option-id',
),
),
),
Result:
- Save switch ON in customizer
wp_options>theme_mods_twenty_fifteen:
a:1:{s:10:"fw_options";a:1:{s:20:"customizer-option-id";b:1;}}
wp_postmeta>post_id:
a:5:{s:12:"page-builder";a:4:{s:4:"json";s:2:"[]";s:14:"corrected_json";s:2:"[]";s:18:"shortcode_notation";s:0:"";s:14:"builder_active";b:1;}s:14:"post-option-id";b:0;}
- Save switch ON in page-builder
wp_options>theme_mods_twenty_fifteen: 1
wp_postmeta>post_id:
a:8:{s:12:"page-builder";a:4:{s:4:"json";s:2:"[]";s:14:"corrected_json";s:2:"[]";s:18:"shortcode_notation";s:0:"";s:14:"builder_active";b:1;}s:14:"post-option-id";b:0;}
Now if I save from page-builder it will write 1 to theme_mods for ON and it clears theme_mods for OFF. And if theme_mods has an option_value of 1 then any customizer changes will not write to the db.
Oh, sorry, I forgot that the 'key' parameter in 'fw-storage' is not included in 2.5.0, it will be included in 2.5.1, so download Unyson from Github.
Nice! What are the option parameters to save customizer option to page-builder? https://github.com/ThemeFuse/Unyson/issues/1388#issuecomment-201440068
I tried reversing the options and using
'customizer-option-id' => array( 'type' => 'switch', 'fw-storage' => array( 'type' => 'post-meta', 'post-id' => 11, 'post-meta' => 'post-option-id', ), ),
but that still saves customizer-option-id to theme_mods.
save customizer option to page-builder
It's not possible. Currently only post options support the fw-storage parameter.
You need this functionality or just testing?
Ah Ok. I thought that was the point of #838.
What is class FW_Option_Storage_Type_Post_Meta for? I thought fw-storage is used to store shortcode options, page, post, customizer etc. and then write it to the specified db location under the specified id.
The desired behavior is:
-
Customizer to Shortcode/Page/Posts Change customizer option Affects shortcode/page/post options Saves in wp_post_meta, wp_posts (or as specified in option)
-
Shortcode/Page/Posts to Customizer Change shortcode/page/post options Affects customizer option Saves in wp_options (or as specified in option)
Does fw-storage work for shortcodes? When I put fw-storage with type wp-option inside a shortcodes options.php it doesn't work.
I'm just testing now, but I think this functionality is necessary.
What is class FW_Option_Storage_Type_Post_Meta for?
To handle this:
array(
'type' => 'switch',
'fw-storage' => array(
'type' => 'post-meta', // <---
// ...
),
)
When this functionality will be necessary, let me know and I will implemented, at the moment I don't want to spend time for it.
At the moment (2) works.
customizer(native) ---> wp_option <--- postOptions(fw-storage)
Does the current functionality work for shortcodes or just {theme}/framework-customizations/theme/options/posts/?
It works with shortcodes. PageBuilder is an option located in post options, and fw-storage is processed recursive til the shortcodes options.