Skip to content

Commit 29d13eb

Browse files
committed
Deploying version 6.4.0
1 parent 368a956 commit 29d13eb

File tree

165 files changed

+9390
-3594
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+9390
-3594
lines changed

acf.php

+24-9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
* Plugin Name: Advanced Custom Fields
1010
* Plugin URI: https://www.advancedcustomfields.com
1111
* Description: Customize WordPress with powerful, professional and intuitive fields.
12-
* Version: 6.3.12
12+
* Version: 6.4.0
1313
* Author: WP Engine
1414
* Author URI: https://wpengine.com/?utm_source=wordpress.org&utm_medium=referral&utm_campaign=plugin_directory&utm_content=advanced_custom_fields
15-
* Update URI: false
15+
* Update URI: https://www.advancedcustomfields.com
1616
* Text Domain: acf
1717
* Domain Path: /lang
1818
* Requires PHP: 7.4
@@ -36,7 +36,7 @@ class ACF {
3636
*
3737
* @var string
3838
*/
39-
public $version = '6.3.12';
39+
public $version = '6.4.0';
4040

4141
/**
4242
* The plugin settings array.
@@ -91,7 +91,7 @@ public function initialize() {
9191

9292
// Define settings.
9393
$this->settings = array(
94-
'name' => __( 'Advanced Custom Fields', 'acf' ),
94+
'name' => 'Advanced Custom Fields',
9595
'slug' => dirname( ACF_BASENAME ),
9696
'version' => ACF_VERSION,
9797
'basename' => ACF_BASENAME,
@@ -133,6 +133,9 @@ public function initialize() {
133133
'enable_meta_box_cb_edit' => true,
134134
);
135135

136+
// Include autoloader.
137+
include_once __DIR__ . '/vendor/autoload.php';
138+
136139
// Include utility functions.
137140
include_once ACF_PATH . 'includes/acf-utility-functions.php';
138141

@@ -144,13 +147,21 @@ public function initialize() {
144147
// Include classes.
145148
acf_include( 'includes/class-acf-data.php' );
146149
acf_include( 'includes/class-acf-internal-post-type.php' );
147-
acf_include( 'includes/class-acf-site-health.php' );
148150
acf_include( 'includes/fields/class-acf-field.php' );
149151
acf_include( 'includes/locations/abstract-acf-legacy-location.php' );
150152
acf_include( 'includes/locations/abstract-acf-location.php' );
151153

154+
// Initialise autoloaded classes.
155+
new ACF\Site_Health\Site_Health();
156+
152157
// Include functions.
153158
acf_include( 'includes/acf-helper-functions.php' );
159+
160+
acf_new_instance( 'ACF\Meta\Comment' );
161+
acf_new_instance( 'ACF\Meta\Post' );
162+
acf_new_instance( 'ACF\Meta\Term' );
163+
acf_new_instance( 'ACF\Meta\User' );
164+
154165
acf_include( 'includes/acf-hook-functions.php' );
155166
acf_include( 'includes/acf-field-functions.php' );
156167
acf_include( 'includes/acf-bidirectional-functions.php' );
@@ -232,7 +243,9 @@ public function initialize() {
232243
acf_include( 'includes/Updater/init.php' );
233244

234245
// Include PRO if included with this build.
235-
acf_include( 'pro/acf-pro.php' );
246+
if ( ! defined( 'ACF_PREVENT_PRO_LOAD' ) || ( defined( 'ACF_PREVENT_PRO_LOAD' ) && ! ACF_PREVENT_PRO_LOAD ) ) {
247+
acf_include( 'pro/acf-pro.php' );
248+
}
236249

237250
if ( is_admin() && function_exists( 'acf_is_pro' ) && ! acf_is_pro() ) {
238251
acf_include( 'includes/admin/admin-options-pages-preview.php' );
@@ -273,6 +286,9 @@ public function init() {
273286
// Load textdomain file.
274287
acf_load_textdomain();
275288

289+
// Make plugin name translatable.
290+
acf_update_setting( 'name', __( 'Advanced Custom Fields', 'acf' ) );
291+
276292
// Include 3rd party compatiblity.
277293
acf_include( 'includes/third-party.php' );
278294

@@ -395,9 +411,8 @@ public function init() {
395411
*/
396412
do_action( 'acf/include_taxonomies', ACF_MAJOR_VERSION );
397413

398-
// If we're on 6.5 or newer, load block bindings. This will move to an autoloader in 6.4.
399-
if ( version_compare( get_bloginfo( 'version' ), '6.5-beta1', '>=' ) ) {
400-
acf_include( 'includes/Blocks/Bindings.php' );
414+
// If we're on 6.5 or newer, load block bindings.
415+
if ( version_compare( get_bloginfo( 'version' ), '6.5', '>=' ) ) {
401416
new ACF\Blocks\Bindings();
402417
}
403418

assets/build/js/acf-field-group.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/build/js/acf-input.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/build/js/acf.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "wp-engine/advanced-custom-fields",
3+
"description": "Advanced Custom Fields",
4+
"type": "wordpress-plugin",
5+
"license": "GPLv2 or later",
6+
"autoload": {
7+
"psr-4": {
8+
"ACF\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "WP Engine"
14+
}
15+
],
16+
"config": {
17+
"optimize-autoloader": true
18+
},
19+
"require": {}
20+
}

includes/acf-meta-functions.php

+166-47
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,21 @@
1111
* @return array
1212
*/
1313
function acf_get_meta( $post_id = 0 ) {
14-
1514
// Allow filter to short-circuit load_value logic.
1615
$null = apply_filters( 'acf/pre_load_meta', null, $post_id );
1716
if ( $null !== null ) {
1817
return ( $null === '__return_null' ) ? null : $null;
1918
}
2019

21-
// Decode $post_id for $type and $id.
22-
$decoded = acf_decode_post_id( $post_id );
20+
// Decode the $post_id for $type and $id.
21+
$decoded = acf_decode_post_id( $post_id );
22+
$instance = acf_get_meta_instance( $decoded['type'] );
23+
$meta = array();
2324

24-
/**
25-
* Determine CRUD function.
26-
*
27-
* - Relies on decoded post_id result to identify option or meta types.
28-
* - Uses xxx_metadata(type) instead of xxx_type_meta() to bypass additional logic that could alter the ID.
29-
*/
30-
if ( $decoded['type'] === 'option' ) {
31-
$allmeta = acf_get_option_meta( $decoded['id'] );
32-
} else {
33-
$allmeta = get_metadata( $decoded['type'], $decoded['id'], '' );
25+
if ( $instance ) {
26+
$meta = $instance->get_meta( $decoded['id'] );
3427
}
3528

36-
// Loop over meta and check that a reference exists for each value.
37-
$meta = array();
38-
if ( $allmeta ) {
39-
foreach ( $allmeta as $key => $value ) {
40-
41-
// If a reference exists for this value, add it to the meta array.
42-
if ( isset( $allmeta[ "_$key" ] ) ) {
43-
$meta[ $key ] = $allmeta[ $key ][0];
44-
$meta[ "_$key" ] = $allmeta[ "_$key" ][0];
45-
}
46-
}
47-
}
48-
49-
// Unserialized results (get_metadata does not unserialize if $key is empty).
50-
$meta = array_map( 'acf_maybe_unserialize', $meta );
51-
5229
/**
5330
* Filters the $meta array after it has been loaded.
5431
*
@@ -74,7 +51,6 @@ function acf_get_meta( $post_id = 0 ) {
7451
* @return array
7552
*/
7653
function acf_get_option_meta( $prefix = '' ) {
77-
7854
// Globals.
7955
global $wpdb;
8056

@@ -241,32 +217,23 @@ function acf_delete_metadata( $post_id = 0, $name = '', $hidden = false ) {
241217
}
242218

243219
/**
244-
* acf_copy_postmeta
245-
*
246220
* Copies meta from one post to another. Useful for saving and restoring revisions.
247221
*
248-
* @date 25/06/2016
249222
* @since 5.3.8
250223
*
251-
* @param (int|string) $from_post_id The post id to copy from.
252-
* @param (int|string) $to_post_id The post id to paste to.
253-
* @return void
224+
* @param integer|string $from_post_id The post id to copy from.
225+
* @param integer|string $to_post_id The post id to paste to.
226+
* @return void
254227
*/
255228
function acf_copy_metadata( $from_post_id = 0, $to_post_id = 0 ) {
256-
257-
// Get all postmeta.
229+
// Get all metadata.
258230
$meta = acf_get_meta( $from_post_id );
259231

260-
// Check meta.
261-
if ( $meta ) {
262-
263-
// Slash data. WP expects all data to be slashed and will unslash it (fixes '\' character issues).
264-
$meta = wp_slash( $meta );
232+
$decoded = acf_decode_post_id( $to_post_id );
233+
$instance = acf_get_meta_instance( $decoded['type'] );
265234

266-
// Loop over meta.
267-
foreach ( $meta as $name => $value ) {
268-
acf_update_metadata( $to_post_id, $name, $value );
269-
}
235+
if ( $meta && $instance ) {
236+
$instance->update_meta( $decoded['id'], $meta );
270237
}
271238
}
272239

@@ -382,3 +349,155 @@ function acf_update_metaref( $post_id = 0, $type = 'fields', $references = array
382349
// Update metadata.
383350
return acf_update_metadata( $post_id, "_acf_$type", $references );
384351
}
352+
353+
/**
354+
* Retrieves an ACF meta instance for the provided meta type.
355+
*
356+
* @since 6.4
357+
*
358+
* @param string $type The meta type as decoded from the post ID.
359+
* @return object|null
360+
*/
361+
function acf_get_meta_instance( string $type ): ?object {
362+
$instance = null;
363+
$meta_locations = acf_get_store( 'acf-meta-locations' );
364+
365+
if ( $meta_locations && $meta_locations->has( $type ) ) {
366+
$instance = acf_get_instance( $meta_locations->get( $type ) );
367+
}
368+
369+
return $instance;
370+
}
371+
372+
/**
373+
* Gets metadata from the database.
374+
*
375+
* @since 6.4
376+
*
377+
* @param integer|string $post_id The post id.
378+
* @param array $field The field array.
379+
* @param boolean $hidden True if we should return the reference key.
380+
* @return mixed
381+
*/
382+
function acf_get_metadata_by_field( $post_id = 0, $field = array(), bool $hidden = false ) {
383+
if ( empty( $field['name'] ) ) {
384+
return null;
385+
}
386+
387+
// Allow filter to short-circuit logic.
388+
$null = apply_filters( 'acf/pre_load_metadata', null, $post_id, $field['name'], $hidden );
389+
if ( $null !== null ) {
390+
return ( $null === '__return_null' ) ? null : $null;
391+
}
392+
393+
// Decode the $post_id for $type and $id.
394+
$decoded = acf_decode_post_id( $post_id );
395+
$id = $decoded['id'];
396+
$type = $decoded['type'];
397+
398+
// Bail early if no $id (possible during new acf_form).
399+
if ( ! $id ) {
400+
return null;
401+
}
402+
403+
$meta_instance = acf_get_meta_instance( $type );
404+
405+
if ( ! $meta_instance ) {
406+
return false;
407+
}
408+
409+
if ( $hidden ) {
410+
return $meta_instance->get_reference( $id, $field['name'] );
411+
}
412+
413+
return $meta_instance->get_value( $id, $field );
414+
}
415+
416+
/**
417+
* Updates metadata in the database.
418+
*
419+
* @since 6.4
420+
*
421+
* @param integer|string $post_id The post id.
422+
* @param array $field The field array.
423+
* @param mixed $value The meta value.
424+
* @param boolean $hidden True if we should update the reference key.
425+
* @return integer|boolean Meta ID if the key didn't exist, true on successful update, false on failure.
426+
*/
427+
function acf_update_metadata_by_field( $post_id = 0, $field = array(), $value = '', bool $hidden = false ) {
428+
if ( empty( $field['name'] ) ) {
429+
return null;
430+
}
431+
432+
// Allow filter to short-circuit logic.
433+
$pre = apply_filters( 'acf/pre_update_metadata', null, $post_id, $field['name'], $value, $hidden );
434+
if ( $pre !== null ) {
435+
return $pre;
436+
}
437+
438+
// Decode the $post_id for $type and $id.
439+
$decoded = acf_decode_post_id( $post_id );
440+
$id = $decoded['id'];
441+
$type = $decoded['type'];
442+
443+
// Bail early if no $id (possible during new acf_form).
444+
if ( ! $id ) {
445+
return false;
446+
}
447+
448+
$meta_instance = acf_get_meta_instance( $type );
449+
450+
if ( ! $meta_instance ) {
451+
return false;
452+
}
453+
454+
if ( $hidden ) {
455+
return $meta_instance->update_reference( $id, $field['name'], $field['key'] );
456+
}
457+
458+
return $meta_instance->update_value( $id, $field, $value );
459+
}
460+
461+
/**
462+
* Deletes metadata from the database.
463+
*
464+
* @since 6.4
465+
*
466+
* @param integer|string $post_id The post id.
467+
* @param array $field The field array.
468+
* @param boolean $hidden True if we should update the reference key.
469+
* @return boolean
470+
*/
471+
function acf_delete_metadata_by_field( $post_id = 0, $field = array(), bool $hidden = false ) {
472+
if ( empty( $field['name'] ) ) {
473+
return null;
474+
}
475+
476+
// Allow filter to short-circuit logic.
477+
$pre = apply_filters( 'acf/pre_delete_metadata', null, $post_id, $field['name'], $hidden );
478+
if ( $pre !== null ) {
479+
return $pre;
480+
}
481+
482+
// Decode the $post_id for $type and $id.
483+
$decoded = acf_decode_post_id( $post_id );
484+
$id = $decoded['id'];
485+
$type = $decoded['type'];
486+
487+
// Bail early if no $id (possible during new acf_form).
488+
if ( ! $id ) {
489+
return false;
490+
}
491+
492+
$meta_instance = acf_get_meta_instance( $type );
493+
494+
if ( ! $meta_instance ) {
495+
return false;
496+
}
497+
498+
if ( $hidden ) {
499+
return $meta_instance->delete_reference( $id, $field['name'] );
500+
}
501+
502+
return $meta_instance->delete_value( $id, $field );
503+
}

0 commit comments

Comments
 (0)