0

I'm working on a WP plugin called WP SoundSystem. It's a plugin designed to run on a "music" website : it handles artists, tracks, albums, playlists... through custom post types and tools. You can see it running on Spiff Radio.

When I publish a new playlist, my function checks every track row from the tracklist and either create a new track post; or returns the ID of the existing track post if it exists (I have a function that checks for the same artist + title + album post metas). Then a list of track IDs is stored as a post meta of the tracklist post.

enter image description here

I designed it like that because I guess it would be a bad idea to add the same track several times; but should better have ONE track with the most accurate informations possible (featured image, audio sources links, etc).

But this brings another problem. I would like to add user-oriented functions to my plugin, among which the ability to create new playlists frontend and/or to add tracks to their existing playlists.

But then, what about the track posts ?

  • What if user A adds a track from user B to its playlist; but that user B deletes the track afterwards ? Or something like that ?
  • Should I remove the delete_post capability for those users ?
  • Should I "transfer" the ownership of the track to user A instead of deleting the post ?
  • Who can edit that track post ?

As you can see, I'm hesitant about the way I store tracks, capabilities I should give to my users, and the way this works.

Or maybe that, instead of storing a list of track IDs for a playlist; I should store a list of track datas (artist+title+album) ?

Have you got any advices on this ? Thanks !

1

1 Answer 1

1

The question is: How do you want to handle it?

From what I understand, you're currently trying to build up a song ("track post") database, from which users should be able to pick from for their playlists. With every user being able to add new songs.

You could solve this in a similar fashion to how StackExchange works: add a Community user. Whenever a song is created, its ownership gets transferred to the Community user. Then add custom capabilities which refer to that Community user. Who can edit posts, who delete, ...?

In this basic version, it might turn out that a user is not able to edit/delete a song s/he initially created. You can even achieve that by saving the original creator as a meta field, hooking into user_has_cap.

5
  • Yes, you understood the thing. And this seems to be a good lead. Let me think about it ! Thanks...
    – gordie
    Jul 2, 2017 at 21:10
  • ...But what is the point of creating a community user ? Why not just setup a "community" role and adjust its capabilities ? Thanks
    – gordie
    Jul 3, 2017 at 7:03
  • Well each post needs an author (does it?), so using a community user, you'll make sure the songs won't get deleted, if the user is, etc.
    – kero
    Jul 3, 2017 at 9:26
  • Mhh it doesn't especially needs an author (but that's the way WP works I guess) - and I could eventually remove the delete_*_posts cap ?
    – gordie
    Jul 3, 2017 at 10:54
  • Well, post_author is NOT NULL in the default WP db schema (so an author is needed, even if it is an invalid user id). And yes, you can manage the capabilities via user_has_cap
    – kero
    Jul 3, 2017 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.