Skip to content

Commit

Permalink
Merge pull request #11 from Beee4life/master
Browse files Browse the repository at this point in the history
Internationalization
  • Loading branch information
Hube2 committed Nov 25, 2016
2 parents b3401c4 + 2d99f7c commit 237978b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 48 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Supports ACF 5

Adds a counter to all text and textarea fields with character limits
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:
Expand Down Expand Up @@ -32,7 +32,7 @@ function my_input_counter_filter($classes=array()) {
return $classes;
}
```
fields that have one of the classes or ids will include a counter.
Fields that have one of the classes or ids will include a counter.

**Filter by ID**
```
Expand All @@ -45,11 +45,15 @@ function my_input_counter_filter($ids=array()) {
```

### Filter the Display
To filter the display add a filter wherever you would add a filter
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 = 'Characters = %%len%% of %%max%%';
$display = sprintf(
__('Characters = %1$s of %2$s', 'acf-counter'),
'%%len%%',
'%%max%%'
);
return $display;
}
```
Expand All @@ -73,3 +77,8 @@ 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][1].

[1]: https://github.com/Beee4life/
99 changes: 55 additions & 44 deletions acf-input-counter.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
<?php

/*
Plugin Name: ACF Input Counter
Plugin URI: https://github.com/Hube2/acf-input-counter/
Description: Show character count for limited text and textarea fields
Version: 1.3.1
Version: 1.4.0
Author: John A. Huebner II
Author URI: https://github.com/Hube2/
Text-domain: acf-counter
Domain-path: languages
GitHub Plugin URI: https://github.com/Hube2/acf-input-counter/
License: GPL
*/
Expand All @@ -18,24 +20,29 @@

class acf_input_counter {

private $version = '1.2.0';
private $version = '1.4.0';

public function __construct() {
add_action('acf/render_field/type=text', array($this, 'render_field'), 20, 1);
add_action('acf/render_field/type=textarea', array($this, 'render_field'), 20, 1);
add_action('acf/input/admin_enqueue_scripts', array($this, 'scripts'));
add_filter('jh_plugins_list', array($this, 'meta_box_data'));
add_action('plugins_loaded', array($this, 'acf_counter_load_plugin_textdomain'));
add_action('acf/render_field/type=text', array($this, 'render_field'), 20, 1);
add_action('acf/render_field/type=textarea', array($this, 'render_field'), 20, 1);
add_action('acf/input/admin_enqueue_scripts', array($this, 'scripts'));
add_filter('jh_plugins_list', array($this, 'meta_box_data'));
} // end public function __construct


public function acf_counter_load_plugin_textdomain() {
load_plugin_textdomain( 'acf-counter', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}

function meta_box_data($plugins=array()) {

$plugins[] = array(
'title' => 'ACF Input Counter',
'screens' => array('acf-field-group', 'edit-acf-field-group'),
'doc' => 'https://github.com/Hube2/acf-input-counter'
'title' => 'ACF Input Counter',
'screens' => array('acf-field-group', 'edit-acf-field-group'),
'doc' => 'https://github.com/Hube2/acf-input-counter'
);
return $plugins;

} // end function meta_box

private function run() {
Expand All @@ -54,11 +61,11 @@ public function scripts() {
return;
}
// wp_enqueue_script
$handle = 'acf-input-counter';
$src = plugin_dir_url(__FILE__).'acf-input-counter.js';
$deps = array('acf-input');
$ver = $this->version;
$in_footer = false;
$handle = 'acf-input-counter';
$src = plugin_dir_url(__FILE__).'acf-input-counter.js';
$deps = array('acf-input');
$ver = $this->version;
$in_footer = false;
wp_enqueue_script($handle, $src, $deps, $ver, $in_footer);
wp_enqueue_style('acf-counter', plugins_url( 'acf-counter.css' , __FILE__ ));
} // end public function scripts
Expand All @@ -73,20 +80,20 @@ 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());

$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']) {
Expand All @@ -95,23 +102,27 @@ public function render_field($field) {
$insert = $this->check($ids, $exist);
}
} // end if filter classes or ids

if (!$insert) {
return;
}
$display = 'chars: %%len%% of %%max%%';
$display = sprintf(
__('chars: %1$s of %2$s', 'acf-counter'),
'%%len%%',
'%%max%%'
);
$display = apply_filters('acf-input-counter/display', $display);
$display = str_replace('%%len%%', '<span class="count">'.$len.'</span>', $display);
$display = str_replace('%%max%%', $max, $display);
?>
<span class="char-count">
<?php
<?php
echo $display;
?>
</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
Expand All @@ -123,50 +134,50 @@ private function check($allow, $exist) {
} // end private function check

} // end class acf_input_counter

if (!function_exists('jh_plugins_list_meta_box')) {
function jh_plugins_list_meta_box() {
if (apply_filters('remove_hube2_nag', false)) {
return;
}
$plugins = apply_filters('jh_plugins_list', array());
$id = 'plugins-by-john-huebner';
$title = '<a style="text-decoration: none; font-size: 1em;" href="https://github.com/Hube2" target="_blank">Plugins by John Huebner</a>';
$callback = 'show_blunt_plugins_list_meta_box';
$screens = array();

$id = 'plugins-by-john-huebner';
$title = '<a style="text-decoration: none; font-size: 1em;" href="https://github.com/Hube2" target="_blank">Plugins by John Huebner</a>';
$callback = 'show_blunt_plugins_list_meta_box';
$screens = array();
foreach ($plugins as $plugin) {
$screens = array_merge($screens, $plugin['screens']);
}
$context = 'side';
$priority = 'low';
$context = 'side';
$priority = 'low';
add_meta_box($id, $title, $callback, $screens, $context, $priority);


} // end function jh_plugins_list_meta_box
add_action('add_meta_boxes', 'jh_plugins_list_meta_box');

function show_blunt_plugins_list_meta_box() {
$plugins = apply_filters('jh_plugins_list', array());
?>
<p style="margin-bottom: 0;">Thank you for using my plugins</p>
<ul style="margin-top: 0; margin-left: 1em;">
<?php
<?php
foreach ($plugins as $plugin) {
?>
<li style="list-style-type: disc; list-style-position:">
<?php
<?php
echo $plugin['title'];
if ($plugin['doc']) {
?> <a href="<?php echo $plugin['doc']; ?>" target="_blank">Documentation</a><?php
?> <a href="<?php echo $plugin['doc']; ?>" target="_blank">Documentation</a><?php
}
?>
</li>
<?php
<?php
}
?>
</ul>
<p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hube02%40earthlink%2enet&lc=US&item_name=Donation%20for%20WP%20Plugins%20I%20Use&no_note=0&cn=Add%20special%20instructions%20to%20the%20seller%3a&no_shipping=1&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank">Please consider making a small donation.</a></p><?php
<p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hube02%40earthlink%2enet&lc=US&item_name=Donation%20for%20WP%20Plugins%20I%20Use&no_note=0&cn=Add%20special%20instructions%20to%20the%20seller%3a&no_shipping=1&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank">Please consider making a small donation.</a></p><?php
}
} // end if !function_exists

Expand Down
Binary file added languages/acf-counter-nl_NL.mo
Binary file not shown.
21 changes: 21 additions & 0 deletions languages/acf-counter-nl_NL.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
msgid ""
msgstr ""
"Project-Id-Version: ACF-counter v1.0\n"
"POT-Creation-Date: 2016-11-20 03:04+0100\n"
"PO-Revision-Date: 2016-11-20 03:07+0100\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.11\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-KeywordsList: __;_e\n"
"Last-Translator: Beee\n"
"Language: nl\n"
"X-Poedit-SearchPath-0: .\n"

#: acf-input-counter.php:110
#, php-format
msgid "chars: %1$s of %2$s"
msgstr "tekens: %1$s van %2$s"
22 changes: 22 additions & 0 deletions languages/acf-counter.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: ACF-counter v1.0\n"
"POT-Creation-Date: 2016-11-20 03:04+0100\n"
"PO-Revision-Date: 2016-11-20 02:48+0100\n"
"Last-Translator: Beee\n"
"Language-Team: \n"
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.11\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-KeywordsList: __;_e\n"
"X-Poedit-SearchPath-0: .\n"

#: acf-input-counter.php:110
#, php-format
msgid "chars: %1$s of %2$s"
msgstr ""

0 comments on commit 237978b

Please sign in to comment.