-
-
Save anteprimorac/09612dc1e92b98b29f08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customize Layout Control Class | |
* | |
* @package Slicejack | |
* @since 1.0 | |
*/ | |
class sj_Layout_Control extends WP_Customize_Control { | |
/** | |
* @access public | |
* @var string | |
*/ | |
public $type = 'layout'; | |
/** | |
* @access public | |
* @var array | |
*/ | |
public $layouts; | |
/** | |
* Constructor. | |
* | |
* @since 1.0 | |
* @uses WP_Customize_Control::__construct() | |
* | |
* @param WP_Customize_Manager $manager | |
* @param string $id | |
* @param array $args | |
*/ | |
public function __construct( $manager, $id, $args = array() ) { | |
$this->layouts = $args[ 'layouts' ]; | |
parent::__construct( $manager, $id, $args ); | |
} | |
/** | |
* Enqueue control related scripts/styles. | |
* | |
* @since 1.0 | |
*/ | |
public function enqueue() { | |
wp_enqueue_style( 'customize-control-layout' ); | |
wp_enqueue_script( 'customize-control-layout' ); | |
} | |
/** | |
* Refresh the parameters passed to the JavaScript via JSON. | |
* | |
* @since 1.0 | |
* @uses WP_Customize_Control::to_json() | |
*/ | |
public function to_json() { | |
parent::to_json(); | |
$this->json['layouts'] = $this->layouts; | |
} | |
/** | |
* Render the control's content. | |
* | |
* @since 1.0 | |
*/ | |
public function render_content() { | |
if ( empty( $this->layouts ) ) | |
return; | |
$name = '_customize-layout-' . $this->id; | |
?> | |
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> | |
<div class="customize-control-content"> | |
<div class="radios"> | |
<?php | |
foreach ( $this->layouts as $value => $layout ) : | |
?> | |
<label> | |
<input type="radio" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> /> | |
<?php echo esc_html( $layout[ 'label' ] ); ?><br/> | |
</label> | |
<?php | |
endforeach; | |
?> | |
</div> | |
<div class="selection"><!-- | |
<?php | |
foreach ( $this->layouts as $value => $layout ) : | |
?> | |
--><div class="layout" data-value="<?php echo $value; ?>"> | |
<div class="icon"><?php echo esc_html( $layout[ 'label' ] ); ?></div> | |
</div><!-- | |
<?php | |
endforeach; | |
?> | |
--></div> | |
</div> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment