Completed
Push — develop ( dd2c91...e970a6 )
by David
02:48
created

WL_Metabox_Field_sameas::save_data()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Metaboxes: sameAs Field Metabox.
4
 *
5
 * @since      3.0.0
6
 * @package    Wordlift
7
 * @subpackage Wordlift/admin/WL_Metabox
8
 */
9
10
/**
11
 * Define the {@link WL_Metabox_Field_sameas} class.
12
 *
13
 * @since      3.0.0
14
 * @package    Wordlift
15
 * @subpackage Wordlift/admin/WL_Metabox
16
 */
17
class WL_Metabox_Field_sameas extends WL_Metabox_Field {
18
19
	/**
20
	 * @inheritdoc
21
	 */
22
	public function __construct( $args ) {
23
		parent::__construct( $args['sameas'] );
24
	}
25
26
	/**
27
	 * @inheritdoc
28
	 */
29
	public function save_data( $values ) {
30
		// The autocomplete select may send JSON arrays in input values.
31
		$merged = array_reduce( (array) $values, function ( $carry, $item ) {
32
			return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
33
		}, array() );
34
35
		parent::save_data( $merged );
36
	}
37
38
	/**
39
	 * @inheritdoc
40
	 */
41
	public function sanitize_data_filter( $value ) {
42
43
		// Call our sanitizer helper.
44
		return Wordlift_Sanitizer::sanitize_url( $value );
45
	}
46
47
	/**
48
	 * @inheritdoc
49
	 */
50
	protected function get_add_button_html( $count ) {
51
52
		// Return an element where the new Autocomplete Select will attach to.
53
		return '<p>'
54
			   . esc_html__( 'Type a URL or any text to find entities from the vocabulary and the cloud:', 'wordlift' )
55
			   . '</p><div id="wl-metabox-field-sameas"></div>';
56
	}
57
58
}
59