Skip to content

Commit

Permalink
[MOOSE-168]: Add misting post type register logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MlKilderkin committed Dec 2, 2024
1 parent 95915b2 commit bde205e
Show file tree
Hide file tree
Showing 14 changed files with 1,039 additions and 789 deletions.
1,313 changes: 769 additions & 544 deletions composer.lock

Large diffs are not rendered by default.

69 changes: 0 additions & 69 deletions wp-content/plugins/core/src/Object_Meta/Meta_Group.php

This file was deleted.

56 changes: 0 additions & 56 deletions wp-content/plugins/core/src/Object_Meta/Meta_Map.php

This file was deleted.

90 changes: 0 additions & 90 deletions wp-content/plugins/core/src/Object_Meta/Meta_Repository.php

This file was deleted.

31 changes: 31 additions & 0 deletions wp-content/plugins/core/src/Post_Types/Meta_Box_Handlers/ACF.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Post_Types\Meta_Box_Handlers;

use Tribe\Plugin\Post_Types\Post_Type_Config;

class ACF implements Meta_Box_Handler_Interface {

/**
* Registers the meta boxes for a post type.
*
* @param \Tribe\Plugin\Post_Types\Post_Type_Config $config
*/
public function register_meta_boxes( Post_Type_Config $config ): void {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return;
}

acf_add_local_field_group( $config->get_meta_boxes() );
}

/**
* Hooks the meta box handler class to the required filters/actions if needed.
*/
public function hook(): void {
add_filter( Meta_Box_Handler_Interface::INSTANCE_FILTER, function () {
return $this;
} );
}

}
39 changes: 39 additions & 0 deletions wp-content/plugins/core/src/Post_Types/Meta_Box_Handlers/CMB2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Post_Types\Meta_Box_Handlers;

use Tribe\Plugin\Post_Types\Post_Type_Config;

class CMB2 implements Meta_Box_Handler_Interface {

protected Post_Type_Config $config;

/**
* Registers the meta boxes for a post type.
*
* @param \Tribe\Plugin\Post_Types\Post_Type_Config $config
*/
public function register_meta_boxes( Post_Type_Config $config ): void {
$this->config = $config;
}

/**
* Hooks the meta box handler class to the required filters/actions if needed.
*/
public function hook(): void {
add_filter( Meta_Box_Handler_Interface::INSTANCE_FILTER, function () {
return $this;
} );

$config = $this->config;

add_filter( 'cmb2_meta_boxes', static function ( $meta_boxes ) use ( $config ) {
$post_type_meta_boxes = $config->get_meta_boxes();
$post_type_meta_boxes = apply_filters( "tribe_{$config->post_type()}_meta_boxes", $post_type_meta_boxes );
$meta_boxes = array_merge( $meta_boxes, $post_type_meta_boxes );

return $meta_boxes;
} );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Post_Types\Meta_Box_Handlers;

use Tribe\Plugin\Post_Types\Post_Type_Config;

interface Meta_Box_Handler_Interface {

public const INSTANCE_FILTER = 'tribe_libs_meta_box_handler';

/**
* Hooks the meta box handler class to the required filters/actions if needed.
*/
public function hook(): void;

/**
* Registers the meta boxes for a post type.
*
* @param \Tribe\Plugin\Post_Types\Post_Type_Config $config
*/
public function register_meta_boxes( Post_Type_Config $config ): void;

}
28 changes: 3 additions & 25 deletions wp-content/plugins/core/src/Post_Types/Post_Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@

namespace Tribe\Plugin\Post_Types;

use Tribe\Plugin\Object_Meta\Meta_Map;
use Tribe\Plugin\Object_Meta\Meta_Repository;

class Post_Object {

public const NAME = '';

protected mixed $meta;

protected int $post_id = 0;

public function __construct( int $post_id = 0, ?Meta_Map $meta = null ) {
public function __construct( int $post_id = 0 ) {
$this->post_id = $post_id;
if ( isset( $meta ) ) {
$this->meta = $meta;
} else {
$this->meta = new Meta_Map( static::NAME );
}
}

/**
Expand All @@ -29,19 +19,7 @@ public function __construct( int $post_id = 0, ?Meta_Map $meta = null ) {
* @param int $post_id The ID of an existing post
*/
public static function factory( int $post_id ): self {
$meta_repo = apply_filters( Meta_Repository::GET_REPO_FILTER, null );

if ( empty( $meta_repo ) ) {
$meta_repo = new Meta_Repository();
}

$post_type = static::NAME;

if ( empty( $post_type ) ) {
$post_type = get_post_type( $post_id );
}

return new self( $post_id, $meta_repo->get( $post_type ) );
return new self( $post_id );
}

/**
Expand All @@ -51,7 +29,7 @@ public static function factory( int $post_id ): self {
* @param string $key
*/
public function get_meta( string $key ): mixed {
return $this->meta->get_value( $this->post_id, $key );
return get_post_meta( $this->post_id, $key, true );
}

public function __get( mixed $key ): mixed {
Expand Down
Loading

0 comments on commit bde205e

Please sign in to comment.