2017 © Pedro Peláez
 

library component-post-type

Post type helper for WordPress

image

flexpress/component-post-type

Post type helper for WordPress

  • Wednesday, August 20, 2014
  • by timperry
  • Repository
  • 1 Watchers
  • 0 Stars
  • 76 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

FlexPress PostType component

Install with Pimple

The PostType component uses two classes: - AbstractPostType, which you extend to create a PostType. - PostTypeHelper, which hooks into everything for you and registers the post types., (*1)

Lets create a pimple config for both of these, (*2)

$pimple["documentPostType"] = function () {
  return new Document();
};

$pimple['PostTypeHelper'] = function ($c) {
    return new PostTypeHelper($c['objectStorage'], array(
        $c["documentPostType"]
    ));
};
  • Note the dependency $c['objectStorage'] is a SPLObjectStorage

Creating a concreate PostType class

Create a concreate class that implements the AbstractPostType class and implements the getName() method., (*3)

class DocumentType extends AbstractPostType {

    public function getName()
    {
      return "document";
    }

}

This above example is the bare minimum you must implement, the example that follows is the other extreme implementing all available methods., (*4)

class Document extends AbstractPostType {

  public function getSingularName()
  {
    return "Doc";
  }

  public function getPluralName()
  {
    return "Docs";
  }

  public function getArgs()
  {
    $args = parent::getArgs();
    $args['supports'] = array("title", "editor");
    return $args;
  }

  protected function getLabels()
  {
    $labels = parent::getLabels();
    $labels['menu_name'] = 'Docs';
    return $labels;
  }

  public function getName()
  {
    return "document";
  }

}

Public Methods

  • getSingularName() - returns the singular name of the post type.
  • getPluralName() - returns the plural name of the post type.
  • getArgs() - returns the array of args.
  • getLabels() - Returns the array of labels.
  • getName() - Returns post type name.

PostTypeHelper usage

Once you have setup the pimple config you are use the PostTypeHelper like this, (*5)

$helper = $pimple['postTypeHelper'];
$helper->registerPostTypes();

That's it, the helper will then add all the needed hooks and register all the post types you have provided it., (*6)

Public methods

  • registerPostTypes() - Registers the post types provided.

The Versions

20/08 2014

dev-master

9999999-dev

Post type helper for WordPress

  Sources   Download

13/08 2014

v1.0.0

1.0.0.0

Post type helper for WordPress

  Sources   Download