wpcom_shortcodereverse_getty

Compose shortcode based on Getty iframes.

Description

wpcom_shortcodereverse_getty( (string) $content ); 

Parameters (1)

0. $content (string)
The content.

Usage

  1. if ( !function_exists( 'wpcom_shortcodereverse_getty' ) ) { 
  2. require_once '/modules/shortcodes/getty.php'; 
  3.  
  4. // The content. 
  5. $content = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wpcom_shortcodereverse_getty($content); 
  9.  

Defined (1)

The function is defined in the following location(s).

/modules/shortcodes/getty.php  
  1. function wpcom_shortcodereverse_getty( $content ) { 
  2. if ( ! is_string( $content ) || false === stripos( $content, 'embed.gettyimages.com/embed' ) ) { 
  3. return $content; 
  4.  
  5. $regexp = '!<iframe\s+src=[\'"](https?:)?//embed\.gettyimages\.com/embed(/|/?\?assets=)(\d+(, \d+)*)[^\'"]*?[\'"]((?:\s+\w+=[\'"][^\'"]*[\'"])*)((?:[\s\w]*))></iframe>!i'; 
  6. $regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) ); 
  7.  
  8. foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) { 
  9. if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) { 
  10. continue; 
  11.  
  12. foreach ( $matches as $match ) { 
  13. $ids = esc_html( $match[3] ); 
  14.  
  15. $params = $match[5]; 
  16.  
  17. if ( 'regexp_ent' == $reg ) { 
  18. $params = html_entity_decode( $params ); 
  19.  
  20. $params = wp_kses_hair( $params, array( 'http' ) ); 
  21.  
  22. $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0; 
  23. $height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0; 
  24.  
  25. $shortcode = '[getty src="' . esc_attr( $ids ) . '"'; 
  26. if ( $width ) { 
  27. $shortcode .= ' width="' . esc_attr( $width ) . '"'; 
  28. if ( $height ) { 
  29. $shortcode .= ' height="' . esc_attr( $height ) . '"'; 
  30. $shortcode .= ']'; 
  31.  
  32. $content = str_replace( $match[0], $shortcode, $content ); 
  33.  
  34. // strip out enclosing div and any other markup 
  35. $regexp = '%<div class="getty\s[^>]*+>.*?<div[^>]*+>(\[getty[^\]]*+\])\s*</div>.*?</div>%is'; 
  36. $regexp_ent = str_replace( array( '&#0*58;', '[^>]' ), array( '&#0*58;|�*58;', '[^&]' ), htmlspecialchars( $regexp, ENT_NOQUOTES ) ); 
  37.  
  38. foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) { 
  39. if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) { 
  40. continue; 
  41.  
  42. foreach ( $matches as $match ) { 
  43. $content = str_replace( $match[0], $match[1], $content ); 
  44.  
  45. /** This action is documented in modules/widgets/social-media-icons.php */ 
  46. do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', 'getty' ); 
  47.  
  48. return $content;