Skip to content

Instantly share code, notes, and snippets.

@stefthoen
Forked from coenjacobs/AbstractType.php
Created March 3, 2017 14:12
Show Gist options
  • Save stefthoen/7ce0cee40d5075f23f911f2771be1908 to your computer and use it in GitHub Desktop.
Save stefthoen/7ce0cee40d5075f23f911f2771be1908 to your computer and use it in GitHub Desktop.
<?php
namespace CoenJacobs\StefExample\PostTypes;
abstract class AbstractType {
public function setup() {
// possibly some setup logic here?
}
public function register() {
// full logic of registering the post type
register_post_type( ... );
}
}
<?php
namespace CoenJacobs\StefExample\PostTypes;
class Activity extends AbstractType {
}
<?php
namespace CoenJacobs\StefExample\PostTypes;
class Manager {
protected $types = [];
public function setup() {
foreach( $this->types as $type ) {
$type->setup();
}
add_action('init', [$this, 'registerTypes'];
}
public function addType(AbstractType $type) {
array_push($this->types, $type);
}
public function registerTypes() {
foreach( $this->types as $type ) {
$type->register();
}
}
}
<?php
namespace CoenJacobs\StefExample;
use CoenJacobs\StefExample\PostTypes\Manager;
class Plugin {
/** @var Manager */
public $post_types;
public function __construct() {
$this->post_types = new Manager();
}
public function setup() {
$this->post_types->setup();
}
}
<?php
/**
* Plugin Name: Stef Example
*/
require('vendor/autoload.php');
add_action('plugins_loaded', function() {
$plugin = new CoenJacobs\StefExample\Plugin();
$plugin->setup();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment