Skip to content

Commit

Permalink
Deploying version 5.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lgladdy committed Mar 23, 2022
1 parent cf480e7 commit c2d6fd0
Show file tree
Hide file tree
Showing 14 changed files with 9,136 additions and 8,213 deletions.
4 changes: 2 additions & 2 deletions acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Advanced Custom Fields
Plugin URI: https://www.advancedcustomfields.com
Description: Customize WordPress with powerful, professional and intuitive fields.
Version: 5.12
Version: 5.12.1
Author: Delicious Brains
Author URI: https://www.advancedcustomfields.com
Text Domain: acf
Expand All @@ -19,7 +19,7 @@
class ACF {

/** @var string The plugin version number. */
var $version = '5.12';
var $version = '5.12.1';

/** @var array The plugin settings array. */
var $settings = array();
Expand Down
2 changes: 2 additions & 0 deletions includes/acf-field-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,8 @@ function acf_duplicate_fields( $fields = array(), $parent_id = 0 ) {
}
acf_append_data( 'generated_keys', $keys );

$duplicates = array();

// Duplicate fields.
foreach ( $fields as $field ) {
$field_id = $field['ID'] ? $field['ID'] : $field['key'];
Expand Down
15 changes: 12 additions & 3 deletions includes/acf-value-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ function acf_get_value( $post_id, $field ) {
// Get field name.
$field_name = $field['name'];

// If we still don't have a proper field array, the field doesn't exist currently.
// Get field ID & type.
$decoded = acf_decode_post_id( $post_id );

// If we don't have a proper field array, the field doesn't exist currently.
if ( empty( $field['type'] ) && empty( $field['key'] ) ) {
// Get field ID & type.
$decoded = acf_decode_post_id( $post_id );

if ( apply_filters( 'acf/prevent_access_to_unknown_fields', false ) || ( 'option' === $decoded['type'] && 'options' !== $decoded['id'] ) ) {
return null;
Expand All @@ -72,6 +73,14 @@ function acf_get_value( $post_id, $field ) {
do_action( 'acf/get_invalid_field_value', $field, __FUNCTION__ );
}

// If we're using a non options_ option key, ensure we have a valid reference key.
if ( 'option' === $decoded['type'] && 'options' !== $decoded['id'] ) {
$meta = acf_get_metadata( $post_id, $field_name, true );
if ( ! $meta || $meta !== $field['key'] ) {
return null;
}
}

// Check store.
$store = acf_get_store( 'values' );
if ( $store->has( "$post_id:$field_name" ) ) {
Expand Down
5 changes: 3 additions & 2 deletions includes/acf-wp-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function acf_get_object_type_rest_base( $type_object ) {
* Extract the ID of a given object/array. This supports all expected types handled by our update_fields() and
* load_fields() callbacks.
*
* @param WP_Post|WP_User|WP_Term|array $object
* @param WP_Post|WP_User|WP_Term|WP_Comment|array $object
* @return int|mixed|null
*/
function acf_get_object_id( $object ) {
Expand All @@ -247,9 +247,10 @@ function acf_get_object_id( $object ) {
case WP_User::class:
case WP_Post::class:
return (int) $object->ID;

case WP_Term::class:
return (int) $object->term_id;
case WP_Comment::class:
return (int) $object->comment_ID;
}
} elseif ( isset( $object['id'] ) ) {
return (int) $object['id'];
Expand Down
6 changes: 6 additions & 0 deletions includes/rest-api/acf-rest-api-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
*/
function acf_get_field_rest_schema( array $field ) {
$type = acf_get_field_type( $field['type'] );
$schema = array();

if ( ! is_object( $type ) || ! method_exists( $type, 'get_rest_schema' ) ) {
return $schema;
}

$schema = $type->get_rest_schema( $field );

/**
Expand Down
29 changes: 25 additions & 4 deletions includes/rest-api/class-acf-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ACF_Rest_Api {

public function __construct() {
add_filter( 'rest_pre_dispatch', array( $this, 'initialize' ), 10, 3 );
add_action( 'rest_api_init', array( $this, 'register_field' ) );
}

public function initialize( $response, $handler, $request ) {
Expand All @@ -44,7 +45,12 @@ public function initialize( $response, $handler, $request ) {
/**
* Register our custom property as a REST field.
*/
private function register_field() {
public function register_field() {
if ( ! $this->request instanceof ACF_Rest_Request ) {
$this->request = new ACF_Rest_Request();
$this->request->parse_request( null );
}

$base = $this->request->object_sub_type;

// If the object sub type ($post_type, $taxonomy, 'user') cannot be determined from the current request,
Expand All @@ -57,6 +63,15 @@ private function register_field() {
$base = $this->request->child_object_type;
}

// If we've already registered this route, no need to do it again.
if ( acf_did( 'acf/register_rest_field' ) ) {
global $wp_rest_additional_fields;

if ( isset( $wp_rest_additional_fields[ $base ], $wp_rest_additional_fields[ $base ]['acf'] ) ) {
return;
}
}

register_rest_field(
$base,
'acf',
Expand Down Expand Up @@ -326,8 +341,9 @@ private function is_admin_mode( $data ) {
*/
private function make_identifier( $object_id, $object_type ) {
$formats = array(
'user' => 'user_%s',
'term' => 'term_%s',
'user' => 'user_%s',
'term' => 'term_%s',
'comment' => 'comment_%s',
);

return isset( $formats[ $object_type ] )
Expand Down Expand Up @@ -394,7 +410,7 @@ private function object_type_has_field_group( $object_type, $field_group, $locat
$match = true;
}

if ( 'user' === $object_type ) {
if ( in_array( $object_type, array( 'user', 'comment' ) ) ) {
$match = true;
}
}
Expand Down Expand Up @@ -463,6 +479,11 @@ private function get_field_groups_by_id( $object_id, $object_type, $object_sub_t
case 'term':
$args = array( 'taxonomy' => $object_sub_type );
break;
case 'comment':
$comment = get_comment( $object_id );
$post_type = get_post_type( $comment->comment_post_ID );
$args = array( 'comment' => $post_type );
break;
case 'post':
default:
$args = array( 'post_id' => $object_id );
Expand Down
13 changes: 11 additions & 2 deletions includes/rest-api/class-acf-rest-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ private function set_http_method() {
* Get the current REST route as determined by WordPress.
*/
private function set_current_route( $request ) {
$this->current_route = $request->get_route();
if ( $request ) {
$this->current_route = $request->get_route();
} else {
$this->current_route = empty( $GLOBALS['wp']->query_vars['rest_route'] ) ? null : $GLOBALS['wp']->query_vars['rest_route'];
}
}

/**
Expand Down Expand Up @@ -141,6 +145,10 @@ private function build_supported_routes() {
$this->supported_routes[] = '/wp/v2/(?P<rest_base>users)';
$this->supported_routes[] = '/wp/v2/(?P<rest_base>users)/(?P<id>[\d]+)';
$this->supported_routes[] = '/wp/v2/(?P<rest_base>users)/me';

// Add comment routes.
$this->supported_routes[] = '/wp/v2/(?P<rest_base>comments)';
$this->supported_routes[] = '/wp/v2/(?P<rest_base>comments)/(?P<id>[\d]+)';
}

/**
Expand Down Expand Up @@ -183,7 +191,8 @@ private function set_object_types() {
// check post types then check taxonomies if a matching post type cannot be found.
if ( $base === 'users' ) {
$this->object_type = $this->object_sub_type = 'user';

} elseif ( $base === 'comments' ) {
$this->object_type = $this->object_sub_type = 'comment';
} elseif ( $post_type = $this->get_post_type_by_rest_base( $base ) ) {
$this->object_type = 'post';
$this->object_sub_type = $post_type->name;
Expand Down
Binary file modified lang/acf-es_ES.mo
Binary file not shown.
Loading

0 comments on commit c2d6fd0

Please sign in to comment.