| Conditions | 31 |
| Paths | 3 |
| Total Lines | 47 |
| Code Lines | 35 |
| 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 |
||
| 5 | function jetpack_featured_images_remove_post_thumbnail( $metadata, $object_id, $meta_key, $single ) { |
||
| 6 | $opts = jetpack_featured_images_get_settings(); |
||
| 7 | |||
| 8 | // Automatically return metadata if it's a PayPal product - we don't want to hide the Featured Image. |
||
| 9 | if ( 'jp_pay_product' === get_post_type( $object_id ) ) { |
||
| 10 | return $metadata; |
||
| 11 | } |
||
| 12 | |||
| 13 | // Return false if the archive option or singular option is unticked. |
||
| 14 | if ( |
||
| 15 | ( true === $opts['archive'] |
||
| 16 | && ( is_home() || is_archive() || is_search() ) |
||
| 17 | && ! $opts['archive-option'] |
||
| 18 | && ( isset( $meta_key ) |
||
| 19 | && '_thumbnail_id' === $meta_key ) |
||
| 20 | && in_the_loop() |
||
| 21 | ) |
||
| 22 | || ( true === $opts['post'] |
||
| 23 | && is_single() |
||
| 24 | && ! jetpack_is_product() |
||
| 25 | && ! $opts['post-option'] |
||
| 26 | && ( isset( $meta_key ) |
||
| 27 | && '_thumbnail_id' === $meta_key ) |
||
| 28 | && in_the_loop() |
||
| 29 | ) |
||
| 30 | || ( true === $opts['page'] |
||
| 31 | && is_singular() |
||
| 32 | && is_page() |
||
| 33 | && ! $opts['page-option'] |
||
| 34 | && ( isset( $meta_key ) |
||
| 35 | && '_thumbnail_id' === $meta_key ) |
||
| 36 | && in_the_loop() |
||
| 37 | ) |
||
| 38 | || ( true === $opts['portfolio'] |
||
| 39 | && post_type_exists( 'jetpack-portfolio' ) |
||
| 40 | && is_singular( 'jetpack-portfolio' ) |
||
| 41 | && ! $opts['portfolio-option'] |
||
| 42 | && ( isset( $meta_key ) |
||
| 43 | && '_thumbnail_id' === $meta_key ) |
||
| 44 | && in_the_loop() |
||
| 45 | ) |
||
| 46 | ) { |
||
| 47 | return false; |
||
| 48 | } else { |
||
| 49 | return $metadata; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | add_filter( 'get_post_metadata', 'jetpack_featured_images_remove_post_thumbnail', true, 4 ); |
||
| 60 |