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.2.1 4.2.2 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / src / Meta / Option.php
advanced-custom-fields / src / Meta Last commit date
Comment.php 6 months ago MetaLocation.php 6 months ago Option.php 6 months ago Post.php 6 months ago Term.php 6 months ago User.php 6 months ago
Option.php
152 lines
1 <?php
2 /**
3 * @package ACF
4 * @author WP Engine
5 *
6 * © 2026 Advanced Custom Fields (ACF®). All rights reserved.
7 * "ACF" is a trademark of WP Engine.
8 * Licensed under the GNU General Public License v2 or later.
9 * https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 namespace ACF\Meta;
13
14 /**
15 * A class to add support for saving to options.
16 */
17 class Option extends MetaLocation {
18
19 /**
20 * The unique slug/name of the meta location.
21 *
22 * @var string
23 */
24 public string $location_type = 'option';
25
26 /**
27 * Retrieves all ACF meta for the provided object ID.
28 *
29 * @since 6.4
30 *
31 * @param integer|string $object_id The ID of the object to get meta from.
32 * @return array
33 */
34 public function get_meta( $object_id = 0 ): array {
35 $all_meta = acf_get_option_meta( $object_id );
36 $meta = array();
37
38 foreach ( $all_meta as $key => $value ) {
39 // If a reference exists for this value, add it to the meta array.
40 if ( isset( $all_meta[ $this->reference_prefix . $key ] ) ) {
41 $meta[ $key ] = $value[0];
42 $meta[ $this->reference_prefix . $key ] = $all_meta[ $this->reference_prefix . $key ][0];
43 }
44 }
45
46 // Return results.
47 return $meta;
48 }
49
50 /**
51 * Retrieves a field value from the database.
52 *
53 * @since 6.4
54 *
55 * @param integer|string $object_id The ID of the object the metadata is for.
56 * @param array $field The field array.
57 * @return mixed
58 */
59 public function get_value( $object_id = 0, array $field = array() ) {
60 return get_option( $object_id . '_' . $field['name'], null );
61 }
62
63 /**
64 * Gets a reference key for the provided field name.
65 *
66 * @since 6.4
67 *
68 * @param integer|string $object_id The ID of the object to get the reference key from.
69 * @param string $field_name The name of the field to get the reference for.
70 * @return string|boolean
71 */
72 public function get_reference( $object_id = '', $field_name = '' ) {
73 return get_option( $this->reference_prefix . $object_id . '_' . $field_name, null );
74 }
75
76 /**
77 * Updates an object ID with the provided meta array.
78 *
79 * @since 6.4
80 *
81 * @param integer|string $object_id The ID of the object the metadata is for.
82 * @param array $meta The metadata to save to the object.
83 * @return void
84 */
85 public function update_meta( $object_id = 0, array $meta = array() ) {
86 $autoload = (bool) acf_get_setting( 'autoload' );
87
88 foreach ( $meta as $name => $value ) {
89 $value = wp_unslash( $value );
90 update_option( $object_id . '_' . $name, $value, $autoload );
91 }
92 }
93
94 /**
95 * Updates a field value in the database.
96 *
97 * @since 6.4
98 *
99 * @param integer|string $object_id The ID of the object the metadata is for.
100 * @param array $field The field array.
101 * @param mixed $value The metadata value.
102 * @return integer|boolean
103 */
104 public function update_value( $object_id = 0, array $field = array(), $value = '' ) {
105 $value = wp_unslash( $value );
106 $autoload = (bool) acf_get_setting( 'autoload' );
107
108 return update_option( $object_id . '_' . $field['name'], $value, $autoload );
109 }
110
111 /**
112 * Updates a reference key in the database.
113 *
114 * @since 6.4
115 *
116 * @param integer|string $object_id The ID of the object the metadata is for.
117 * @param string $field_name The name of the field to update the reference for.
118 * @param string $value The value of the reference key.
119 * @return integer|boolean
120 */
121 public function update_reference( $object_id = 0, string $field_name = '', string $value = '' ) {
122 $autoload = (bool) acf_get_setting( 'autoload' );
123 return update_option( $this->reference_prefix . $object_id . '_' . $field_name, $value, $autoload );
124 }
125
126 /**
127 * Deletes a field value from the database.
128 *
129 * @since 6.4
130 *
131 * @param integer|string $object_id The ID of the object the metadata is for.
132 * @param array $field The field array.
133 * @return boolean
134 */
135 public function delete_value( $object_id = 0, array $field = array() ): bool {
136 return delete_option( $object_id . '_' . $field['name'] );
137 }
138
139 /**
140 * Deletes a reference key from the database.
141 *
142 * @since 6.4
143 *
144 * @param integer|string $object_id The ID of the object the metadata is for.
145 * @param string $field_name The name of the field to delete the reference from.
146 * @return boolean
147 */
148 public function delete_reference( $object_id = 0, string $field_name = '' ): bool {
149 return delete_option( $this->reference_prefix . $object_id . '_' . $field_name );
150 }
151 }
152