diff --git a/includes/class-mastodon-admin.php b/includes/class-mastodon-admin.php index 87009f7..329c62f 100644 --- a/includes/class-mastodon-admin.php +++ b/includes/class-mastodon-admin.php @@ -692,6 +692,15 @@ function ( $post_type ) { } } + if ( isset( $_POST['create_post_format'] ) ) { + $create_post_format = sanitize_text_field( wp_unslash( $_POST['create_post_format'] ) ); + if ( in_array( $create_post_format, $post_formats ) ) { + $app->set_create_post_format( $create_post_format ); + } else { + $app->set_create_post_format( '' ); + } + } + if ( isset( $_POST['view_post_types'] ) && is_array( $_POST['view_post_types'] ) ) { $view_post_types = array( Mastodon_API::ANNOUNCE_CPT => true, diff --git a/includes/class-mastodon-api.php b/includes/class-mastodon-api.php index b20fa9b..451f61d 100644 --- a/includes/class-mastodon-api.php +++ b/includes/class-mastodon-api.php @@ -1997,16 +1997,8 @@ public function api_submit_post( $request ) { $media_ids = $request->get_param( 'media_ids' ); $scheduled_at = $request->get_param( 'scheduled_at' ); - $app = Mastodon_App::get_current_app(); - $app_post_formats = array(); - if ( $app ) { - $app_post_formats = $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] ); - + $app = Mastodon_App::get_current_app(); + $post_format = $app->get_create_post_format(); $status = apply_filters( 'mastodon_api_submit_status', null, $status_text, $in_reply_to_id, $media_ids, $post_format, $visibility, $scheduled_at, $request ); return $this->validate_entity( $status, Entity\Status::class ); @@ -2386,16 +2378,8 @@ public function api_edit_post( $request ) { $media_ids = $request->get_param( 'media_ids' ); $scheduled_at = $request->get_param( 'scheduled_at' ); - $app = Mastodon_App::get_current_app(); - $app_post_formats = array(); - if ( $app ) { - $app_post_formats = $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] ); - + $app = Mastodon_App::get_current_app(); + $post_format = $app->get_create_post_format(); $status = apply_filters( 'mastodon_api_edit_status', null, $post_id, $status_text, $in_reply_to_id, $media_ids, $post_format, $visibility, $scheduled_at, $request ); return $this->validate_entity( $status, Entity\Status::class ); diff --git a/includes/class-mastodon-app.php b/includes/class-mastodon-app.php index b192a61..07eba8d 100644 --- a/includes/class-mastodon-app.php +++ b/includes/class-mastodon-app.php @@ -107,6 +107,15 @@ public function get_create_post_type() { return $create_post_type; } + public function get_create_post_format( $raw = false ) { + $create_post_format = get_term_meta( $this->term->term_id, 'create_post_format', true ); + if ( ! $create_post_format && ! $raw ) { + $post_formats = $this->get_post_formats(); + $create_post_format = reset( $post_formats ); + } + return $create_post_format; + } + public function get_view_post_types() { $view_post_types = get_term_meta( $this->term->term_id, 'view_post_types', true ); if ( ! $view_post_types ) { @@ -144,6 +153,10 @@ public function set_create_post_type( $create_post_type ) { return update_term_meta( $this->term->term_id, 'create_post_type', $create_post_type ); } + public function set_create_post_format( $create_post_format ) { + return update_term_meta( $this->term->term_id, 'create_post_format', $create_post_format ); + } + public function set_view_post_types( $view_post_types ) { return update_term_meta( $this->term->term_id, 'view_post_types', $view_post_types ); } @@ -256,6 +269,13 @@ public function get_current_settings_text( string $content = '' ) { $content .= PHP_EOL . _x( 'Create new posts as', 'select post type', 'enable-mastodon-apps' ) . ': '; $content .= get_post_type_object( $this->get_create_post_type() )->labels->singular_name; + $content .= PHP_EOL . _x( 'in the post format', 'select post type', 'enable-mastodon-apps' ) . ': '; + foreach ( get_post_format_strings() as $slug => $name ) { + if ( $slug === $this->get_create_post_format() ) { + $content .= $name; + break; + } + } $t = PHP_EOL . __( 'Show these post types', 'enable-mastodon-apps' ) . ': '; foreach ( $this->get_view_post_types() as $post_type ) { if ( in_array( $post_type, array( Mastodon_API::ANNOUNCE_CPT, Mastodon_API::POST_CPT ), true ) ) { diff --git a/templates/app.php b/templates/app.php index 585f727..72c2fdd 100644 --- a/templates/app.php +++ b/templates/app.php @@ -29,6 +29,10 @@ ) ); $app_post_formats = $app->get_post_formats(); +$selected_post_format = $app->get_create_post_format(); +if ( ! $selected_post_format ) { + $selected_post_format = 'standard'; +} ?>
@@ -140,6 +144,17 @@ + +


@@ -217,17 +232,7 @@ ) ); ?> - - +

@@ -282,3 +287,35 @@
+ diff --git a/templates/registered-apps.php b/templates/registered-apps.php index 7602587..dd2312e 100644 --- a/templates/registered-apps.php +++ b/templates/registered-apps.php @@ -42,8 +42,10 @@ - - + + + + @@ -68,16 +70,49 @@ ?> ', is_array( $app->get_redirect_uris() ) ? $app->get_redirect_uris() : explode( ',', $app->get_redirect_uris() ) ), array( 'br' => array() ) ); ?> - get_scopes() ); ?> - + $label ) { - if ( in_array( $format, $app->get_post_formats() ) ) { - echo esc_html( $label ) . '
'; + $_post_type = get_post_type_object( $app->get_create_post_type() ); + echo esc_html( $_post_type->labels->singular_name ); + ?> + + + get_create_post_format() ) { + echo esc_html_x( 'Standard', 'Post format' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain + + } else { + foreach ( get_post_format_strings() as $slug => $name ) { + if ( $slug === $app->get_create_post_format() ) { + echo esc_html( $name ); + break; + } } } ?> + + get_post_formats(); + if ( empty( $post_formats ) ) { + echo esc_html( __( 'All' ) ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain + } else { + echo esc_html( + implode( + ', ', + array_map( + function ( $slug ) { + return get_post_format_strings()[ $slug ]; + }, + $post_formats + ) + ) + ); + } + ?> + + get_scopes() ); ?> get_last_used() ); ?> get_creation_date() ); ?> diff --git a/tests/test-statuses-endpoint.php b/tests/test-statuses-endpoint.php index 27dc055..10abf84 100644 --- a/tests/test-statuses-endpoint.php +++ b/tests/test-statuses-endpoint.php @@ -165,6 +165,7 @@ public function submit_status_data_provider() { */ public function test_submit_status( $status, $new_format, $new_post_type, $disable_blocks, $expected_title, $expected_content ) { $this->app->set_post_formats( $new_format ); + $this->app->set_create_post_format( $new_format ); $this->app->set_create_post_type( $new_post_type ); $this->app->set_disable_blocks( $disable_blocks );