Example #1
0
 /**
  * Handles our oEmbed ajax request
  * @since  0.9.5
  * @return object oEmbed embed code | fallback | error message
  */
 public function oembed_handler()
 {
     // verify our nonce
     if (!(isset($_REQUEST['cmb_ajax_nonce'], $_REQUEST['oembed_url']) && wp_verify_nonce($_REQUEST['cmb_ajax_nonce'], 'ajax_nonce'))) {
         die;
     }
     // sanitize our search string
     $oembed_string = sanitize_text_field($_REQUEST['oembed_url']);
     // send back error if empty
     if (empty($oembed_string)) {
         self::send_result('<p class="ui-state-error-text">' . __('Please Try Again', 'cmb') . '</p>', false);
     }
     // Set width of embed
     $embed_width = isset($_REQUEST['oembed_width']) && intval($_REQUEST['oembed_width']) < 640 ? intval($_REQUEST['oembed_width']) : '640';
     // set url
     $oembed_url = esc_url($oembed_string);
     // set args
     $embed_args = array('width' => $embed_width);
     self::$ajax_update = true;
     // Get embed code (or fallback link)
     $html = self::get_oembed($oembed_url, $_REQUEST['object_id'], array('object_type' => isset($_REQUEST['object_type']) ? $_REQUEST['object_type'] : 'post', 'oembed_args' => $embed_args, 'field_id' => $_REQUEST['field_id']));
     self::send_result($html);
 }