@@ 55-112 (lines=58) @@ | ||
52 | } |
|
53 | break; |
|
54 | case 'delete_post': |
|
55 | case 'delete_page': |
|
56 | $post = get_post( $args[0] ); |
|
57 | if ( ! $post ) { |
|
58 | $caps[] = 'do_not_allow'; |
|
59 | break; |
|
60 | } |
|
61 | ||
62 | if ( 'revision' == $post->post_type ) { |
|
63 | $post = get_post( $post->post_parent ); |
|
64 | if ( ! $post ) { |
|
65 | $caps[] = 'do_not_allow'; |
|
66 | break; |
|
67 | } |
|
68 | } |
|
69 | ||
70 | $post_type = get_post_type_object( $post->post_type ); |
|
71 | if ( ! $post_type ) { |
|
72 | /* translators: 1: post type, 2: capability name */ |
|
73 | _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
74 | $caps[] = 'edit_others_posts'; |
|
75 | break; |
|
76 | } |
|
77 | ||
78 | if ( ! $post_type->map_meta_cap ) { |
|
79 | $caps[] = $post_type->cap->$cap; |
|
80 | // Prior to 3.1 we would re-call map_meta_cap here. |
|
81 | if ( 'delete_post' == $cap ) |
|
82 | $cap = $post_type->cap->$cap; |
|
83 | break; |
|
84 | } |
|
85 | ||
86 | // If the post author is set and the user is the author... |
|
87 | if ( $post->post_author && $user_id == $post->post_author ) { |
|
88 | // If the post is published or scheduled... |
|
89 | if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
90 | $caps[] = $post_type->cap->delete_published_posts; |
|
91 | } elseif ( 'trash' == $post->post_status ) { |
|
92 | $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
93 | if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
94 | $caps[] = $post_type->cap->delete_published_posts; |
|
95 | } else { |
|
96 | $caps[] = $post_type->cap->delete_posts; |
|
97 | } |
|
98 | } else { |
|
99 | // If the post is draft... |
|
100 | $caps[] = $post_type->cap->delete_posts; |
|
101 | } |
|
102 | } else { |
|
103 | // The user is trying to edit someone else's post. |
|
104 | $caps[] = $post_type->cap->delete_others_posts; |
|
105 | // The post is published or scheduled, extra cap required. |
|
106 | if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
107 | $caps[] = $post_type->cap->delete_published_posts; |
|
108 | } elseif ( 'private' == $post->post_status ) { |
|
109 | $caps[] = $post_type->cap->delete_private_posts; |
|
110 | } |
|
111 | } |
|
112 | break; |
|
113 | // edit_post breaks down to edit_posts, edit_published_posts, or |
|
114 | // edit_others_posts |
|
115 | case 'edit_post': |
|
@@ 116-173 (lines=58) @@ | ||
113 | // edit_post breaks down to edit_posts, edit_published_posts, or |
|
114 | // edit_others_posts |
|
115 | case 'edit_post': |
|
116 | case 'edit_page': |
|
117 | $post = get_post( $args[0] ); |
|
118 | if ( ! $post ) { |
|
119 | $caps[] = 'do_not_allow'; |
|
120 | break; |
|
121 | } |
|
122 | ||
123 | if ( 'revision' == $post->post_type ) { |
|
124 | $post = get_post( $post->post_parent ); |
|
125 | if ( ! $post ) { |
|
126 | $caps[] = 'do_not_allow'; |
|
127 | break; |
|
128 | } |
|
129 | } |
|
130 | ||
131 | $post_type = get_post_type_object( $post->post_type ); |
|
132 | if ( ! $post_type ) { |
|
133 | /* translators: 1: post type, 2: capability name */ |
|
134 | _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
135 | $caps[] = 'edit_others_posts'; |
|
136 | break; |
|
137 | } |
|
138 | ||
139 | if ( ! $post_type->map_meta_cap ) { |
|
140 | $caps[] = $post_type->cap->$cap; |
|
141 | // Prior to 3.1 we would re-call map_meta_cap here. |
|
142 | if ( 'edit_post' == $cap ) |
|
143 | $cap = $post_type->cap->$cap; |
|
144 | break; |
|
145 | } |
|
146 | ||
147 | // If the post author is set and the user is the author... |
|
148 | if ( $post->post_author && $user_id == $post->post_author ) { |
|
149 | // If the post is published or scheduled... |
|
150 | if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
151 | $caps[] = $post_type->cap->edit_published_posts; |
|
152 | } elseif ( 'trash' == $post->post_status ) { |
|
153 | $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
154 | if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
155 | $caps[] = $post_type->cap->edit_published_posts; |
|
156 | } else { |
|
157 | $caps[] = $post_type->cap->edit_posts; |
|
158 | } |
|
159 | } else { |
|
160 | // If the post is draft... |
|
161 | $caps[] = $post_type->cap->edit_posts; |
|
162 | } |
|
163 | } else { |
|
164 | // The user is trying to edit someone else's post. |
|
165 | $caps[] = $post_type->cap->edit_others_posts; |
|
166 | // The post is published or scheduled, extra cap required. |
|
167 | if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
168 | $caps[] = $post_type->cap->edit_published_posts; |
|
169 | } elseif ( 'private' == $post->post_status ) { |
|
170 | $caps[] = $post_type->cap->edit_private_posts; |
|
171 | } |
|
172 | } |
|
173 | break; |
|
174 | case 'read_post': |
|
175 | case 'read_page': |
|
176 | $post = get_post( $args[0] ); |