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