Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 140 lines (104 sloc) 4.257 kB
2e014cc @hunk update
hunk authored
1 <?php
2 /**
3 *
4 */
5 class mf_register{
6
7 public $name = 'mf_register';
8
9 function __construct(){
10 add_action('init', array( &$this, 'mf_register_custom_taxonomies' ) );
11 add_action('init', array( &$this, 'mf_register_post_types' ) );
0f441a4 @hunk move cap in save post type, add export post type
hunk authored
12
2e014cc @hunk update
hunk authored
13 }
14
15 // register post type
16 public function mf_register_post_types(){
8a6cf3f @hunk add function $this->flash
hunk authored
17 global $mf_pt_register;
2e014cc @hunk update
hunk authored
18
19 $post_types = $this->_get_post_types();
0f441a4 @hunk move cap in save post type, add export post type
hunk authored
20
2e014cc @hunk update
hunk authored
21 foreach($post_types as $p){
1362832 @hunk replace json_encode for serialize
hunk authored
22 $p = unserialize($p['arguments']);
2e014cc @hunk update
hunk authored
23
24 $name = $p['core']['type'];
25 $option = $p['option'];
26
27 $option['show_in_menu'] = ($option['show_in_menu']) ? true : false;
28 $option['query_var'] = ($option['query_var']) ? true : false;
f610ab4 @hunk fix for 'exclude from search' option
hunk authored
29 $option['exclude_from_search'] = ($option['exclude_from_search']) ? true : false;
2e014cc @hunk update
hunk authored
30 $option['labels'] = $p['label'];
31
32
33 if( isset($p['support']) ){
34 foreach($p['support'] as $k => $v){
35 $option['supports'][] = $k;
36 }
37 }
38
39 if( isset($p['taxonomy']) ){
40 foreach($p['taxonomy'] as $k => $v){
41 //register_taxonomy_for_object_type($k, $name);
42 $option['taxonomies'][] = $k;
43 }
44 }
ad4fcd6 @leocaseiro Fixed Notice: Undefined index: in has_archive mf_register.php on line 45
leocaseiro authored
45 if(isset($option['has_archive']) && $option['has_archive'] && isset($option['has_archive_slug']) && $option['has_archive_slug'])
faee6ab @hunk flush in rewrite rules
hunk authored
46 $option['has_archive'] = $option['has_archive_slug'];
47
48
2e014cc @hunk update
hunk authored
49 if($option['rewrite'] && $option['rewrite_slug'])
54a9731 @hunk fix in order for post type, and add Capabilities
hunk authored
50 $option['rewrite'] = array( 'slug' => $option['rewrite_slug'],'with_front' => true );
2e014cc @hunk update
hunk authored
51
52
53 unset($option['rewrite_slug']);
8a6cf3f @hunk add function $this->flash
hunk authored
54 array_push($mf_pt_register,$name);
54a9731 @hunk fix in order for post type, and add Capabilities
hunk authored
55
56 if($option['menu_position']){
57 $option['menu_position'] = (int)$option['menu_position'];
58 }
59
60 //check Capability type
61 trim($option['capability_type']);
62 if(empty($option['capability_type'])){
63 $option['capability_type'] = 'post';
64 }elseif( !in_array($option['capability_type'],array('post','page')) ){
0f441a4 @hunk move cap in save post type, add export post type
hunk authored
65 $option['capabilities'] = $this->_get_cap($option['capability_type']);
54a9731 @hunk fix in order for post type, and add Capabilities
hunk authored
66 }
530a01f @hunk fixes
hunk authored
67
68 //description
69 $option['description'] = $p['core']['description'];
2e014cc @hunk update
hunk authored
70 register_post_type($name,$option);
0f441a4 @hunk move cap in save post type, add export post type
hunk authored
71
2e014cc @hunk update
hunk authored
72 }
fb7470a @hunk add options in nw field
hunk authored
73
2e014cc @hunk update
hunk authored
74 }
75
0f441a4 @hunk move cap in save post type, add export post type
hunk authored
76 public function _get_cap($name){
54a9731 @hunk fix in order for post type, and add Capabilities
hunk authored
77
78 $caps = array(
79 'edit_post' => sprintf('edit_%s',$name),
0f441a4 @hunk move cap in save post type, add export post type
hunk authored
80 'read_post' => sprintf('read_%s',$name),
54a9731 @hunk fix in order for post type, and add Capabilities
hunk authored
81 'delete_post' => sprintf('delete_%s',$name),
0f441a4 @hunk move cap in save post type, add export post type
hunk authored
82 'edit_posts' => sprintf('edit_%ss',$name),
83 'edit_others_posts' => sprintf('edit_others_%ss',$name),
84 'publish_posts' => sprintf('publish_%ss',$name),
85 'read_private_posts' => sprintf('read_private_%ss',$name)
54a9731 @hunk fix in order for post type, and add Capabilities
hunk authored
86 );
87
0f441a4 @hunk move cap in save post type, add export post type
hunk authored
88 return $caps;
54a9731 @hunk fix in order for post type, and add Capabilities
hunk authored
89 }
90
2e014cc @hunk update
hunk authored
91 public function mf_register_custom_taxonomies(){
92
93 $taxonomies = $this->_get_custom_taxonomies();
94 foreach($taxonomies as $tax){
1362832 @hunk replace json_encode for serialize
hunk authored
95 $tax = unserialize($tax['arguments']);
48ff0f5 @hunk add validation in custom taxonomy
hunk authored
96 $name = $tax['core']['type'];
2e014cc @hunk update
hunk authored
97 $option = $tax['option'];
f08c22b @hunk Fix en notice for register custom taxonomy
hunk authored
98
99 $option['show_in_nav_menus'] = ($option['show_in_nav_menus']) ? true : false;
2e014cc @hunk update
hunk authored
100 $option['query_var'] = ($option['query_var']) ? true : false;
101
102
103 if( !$option['update_count_callback'] ){
104 unset($option['update_count_callback']);
105 }
106 $option['labels'] = $tax['label'];
107 $in = $tax['post_types'];
108
109 if($option['rewrite'] && $option['rewrite_slug'])
110 $option['rewrite'] = array( 'slug' => $option['rewrite_slug'] );
111
112 unset($option['rewrite_slug']);
113 register_taxonomy($name,$in, $option);
114 }
115
116 }
117
118 /**
119 * return all post types
120 */
121 private function _get_post_types(){
122 global $wpdb;
123
124 $query = sprintf('SELECT * FROM %s ORDER BY id',MF_TABLE_POSTTYPES);
125 $posttypes = $wpdb->get_results( $query, ARRAY_A );
126 return $posttypes;
127 }
128
129 /**
130 * return all custom_taxonomy
131 */
132 private function _get_custom_taxonomies(){
133 global $wpdb;
134
135 $query = sprintf('SELECT * FROM %s ORDER BY id',MF_TABLE_CUSTOM_TAXONOMY);
136 $custom_taxonomies = $wpdb->get_results( $query, ARRAY_A );
137 return $custom_taxonomies;
138 }
139 }
Something went wrong with that request. Please try again.