Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TypeRocket 3.0 - Unleash WordPress and Be Amazing

Kevin Dees
September 25, 2016

TypeRocket 3.0 - Unleash WordPress and Be Amazing

In this talk, we walk through version 3.0 of TypeRocket at WordCamp Raleigh 2016.

Kevin Dees

September 25, 2016
Tweet

More Decks by Kevin Dees

Other Decks in Programming

Transcript

  1. LETS CODE: PART 1 1. Post Types 2. Dashboard Meta

    Box 3. Taxonomy Custom Fields 4. Theme Options 5. Profile Fields
  2. // Make Post Type $person = tr_post_type('Person', 'Team'); // Set

    Icon $person->setIcon('users'); // Title Only $person->setArgument('supports', ['title'] ); // Set Placeholder Text $person->setTitlePlaceholder('Enter full name here');
  3. // Meta Box With Fields $box = tr_meta_box('Team Details')->apply($person); $box->setCallback(function()

    { $form = tr_form(); echo $form->text('Job Title'); }); // Taxonomy $dep = tr_taxonomy('Department')->apply($person);
  4. // Inline Fields $person->setTitleForm( function() { $form = tr_form(); echo

    $form->image('Photo'); // Save To Builtin Posts Table $editor = $form->editor('post_content'); echo $editor->setLabel('About Person'); } );
  5. class Person extends WPPost { protected $postType = 'person'; //

    Only save these fields protected $fillable = [ 'photo', 'post_content', 'job_title' ]; // Format photo as an integer protected $format = [ 'photo' => 'intval' ]; }
  6. <?php while( have_posts() ) : the_post(); ?> <?php // Image

    $img_id = tr_posts_field('photo'); echo wp_get_attachment_image($img_id, 'full'); ?> <h3><?php echo tr_posts_field('job_title'); ?></h3> <?php the_content(); ?> <?php endwhile; ?>
  7. // Remember The Taxonomy $dep = tr_taxonomy('Department')->apply($person); // Add Fields

    $dep->setMainForm(function() { $form = tr_form(); echo $form->text('Location'); });
  8. <h1>Theme Options</h1> <?php $form = new \TypeRocket\Elements\Form(); $form->useJson()->setGroup( $this->getName() );

    ?> <div class="typerocket-container"> <?php echo $form->open(); // Sections $about = $form->text('Company Name'); $api = $form->password( 'Google Maps API Key'); $save = $form->submit( 'Save' ); // Tabs tr_tabs() ->setSidebar( $save ) ->addTab( 'About', $about ) ->addTab( 'APIs', $api ) ->render( 'box' ); echo $form->close(); ?> </div>
  9. LETS CODE: PART 2 1. Page Builder 2. Custom Resource

    3. Kernel and Middleware 4. Front-end Fields and Routes
  10. CREATE TABLE `wp_seats` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,

    `persons_id` bigint(20) DEFAULT NULL, `number` varchar(255) DEFAULT NULL, `price` double(10,2) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  11. <?php namespace App\Controllers; use \TypeRocket\Controllers\Controller; class SeatController extends Controller {

    public function index() { } public function add() { } public function create() { } public function edit() { } public function update() { } public function destroy() { } }
  12. $table = tr_tables(); $table->setColumns('number', [ 'number' => [ 'sort' =>

    true, 'actions' => ['edit', 'view', 'delete'], 'label' => 'Seat Number' ], 'persons_id' => [ 'label' => 'Person', ], 'price' => [ 'label' => 'Price', ] ]); $table->render();
  13. ADD

  14. public function add() { $form = tr_form('seat', 'create'); return tr_view('seats.add',

    ['form' => $form]); } public function create() { $seat = new \App\Models\Seat(); $seat->number = $this->request->getFields('number'); $seat->price = $this->request->getFields('price'); $seat->persons_id = $this->request->getFields('persons_id'); $id = $seat->save(); // Redirect $this->response->flashNext('Seat created!'); return tr_redirect()->toPage('seat', 'edit', $id); }
  15. // resources/pages/seats/add.php echo $form->open(); echo $form->text('Number'); echo $form->text('Price'); // Search

    Field echo $form->search('persons_id') ->setLabel('Person') ->setPostType('person'); echo $form->submit('Add'); echo $form->close();
  16. public function edit($id) { $form = tr_form('seat', 'update', $id); return

    tr_view('seats.edit', ['form' => $form]); } public function update($id) { $seat = new \App\Models\Seat(); $seat->findOrDie($id); // Find or Die $seat->number = $this->request->getFields('number'); $seat->price = $this->request->getFields('price'); $seat->persons_id = $this->request->getFields('persons_id'); $seat->save(); // Redirect $this->response->flashNext('Seat updated!'); return tr_redirect()->back(); }
  17. <?php // resources/pages/seats/edit.php echo $form->open(); echo $form->text('Number'); echo $form->text('Price'); echo

    $form->search('persons_id') ->setLabel('Person') ->setPostType('person'); echo $form->submit('Update'); // changed echo $form->close();
  18. public function destroy($id) { $seat = new \App\Models\Seat(); $seat->findOrDie($id); $seat->delete();

    $this->response->setMessage('Seat Deleted: '.$seat->number); return tr_redirect()->back(); }
  19. class Seat extends Model { protected $resource = 'seats'; //

    Belongs To Person public function person() { return $this->belongsTo( Person::class, 'persons_id' ); } }
  20. class Person extends WPPost { protected $postType = 'person'; //

    ... public function seats() { return $this->hasMany( Seat::class, 'persons_id' ); } }
  21. public function show($id) { $seat = new \App\Models\Seat(); $seat->findOrDie($id); $person

    = $seat->person()->get(); return tr_view('seats.show', compact('seat', 'person')); }
  22. <h3>Seat Number <?php echo $seat->number; ?></h3> <p>Price: $<?php echo $seat->price;

    ?></p> <p>Person's Name: <?php echo $person->post_title; ?></p>
  23. class Kernel extends \TypeRocket\Http\Kernel { protected $middleware = [ 'hookGlobal'

    => [ AuthRead::class ], 'resourceGlobal' => [ AuthRead::class, Middleware\VerifyNonce::class ], 'noResource' => [ AuthAdmin::class ], 'user' => [ IsUserOrCanEditUsers::class ], 'post' => [ OwnsPostOrCanEditPosts::class ], // ... 'tag' => [ CanManageCategories::class ] ]; }
  24. class Kernel extends \TypeRocket\Http\Kernel { protected $middleware = [ //

    ... 'person' => [ OwnsPostOrCanEditPosts::class ], 'seat' => [ AuthAdmin::class ] ]; }
  25. <?php namespace App\Http\Middleware; use \TypeRocket\Http\Middleware\Middleware; class Example extends Middleware {

    public function handle() { $request = $this->request; $response = $this->response; // Do stuff before controller is called $this->next->handle(); // Do stuff after controller is called } }
  26. <?php class Example extends Middleware { public function handle() {

    $request = $this->request; $response = $this->response; $response->exitNotFound(); // Doing Stuff $this->next->handle(); } }
  27. class Kernel extends \TypeRocket\Http\Kernel { protected $middleware = [ //

    ... 'seat' => [ AuthAdmin::class, Middleware\Example::class ] ]; }
  28. <section class="typerocket-container"> <?php $form = tr_form('seat', 'create'); // Create $form->useRoute('post',

    'seats'); // Route echo $form->open(); echo $form->text('Number'); echo $form->text('Price'); echo $form->search('persons_id') ->setLabel('Person') ->setPostType('person'); echo $form->submit('Add'); echo $form->close(); ?> </section>
  29. // Remember Me public function show($id) { $seat = new

    \App\Models\Seat(); $seat->findOrDie($id); $person = $seat->person()->get(); return tr_view('seats.show', compact('seat', 'person')); }
  30. var templates = './wordpress/assets/templates'; // Your WordPress Templates SASS mix.sass('theme.scss');

    mix.sass('admin.scss'); // Your WordPress Templates JS mix.scripts([ 'plugins.js', 'theme.js' ], templates + '/js/theme.js'); mix.scripts([ 'admin.js' ], templates + '/js/admin.js');