Created
December 18, 2012 04:04
-
-
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...
This file contains hidden or 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 | |
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