Skip to content

Commit

Permalink
Update Page and Post to use a similar approach to CPTs
Browse files Browse the repository at this point in the history
  • Loading branch information
darylldoyle committed Apr 3, 2024
1 parent d388f53 commit 1fd2092
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* AbstractCorePostType
*
* @package TenUpPlugin
*/

namespace TenUpPlugin\PostTypes;

/**
* Abstract class for core post types.
*
* This class is intended to be extended by post types that are part of core WordPress functionality.
* This allows for a more common interface for core post types and custom post types.
* It's unlikely that this class will need to be used directly.
*/
abstract class AbstractCorePostType extends AbstractPostType {

/**
* Get the singular post type label.
*
* No-op for core post types since they are already registered by WordPress.
*
* @return string
*/
public function get_singular_label() {
return '';
}

/**
* Get the plural post type label.
*
* No-op for core post types since they are already registered by WordPress.
*
* @return string
*/
public function get_plural_label() {
return '';
}

/**
* Get the menu icon for the post type.
*
* No-op for core post types since they are already registered by WordPress.
*
* @return string
*/
public function get_menu_icon() {
return '';
}

/**
* Checks whether the Module should run within the current context.
*
* True for core post types since they are already registered by WordPress.
*
* @return bool
*/
public function can_register() {
return true;
}

/**
* Registers a post type and associates its taxonomies.
*
* @uses $this->get_name() to get the post's type name.
* @return Bool Whether this theme has supports for this post type.
*/
public function register() {
$this->register_taxonomies();
$this->after_register();

return true;
}
}
29 changes: 21 additions & 8 deletions mu-plugins/10up-plugin/includes/classes/PostTypes/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,37 @@

/**
* Page Post Type
*
* This class is a placeholder for the core Page post type.
* It's here to allow engineers to extend the core Page post type in the same way as custom post types.
*/
class Page extends Module {
class Page extends AbstractCorePostType {

/**
* Get the post type name.
*
* @return string
*/
public function get_name() {
return 'page';
}

/**
* Can the class be registered?
* Returns the default supported taxonomies. The subclass should declare the
* Taxonomies that it supports here if required.
*
* @return bool
* @return array
*/
public function can_register() {
return true;
public function get_supported_taxonomies() {
return [];
}

/**
* Register hooks and filters.
* Run any code after the post type has been registered.
*
* @return void
*/
public function register() {
// Register any hooks/filters you need.
public function after_register() {
// Do nothing.
}
}
33 changes: 23 additions & 10 deletions mu-plugins/10up-plugin/includes/classes/PostTypes/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,41 @@

namespace TenUpPlugin\PostTypes;

use TenUpPlugin\Module;

/**
* Post Post type.
*
* This class is a placeholder for the core Post post type.
* It's here to allow engineers to extend the core Post post type in the same way as custom post types.
*/
class Post extends Module {
class Post extends AbstractCorePostType {

/**
* Get the post type name.
*
* @return string
*/
public function get_name() {
return 'post';
}

/**
* Can the class be registered?
* Returns the default supported taxonomies. The subclass should declare the
* Taxonomies that it supports here if required.
*
* Note: This will not remove the default taxonomies that are registered by core.
*
* @return bool
* @return array
*/
public function can_register() {
return true;
public function get_supported_taxonomies() {
return [];
}

/**
* Register hooks and filters.
* Run any code after the post type has been registered.
*
* @return void
*/
public function register() {
// Register any hooks/filters you need.
public function after_register() {
// Do nothing.
}
}

0 comments on commit 1fd2092

Please sign in to comment.