Conditions | 14 |
Paths | 10 |
Total Lines | 59 |
Code Lines | 32 |
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 |
||
49 | function wpcom_shortcodereverse_getty( $content ) { |
||
50 | if ( ! is_string( $content ) || false === stripos( $content, 'embed.gettyimages.com/embed' ) ) { |
||
51 | return $content; |
||
52 | } |
||
53 | |||
54 | $regexp = '!<iframe\s+src=[\'"](https?:)?//embed\.gettyimages\.com/embed(/|/?\?assets=)(\d+(,\d+)*)[^\'"]*?[\'"]((?:\s+\w+=[\'"][^\'"]*[\'"])*)((?:[\s\w]*))></iframe>!i'; |
||
55 | $regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) ); |
||
56 | |||
57 | foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) { |
||
58 | if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) { |
||
59 | continue; |
||
60 | } |
||
61 | |||
62 | foreach ( $matches as $match ) { |
||
63 | $ids = esc_html( $match[3] ); |
||
64 | |||
65 | $params = $match[5]; |
||
66 | |||
67 | if ( 'regexp_ent' == $reg ) { |
||
68 | $params = html_entity_decode( $params ); |
||
69 | } |
||
70 | |||
71 | $params = wp_kses_hair( $params, array( 'http' ) ); |
||
72 | |||
73 | $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0; |
||
74 | $height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0; |
||
75 | |||
76 | $shortcode = '[getty src="' . esc_attr( $ids ) . '"'; |
||
77 | if ( $width ) { |
||
78 | $shortcode .= ' width="' . esc_attr( $width ) . '"'; |
||
79 | } |
||
80 | if ( $height ) { |
||
81 | $shortcode .= ' height="' . esc_attr( $height ) . '"'; |
||
82 | } |
||
83 | $shortcode .= ']'; |
||
84 | |||
85 | $content = str_replace( $match[0], $shortcode, $content ); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | // strip out enclosing div and any other markup |
||
90 | $regexp = '%<div class="getty\s[^>]*+>.*?<div[^>]*+>(\[getty[^\]]*+\])\s*</div>.*?</div>%is'; |
||
91 | $regexp_ent = str_replace( array( '&#0*58;', '[^>]' ), array( '&#0*58;|�*58;', '[^&]' ), htmlspecialchars( $regexp, ENT_NOQUOTES ) ); |
||
92 | |||
93 | foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) { |
||
94 | if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) { |
||
95 | continue; |
||
96 | } |
||
97 | |||
98 | foreach ( $matches as $match ) { |
||
99 | $content = str_replace( $match[0], $match[1], $content ); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | /** This action is documented in modules/widgets/social-media-icons.php */ |
||
104 | do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', 'getty' ); |
||
105 | |||
106 | return $content; |
||
107 | } |
||
108 | |||
139 |