From a5f19f49d1e54a01f8e16a375effe5379fd1de5f Mon Sep 17 00:00:00 2001 From: Greg Ross Date: Sun, 7 Jan 2024 18:16:42 -0500 Subject: [PATCH] Convert hashtags to categories/tags. Scan the body for anything that matches a category or tag name that starts with a hashtag. --- includes/class-mastodon-api.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/class-mastodon-api.php b/includes/class-mastodon-api.php index 831b6133..e27ff30d 100644 --- a/includes/class-mastodon-api.php +++ b/includes/class-mastodon-api.php @@ -1363,6 +1363,22 @@ public function api_submit_post( $request ) { } } + $categories = get_categories( array( 'orderby' => 'name', 'hide_empty' => false ) ); + $post_data['post_category'] = array(); + foreach( $categories as $category ) { + if( stristr( $status, '#' . $category->name ) !== false ) { + $post_data['post_category'][] = $category->term_id; + } + } + + $tags = get_tags( array( 'orderby' => 'name', 'hide_empty' => false ) ); + $post_data['tags_input'] = array(); + foreach( $tags as $tag ) { + if( stristr( $status, '#' . $tag->name ) !== false ) { + $post_data['tags_input'][] = $tag->name; + } + } + $post_id = wp_insert_post( $post_data ); if ( is_wp_error( $post_id ) ) { return $post_id;