control-color-alpha icon indicating copy to clipboard operation
control-color-alpha copied to clipboard

Unable to get it to work

Open idlevibes95 opened this issue 3 years ago • 2 comments

Sorry in advance if my question is stupid and I know it's probably an easy fix, but I've been trying to make it work for hours and I just don't know what I'm doing wrong.

I've added the ColorAlpha.php, WPTRTColorAlphaControl.js, WPTRTColorAlphaForm.js and index.js files to the inc file in my theme.

I've added this in functions.php:

add_action( 'customize_register', function( $wp_customize ) { $wp_customize->register_control_type( '\WPTRT\Customize\Control\ColorAlpha' ); } );

I've added these codes in customizer.php (also in inc, if it matters):

use \WPTRT\Customize\Control\ColorAlpha;

add_action( 'customize_register', function( $wp_customize ) {

	$wp_customize->add_setting( 'your_setting_id' , [
		'default'           => 'rgba(0,0,0,0.5)', // Use any HEX or RGBA value.
		'transport'         => 'refresh',
		'sanitize_callback' => 'my_custom_sanitization_callback'
	] );
	$wp_customize->add_control( new ColorAlpha( $wp_customize, 'your_setting_id', [
		'label'      => __( 'My Color', 'mytheme' ),
		'section'    => 'colors',
		'settings'   => 'your_setting_id',
	] ) );

} );

And when I try to check the customizer, I get a critical error message:

Uncaught Error: Class 'WPTRT\Customize\Control\ColorAlpha' not found in /wp-content/themes/theme-name/inc/customizer.php:17

idlevibes95 avatar Jan 17 '22 21:01 idlevibes95

You have use \WPTRT\... but did you actually load the file with require or include?

joyously avatar Jan 17 '22 22:01 joyously

I've added it and the error is gone, but the control is not showing up at all. The Colors section is empty.

idlevibes95 avatar Jan 18 '22 20:01 idlevibes95