Code Monkey home page Code Monkey logo

wp-register's Introduction

wp-register

WordPress has many registration tasks. WP Register makes registering custom blocks, image sizes, menus, post types, taxonomies, sidebars and widgets easy.

WP Register is maintained by Make it WorkPress.

Usage

Include the WP_Register class in your plugin, theme or child theme file. Require it in your file, use an autoloader or include it using composer. You can read more about autoloading in the readme of wp-autoload.

Build your array with registrations

You can add the types you want to register through an multidimensional array, as explained in the example below

$registrations = [
    'blocks' => [
        [
            'type'  => 'custom/block-type',                     // The type, object or json path for the custom gutenberg block
            'args'  => ['style' => 'custom-block-type-style']   // The arguments for registering a block, following the arguments in the codex
        ]
    ]
    'image_sizes' => [
        [
            'name'   => 'fhd',
            'height' => 1080,
            'width'  => 1920,
            'crop'   => true
        ]
    ],
    'menus' => [
        'menu-location'     => __('Custom Menu Location', 'textdomain'),
        'another-location'  => __('AnotherCustom Menu Location', 'textdomain')
    ],     
    'post_types' => [
        [
            'name'          => 'beer', 
            'plural'        => __('Beers', 'textdomain'), 
            'singular'      => __('Beer', 'textdomain'), 
            'args'          => ['public' => true]       // Contains the arguments as they are supported by register_post_type. (optional)
            'taxonomies'    => ['category']             // Connects existing taxonomies to this post type. Should be an array. (optional)
            'slug'          => 'slug'                   // Sets a custom slug, fastforward for the rewrite slug setting in arguments
            'icon'          => 'dashicon-beer'          // Sets a custom wp-admin menu icon, fastforward for the menu_icon setting in arguments
        ]
    ],
    'sidebars' => [
        [
            'id'            => 'custom-sidebar', 
            'name'          => __('Custom Sidebar', 'textdomain'), 
            'description'   => __('Description for this sidebar', 'textdomain'),
            'before_widget' => '<section id="%1$s" class="widget %2$s">', // The opening element for the widget (optional)
            'after_widget'  => '</section>',  // The closing element for the widget (optional)
            'before_title'  => '<h3 class="widget-title">',  // The opening title tag for the widget (optional)
            'after_title'   => '</h3>' // The closing title tag for the widget (optional)
        ]
    ],    
    'taxonomies' => [
        [
            'name'      => 'type', 
            'object'    => 'beer', 
            'plural'    => __('Types', 'textdomain'), 
            'singular'  => __('Type', 'textdomain'),
            'args'      => ['hierarchical' => true] // Contains the arguments as they are supported by register_post_type. (optional)
       ]
    ],
    'widgets' => [
        'WidgetClass' // The name of your custom widget class, namespeced if using autoload
    ],
];

Create instance

Create a new instance of the WP_Register class with your registration array and textdomain string as arguments in the following manner.

$register = new MakeitWorkPress\WP_Register\Register( $registrations, 'textdomain' );

The Register class accepts two arguments, namely an Array $registrations and String $textdomain.

wp-register's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.