jetpack_kickstarter_embed_to_shortcode

Converts Kickstarter iframe embeds to a shortcode.

Description

(string) jetpack_kickstarter_embed_to_shortcode( (string) $content ); 

EG:

Returns (string)

Parameters (1)

0. $content (string)
Entry content that possibly includes a Kickstarter embed.

Usage

  1. if ( !function_exists( 'jetpack_kickstarter_embed_to_shortcode' ) ) { 
  2. require_once '/modules/shortcodes/kickstarter.php'; 
  3.  
  4. // Entry content that possibly includes a Kickstarter embed. 
  5. $content = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jetpack_kickstarter_embed_to_shortcode($content); 
  9.  

Defined (1)

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

/modules/shortcodes/kickstarter.php  
  1. function jetpack_kickstarter_embed_to_shortcode( $content ) { 
  2. if ( ! is_string( $content ) || false === stripos( $content, 'www.kickstarter.com/projects' ) ) { 
  3. return $content; 
  4.  
  5. $regexp = '!<iframe((?:\s+\w+=[\'"][^\'"]*[\'"])*)\s+src=[\'"](http://www\.kickstarter\.com/projects/[^/]+/[^/]+)/[^\'"]+[\'"]((?:\s+\w+=[\'"][^\'"]*[\'"])*)>[\s]*</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. $url = esc_url( $match[2] ); 
  14.  
  15. $params = $match[1] . $match[3]; 
  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.  
  24. $shortcode = '[kickstarter url=' . $url . ( ( ! empty( $width ) ) ? " width=$width" : '' ) . ']'; 
  25. $content = str_replace( $match[0], $shortcode, $content ); 
  26.  
  27. return $content;