public function render() { $field = $this->field; $meta_value = trim($field->escaped_value()); $oembed = !empty($meta_value) ? cmb2_ajax()->get_oembed(array('url' => $field->escaped_value(), 'object_id' => $field->object_id, 'object_type' => $field->object_type, 'oembed_args' => array('width' => '640'), 'field_id' => $this->_id())) : ''; return parent::render(array('class' => 'cmb2-oembed regular-text', 'data-objectid' => $field->object_id, 'data-objecttype' => $field->object_type)) . '<p class="cmb-spinner spinner" style="display:none;"></p>' . '<div id="' . $this->_id('-status') . '" class="cmb2-media-status ui-helper-clearfix embed_wrap">' . $oembed . '</div>'; }
public function hooks() { // Handle oembed Ajax $this->once('wp_ajax_cmb2_oembed_handler', array(cmb2_ajax(), 'oembed_handler')); $this->once('wp_ajax_nopriv_cmb2_oembed_handler', array(cmb2_ajax(), 'oembed_handler')); foreach (get_class_methods('CMB2_Show_Filters') as $filter) { add_filter('cmb2_show_on', array('CMB2_Show_Filters', $filter), 10, 3); } }
public function universal_hooks() { // Handle oembed Ajax $this->once('wp_ajax_cmb2_oembed_handler', array(cmb2_ajax(), 'oembed_handler')); $this->once('wp_ajax_nopriv_cmb2_oembed_handler', array(cmb2_ajax(), 'oembed_handler')); foreach (get_class_methods('CMB2_Show_Filters') as $filter) { add_filter('cmb2_show_on', array('CMB2_Show_Filters', $filter), 10, 3); } if (is_admin()) { // register our scripts and styles for cmb $this->once('admin_enqueue_scripts', array(__CLASS__, 'register_scripts'), 8); } }
/** * Get a cmb oEmbed. Handles oEmbed getting for non-post objects * @since 2.0.0 * @param array $args 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. * * @return string oEmbed string */ function cmb2_get_oembed($args = array()) { $oembed = cmb2_ajax()->get_oembed_no_edit($args); // Send back our embed if ($oembed['embed'] && $oembed['embed'] != $oembed['fallback']) { return '<div class="cmb2-oembed">' . $oembed['embed'] . '</div>'; } $error = sprintf(__('No oEmbed Results Found for %s. View more info at %s.', 'cmb2'), $oembed['fallback'], ' <a href="http://codex.wordpress.org/Embeds" target="_blank">codex.wordpress.org/Embeds</a>'); if (isset($args['wp_error']) && $args['wp_error']) { return new WP_Error('cmb2_get_oembed_result', $wp_error, compact('oembed', 'args')); } // Otherwise, send back error info that no oEmbeds were found return '<p class="ui-state-error-text">' . $error . '</p>'; }
/** * Get a cmb oEmbed. Handles oEmbed getting for non-post objects * @since 2.0.0 * @param array $args 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, * * @return string oEmbed string */ function cmb2_get_oembed($args = array()) { return cmb2_ajax()->get_oembed($args); }
public function test_class_getters() { $this->assertInstanceOf('CMB2_Ajax', cmb2_ajax()); $this->assertInstanceOf('CMB2_Utils', cmb2_utils()); $this->assertInstanceOf('CMB2_Option', cmb2_options('test')); }
/** * Add a field to the metabox * @since 2.0.0 * @param array $field Metabox field config array * @param int $position (optional) Position of metabox. 1 for first, etc * @return mixed Field id or false */ public function add_field(array $field, $position = 0) { if (!is_array($field) || !array_key_exists('id', $field)) { return false; } if ('oembed' === $field['type']) { // Initiate oembed Ajax hooks cmb2_ajax(); } if (isset($field['column']) && false !== $field['column']) { $this->has_columns = true; $column = is_array($field['column']) ? $field['column'] : array(); $field['column'] = wp_parse_args($column, array('name' => isset($field['name']) ? $field['name'] : '', 'position' => false)); } $this->_add_field_to_array($field, $this->meta_box['fields'], $position); return $field['id']; }
/** * Add a field to the metabox * @since 2.0.0 * @param array $field Metabox field config array * @param int $position (optional) Position of metabox. 1 for first, etc * @return mixed Field id or false */ public function add_field(array $field, $position = 0) { if (!is_array($field) || !array_key_exists('id', $field)) { return false; } if ('oembed' === $field['type']) { // Initiate oembed Ajax hooks cmb2_ajax(); } $this->_add_field_to_array($field, $this->meta_box['fields'], $position); return $field['id']; }