1: <?php
2:
3: 4: 5:
6: class Papi_Property_Url extends Papi_Property {
7:
8: 9: 10: 11: 12:
13: public function get_default_settings() {
14: return [
15: 'mediauploader' => false
16: ];
17: }
18:
19: 20: 21:
22: public function html() {
23: $settings = $this->get_settings();
24:
25: papi_render_html_tag( 'input', [
26: 'class' => $settings->mediauploader ? 'papi-url-media-input' : null,
27: 'id' => $this->html_id(),
28: 'name' => $this->html_name(),
29: 'type' => 'url',
30: 'value' => $this->get_value()
31: ] );
32:
33: if ( $settings->mediauploader ) {
34: echo ' ';
35:
36: papi_render_html_tag( 'input', [
37: 'class' => 'button papi-url-media-button',
38: 'data-papi-action' => 'mediauploader',
39: 'id' => $this->html_id(),
40: 'name' => $this->html_name() . '_button',
41: 'type' => 'button',
42: 'value' => __( 'Select file', 'papi' )
43: ] );
44: }
45: }
46:
47: 48: 49: 50: 51: 52: 53: 54: 55:
56: public function import_value( $value, $slug, $post_id ) {
57: return $this->load_value( $value, $slug, $post_id );
58: }
59:
60: 61: 62: 63: 64: 65: 66: 67: 68:
69: public function load_value( $value, $slug, $post_id ) {
70: if ( filter_var( $value, FILTER_VALIDATE_URL ) ) {
71: return $value;
72: }
73: }
74:
75: 76: 77: 78: 79: 80: 81: 82: 83:
84: public function update_value( $value, $slug, $post_id ) {
85: return $this->load_value( $value, $slug, $post_id );
86: }
87: }
88: