mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Introduce new theme customizer to replace theme preview. Rough first pass. props koopersmith, ocean90. see #19910.
Merges in http://plugins.svn.wordpress.org/gandalf/branches/dev/ rev 510148. git-svn-id: https://develop.svn.wordpress.org/trunk@19995 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
83
wp-includes/class-wp-customize-section.php
Normal file
83
wp-includes/class-wp-customize-section.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Customize Section Class
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Customize
|
||||
* @since 3.4.0
|
||||
*/
|
||||
|
||||
class WP_Customize_Section {
|
||||
public $id;
|
||||
public $priority = 10;
|
||||
public $capability = 'edit_theme_options';
|
||||
public $theme_supports = '';
|
||||
public $title = '';
|
||||
public $description = '';
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param string $id An specific ID of the section.
|
||||
* @param array $args Section arguments.
|
||||
*/
|
||||
function __construct( $id, $args = array() ) {
|
||||
$this->id = $id;
|
||||
|
||||
$keys = array_keys( get_class_vars( __CLASS__ ) );
|
||||
foreach ( $keys as $key ) {
|
||||
if ( isset( $args[ $key ] ) )
|
||||
$this->$key = $args[ $key ];
|
||||
}
|
||||
|
||||
$this->settings = array(); // Users cannot customize the $settings array.
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the theme supports the section and check user capabilities.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @return bool False if theme doesn't support the section or user doesn't have the capability.
|
||||
*/
|
||||
function check_capabilities() {
|
||||
if ( ! $this->capability || ! current_user_can( $this->capability ) )
|
||||
return false;
|
||||
|
||||
if ( $this->theme_supports && ! current_theme_supports( $this->theme_supports ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the section.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
function render() {
|
||||
if ( ! $this->check_capabilities() )
|
||||
return;
|
||||
?>
|
||||
<li id="customize-section-<?php echo esc_attr( $this->id ); ?>" class="control-section customize-section">
|
||||
<h3 class="customize-theme-title"><?php echo esc_html( $this->title ); ?></h3>
|
||||
<ul>
|
||||
<?php if ( $this->description ) : ?>
|
||||
<li><p class="howto"><?php echo $this->description; ?></p></li>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ( $this->settings as $setting ) : ?>
|
||||
<li>
|
||||
<?php $setting->_render(); ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user