Skip to content

Instantly share code, notes, and snippets.

View anthonybudd's full-sized avatar

Anthony C. Budd anthonybudd

View GitHub Profile
<?php
WP_Route::get('/', function(){
return "Hello World."
});
WP_Route::get('/flights', 'flights'); // flights()
WP_Route::post('/flights/{flight}', 'singleFlight'); // singleFlight($flight)
WP_Route::put('/flights/{flight}/book/{date}', 'bookFlight');
WP_Route::delete('/flights/{flight}/delete', 'deleteFlight');
public static function fieldsCallback(){
$this_ = Self::newWithoutConstructor();
if(method_exists($this_, 'cmb2Fields')){
$fields = $this_->cmb2Fields();
if(function_exists('new_cmb2_box') && is_array($fields)){
if(!isset($fields['meta_box'])){
$fields['meta_box'] = [
'id' => get_called_class(),
<?php
WP_Route::redirect('open-google', 'https://google.com', 301);
<?php
WP_Route::match(['get', 'post'], 'flights/{flight}/confirm', 'confirmFlight');
function confirmFlight($flight){
// Your Code Here
}
<?php
WP_Route::get('flights', 'listFlights');
WP_Route::post('flights/{flight}', array('FlightController', 'singleFlight'));
function listFlights(){
// Your Code Here
}
Class FlightController{
<?php
WP_Route::get('flights/{flight}', 'singleFlight');
// http://example.com/flights/1
function singleFlight($flight){
echo $flight; // 1
// Your Code Here!
<?php
WP_Route::get('flights', 'listFlights');
// http://example.com/flights
function listFlights(){
// Your Code Here!
}
<?php
Class ExampleCronEvent extends WP_Cron{
public $every = [
'seconds' => 30,
'minutes' => 15,
'hours' => 1,
];
<?php
Class ExampleAction extends WP_AJAX{
protected $action = 'example-action';
protected function run(){
if($this->has('name')){
update_option('name', $this->get('name'));
<?php
Class Product extends WP_Model{
public $postType = 'product';
public $attributes = [
'color',
'weight'
];
}
Product::register();