Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-10-31 10:32:25

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Is txp:if_plugin version attribute semver compatible?

Hi!

I’m thinking about packaged themes now that the theme support is close to being rolled into Textpattern 4.7. Specifically how themes can be enhanced with plugins.

What I don’t want to do is force the WordPress-like behaviour of making users install copious plugins in oder to get a theme to work – that behaviour leads to broken themes and security holes when plugins aren’t kept up-to-date or aren’t well written in the first place. In fact I’m keen that Textpattern themes work on a basic level without any plugins at all.

However, I am in favour of progressively enhancing themes depending on if certain plugins are installed. Which rather ramblingly leads me to my question:

We have the tag <txp:if_plug> which allows for checking whether a plugin is installed and can do stuff conditionally when the plugin is indeed install – which is great. However, the version attribute for that tag; does it support semantic versioning? For example if I use…

<txp:if_plugin name="etc_pagination" version="0.5">
    ...stuff here...
</txp:if_plugin>

…then does that recognise 0.5.2 for example as meeting that criteria, or does it try to look for exact 0.5 only and flip out when it sees 0.5.2? That is quite fundamental to themes working as I intend – we need it to be semver compatible.

Let me know. If it does then I can simply update the tag doc page to document that fact. If not then I’d really like it to be fixed.

Offline

#2 2017-10-31 11:20:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,273
Website GitHub

Re: Is txp:if_plugin version attribute semver compatible?

The tag uses version_compare which is pretty much semver compliant (although it doesn’t state so in the PHP docs, so maybe there are corner cases). We should be good to go here. Try it out with any installed plugin by specifying any lower version number and see what happens.

However, I doubt it’s clever enough to figure major/minor dependencies. If you say that a plugin must be “1.2” it’ll render contained content if the plugin is 1.2, 1.2.1, 1.2.2, 1.2.3-beta, 1.3, 1.4, 1.5, 2.0, 2.1, 3.0, … The point is, it won’t stop at the “current stable branch” but will dutifully allow you to show content if the version is anything greater than or equal to the version specified in the tag.

Last edited by Bloke (2017-10-31 11:22:18)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2017-10-31 11:23:17

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Is txp:if_plugin version attribute semver compatible?

Bloke wrote #307582:

However, I doubt it’s clever enough to figure major/minor dependencies. If you say that a plugin must be “1.2” it’ll render contained content if the plugin is 1.2, 1.2.1, 1.2.2, 1.2.3-beta, 1.3, 1.4, 1.5, 2.0, 2.1, … The point is, it won’t stop at the “current stable branch” but will dutifully allow you to show content if the version is anything greater than the version specified in the tag.

That’s fine, as long as it’s >= 0.5 that works for me. If plugin authors introduce breaking changes between versions (hopefully not, but does happen sometimes) then the theme can be updated for that.

Offline

#4 2017-10-31 11:26:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,273
Website GitHub

Re: Is txp:if_plugin version attribute semver compatible?

Yep, it works. Just tried it.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2017-11-01 08:11:23

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: Is txp:if_plugin version attribute semver compatible?

philwareham wrote #307581:

[…] I am in favour of progressively enhancing themes depending on if certain plugins are installed […]

That’s also my way of thinking about themes.

Bloke wrote #307582:

The tag uses version_compare which is pretty much semver compliant (although it doesn’t state so in the PHP docs, so maybe there are corner cases). We should be good to go here.

Good to know!


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#6 2017-11-01 08:46:04

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Is txp:if_plugin version attribute semver compatible?

OK, I’ve updated the if_plugin tag doc to reflect this.

Offline

Board footer

Powered by FluxBB