-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-type.php
More file actions
172 lines (155 loc) · 3.99 KB
/
post-type.php
File metadata and controls
172 lines (155 loc) · 3.99 KB
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
<?php
/**
* Returns all public post types.
*
* format: post_type => Post Type Label.
*
* @version 1.0.0
*
* @return array Array with public post types
*/
function wppj_get_post_types() {
$post_types = array();
$post_types_obj = get_post_types( array( 'public' => true ), 'objects', 'and' );
foreach ( (array) $post_types_obj as $key => $value ) {
$post_types[ $key ] = esc_attr( $value->labels->menu_name );
}
return $post_types;
}
/**
* Get the post types for parsing JSON files.
*
* Adds labels for phpdoc parser post types (back compat)
*
* @param array $post_types Array with post types.
* @return array Array with post types.
*/
function wppj_get_json_post_types( $post_types ) {
$phpdoc_post_types = wppj_get_phpdoc_parser_post_types();
foreach ( $post_types as $key => $value ) {
if ( wppj_is_phpdoc_parser_post_type( $key ) ) {
$phpdoc_key = array_search( $key, $phpdoc_post_types );
if ( false !== $phpdoc_key ) {
unset( $post_types[ $key ] );
$post_types[ $phpdoc_key ] = $key;
continue;
}
}
$post_types[ $key ] = $key;
}
return $post_types;
}
/**
* Returns phpdoc parser post types
*
* format: slug => post_type
*
* @version 1.0.0
*
* @return array Array with phpdoc parser post types.
*/
function wppj_get_phpdoc_parser_post_types() {
return array(
'functions' => 'wp-parser-function',
'hooks' => 'wp-parser-hook',
'classes' => 'wp-parser-class',
'methods' => 'wp-parser-method',
);
}
/**
* Returns phpdoc parser hook type slugs
*
* @version 1.0.0
*
* @return array Array with phpdoc parser hook types.
*/
function wppj_get_phpdoc_parser_hook_types() {
return array( 'actions', 'filters' );
}
/**
* Returns parsed WordPress version.
*
* @version 1.0.0
*
* @return string WordPress version
*/
function wppj_get_phpdoc_parser_version() {
global $wp_version;
if ( function_exists( 'DevHub\get_current_version' ) ) {
return DevHub\get_current_version();
}
$current_version = get_option( 'wp_parser_imported_wp_version' );
if ( ! empty( $current_version ) ) {
return $current_version;
}
return $wp_version;
}
/**
* Checks if a post type is a phpdoc parser post type.
*
* @version 1.0.0
*
* @param string $post_type Post Type.
* @return bool True if it's a phpdoc parser post type.
*/
function wppj_is_phpdoc_parser_post_type( $post_type ) {
$phpdoc_post_types = wppj_get_phpdoc_parser_post_types();
if ( in_array( $post_type, array_values( $phpdoc_post_types ) ) ) {
return true;
}
return false;
}
/**
* Checks if **all** of the post types from WP parser exist.
*
* @version 1.0.0
*
* @return bool Returns false if one or more of the post types are missing.
*/
function wppj_phpdoc_parser_post_types_exists() {
$post_types = wppj_get_phpdoc_parser_post_types();
foreach ( $post_types as $type => $post_type ) {
if ( ! post_type_exists( $post_type ) ) {
return false;
}
}
return true;
}
/**
* Checks if a hook reference type slug is a duplicate.
*
* @version 1.0.0
*
* @param string $ref_type WP Parser type of reference.
* @param string $post_name Post slug.
* @return boolean True if slug has "-{$int}"" appended to slug.
*/
function wppj_is_hook_duplicate( $ref_type, $post_name ) {
$return = false;
$hook_types = wppj_get_phpdoc_parser_hook_types();
if ( in_array( $ref_type, $hook_types ) || ( 'hooks' === $ref_type ) ) {
// match -number at end of slug
if ( preg_match( '/\-\d+$/', $post_name ) ) {
$return = true;
}
}
return $return;
}
/**
* Checks if a function, hook, action, filter or class is deprecated.
*
* @version 1.0.0
*
* @param int $post_id Post ID
* @return boolean Returns true if a function, hook or class is deprecated.
*/
function wppj_is_deprecated( $post_id ) {
$return = false;
$source_file_object = wp_get_post_terms( $post_id, 'wp-parser-source-file', array( 'fields' => 'names' ) );
if ( isset( $source_file_object[0] ) && $source_file_object[0] ) {
if ( false !== strpos( $source_file_object[0], 'deprecated' ) ) {
$return = true;
}
}
return $return;
}