Skip to content

Commit

Permalink
added filter for adding counter to fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Hube2 committed Sep 27, 2016
1 parent 0eb0e53 commit f173b29
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions acf-input-counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ public function render_field($field) {
}
$len = strlen($field['value']);
$max = $field['maxlength'];

$classes = apply_filters('acf-input-counter/classes', array());
$ids = apply_filters('acf-input-counter/ids', array());

$insert = true;
if (count($classes) || count($ids)) {
$insert = false;

$exist = array();
if ($field['wrapper']['class']) {
$exist = explode(' ', $field['wrapper']['class']);
}
$insert = $this->check($classes, $exist);

if (!$insert && $field['wrapper']['id']) {
$exist = array();
if ($field['wrapper']['id']) {
$exist = explode(' ', $field['wrapper']['id']);
}
$insert = $this->check($ids, $exist);
}
} // end if filter classes or ids

if (!$insert) {
return;
}
?>
<span class="char-count">
<?php
Expand All @@ -69,6 +95,16 @@ public function render_field($field) {
</span>
<?php
} // end public function render_field

private function check($allow, $exist) {
// if there is anything in $allow
// see if any of those values are in $exist
$intersect = array_intersect($allow, $exist);
if (count($intersect)) {
return true;
}
return false;
} // end private function check

} // end class acf_input_counter

Expand Down

0 comments on commit f173b29

Please sign in to comment.