Skip to content

Instantly share code, notes, and snippets.

View collegeman's full-sized avatar

Aaron Collegeman collegeman

View GitHub Profile
@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;
<?php
// open the JSON file
$json = json_decode(file_get_contents('cleveland-film-festival-2016.json'));
// open a file to put the CSV into
$outfile = fopen('cleveland-film-festival-2016.csv', 'w');
// loop over the JSON file, one film at a time
foreach($json as $film) {
// build an array from the film content
$out = [
$film->title,
@collegeman
collegeman / cleveland-international-film-festival-crawler-2016.js
Last active March 18, 2016 14:53
Paste into Chrome console, crawl films.
/*
To use this script, open Chrome and browse to
http://www.clevelandfilm.org/schedule
Open the JavaScript console (CMD + ALT + J on Mac), and
paste the whole script into the command line.
The script is asynchronous, meaning that when you run it,
it will appear to finish immediately, but in fact the
script makes one request for each film-like thing it finds
on the schedule page. You can see it running by clicking
on the Network tab of the debugger window (already open