Skip to content

Commit

Permalink
Show '⁂ Fediverse Preview' link in Row-Actions (#989)
Browse files Browse the repository at this point in the history
* Show '⁂ Preview' link in Row-Actions

* be more precise

* add some more checks

* added changedlog item

* add items to changelog

* only show preview if site supports no blocks

thanks @mattwiebe
  • Loading branch information
pfefferle authored Nov 22, 2024
1 parent 9a485ef commit b729704
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Dev - XXXX-XX-XX

### Added

* Fediverse Preview on post-overview page
* GitHub action to enforce Changelog updates.

### Improved

* Outsource Constants to a separate file
Expand Down
33 changes: 33 additions & 0 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static function init() {
\add_action( 'load-comment.php', array( self::class, 'edit_comment' ) );
\add_action( 'load-post.php', array( self::class, 'edit_post' ) );
\add_action( 'load-edit.php', array( self::class, 'list_posts' ) );
\add_filter( 'page_row_actions', array( self::class, 'row_actions' ), 10, 2 );
\add_filter( 'post_row_actions', array( self::class, 'row_actions' ), 10, 2 );
\add_action( 'personal_options_update', array( self::class, 'save_user_settings' ) );
\add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_scripts' ) );
\add_action( 'admin_notices', array( self::class, 'admin_notices' ) );
Expand Down Expand Up @@ -794,4 +796,35 @@ public static function dashboard_glance_items( $items ) {

return $items;
}

/**
* Add a "⁂ Preview" link to the row actions.
*
* @param array $actions The existing actions.
* @param \WP_Post $post The post object.
*
* @return array The modified actions.
*/
public static function row_actions( $actions, $post ) {
// check if the post is enabled for ActivityPub.
if (
! \post_type_supports( \get_post_type( $post ), 'activitypub' ) ||
! in_array( $post->post_status, array( 'pending', 'draft', 'future', 'publish' ), true ) ||
! \current_user_can( 'edit_post', $post->ID ) ||
ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL === get_content_visibility( $post ) ||
site_supports_blocks()
) {
return $actions;
}

$preview_url = add_query_arg( 'activitypub', 'true', \get_preview_post_link( $post ) );

$actions['activitypub'] = sprintf(
'<a href="%s" target="_blank">%s</a>',
\esc_url( $preview_url ),
\esc_html__( '⁂ Fediverse Preview', 'activitypub' )
);

return $actions;
}
}
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ For reasons of data protection, it is not possible to see the followers of other

= Dev =

* Added: Fediverse Preview on post-overview page
* Added: GitHub action to enforce Changelog updates.
* Improved: Outsource Constants to a separate file
* Improved: Better handling of `readme.txt` and `README.md`
Expand Down

0 comments on commit b729704

Please sign in to comment.