@@ -263,6 +263,24 @@ public function process_admin() {
263263 delete_option ( 'mastodon_api_debug_mode ' );
264264 }
265265
266+ if ( isset ( $ _POST ['mastodon_api_announcements_group ' ] ) ) {
267+ $ announcement_types = array (
268+ 'page ' => 'page ' ,
269+ 'post ' => 'post ' ,
270+ 'category ' => 'category ' ,
271+ 'tag ' => 'tag ' ,
272+ );
273+ if ( $ announcement_types [ $ _POST ['mastodon_api_announcements_group ' ] ] === $ _POST ['mastodon_api_announcements_group ' ] ) {
274+ update_option ( 'mastodon_api_announcement_type ' , $ announcement_types [ $ _POST ['mastodon_api_announcements_group ' ] ] );
275+ } else {
276+ update_option ( 'mastodon_api_announcement_type ' , 'default ' );
277+ }
278+ }
279+
280+ if ( isset ( $ _POST ['mastodon_api_announcements_id ' ] ) ) {
281+ update_option ( 'mastodon_api_announcement_id ' , sanitize_text_field ( $ _POST ['mastodon_api_announcements_id ' ] ) );
282+ }
283+
266284 if ( isset ( $ _POST ['mastodon_api_default_post_formats ' ] ) && is_array ( $ _POST ['mastodon_api_default_post_formats ' ] ) ) {
267285 $ default_post_formats = array_filter (
268286 $ _POST ['mastodon_api_default_post_formats ' ],
@@ -327,6 +345,13 @@ public function admin_page() {
327345 $ activitypub_installed = isset ( $ plugins ['activitypub/activitypub.php ' ] );
328346 $ friends_installed = isset ( $ plugins ['friends/friends.php ' ] );
329347
348+ $ announcements_type = get_option ( 'mastodon_api_announcement_type ' , 'default ' );
349+ $ announcements_id = get_option ( 'mastodon_api_announcement_id ' , false );
350+
351+ if ( false === $ announcements_type ) {
352+ $ announcements_type = 'default ' ;
353+ }
354+
330355 function output_request_log ( $ request , $ rest_nonce ) {
331356 $ date = \DateTimeImmutable::createFromFormat ( 'U.u ' , $ request ['timestamp ' ] );
332357 $ url = add_query_arg (
@@ -523,6 +548,37 @@ function td_timestamp( $timestamp, $strikethrough_past = false ) {
523548 </details>
524549 </td>
525550 </tr>
551+ <tr>
552+ <th scope="row"><?php esc_html_e ( 'Announcements Type ' , 'enable-mastodon-apps ' ); ?> </th>
553+ <td>
554+ <fieldset>
555+ <input type="radio" value="default" name="mastodon_api_announcements_group" id="mastodon_api_annoucments_default"<?php checked ( $ announcements_type , 'default ' ); ?> >
556+ <label for="mastodon_api_announcements_group"><?php esc_html_e ( 'Default ' , 'enable-mastodon-apps ' ); ?> </label><br>
557+ <input type="radio" value="post" name="mastodon_api_announcements_group" id="mastodon_api_annoucments_post"<?php checked ( $ announcements_type , 'post ' ); ?> >
558+ <label for="mastodon_api_announcements_group"><?php esc_html_e ( 'Single Post ' , 'enable-mastodon-apps ' ); ?> </label><br>
559+ <input type="radio" value="page" name="mastodon_api_announcements_group" id="mastodon_api_annoucments_page"<?php checked ( $ announcements_type , 'page ' ); ?> >
560+ <label for="mastodon_api_announcements_group"><?php esc_html_e ( 'Single Page ' , 'enable-mastodon-apps ' ); ?> </label><br>
561+ <input type="radio" value="category" name="mastodon_api_announcements_group" id="mastodon_api_annoucments_category"<?php checked ( $ announcements_type , 'category ' ); ?> >
562+ <label for="mastodon_api_announcements_group"><?php esc_html_e ( 'All posts in a category ' , 'enable-mastodon-apps ' ); ?> </label><br>
563+ <input type="radio" value="tag" name="mastodon_api_announcements_group" id="mastodon_api_annoucments_tag"<?php checked ( $ announcements_type , 'tag ' ); ?> >
564+ <label for="mastodon_api_announcements_group"><?php esc_html_e ( 'All posts with a tag ' , 'enable-mastodon-apps ' ); ?> </label><br>
565+ </fieldset>
566+ <p class="description">
567+ <?php esc_html_e ( 'Select one of the above to use for the Mastodon annoucments tab. ' , 'enable-mastodon-apps ' ); ?>
568+ </p>
569+ </td>
570+ </tr>
571+ <tr>
572+ <th scope="row"><?php esc_html_e ( 'Announcements ID ' , 'enable-mastodon-apps ' ); ?> </th>
573+ <td>
574+ <fieldset>
575+ <input type="text" id="mastodon_api_announcements_id" name="mastodon_api_announcements_id" value="<?php echo sanitize_text_field ( $ announcements_id ); ?> ">
576+ </fieldset>
577+ <p class="description">
578+ <?php esc_html_e ( 'Enter the post id, page id, category slug, or tag slug to use for annoucments as selected above. ' , 'enable-mastodon-apps ' ); ?>
579+ </p>
580+ </td>
581+ </tr>
526582 </tbody>
527583 </table>
528584
0 commit comments