Skip to content

Commit

Permalink
housekeeping. Added multiple return types
Browse files Browse the repository at this point in the history
  • Loading branch information
kevdotbadger committed Oct 14, 2014
1 parent 99ef6a4 commit 35d1c3d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
69 changes: 53 additions & 16 deletions acf-star_rating-v5.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ function render_field_settings( $field ) {
));

acf_render_field_setting( $field, array(
'label' => __('Return Formatted List?','acf-star_rating'),
'instructions' => __('Should this be returned in a Font-Awesome formatted list?','acf-star_rating'),
'type' => 'radio',
'label' => __('Return Type','acf-star_rating'),
'instructions' => __('What should be returned?','acf-star_rating'),
'type' => 'select',
'layout' => 'horizontal',
'choices' => array(
'1' => __('Yes', 'acf'),
'0' => __('No', 'acf'),
'0' => __('Number', 'num'),
'1' => __('List (unstyled)', 'list_u'),
'2' => __('List (fa-awesome)', 'list_fa'),
),
'name' => 'return_fa'
'name' => 'return_type'
));

}
Expand Down Expand Up @@ -136,12 +137,7 @@ function render_field( $field ) {

<ul>
<?php for($count = 1; $count < $field['max_stars'] + 1; $count++): ?>
<?php
$class = "fa-star-o";
if( $count <= esc_attr($field['value']) ){
$class = "fa-star";
}
?>
<?php $class = ($count <= esc_attr($field['value'])) ? "fa-star" : "fa-star-o"; ?>
<li><i class="fa <?php echo $class ?>"></i></li>
<?php endfor ?>
</ul>
Expand Down Expand Up @@ -375,16 +371,57 @@ function update_value( $value, $post_id, $field ) {
*/

function format_value( $value, $post_id, $field ) {

// bail early if no value
if( empty($value) ) {

return $value;

}

// return
return floatval( $value );

switch( $field['return_type'] ){
case 0: // num
return floatval( $value );
break;
case 1: // list (unstyled) ?>

<ul class='star-rating'>
<?php for( $i = 1; $i < $field['max_stars'] + 1; $i++ ): ?>
<?php $class = ($i <= $value) ? "full" : "blank"; ?>
<li class='<?php echo $class ?>'><?php echo $i ?></li>
<?php endfor ?>
</ul>

<?php break;
case 2: // list (styled) ?>

<?php

$dir = plugin_dir_url( __FILE__ );

// register & include CSS
wp_register_style( 'acf-input-star_rating', "{$dir}css/input.css" );
wp_enqueue_style('acf-input-star_rating');

?>

<!-- Get FA -->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

<div class="field_type-star_rating">

<ul>
<?php for( $i = 1; $i < $field['max_stars'] + 1; $i++ ): ?>
<?php $class = ($i <= $value) ? "fa-star" : "fa-star-o"; ?>
<li><i class='fa <?php echo $class ?>'></i></li>
<?php endfor ?>
</ul>

</div>

<?php break;

}

}

Expand Down
2 changes: 0 additions & 2 deletions js/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

function initialize_field( $el ) {

console.log( $el );

var container = $el;
var star_list = $("ul", container);
var star_list_items = $("li", star_list);
Expand Down

0 comments on commit 35d1c3d

Please sign in to comment.