opencredit / badgeos

BadgeOS is a plugin to WordPress that allows you to easily create badges and set up the steps and achievements users take to earn them. Badges are Mozilla OBI compatible and sharable via Credly.
http://www.badgeos.org
GNU Affero General Public License v3.0
92 stars 64 forks source link

Modify layout of badgeos_render_achievement #483

Open cyclingzealot opened 9 years ago

cyclingzealot commented 9 years ago

This may be too big of a question for some free advice.... happy to compensate fairly for your time.

If I have a customer that would like to modify the layout when all of a user achivement's is listed in it's buddy press profile. This is produced by badgeos_render_achievement in badgeos/includes/content-filters.php (line 393).

Is using the filter hook badgeos_render_achievement the only way? If so, I'm thinking of using XPath and DOMNode.

The requested change requires removing divs and changing width attributes.

I recall the conversation in https://github.com/opencredit/badgeos/issues/466 where you mention archive.php. If I had, in my theme, a archive-quest.php or archive-badge.php or archive-$whateverTheAchivementPostType is named, would that override the call to badgeos_render_achievement?

Rewritting the code would mean I can't contribute back upstream, unless there's a git technique I don't know about.

tw2113 commented 9 years ago

The template used isn't going to be overwritten by anything, because the badgeos_render_achievement isn't used at that level. From what I can see in the codebase, that function is used in the ajax callback for fetching achievements, most frequently used with [badgeos_achievements_list] as well as the single [badgeos_achievement] shortcode output.

As is, until we figure some better way out to handle rendering, https://github.com/opencredit/badgeos/issues/128, the filter is going to be your best bet. I also believe XPath and DOMNode are overkill here. It'd be better and more performant to simply copy/paste the default resulting output and edit as necessary. Essentially rebuild-up yourself instead of taking and trying to whittle away programmatically.

Regarding your last bullet point, if you must manually edit the code itself instead of doing the filter, the trick would be to do a separate git branch. Create a new branch from your current point in the code, and do your edits there. That way, you would still have a copy that you can use to contribute back with.