diff --git a/assets-src/js/index.js b/assets-src/js/index.js index 3ebc789..9b9d6cb 100644 --- a/assets-src/js/index.js +++ b/assets-src/js/index.js @@ -71,7 +71,7 @@ const promoteImagifyButton = createHigherOrderComponent( ( BlockEdit ) => { initialOpen={true} >

- {__('Boost your site’s performance by compressing images with Imagify, developed by WP Rocket.', '%domain%')} + { wpmedia_pluginfamily.notice_text }

{success ? ( get_error_message() ); } - $this->set_imagify_partner( '%imagifypartnerid%' ); + // Allow host plugin to define the Imagify partner ID. + $partner = apply_filters( 'wpmedia/plugin_family/imagify_partner', '%imagifypartnerid%' ); + $this->set_imagify_partner( $partner ); wp_send_json_success( __( 'Imagify installed! Click here to start using it.', '%domain%' ) ); } @@ -411,10 +413,28 @@ private function can_enqueue_admin_assets( $page = '' ): bool { if ( $this->is_promote_imagify_dismissed() ) { return false; } - if ( empty( $page ) ) { - return in_array( get_current_screen()->id, [ 'post', 'upload' ], true ); + + // Allow core admin screens; third-parties can extend via the filter below. + $allowed_pages = [ 'post.php', 'post-new.php', 'upload.php' ]; + + // If hook suffix is provided by admin_enqueue_scripts. + if ( ! empty( $page ) ) { + $allowed = in_array( $page, $allowed_pages, true ); + /** + * Filter whether plugin-family assets can be enqueued on a given admin page. + * + * @param bool $allowed Whether enqueuing is allowed. + * @param string $page Hook suffix. + * @param string $screen Screen ID (empty in this branch). + */ + return (bool) apply_filters( 'wpmedia/plugin_family/can_enqueue_admin_assets', $allowed, $page, '' ); } - return in_array( $page, [ 'post.php', 'post-new.php', 'upload.php' ], true ); + + // Fallback to current screen ID checks. + $screen_id = function_exists( 'get_current_screen' ) && get_current_screen() ? get_current_screen()->id : ''; + $allowed = in_array( $screen_id, [ 'post', 'upload' ], true ) || in_array( $screen_id, $allowed_pages, true ); + + return (bool) apply_filters( 'wpmedia/plugin_family/can_enqueue_admin_assets', $allowed, '', $screen_id ); } /** @@ -428,6 +448,7 @@ private function add_install_imagify_localized_script( $script_id ) { 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'install-imagify-nonce' ), 'plugins_page_url' => admin_url( 'plugins.php' ), + 'notice_text' => apply_filters( 'wpmedia/plugin_family/notice_text', esc_html__( 'Boost your site\'s performance by compressing images with Imagify, developed by WP Rocket.', '%domain%' ) ), ]; wp_add_inline_script( $script_id, diff --git a/src/View/promote-imagify-uploader.php b/src/View/promote-imagify-uploader.php index 95bd8bf..c3606b6 100644 --- a/src/View/promote-imagify-uploader.php +++ b/src/View/promote-imagify-uploader.php @@ -10,13 +10,16 @@

- + \ No newline at end of file diff --git a/src/assets/js/index.js b/src/assets/js/index.js index 399a872..cb12940 100644 --- a/src/assets/js/index.js +++ b/src/assets/js/index.js @@ -1 +1 @@ -(()=>{"use strict";const e=window.wp.hooks,i=window.wp.compose,n=window.wp.element,o=window.wp.blockEditor,t=window.wp.components,a=window.wp.i18n,s=window.wp.primitives,r=window.ReactJSXRuntime,l=(0,r.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"-2 -2 24 24",children:(0,r.jsx)(s.Path,{d:"M10 1c-5 0-9 4-9 9s4 9 9 9 9-4 9-9-4-9-9-9zm0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7zm1-11H9v3H6v2h3v3h2v-3h3V9h-3V6zM10 1c-5 0-9 4-9 9s4 9 9 9 9-4 9-9-4-9-9-9zm0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7zm1-11H9v3H6v2h3v3h2v-3h3V9h-3V6z"})}),c=(0,r.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,r.jsx)(s.Path,{d:"M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"})}),m=(0,i.createHigherOrderComponent)(e=>i=>{const[s,m]=(0,n.useState)(!1),[d,w]=(0,n.useState)(!1),[p,g]=(0,n.useState)(!0);return"core/image"===i.name&&p?(0,r.jsxs)(n.Fragment,{children:[(0,r.jsx)(e,{...i}),(0,r.jsxs)(o.InspectorControls,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",fontWeight:"bold",marginBottom:"8px"},children:[(0,r.jsx)(t.Icon,{icon:l,style:{marginRight:8,marginLeft:8}}),(0,r.jsx)("span",{style:{flex:1},children:(0,a.__)("Optimize Your Images","%domain%")}),(0,r.jsx)(t.Button,{onClick:async()=>{try{await fetch(wpmedia_pluginfamily.ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},body:new URLSearchParams({action:"dismiss_promote_imagify",_ajax_nonce:wpmedia_pluginfamily.nonce}).toString()})}catch(e){console.error("AJAX error: ",e)}g(!1)},size:"compact",icon:c,iconPosition:"right"})]}),(0,r.jsxs)(t.PanelBody,{title:"",initialOpen:!0,children:[(0,r.jsx)("p",{style:{marginLeft:16},children:(0,a.__)("Boost your site’s performance by compressing images with Imagify, developed by WP Rocket.","%domain%")}),d?(0,r.jsx)("a",{href:wpmedia_pluginfamily.plugins_page_url,target:"_blank",rel:"noopener noreferrer",style:{marginLeft:16,color:"green",fontWeight:"bold",display:"block"},children:(0,a.__)("Imagify installed! Click here to start using it.","%domain%")}):(0,r.jsx)(t.Button,{style:{marginLeft:16},isSecondary:!0,isBusy:s,disabled:s,onClick:async()=>{m(!0);try{const e=await fetch(wpmedia_pluginfamily.ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},body:new URLSearchParams({action:"install_imagify",_ajax_nonce:wpmedia_pluginfamily.nonce}).toString()});(await e.json()).success&&(w(!0),window.open(wpmedia_pluginfamily.plugins_page_url,"_blank"))}catch(e){console.error("AJAX error: ",e)}m(!1)},children:(0,a.__)("Install Imagify Now","%domain%")})]})]})]}):(0,r.jsx)(e,{...i})},"promoteImagifyButton");(0,e.addFilter)("editor.BlockEdit","wpmedia-plugin-family/promote-imagify",m)})(); \ No newline at end of file +(()=>{"use strict";const e=window.wp.hooks,i=window.wp.compose,n=window.wp.element,t=window.wp.blockEditor,o=window.wp.components,a=window.wp.i18n,r=window.wp.primitives,s=window.ReactJSXRuntime,l=(0,s.jsx)(r.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"-2 -2 24 24",children:(0,s.jsx)(r.Path,{d:"M10 1c-5 0-9 4-9 9s4 9 9 9 9-4 9-9-4-9-9-9zm0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7zm1-11H9v3H6v2h3v3h2v-3h3V9h-3V6zM10 1c-5 0-9 4-9 9s4 9 9 9 9-4 9-9-4-9-9-9zm0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7zm1-11H9v3H6v2h3v3h2v-3h3V9h-3V6z"})}),c=(0,s.jsx)(r.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,s.jsx)(r.Path,{d:"M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"})}),m=(0,i.createHigherOrderComponent)(e=>i=>{const[r,m]=(0,n.useState)(!1),[d,w]=(0,n.useState)(!1),[p,g]=(0,n.useState)(!0);return"core/image"===i.name&&p?(0,s.jsxs)(n.Fragment,{children:[(0,s.jsx)(e,{...i}),(0,s.jsxs)(t.InspectorControls,{children:[(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",fontWeight:"bold",marginBottom:"8px"},children:[(0,s.jsx)(o.Icon,{icon:l,style:{marginRight:8,marginLeft:8}}),(0,s.jsx)("span",{style:{flex:1},children:(0,a.__)("Optimize Your Images","%domain%")}),(0,s.jsx)(o.Button,{onClick:async()=>{try{await fetch(wpmedia_pluginfamily.ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},body:new URLSearchParams({action:"dismiss_promote_imagify",_ajax_nonce:wpmedia_pluginfamily.nonce}).toString()})}catch(e){console.error("AJAX error: ",e)}g(!1)},size:"compact",icon:c,iconPosition:"right"})]}),(0,s.jsxs)(o.PanelBody,{title:"",initialOpen:!0,children:[(0,s.jsx)("p",{style:{marginLeft:16},children:wpmedia_pluginfamily.notice_text}),d?(0,s.jsx)("a",{href:wpmedia_pluginfamily.plugins_page_url,target:"_blank",rel:"noopener noreferrer",style:{marginLeft:16,color:"green",fontWeight:"bold",display:"block"},children:(0,a.__)("Imagify installed! Click here to start using it.","%domain%")}):(0,s.jsx)(o.Button,{style:{marginLeft:16},isSecondary:!0,isBusy:r,disabled:r,onClick:async()=>{m(!0);try{const e=await fetch(wpmedia_pluginfamily.ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},body:new URLSearchParams({action:"install_imagify",_ajax_nonce:wpmedia_pluginfamily.nonce}).toString()});(await e.json()).success&&(w(!0),window.open(wpmedia_pluginfamily.plugins_page_url,"_blank"))}catch(e){console.error("AJAX error: ",e)}m(!1)},children:(0,a.__)("Install Imagify Now","%domain%")})]})]})]}):(0,s.jsx)(e,{...i})},"promoteImagifyButton");(0,e.addFilter)("editor.BlockEdit","wpmedia-plugin-family/promote-imagify",m)})(); \ No newline at end of file