Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 1.54 KB

metabox.md

File metadata and controls

44 lines (35 loc) · 1.54 KB

Metabox

Create Metabox

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,
                ]);
            },
        ]);

Use Class Method for inputHandler and/or outputHandler

The second argument in the array is the method name on the instance of $this.

            'inputHandler'  => [$this, 'inputHandler'],
            'outputHandler' => [$this, 'outputHandler'],

Display Metabox on a Post Type

Add post type slugs to the postType array.

            'postType'      => ['page', 'post', 'project'],