本文整理汇总了PHP中cmb2_ajax函数的典型用法代码示例。如果您正苦于以下问题:PHP cmb2_ajax函数的具体用法?PHP cmb2_ajax怎么用?PHP cmb2_ajax使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cmb2_ajax函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
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>';
}
示例2: hooks
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);
}
}
示例3: universal_hooks
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);
}
}
示例4: cmb2_get_oembed
/**
* 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>';
}
示例5: cmb2_get_oembed
/**
* 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);
}
示例6: test_class_getters
public function test_class_getters()
{
$this->assertInstanceOf('CMB2_Ajax', cmb2_ajax());
$this->assertInstanceOf('CMB2_Utils', cmb2_utils());
$this->assertInstanceOf('CMB2_Option', cmb2_options('test'));
}
示例7: add_field
/**
* 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'];
}
示例8: add_field
/**
* 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'];
}