Skip to content

Instantly share code, notes, and snippets.

Last active Jul 29, 2016
What would you like to do?
namespace Acme\Admin;
class Ajax_Manager {
public function register( $object, $method ) {
array( $object, $method )
public function __construct( $ajax_manager ) {
// If options exist, then use them; otherwise, initialize an empty array.
$this->options =
get_option( 'acme-options' ) ?
get_option( 'acme-options' ) :
/* For this example, assume there is a default set of options called
* `$default_options` that are used whenever no options are present
* for the given options key above.
* Merge the arrays. The default options must go first so the existing
* options override the default options.
$this->options = array_merge( $default_options, $this->options );
* Assume that the options are composed of key/value pairs and we're
* only using the event options.
$event_partial = new Views\Partials\Event( $this->options['event'] );
// Tell the Ajax Messenger the event partial has an Ajax callback.
$ajax_manager->register( $event_partial, 'the_taxonomies' );
$submenu = new Display\Submenu(
new Display\Submenu_Page( new Admin\Ajax_Manager() )
var send_ajax_request = function( cpt_id ) {
// Define the function and the data to send to the server.
var data = {
'action': 'the_taxonomies',
'post_type': cpt_id
// Send the request to the server and handle the response.
$.post( ajaxurl, data, function( response ) {
// Handle your response here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment