- Create Metabox
- Use Class Method for inputHandler and/or outputHandler
- Display Metabox on a Post Type
The WordPress add_meta_box
function is abstracted with our metabox manager. Instead use the syntax below. Note: 'postType'
takes place of the add_meta_box
'screen'
argument.
<?php
$this->app['metabox']->create([
'id' => 'sidebar',
'title' => 'Sidebar',
'context' => 'side',
'postType' => ['page'],
'inputHandler' => function ($post, Request $request) {
$post->setMeta('sidebar', $request->get('sidebar'));
},
'outputHandler' => function ($post) {
return view('metabox.sidebar', [
'sidebarOptions' => ['sidebar1' => 'Sidebar 1', 'sidebar2' => 'Sidebar 2'],
'post' => $post,
]);
},
]);
The second argument in the array is the method name on the instance of $this
.
'inputHandler' => [$this, 'inputHandler'],
'outputHandler' => [$this, 'outputHandler'],
Add post type slugs to the postType
array.
'postType' => ['page', 'post', 'project'],