(new Page)->whereMeta('featured', 'yes')->get();
(new Post)->published()->with(['meta', 'author.meta'])->paginate();
(new Page)->published()->find()->load(['meta', 'author.meta']);
(new User)->with(['meta'])->get();
ORM + Eager Loading
TypeRocket brings a powerful ORM to WordPress that is designed for WordPress.
// View: blog.single
$this->layout('layouts.blog');
if($posts) :
foreach($posts as $post) :
echo '<h1>' . $post->title() . '</h1>';
echo $post->content();
endwhile;
endif;
// View: layouts.blog
$this->header('parts.header');
$this->yield('main');
$this->footer('parts.footer');
Views
Upgrade from the WordPress spaghetti code to DRY TypeRocket Pro templates.
tr_route()->get()->on('my-api/posts/*', 'post@ApiController');
class ApiController extends Controller
{
function posts(Post $post, Response $response) {
if($post->can('read')) {
return $post->load(['meta', 'author.meta'])->paginate();
}
return $response->unauthorized('No so fast!');
}
}
Routes
Create custom routes using an elegant syntax. Power up using controllers.
class PostPolicy extends Policy
{
public function update(AuthUser $auth, WPPost $post)
{
if( $auth->isCapable('edit_posts') || $auth->getID() == $post->getUserID()) {
return true;
}
return false;
}
}
class CanEditUsers extends Middleware {
public function handle() {
if( ! $this->handler->getHook() && ! current_user_can( 'edit_users' ) ) {
tr_abort(401);
}
$this->next->handle();
}
}
Middleware & Policies
Take control of the rest life cycle. Secure your controllers.
// wp-content/themes/my-theme/index.php
tr_template_router('post@BlogController');
class BlogController extends TemplateController
{
public function __construct()
{
$this->buildPosts(Post::class);
}
public function post()
{
return tr_view('blog.single', ['posts' => $this->posts]);
}
}
MVC in Themes
Add Pro's MVC to your WordPress theme's template files.