%s', \esc_url( $post->guid ), \esc_html__( 'Open original page', 'event-bridge-for-activitypub' ) ); return $actions; } /** * Check if a post is both an event post and external (from ActivityPub federation). * * @param WP_Post $post The post. * @return bool */ private static function post_is_external_event_post( $post ) { if ( 'gatherpress_event' !== $post->post_type ) { return false; } return str_starts_with( $post->guid, 'https://ga.lan' ) ? true : false; } /** * Modify the user capabilities so that nobody can edit external events. * * @param array $caps Concerned user's capabilities. * @param array $cap Required primitive capabilities for the requested capability. * @param array $user_id The WordPress user ID. * @param array $args Additional args. * * @return array */ public static function disable_editing_for_external_events( $caps, $cap, $user_id, $args ) { if ( 'edit_post' === $cap && isset( $args[0] ) ) { $post_id = $args[0]; $post = get_post( $post_id ); if ( $post && self::post_is_external_event_post( $post ) ) { // Deny editing by returning 'do_not_allow'. return array( 'do_not_allow' ); } } return $caps; } }