File size: 908 Bytes
6778ee0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export const WORDPRESS_PLUGIN_VERSION_SELECTOR =
  'meta[name="plausible-analytics-version"]'

const WORDPRESS_SIGNATURES = ['wp-content', 'wp-includes', 'wp-json']

function scanWpPlugin(document) {
  if (typeof document.querySelector === 'function') {
    const metaTag = document.querySelector(WORDPRESS_PLUGIN_VERSION_SELECTOR)
    return metaTag !== null
  }

  return false
}

function scanWp(html) {
  if (typeof html === 'string') {
    return WORDPRESS_SIGNATURES.some((signature) => {
      return html.includes(signature)
    })
  }

  return false
}

export function checkWordPress(document) {
  if (typeof document === 'object') {
    const wordpressPlugin = scanWpPlugin(document)
    const wordpressLikely =
      wordpressPlugin || scanWp(document.documentElement?.outerHTML)

    return { wordpressPlugin, wordpressLikely }
  }

  return { wordpressPlugin: false, wordpressLikely: false }
}