Completed
Push — master ( 0ab7b5...1a45bc )
by Marin
02:48
created

Scripts_Field::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php 
2
3
namespace Carbon_Fields\Field;
4
5
/**
6
 * Abstract scripts field class.
7
 * Intended only for use in theme options container.
8
 */
9
abstract class Scripts_Field extends Textarea_Field {
10
	/**
11
	 * Initialization actions
12
	 */
13
	public function init() {
14
		$this->help_text( $this->get_default_help_text() );
15
16
		add_action( $this->get_hook_name(), array( $this, 'print_scripts' ) );
17
18
		parent::init();
19
	}
20
21
	/**
22
	 * Display the field value in the front-end header.
23
	 */
24
	public function print_scripts() {
25
		if ( ! $this->store || ! is_a( $this->store, 'Carbon_Fields\\Datastore\\Theme_Options_Datastore' ) ) {
26
			return;
27
		}
28
29
		echo get_option( $this->name );
1 ignored issue
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_option'
Loading history...
30
	}
31
32
	/**
33
	 * Default help text to be displayed for this type of field.
34
	 */
35
	abstract public function get_default_help_text();
36
37
	/**
38
	 * Action name to be hooked on.
39
	 */
40
	abstract public function get_hook_name();
41
}
42