Make WordPress Core

Opened 8 years ago

Closed 7 years ago

#37174 closed defect (bug) (fixed)

class-wp-customize-color-control.php fails when data.defaultValue is empty

Reported by: andreagobetti's profile andreagobetti Owned by: westonruter's profile westonruter
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.1
Component: Customize Keywords: has-patch
Focuses: javascript, administration, template Cc:

Description

When using the visual composer (wp-admin/customize.php) sometimes it simply does not work and throws the error:

data.defaultValue.substring( 0, 1 ) it's not a function

I fixed it by replacing:

public function content_template() {
		?>
		<#
		var defaultValue = '';
		if(data.defaultValue)
		{
			

with:

public function content_template() {
		?>
		<#
		var defaultValue = '';
		if(data.defaultValue && data.defaultValue.length>0)
		{
			

Attachments (1)

37174.0.diff (667 bytes) - added by westonruter 8 years ago.
Check if default value _.isString()

Download all attachments as: .zip

Change History (12)

#1 @azaozz
8 years ago

  • Component changed from Editor to Customize

#2 @westonruter
8 years ago

@andreagobetti is the color picker control for a core setting (e.g. background color) or for a setting of your own? What is the underlying value of setting? If it is false then this would explain it.

@westonruter
8 years ago

Check if default value _.isString()

#3 @westonruter
8 years ago

  • Keywords has-patch reporter-feedback added

#4 @yonivh
7 years ago

I had the same issue which gave me a "Uncaught TypeError: data.defaultValue.substring is not a function" console notice which broke the customizer. Adding the length check fixed it for me.

I can confirm the 'Palmas' theme produced this problem for me. After switching to another theme, the customizer worked just fine.

#5 @westonruter
7 years ago

@yonivh The Palmas theme is not on WordPress.org so I can't test it. Can you try 37174.0.diff and see if it fixes the issue?

#6 @westonruter
7 years ago

@yonivh it would be helpful to actually see what defaultValue is being set to in the theme.

#7 @yonivh
7 years ago

@westonruter, that fix also works for me.

The additional info you requested: when I log data.defaultValue in the console, it returns nothing. When I use some random print_r/var_dump function (https://jsfiddle.net/jaredwilli/jtqNY/) it tells me the variable is an empty object. So I've just logged 'data'. Results are below.

This is a child of data which works:

active:true
content:"<li id="customize-control-border_color" class="customize-control customize-control-color">↵					</li>"
defaultValue:"#dddddd"
description:""
instanceNumber:59
label:"Border color"
mode:"full"
priority:4
section:"colors"
settings:{default: "border_color"}
statuses:{"": "Standaard"}
type:"color"

This is a child of data which doesn't work:

active:true
content:"<li id="customize-control-widget_title_color" class="customize-control customize-control-color">↵					</li>"
defaultValue:[]
description:""
instanceNumber:60
label:"Widget title color"
mode:"full"
priority:4
section:"colors"
settings:{default: "widget_title_color"}
statuses:{"": "Standaard"}
type:"color"

Update: When I open the customizer and select a color for "Background & Sidebar Colors / Widget title color", this is inside the input field: "[object Object]".

Last edited 7 years ago by yonivh (previous) (diff)

#8 @westonruter
7 years ago

@yonivh which theme is being used which results in defaultValue: []?

#9 @yonivh
7 years ago

@westonruter, it's called 'Palmas' and can be found here: https://justfreethemes.com/palmas/

#10 @westonruter
7 years ago

  • Keywords reporter-feedback removed
  • Milestone changed from Awaiting Review to 4.9
  • Owner set to westonruter
  • Status changed from new to accepted
  • Version changed from 4.5.3 to 4.1

#11 @westonruter
7 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 41256:

Customize: Harden color control's logic for obtaining default value to prevent JS error when non-string default supplied.

Props andreagobetti, yonivh for testing.
Fixes #37174.

Note: See TracTickets for help on using tickets.