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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 / includes / fields / class-acf-field-url.php
advanced-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 5 months ago class-acf-field-button-group.php 5 months ago class-acf-field-checkbox.php 2 months ago class-acf-field-color_picker.php 5 months ago class-acf-field-date_picker.php 5 months ago class-acf-field-date_time_picker.php 5 months ago class-acf-field-email.php 5 months ago class-acf-field-file.php 5 months ago class-acf-field-google-map.php 5 months ago class-acf-field-group.php 5 months ago class-acf-field-icon_picker.php 6 months ago class-acf-field-image.php 1 month ago class-acf-field-link.php 5 months ago class-acf-field-message.php 6 months ago class-acf-field-number.php 5 months ago class-acf-field-oembed.php 2 months ago class-acf-field-output.php 6 months ago class-acf-field-page_link.php 1 month ago class-acf-field-password.php 5 months ago class-acf-field-post_object.php 1 month ago class-acf-field-radio.php 2 months ago class-acf-field-range.php 5 months ago class-acf-field-relationship.php 1 month ago class-acf-field-select.php 2 months ago class-acf-field-separator.php 6 months ago class-acf-field-tab.php 6 months ago class-acf-field-taxonomy.php 2 months ago class-acf-field-text.php 5 months ago class-acf-field-textarea.php 5 months ago class-acf-field-time_picker.php 5 months ago class-acf-field-true_false.php 5 months ago class-acf-field-url.php 5 months ago class-acf-field-user.php 2 months ago class-acf-field-wysiwyg.php 5 months ago class-acf-field.php 5 months ago index.php 2 years ago
class-acf-field-url.php
201 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 if ( ! class_exists( 'acf_field_url' ) ) :
13
14 /**
15 * The URL field class.
16 */
17 class acf_field_url extends acf_field {
18
19
20 /**
21 * This function will setup the field type data
22 *
23 * @since 5.0.0
24 */
25 public function initialize() {
26 // vars
27 $this->name = 'url';
28 $this->label = __( 'URL', 'acf' );
29 $this->description = __( 'A text input specifically designed for storing web addresses.', 'acf' );
30 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-url.png';
31 $this->doc_url = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/url/', 'docs', 'field-type-selection' );
32 $this->defaults = array(
33 'default_value' => '',
34 'placeholder' => '',
35 );
36 $this->supports = array(
37 'escaping_html' => true,
38 );
39 }
40
41
42 /**
43 * Create the HTML interface for your field
44 *
45 * @since 3.6
46 *
47 * @param array $field An array holding all the field's data.
48 */
49 public function render_field( $field ) {
50 $atts = array();
51 $keys = array( 'type', 'id', 'class', 'name', 'value', 'placeholder', 'pattern' );
52 $keys2 = array( 'readonly', 'disabled', 'required' );
53
54 // atts (value="123")
55 foreach ( $keys as $k ) {
56 if ( isset( $field[ $k ] ) ) {
57 $atts[ $k ] = $field[ $k ];
58 }
59 }
60
61 // atts2 (disabled="disabled")
62 foreach ( $keys2 as $k ) {
63 if ( ! empty( $field[ $k ] ) ) {
64 $atts[ $k ] = $k;
65 }
66 }
67
68 // remove empty atts
69 $atts = acf_clean_atts( $atts );
70
71 // render
72 $html = '<div class="acf-input-wrap acf-url">';
73 $html .= '<i class="acf-icon -globe -small"></i>' . acf_get_text_input( $atts );
74 $html .= '</div>';
75
76 // return
77 echo $html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- safe HTML, escaped by acf_get_text_input.
78 }
79
80
81 /**
82 * Create extra options for your field. This is rendered when editing a field.
83 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
84 *
85 * @since 3.6
86 *
87 * @param array $field An array holding all the field's data.
88 */
89 public function render_field_settings( $field ) {
90 acf_render_field_setting(
91 $field,
92 array(
93 'label' => __( 'Default Value', 'acf' ),
94 'instructions' => __( 'Appears when creating a new post', 'acf' ),
95 'type' => 'text',
96 'name' => 'default_value',
97 )
98 );
99 }
100
101 /**
102 * Renders the field settings used in the "Presentation" tab.
103 *
104 * @since 6.0
105 *
106 * @param array $field The field settings array.
107 * @return void
108 */
109 public function render_field_presentation_settings( $field ) {
110 acf_render_field_setting(
111 $field,
112 array(
113 'label' => __( 'Placeholder Text', 'acf' ),
114 'instructions' => __( 'Appears within the input', 'acf' ),
115 'type' => 'text',
116 'name' => 'placeholder',
117 )
118 );
119 }
120
121
122 /**
123 * Validate the fields value is correctly formatted as a URL
124 *
125 * @since 5.0.0
126 *
127 * @param mixed $valid The current validity of the field value. Boolean true if valid, a validation error message string if not.
128 * @param string $value The value of the field.
129 * @param array $field Field object array.
130 * @param string $input The form input name for this field.
131 * @return mixed Boolean true if valid, a validation error message string if not.
132 */
133 public function validate_value( $valid, $value, $field, $input ) {
134
135 // bail early if empty
136 if ( empty( $value ) ) {
137 return $valid;
138 }
139
140 if ( strpos( $value, '://' ) !== false ) {
141
142 // url
143 } elseif ( strpos( $value, '//' ) === 0 ) {
144
145 // protocol relative url
146 } else {
147 $valid = __( 'Value must be a valid URL', 'acf' );
148 }
149
150 // return
151 return $valid;
152 }
153
154 /**
155 * This filter is applied to the $value after it is loaded from the db, and before it is returned to the template
156 *
157 * @since 6.2.6
158 *
159 * @param mixed $value The value which was loaded from the database.
160 * @param mixed $post_id The $post_id from which the value was loaded.
161 * @param array $field The field array holding all the field options.
162 * @param boolean $escape_html Should the field return a HTML safe formatted value.
163 * @return mixed $value The modified value
164 */
165 public function format_value( $value, $post_id, $field, $escape_html ) {
166 if ( $escape_html ) {
167 return esc_url( $value );
168 }
169 return $value;
170 }
171
172 /**
173 * Return the schema array for the REST API.
174 *
175 * @param array $field The field object.
176 * @return array
177 */
178 public function get_rest_schema( array $field ) {
179 $schema = parent::get_rest_schema( $field );
180 $schema['format'] = 'uri';
181
182 return $schema;
183 }
184
185 /**
186 * Returns an array of JSON-LD Property output types that are supported by this field type.
187 *
188 * @since 6.8
189 *
190 * @return string[]
191 */
192 public function get_jsonld_output_types(): array {
193 return array( 'URL' );
194 }
195 }
196
197
198 // initialize
199 acf_register_field_type( 'acf_field_url' );
200 endif; // class_exists check
201