Advanced Custom Fields: Table Field - Version 1.2.6

Version Description

Fixes an PHP error and improves JavaScript code.

=

Download this release

Release Info

Developer Jonua
Plugin Icon 128x128 Advanced Custom Fields: Table Field
Version 1.2.6
Comparing to
See all releases

Code changes from version 1.2.5 to 1.2.6

Files changed (6) hide show
  1. acf-table-v4.php +9 -9
  2. acf-table-v5.php +16 -25
  3. acf-table.php +1 -1
  4. js/input-v4.js +3 -4
  5. js/input-v5.js +3 -4
  6. readme.txt +121 -14
acf-table-v4.php CHANGED
@@ -36,7 +36,7 @@
36
// settings
37
$this->settings = array(
38
'dir_url' => plugins_url( '', __FILE__ ) . '/',
39
- 'version' => '1.2.5',
40
);
41
42
// PREVENTS SAVING INVALID TABLE FIELD JSON DATA {
@@ -128,16 +128,11 @@
128
{
129
// Note: This function can be removed if not used
130
131
- // register acf scripts
132
- wp_register_script('acf-input-table', $this->settings['dir_url'] . 'js/input-v4.js', array('acf-input'), $this->settings['version'] );
133
- wp_register_style('acf-input-table', $this->settings['dir_url'] . 'css/input.css', array('acf-input'), $this->settings['version'] );
134
-
135
- // scripts
136
- wp_enqueue_script(array(
137
- 'acf-input-table',
138
- ));
139
140
// styles
141
wp_enqueue_style(array(
142
'acf-input-table',
143
));
@@ -166,6 +161,11 @@
166
// key is needed in the field names to correctly save the data
167
$key = $field['name'];
168
169
// Create Field Options HTML
170
171
// USER HEADER
36
// settings
37
$this->settings = array(
38
'dir_url' => plugins_url( '', __FILE__ ) . '/',
39
+ 'version' => '1.2.6',
40
);
41
42
// PREVENTS SAVING INVALID TABLE FIELD JSON DATA {
128
{
129
// Note: This function can be removed if not used
130
131
+ /// scripts
132
+ wp_enqueue_script( 'acf-input-table', $this->settings['dir_url'] . 'js/input-v4.js', array( 'jquery', 'acf-input' ), $this->settings['version'], true );
133
134
// styles
135
+ wp_register_style( 'acf-input-table', $this->settings['dir_url'] . 'css/input.css', array( 'acf-input' ), $this->settings['version'] );
136
wp_enqueue_style(array(
137
'acf-input-table',
138
));
161
// key is needed in the field names to correctly save the data
162
$key = $field['name'];
163
164
+ if ( empty( $field['use_header'] ) ) {
165
+
166
+ $field['use_header'] = 0;
167
+ }
168
+
169
// Create Field Options HTML
170
171
// USER HEADER
acf-table-v5.php CHANGED
@@ -21,7 +21,7 @@ class acf_field_table extends acf_field {
21
* settings (array) Array of settings
22
*/
23
$this->settings = array(
24
- 'version' => '1.2.5',
25
'dir_url' => plugins_url( '', __FILE__ ) . '/',
26
);
27
@@ -152,18 +152,10 @@ class acf_field_table extends acf_field {
152
* This will show what data is available
153
*/
154
155
- //echo '<pre>';
156
- // print_r( $field );
157
- //echo '</pre>';
158
159
- /*
160
- * Create a simple text input using the 'font_size' setting.
161
- */
162
- /*
163
- ?>
164
- <input type="text" name="<?php echo esc_attr($field['name']) ?>" value="<?php echo esc_attr($field['value']) ?>" style="font-size:<?php echo $field['font_size'] ?>px;" />
165
- <?php
166
- */
167
168
$data_field['use_header'] = $field['use_header'];
169
@@ -173,16 +165,16 @@ class acf_field_table extends acf_field {
173
174
// OPTION HEADER {
175
176
- if ( $data_field['use_header'] === 0 ) {
177
178
- $e .= '<div class="acf-table-optionbox">';
179
- $e .= '<label>' . __( 'use table header', 'acf-table' ) . ' </label>';
180
- $e .= '<select class="acf-table-optionbox-field acf-table-fc-opt-use-header" name="acf-table-opt-use-header">';
181
- $e .= '<option value="0">' . __( 'No', 'acf-table' ) . '</option>';
182
- $e .= '<option value="1">' . __( 'Yes', 'acf-table' ) . '</option>';
183
- $e .= '</select>';
184
- $e .= '</div>';
185
- }
186
187
// }
188
@@ -213,12 +205,11 @@ class acf_field_table extends acf_field {
213
function input_admin_enqueue_scripts() {
214
215
// register & include JS
216
- wp_register_script( 'acf-input-table', $this->settings['dir_url'] . 'js/input-v5.js', array('acf-input'), $this->settings['version'] );
217
- wp_enqueue_script('acf-input-table');
218
219
// register & include CSS
220
- wp_register_style( 'acf-input-table', $this->settings['dir_url'] . 'css/input.css', array('acf-input'), $this->settings['version'] );
221
- wp_enqueue_style('acf-input-table');
222
223
}
224
21
* settings (array) Array of settings
22
*/
23
$this->settings = array(
24
+ 'version' => '1.2.6',
25
'dir_url' => plugins_url( '', __FILE__ ) . '/',
26
);
27
152
* This will show what data is available
153
*/
154
155
+ if ( empty( $field['use_header'] ) ) {
156
157
+ $field['use_header'] = 0;
158
+ }
159
160
$data_field['use_header'] = $field['use_header'];
161
165
166
// OPTION HEADER {
167
168
+ if ( $data_field['use_header'] === 0 ) {
169
170
+ $e .= '<div class="acf-table-optionbox">';
171
+ $e .= '<label>' . __( 'use table header', 'acf-table' ) . ' </label>';
172
+ $e .= '<select class="acf-table-optionbox-field acf-table-fc-opt-use-header" name="acf-table-opt-use-header">';
173
+ $e .= '<option value="0">' . __( 'No', 'acf-table' ) . '</option>';
174
+ $e .= '<option value="1">' . __( 'Yes', 'acf-table' ) . '</option>';
175
+ $e .= '</select>';
176
+ $e .= '</div>';
177
+ }
178
179
// }
180
205
function input_admin_enqueue_scripts() {
206
207
// register & include JS
208
+ wp_enqueue_script( 'acf-input-table', $this->settings['dir_url'] . 'js/input-v5.js', array( 'jquery', 'acf-input' ), $this->settings['version'], true );
209
210
// register & include CSS
211
+ wp_register_style( 'acf-input-table', $this->settings['dir_url'] . 'css/input.css', array( 'acf-input' ), $this->settings['version'] );
212
+ wp_enqueue_style( 'acf-input-table' );
213
214
}
215
acf-table.php CHANGED
@@ -3,7 +3,7 @@
3
Plugin Name: Advanced Custom Fields: Table Field
4
Plugin URI: http://www.johannheyne.de/
5
Description: This free Add-on adds a table field type for the Advanced Custom Fields plugin
6
- Version: 1.2.5
7
Author: Johann Heyne
8
Author URI: http://www.johannheyne.de/
9
License: GPLv2 or later
3
Plugin Name: Advanced Custom Fields: Table Field
4
Plugin URI: http://www.johannheyne.de/
5
Description: This free Add-on adds a table field type for the Advanced Custom Fields plugin
6
+ Version: 1.2.6
7
Author: Johann Heyne
8
Author URI: http://www.johannheyne.de/
9
License: GPLv2 or later
js/input-v4.js CHANGED
@@ -1,11 +1,10 @@
1
- jQuery.noConflict();
2
- jQuery( document ).ready(function( $ ){
3
4
function ACFTableField() {
5
6
var t = this;
7
8
- t.version = '1.2.5';
9
10
t.param = {};
11
@@ -1180,4 +1179,4 @@ jQuery( document ).ready(function( $ ){
1180
var acf_table_field = new ACFTableField();
1181
acf_table_field.init();
1182
1183
- });
1
+ (function($) {
2
3
function ACFTableField() {
4
5
var t = this;
6
7
+ t.version = '1.2.6';
8
9
t.param = {};
10
1179
var acf_table_field = new ACFTableField();
1180
acf_table_field.init();
1181
1182
+ })( jQuery );
js/input-v5.js CHANGED
@@ -1,11 +1,10 @@
1
- jQuery.noConflict();
2
- jQuery( document ).ready( function( $ ) {
3
4
function ACFTableField() {
5
6
var t = this;
7
8
- t.version = '1.2.5';
9
10
t.param = {};
11
@@ -1181,4 +1180,4 @@ jQuery( document ).ready( function( $ ) {
1181
var acf_table_field = new ACFTableField();
1182
acf_table_field.init();
1183
1184
- });
1
+ (function($) {
2
3
function ACFTableField() {
4
5
var t = this;
6
7
+ t.version = '1.2.6';
8
9
t.param = {};
10
1180
var acf_table_field = new ACFTableField();
1181
acf_table_field.init();
1182
1183
+ })( jQuery );
readme.txt CHANGED
@@ -1,26 +1,34 @@
1
=== Advanced Custom Fields: Table Field ===
2
- Contributors: Johann Heyne
3
Tags: acf table
4
Requires at least: 4.9
5
Tested up to: 4.9.8
6
- Stable tag: trunk
7
License: GPLv2 or later
8
9
- A Table Field Add-on for the Advanced Custom Fields Plugin
10
11
== Description ==
12
13
- The Table Field Plugin enhances the functionality of the "Advanced Custom Fields" plugin with easy-to-edit tables. The plugin requires the "Advanced Custom Fields" plugin and is compatible with version 4 and 5. The table field works also with the repeater and flexible field types.
14
15
- * table header (option)
16
- * add and remove table columns and rows
17
- * change order of columns and rows by dragging
18
- * to move to the next cells editor press key: tab
19
- * to move to the previous cells editor press key: shift + tab
20
21
- === Output Table HTML ===
22
23
- To render the table fields data as an html table in one of your template files you can start with the following basic code example:
24
25
`
26
$table = get_field( 'your_table_field_name' );
@@ -68,11 +76,12 @@ if ( $table ) {
68
echo '</table>';
69
}
70
`
71
- === Line Breaks ===
72
73
This is about displaying line breaks in the admin tables and getting line breaks as `<br>` when outputting the tables HTML.
74
75
- = Converting Line Breaks for HTML Output =
76
77
To convert line breaks to `<br>` in tables HTML output the PHP function `nl2br()` can be used:
78
@@ -94,7 +103,7 @@ with…
94
echo nl2br( $td['c'] );
95
`
96
97
- = Displaying Line Breaks in Editing Tables =
98
99
To display natural line breaks in the editing tables in the admin area, add the following styles to the admin area.
100
@@ -120,6 +129,84 @@ function acf_table_styles() {
120
}
121
`
122
123
== Installation ==
124
125
This software can be used as both a WP plugin and a theme include.
@@ -139,8 +226,28 @@ However, only when activated as a plugin will updates be available.
139
2. Grab the rows and columns in the grey area and drag them.
140
141
142
== Changelog ==
143
144
= 1.2.5 =
145
* Adds danish translation, thanks to Jeppe Skovsgaard
146
1
=== Advanced Custom Fields: Table Field ===
2
+ Contributors: jonua
3
Tags: acf table
4
Requires at least: 4.9
5
Tested up to: 4.9.8
6
+ Stable tag: 1.2.6
7
+ Requires PHP: 7.0.0
8
License: GPLv2 or later
9
10
+ A Table Field Add-on for the Advanced Custom Fields Plugin.
11
12
== Description ==
13
14
+ The Table Field Plugin enhances the functionality of the ["Advanced Custom Fields" plugin](https://de.wordpress.org/plugins/advanced-custom-fields/) with easy-to-edit tables.
15
16
+ This plugin requires the ["Advanced Custom Fields" plugin](https://de.wordpress.org/plugins/advanced-custom-fields/) or the [Pro version](https://www.advancedcustomfields.com/pro/)!
17
18
+ The table field works also with the repeater and flexible field types.
19
20
+ = Features =
21
+ * Table Header (Option)
22
+ * Add and remove table columns and rows
23
+ * Change order of columns and rows by dragging
24
+ * To move to the next cells editor press key: tab
25
+ * To move to the previous cells editor press key: shift + tab
26
+
27
+ == Frequently Asked Questions ==
28
+
29
+ = How to output the table html? =
30
+
31
+ To render the table fields data as an html table in one of your template files (page.php, single.php) you can start with the following basic code example:
32
33
`
34
$table = get_field( 'your_table_field_name' );
76
echo '</table>';
77
}
78
`
79
+
80
+ = How to handle line breaks? =
81
82
This is about displaying line breaks in the admin tables and getting line breaks as `<br>` when outputting the tables HTML.
83
84
+ **Converting Line Breaks for HTML Output**
85
86
To convert line breaks to `<br>` in tables HTML output the PHP function `nl2br()` can be used:
87
103
echo nl2br( $td['c'] );
104
`
105
106
+ **Displaying Line Breaks in Editing Tables**
107
108
To display natural line breaks in the editing tables in the admin area, add the following styles to the admin area.
109
129
}
130
`
131
132
+ = How to use the table field in Elementor Page Builder? =
133
+
134
+ In general, its up to Elementor to support ACF field types on the Elementor widgets. All supported ACF fields by Elementor [you can find here](https://docs.elementor.com/article/381-elementor-integration-with-acf). But because the table field is not a native ACF field, the support for this field may never happen.
135
+
136
+ For now the way to go is using the Elementors shortcode Widget. Before you can use a shortcode to display a table fields table, you have to setup a shortcode in functions.php. The following code does this. You can modify the table html output for your needs.
137
+
138
+ `function shortcode_acf_tablefield( $atts ) {
139
+
140
+ $a = shortcode_atts( array(
141
+ 'field-name' => false,
142
+ 'post-id' => false,
143
+ ), $atts );
144
+
145
+ $table = get_field( $a['field-name'], $a['post-id'] );
146
+
147
+ $return = '';
148
+
149
+ if ( $table ) {
150
+
151
+ $return .= '<table border="0">';
152
+
153
+ if ( $table['header'] ) {
154
+
155
+ $return .= '<thead>';
156
+
157
+ $return .= '<tr>';
158
+
159
+ foreach ( $table['header'] as $th ) {
160
+
161
+ $return .= '<th>';
162
+ $return .= $th['c'];
163
+ $return .= '</th>';
164
+ }
165
+
166
+ $return .= '</tr>';
167
+
168
+ $return .= '</thead>';
169
+ }
170
+
171
+ $return .= '<tbody>';
172
+
173
+ foreach ( $table['body'] as $tr ) {
174
+
175
+ $return .= '<tr>';
176
+
177
+ foreach ( $tr as $td ) {
178
+
179
+ $return .= '<td>';
180
+ $return .= $td['c'];
181
+ $return .= '</td>';
182
+ }
183
+
184
+ $return .= '</tr>';
185
+ }
186
+
187
+ $return .= '</tbody>';
188
+
189
+ $return .= '</table>';
190
+ }
191
+
192
+ return $return;
193
+ }
194
+
195
+ add_shortcode( 'table', 'shortcode_acf_tablefield' );`
196
+
197
+
198
+ Then use the shortcode in a Elementors shortcode widget like this, to **insert a table from the current page or post**…
199
+
200
+ `[table field-name="your table field name"]`
201
+
202
+ You also can **insert a table from another page or post**…
203
+
204
+ `[table field-name="your table field name" post-id="123"]`
205
+
206
+ Or you can **insert a table from a ACF option page**…
207
+
208
+ `[table field-name="your table field name" post-id="option"]`
209
+
210
== Installation ==
211
212
This software can be used as both a WP plugin and a theme include.
226
2. Grab the rows and columns in the grey area and drag them.
227
228
229
+ == Translations ==
230
+
231
+ * English - default, always included
232
+ * German: Deutsch - immer dabei!
233
+ * Danish: Dansk - altid der!
234
+ * Polish: Polski - zawsze tam jest!
235
+
236
+ *Note:* Please [contribute your language](https://translate.wordpress.org/projects/wp-plugins/advanced-custom-fields-table-field) to the plugin to make it even more useful.
237
+
238
+
239
+ == Upgrade Notice ==
240
+
241
+ = 1.2.6 =
242
+ Fixes an PHP error and improves JavaScript code.
243
+
244
+
245
== Changelog ==
246
247
+ = 1.2.6 =
248
+ * Replaces jQuery.noConflict methode
249
+ * Prevents PHP error if table fields value is from a previous fieldtype
250
+
251
= 1.2.5 =
252
* Adds danish translation, thanks to Jeppe Skovsgaard
253