GithubHelp home page GithubHelp logo

hube2 / acf-input-counter Goto Github PK

View Code? Open in Web Editor NEW
70.0 7.0 25.0 48 KB

Adds a counter to all text and textarea fields with character limits

License: GNU General Public License v3.0

JavaScript 12.50% PHP 85.51% CSS 1.99%

acf-input-counter's Introduction

ACF Input Counter

Supports ACF 5

Adds a counter to all text and textarea fields with character limits.

This is a simple plugin that will add a counter below all ACF text and text area fields to show how many characters have been added and what the limit is. The display will look something like this:

chars: 25 of 55

This plugin will not work in ACF 4 for 2 reasons:

  • The acf/render_field hook is not supported by ACF 4
  • The JavaScript used in this plugin is specific to ACF 5

This plugin also serves as a simple example of how to extend the functionality of fields in ACF 5.

Add Counter Filter

By defaults, the counter is added to all text and textarea fields that have a max length. If you would like to only add the counter on specific fields you can filter them by either the ACF Wrapper Class or the ACF Wrapper ID of the field. You can allow multiple classes or ids. If classes or ID values are present then only fields that have one of the classes or ids will include a counter.

Filter by Class

add_filter('acf-input-counter/classes', 'my_input_counter_filter');
function my_input_counter_filter($classes=array()) {
  // add 1 or more classes to the array
	$classes[] = 'this-is-a-class';
	return $classes;
}

Fields that have one of the classes or ids will include a counter.

Filter by ID

add_filter('acf-input-counter/ids', 'my_input_counter_filter');
function my_input_counter_filter($ids=array()) {
  // add 1 or more classes to the array
	$ids[] = 'this-is-an-ID';
	return $ids;
}

Filter the Display

To filter the display add a filter wherever you would add a filter.

add_filter('acf-input-counter/display', 'my_acf_counter_filter');
function my_acf_counter_filter($display) {
    $display = sprintf(
        __('Characters = %1$s of %2$s', 'acf-counter'),
        '%%len%%',
        '%%max%%'
    );
	return $display;
}

In the example string above %%len%% represents where you want the current character count shown, %%max%% represents where you want the fields maximum length displayed and %%remain%% represents where you want the remaining character length displayed. You can generate this string any way you want. For example, you can translate it or use sprintf(), as long as it contains the two markers where the values should be shown. If you do not include these markers then they simply will not be shown. It's up to you to make sure they are present.

I've puzzled with how to allow this to be altered and this is the best I've been able to come up with. If you have a better idea, let me know in the issues.

Automatic Updates

Install GitHub Updater on your site if you want to recieve automatic updates for this plugin.

Remove Nag

You may notice that I've started adding a little nag to my plugins. It's just a box on some pages that lists my plugins that you're using with a request do consider making a donation for using them. If you want to disable them add the following filter to your functions.php file.

add_filter('remove_hube2_nag', '__return_true');

i18n

The plugin is now also internationalized and it has a .pot file. Also included is a Dutch translation by Beee.

acf-input-counter's People

Contributors

andymardell avatar beee4life avatar gemmadlou avatar hanscz avatar hube2 avatar jameelmoses avatar jbboynton avatar jsphpl avatar treyssatvincent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

acf-input-counter's Issues

Wordpress Plugin Repository

It's not really an issue, but are there any plans to have this plugin in the Wordpress Plugin repository? If so, that would be awesome. I'd love to assist you think it's a good idea.

Not working with ACF v5.4.5?

Not too familiar with either the plugin or ACF internals so apologies if I'm missing something obvious. I can see in dev tools that acf-input-counter.js is being loaded, my text field does have a limit of 160 characters (published the group twice after installing the plugin just to make sure) but I still cannot see counter appear.

Field definition:

field_definition

Field in use:

field

Let me know how I can help nail down the problem.

Possible 'feature' ?

I noticed that there is no counter/limit on the number field in ACF Pro.

Maybe that could be an addition ?

Possible features ?

Is it possible to use placeholder instead of max-length to trigger the counter ? In fact, i would like this counter but i don't need to limit my characters with max-length

filter fields

Add filter to allow only adding counter to specific fields. Will require additional checks in JS to make sure containers exist before trying to insert count into non-existent elements.

Visual part of tinymce broken

Just a heads up, I installed ACF Input Counter 1.4.0 and ACF 5.6.10 and on activation of ACF Input Counter the visual part of the wysiwyg no longer displays, the text in the field is shown as html and the visual tab no longer works.

Interfering with ACF

checking to see if the current page is the acf field group editor is somehow interfering with ACF

Add a proper readme file

Like it says, this should have a proper readme.txt file so that people can see what's been updated if they use github updater.

Small bug Notice: Trying to get property of non-object

Hi John, i find a small bug in file acf-input-counter.php

In line 61:

$len = strlen(get_field($field['name'], $post->ID, false));

With Debug TRUE, generated this error: Notice: Trying to get property of non-object

filter display

Add filter so that display of max and count can be altered.

wysiwyg editor char limits not showing after last update

After last update characters in other fields again began to show count as I typed. But way to set character limits in wysiwyg editors are now gone. I am not a coder. This was helping me a lot to write content for web pages without spilling over beyond design box boundaries. Request this to be addressed please. I truly appreciate all the hard work you put in, and it is because of people like you that some of us can have some relief in otherwise complex work. Thanks a lot, and wish you all the best.

Merge WYSIWYG support

I'm wondering if I updated and got the WYSIWYG support working again if you would consider merging it here. @puntonero created this feature here when the plugin was at 1.4, but now it's no longer working for me with the current ACF release and this plugin is up to 1.5...

Definitely a feature I would be willing to help maintain and seems like it would make sense to have everyone contributing to the same code base. Just getting a sense for if I need to plan to maintain my own fork for this feature or not.

Thanks!

Version mismatch

Looks like acf-input-counter.php is version 1.4.1 but releases stop at 1.4.0

Unexpected result with &

I have a text field which is capped at let's say 50 characters.

If I write a title which has 49 characters and includes an &, an error is thrown, since & gets stored as & which is 4 characters more and this not a 'valid input'.

Is there a way around this ???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.