Skip to content

Instantly share code, notes, and snippets.

@shawnsandy
Created December 18, 2012 04:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnsandy/4324907 to your computer and use it in GitHub Desktop.
Save shawnsandy/4324907 to your computer and use it in GitHub Desktop.
A simple custom control I wrote for the WordPress theme customizer that allows you to create user select drop-down list...
<?php
if (class_exists('WP_Customize_Control')):
class Selected_Users_Control extends WP_Customize_Control {
public $type = 'option';
public $query = array('orderby' => 'nicename');
public $description = '';
public function render_content() {
$query = $this->query;
$pgs = $this->user_array($query);
?>
<label>
<span class="customize-control-title" ><?php echo esc_html($this->label); ?></span>
<select <?php $this->link(); ?>>
<option></option>
<?php foreach ($pgs as $key => $value): ?>
<option value="<?php echo $key ?>" <?php echo ($key == $this->value() ? 'selected' : '') ?>>
<?php echo $value; ?>
</option>
<?php endforeach; ?>
</select>
<span style="display: block"><?php echo esc_html($this->description) ?></span>
</label>
<?php
}
public function user_array($args = '') {
$arrray = get_users($args);
foreach ($arrray as $items) {
$pgs["{$items->ID}"] = $items->user_nicename;
}
return $pgs;
}
}
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment