Skip to content

Instantly share code, notes, and snippets.

View collegeman's full-sized avatar

Aaron Collegeman collegeman

View GitHub Profile
@collegeman
collegeman / routes.php
Last active December 2, 2016 20:01
What routing looks like in an Illuminated WordPress Plugin
<?php
// in your plugin's src/routes.php file
$router->rewrite('/some/arbitrary/url/{slug}', function($slug) {
// you can do anything here
update_option('option_name', $slug);
// if you return false, the request is over
//return false;
// if you return a string, WordPress will try to load a template by that name
return 'my-custom-template';
@collegeman
collegeman / plugin.php
Created December 2, 2016 19:36
A more powerful example of what you can do with an Illuminated WordPress Plugin
<?php
namespace YourPlugin;
use YourPlugin\Notifications\PostSaved;
/**
* Your plugin inherits everything that a Laravel container can do.
* Like, sending messages on Slack using Laravel's Notification framework.
*/
class YourPlugin extends \FatPanda\Illuminate\WordPress\Plugin
{
/**
@collegeman
collegeman / plugin.php
Created December 2, 2016 19:13
A useless but illustrative example of what an Illuminated WordPress Plugin looks like
<?php
namespace YourPlugin;
/**
* Your plugin inherits everything that a Laravel container can do.
* Like, querying a database, which is useless, but illustrative.
*/
class YourPlugin extends \FatPanda\Illuminate\WordPress\Plugin
{
/**
* This function is automatically discovered and hooked
@collegeman
collegeman / hypothetical-routing-syntax.php
Last active December 1, 2016 21:58
Hypothetical, simpler example of routing in WordPress.
<?php
$app->get('/author/{id}', function($id) {
$posts = get_posts( array(
'author' => $id,
) );
if ( empty( $posts ) ) {
return null;
}
@collegeman
collegeman / endpoint.php
Created December 1, 2016 21:55
Defining a custom REST API endpoint in WordPress
<?php
/**
* Grab latest post title by an author!
*
* @param array $data Options for the function.
* @return string|null Post title for the latest,
 * or null if none.
*/
function my_awesome_func( $data ) {
$posts = get_posts( array(
'author' => $data['id'],
@collegeman
collegeman / routes.php
Created December 1, 2016 21:52
Defining a route in Laravel or Lumen
<?php
$app->get('/foo/{var}', function($var) {
// do something with $var
return 'result';
});
@collegeman
collegeman / workbench-todos.md
Last active November 26, 2016 21:48
What do we want to be able to do with WorkBench?

What do we want to be able to do with WorkBench?

WP-CLI extensions:

  • wp plugin create {plugin-folder-name}

    Should invoke FatPanda\WordPress\PluginWorkbench::createPlugin to start interactive plugin wizard

  • wp plugin create-controller {plugin-folder-name} {ControllerName} [{PhpNamespace}]

[2016-11-14 16:43:08] lumen.ERROR: BadMethodCallException: Method shuffle does not exist. in /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/support/Traits/Macroable.php:52
Stack trace:
#0 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Connectors/ConnectionFactory.php(123): Illuminate\Support\Arr::__callStatic('shuffle', Array)
#1 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
#2 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Connection.php(964): call_user_func(Object(Closure))
#3 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Connection.php(832): Illuminate\Database\Connection->getPdo()
#4 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Connection.php(717): Illuminate\Database\Connection->reconnectIfMissingConnection()
#5 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Co
[2016-11-14 16:43:08] lumen.ERROR: BadMethodCallException: Method shuffle does not exist. in /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/support/Traits/Macroable.php:52
Stack trace:
#0 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Connectors/ConnectionFactory.php(123): Illuminate\Support\Arr::__callStatic('shuffle', Array)
#1 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
#2 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Connection.php(964): call_user_func(Object(Closure))
#3 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Connection.php(832): Illuminate\Database\Connection->getPdo()
#4 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Connection.php(717): Illuminate\Database\Connection->reconnectIfMissingConnection()
#5 /home/forge/giftedhire.com/releases/20161114164047/vendor/illuminate/database/Co
@collegeman
collegeman / Handler.php
Last active September 5, 2022 06:59
Boilerplated files for Lumen-based WordPress plugins
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;