1 <?php
2 /**
3 * UIX Post Type
4 *
5 * @package ui
6 * @author David Cramer
7 * @license GPL-2.0+
8 * @link
9 * @copyright 2016 David Cramer
10 */
11 namespace uix\ui;
12
13 /**
14 * UIX Post Type class for adding custom post types
15 * @package uix\ui
16 * @author David Cramer
17 */
18 class post_type extends uix{
19
20 /**
21 * The type of object
22 *
23 * @since 1.0.0
24 * @access public
25 * @var string
26 */
27 public $type = 'post';
28
29
30 /**
31 * setup actions and hooks to register post types
32 *
33 * @since 1.0.0
34 * @access protected
35 */
36 protected function actions() {
37
38 // run parent actions ( keep 'admin_head' hook )
39 parent::actions();
40 // add settings page
41 add_action( 'init', array( $this, 'render' ) );
42
43 }
44
45
46 /**
47 * Render the custom header styles
48 *
49 * @since 1.0.0
50 * @access protected
51 */
52 protected function enqueue_active_assets(){
53 // output the styles
54 ?><style type="text/css">
55 .contextual-help-tabs .active {
56 border-left: 6px solid <?php echo $this->base_color(); ?> !important;
57 }
58 #wpbody-content .wrap > h1 {
59 box-shadow: 0 0 2px rgba(0, 2, 0, 0.1),11px 0 0 <?php echo $this->base_color(); ?> inset;
60 }
61 #wpbody-content .wrap > h1 a.page-title-action:hover{
62 background: <?php echo $this->base_color(); ?>;
63 border-color: <?php echo $this->base_color(); ?>;
64 }
65 #wpbody-content .wrap > h1 a.page-title-action:focus{
66 box-shadow: 0 0 2px <?php echo $this->base_color(); ?>;
67 border-color: <?php echo $this->base_color(); ?>;
68 }
69 </style>
70 <?php
71 }
72
73 /**
74 * Define core UIX styling to identify UIX post types
75 *
76 * @since 1.0.0
77 * @access public
78 */
79 public function set_assets() {
80 $this->assets['style']['post'] = $this->url . 'assets/css/post' . UIX_ASSET_DEBUG . '.css';
81 parent::set_assets();
82 }
83
84 /**
85 * Render (register) the post type
86 *
87 * @since 1.0.0
88 * @access public
89 */
90 public function render() {
91
92 if( !empty( $this->struct['settings'] ) )
93 register_post_type( $this->slug, $this->struct['settings'] );
94
95 }
96
97 /**
98 * Determin which post types are active and set them active and render some styling
99 * Intended to be ovveridden
100 * @since 1.0.0
101 * @access public
102 */
103 public function is_active(){
104
105 if( !is_admin() ){ return false; }
106
107 $screen = get_current_screen();
108
109 return $screen->post_type === $this->slug;
110
111 }
112
113 }