Skip to content

Instantly share code, notes, and snippets.

@coenjacobs
Created March 3, 2017 12:35
Show Gist options
  • Save coenjacobs/3aff9e1266925416258761f03acc40f2 to your computer and use it in GitHub Desktop.
Save coenjacobs/3aff9e1266925416258761f03acc40f2 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