post_content, $match ) ) { $tags = array_merge( $tags, $match[1] ); } if ( \preg_match_all( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', $post->post_excerpt, $match ) ) { $tags = array_merge( $tags, $match[1] ); } $tags = \implode( ', ', $tags ); \wp_add_post_tags( $post->ID, $tags ); return $id; } /** * Filter to replace the #tags in the content with links * * @param string $the_content the post-content * * @return string the filtered post-content */ public static function the_content( $the_content ) { return enrich_content_data( $the_content, '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', array( self::class, 'replace_with_links' ) ); } /** * A callback for preg_replace to build the term links * * @param array $result the preg_match results * @return string the final string */ public static function replace_with_links( $result ) { $tag = $result[1]; $tag_object = \get_term_by( 'name', $tag, 'post_tag' ); if ( ! $tag_object ) { $tag_object = \get_term_by( 'name', $tag, 'category' ); } if ( $tag_object ) { $link = \get_term_link( $tag_object, 'post_tag' ); return \sprintf( '', $link, $tag ); } return '#' . $tag; } }