SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | ||
3 | global $intense_post_types; | |
4 | ||
5 | class Intense_Post_Type { | |
6 | public $type; | |
7 | public $title; | |
8 | public $singular; | |
9 | public $plural; | |
10 | public $fields; | |
11 | public $icon; | |
12 | ||
13 | public function register() { | |
14 | //CPT's | |
15 | if ( $this->type != 'intense_post' ) { | |
16 | register_post_type( | |
17 | $this->type, | |
18 | array( | |
19 | 'labels' => array( | |
20 | 'name' => $this->plural, | |
21 | 'singular_name' => $this->singular, | |
22 | 'menu_name' => $this->plural, | |
23 | 'all_items' => __( 'All', "intense" ) . ' ' . $this->plural, | |
24 | 'add_new_item' => __( 'Add New', "intense" ) . ' ' . $this->singular, | |
25 | 'edit_item' => __( 'Edit', "intense" ) . ' ' . $this->singular, | |
26 | 'new_item' => __( 'New', "intense" ) . ' ' . $this->singular, | |
27 | 'view_item' => __( 'View', "intense" ) . ' ' . $this->singular, | |
28 | 'search_items' => __( 'Edit', "intense" ) . ' ' . $this->singular, | |
29 | 'not_found' => __( 'No', "intense" ) . ' ' . $this->plural . ' ' . __( 'found', "intense" ), | |
30 | 'not_found_in_trash' => __( 'No', "intense" ) . ' ' . $this->plural . ' ' . __( 'found in Trash', "intense" ) | |
31 | ), | |
32 | 'public' => true, | |
33 | 'has_archive' => true, | |
34 | 'rewrite' => array( 'slug' => strtolower( $this->singular ) ), | |
35 | 'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ), | |
36 | 'can_export' => true, | |
37 | 'menu_icon'=> $this->icon, | |
38 | ) | |
39 | ); | |
40 | ||
41 | } | |
42 | ||
43 | if ( function_exists( "register_field_group" ) && $this->type != 'intense_snippets' ) { | |
44 | $postType = $this->type; | |
45 | ||
46 | if ( $this->type == 'intense_post' ) { | |
47 | $postType = 'post'; | |
48 | } | |
49 | ||
50 | register_field_group( array ( | |
51 | 'id' => 'acf_' . strtolower( $this->singular ) . '-options', | |
52 | 'title' => $this->singular . ' ' . __( 'Options', "intense" ), | |
53 | 'fields' => $this->fields, | |
54 | 'location' => array ( | |
55 | array ( | |
56 | array ( | |
57 | 'param' => 'post_type', | |
58 | 'operator' => '==', | |
59 | 'value' => $postType, | |
60 | 'order_no' => 0, | |
61 | 'group_no' => 0, | |
62 | ), | |
63 | ), | |
64 | ), | |
65 | 'options' => array ( | |
66 | 'position' => 'normal', | |
67 | 'layout' => 'default', | |
68 | 'hide_on_screen' => array ( | |
69 | ), | |
70 | ), | |
71 | 'menu_order' => 0, | |
72 | ) ); | |
73 | } | |
74 | ||
75 | if ( isset( $this->category_taxonomy_key ) && $this->category_taxonomy_key != '' ) { | |
76 | $this->register_category_taxonomy( $this->category_taxonomy_key ); | |
77 | } | |
78 | ||
79 | if ( is_array( $this->taxonomies ) ) { | |
80 | foreach ( $this->taxonomies as $key => $taxonomy ) { | |
81 | if ( is_array( $taxonomy ) ) { | |
82 | $this->register_taxonomy( $taxonomy['key'] ,$taxonomy['singular'], $taxonomy['plural'] ); | |
83 | } | |
84 | } | |
85 | } | |
86 | } | |
87 | ||
88 | public function register_category_taxonomy( $key ) { | |
89 | register_taxonomy( $key, $this->type, array( 'hierarchical' => true, 'label' => $this->singular . ' ' . __( 'Categories', "intense" ), 'query_var' => true, 'rewrite' => true ) ); | |
90 | } | |
91 | ||
92 | public function register_taxonomy( $key, $singular, $plural ) { | |
93 | $labels = array(); | |
94 | $labels['name'] = $plural; | |
95 | $labels['singular_name'] = $singular; | |
96 | $labels['search_items'] = __( 'Search', "intense" ) . ' ' . $plural; | |
97 | $labels['add_new_item'] = __( 'Add New', "intense" ) . ' ' . $singular; | |
98 | $labels['new_item_name'] = __( 'New', "intense" ) . ' ' . $singular . ' ' . __( 'Name', "intense" ); | |
99 | $labels['menu_name'] = $plural; | |
100 | ||
101 | register_taxonomy( $key, $this->type, array( 'hierarchical' => true, 'label' => $plural, 'labels' => $labels, 'query_var' => true, 'rewrite' => true ) ); | |
102 | } | |
103 | ||
104 | public function get_excerpt( $limit ) { | |
105 | $excerpt = explode( ' ', get_the_excerpt(), $limit ); | |
106 | ||
107 | return $this->get_clean_excerpt( $excerpt, $limit ); | |
108 | } | |
109 | ||
110 | protected function get_clean_excerpt( $excerpt, $limit ) { | |
111 | if ( count( $excerpt ) >= $limit ) { | |
112 | array_pop( $excerpt ); | |
113 | $excerpt = implode( " ", $excerpt ).'...'; | |
114 | } else { | |
115 | $excerpt = implode( " ", $excerpt ); | |
116 | } | |
117 | ||
118 | $excerpt = preg_replace( '`\[[^\]]*\]`', '', $excerpt ); | |
119 | ||
120 | return $excerpt; | |
121 | } | |
122 | ||
123 | public function get_content( $limit ) { | |
124 | $content = get_the_content(); | |
125 | ||
126 | return $this->get_clean_content( $content, $limit ); | |
127 | } | |
128 | ||
129 | protected function get_clean_content( $content, $limit ) { | |
130 | $original_content = preg_replace( "~(?:\[/?)[^/\]]+/?\]~s", '', $content ); | |
131 | ||
132 | $content = explode( ' ', $original_content, $limit ); | |
133 | ||
134 | if ( count( $content ) >= $limit ) { | |
135 | array_pop( $content ); | |
136 | $content = implode( " ", $content ).'...'; | |
137 | } else { | |
138 | $content = implode( " ", $content ); | |
139 | } | |
140 | ||
141 | $content = apply_filters( 'the_content', $content ); | |
142 | $content = str_replace( ']]>', ']]>', $content ); | |
143 | ||
144 | return $content; | |
145 | } | |
146 | ||
147 | public function get_subtitle() { | |
148 | return ''; | |
149 | } | |
150 | } | |
151 | ||
152 | class Intense_Post_Types { | |
153 | public $post_types; | |
154 | ||
155 | function __construct() { | |
156 | $this->add_types(); | |
157 | ||
158 | add_action( 'wp_loaded', array( $this, 'register' ) ); | |
159 | add_filter( 'enter_title_here', array( $this, 'get_title' ) ); | |
160 | add_filter( 'template_include', array( $this, 'content_single' ) ); | |
161 | } | |
162 | ||
163 | function add_types() { | |
164 | global $intense_visions_options; | |
165 | ||
166 | $types = array ( | |
167 | "books", | |
168 | "clients", | |
169 | "coupons", | |
170 | "events", | |
171 | "faq", | |
172 | "jobs", | |
173 | "locations", | |
174 | "movies", | |
175 | "news", | |
176 | "portfolio", | |
177 | "post", | |
178 | //"pricing", | |
179 | "project", | |
180 | "quotes", | |
181 | "recipes", | |
182 | "snippets", | |
183 | "team", | |
184 | "templates", | |
185 | "testimonials", | |
186 | ); | |
187 | ||
188 | foreach ( $types as $custom_post_type ) { | |
189 | if ( isset( $intense_visions_options[ 'intense_cpt_' . $custom_post_type ] ) && $intense_visions_options[ 'intense_cpt_' . $custom_post_type ] ) { | |
190 | require_once INTENSE_PLUGIN_FOLDER . '/inc/cpt/' . $custom_post_type . '.php'; | |
191 | ||
192 | $class = "Intense_Post_Type_" . ucfirst( $custom_post_type ); | |
193 | $object = new $class(); | |
194 | ||
195 | ||
196 | $this->post_types[ strtolower( $class ) ] = $object; | |
197 | flush_rewrite_rules(); | |
198 | } | |
199 | } | |
200 | ||
201 | require_once INTENSE_PLUGIN_FOLDER . '/inc/cpt/post.php'; | |
202 | $this->post_types[ 'intense_post_type_post' ] = new Intense_Post_Type_Post(); | |
203 | ||
204 | } | |
205 | ||
206 | function is_type_enabled( $type ) { | |
207 | $post_type = $this->get_post_type( $type ); | |
208 | ||
209 | if ( isset( $post_type ) ) { | |
210 | return true; | |
211 | } else { | |
212 | return false; | |
213 | } | |
214 | ||
215 | } | |
216 | ||
217 | function register() { | |
218 | foreach ($this->post_types as $key => $value) { | |
219 | $value->register(); | |
220 | } | |
221 | } | |
222 | ||
223 | function get_post_type( $type ) { | |
224 | $class = strtolower( "Intense_Post_Type_" . ucfirst( str_replace( 'intense_', '', $type ) ) ); | |
225 | ||
226 | if ( isset( $this->post_types[ $class ] ) ) { | |
227 | return $this->post_types[ $class ]; | |
228 | } | |
229 | ||
230 | return null; | |
231 | } | |
232 | ||
233 | function get_title( $title ) { | |
234 | $screen = get_current_screen(); | |
235 | $type = $screen->post_type; | |
236 | $post_type = $this->get_post_type( $type ); | |
237 | ||
238 | if ( isset( $post_type ) ) { | |
239 | $title = $post_type->title; | |
240 | } | |
241 | ||
242 | return $title; | |
243 | } | |
244 | ||
245 | function content_single( $single_template ) { | |
246 | global $intense_visions_options; | |
247 | ||
248 | $post_type = $this->get_post_type( get_post_type() ); | |
249 | ||
250 | if ( is_single() && !is_page() && !empty( $post_type ) && get_post_type() != 'intense_templates' ) { | |
251 | if ( get_field( get_post_type() . '_single_template' ) != '' ) { | |
252 | $template = get_field( 'intense_' . str_replace( 'intense_', '', get_post_type() ) . '_single_template' ); | |
253 | } else { | |
254 | $template = $intense_visions_options[ 'intense_cpt_' . str_replace( 'intense_', '', get_post_type() ) . '_single' ]; | |
255 | } | |
256 | ||
257 | // if the template is numeric then it is a templates that they have saved in WordPress | |
258 | if ( is_numeric( str_replace("template_", "", $template ) ) ) { | |
259 | $template_post = get_post( str_replace("template_", "", $template ) ); | |
260 | $found_template = Intense_Post_Type_Templates::get_template_cache( $template_post->ID ); | |
261 | } else { | |
262 | $found_template = intense_locate_plugin_template( '/custom-post/' . get_post_type() . '/single/' . $template . '.php' ); | |
263 | } | |
264 | ||
265 | if ( !empty( $found_template ) ) { | |
266 | $single_template = $found_template; | |
267 | } | |
268 | } | |
269 | ||
270 | return $single_template; | |
271 | } | |
272 | } | |
273 | ||
274 | $intense_post_types = new Intense_Post_Types(); |