Plugin Directory

Changeset 3327873


Ignore:
Timestamp:
07/15/2025 03:06:30 AM (9 months ago)
Author:
sethta
Message:

Update to version 1.3.0

Location:
easy-critical-css
Files:
301 added
23 edited

Legend:

Unmodified
Added
Removed
  • easy-critical-css/trunk/assets/admin.css

    r3284313 r3327873  
    3636}
    3737
     38.excluded,
    3839.paused,
    3940.unprocessed {
  • easy-critical-css/trunk/assets/admin.js

    r3284313 r3327873  
    1717
    1818  setupConfirmation('ecc-reset', 'ecc-reset-form')
    19   setupConfirmation('ecc-delete', 'ecc-uninstall-form')
     19  setupConfirmation('ecc-delete', 'ecc-delete-form')
     20  setupConfirmation('ecc-uninstall', 'ecc-uninstall-form')
     21
     22  function toggleDeleteSection() {
     23    const mode = document.querySelector('input[name="easy_cc_critical_css_mode"]:checked')?.value
     24    const section = document.getElementById('ecc-delete-section')
     25    if (!section) return
     26
     27    // Only show when mode is auto
     28    section.style.display = (mode === 'auto') ? '' : 'none'
     29  }
    2030
    2131  function toggleSettingVisibility(settingId, behavior = false) {
     
    4151        toggleSettingVisibility('forced-critical-selectors-container')
    4252        toggleSettingVisibility('forced-secondary-selectors-container', true)
     53        toggleSettingVisibility('add-common-secondary-container', true)
    4354        toggleSettingVisibility('exclude-css-files-container')
    4455        toggleSettingVisibility('ignore-cross-domain-css-container')
     
    4657        toggleSettingVisibility('regenerate-triggers-container')
    4758        toggleSettingVisibility('expired-css-behavior-container')
     59        toggleDeleteSection()
    4860      })
    4961    })
     
    5264      el.addEventListener('change', () => {
    5365        toggleSettingVisibility('forced-secondary-selectors-container', true)
     66        toggleSettingVisibility('add-common-secondary-container', true)
    5467      })
    5568    })
     
    6174  toggleSettingVisibility('forced-critical-selectors-container')
    6275  toggleSettingVisibility('forced-secondary-selectors-container', true)
     76  toggleSettingVisibility('add-common-secondary-container', true)
    6377  toggleSettingVisibility('exclude-css-files-container')
    6478  toggleSettingVisibility('ignore-cross-domain-css-container')
     
    6680  toggleSettingVisibility('regenerate-triggers-container')
    6781  toggleSettingVisibility('expired-css-behavior-container')
     82  toggleDeleteSection()
    6883})
  • easy-critical-css/trunk/build/index.asset.php

    r3284313 r3327873  
    1 <?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'b7abfc10869f68877d2a');
     1<?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '8b825f7979662931e8de');
  • easy-critical-css/trunk/build/index.js

    r3284313 r3327873  
    1 (()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var i in s)e.o(s,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:s[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};window.React;const t=window.wp.plugins,s=window.wp.editor,i=window.wp.data,a=window.wp.components,n=window.wp.i18n,c=window.ReactJSXRuntime,r={completed:(0,n.__)("Completed","easy-critical-css"),expired:(0,n.__)("Expired","easy-critical-css"),failed:(0,n.__)("Failed","easy-critical-css"),invalid:(0,n.__)("Invalid API","easy-critical-css"),paused:(0,n.__)("Paused","easy-critical-css"),unavailable:(0,n.__)("Unavailable","easy-critical-css"),unprocessed:(0,n.__)("Unprocessed","easy-critical-css"),unreachable:(0,n.__)("Unreachable","easy-critical-css"),pending:(0,n.__)("Pending","easy-critical-css"),error:(0,n.__)("Error","easy-critical-css")},o={completed:"#1e7e34",expired:"#995a00",failed:"#b12331",invalid:"#b12331",paused:"#6c757d",unavailable:"#6c757d",unprocessed:"#6c757d",unreachable:"#b12331",pending:"#007cba",error:"#000"},l=({status:e,loading:t,fetchStatus:s})=>(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,c.jsx)("span",{children:(0,n.__)("Status:","easy-critical-css")}),(0,c.jsx)("span",{style:{display:"inline-block",padding:"3px 8px",borderRadius:"12px",background:o[e||"error"],color:"#fff",fontWeight:"500"},children:r[e||"error"]})]}),(0,c.jsx)(a.Button,{onClick:s,variant:"secondary","aria-label":(0,n.__)("Refresh Status","easy-critical-css"),children:t?(0,c.jsx)(a.Spinner,{}):(0,n.__)("Refresh","easy-critical-css")})]}),d=window.wp.element,p=window.wp.apiFetch;var u=e.n(p);const g=({postId:e,fetchStatus:t,status:s,activate_critical_css:i})=>{const[r,o]=(0,d.useState)(!1),[l,p]=(0,d.useState)(null),[g,h]=(0,d.useState)(null);return"paused"!==s&&i?(0,c.jsxs)("div",{style:{marginTop:"10px"},children:[g&&(0,c.jsx)("div",{style:{marginBottom:"10px"},children:(0,c.jsx)(a.Notice,{status:"error",isDismissible:!0,onRemove:()=>h(null),children:g})}),l&&(0,c.jsx)("div",{style:{marginBottom:"10px"},children:(0,c.jsx)(a.Notice,{status:"success",isDismissible:!0,onRemove:()=>p(null),children:l})}),(0,c.jsx)(a.Button,{onClick:async()=>{o(!0),h(null),p(null);try{const s=await u()({path:"/easy-critical-css/v1/generate",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({identifier:e})});if(!s||s.code)throw new Error(s.message||(0,n.__)("An error occurred.","easy-critical-css"));p((0,n.__)("Critical CSS generation started successfully.","easy-critical-css")),t()}catch(e){console.error(e),h(e&&"object"==typeof e&&"message"in e?e.message:(0,n.__)("An unknown error occurred.","easy-critical-css"))}o(!1)},variant:"primary",style:{width:"100%",justifyContent:"center"},children:r?(0,c.jsx)(a.Spinner,{}):"completed"===s||"expired"===s?(0,n.__)("Re-Generate Critical CSS","easy-critical-css"):(0,n.__)("Generate Critical CSS","easy-critical-css")})]}):null},h=({keyName:e,setting:t,settings:s,effectiveMode:i,effectiveSecondaryBehavior:n,handleSettingsChange:r})=>{var o;const l=void 0!==s[e]?s[e]:t.default,d="boolean"==typeof i?String(i):i,p="checkbox"!==t.type,u="object"==typeof t.label?t.label[d]||t.label.auto:t.label,g="object"==typeof t.desc?t.desc[d]||t.desc.auto:t.desc,h={marginRight:"10px",maxWidth:"245px",whiteSpace:"normal",wordWrap:"break-word",textAlign:"left"};return(0,c.jsxs)("div",{children:[p&&(0,c.jsxs)("label",{htmlFor:e,style:{display:"flex",alignItems:"center",fontWeight:"500",marginBottom:"5px"},children:[u,g&&(0,c.jsx)(a.Tooltip,{text:g,style:h,children:(0,c.jsx)("span",{style:{marginLeft:"5px",cursor:"help",color:"#999"},children:(0,c.jsx)(a.Icon,{icon:"editor-help"})})})]}),"checkbox"===t.type&&(0,c.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[(0,c.jsx)(a.CheckboxControl,{label:u,checked:!!l,onChange:t=>r(e,t)},e),g&&(0,c.jsx)(a.Tooltip,{text:g,style:h,children:(0,c.jsx)("span",{style:{marginBottom:"8px",marginLeft:"5px",cursor:"help",color:"#999"},children:(0,c.jsx)(a.Icon,{icon:"editor-help"})})})]}),"select"===t.type&&(0,c.jsx)("select",{id:e,value:String(l),onChange:t=>r(e,t.target.value),style:{width:"100%",padding:"5px"},children:Object.entries(null!==(o=t.options)&&void 0!==o?o:{}).map((([e,t])=>(0,c.jsx)("option",{value:e,children:t},e)))}),"textarea"===t.type&&(0,c.jsx)("textarea",{id:e,value:"string"==typeof l?l:"",onChange:t=>r(e,t.target.value),rows:5,style:{width:"100%",padding:"5px"}}),"text"===t.type&&(0,c.jsx)("input",{id:e,type:"text",value:"string"==typeof l?l:"",onChange:t=>r(e,t.target.value),style:{width:"100%",padding:"5px"}})]},e)},y=({settingsSchema:e,settings:t,effectiveMode:s,effectiveSecondaryBehavior:i,settingsVisible:r,setSettingsVisible:o,handleSettingsChange:l})=>{const d=Object.entries(e).filter((([e,a])=>((e,t,s,i,a)=>{if(!t.visible)return!0;for(const[e,n]of Object.entries(t.visible)){const t=s[e];if("critical_css_mode"===e&&("default"===t?i!==n:t!==n)||"secondary_css_behavior"===e&&("default"===t?a!==n:t!==n)||"critical_css_mode"!==e&&"secondary_css_behavior"!==e&&t!==n)return!1}return!0})(0,a,t,s,i)));return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(a.Button,{type:"button","aria-expanded":r,className:"components-button components-panel__body-toggle",style:{padding:"10px",background:"#f8f8f8",cursor:"pointer",userSelect:"none",marginTop:"15px"},onClick:()=>o(!r),children:[(0,n.__)("Settings","easy-critical-css"),(0,c.jsx)("span",{"aria-hidden":"true",children:(0,c.jsx)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",className:"components-panel__arrow","aria-hidden":"true",focusable:"false",children:r?(0,c.jsx)("path",{d:"M6.5 12.4L12 8l5.5 4.4-.9 1.2L12 10l-4.5 3.6-1-1.2z"}):(0,c.jsx)("path",{d:"M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z"})})})]}),r&&(0,c.jsx)("div",{style:{marginTop:"10px"},children:d.map((([e,a],n,r)=>{const o=n===r.length-1;return(0,c.jsx)("div",{style:{marginBottom:o?"0px":"15px"},children:(0,c.jsx)(h,{keyName:e,setting:a,settings:t,effectiveMode:s,effectiveSecondaryBehavior:i,handleSettingsChange:l})},e)}))})]})},{settingsSchema:f,settings:x,mode:v,secondaryBehavior:_}=eccSettings;(0,t.registerPlugin)("critical-css-sidebar",{render:()=>{const e=(0,i.useSelect)((e=>e("core/editor").getCurrentPostId()),[]),{settings:t,updateSetting:a}=((e,t,s)=>{const[a,n]=(0,d.useState)((()=>({...Object.fromEntries(Object.entries(e).map((([e,t])=>[e,t.default]))),...t}))),{editPost:c}=(0,i.useDispatch)("core/editor");return(0,d.useEffect)((()=>{s&&(async()=>{try{const e=await u()({path:`/easy-critical-css/v1/get-settings/${s}`});n((t=>({...t,...e})))}catch(e){console.error("Error fetching Easy Critical CSS settings:",e)}})()}),[s]),{settings:a,updateSetting:(e,t)=>{n((s=>({...s,[e]:t}))),u()({path:`/easy-critical-css/v1/update-settings/${s}`,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({[e]:t})}).catch((t=>console.error(`Error updating ${e}:`,t))),c({meta:{[e]:t}})}}})(f,x,e),{status:n,loading:r,fetchStatus:o}=((e,t)=>{const[s,i]=(0,d.useState)(null),[a,n]=(0,d.useState)(!1),c=async()=>{if(e){n(!0),console.log("Fetching Critical CSS for Post ID:",e);try{const s=await u()({path:`/easy-critical-css/v1/status/${e}`});i(t?s.status:"paused")}catch(e){const t=e;"invalid_post_id"===t?.code?i("unavailable"):(console.error("Error fetching Critical CSS status:",e),i("error"))}n(!1)}};return(0,d.useEffect)((()=>{c()}),[e,t]),{status:s,loading:a,fetchStatus:c}})(e,t.activate_critical_css);((e,t)=>{const s=(0,i.useSelect)((e=>({isSaving:e("core/editor").isSavingPost()})),[]);(0,d.useEffect)((()=>{s&&(console.log("Saving settings on post save:",t),u()({path:`/easy-critical-css/v1/update-settings/${e}`,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((()=>console.log("Easy Critical CSS Settings saved with post update"))).catch((e=>console.error("Error saving settings with post update:",e))))}),[s])})(e,t);const{effectiveMode:p,effectiveSecondaryBehavior:h}=((e,t,s)=>({effectiveMode:e.critical_css_mode&&"default"!==e.critical_css_mode?e.critical_css_mode:t,effectiveSecondaryBehavior:e.secondary_css_behavior&&"default"!==e.secondary_css_behavior?e.secondary_css_behavior:s}))(t,v,_),{settingsVisible:S,setSettingsVisible:m}=(e=>{const[t,s]=(0,d.useState)(!1);return(0,d.useEffect)((()=>{s("manual"===e)}),[]),{settingsVisible:t,setSettingsVisible:s}})(p);return(0,c.jsxs)(s.PluginDocumentSettingPanel,{name:"easy-critical-css-sidebar",title:"Easy Critical CSS",className:"easy-critical-css-panel",children:["manual"!==p&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(l,{status:n,loading:r,fetchStatus:o}),(0,c.jsx)(g,{postId:e,fetchStatus:o,status:n,activate_critical_css:t.activate_critical_css})]}),(0,c.jsx)(y,{settingsSchema:f,settings:t,effectiveMode:p,effectiveSecondaryBehavior:h,settingsVisible:S,setSettingsVisible:m,handleSettingsChange:a})]})}})})();
     1(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var i in s)e.o(s,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:s[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};window.React;const t=window.wp.plugins,s=window.wp.editor,i=window.wp.data,a=window.wp.components,c=window.wp.i18n,n=window.ReactJSXRuntime,r={completed:(0,c.__)("Completed","easy-critical-css"),expired:(0,c.__)("Expired","easy-critical-css"),excluded:(0,c.__)("Excluded","easy-critical-css"),failed:(0,c.__)("Failed","easy-critical-css"),invalid:(0,c.__)("Invalid API","easy-critical-css"),paused:(0,c.__)("Paused","easy-critical-css"),unavailable:(0,c.__)("Unavailable","easy-critical-css"),unprocessed:(0,c.__)("Unprocessed","easy-critical-css"),unreachable:(0,c.__)("Unreachable","easy-critical-css"),pending:(0,c.__)("Pending","easy-critical-css"),error:(0,c.__)("Error","easy-critical-css")},o={completed:"#1e7e34",expired:"#995a00",excluded:"#6c757d",failed:"#b12331",invalid:"#b12331",paused:"#6c757d",unavailable:"#6c757d",unprocessed:"#6c757d",unreachable:"#b12331",pending:"#007cba",error:"#000"},l=({status:e,loading:t,fetchStatus:s})=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,n.jsx)("span",{children:(0,c.__)("Status:","easy-critical-css")}),(0,n.jsx)("span",{style:{display:"inline-block",padding:"3px 8px",borderRadius:"12px",background:o[e||"error"],color:"#fff",fontWeight:"500"},children:r[e||"error"]})]}),(0,n.jsx)(a.Button,{onClick:s,variant:"secondary","aria-label":(0,c.__)("Refresh Status","easy-critical-css"),children:t?(0,n.jsx)(a.Spinner,{}):(0,c.__)("Refresh","easy-critical-css")})]}),d=window.wp.element,p=window.wp.apiFetch;var u=e.n(p);const g=({postId:e,fetchStatus:t,status:s,activate_critical_css:i})=>{const[r,o]=(0,d.useState)(!1),[l,p]=(0,d.useState)(null),[g,h]=(0,d.useState)(null);return"paused"!==s&&i?(0,n.jsxs)("div",{style:{marginTop:"10px"},children:[g&&(0,n.jsx)("div",{style:{marginBottom:"10px"},children:(0,n.jsx)(a.Notice,{status:"error",isDismissible:!0,onRemove:()=>h(null),children:g})}),l&&(0,n.jsx)("div",{style:{marginBottom:"10px"},children:(0,n.jsx)(a.Notice,{status:"success",isDismissible:!0,onRemove:()=>p(null),children:l})}),(0,n.jsx)(a.Button,{onClick:async()=>{o(!0),h(null),p(null);try{const s=await u()({path:"/easy-critical-css/v1/generate",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({identifier:e})});if(!s||s.code)throw new Error(s.message||(0,c.__)("An error occurred.","easy-critical-css"));p((0,c.__)("Critical CSS generation started successfully.","easy-critical-css")),t()}catch(e){console.error(e),h(e&&"object"==typeof e&&"message"in e?e.message:(0,c.__)("An unknown error occurred.","easy-critical-css"))}o(!1)},variant:"primary",style:{width:"100%",justifyContent:"center"},children:r?(0,n.jsx)(a.Spinner,{}):"completed"===s||"expired"===s?(0,c.__)("Re-Generate Critical CSS","easy-critical-css"):(0,c.__)("Generate Critical CSS","easy-critical-css")})]}):null},h=({keyName:e,setting:t,settings:s,effectiveMode:i,effectiveSecondaryBehavior:c,handleSettingsChange:r})=>{var o;const l=void 0!==s[e]?s[e]:t.default,d="boolean"==typeof i?String(i):i,p="checkbox"!==t.type,u="object"==typeof t.label?t.label[d]||t.label.auto:t.label,g="object"==typeof t.desc?t.desc[d]||t.desc.auto:t.desc,h={marginRight:"10px",maxWidth:"245px",whiteSpace:"normal",wordWrap:"break-word",textAlign:"left"};return(0,n.jsxs)("div",{children:[p&&(0,n.jsxs)("label",{htmlFor:e,style:{display:"flex",alignItems:"center",fontWeight:"500",marginBottom:"5px"},children:[u,g&&(0,n.jsx)(a.Tooltip,{text:g,style:h,children:(0,n.jsx)("span",{style:{marginLeft:"5px",cursor:"help",color:"#999"},children:(0,n.jsx)(a.Icon,{icon:"editor-help"})})})]}),"checkbox"===t.type&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[(0,n.jsx)(a.CheckboxControl,{label:u,checked:!!l,onChange:t=>r(e,t)},e),g&&(0,n.jsx)(a.Tooltip,{text:g,style:h,children:(0,n.jsx)("span",{style:{marginBottom:"8px",marginLeft:"5px",cursor:"help",color:"#999"},children:(0,n.jsx)(a.Icon,{icon:"editor-help"})})})]}),"select"===t.type&&(0,n.jsx)("select",{id:e,value:String(l),onChange:t=>r(e,t.target.value),style:{width:"100%",padding:"5px"},children:Object.entries(null!==(o=t.options)&&void 0!==o?o:{}).map((([e,t])=>(0,n.jsx)("option",{value:e,children:t},e)))}),"textarea"===t.type&&(0,n.jsx)("textarea",{id:e,value:"string"==typeof l?l:"",onChange:t=>r(e,t.target.value),rows:5,style:{width:"100%",padding:"5px"}}),"text"===t.type&&(0,n.jsx)("input",{id:e,type:"text",value:"string"==typeof l?l:"",onChange:t=>r(e,t.target.value),style:{width:"100%",padding:"5px"}})]},e)},y=({settingsSchema:e,settings:t,effectiveMode:s,effectiveSecondaryBehavior:i,settingsVisible:r,setSettingsVisible:o,handleSettingsChange:l})=>{const d=Object.entries(e).filter((([e,a])=>((e,t,s,i,a)=>{if(!t.visible)return!0;for(const[e,c]of Object.entries(t.visible)){const t=s[e];if("critical_css_mode"===e&&("default"===t?i!==c:t!==c)||"secondary_css_behavior"===e&&("default"===t?a!==c:t!==c)||"critical_css_mode"!==e&&"secondary_css_behavior"!==e&&t!==c)return!1}return!0})(0,a,t,s,i)));return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(a.Button,{type:"button","aria-expanded":r,className:"components-button components-panel__body-toggle",style:{padding:"10px",background:"#f8f8f8",cursor:"pointer",userSelect:"none",marginTop:"15px"},onClick:()=>o(!r),children:[(0,c.__)("Settings","easy-critical-css"),(0,n.jsx)("span",{"aria-hidden":"true",children:(0,n.jsx)("svg",{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",className:"components-panel__arrow","aria-hidden":"true",focusable:"false",children:r?(0,n.jsx)("path",{d:"M6.5 12.4L12 8l5.5 4.4-.9 1.2L12 10l-4.5 3.6-1-1.2z"}):(0,n.jsx)("path",{d:"M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z"})})})]}),r&&(0,n.jsx)("div",{style:{marginTop:"10px"},children:d.map((([e,a],c,r)=>{const o=c===r.length-1;return(0,n.jsx)("div",{style:{marginBottom:o?"0px":"15px"},children:(0,n.jsx)(h,{keyName:e,setting:a,settings:t,effectiveMode:s,effectiveSecondaryBehavior:i,handleSettingsChange:l})},e)}))})]})},{settingsSchema:f,settings:x,mode:v,secondaryBehavior:_}=eccSettings;(0,t.registerPlugin)("critical-css-sidebar",{render:()=>{const e=(0,i.useSelect)((e=>e("core/editor").getCurrentPostId()),[]),{settings:t,updateSetting:a}=((e,t,s)=>{const[a,c]=(0,d.useState)((()=>({...Object.fromEntries(Object.entries(e).map((([e,t])=>[e,t.default]))),...t}))),{editPost:n}=(0,i.useDispatch)("core/editor");return(0,d.useEffect)((()=>{s&&(async()=>{try{const e=await u()({path:`/easy-critical-css/v1/get-settings/${s}`});c((t=>({...t,...e})))}catch(e){console.error("Error fetching Easy Critical CSS settings:",e)}})()}),[s]),{settings:a,updateSetting:(e,t)=>{c((s=>({...s,[e]:t}))),u()({path:`/easy-critical-css/v1/update-settings/${s}`,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({[e]:t})}).catch((t=>console.error(`Error updating ${e}:`,t))),n({meta:{[e]:t}})}}})(f,x,e),{status:c,loading:r,fetchStatus:o}=((e,t)=>{const[s,i]=(0,d.useState)(null),[a,c]=(0,d.useState)(!1),n=async()=>{if(e){c(!0),console.log("Fetching Critical CSS for Post ID:",e);try{const s=await u()({path:`/easy-critical-css/v1/status/${e}`});i(t?s.status:"paused")}catch(e){const t=e;"invalid_post_id"===t?.code?i("unavailable"):(console.error("Error fetching Critical CSS status:",e),i("error"))}c(!1)}};return(0,d.useEffect)((()=>{n()}),[e,t]),{status:s,loading:a,fetchStatus:n}})(e,t.activate_critical_css);((e,t)=>{const s=(0,i.useSelect)((e=>({isSaving:e("core/editor").isSavingPost()})),[]);(0,d.useEffect)((()=>{s&&(console.log("Saving settings on post save:",t),u()({path:`/easy-critical-css/v1/update-settings/${e}`,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((()=>console.log("Easy Critical CSS Settings saved with post update"))).catch((e=>console.error("Error saving settings with post update:",e))))}),[s])})(e,t);const{effectiveMode:p,effectiveSecondaryBehavior:h}=((e,t,s)=>({effectiveMode:e.critical_css_mode&&"default"!==e.critical_css_mode?e.critical_css_mode:t,effectiveSecondaryBehavior:e.secondary_css_behavior&&"default"!==e.secondary_css_behavior?e.secondary_css_behavior:s}))(t,v,_),{settingsVisible:S,setSettingsVisible:m}=(e=>{const[t,s]=(0,d.useState)(!1);return(0,d.useEffect)((()=>{s("manual"===e)}),[]),{settingsVisible:t,setSettingsVisible:s}})(p);return(0,n.jsxs)(s.PluginDocumentSettingPanel,{name:"easy-critical-css-sidebar",title:"Easy Critical CSS",className:"easy-critical-css-panel",children:["manual"!==p&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l,{status:c,loading:r,fetchStatus:o}),(0,n.jsx)(g,{postId:e,fetchStatus:o,status:c,activate_critical_css:t.activate_critical_css})]}),(0,n.jsx)(y,{settingsSchema:f,settings:t,effectiveMode:p,effectiveSecondaryBehavior:h,settingsVisible:S,setSettingsVisible:m,handleSettingsChange:a})]})}})})();
  • easy-critical-css/trunk/easy-critical-css.php

    r3319025 r3327873  
    33 * Plugin Name:       Easy Critical CSS
    44 * Description:       Easily inject Critical CSS and optimized Secondary CSS to improve page speed and performance.
    5  * Version:           1.2.1
     5 * Version:           1.3.0
    66 * Requires at least: 6.2
    77 * Tested up to:      6.8.1
  • easy-critical-css/trunk/inc/class-admin-settings.php

    r3317868 r3327873  
    3030        <div class="wrap">
    3131            <h1><?php esc_html_e( 'Easy Critical CSS Settings', 'easy-critical-css' ); ?></h1>
     32
     33            <?php
     34            // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No need for nonce verification as we are using this for read-only purposes.
     35            if ( isset( $_GET['settings-reset'] ) && 'true' === $_GET['settings-reset'] ) {
     36                echo '<div class="notice notice-success"><p>'
     37                . esc_html__( 'All Easy Critical CSS settings have been reset.', 'easy-critical-css' )
     38                . '</p></div>';
     39            }
     40
     41            // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No need for nonce verification as we are using this for read-only purposes.
     42            if ( isset( $_GET['styles-deleted'] ) && 'true' === $_GET['styles-deleted'] ) {
     43                echo '<div class="notice notice-success"><p>'
     44                . esc_html__( 'All Critical and Secondary CSS styles have been deleted.', 'easy-critical-css' )
     45                . '</p></div>';
     46            }
     47            ?>
    3248
    3349            <form method="post" action="options.php">
     
    5571            </form>
    5672
     73            <div id="ecc-delete-section">
     74                <hr>
     75                <h2><?php esc_html_e( 'Delete Current Critical CSS', 'easy-critical-css' ); ?></h2>
     76                <p><?php esc_html_e( 'Click the button below to delete all associated Critical and Secondary CSS. This action will not clear any settings, but cannot be undone.', 'easy-critical-css' ); ?></p>
     77                <form id="ecc-delete-form" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>"
     78                    data-confirm="<?php esc_attr_e( 'Are you sure you want to delete all stored Easy Critical CSS styles? This action CANNOT be undone.', 'easy-critical-css' ); ?>">
     79                    <input type="hidden" name="action" value="easy_cc_delete">
     80                    <?php wp_nonce_field( 'easy_cc_delete', 'easy_cc_nonce' ); ?>
     81                    <p class="submit">
     82                    <button id="ecc-delete" type="submit" class="button button-danger">
     83                        <?php esc_html_e( 'Delete All Critical & Secondary CSS Styles', 'easy-critical-css' ); ?>
     84                    </button>
     85                    </p>
     86                </form>
     87            </div>
     88
     89
    5790            <hr>
    5891            <h2><?php esc_html_e( 'Uninstall Plugin & Delete All Data', 'easy-critical-css' ); ?></h2>
     
    6497                <?php wp_nonce_field( 'easy_cc_uninstall', 'easy_cc_nonce' ); ?>
    6598                <p class="submit">
    66                     <button id="ecc-delete" class="button button-danger">
     99                    <button id="ecc-uninstall" class="button button-danger">
    67100                        <?php esc_html_e( 'Delete All Data & Uninstall', 'easy-critical-css' ); ?>
    68101                    </button>
     
    257290                'desc'       => __( 'Specify CSS selectors that should always be included in stripped Secondary CSS, even if they are normally stripped.', 'easy-critical-css' ) . $forced_selectors_desc,
    258291            ],
     292            'add_common_secondary'       => [
     293                'label'         => __( 'Include Common Secondary Selectors', 'easy-critical-css' ),
     294                'type'          => 'checkbox',
     295                'value_type'    => 'boolean',
     296                'options'       => [
     297                    'label' => __( 'Include selectors commonly added via JavaScript.', 'easy-critical-css' ),
     298                ],
     299                'desc'          => __( 'By default, the Critical CSS generator only captures selectors present on initial page load. Selectors that are added later by user interaction may be missed. Checking this will include a set of those common secondary selectors, and more may be added in future releases.', 'easy-critical-css' ),
     300                'default_value' => true,
     301                'default_label' => __( 'Checked', 'easy-critical-css' ),
     302            ],
    259303            'default_critical_css'       => [
    260304                'label'      => __( 'Default Critical CSS', 'easy-critical-css' ),
  • easy-critical-css/trunk/inc/class-compatibility-cache.php

    r3307644 r3327873  
    1717        add_action( 'easy_cc_single_expired', [ __CLASS__, 'clear_cache_single' ] );
    1818        add_action( 'easy_cc_single_generated', [ __CLASS__, 'clear_cache_single' ] );
    19     }
    20 
    21     public static function clear_cloudflare_cache( $url = null ) {
    22         $cloudflare_email   = defined( 'CLOUDFLARE_EMAIL' ) ? CLOUDFLARE_EMAIL : get_option( 'cloudflare_email' );
    23         $cloudflare_api_key = defined( 'CLOUDFLARE_API_KEY' ) ? CLOUDFLARE_API_KEY : get_option( 'cloudflare_api_key' );
    24         $cloudflare_zone_id = defined( 'CLOUDFLARE_ZONE_ID' ) ? CLOUDFLARE_ZONE_ID : get_option( 'cloudflare_zone_id' );
    25 
    26         if ( empty( $cloudflare_email ) || empty( $cloudflare_api_key ) || empty( $cloudflare_zone_id ) ) {
    27             return;
    28         }
    29 
    30         $body = $url ? [ 'files' => [ esc_url_raw( $url ) ] ] : [ 'purge_everything' => true ];
    31 
    32         $response = wp_remote_request(
    33             'https://api.cloudflare.com/client/v4/zones/' . $cloudflare_zone_id . '/purge_cache',
    34             [
    35                 'method'  => 'POST',
    36                 'headers' => [
    37                     'X-Auth-Email' => $cloudflare_email,
    38                     'X-Auth-Key'   => $cloudflare_api_key,
    39                     'Content-Type' => 'application/json',
    40                 ],
    41                 'body'    => wp_json_encode( $body ),
    42                 'timeout' => 10,
    43             ]
    44         );
    4519    }
    4620
     
    176150
    177151        // Cloudflare (if API details exist).
    178         self::clear_cloudflare_cache();
     152        Compatibility_Cloudflare::clear_cloudflare_cache();
    179153    }
    180154
     
    308282
    309283        // Cloudflare (if API details exist).
    310         self::clear_cloudflare_cache( $url );
     284        Compatibility_Cloudflare::clear_cloudflare_cache( $url );
    311285    }
    312286
  • easy-critical-css/trunk/inc/class-critical-css-injector.php

    r3319025 r3327873  
    7474        $serve_from_files  = Settings::get_global_serve_css_from_files();
    7575        $has_db_critical   = ! empty( $generated_css['critical_css'] );
    76         $has_file_critical = $serve_from_files && is_readable( trailingslashit( wp_upload_dir()['basedir'] ) . 'easy-critical-css/critical/' . $url_hash . '.css' );
     76        $has_file_critical = $serve_from_files && is_readable( trailingslashit( wp_upload_dir()['basedir'] ) . 'easy-critical-css/critical/' . sanitize_file_name( $url_hash ) . '.css' );
    7777
    7878        // Check for critical CSS.
  • easy-critical-css/trunk/inc/class-critical-css-status.php

    r3295017 r3327873  
    8686        }
    8787
    88         return $generated['status'];
     88        /**
     89         * Filters the Critical CSS status of an individual post/page.
     90         *
     91         * @since 1.3.0
     92         *
     93         * @param string $status Critical CSS status of an individual post/page.
     94         * @param string|int $identifier URL, Post ID, or URL hash.
     95         */
     96        $status = apply_filters( 'easy_cc_critical_status', $generated['status'], $identifier );
     97
     98        return $status;
    8999    }
    90100
     
    93103            'completed'   => __( 'Completed', 'easy-critical-css' ),
    94104            'expired'     => __( 'Expired', 'easy-critical-css' ),
     105            'excluded'    => __( 'Excluded', 'easy-critical-css' ),
    95106            'failed'      => __( 'Failed', 'easy-critical-css' ),
    96107            'invalid'     => __( 'Invalid API', 'easy-critical-css' ),
     
    122133
    123134        $critical_css = Critical_CSS::get_generated_css( $identifier );
    124         $has_critical = ! empty( $critical_css['critical_css'] );
     135
     136        // Has Critical in the DB?
     137        $has_db_critical = ! empty( $critical_css['critical_css'] );
     138
     139        // What about files?
     140        $serve_from_files  = Settings::get_global_serve_css_from_files();
     141        $upload_base       = trailingslashit( wp_upload_dir()['basedir'] ) . 'easy-critical-css/critical/';
     142        $hash              = sanitize_file_name( $critical_css['url_hash'] );
     143        $has_file_critical = $serve_from_files && is_readable( "{$upload_base}{$hash}.css" );
     144
     145        // Critical exists in either DB or as a file.
     146        $has_critical = $has_db_critical || $has_file_critical;
     147
    125148        $status       = self::get_status( $identifier );
    126149        $status_label = self::get_critical_css_status_label( $status );
     
    133156            ]
    134157        );
     158
     159        // If there’s savings data AND we display secondary, show it in the admin bar.
     160        if (
     161            Settings::get_individual_secondary_behavior( $identifier )
     162            && ! empty( $critical_css['size_savings'] )
     163        ) {
     164            $savings = json_decode( wp_unslash( $critical_css['size_savings'] ), true );
     165
     166            if ( is_array( $savings ) && isset( $savings['bytes'], $savings['percent'] ) ) {
     167                $bytes   = size_format( $savings['bytes'] );
     168                $percent = number_format_i18n( $savings['percent'], 0 ) . '%';
     169
     170                $wp_admin_bar->add_node(
     171                    [
     172                        'id'     => 'critical_css_savings',
     173                        'title'  => sprintf(
     174                            /* translators: 1: human-readable bytes, 2: percent saved */
     175                            __( 'Savings: %1$s (%2$s)', 'easy-critical-css' ),
     176                            $bytes,
     177                            $percent
     178                        ),
     179                        'parent' => 'critical_css_status',
     180                    ]
     181                );
     182            }
     183        }
    135184
    136185        // Do we need to show the Generate Critical CSS link?
     
    148197            );
    149198        }
     199
     200        // Do we need Delete link
     201        if ( $has_critical && current_user_can( 'manage_options' ) ) {
     202            $wp_admin_bar->add_node(
     203                [
     204                    'id'     => 'critical_css_delete',
     205                    'title'  => __( 'Delete Generated Critical CSS', 'easy-critical-css' ),
     206                    'parent' => 'critical_css_status',
     207                    'href'   => '#',
     208                    'meta'   => [ 'class' => 'critical-css-delete-link' ],
     209                ]
     210            );
     211        }
    150212    }
    151213
     
    184246                    })
    185247                })
     248                document.querySelectorAll('.critical-css-delete-link a').forEach(link => {
     249                    link.addEventListener('click', function (event) {
     250                        event.preventDefault()
     251                        if (!eccIdentifier) return
     252       
     253                        if (!confirm('<?php echo esc_js( __( 'Are you sure you want to delete Critical CSS?', 'easy-critical-css' ) ); ?>')) {
     254                            return
     255                        }
     256       
     257                        wp.apiFetch({
     258                            path: '/easy-critical-css/v1/delete',
     259                            method: 'POST',
     260                            headers: { 'Content-Type': 'application/json' },
     261                            body: JSON.stringify({ identifier: eccIdentifier })
     262                        })
     263                        .then(() => alert('<?php echo esc_js( __( 'Critical CSS styles deleted successfully.', 'easy-critical-css' ) ); ?>'))
     264                        .catch(err => alert('<?php echo esc_js( __( 'Error: ', 'easy-critical-css' ) ); ?>' + err.message))
     265                    })
     266                })
    186267            })
    187268        </script>
  • easy-critical-css/trunk/inc/class-critical-css.php

    r3317868 r3327873  
    4646                'zip',
    4747                'gz',
     48                'rar',
    4849            ]
    4950        );
     
    5253        $path_info = pathinfo( wp_parse_url( $current_url, PHP_URL_PATH ) );
    5354        if ( isset( $path_info['extension'] ) && in_array( strtolower( $path_info['extension'] ), $excluded_extensions, true ) ) {
     55            return null;
     56        }
     57
     58        // Block any wp-admin requests
     59        $path = wp_parse_url( $current_url, PHP_URL_PATH );
     60        if ( strpos( $path, '/wp-admin/' ) !== false ) {
    5461            return null;
    5562        }
  • easy-critical-css/trunk/inc/class-database.php

    r3307644 r3327873  
    249249        return (bool) $deleted;
    250250    }
     251
     252    public static function clear_all_styles() {
     253        global $wpdb;
     254
     255        $table_name = esc_sql( self::get_table_name() );
     256
     257        return $wpdb->query(
     258            // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
     259            "UPDATE $table_name
     260                SET
     261                    requested_time    = NULL,
     262                    generated_time    = NULL,
     263                    critical_css      = NULL,
     264                    remaining_css     = NULL,
     265                    secondary_css     = NULL,
     266                    size_savings      = NULL,
     267                    processing_status = 'unprocessed'
     268            "
     269        );
     270    }
     271
     272    public static function clear_individual_styles( $identifier ) {
     273        global $wpdb;
     274
     275        $table_name = esc_sql( self::get_table_name() );
     276        $hash       = Helpers::get_url_hash( $identifier );
     277
     278        return $wpdb->query(
     279            $wpdb->prepare(
     280                // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
     281                "UPDATE {$table_name}
     282                    SET
     283                        generated_time    = NULL,
     284                        critical_css      = NULL,
     285                        remaining_css     = NULL,
     286                        secondary_css     = NULL,
     287                        size_savings      = NULL,
     288                        processing_status = 'unprocessed'
     289                    WHERE url_hash = %s
     290                ",
     291                $hash
     292            )
     293        );
     294    }
    251295}
  • easy-critical-css/trunk/inc/class-helpers.php

    r3317868 r3327873  
    289289
    290290    /**
    291      * Parses a newline-separated string into a clean array.
     291     * Parses a newline-separated string into a clean deduped array.
    292292     *
    293293     * @param string $selector_string Raw newline-separated string.
     
    296296     */
    297297    public static function parse_newline_list( $selector_string ) {
    298         return array_values(
    299             array_filter(
    300                 array_map( 'trim', explode( "\n", $selector_string ) ),
    301                 function ( $item ) {
    302                     return $item !== '';
    303                 }
    304             )
    305         );
     298        $seen   = [];
     299        $result = [];
     300
     301        $selectors = explode( "\n", $selector_string );
     302        foreach ( $selectors as $selector ) {
     303            $item = trim( $selector );
     304            if ( $item === '' || isset( $seen[ $item ] ) ) {
     305                continue;
     306            }
     307            $seen[ $item ] = true;
     308            $result[]      = $item;
     309        }
     310
     311        return $result;
    306312    }
    307313
     
    316322            'rnd',
    317323            'no-cache',
     324            'timestamp',
    318325            'sucurianticache',
    319326            'wp_scrape_key',
  • easy-critical-css/trunk/inc/class-plugin.php

    r3319025 r3327873  
    1010    private static $instance = null;
    1111
    12     private static $plugin_version = '1.2.1';
     12    private static $plugin_version = '1.3.0';
    1313
    1414    private static $db_version = '2';
     
    7171        Critical_CSS_Regenerate::init();
    7272        Compatibility_Cache::init();
     73        Compatibility_Cloudflare::init();
     74        Compatibility_Trellis::init();
     75        Compatibility_WooCommerce::init();
    7376        Compatibility_WP_Rocket::init();
    74         Compatibility_Trellis::init();
    7577        Critical_CSS::init();
    7678        Database::init();
    7779        Gutenberg::init();
     80        Delete_Handler::init();
    7881        Reset_Handler::init();
    7982        REST_API::init();
  • easy-critical-css/trunk/inc/class-reset-handler.php

    r3284313 r3327873  
    4444        self::reset_settings();
    4545
    46         // Flush rewite rules.
     46        // Flush rewrite rules.
    4747        flush_rewrite_rules();
     48
     49        // Clear all cache.
     50        Compatibility_Cache::clear_cache_all();
    4851
    4952        // Redirect w/success message.
  • easy-critical-css/trunk/inc/class-rest-api.php

    r3319025 r3327873  
    2626                'permission_callback' => '__return_true',
    2727                'args'                => [
    28                     'hash'         => [
     28                    'hash'            => [
    2929                        'required' => true,
    3030                        'type'     => 'string',
    3131                    ],
    32                     'handshake'    => [
     32                    'handshake'       => [
    3333                        'required' => true,
    3434                        'type'     => 'string',
    3535                    ],
    36                     'criticalCSS'  => [
    37                         'required' => true,
     36                    'criticalCSS'     => [
     37                        'required' => false,
    3838                        'type'     => 'string',
    3939                    ],
    40                     'remainingCSS' => [
    41                         'required' => true,
     40                    'remainingCSS'    => [
     41                        'required' => false,
    4242                        'type'     => 'string',
    4343                    ],
    44                     'secondaryCSS' => [
    45                         'required' => true,
     44                    'secondaryCSS'    => [
     45                        'required' => false,
    4646                        'type'     => 'string',
    4747                    ],
    48                     'url'          => [
     48                    'criticalCSSUrl'  => [
     49                        'required'          => false,
     50                        'type'              => 'string',
     51                        'validate_callback' => [ __CLASS__, 'validate_criticalcss_net_url' ],
     52                    ],
     53                    'remainingCSSUrl' => [
     54                        'required'          => false,
     55                        'type'              => 'string',
     56                        'validate_callback' => [ __CLASS__, 'validate_criticalcss_net_url' ],
     57                    ],
     58                    'secondaryCSSUrl' => [
     59                        'required'          => false,
     60                        'type'              => 'string',
     61                        'validate_callback' => [ __CLASS__, 'validate_criticalcss_net_url' ],
     62                    ],
     63                    'url'             => [
    4964                        'required'          => true,
    5065                        'type'              => 'string',
    51                         'validate_callback' => 'esc_url_raw',
     66                        'validate_callback' => function ( $url ) {
     67                            return (bool) filter_var( $url, FILTER_VALIDATE_URL );
     68                        },
    5269                    ],
    5370                ],
     
    133150        register_rest_route(
    134151            self::$route_namespace,
     152            '/delete',
     153            [
     154                'methods'             => 'POST',
     155                'callback'            => [ __CLASS__, 'handle_delete_request' ],
     156                'permission_callback' => function () {
     157                    return current_user_can( 'manage_options' );
     158                },
     159                'args'                => [
     160                    'identifier' => [
     161                        'required'          => true,
     162                        'validate_callback' => function ( $param ) {
     163                            return is_numeric( $param ) || filter_var( $param, FILTER_VALIDATE_URL );
     164                        },
     165                    ],
     166                ],
     167            ]
     168        );
     169
     170        register_rest_route(
     171            self::$route_namespace,
    135172            '/content',
    136173            [
     
    198235    }
    199236
     237    private static function validate_criticalcss_net_url( $url ) {
     238        // Allow empty for inline-only cases.
     239        if ( $url === '' ) {
     240            return true;
     241        }
     242
     243        // Basic URL syntax check.
     244        if ( filter_var( $url, FILTER_VALIDATE_URL ) === false ) {
     245            return false;
     246        }
     247
     248        // Parse out the host and scheme.
     249        $parts = wp_parse_url( $url );
     250        if ( empty( $parts['scheme'] ) || empty( $parts['host'] ) ) {
     251            return false;
     252        }
     253
     254        // Must be https.
     255        if ( 'https' !== $parts['scheme'] ) {
     256            return false;
     257        }
     258
     259        // Host must end in ".criticalcss.net".
     260        if ( ! preg_match( '/(^|\.)criticalcss\.net$/i', $parts['host'] ) ) {
     261            return false;
     262        }
     263
     264        return true;
     265    }
     266
    200267    private static function remove_old_css_files( $hash ) {
    201268        $upload_dir = wp_upload_dir();
     
    270337        }
    271338
     339        // If no inline CSS, but we have URLs, fetch them now.
     340        $css_types = [
     341            'critical'  => 'criticalCSS',
     342            'remaining' => 'remainingCSS',
     343            'secondary' => 'secondaryCSS',
     344        ];
     345        foreach ( $css_types as $type => $param_key ) {
     346            $url_key = $type . 'Url';
     347            if ( empty( $params[ $param_key ] ) && ! empty( $params[ $url_key ] ) ) {
     348                $resp = wp_remote_get( esc_url_raw( $params[ $url_key ] ), [ 'timeout' => 20 ] );
     349                if ( is_wp_error( $resp ) || 200 !== wp_remote_retrieve_response_code( $resp ) ) {
     350                    if ( $type === 'critical' ) {
     351                        return new WP_Error(
     352                            'css_fetch_failed',
     353                            __( 'Could not fetch critical CSS from URL.', 'easy-critical-css' ),
     354                            [ 'status' => 502 ]
     355                        );
     356                    }
     357                    continue;
     358                }
     359                $params[ $param_key ] = wp_remote_retrieve_body( $resp );
     360            }
     361        }
     362
     363        // Now if we are empty, this is a legit failure.
    272364        if ( empty( $params['criticalCSS'] ) ) {
    273365            // Store CSS failure.
     
    415507
    416508        return rest_ensure_response( $result );
     509    }
     510
     511    public static function handle_delete_request( WP_REST_Request $request ) {
     512        $identifier = $request->get_param( 'identifier' );
     513        $result     = Delete_Handler::delete_one( $identifier );
     514
     515        if ( is_wp_error( $result ) ) {
     516            return $result;
     517        }
     518
     519        return rest_ensure_response(
     520            [
     521                'success' => true,
     522                'message' => __( 'Critical CSS styles deleted for the page.', 'easy-critical-css' ),
     523            ]
     524        );
    417525    }
    418526
     
    556664        }
    557665
    558         return [
     666        $response = [
    559667            'html'        => $body,
    560668            'stylesheets' => $stylesheet_hrefs,
     
    562670            'css'         => $css_combined,
    563671        ];
     672
     673        return rest_ensure_response( $response );
    564674    }
    565675}
  • easy-critical-css/trunk/inc/class-settings.php

    r3317868 r3327873  
    117117    public static function get_global_forced_critical() {
    118118        $selectors = self::get_global_setting( 'forced_critical_selectors', '' );
     119
    119120        return Helpers::parse_newline_list( $selectors );
    120121    }
     
    130131        $global    = self::get_global_forced_critical();
    131132        $selectors = (string) self::get_individual_setting( $identifier, 'forced_critical_selectors', implode( "\n", $global ) );
    132         return Helpers::parse_newline_list( $selectors );
     133
     134        return Helpers::parse_newline_list( $selectors );
     135    }
     136
     137    /**
     138     * Gets the global Add Common Secondary Selectors.
     139     *
     140     * @return bool
     141     */
     142    public static function get_global_add_common_secondary() {
     143        return (bool) self::get_global_setting( 'add_common_secondary', true );
    133144    }
    134145
     
    140151    public static function get_global_forced_secondary() {
    141152        $selectors = self::get_global_setting( 'forced_secondary_selectors', '' );
     153
     154        // Add common secondary selectors if setting active.
     155        if ( self::get_global_add_common_secondary() ) {
     156            $selectors .= "\n.active";
     157        }
     158
    142159        return Helpers::parse_newline_list( $selectors );
    143160    }
     
    153170        $global    = self::get_global_forced_secondary();
    154171        $selectors = (string) self::get_individual_setting( $identifier, 'forced_secondary_selectors', implode( "\n", $global ) );
     172
     173        // Add common secondary selectors if setting active.
     174        if ( self::get_global_add_common_secondary() ) {
     175            $selectors .= "\n.active";
     176        }
     177
    155178        return Helpers::parse_newline_list( $selectors );
    156179    }
     
    174197    public static function get_individual_default_critical_css( $identifier ) {
    175198        $global = self::get_global_default_critical_css();
     199
    176200        return (string) self::get_individual_setting( $identifier, 'critical_css', $global );
    177201    }
     
    195219    public static function get_global_excluded_css_files() {
    196220        $files = self::get_global_setting( 'exclude_css_files', '' );
     221
    197222        return Helpers::parse_newline_list( $files );
    198223    }
     
    208233        $global = self::get_global_excluded_css_files();
    209234        $files  = (string) self::get_individual_setting( $identifier, 'exclude_css_files', implode( "\n", $global ) );
     235
    210236        return Helpers::parse_newline_list( $files );
    211237    }
  • easy-critical-css/trunk/inc/class-uninstall-handler.php

    r3317868 r3327873  
    2929
    3030        // Delete any static files.
    31         $basedir = trailingslashit( wp_upload_dir()['basedir'] ) . 'easy-critical-css';
    32         $subdirs = [ 'critical', 'secondary', 'remaining' ];
    33 
    34         foreach ( $subdirs as $subdir ) {
    35             $dir = trailingslashit( $basedir ) . $subdir;
    36 
    37             if ( file_exists( $dir ) ) {
    38                 foreach ( glob( "$dir/*.css" ) as $file ) {
    39                     wp_delete_file( $file );
    40                 }
    41 
    42                 // We are deleting from wp-content/uploads which is writable on all standard WordPress installs.
    43                 // WP_Filesystem is not needed here and may cause permission prompts on some hosts.
    44                 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
    45                 rmdir( $dir );
    46             }
    47         }
    48 
    49         if ( is_dir( $basedir ) && count( glob( "$basedir/*" ) ) === 0 ) {
    50             // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
    51             rmdir( $basedir );
    52         }
     31        Delete_Handler::delete_files();
    5332
    5433        // Delete log file.
     
    6746        easy_cc_fs()->add_action( 'after_uninstall', 'easy_cc_fs_uninstall_cleanup' );
    6847
     48        // Clear all cache.
     49        Compatibility_Cache::clear_cache_all();
     50
    6951        // Deactivate Easy Critical CSS plugin.
    7052        deactivate_plugins( Plugin::get_plugin_file() );
     53
     54        // Flush rewrite rules.
     55        flush_rewrite_rules();
    7156
    7257        // Redirect w/success message.
  • easy-critical-css/trunk/readme.txt

    r3319025 r3327873  
    102102== Changelog ==
    103103
     104= 1.3.0 =
     105- FEATURE: Adds WooCommerce compatibility
     106- FEATURE: Hovering over the Critical CSS status now displays the size savings when using Secondary CSS
     107- FEATURE: Introduces new setting to auto include common Secondary selectors
     108- FEATURE: Creates new Settings buttons to quickly delete all and page-specific previously auto-generated styles
     109- FIX: Dedupes any user-added forced selectors
     110- FIX: Improves Cloudflare support
     111
    104112= 1.2.1 =
    105113- OPTIMIZATION: Utilizes a preload swap to defer Secondary CSS instead of a print/media swap
  • easy-critical-css/trunk/src/components/statusIndicator.tsx

    r3284313 r3327873  
    77  completed: __('Completed', 'easy-critical-css'),
    88  expired: __('Expired', 'easy-critical-css'),
     9  excluded: __('Excluded', 'easy-critical-css'),
    910  failed: __('Failed', 'easy-critical-css'),
    1011  invalid: __('Invalid API', 'easy-critical-css'),
     
    2021  completed: '#1e7e34',
    2122  expired: '#995a00',
     23  excluded: '#6c757d',
    2224  failed: '#b12331',
    2325  invalid: '#b12331',
  • easy-critical-css/trunk/src/types/types.ts

    r3284313 r3327873  
    11export type Status = 'completed'
    22| 'expired'
     3| 'excluded'
    34| 'failed'
    45| 'invalid'
  • easy-critical-css/trunk/vendor/composer/autoload_classmap.php

    r3317868 r3327873  
    1212    'EasyCriticalCSS\\Admin_Settings' => $baseDir . '/inc/class-admin-settings.php',
    1313    'EasyCriticalCSS\\Compatibility_Cache' => $baseDir . '/inc/class-compatibility-cache.php',
     14    'EasyCriticalCSS\\Compatibility_Cloudflare' => $baseDir . '/inc/class-compatibility-cloudflare.php',
    1415    'EasyCriticalCSS\\Compatibility_Trellis' => $baseDir . '/inc/class-compatibility-trellis.php',
    1516    'EasyCriticalCSS\\Compatibility_WP_Rocket' => $baseDir . '/inc/class-compatibility-wp-rocket.php',
     17    'EasyCriticalCSS\\Compatibility_WooCommerce' => $baseDir . '/inc/class-compatibility-woocommerce.php',
    1618    'EasyCriticalCSS\\Critical_CSS' => $baseDir . '/inc/class-critical-css.php',
    1719    'EasyCriticalCSS\\Critical_CSS_Injector' => $baseDir . '/inc/class-critical-css-injector.php',
     
    2123    'EasyCriticalCSS\\Database' => $baseDir . '/inc/class-database.php',
    2224    'EasyCriticalCSS\\Debug' => $baseDir . '/inc/class-debug.php',
     25    'EasyCriticalCSS\\Delete_Handler' => $baseDir . '/inc/class-delete-handler.php',
    2326    'EasyCriticalCSS\\Gutenberg' => $baseDir . '/inc/class-gutenberg.php',
    2427    'EasyCriticalCSS\\Helpers' => $baseDir . '/inc/class-helpers.php',
  • easy-critical-css/trunk/vendor/composer/autoload_static.php

    r3317868 r3327873  
    3131        'EasyCriticalCSS\\Admin_Settings' => __DIR__ . '/../..' . '/inc/class-admin-settings.php',
    3232        'EasyCriticalCSS\\Compatibility_Cache' => __DIR__ . '/../..' . '/inc/class-compatibility-cache.php',
     33        'EasyCriticalCSS\\Compatibility_Cloudflare' => __DIR__ . '/../..' . '/inc/class-compatibility-cloudflare.php',
    3334        'EasyCriticalCSS\\Compatibility_Trellis' => __DIR__ . '/../..' . '/inc/class-compatibility-trellis.php',
    3435        'EasyCriticalCSS\\Compatibility_WP_Rocket' => __DIR__ . '/../..' . '/inc/class-compatibility-wp-rocket.php',
     36        'EasyCriticalCSS\\Compatibility_WooCommerce' => __DIR__ . '/../..' . '/inc/class-compatibility-woocommerce.php',
    3537        'EasyCriticalCSS\\Critical_CSS' => __DIR__ . '/../..' . '/inc/class-critical-css.php',
    3638        'EasyCriticalCSS\\Critical_CSS_Injector' => __DIR__ . '/../..' . '/inc/class-critical-css-injector.php',
     
    4042        'EasyCriticalCSS\\Database' => __DIR__ . '/../..' . '/inc/class-database.php',
    4143        'EasyCriticalCSS\\Debug' => __DIR__ . '/../..' . '/inc/class-debug.php',
     44        'EasyCriticalCSS\\Delete_Handler' => __DIR__ . '/../..' . '/inc/class-delete-handler.php',
    4245        'EasyCriticalCSS\\Gutenberg' => __DIR__ . '/../..' . '/inc/class-gutenberg.php',
    4346        'EasyCriticalCSS\\Helpers' => __DIR__ . '/../..' . '/inc/class-helpers.php',
  • easy-critical-css/trunk/vendor/composer/installed.php

    r3319025 r3327873  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '6dbdd173fea13327e403938376d1d677bae57e28',
     6        'reference' => 'a88ecc654551c83ad454541fa5297413a497f7b8',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    3232            'pretty_version' => 'dev-main',
    3333            'version' => 'dev-main',
    34             'reference' => '6dbdd173fea13327e403938376d1d677bae57e28',
     34            'reference' => 'a88ecc654551c83ad454541fa5297413a497f7b8',
    3535            'type' => 'wordpress-plugin',
    3636            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.