2017 © Pedro Peláez
 

library wordpress-metaboxes

A library to set up metaboxes in WordPress.

image

grottopress/wordpress-metaboxes

A library to set up metaboxes in WordPress.

  • Wednesday, November 22, 2017
  • by akadusei
  • Repository
  • 1 Watchers
  • 0 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

WordPress Metaboxes

Description

A library to set up metaboxes in WordPress., (*1)

Usage

Install via composer:, (*2)

composer require grottopress/wordpress-metaboxes, (*3)

Use thus:, (*4)

<?php

use GrottoPress\WordPress\Metaboxes\MetaboxesTrait;

/**
 * Define your own metaboxes class
 */
class My_Metaboxes_Class {
    /**
     * Import the metaboxes trait
     */
    use MetaboxesTrait;

    /**
     * Define your metaboxes with the `metaboxes` method
     */
    protected function metaboxes( WP_Post $post ): array {
        $boxes = [];

        if ( \is_post_type_hierarchical( $post->post_type ) ) {
            $boxes[] = [
                'id' => 'my-metabox-1',
                'title' => \esc_html__( 'My Metabox 1' ),
                'context' => 'side',
                'priority' => 'default',
                'screen' => 'page',
                'fields' => [
                    [
                        'id' => 'my-metabox-1-field-1',
                        'type' => 'select',
                        'choices' => [
                            'left' => \esc_html__( 'Left' ),
                            'right' => \esc_html__( 'Right' ),
                        ],
                        'label' => \esc_html__( 'Select direction' ),
                        'label_pos' => 'before_field', // or 'after_field'
                    ],
                ],
                'notes' => '<p>' . \esc_html__( 'Just a super cool layout metabox example' ) . '</p>',
            ];
        }

        $boxes[] = [
            'id' => 'my-metabox-2',
            'title' => \esc_html__( 'My Metabox 2' ),
            'screen' => 'post',
            'fields' => [
                [
                    'id' => 'my-metabox-2-field-1',
                    'type' => 'text',
                    'label' => \esc_html__( 'My first field' ),
                    'label_pos' => 'before_field', // or 'after_field'
                    'sanitize_callback' => 'sanitize_text_field',
                ],
                [
                    'id' => 'my-metabox-2-field-2',
                    'type' => 'email',
                    'label' => \esc_html__( 'My second field' ),
                    'label_pos' => 'before_field', // or 'after_field'
                    'sanitize_callback' => 'sanitize_email',
                ],
                [
                    'id' => 'my-metabox-2-field-3',
                    'type' => 'url',
                    'label' => \esc_html__( 'My third field' ),
                    'label_pos' => 'before_field', // or 'after_field'
                    'sanitize_callback' => 'esc_url',
                ]
            ],
            'notes' => '<p>' . \esc_html__( 'My awesome metabox example.' ) . '</p>',
        ];

        return $boxes;
    }

}

// Add your metaboxes to WordPress
$metaboxes = new My_Metaboxes_Class();
$metaboxes->setup();

The Versions

22/11 2017

dev-master

9999999-dev

A library to set up metaboxes in WordPress.

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress

22/11 2017

0.2.1

0.2.1.0

A library to set up metaboxes in WordPress.

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress

22/11 2017

dev-dev

dev-dev

A library to set up metaboxes in WordPress.

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress

28/09 2017

0.2.0

0.2.0.0

A library to set up metaboxes in WordPress.

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress

13/09 2017

0.1.0

0.1.0.0

A library to set up metaboxes in WordPress.

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress