cmb2_get_oembed

Get a cmb oEmbed.

Description

(string) cmb2_get_oembed( (array) $args = array() ); 

Handles oEmbed getting for non-post objects

Returns (string)

oEmbed string

Parameters (1)

0. $args — Optional. (array) => array()
Arguments. Accepts: url - URL to retrieve the oEmbed from, object_id, - $post_id, object_type - post, oembed_args - $embed_args, // array containing width, etc field_id - false, cache_key - false, wp_error - true/false, // To return a wp_error object if no embed found.

Usage

  1. if ( !function_exists( 'cmb2_get_oembed' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'cmb2/includes/helper-functions.php'; 
  3. $args = array(); 
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = cmb2_get_oembed($args); 
  7.  

Defined (1)

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

/includes/helper-functions.php  
  1. function cmb2_get_oembed( $args = array() ) { 
  2. $oembed =cmb2_ajax)->get_oembed_no_edit( $args ); 
  3.  
  4. // Send back our embed 
  5. if ( $oembed['embed'] && $oembed['embed'] != $oembed['fallback'] ) { 
  6. return '<div class="cmb2-oembed">' . $oembed['embed'] . '</div>'; 
  7.  
  8. $error = sprintf( 
  9. /** translators: 1: results for. 2: link to codex.wordpress.org/Embeds */ 
  10. esc_html__( 'No oEmbed Results Found for %1$s. View more info at %2$s.', cmb2 ),  
  11. $oembed['fallback'],  
  12. '<a href="https://codex.wordpress.org/Embeds" target="_blank">codex.wordpress.org/Embeds</a>' 
  13. ); 
  14.  
  15. if ( isset( $args[wp_error] ) && $args[wp_error] ) { 
  16. return new WP_Error( 'cmb2_get_oembed_result', $wp_error, compact( 'oembed', 'args' ) ); 
  17.  
  18. // Otherwise, send backerrorinfo that no oEmbeds were found 
  19. return '<p class="ui-state-error-text">' . $error . '</p>';