@kevindees kevindees released this Sep 18, 2015 · 371 commits to master since this release

Assets 2

TypeRocket 2

Coding advanced WordPress themes became a blast. Be good looking and do cool stuff with less code.

http://typerocket.com

Requirements

  • WordPress 4.0+
  • PHP 5.3+

Language

  • English only

What can you do with TypeRocket?

  • You can make make post types, taxonomies and meta boxes with one line of code.
  • Add fields to post types, comments, meta boxes, option pages, user profiles and even on the front-end inside theme template files.
  • You can access a number of pre-made TypeRocket plugins for features like SEO and Theme Options installed directly into your theme.

Documentation

https://typerocket.com/docs/

Book Post Type Example

Gracefully configure WordPress without needing hooks.

  • Add a "Book" post type
  • Add a custom menu icon to "Book" (200+ icons)
  • Add an "Author" taxonomy to "Book" post type
// In your themes functions.php
include( 'typerocket/init.php' );

// Add taxonomy with custom "name" gracefully
$bookAuthor = tr_taxonomy('Author')->setId('book_author');

// Add post type with icon and taxonomy gracefully
$book = tr_post_type('Book')->setIcon('book')->apply($bookAuthor);
  • Add a MetaBox to "Book"
  • Set custom Title placeholder text
$bookDetails = tr_meta_box('Details');
$book->apply($bookDetails)->setTitlePlaceholder('Enter Book Title');
  • Use debug mode to get meta box content provider function
  • Add custom fields for ISBN and Book Cover
function add_meta_content_details() {
    $form = tr_form();
    echo $form->text('ISBN Number');
    echo $form->image('Book Cover');
}

GitHub Logo

Note: Flush the WordPress permalinks when you register a post type.

Fillable Fields Example

By default TypeRocket will save any and all fields. This is just fine in many cases and makes life easy. When you need to filter, validate or fill only specific fields we have you covered.

Set the fields for the "Book" post type the only fillable fields to make things a little more secure. You can do this by creating a book controller and model inside the app folder.

BooksModel.php is the main file we care about.

<?php // /typerocket/app/Models/BooksModel.php
namespace TypeRocket\Models;

class BooksModel extends PostTypesModel
{
    protected $fillable = array(
        'book_cover',
        'isbn_number'
    );

    protected $postType = 'book';
}

BooksController.php needs to be created to handle the actions. Blank works just fine.

<?php // /typerocket/app/Controllers/BooksController.php
namespace TypeRocket\Controllers;

class BooksController extends PostTypesController
{
}

Now only "ISBN Number" and "Book Cover" will be saved. However, because the resource controller/model has been specified, "books", only an administrator can manage the new fields.

XKernel

You will need to create a new Kernel class called XKernel to specify the middleware you want to use. Middleware can be used for all kinds of fun things. In this case we want "books" to authenticate like posts.

XKernel.php manages the middleware for the resource and request types.

<?php // /typerocket/app/Http/XKernel.php
namespace TypeRocket\Http;

class XKernel extends Kernel
{

    protected $middleware = array(
        'hookGlobal' =>
            array('AuthRead'),
        'restGlobal' =>
            array(
                'AuthRead',
                'ValidateCsrf'
            ),
        'noResource' => array(
            'AuthAdmin'
        ),
        'books' => // new resource middleware
            array('OwnsPostOrCanEditPosts'),
        'users' =>
            array('IsUserOrCanEditUsers'),
        'posts' =>
            array('OwnsPostOrCanEditPosts'),
        'pages' =>
            array('OwnsPostOrCanEditPosts'),
        'comments' =>
            array('OwnsCommentOrCanEditComments'),
        'options' =>
            array('CanManageOptions')
    );
}

Filter Fields Example

If we want to filter the fields we can do this as well. Lets use the controller filter to sanitize the data being saved.

  • Make sure the "ISBN Number" doesn't contain invalid characters
  • Cast the "Book Cover" to an integer since we reference it by the attachment ID.
add_filter('tr_model_secure_fields', function($fields, $model) {
    if($model instanceof \TypeRocket\Models\BooksModel) {

        if(isset($fields['isbn_number'])) {
            $isbn = strtoupper($fields['isbn_number']);
            $isbn = preg_replace('/((?![Xx0-9-]+).)*/i', '', $isbn);
            $fields['isbn_number'] = $isbn;
        }

        if(isset($fields['book_cover'])) {
            $fields['book_cover'] = (int) $fields['book_cover'];
        }

    }
    return $fields;
}, 10, 2);

Visit TypeRocket http://typerocket.com to get access to the tutorials and documentation.

Icons

http://icomoon.io/#preview-free licensed under the GPL.