Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
16 | class acf_field_image extends acf_field { |
||
17 | |||
18 | |||
19 | /* |
||
20 | * __construct |
||
21 | * |
||
22 | * This function will setup the field type data |
||
23 | * |
||
24 | * @type function |
||
25 | * @date 5/03/2014 |
||
26 | * @since 5.0.0 |
||
27 | * |
||
28 | * @param n/a |
||
29 | * @return n/a |
||
30 | */ |
||
|
|||
31 | |||
32 | function __construct() { |
||
68 | |||
69 | |||
70 | /* |
||
71 | * render_field() |
||
72 | * |
||
73 | * Create the HTML interface for your field |
||
74 | * |
||
75 | * @param $field - an array holding all the field's data |
||
76 | * |
||
77 | * @type action |
||
78 | * @since 3.6 |
||
79 | * @date 23/01/13 |
||
80 | */ |
||
81 | |||
82 | function render_field( $field ) { |
||
155 | |||
156 | |||
157 | /* |
||
158 | * render_field_settings() |
||
159 | * |
||
160 | * Create extra options for your field. This is rendered when editing a field. |
||
161 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
||
162 | * |
||
163 | * @type action |
||
164 | * @since 3.6 |
||
165 | * @date 23/01/13 |
||
166 | * |
||
167 | * @param $field - an array holding all the field's data |
||
168 | */ |
||
169 | |||
170 | function render_field_settings( $field ) { |
||
307 | |||
308 | |||
309 | /* |
||
310 | * format_value() |
||
311 | * |
||
312 | * This filter is appied to the $value after it is loaded from the db and before it is returned to the template |
||
313 | * |
||
314 | * @type filter |
||
315 | * @since 3.6 |
||
316 | * @date 23/01/13 |
||
317 | * |
||
318 | * @param $value (mixed) the value which was loaded from the database |
||
319 | * @param $post_id (mixed) the $post_id from which the value was loaded |
||
320 | * @param $field (array) the field array holding all the field options |
||
321 | * |
||
322 | * @return $value (mixed) the modified value |
||
323 | */ |
||
324 | |||
325 | View Code Duplication | function format_value( $value, $post_id, $field ) { |
|
363 | |||
364 | |||
365 | /* |
||
366 | * get_media_item_args |
||
367 | * |
||
368 | * description |
||
369 | * |
||
370 | * @type function |
||
371 | * @date 27/01/13 |
||
372 | * @since 3.6.0 |
||
373 | * |
||
374 | * @param $vars (array) |
||
375 | * @return $vars |
||
376 | */ |
||
377 | |||
378 | function get_media_item_args( $vars ) { |
||
384 | |||
385 | |||
386 | /* |
||
387 | * image_size_names_choose |
||
388 | * |
||
389 | * @description: |
||
390 | * @since: 3.5.7 |
||
391 | * @created: 13/01/13 |
||
392 | */ |
||
393 | |||
394 | /* |
||
395 | function image_size_names_choose( $sizes ) |
||
396 | { |
||
397 | global $_wp_additional_image_sizes; |
||
398 | |||
399 | if( $_wp_additional_image_sizes ) |
||
400 | { |
||
401 | foreach( $_wp_additional_image_sizes as $k => $v ) |
||
402 | { |
||
403 | $title = $k; |
||
404 | $title = str_replace('-', ' ', $title); |
||
405 | $title = str_replace('_', ' ', $title); |
||
406 | $title = ucwords( $title ); |
||
407 | |||
408 | $sizes[ $k ] = $title; |
||
409 | } |
||
410 | // foreach( $image_sizes as $image_size ) |
||
411 | } |
||
412 | |||
413 | return $sizes; |
||
414 | } |
||
415 | */ |
||
416 | |||
417 | |||
418 | /* |
||
419 | * wp_prepare_attachment_for_js |
||
420 | * |
||
421 | * this filter allows ACF to add in extra data to an attachment JS object |
||
422 | * This sneaky hook adds the missing sizes to each attachment in the 3.5 uploader. |
||
423 | * It would be a lot easier to add all the sizes to the 'image_size_names_choose' filter but |
||
424 | * then it will show up on the normal the_content editor |
||
425 | * |
||
426 | * @type function |
||
427 | * @since: 3.5.7 |
||
428 | * @date 13/01/13 |
||
429 | * |
||
430 | * @param {int} $post_id |
||
431 | * @return {int} $post_id |
||
432 | */ |
||
433 | |||
434 | function wp_prepare_attachment_for_js( $response, $attachment, $meta ) { |
||
475 | |||
476 | |||
477 | /* |
||
478 | * update_value() |
||
479 | * |
||
480 | * This filter is appied to the $value before it is updated in the db |
||
481 | * |
||
482 | * @type filter |
||
483 | * @since 3.6 |
||
484 | * @date 23/01/13 |
||
485 | * |
||
486 | * @param $value - the value which will be saved in the database |
||
487 | * @param $post_id - the $post_id of which the value will be saved |
||
488 | * @param $field - the field array holding all the field options |
||
489 | * |
||
490 | * @return $value - the modified value |
||
491 | */ |
||
492 | |||
493 | View Code Duplication | function update_value( $value, $post_id, $field ) { |
|
514 | |||
515 | |||
516 | } |
||
517 | |||
523 |
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.