Skip to content

Commit

Permalink
hook in when cmb2_ajax function is called. Also hook in when a oembed…
Browse files Browse the repository at this point in the history
… field is added
  • Loading branch information
jtsternberg committed Feb 8, 2016
1 parent a17c726 commit d4dc402
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions includes/CMB2.php
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,11 @@ public function add_field( array $field, $position = 0 ) {
return false;
}

if ( 'oembed' === $field['type'] ) {
// Initiate oembed Ajax hooks
cmb2_ajax();
}

$this->_add_field_to_array(
$field,
$this->meta_box['fields'],
Expand Down
23 changes: 23 additions & 0 deletions includes/CMB2_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ class CMB2_Ajax {
protected $object_type = 'post';
protected $ajax_update = false;

/**
* Constructor
* @since 2.2.0
*/
public function __construct() {
self::hooks( $this );
}

/**
* Hook in the oembed ajax handlers
* @since 2.2.0
* @param CMB2_Ajax $self This object (for hooking)
*/
public static function hooks( $self ) {
static $hooked = false;

if ( ! $hooked ) {
add_action( 'wp_ajax_cmb2_oembed_handler', array( $self, 'oembed_handler' ) );
add_action( 'wp_ajax_nopriv_cmb2_oembed_handler', array( $self, 'oembed_handler' ) );
$hooked = true;
}
}

/**
* Handles our oEmbed ajax request
* @since 0.9.5
Expand Down
4 changes: 0 additions & 4 deletions includes/CMB2_hookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ public function __construct( CMB2 $cmb ) {
}

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 );
}
Expand Down

0 comments on commit d4dc402

Please sign in to comment.