Skip to content

Adds wordpress detection #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

housseindjirdeh
Copy link
Collaborator

Copy link
Contributor

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone brought up

Since WordPress 4.4, there should be a link element in the header with a rel attribute equal to api.w.org and a href attribute equal to the site's URL.

I think that's our strongest signal. Falling back on wp-includes sg.

I was thinking something like this, but I'm open to alternatives..

const hasAPILinkElem = ....
const hasWPIncludes = ...
if (!hasAPILinkElem || !hasWPIncludes) return false;

const generatorMeta = ...
const version = ...
if (version) return { version }
else return { version: UNKNOWN_VERSION };

test: function (win) {
if (!!document.querySelector('meta[name=generator][content^="WordPress"]')) {
var versionName = document.querySelector("meta[name='generator']").getAttribute("content");
return { version: versionName.replace(/[^0-9\.]+/g,"") };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

over on https://wordpress.org/news/ i spotted WordPress 5.2-alpha-44796 so I think we'll need something different..
.replace(/^\w+\s/,'') perhaps?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. The version can look like any one of:

  • 5.1.2
  • 5.1-beta2
  • 5.0-RC1
  • 5.2-alpha-44742-src

So yes, just removing 'WordPress ' from the beginning will be the way to go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh didn't know more than just numbered releases could be included. Fixed 👍

@housseindjirdeh
Copy link
Collaborator Author

@paulirish Updated it to your suggestion. I think it looks good.

One thing however: I used if (!hasAPILinkElem && !hasWPIncludes) instead of ||. I'm assuming that we would want to fallback to wp-includes for WordPress versions older than 4.4, but somebody correct me if I'm wrong.

CC @Shelob9

Copy link
Contributor

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree on the &&. :) good call.

this looks great.

@Shelob9
Copy link

Shelob9 commented Mar 7, 2019

@housseindjirdeh This looks good to me.

@housseindjirdeh housseindjirdeh merged commit 1247833 into johnmichel:master Mar 7, 2019
@westonruter
Copy link

Note: As of WordPress 6.3.0, sites will no longer be outputting this link:

<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="https://example.com/wp-includes/wlwmanifest.xml">

The logic needs to be updated to not depend on it. See #203.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants