wordpress-activitypub/includes/base/class-transformer-base.php

65 lines
1.8 KiB
PHP
Raw Normal View History

2023-11-18 13:40:27 +01:00
<?php
/**
* Inspired by the PHP ActivityPub Library by @Landrok
*
* @link https://github.com/landrok/activitypub
*/
2023-11-18 15:00:28 +01:00
namespace Activitypub;
2023-11-18 13:40:27 +01:00
/**
* Base class to implement WordPress to ActivityPub transformers.
*/
abstract class Transformer_Base {
/**
* Get the supported WP post_types that the transformer can use as an input.
*
* By default all post types are supported.
*
* @since version_number_transformer_management_placeholder
2023-11-18 13:42:56 +01:00
* @return string[] An array containing all the supported post types.
2023-11-18 13:40:27 +01:00
*/
public function get_supported_post_types() {
2023-11-19 17:32:41 +01:00
return \get_post_types( array( 'public' => true ), 'names' );
2023-11-18 13:40:27 +01:00
}
2023-11-19 17:32:41 +01:00
/**
* Get the name of the plugin that registered the transformer.
*
* @see Forked from the WordPress elementor plugin.
*
* @since version_number_transformer_management_placeholder
* @return string Plugin name
*/
private function get_plugin_name_from_transformer_instance( $transformer ) {
$class_reflection = new \ReflectionClass( $transformer );
$plugin_basename = plugin_basename( $class_reflection->getFileName() );
$plugin_directory = strtok( $plugin_basename, '/' );
$plugins_data = get_plugins( '/' . $plugin_directory );
$plugin_data = array_shift( $plugins_data );
return $plugin_data['Name'] ?? esc_html__( 'Unknown', 'activitypub' );
}
2023-11-18 13:40:27 +01:00
/**
* Get the name used for registering the transformer with the ActivityPub plugin.
*
* @since version_number_transformer_management_placeholder
2023-11-18 13:42:56 +01:00
*
* @return string name
2023-11-18 13:40:27 +01:00
*/
abstract public function get_name();
/**
* Get the display name for the ActivityPub transformer.
*
* @since version_number_transformer_management_placeholder
2023-11-18 13:42:56 +01:00
*
* @return string display name
2023-11-18 13:40:27 +01:00
*/
abstract public function get_title();
}