-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandpickedCollectionColumn.php
executable file
·187 lines (124 loc) · 3.62 KB
/
HandpickedCollectionColumn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* Plugin Name: Chef Handpicked Collection Column
* Plugin URI: http://chefduweb.nl/plugins/chef-handpicked-collection-column
* Description: pick the content of your collection by hand
* Version: 1.1
* Author: Luc Princen & Remy Bakker
* Author URI: http://www.chefduweb.nl/
* License: GPLv2
*
* @package Cuisine
* @category Core
* @author Chef du Web
*/
//Chaning the namespaces is the most important part,
//after that the bus pretty much drives itself.
namespace HandpickedCollectionColumn;
use Cuisine\Wrappers\Script;
use Cuisine\Wrappers\Sass;
use Cuisine\Utilities\Url;
class ColumnIgniter{
/**
* Static bootstrapped HandpickedCollectionColumn\ColumnIgniter instance.
*
* @var \HandpickedCollectionColumn\ColumnIgniter
*/
public static $instance = null;
/**
* Init admin events & vars
*/
function __construct(){
//register column:
$this->register();
//load the right files
$this->load();
//assets:
$this->enqueues();
}
/**
* Register this column-type with Chef Sections
*
* @return void
*/
private function register(){
add_filter( 'chef_sections_column_types', function( $types ){
$base = Url::path( 'plugin', 'chef-handpicked-collection-column', true );
//change the $types[ key ] and the name value:
$types['handpickedcollection'] = array(
'name' => 'Handpicked Collection',
'class' => 'HandpickedCollectionColumn\Column',
'template' => $base.'Assets/template.php'
);
return $types;
});
add_action( 'init', function(){
add_filter( 'cuisine_field_types', function( $arr ){
$arr['handpickedcollection'] = array(
'name' => 'Posts Zoeker',
'class' => 'HandpickedCollectionColumn\\Hooks\\HandpickedCollectionField'
);
return $arr;
});
});
}
/**
* Load all includes for this plugin
*
* @return void
*/
private function load(){
//auto-loads all .php files in these directories.
$includes = array(
'Classes/Wrappers', //facades
'Classes/Hooks',
'Classes/Front',
'Classes/Admin',
'Classes'
);
foreach( $includes as $inc ){
$root = static::getPluginPath();
$files = glob( $root.$inc.'/*.php' );
foreach ( $files as $file ){
require_once( $file );
}
}
}
/**
* Enqueue scripts & Styles
*
* @return void
*/
private function enqueues(){
add_action( 'admin_menu', function(){
$url = Url::plugin( 'chef-handpicked-collection-column', true ).'Assets';
//enqueue a script
//wp_enqueue_script( 'chef_related', $url.'/js/Admin.js' );
wp_enqueue_script( 'chef_handpicked_collection_search', $url.'/js/HandpickedCollectionSearch.js' );
//enqueue a stylesheet:
wp_enqueue_style( 'handpicked-collection-style', $url.'/css/admin.css' );
});
}
/*=============================================================*/
/** Getters & Setters */
/*=============================================================*/
/**
* Init the \HandpickedCollectionColumn\ColumnIgniter Class
*
* @return \HandpickedCollectionColumn\ColumnIgniter
*/
public static function getInstance(){
return static::$instance = new static();
}
/**
* Get the plugin path
*
* @return string
*/
public static function getPluginPath(){
return __DIR__.DS;
}
}
add_action('chef_sections_loaded', function(){
\HandpickedCollectionColumn\ColumnIgniter::getInstance();
});