acf-focuspoint icon indicating copy to clipboard operation
acf-focuspoint copied to clipboard

feat: Image field interop

Open hirasso opened this issue 7 months ago • 0 comments

This PR makes it easier to switch between the field types "Image" and "FocusPoint":

  • if the field is a FocusPoint field and previously was an image field (the value is an ID), construct the default value based on the id:
function load_value( $value, $post_id, $field ) {
	if (is_numeric($value)) {
		return array(
			'id' => $value,
			'top' => 50,
			'left' => 50
		);
	}
	return $value;
}
  • if the field is an image field and looks like it was previously a focuspoint field, use the id:
public function load_value_image($value) {
	if (
		$this->has_exact_keys($value, ['id', 'left', 'top'])
		&& is_numeric($value['id'])
		&& wp_attachment_is_image($value['id'])
		) {
		return intval($value['id']);
	}
	return $value;
}

hirasso avatar Jul 30 '24 09:07 hirasso