Snippet Repo

Continuing the discussion from The problem with relying on WP Software while running CP:

I really like the idea of a snippet repo, I think the best way to accomplish this would be hosting it on GitHub and allowing users to submit PRs to add new snippets. Thoughts?

Similar to the ClassicCommerce Snippets

1 Like

Would it work from GitHub gists?

CC code snippets are not on GitHub. They are embedded into the posts, similar to how code is embedded into the documentation guides.

These will rarely change, so I think for simplicity’s sake we don’t need Gists and continue using already available syntax highlighter on the docs site.

I would put them under Developer Guides, since this is more developer-oriented. Regular users might not know how to edit code or access files via FTP or cPanel File Manager, etc. I would add taxonomy support (extend Categories or Tags to support CPTs) and create a Snippets taxonomy so we can have a way to filter snippet posts if necessary.

Another option is to create a custom post type Snippets, and keep it separate.

I would use a CPT for these snippets to keep things clean, but import them from Github gists precisely so they can be improved and iterated upon through comments and PRs.

1 Like

Would this make sense to throw on to the directory? We would have “Plugins”, “Themes”, “Snippets” and “Developers”?

Would this be just a library to copy/paste? Or would users be able to “install” snippets on their websites?

1 Like

Copy/paste, IMO. And with a recommendation to add the snips to a utility plugin instead of functions.php.


Seems like the most used ones would be incorporated into core.

I would suggest that the recommendation be either a utility plugin or (my own strong preference) an mu-plugin.

And yes, @joyously, this would be a good way of testing whether any of these gists should be incorporated into core.

1 Like

The problem with snippets on the doc site - as much I’d love it - are 2:

  • we have no forms to submit anything, thus either Git or this forum would be required to act as a “submission place” for people to add their snips (if ever someone is going to add a snippet, that is)
  • if we have it on our doc sooner or later someone is going to say “my site is broken because of the code you told me to use”.

If the snips are on git, it is less “official”, can still be vetted, and is easier for people to submit and for us to manage.

For example we could create a repo, where you can only PR to it, and snips would need to be vetted minimally to get merged.
That does not make it a officially “Documented” code, but also is not just a random Gist.

I dislike externalising this to Git very much, would love to keep it all on docs, but … I am not sure the risks justify the means here.

It’s a great idea. Compiling the CC Snippets was one of the most useful things I ever did, and I still refer back to it. Having a similar collection for CP would be a big step toward helping people break away from their WP-plugin dependence.

From memory (and it is very vague), I started out using gist but eventually moved to a CPT. I bodged up a syntax highlighter and I seem to remember there were some moves to make my jumbled mess of code into a CP research plugin… I think this is it here:

Edit. @omukiguy was involved so he might have more idea (and a better memory)

1 Like

There is no reason snippets can’t be stored in a GitHub Repo which allows people to make PRs with new ones, but still be shown on a site?

1 Like

What is wrong with using comments on the CP site?
The WP Code Reference has feedback, which is monitored. There are a lot of good snippets in there. CP could use the same workflow of moderated comments. You don’t need GitHub, and it’s a separate account in order to contribute.

1 Like

I agree, using CP for CP would be simple without adding GitHub to complicate things. If we consider the snippets we want to catalog, these will rarely change. I don’t think this warrants version control for each snippet, and basic revisions would suffice.

New snippets should be posted here in the forum to be reviewed and discussed, and listed on the site once approved. They could be tagged with “code-snippet” tag in Documentation forum.

If we use comments for feedback, edits, notes, etc. then we should either allow forum users to become subscribers to leave comments or add hCaptcha to prevent spam (and CP can earn money too).

I think we all forgot what happened to the old documentation that lived on GitHub :grin: Nobody ever submitted anything or added anything to it. Let’s not make that mistake again.

Edit: Each snippet should have it’s own page/post. We can create them all at once with just the code snippets, and then some of us can go in and start writing descriptions and instructions as needed.

Documentation and code are completely different things. We do PRs for code on Github now; I don’t see why we shouldn’t replicate that for gists.

It’s not about version control. It’s about wanting them to be a model of good practice, not the mish-mash that you see on the WP documentation site.

This also avoids the need to add anyone as users just to comment (and please don’t ever suggest captcha!). I don’t understand why we’d want comments there at all anyway. That’s what this forum is for.


I agree with Tim, I also think this helps getting more eyes on these snippets since it is public prior to including it on our “official” snippet repo vs having a select few people who would review and approve them.

1 Like

I’m not against using Gists, just want to make sure we understand what we’re doing and the issues that this brings. Two problems I’ve always had with Gists are lack of categorization feature and inability to disable comments. So people would leave comments on Gists and we would have to deal with those too. Unless that would also be an acceptable way to suggest changes and discuss code snippets.

If we have gists as a distinct CPT on the website, we could use custom taxonomies to sort them. As a CPT, turning comments off is easy.

Remember I’m not suggesting Github instead of a CPT, but rather that they should be linked.

1 Like

I never liked Gists.
One thing that has been the topic of the WP docs team lately is how to consolidate the issue tracking for all their various docs.
So keep that in mind as you build out more and more things in various places like GitHub, Slack, forums, CP docs site.
The difficulty is for users finding where to comment or submit a suggestion, and for contributors to know where each piece is handled and get set up to contribute.

1 Like

Your warning is valid, @joyously. In fact, that’s a lesson that CP has learned. But I don’t see that as a problem here.

In fact, what we’d be doing by using Github gists coupled with a CPT is emphasizing that code suggestions go on Github, while other comments go on the forum.