Skip to content

Instantly share code, notes, and snippets.

@anthonybudd
Last active March 11, 2018 19:29
Show Gist options
  • Save anthonybudd/f42cb2722eb4876919f682a9a160c4ee to your computer and use it in GitHub Desktop.
Save anthonybudd/f42cb2722eb4876919f682a9a160c4ee to your computer and use it in GitHub Desktop.
<?php
Class ExampleAction extends WP_AJAX{
protected $action = 'example-action';
protected function run(){
if($this->has('name')){
update_option('name', $this->get('name'));
}
}
}
ExampleAction::listen();
ExampleAction::url(); // http://example.com/wp-admin/admin-ajax.php?action=example-action
ExampleAction::url(['name' => 'Anthony Budd']); // http://example.com/wp-admin/admin-ajax.php?action=example-action&name=Anthony%20Budd
// Example:
// <a href="<?= ExampleAction::url(['name' => 'Anthony Budd']) ?>">Link</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment