add entry point to support for wp_comment

This commit is contained in:
André Menrath 2023-11-20 14:30:07 +01:00
parent 85eabd018a
commit b843d841f2

View file

@ -7,6 +7,9 @@
namespace Activitypub;
use WP_Post;
use WP_Comment;
use function Activitypub\camel_to_snake_case;
use function Activitypub\snake_to_camel_case;
@ -235,7 +238,7 @@ class Transformers_Manager {
*
* Retrieve the registered transformers list.
*
* @since 1.0.0
* @since version_number_transformer_management_placeholder
* @access public
*
* @param string $transformers Optional. Widget name. Default is null.
@ -254,29 +257,34 @@ class Transformers_Manager {
return $this->transformers;
}
/**
* Get the right ActivityPub transformer.
*
* @since 1.0.0
* @since version_number_transformer_management_placeholder
* @access public
*
* @param WP_Post $wp_post The WordPress Post.
* @param WP_Post|WP_Comment $wp_post The WordPress Post/Comment.
*
* @return Transformer_Base|null Registered transformers.
*/
public function get_transformer( $wp_post ) {
public function get_transformer( $object ) {
switch ( get_class( $object ) ) {
case 'WP_Post':
if ( is_null( $this->transformers ) ) {
$this->init_transformers();
}
if ( null !== $transformer ) {
return isset( $this->transformers[ $transformer ] ) ? $this->transformers[ $transformer ] : null;
}
$post_type = get_post_type( $wp_post );
$post_type = get_post_type( $object );
$transformer_mapping = \get_option( 'activitypub_transformer_mapping', array( 'post' => 'activitypub/default', 'page' => 'activitypub/default' ) ) ? \get_option( 'activitypub_transformer_mapping', array( 'post' => 'activitypub/default', 'page' => 'activitypub/default' ) ) : array();
$transformer_name = $transformer_mapping[ $post_type ];
return new $this->transformers[ $transformer_name ];
case 'WP_Comment':
return new Comment( $object );
default:
return apply_filters( 'activitypub_transformer', null, $object, get_class( $object ) );
}
}