Created
March 3, 2017 12:35
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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( ... ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace CoenJacobs\StefExample\PostTypes; | |
class Activity extends AbstractType { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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