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

TypeRocket 3.0: Unleash WordPress and be amazing (Wilmington NC)

Kevin Dees
November 01, 2016

TypeRocket 3.0: Unleash WordPress and be amazing (Wilmington NC)

TypeRocket 3 is the WordPress framework for developers. Build sites and themes fast, custom and beautiful. Ever wanted WordPress to use composer? Want to build component based designs? Want to have a forms API with model binding, custom routes, controllers,
use themes outside of public view to boost security, have a custom console to build your own CLI commands, make post types/taxonomies/meta boxes with one line of code, or create use custom tables? All this is just the beginning of TypeRocket 3 for WordPress. Get theme options and advanced SEO with Twitter cards out of the box. You may not need a single plugin for your next site. TypeRocket 3 has completely reimagined what developing WordPress sites can be without sacrificing speed, stability or breaking WordPress
core. Come and see what making WordPress sites is like in Modern PHP.

Kevin Dees

November 01, 2016
Tweet

More Decks by Kevin Dees

Other Decks in Technology

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' ]; }
  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 = tr_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. 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;
  10. <?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() { } }
  11. $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();
  12. ADD

  13. 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); }
  14. // 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();
  15. 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(); }
  16. <?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();
  17. 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(); }
  18. class Seat extends Model { protected $resource = 'seats'; //

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

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

    = $seat->person()->get(); return tr_view('seats.show', compact('seat', 'person')); }
  21. <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>
  22. 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 ] ]; }
  23. class Kernel extends \TypeRocket\Http\Kernel { protected $middleware = [ //

    ... 'person' => [ OwnsPostOrCanEditPosts::class ], 'seat' => [ AuthAdmin::class ] ]; }
  24. TYPEROCKET.COM ▸ Forms and All Fields ▸ Commands ▸ Front-end

    Fields ▸ Custom Routes ▸ And way more!