b744dc551d
* Comments 1 * Delete FUNDING.yml * Add basic BuddyPress support fix #122 thanks and props @skysarwer * change URL to `bp_core_get_user_domain` * fix "Follow" issue fix #133 * fix #135 * version bump * Create phpunit.yml * Update composer.json * Update composer.json * Update phpunit.yml * Update composer.json * Create phpcs.yml * Update phpcs.xml * Update composer.json * phpcs fixes * fix typo * Comments update * webfinger_extract remove extra param * coding standards * Replies Collection, settings, other fixes * Create stale.yml * move stale file * code standards cleanup * Migrate / Update script * bugfix * add settings link to plugin page * fix code standards * fix cs * fix PHPCS * PHPCS fixes * change background image for wp.org * fix docker * fix webfinger for email identifiers fix #152 * version bump * update composer file to fix unit testing * allow plugins * fix dependencies * Migrate tools * code cleanup * regression fix * Fix announce, clarified language * update included filename * code cleanup * Improve migration UX * Add comments view, warnings to migrate page * style fix * more style fixes * Fix send_delete_activity * replace ap_comment_id to reuse replytocom var * Comments class missing attributes * Post class fix attributes * move js file to assets/js * Separate file for Comment processing hooks * fix file path * associate comments to back compat post * Fix js assets enqueue * change regex matching potential hashtags Matches any string starting with '#' and consisting of any number and combination of [A-Za-z0-9_] that is directly followed by whitespace or punctuation. Groups everything after '#' for access in functions using this regex. This fixes #183 (incomplete links on hashtags containing special characters) by not matching these at all. * also detect hashtags at the start of a paragraph * restrict html tags after which to detect a hashtag Hashtags should not be detected after just any html tag - for example not after an opening a or div. To still allow detection at the start of a line, allow specifically p and br to directly precede a hashtag. * fix pagination * Add Custom Post Type support to outbox API * remove comment_type * fix comparison * remove trailing spaces * fix phpcs issues * fix phpcs issues * run phpcs also on pull_requests * fix phpcs issues * support threaded comments from ActivityPub * refactor support for threaded comments from ActivityPub * remove debugging log line * add first unit tests for class inbox * fix code smells * make filter function static * attempt to resolve backwards compatibility issues * update js to new file * delete old js * Remove migrate code * update post meta canonical * remove type and mention meta from comment filters * extract mentions from comment_content * phpcbf * remove extra curly bracket * Remove migrate code * remove version_check() * Update enqueue scripts * Remove remote comments from preprocessing * Reply to comments from Dashboard * rename function, inserts users into reply text * Update dispatch comments * update comment model * fix comment model replies property * fix preprocess_comment cap check * Add webfinger filter to comments * Add comment edit datetime * cleanup * fix var name * cleanup * phpcbf * better actual translation support * Separate comment reply script * migrate dispatch, migrate comment model to transform * ignore WP_Comment type for now * Adds new helpers for resolving inReplyTo url * Update activitypub_send_comment_activity to include type * remove redundant id check * reinclude user_id in saved ap_object meta * update post field meta * Fix comment updated datetime * front-end reply inserts @mentions * enqueue reply script on front end * use const instead of dirname * some simplifications * move some functions * fixes * some more fixes * fix namespace * fix unittests * fix testcase * fixed typo * fix tests * fix tests * fix PHPCS * move functions to transformer class * fix warnings * Link remote comments on frontend * Link to comment source as row action * Init Comments class * remove dead dispatch action * re-add extract mentions filter * Restore and tweak Comment transform * Schedule comments activities for non-admin users * lint * remove context property * rename get_id method to generate_id * fix locale * move functions * PHPDoc * this is never used * remove some edit methods * remove replies for now * remove JS calls * remove reply_recipients * never used * remove other query-vars * otherwise to_json would not work properly * small changes * use `c` for comment IDs * remove comments.php for now maybe re-add it later * wp_insert_post is an action * also parse comment_text * remove duplicate functions * add Base transformer * remove invalid test * update to new query var * update dispatcher to support comments and posts * fix transition * remove unused functions for now * schedule_comment_activity seems to ignore create and update * fix wrong use of functions! * not every platforms sends an URL * check source-id first * remove hashtags for now * fallback to ID * fix typo * move to_activity to Base class * remove unused function * add support for announce and like * also ping inboxes of other commenters in the thread * restructure WebFinger class * some small improvements * simplified to_object class props @Menrath for the feedback and the idea! * fix unit tests * make transformer filterable /cc @Menrath * use transformer factory, so that transformer can be overwritten * phpcs fixes * fix attachments * fix comment transformer * remove comments for now * update readme/changelog * simplify and unify json_encodes --------- Co-authored-by: Django Doucet <mediaformat.ux@gmail.com> Co-authored-by: Andreas <andreas@bocops.de> Co-authored-by: Eana Hufwe <eana@1a23.com> Co-authored-by: Matthew Exon <git.mexon@spamgourmet.com> Co-authored-by: Django Doucet <django.doucet@webdevstudios.com>
593 lines
15 KiB
PHP
593 lines
15 KiB
PHP
<?php
|
|
namespace Activitypub\Transformer;
|
|
|
|
use WP_Post;
|
|
use Activitypub\Shortcodes;
|
|
use Activitypub\Model\Blog_User;
|
|
use Activitypub\Transformer\Base;
|
|
use Activitypub\Collection\Users;
|
|
use Activitypub\Activity\Base_Object;
|
|
|
|
use function Activitypub\esc_hashtag;
|
|
use function Activitypub\is_single_user;
|
|
use function Activitypub\get_rest_url_by_path;
|
|
use function Activitypub\site_supports_blocks;
|
|
|
|
/**
|
|
* WordPress Post Transformer
|
|
*
|
|
* The Post Transformer is responsible for transforming a WP_Post object into different other
|
|
* Object-Types.
|
|
*
|
|
* Currently supported are:
|
|
*
|
|
* - Activitypub\Activity\Base_Object
|
|
*/
|
|
class Post extends Base {
|
|
/**
|
|
* Returns the ID of the WordPress Post.
|
|
*
|
|
* @return int The ID of the WordPress Post
|
|
*/
|
|
public function get_wp_user_id() {
|
|
return $this->object->post_author;
|
|
}
|
|
|
|
/**
|
|
* Change the User-ID of the WordPress Post.
|
|
*
|
|
* @return int The User-ID of the WordPress Post
|
|
*/
|
|
public function change_wp_user_id( $user_id ) {
|
|
$this->object->post_author = $user_id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Transforms the WP_Post object to an ActivityPub Object
|
|
*
|
|
* @see \Activitypub\Activity\Base_Object
|
|
*
|
|
* @return \Activitypub\Activity\Base_Object The ActivityPub Object
|
|
*/
|
|
public function to_object() {
|
|
$post = $this->object;
|
|
$object = parent::to_object();
|
|
|
|
$published = \strtotime( $post->post_date_gmt );
|
|
|
|
$object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
|
|
|
|
$updated = \strtotime( $post->post_modified_gmt );
|
|
|
|
if ( $updated > $published ) {
|
|
$object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
|
|
}
|
|
|
|
$object->set_content_map(
|
|
array(
|
|
$this->get_locale() => $this->get_content(),
|
|
)
|
|
);
|
|
$path = sprintf( 'users/%d/followers', intval( $post->post_author ) );
|
|
|
|
$object->set_to(
|
|
array(
|
|
'https://www.w3.org/ns/activitystreams#Public',
|
|
get_rest_url_by_path( $path ),
|
|
)
|
|
);
|
|
|
|
return $object;
|
|
}
|
|
|
|
/**
|
|
* Returns the ID of the Post.
|
|
*
|
|
* @return string The Posts ID.
|
|
*/
|
|
public function get_id() {
|
|
return $this->get_url();
|
|
}
|
|
|
|
/**
|
|
* Returns the URL of the Post.
|
|
*
|
|
* @return string The Posts URL.
|
|
*/
|
|
public function get_url() {
|
|
$post = $this->object;
|
|
|
|
if ( 'trash' === get_post_status( $post ) ) {
|
|
$permalink = \get_post_meta( $post->ID, 'activitypub_canonical_url', true );
|
|
} else {
|
|
$permalink = \get_permalink( $post );
|
|
}
|
|
|
|
return \esc_url( $permalink );
|
|
}
|
|
|
|
/**
|
|
* Returns the User-URL of the Author of the Post.
|
|
*
|
|
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
|
|
*
|
|
* @return string The User-URL.
|
|
*/
|
|
protected function get_attributed_to() {
|
|
if ( is_single_user() ) {
|
|
$user = new Blog_User();
|
|
return $user->get_url();
|
|
}
|
|
|
|
return Users::get_by_id( $this->object->post_author )->get_url();
|
|
}
|
|
|
|
/**
|
|
* Generates all Media Attachments for a Post.
|
|
*
|
|
* @return array The Attachments.
|
|
*/
|
|
protected function get_attachment() {
|
|
// Once upon a time we only supported images, but we now support audio/video as well.
|
|
// We maintain the image-centric naming for backwards compatibility.
|
|
$max_media = intval( \apply_filters( 'activitypub_max_image_attachments', \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ) ) );
|
|
|
|
if ( site_supports_blocks() && \has_blocks( $this->object->post_content ) ) {
|
|
return $this->get_block_attachments( $max_media );
|
|
}
|
|
|
|
return $this->get_classic_editor_images( $max_media );
|
|
}
|
|
|
|
/**
|
|
* Get media attachments from blocks. They will be formatted as ActivityPub attachments, not as WP attachments.
|
|
*
|
|
* @param int $max_media The maximum number of attachments to return.
|
|
*
|
|
* @return array The attachments.
|
|
*/
|
|
protected function get_block_attachments( $max_media ) {
|
|
// max media can't be negative or zero
|
|
if ( $max_media <= 0 ) {
|
|
return array();
|
|
}
|
|
|
|
$id = $this->object->ID;
|
|
|
|
$media_ids = array();
|
|
|
|
// list post thumbnail first if this post has one
|
|
if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) {
|
|
$media_ids[] = \get_post_thumbnail_id( $id );
|
|
}
|
|
|
|
if ( $max_media > 0 ) {
|
|
$blocks = \parse_blocks( $this->object->post_content );
|
|
$media_ids = self::get_media_ids_from_blocks( $blocks, $media_ids, $max_media );
|
|
}
|
|
|
|
return \array_filter( \array_map( array( self::class, 'wp_attachment_to_activity_attachment' ), $media_ids ) );
|
|
}
|
|
|
|
/**
|
|
* Get image attachments from the classic editor.
|
|
* Note that audio/video attachments are only supported in the block editor.
|
|
*
|
|
* @param int $max_images The maximum number of images to return.
|
|
*
|
|
* @return array The attachments.
|
|
*/
|
|
protected function get_classic_editor_images( $max_images ) {
|
|
// max images can't be negative or zero
|
|
if ( $max_images <= 0 ) {
|
|
return array();
|
|
}
|
|
|
|
$id = $this->object->ID;
|
|
|
|
$image_ids = array();
|
|
|
|
// list post thumbnail first if this post has one
|
|
if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) {
|
|
$image_ids[] = \get_post_thumbnail_id( $id );
|
|
--$max_images;
|
|
}
|
|
|
|
if ( $max_images > 0 ) {
|
|
$query = new \WP_Query(
|
|
array(
|
|
'post_parent' => $id,
|
|
'post_status' => 'inherit',
|
|
'post_type' => 'attachment',
|
|
'post_mime_type' => 'image',
|
|
'order' => 'ASC',
|
|
'orderby' => 'menu_order ID',
|
|
'posts_per_page' => $max_images,
|
|
)
|
|
);
|
|
foreach ( $query->get_posts() as $attachment ) {
|
|
if ( ! \in_array( $attachment->ID, $image_ids, true ) ) {
|
|
$image_ids[] = $attachment->ID;
|
|
}
|
|
}
|
|
}
|
|
$image_ids = \array_unique( $image_ids );
|
|
|
|
return \array_filter( \array_map( array( self::class, 'wp_attachment_to_activity_attachment' ), $image_ids ) );
|
|
}
|
|
|
|
/**
|
|
* Recursively get media IDs from blocks.
|
|
* @param array $blocks The blocks to search for media IDs
|
|
* @param array $media_ids The media IDs to append new IDs to
|
|
* @param int $max_media The maximum number of media to return.
|
|
*
|
|
* @return array The image IDs.
|
|
*/
|
|
protected static function get_media_ids_from_blocks( $blocks, $media_ids, $max_media ) {
|
|
|
|
foreach ( $blocks as $block ) {
|
|
// recurse into inner blocks
|
|
if ( ! empty( $block['innerBlocks'] ) ) {
|
|
$media_ids = self::get_media_ids_from_blocks( $block['innerBlocks'], $media_ids, $max_media );
|
|
}
|
|
|
|
switch ( $block['blockName'] ) {
|
|
case 'core/image':
|
|
case 'core/cover':
|
|
case 'core/audio':
|
|
case 'core/video':
|
|
case 'videopress/video':
|
|
if ( ! empty( $block['attrs']['id'] ) ) {
|
|
$media_ids[] = $block['attrs']['id'];
|
|
}
|
|
break;
|
|
case 'jetpack/slideshow':
|
|
case 'jetpack/tiled-gallery':
|
|
if ( ! empty( $block['attrs']['ids'] ) ) {
|
|
$media_ids = array_merge( $media_ids, $block['attrs']['ids'] );
|
|
}
|
|
break;
|
|
case 'jetpack/image-compare':
|
|
if ( ! empty( $block['attrs']['beforeImageId'] ) ) {
|
|
$media_ids[] = $block['attrs']['beforeImageId'];
|
|
}
|
|
if ( ! empty( $block['attrs']['afterImageId'] ) ) {
|
|
$media_ids[] = $block['attrs']['afterImageId'];
|
|
}
|
|
break;
|
|
}
|
|
|
|
// depupe
|
|
$media_ids = \array_unique( $media_ids );
|
|
|
|
// stop doing unneeded work
|
|
if ( count( $media_ids ) >= $max_media ) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
// still need to slice it because one gallery could knock us over the limit
|
|
return array_slice( $media_ids, 0, $max_media );
|
|
}
|
|
|
|
/**
|
|
* Converts a WordPress Attachment to an ActivityPub Attachment.
|
|
*
|
|
* @param int $id The Attachment ID.
|
|
*
|
|
* @return array The ActivityPub Attachment.
|
|
*/
|
|
public static function wp_attachment_to_activity_attachment( $id ) {
|
|
$attachment = array();
|
|
$mime_type = \get_post_mime_type( $id );
|
|
$mime_type_parts = \explode( '/', $mime_type );
|
|
// switching on image/audio/video
|
|
switch ( $mime_type_parts[0] ) {
|
|
case 'image':
|
|
$image_size = 'full';
|
|
|
|
/**
|
|
* Filter the image URL returned for each post.
|
|
*
|
|
* @param array|false $thumbnail The image URL, or false if no image is available.
|
|
* @param int $id The attachment ID.
|
|
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
|
*/
|
|
$thumbnail = apply_filters(
|
|
'activitypub_get_image',
|
|
self::get_wordpress_attachment( $id, $image_size ),
|
|
$id,
|
|
$image_size
|
|
);
|
|
|
|
if ( $thumbnail ) {
|
|
$alt = \get_post_meta( $id, '_wp_attachment_image_alt', true );
|
|
$image = array(
|
|
'type' => 'Image',
|
|
'url' => $thumbnail[0],
|
|
'mediaType' => $mime_type,
|
|
);
|
|
|
|
if ( $alt ) {
|
|
$image['name'] = $alt;
|
|
}
|
|
$attachment = $image;
|
|
}
|
|
break;
|
|
|
|
case 'audio':
|
|
case 'video':
|
|
$attachment = array(
|
|
'type' => 'Document',
|
|
'mediaType' => $mime_type,
|
|
'url' => \wp_get_attachment_url( $id ),
|
|
'name' => \get_the_title( $id ),
|
|
);
|
|
$meta = wp_get_attachment_metadata( $id );
|
|
// height and width for videos
|
|
if ( isset( $meta['width'] ) && isset( $meta['height'] ) ) {
|
|
$attachment['width'] = $meta['width'];
|
|
$attachment['height'] = $meta['height'];
|
|
}
|
|
// @todo: add `icon` support for audio/video attachments. Maybe use post thumbnail?
|
|
break;
|
|
}
|
|
|
|
return \apply_filters( 'activitypub_attachment', $attachment, $id );
|
|
}
|
|
|
|
/**
|
|
* Return details about an image attachment.
|
|
*
|
|
* @param int $id The attachment ID.
|
|
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
|
*
|
|
* @return array|false Array of image data, or boolean false if no image is available.
|
|
*/
|
|
protected static function get_wordpress_attachment( $id, $image_size = 'full' ) {
|
|
/**
|
|
* Hook into the image retrieval process. Before image retrieval.
|
|
*
|
|
* @param int $id The attachment ID.
|
|
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
|
*/
|
|
do_action( 'activitypub_get_image_pre', $id, $image_size );
|
|
|
|
$image = \wp_get_attachment_image_src( $id, $image_size );
|
|
|
|
/**
|
|
* Hook into the image retrieval process. After image retrieval.
|
|
*
|
|
* @param int $id The attachment ID.
|
|
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
|
*/
|
|
do_action( 'activitypub_get_image_post', $id, $image_size );
|
|
|
|
return $image;
|
|
}
|
|
|
|
/**
|
|
* Returns the ActivityStreams 2.0 Object-Type for a Post based on the
|
|
* settings and the Post-Type.
|
|
*
|
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
|
|
*
|
|
* @return string The Object-Type.
|
|
*/
|
|
protected function get_object_type() {
|
|
if ( 'wordpress-post-format' !== \get_option( 'activitypub_object_type', 'note' ) ) {
|
|
return \ucfirst( \get_option( 'activitypub_object_type', 'note' ) );
|
|
}
|
|
|
|
// Default to Article.
|
|
$object_type = 'Article';
|
|
$post_type = \get_post_type( $this->object );
|
|
switch ( $post_type ) {
|
|
case 'post':
|
|
$post_format = \get_post_format( $this->object );
|
|
switch ( $post_format ) {
|
|
case 'aside':
|
|
case 'status':
|
|
case 'quote':
|
|
case 'note':
|
|
$object_type = 'Note';
|
|
break;
|
|
case 'gallery':
|
|
case 'image':
|
|
$object_type = 'Image';
|
|
break;
|
|
case 'video':
|
|
$object_type = 'Video';
|
|
break;
|
|
case 'audio':
|
|
$object_type = 'Audio';
|
|
break;
|
|
default:
|
|
$object_type = 'Article';
|
|
break;
|
|
}
|
|
break;
|
|
case 'page':
|
|
$object_type = 'Page';
|
|
break;
|
|
case 'attachment':
|
|
$mime_type = \get_post_mime_type();
|
|
$media_type = \preg_replace( '/(\/[a-zA-Z]+)/i', '', $mime_type );
|
|
switch ( $media_type ) {
|
|
case 'audio':
|
|
$object_type = 'Audio';
|
|
break;
|
|
case 'video':
|
|
$object_type = 'Video';
|
|
break;
|
|
case 'image':
|
|
$object_type = 'Image';
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
$object_type = 'Article';
|
|
break;
|
|
}
|
|
|
|
return $object_type;
|
|
}
|
|
|
|
/**
|
|
* Returns a list of Mentions, used in the Post.
|
|
*
|
|
* @see https://docs.joinmastodon.org/spec/activitypub/#Mention
|
|
*
|
|
* @return array The list of Mentions.
|
|
*/
|
|
protected function get_cc() {
|
|
$cc = array();
|
|
|
|
$mentions = $this->get_mentions();
|
|
if ( $mentions ) {
|
|
foreach ( $mentions as $url ) {
|
|
$cc[] = $url;
|
|
}
|
|
}
|
|
|
|
return $cc;
|
|
}
|
|
|
|
/**
|
|
* Returns a list of Tags, used in the Post.
|
|
*
|
|
* This includes Hash-Tags and Mentions.
|
|
*
|
|
* @return array The list of Tags.
|
|
*/
|
|
protected function get_tag() {
|
|
$tags = array();
|
|
|
|
$post_tags = \get_the_tags( $this->object->ID );
|
|
if ( $post_tags ) {
|
|
foreach ( $post_tags as $post_tag ) {
|
|
$tag = array(
|
|
'type' => 'Hashtag',
|
|
'href' => \esc_url( \get_tag_link( $post_tag->term_id ) ),
|
|
'name' => esc_hashtag( $post_tag->name ),
|
|
);
|
|
$tags[] = $tag;
|
|
}
|
|
}
|
|
|
|
$mentions = $this->get_mentions();
|
|
if ( $mentions ) {
|
|
foreach ( $mentions as $mention => $url ) {
|
|
$tag = array(
|
|
'type' => 'Mention',
|
|
'href' => \esc_url( $url ),
|
|
'name' => \esc_html( $mention ),
|
|
);
|
|
$tags[] = $tag;
|
|
}
|
|
}
|
|
|
|
return $tags;
|
|
}
|
|
|
|
/**
|
|
* Returns the content for the ActivityPub Item.
|
|
*
|
|
* The content will be generated based on the user settings.
|
|
*
|
|
* @return string The content.
|
|
*/
|
|
protected function get_content() {
|
|
global $post;
|
|
|
|
/**
|
|
* Provides an action hook so plugins can add their own hooks/filters before AP content is generated.
|
|
*
|
|
* Example: if a plugin adds a filter to `the_content` to add a button to the end of posts, it can also remove that filter here.
|
|
*
|
|
* @param WP_Post $post The post object.
|
|
*/
|
|
do_action( 'activitypub_before_get_content', $post );
|
|
|
|
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
|
$post = $this->object;
|
|
$content = $this->get_post_content_template();
|
|
|
|
// Register our shortcodes just in time.
|
|
Shortcodes::register();
|
|
// Fill in the shortcodes.
|
|
setup_postdata( $post );
|
|
$content = do_shortcode( $content );
|
|
wp_reset_postdata();
|
|
|
|
$content = \wpautop( $content );
|
|
$content = \preg_replace( '/[\n\r\t]/', '', $content );
|
|
$content = \trim( $content );
|
|
|
|
$content = \apply_filters( 'activitypub_the_content', $content, $post );
|
|
|
|
// Don't need these any more, should never appear in a post.
|
|
Shortcodes::unregister();
|
|
|
|
return $content;
|
|
}
|
|
|
|
/**
|
|
* Gets the template to use to generate the content of the activitypub item.
|
|
*
|
|
* @return string The Template.
|
|
*/
|
|
protected function get_post_content_template() {
|
|
$type = \get_option( 'activitypub_post_content_type', 'content' );
|
|
|
|
switch ( $type ) {
|
|
case 'excerpt':
|
|
$template = "[ap_excerpt]\n\n[ap_permalink type=\"html\"]";
|
|
break;
|
|
case 'title':
|
|
$template = "[ap_title]\n\n[ap_permalink type=\"html\"]";
|
|
break;
|
|
case 'content':
|
|
$template = "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]";
|
|
break;
|
|
default:
|
|
$template = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
|
|
break;
|
|
}
|
|
|
|
return apply_filters( 'activitypub_object_content_template', $template, $this->object );
|
|
}
|
|
|
|
/**
|
|
* Helper function to get the @-Mentions from the post content.
|
|
*
|
|
* @return array The list of @-Mentions.
|
|
*/
|
|
protected function get_mentions() {
|
|
return apply_filters( 'activitypub_extract_mentions', array(), $this->object->post_content, $this->object );
|
|
}
|
|
|
|
/**
|
|
* Returns the locale of the post.
|
|
*
|
|
* @return string The locale of the post.
|
|
*/
|
|
public function get_locale() {
|
|
$post_id = $this->object->ID;
|
|
$lang = \strtolower( \strtok( \get_locale(), '_-' ) );
|
|
|
|
/**
|
|
* Filter the locale of the post.
|
|
*
|
|
* @param string $lang The locale of the post.
|
|
* @param int $post_id The post ID.
|
|
* @param WP_Post $post The post object.
|
|
*
|
|
* @return string The filtered locale of the post.
|
|
*/
|
|
return apply_filters( 'activitypub_post_locale', $lang, $post_id, $this->object );
|
|
}
|
|
}
|