PHPackages                             gebruederheitz/wp-easy-cpt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gebruederheitz/wp-easy-cpt

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

gebruederheitz/wp-easy-cpt
==========================

Easy to use tools for a robust Wordpress custom post type setup.

v2.3.3(2y ago)11501GPL-3.0-onlyPHPPHP &gt;=7.3

Since Jan 31Pushed 2y ago1 watchersCompare

[ Source](https://github.com/gebruederheitz/wp-easy-cpt)[ Packagist](https://packagist.org/packages/gebruederheitz/wp-easy-cpt)[ RSS](/packages/gebruederheitz-wp-easy-cpt/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (13)Used By (0)

Wordpress Easy Custom Post Type
===============================

[](#wordpress-easy-custom-post-type)

*Easy to use tools for a robust Wordpress custom post type setup.*

---

Installation
------------

[](#installation)

via composer:

```
> composer require gebruederheitz/wp-easy-cpt
```

Make sure you have Composer autoload or an alternative class loader present.

Usage
-----

[](#usage)

### Post Type abstract class

[](#post-type-abstract-class)

```
use Gebruederheitz\Wordpress\CustomPostType\PostType;
use Gebruederheitz\Wordpress\CustomPostType\PostTypeRegistrationArgs;

class NewsPostType extends PostType
{
    /**
     * @required Supply a slug-type name which will be used in the DB amongst
     *           other places
     */
    public static $postTypeName = 'news';

    /**
     * @required The name users will see
     */
    public static $prettyName = 'News';

    /**
     * @optional Where the metabox will appear: one of 'side', 'normal', 'advanced'
     * @default 'side'
     */
    public static $context = 'normal';

    /**
     * @var bool Whether to use a Gutenberg editor and call the allowed block
     *           types hook. Set to "false" by default, so if you don't need
     *           Gutenberg you can just leave this out.
     */
    protected $withGutenberg = true;

    /**
     * @var bool Whether to load the media picker scripts on the edit page.
     *           If you don't need to use a media picker, you can leave this
     *           bit out.
     */
    protected $withMedia = true;

    /**
     * @var array List of allowed block types if Gutenberg is enabled. If you
     *            did not set $withGutenberg to `true` you won't need this.
     *            Otherwise supply a string-array of block names
     *            (e.g. `core/button`).
     */
    protected $allowedBlockTypes = [
        'core/paragraph',
        'core/columns',
    ];

    /**
     * @var string The translation domain to use for menu labels etc.
     *
     * If you are using the "ghwp" domain, you can skip this setting, otherwise
     * set it to your theme / plugin's i18n domain.
     */
    protected $translationDomain = 'ghwp';

    // -------------------------------------------------------------------------
    // There are only two methods you need to define, and one you will want to
    // override:
    // -------------------------------------------------------------------------

    /**
     * Renders the meta box for users to edit additional post type fields.
     *
     * @return void
     */
    public function renderMetabox()
    {
        /** @var WP_Post */
        global $post;

        // ---------------------------------------------------------------------
        // You could go old-school
        // ---------------------------------------------------------------------
        ?>
