Unyson Error On Theme Change
I'm using the Unyson Page Builder and have added some custom Shortcodes in my Theme. When changing the theme, usually shortcodes turn into ordinary text, because the Shortcodes are not available in the other Theme. But I also receive an error on the page when it is loaded:
( ! ) Notice: Array to string conversion in \wp-content\plugins\unyson\framework\includes\option-types\color-picker\class-fw-option-type-color-picker.php on line 84
--
1 | 0.0005 | 243336 | {main}( ) | ...\index.php:0
2 | 0.0007 | 246408 | require( '...\wp-blog-header.php' ) | ...\index.php:17
3 | 1.0969 | 63168696 | wp( ) | ...\wp-blog-header.php:16
4 | 1.0969 | 63168992 | WP->main( ) | ...\functions.php:955
5 | 1.1013 | 63225584 | WP->query_posts( ) | ...\class-wp.php:735
6 | 1.1014 | 63226056 | WP_Query->query( ) | ...\class-wp.php:617
7 | 1.1014 | 63233008 | WP_Query->get_posts( ) | ...\class-wp-query.php:3248
8 | 1.1037 | 63265720 | apply_filters_ref_array( ) | ...\class-wp-query.php:3007
9 | 1.1037 | 63265800 | WP_Hook->apply_filters( ) | ...\plugin.php:244
10 | 1.1037 | 63267096 | call_user_func_array:{ ...\wp-includes\class-wp-hook.php:298} ( ) | ...\class-wp-hook.php:298
11 | 1.1037 | 63267688 | FW_Extension_Page_Builder->_filter_the_posts( ) | ...\class-wp-hook.php:298
12 | 1.1038 | 63268424 | FW_Extension_Page_Builder->get_post_content_shortcodes( ) | ...\class-fw-extension-page-builder.php:375
13 | 1.1287 | 63670616 | FW_Option_Type_Page_Builder->json_to_shortcodes( ) | ...\class-fw-extension-page-builder.php:329
14 | 1.1288 | 63697320 | FW_Option_Type_Builder->get_value_from_items( ) | ...\class-fw-option-type-page-builder.php:285
15 | 1.1292 | 63698464 | Page_Builder_Section_Item->get_value_from_attributes( ) | ...\class-fw-option-type-builder.php:131
16 | 1.1293 | 63702272 | fw_get_options_values_from_input( ) | ...\class-page-builder-section-item.php:96
17 | 1.1295 | 63705640 | FW_Option_Type->get_value_from_input( ) | ...\general.php:1155
18 | 1.1296 | 63707144 | FW_Option_Type_Color_Picker->_get_value_from_input( ) | ...\class-fw-option-type.php:296
There is no problem when deactivating the plugin - shortocodes are just displayed as ordinary text. But if the theme is changed and Unyson activated the above mentioned Error is displayed. It's visible when WP_DEBUG is 'true', but still it's a problem. I'm not sure the problem is exactly in that file, as I don't see it having any connection with the fields in the Shortcode.
I'm using the latest WordPress and Unyson versions.
If theme have customs hortcodes and you change theme they are rendered as simple text whitout errors, maybe you use functions from plugin without checking if unyson is enabled, there are many causes that can generate this share your code so I can see what is wrong.
There are no additional plugins that use Unyson functions - with only Unyson activated, the error is visible. Other than that, I'm using Unyson Theme Settings in the Theme to change colors/typography. Could it be something from the database that is checked from Unyson, but fails when the theme is changed?
Unyson on activate/deactivate theme check for required extensions and don't touch shortcodes options I can't reproduce this if you want me to help, you need to show your code you can send it here: viorel [ at ] themefuse [ dot ] com
I managed to pinpoint the problem, which is quite bizarre. I'm defining my own Section Shortcode in the Theme which has a different background_color field:
'background_color' => array(
'type' => 'multi-picker',
'label' => false,
'desc' => false,
'value' => array(
'background_color' => 'no',
),
'picker' => array(
'background_color' => array(
'type' => 'switch',
'value' => 'no',
'label' => esc_html__('Background Color', 'odrin'),
'left-choice' => array(
'value' => 'yes' ,
'label' => esc_html__('Yes', 'odrin'),
),
'right-choice' => array(
'value' => 'no',
'label' => esc_html__('No', 'odrin'),
),
),
),
'choices' => array(
'yes' => array(
'background_color' => array(
'label' => esc_html__( 'Choose Color', 'odrin' ),
'desc' => esc_html__('Please select the background color', 'odrin'),
'type' => 'color-picker',
'value' => '#ffffff'
),
)
),
'show_borders' => false,
),
The problem comes from the fact that when the Theme is changed, the Section options switch to the default ones, which also have a background_color field, but defined differently:
'background_color' => array(
'label' => __('Background Color', 'fw'),
'desc' => __('Please select the background color', 'fw'),
'type' => 'color-picker',
),
But as the Page now "remembers" the first Section options from the custom Shortcode, the value given in the class-fw-option-type-color-picker.php file, is an array - which is where the error comes from.
If I change the name of my field so that it doesn't overwrite the default background_color the problem is gone, as my field is no longer loaded when the Theme is changed. I'm not sure if this will require any changes in the plugin or perhaps in the documentation, as this is quite a "niche" problem, but can be troublesome to find.
I don't think all options should be controlled by type because this can create a big memory consumption and a long delay execution if you have many options. Unyson is a plugin more oriented for developers so developers rewriting plugin functionality need to know what they are doing.