Conditions | 13 |
Paths | 24 |
Total Lines | 108 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
112 | function wp_post_revision_fields( $return ) { |
||
113 | |||
114 | |||
115 | //globals |
||
116 | global $post, $pagenow; |
||
117 | |||
118 | |||
119 | // validate |
||
120 | $allowed = false; |
||
121 | |||
122 | |||
123 | // Normal revisions page |
||
124 | if( $pagenow == 'revision.php' ) |
||
125 | { |
||
126 | $allowed = true; |
||
127 | } |
||
128 | |||
129 | |||
130 | // WP 3.6 AJAX revision |
||
131 | if( $pagenow == 'admin-ajax.php' && isset($_POST['action']) && $_POST['action'] == 'get-revision-diffs' ) |
||
132 | { |
||
133 | $allowed = true; |
||
134 | } |
||
135 | |||
136 | |||
137 | // bail |
||
138 | if( !$allowed ) |
||
139 | { |
||
140 | return $return; |
||
141 | } |
||
142 | |||
143 | |||
144 | // vars |
||
145 | $post_id = 0; |
||
146 | |||
147 | |||
148 | // determine $post_id |
||
149 | if( isset($_POST['post_id']) ) |
||
150 | { |
||
151 | $post_id = $_POST['post_id']; |
||
152 | } |
||
153 | elseif( isset($post->ID) ) |
||
154 | { |
||
155 | $post_id = $post->ID; |
||
156 | } |
||
157 | else |
||
158 | { |
||
159 | return $return; |
||
160 | } |
||
161 | |||
162 | |||
163 | // setup global array |
||
164 | $GLOBALS['acf_revisions_fields'] = array(); |
||
165 | |||
166 | |||
167 | // get field objects |
||
168 | $custom_fields = get_post_custom( $post_id ); |
||
169 | |||
170 | |||
171 | // populate vars |
||
172 | if( !empty($custom_fields) ) |
||
173 | { |
||
174 | foreach( $custom_fields as $k => $v ) |
||
175 | { |
||
176 | // value is always an array |
||
177 | $v = $v[0]; |
||
178 | |||
179 | |||
180 | // bail early if $value is not is a field_key |
||
181 | if( !acf_is_field_key($v) ) |
||
182 | { |
||
183 | continue; |
||
184 | } |
||
185 | |||
186 | |||
187 | // remove prefix '_' field from reference |
||
188 | $field_name = substr($k, 1); |
||
189 | |||
190 | |||
191 | // get field |
||
192 | //$field = acf_get_field($v); |
||
193 | |||
194 | |||
195 | // append to return |
||
196 | $return[ $field_name ] = $field_name; |
||
197 | |||
198 | |||
199 | // load value |
||
200 | add_filter("_wp_post_revision_field_{$field_name}", array($this, 'wp_post_revision_field'), 10, 4); |
||
201 | |||
202 | |||
203 | // WP 3.5: left vs right |
||
204 | // Add a value of the revision ID (as there is no way to determine this within the '_wp_post_revision_field_' filter!) |
||
205 | if( isset($_GET['action'], $_GET['left'], $_GET['right']) && $_GET['action'] == 'diff' ) |
||
206 | { |
||
207 | global $left_revision, $right_revision; |
||
208 | |||
209 | $left_revision->$field_name = 'revision_id=' . $_GET['left']; |
||
210 | $right_revision->$field_name = 'revision_id=' . $_GET['right']; |
||
211 | } |
||
212 | |||
213 | } |
||
214 | } |
||
215 | |||
216 | |||
217 | return $return; |
||
218 | |||
219 | } |
||
220 | |||
359 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.