Skip to content
Open
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
133 changes: 70 additions & 63 deletions customizer/alpha-color-picker/alpha-color-picker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,75 +19,82 @@
* You should have received a copy of the GNU General Public License
* along with this Alpha Color Picker. If not, see <http://www.gnu.org/licenses/>.
*/
class Customize_Alpha_Color_Control extends WP_Customize_Control {
if(class_exists('WP_Customize_Control')){
class Customize_Alpha_Color_Control extends WP_Customize_Control {

/**
* Official control name.
*/
public $type = 'alpha-color';
/**
* Official control name.
*/
public $type = 'alpha-color';

/**
* Add support for palettes to be passed in.
*
* Supported palette values are true, false, or an array of RGBa and Hex colors.
*/
public $palette;
/**
* Add support for palettes to be passed in.
*
* Supported palette values are true, false, or an array of RGBa and Hex colors.
*/
public $palette;

/**
* Add support for showing the opacity value on the slider handle.
*/
public $show_opacity;
/**
* Add support for showing the opacity value on the slider handle.
*/
public $show_opacity;

/**
* Enqueue scripts and styles.
*
* Ideally these would get registered and given proper paths before this control object
* gets initialized, then we could simply enqueue them here, but for completeness as a
* stand alone class we'll register and enqueue them here.
*/
public function enqueue() {
wp_enqueue_script(
'alpha-color-picker',
get_stylesheet_directory_uri() . '/admin/customizer/alpha-color-picker/alpha-color-picker.js',
array( 'jquery', 'wp-color-picker' ),
'1.0.0',
true
);
wp_enqueue_style(
'alpha-color-picker',
get_stylesheet_directory_uri() . '/admin/customizer/alpha-color-picker/alpha-color-picker.css',
array( 'wp-color-picker' ),
'1.0.0'
);
}

/**
* Render the control.
*/
public function render_content() {

// Process the palette
if ( is_array( $this->palette ) ) {
$palette = implode( '|', $this->palette );
} else {
// Default to true.
$palette = ( false === $this->palette || 'false' === $this->palette ) ? 'false' : 'true';
/**
* Enqueue scripts and styles.
*
* Ideally these would get registered and given proper paths before this control object
* gets initialized, then we could simply enqueue them here, but for completeness as a
* stand alone class we'll register and enqueue them here.
*/
public function enqueue() {
wp_enqueue_script(
'alpha-color-picker',
get_stylesheet_directory_uri() . '/admin/customizer/alpha-color-picker/alpha-color-picker.js',
array( 'jquery', 'wp-color-picker' ),
'1.0.0',
true
);
wp_enqueue_style(
'alpha-color-picker',
get_stylesheet_directory_uri() . '/admin/customizer/alpha-color-picker/alpha-color-picker.css',
array( 'wp-color-picker' ),
'1.0.0'
);
}

// Support passing show_opacity as string or boolean. Default to true.
$show_opacity = ( false === $this->show_opacity || 'false' === $this->show_opacity ) ? 'false' : 'true';
/**
* Render the control.
*/
public function render_content() {

// Begin the output. ?>
<label>
<?php // Output the label and description if they were passed in.
if ( isset( $this->label ) && '' !== $this->label ) {
echo '<span class="customize-control-title">' . sanitize_text_field( $this->label ) . '</span>';
// Process the palette
if ( is_array( $this->palette ) ) {
$palette = implode( '|', $this->palette );
} else {
// Default to true.
$palette = ( false === $this->palette || 'false' === $this->palette ) ? 'false' : 'true';
}
if ( isset( $this->description ) && '' !== $this->description ) {
echo '<span class="description customize-control-description">' . sanitize_text_field( $this->description ) . '</span>';
} ?>
<input class="alpha-color-control" type="text" data-show-opacity="<?php echo $show_opacity; ?>" data-palette="<?php echo esc_attr( $palette ); ?>" data-default-color="<?php echo esc_attr( $this->settings['default']->default ); ?>" <?php $this->link(); ?> />
</label>
<?php

// Support passing show_opacity as string or boolean. Default to true.
$show_opacity = ( false === $this->show_opacity || 'false' === $this->show_opacity ) ? 'false' : 'true';

// Begin the output. ?>
<?php
if($this->label){
echo '<span class="customize-control-title">' . sanitize_text_field( $this->label ) . '</span>';
}
?>
<label>
<?php // Output the label and description if they were passed in.
if ( isset( $this->label ) && '' !== $this->label ) {
echo '<span class="customize-control-title">' . sanitize_text_field( $this->label ) . '</span>';
}
if ( isset( $this->description ) && '' !== $this->description ) {
echo '<span class="description customize-control-description">' . sanitize_text_field( $this->description ) . '</span>';
} ?>
<input class="alpha-color-control" type="text" data-show-opacity="<?php echo $show_opacity; ?>" data-palette="<?php echo esc_attr( $palette ); ?>" data-default-color="<?php echo esc_attr( $this->settings['default']->default ); ?>" <?php $this->link(); ?> />
</label>
<?php
}
}
}
}