add_filter( 'user_has_cap', $this, 'grant_member_page_edit', 10, 4 ); } public function grant_member_page_edit( array $allcaps, array $caps, array $args, \WP_User $user ): array { // $caps holds the primitive caps the meta cap was mapped to, so the // requested meta cap itself is in $args[0]. if ( ! in_array( $args[0] ?? '', [ 'edit_post', 'edit_page' ], true ) ) { return $allcaps; } $post_id = $args[2] ?? null; if ( ! $post_id || 'page' !== get_post_type( $post_id ) ) { return $allcaps; } // Is this a academiccrew member page? $member_id = (int) get_post_meta( $post_id, '_academiccrew_member_id', true ); if ( ! $member_id ) { return $allcaps; } // Does the current user own this member profile? $owner_user_id = (int) get_post_meta( $member_id, '_academiccrew_wp_user_id', true ); if ( $owner_user_id && $owner_user_id === $user->ID ) { // Grant the primitive caps this meta cap maps to (edit_pages, // edit_published_pages, …), for this one page only. foreach ( $caps as $cap ) { $allcaps[ $cap ] = true; } } return $allcaps; } }