| 1 |
const { __ } = wp.i18n; |
| 2 |
const { PluginDocumentSettingPanel } = wp.editPost; |
| 3 |
const { CheckboxControl } = wp.components; |
| 4 |
const { dispatch, useSelect } = wp.data; |
| 5 |
const { registerPlugin } = wp.plugins; |
| 6 |
|
| 7 |
/** |
| 8 |
* PoweredCacheMetaBox |
| 9 |
* |
| 10 |
* @return PluginDocumentSettingPanel |
| 11 |
*/ |
| 12 |
const PoweredCacheMetaBox = () => { |
| 13 |
const meta = useSelect((select) => select('core/editor').getEditedPostAttribute('meta')); |
| 14 |
const disableCache = meta.powered_cache_disable_cache || false; |
| 15 |
const disableLazyLoad = meta.powered_cache_disable_lazyload || false; |
| 16 |
|
| 17 |
if (!('powered_cache_disable_cache' in meta) && !('powered_cache_disable_lazyload' in meta)) { |
| 18 |
return null; // nothing to control |
| 19 |
} |
| 20 |
|
| 21 |
return ( |
| 22 |
<PluginDocumentSettingPanel |
| 23 |
icon="superhero" |
| 24 |
title={__('Powered Cache', 'powered-cache')} |
| 25 |
className="powered-cache-panel" |
| 26 |
> |
| 27 |
{'powered_cache_disable_cache' in meta && ( |
| 28 |
<CheckboxControl |
| 29 |
label={__("Don't cache this post", 'powered-cache')} |
| 30 |
checked={disableCache} |
| 31 |
onChange={() => { |
| 32 |
dispatch('core/editor').editPost({ |
| 33 |
meta: { powered_cache_disable_cache: !disableCache }, |
| 34 |
}); |
| 35 |
}} |
| 36 |
/> |
| 37 |
)} |
| 38 |
|
| 39 |
{'powered_cache_disable_lazyload' in meta && ( |
| 40 |
<CheckboxControl |
| 41 |
label={__('Disable lazy loading for this post', 'powered-cache')} |
| 42 |
checked={disableLazyLoad} |
| 43 |
onChange={() => { |
| 44 |
dispatch('core/editor').editPost({ |
| 45 |
meta: { powered_cache_disable_lazyload: !disableLazyLoad }, |
| 46 |
}); |
| 47 |
}} |
| 48 |
/> |
| 49 |
)} |
| 50 |
</PluginDocumentSettingPanel> |
| 51 |
); |
| 52 |
}; |
| 53 |
|
| 54 |
registerPlugin('powered-cache-post-meta', { render: PoweredCacheMetaBox }); |
| 55 |
|