Completed
Push — develop ( 704bfc...0cb6ff )
by David
26:15 queued 11:17
created

core::core_assets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Interface for WordPress core
5
 *
6
 * @package   uix
7
 * @author    David Cramer
8
 * @license   GPL-2.0+
9
 * @link
10
 * @copyright 2016 David Cramer
11
 */
12
13
namespace uix\ui\core;
14
15
class core {
16
17
	/**
18
	 * List of core object scripts ( common scripts )
19
	 *
20
	 * @since  1.0.0
21
	 * @access protected
22
	 * @var      array
23
	 */
24
	protected $scripts = [];
25
26
	/**
27
	 * List of core object styles ( common styles )
28
	 *
29
	 * @since  1.0.0
30
	 * @access protected
31
	 * @var      array
32
	 */
33
	protected $styles = [];
34
35
36
	/**
37
	 * setup actions and hooks - override to add specific hooks. use
38
	 * parent::actions() to keep admin head
39
	 *
40
	 * @since  1.0.0
41
	 * @access protected
42
	 */
43
	protected function actions() {
44
45
		// init uix after loaded.
46
		add_action( 'init', [ $this, 'init' ] );
47
		// set location.
48
		$location = 'wp_print_styles';
49
		if ( is_admin() ) {
50
			$location = 'admin_enqueue_scripts';
51
		}
52
		// init UIX headers.
53
		add_action( $location, [ $this, 'enqueue_core' ] );
54
	}
55
56
57
	/**
58
	 * Define core UIX styles - override to register core ( common styles for
59
	 * uix type )
60
	 *
61
	 * @since  1.0.0
62
	 * @access public
63
	 */
64
	public function set_assets() {
65
		if ( ! empty( $this->struct['style'] ) ) {
66
			$this->assets['style'] = array_merge( $this->assets['style'], $this->struct['style'] );
0 ignored issues
show
Bug introduced by
The property assets does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property struct does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
67
		}
68
		if ( ! empty( $this->struct['script'] ) ) {
69
			$this->assets['script'] = array_merge( $this->assets['script'], $this->struct['script'] );
70
		}
71
	}
72
73
	/**
74
	 * enqueue core assets
75
	 *
76
	 * @since  1.0.0
77
	 * @access public
78
	 */
79
	public function enqueue_core() {
80
81
		// Register uix core asset.
82
		$this->core_assets();
83
		$this->enqueue_actions();
84
		// push assets to ui manager.
85
		uix()->set_assets( $this->assets );
86
		// done enqueuing - dpo inline or manual enqueue.
87
		$this->set_active_styles();
88
	}
89
90
	/**
91
	 * Do core enqueue actions.
92
	 *
93
	 * @since  3.0.0
94
	 * @access public
95
	 */
96
	private function enqueue_actions() {
97
		/**
98
		 * Do object initilisation.
99
		 *
100
		 * @param object current uix instance
101
		 */
102
		do_action( 'uix_admin_enqueue_scripts_' . $this->type, $this );
0 ignored issues
show
Bug introduced by
The property type does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
103
104
		/**
105
		 * Do object initilisation for specific slug.
106
		 *
107
		 * @param object current uix instance
108
		 */
109
		do_action( 'uix_admin_enqueue_scripts_' . $this->type . '_' . $this->slug, $this );
0 ignored issues
show
Bug introduced by
The property slug does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
110
	}
111
112
	/**
113
	 * Register UIX depend js and css and call set assets
114
	 *
115
	 * @since  1.0.0
116
	 * @access protected
117
	 */
118
	protected function core_assets() {
119
		wp_register_script( 'uix', $this->url . 'assets/js/core' . UIX_ASSET_DEBUG . '.js' );
0 ignored issues
show
Bug introduced by
The property url does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
120
		wp_register_style( 'uix', $this->url . 'assets/css/core' . UIX_ASSET_DEBUG . '.css', [ 'dashicons' ] );
121
		wp_localize_script( 'uix', 'uixApi', [
122
			'root'  => esc_url_raw( rest_url() ),
123
			'nonce' => wp_create_nonce( 'wp_rest' ),
124
		] );
125
126
		// set assets . methods at before this point can set assets, after this not so much.
127
		$this->set_assets();
128
	}
129
130
	/**
131
	 * runs after assets have been enqueued
132
	 *
133
	 * @since  1.0.0
134
	 * @access protected
135
	 */
136
	protected function set_active_styles() {
137
	}
138
139
	/**
140
	 * Base color helper
141
	 *
142
	 * @since  1.0.0
143
	 * @access public
144
	 */
145
	protected function base_color() {
146
		$color = '#D84315';
147
		if ( empty( $this->struct['base_color'] ) ) {
148
			if ( ! empty( $this->parent ) ) {
149
				$color = $this->parent->base_color();
0 ignored issues
show
Bug introduced by
The property parent does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
150
			}
151
		} else {
152
			$color = $this->struct['base_color'];
153
		}
154
155
		/**
156
		 * do object initilisation for specific slug
157
		 *
158
		 * @param object current uix instance
159
		 */
160
		return apply_filters( 'uix_base_color_' . $this->type . '_' . $this->slug, $color );
161
162
	}
163
}
164
165