Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge branch 'feature/add-models' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
perruche committed Jan 18, 2022
2 parents a10a96e + 9e4a5ce commit 819fe50
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,66 @@
namespace Studiometa\Managers;

use Studiometa\Managers\ManagerInterface;
use Studiometa\WPToolkit\Builders\PostTypeBuilder;

/** Class **/
class CustomPostTypesManager implements ManagerInterface {
/**
* {@inheritdoc}
*/
public function run() {
add_action( 'init', array( $this, 'register_custom_post_types' ), 1 );
add_action( 'init', array( $this, 'register_custom_post_type_sample' ), 1 );
add_filter( 'Timber\PostClassMap', array( $this, 'set_timber_classmap' ) );
}

/**
* Register custom post types.
* Register a custom post type "Sample".
*
* Use one method per custom post type.
* Use PostTypeBuilder from studiometa/wp-toolkit to register the post type.
*
* @see https://github.com/studiometa/wp-toolkit
*
* @todo use Studiometa\WP_Factory
* @return void
*/
public function register_custom_post_types() {
public function register_custom_post_type_sample() {
$cpt = new PostTypeBuilder( 'sample' );
$cpt->set_labels( 'Sample', 'Samples' )
->register();
}

/**
* Set the class map for Timber instantiation of posts.
*
* @param string $post_class The default post class.
* @return array The project's class map.
*/
public function set_timber_classmap( string $post_class ): array {
$post_types = get_post_types();
$class_map = array();
$exclude_post_types = array(
'attachment',
'revision',
'nav_menu_item',
'custom_css',
'customize_changeset',
'oembed_cache',
'user_request',
'wp_block',
'wp_template',
'acf-field-group',
'acf-field',
);

foreach ( $post_types as $key => $post_type ) {
// Do not change the class_map of default WordPress post_types.
if ( in_array( $post_type, $exclude_post_types, true ) ) {
continue;
}

$class_map[ $key ] = '\Studiometa\Models\\' . ucfirst( $key );
}

return $class_map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@
namespace Studiometa\Managers;

use Studiometa\Managers\ManagerInterface;
use Studiometa\WPToolkit\Builders\TaxonomyBuilder;

/** Class **/
class TaxonomiesManager implements ManagerInterface {
/**
* {@inheritdoc}
*/
public function run() {
add_action( 'init', array( $this, 'register_taxonomies' ), 1 );
add_action( 'init', array( $this, 'register_taxonomy_sample' ), 1 );
}

/**
* Register custom taxonomies.
* Register a custom taxonomy "sample".
*
* Use one method per taxonomy.
* Use TaxonomyBuilder from studiometa/wp-toolkit to register the taxonomy.
*
* @see https://github.com/studiometa/wp-toolkit
*
* @todo use Studiometa\WP_Factory
* @return void
*/
public function register_taxonomies() {
public function register_taxonomy_sample() {
$tax = new TaxonomyBuilder( 'sample-cat' );
$tax->set_post_types( 'sample' )
->set_labels( 'Sample Category', 'Sample Categories' )
->register();
}
}
14 changes: 14 additions & 0 deletions template/web/wp-content/themes/<%= slug %>/app/Models/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Additional functionality for extending the TimberPost object.
*
* @package Studiometa
* @subpackage Models
*/

namespace Studiometa\Models;

use Timber\Post as TimberPost;

/** Class */
class Page extends TimberPost {}
14 changes: 14 additions & 0 deletions template/web/wp-content/themes/<%= slug %>/app/Models/Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Additional functionality for extending the TimberPost object.
*
* @package Studiometa
* @subpackage Models
*/

namespace Studiometa\Models;

use Timber\Post as TimberPost;

/** Class */
class Post extends TimberPost {}

This file was deleted.

0 comments on commit 819fe50

Please sign in to comment.