Skip to content

Commit

Permalink
Set the post title before saving the post
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Apr 21, 2023
1 parent d26e82d commit 5c64c8c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions includes/class-mastodon-api.php
Original file line number Diff line number Diff line change
@@ -993,6 +993,18 @@ public function api_submit_post( $request ) {
'post_title' => '',
);

$app_post_formats = $this->app->get_post_formats();
if ( empty( $app_post_formats ) ) {
$app_post_formats = array( 'status' );
}
$post_format = apply_filters( 'mastodon_api_new_post_format', $app_post_formats[0] );
if ( 'standard' === $post_format ) {
// Use the first line of a post as the post title if we're using a standard post format.
list( $post_title, $post_content ) = explode( PHP_EOL, $post_data['post_content'], 2 );
$post_data['post_title'] = $post_title;
$post_data['post_content'] = trim( $post_content );
}

if ( $parent_post ) {
$post_data['post_parent'] = $parent_post->ID;
}
@@ -1026,17 +1038,7 @@ public function api_submit_post( $request ) {
return $post_id;
}

$app_post_formats = $this->app->get_post_formats();
if ( empty( $app_post_formats ) ) {
$app_post_formats = array( 'status' );
}
$post_format = apply_filters( 'mastodon_api_new_post_format', $app_post_formats[0] );
if ( 'standard' === $post_format ) {
// Use the first line of a post as the post title if we're using a standard post format.
list( $post_title, $post_content ) = explode( PHP_EOL, $post_data['post_content'], 2 );
$post_data['post_title'] = $post_title;
$post_data['post_content'] = trim( $post_content );
} else {
if ( 'standard' !== $post_format ) {
set_post_format( $post_id, $post_format );
}

0 comments on commit 5c64c8c

Please sign in to comment.