Skip to content

Commit afaaabe

Browse files
authored
Update to last version (#131)
1 parent 91945b7 commit afaaabe

File tree

5 files changed

+61
-38
lines changed

5 files changed

+61
-38
lines changed

includes/fields/class-acf-field-flexible-content.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ public function get_layout( $name, $field ) {
10171017
public function delete_row( $i, $field, $post_id ) {
10181018

10191019
// vars
1020-
$value = acf_get_metadata( $post_id, $field['name'] );
1020+
$value = acf_get_metadata_by_field( $post_id, $field );
10211021

10221022
// bail early if no value
10231023
if ( ! is_array( $value ) || ! isset( $value[ $i ] ) ) {
@@ -1113,7 +1113,7 @@ public function update_value( $value, $post_id, $field ) {
11131113

11141114
// vars
11151115
$new_value = array();
1116-
$old_value = acf_get_metadata( $post_id, $field['name'] );
1116+
$old_value = acf_get_metadata_by_field( $post_id, $field );
11171117
$old_value = is_array( $old_value ) ? $old_value : array();
11181118

11191119
// update
@@ -1185,7 +1185,7 @@ public function update_value( $value, $post_id, $field ) {
11851185
public function delete_value( $post_id, $key, $field ) {
11861186

11871187
// vars
1188-
$old_value = acf_get_metadata( $post_id, $field['name'] );
1188+
$old_value = acf_get_metadata_by_field( $post_id, $field['name'] );
11891189
$old_value = is_array( $old_value ) ? $old_value : array();
11901190

11911191
// bail early if no rows or no sub fields

includes/fields/class-acf-field-repeater.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ public function pre_render_fields( $fields, $post_id = false ) {
142142
* @param array $field An array holding all the field's data.
143143
*/
144144
public function render_field( $field ) {
145+
$_field = $field;
145146
$field['orig_name'] = $this->get_field_name_from_input_name( $field['name'] );
146-
$field['total_rows'] = (int) acf_get_metadata( $this->post_id, $field['orig_name'] );
147+
$_field['name'] = $field['orig_name'];
148+
$field['total_rows'] = (int) acf_get_metadata_by_field( $this->post_id, $_field );
147149
$table = new ACF_Repeater_Table( $field );
148150
$table->render();
149151
}
@@ -610,7 +612,7 @@ public function update_value( $value, $post_id, $field ) {
610612
}
611613

612614
$new_value = 0;
613-
$old_value = (int) acf_get_metadata( $post_id, $field['name'] );
615+
$old_value = (int) acf_get_metadata_by_field( $post_id, $field );
614616

615617
if ( ! empty( $field['pagination'] ) && did_action( 'acf/save_post' ) && ! isset( $_POST['_acf_form'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Value not used.
616618
$old_rows = acf_get_value( $post_id, $field );
@@ -778,7 +780,7 @@ public function delete_field( $field ) {
778780
*/
779781
public function delete_value( $post_id, $key, $field ) {
780782
// Get the old value from the database.
781-
$old_value = (int) acf_get_metadata( $post_id, $field['name'] );
783+
$old_value = (int) acf_get_metadata_by_field( $post_id, $field );
782784

783785
// Bail early if no rows or no subfields.
784786
if ( ! $old_value || empty( $field['sub_fields'] ) ) {

includes/fields/class-acf-repeater-table.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,14 @@ public function render() {
163163
'data-min' => $this->field['min'],
164164
'data-max' => $this->field['max'],
165165
'data-pagination' => ! empty( $this->field['pagination'] ),
166+
'data-prefix' => $this->field['prefix'],
166167
);
167168

168169
if ( $this->field['pagination'] ) {
169170
$div['data-per_page'] = $this->field['rows_per_page'];
170171
$div['data-total_rows'] = $this->field['total_rows'];
171172
$div['data-orig_name'] = $this->field['orig_name'];
172-
$div['data-nonce'] = wp_create_nonce( $this->field['key'] );
173+
$div['data-nonce'] = wp_create_nonce( 'acf_field_' . $this->field['type'] . '_' . $this->field['key'] );
173174
}
174175

175176
if ( empty( $this->value ) ) {

includes/forms/form-front.php

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,39 @@
88
#[AllowDynamicProperties]
99
class acf_form_front {
1010

11-
/** @var array An array of registered form settings */
11+
/**
12+
* An array of registered form settings.
13+
*
14+
* @var array
15+
*/
1216
private $forms = array();
1317

14-
/** @var array An array of default fields */
18+
/**
19+
* An array of default fields.
20+
*
21+
* @var array
22+
*/
1523
public $fields = array();
1624

25+
/**
26+
* Constructs the class.
27+
*
28+
* @since ACF 5.0.0
29+
*/
30+
public function __construct() {
31+
add_action( 'acf/validate_save_post', array( $this, 'validate_save_post' ), 1 );
32+
add_filter( 'acf/pre_save_post', array( $this, 'pre_save_post' ), 5, 2 );
33+
}
1734

1835
/**
19-
* This function will setup the class functionality
36+
* Returns fields used by frontend forms.
2037
*
21-
* @type function
22-
* @date 5/03/2014
23-
* @since ACF 5.0.0
38+
* @since SCF 6.5
2439
*
25-
* @param n/a
26-
* @return n/a
40+
* @return array
2741
*/
28-
function __construct() {
29-
30-
// vars
42+
public function get_default_fields(): array {
3143
$this->fields = array(
32-
3344
'_post_title' => array(
3445
'prefix' => 'acf',
3546
'name' => '_post_title',
@@ -56,19 +67,13 @@ function __construct() {
5667
'value' => '',
5768
'wrapper' => array( 'style' => 'display:none !important;' ),
5869
),
59-
6070
);
6171

62-
// actions
63-
add_action( 'acf/validate_save_post', array( $this, 'validate_save_post' ), 1 );
64-
65-
// filters
66-
add_filter( 'acf/pre_save_post', array( $this, 'pre_save_post' ), 5, 2 );
72+
return $this->fields;
6773
}
6874

69-
7075
/**
71-
* description
76+
* Validates form arguments and applies defaults.
7277
*
7378
* @type function
7479
* @date 28/2/17
@@ -183,6 +188,15 @@ function get_form( $id = '' ) {
183188
return $this->forms[ $id ];
184189
}
185190

191+
/**
192+
* Returns all registered forms.
193+
*
194+
* @type function
195+
* @date 28/2/17
196+
* @since ACF 5.5.8
197+
*
198+
* @return forms (array)
199+
*/
186200
function get_forms() {
187201
return $this->forms;
188202
}
@@ -200,7 +214,7 @@ function get_forms() {
200214
function validate_save_post() {
201215

202216
// register field if isset in $_POST
203-
foreach ( $this->fields as $k => $field ) {
217+
foreach ( $this->get_default_fields() as $k => $field ) {
204218

205219
// bail early if no in $_POST
206220
if ( ! isset( $_POST['acf'][ $k ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified elsewhere.
@@ -444,7 +458,7 @@ function render_form( $args = array() ) {
444458
acf_update_setting( 'uploader', $args['uploader'] );
445459

446460
// Register local fields.
447-
foreach ( $this->fields as $k => $field ) {
461+
foreach ( $this->get_default_fields() as $k => $field ) {
448462
acf_add_local_field( $field );
449463
}
450464

@@ -513,9 +527,9 @@ function render_form( $args = array() ) {
513527

514528
// display form
515529
if ( $args['form'] ) : ?>
516-
<form <?php echo acf_esc_attrs( $args['form_attributes'] ); ?>>
530+
<form <?php echo acf_esc_attrs( $args['form_attributes'] ); ?>>
517531
<?php
518-
endif;
532+
endif;
519533

520534
// Render hidde form data.
521535
acf_form_data(
@@ -533,12 +547,12 @@ function render_form( $args = array() ) {
533547
<?php echo $args['html_after_fields']; ?><?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers. ?>
534548
</div>
535549
<?php if ( $args['form'] ) : ?>
536-
<div class="acf-form-submit">
537-
<?php printf( $args['html_submit_button'], $args['submit_value'] ); ?><?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers. ?>
538-
<?php echo $args['html_submit_spinner']; ?><?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers. ?>
539-
</div>
540-
</form>
541-
<?php endif;
550+
<div class="acf-form-submit">
551+
<?php printf( $args['html_submit_button'], $args['submit_value'] ); ?><?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers. ?>
552+
<?php echo $args['html_submit_spinner']; ?><?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers. ?>
553+
</div>
554+
</form>
555+
<?php endif;
542556
}
543557
}
544558

includes/validation.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,19 @@ public function reset_errors() {
131131
*/
132132
public function ajax_validate_save_post() {
133133
if ( ! acf_verify_ajax() ) {
134+
if ( empty( $_REQUEST['nonce'] ) ) {
135+
$nonce_error = __( 'SCF was unable to perform validation because no nonce was received by the server.', 'secure-custom-fields' );
136+
} else {
137+
$nonce_error = __( 'SCF was unable to perform validation because the provided nonce failed verification.', 'secure-custom-fields' );
138+
}
139+
134140
wp_send_json_success(
135141
array(
136142
'valid' => 0,
137143
'errors' => array(
138144
array(
139145
'input' => false,
140-
'message' => __( 'ACF was unable to perform validation due to an invalid security nonce being provided.', 'secure-custom-fields' ),
146+
'message' => __( 'SCF was unable to perform validation due to an invalid security nonce being provided.', 'secure-custom-fields' ),
141147
),
142148
),
143149
)

0 commit comments

Comments
 (0)