pinterest_embed_handler

The WordPress Core pinterest embed handler function.

Description

pinterest_embed_handler( $matches, $attr, $url ); 

Parameters (3)

0. $matches
The matches.
1. $attr
The attr.
2. $url
The url.

Usage

  1. if ( !function_exists( 'pinterest_embed_handler' ) ) { 
  2. require_once '/modules/shortcodes/pinterest.php'; 
  3.  
  4. // The matches. 
  5. $matches = null; 
  6.  
  7. // The attr. 
  8. $attr = null; 
  9.  
  10. // The url. 
  11. $url = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = pinterest_embed_handler($matches, $attr, $url); 
  15.  

Defined (1)

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

/modules/shortcodes/pinterest.php  
  1. function pinterest_embed_handler( $matches, $attr, $url ) { 
  2. // Pinterest's JS handles making the embed 
  3. $script_src = '//assets.pinterest.com/js/pinit.js'; 
  4. wp_enqueue_script( 'pinterest-embed', $script_src, array(), false, true ); 
  5.  
  6. $path = parse_url( $url, PHP_URL_PATH ); 
  7. if ( 0 === strpos( $path, '/pin/' ) ) { 
  8. $embed_type = 'embedPin'; 
  9. } elseif ( preg_match( '#^/([^/]+)/?$#', $path ) ) { 
  10. $embed_type = 'embedUser'; 
  11. } elseif ( preg_match( '#^/([^/]+)/([^/]+)/?$#', $path ) ) { 
  12. $embed_type = 'embedBoard'; 
  13. } else { 
  14. if ( current_user_can( 'edit_posts' ) ) { 
  15. return __( 'Sorry, that Pinterest URL was not recognized.', 'jetpack' ); 
  16. return; 
  17.  
  18. $return = sprintf( '<a data-pin-do="%s" href="%s"></a>', esc_attr( $embed_type ), esc_url( $url ) ); 
  19.  
  20. // If we're generating an embed view for the WordPress Admin via ajax... 
  21. if ( doing_action( 'wp_ajax_parse-embed' ) ) { 
  22. $return .= sprintf( '<script src="%s"></script>', esc_url( $script_src ) ); 
  23.  
  24. return $return;