Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/lazy-components/cimo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
} from '@wordpress/element'
import { models } from '@wordpress/api'

let isPolling = false

const CimoDownloadNotice = props => {
const { inMediaLibrary = false } = props
const [ data, setData ] = useState( { status: cimo?.status, action: cimo?.action } )
const pollCountRef = useRef( 0 )

Expand All @@ -33,6 +36,12 @@ const CimoDownloadNotice = props => {

// Polls the Cimo plugin status to detect installation or activation state changes
const pollStatus = ( action, link, pollOnce = false ) => {
if ( isPolling ) {
return
}

isPolling = true

fetch( ajaxUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
Expand Down Expand Up @@ -76,6 +85,7 @@ const CimoDownloadNotice = props => {
( action === 'install' && ( _data.status === 'installed' || _data.status === 'activated' ) ) ||
( action === 'activate' && _data.status === 'activated' )
) {
isPolling = false
return
}

Expand All @@ -89,6 +99,10 @@ const CimoDownloadNotice = props => {
}

useEffect( () => {
if ( inMediaLibrary ) {
return
}

const _media = wp.media
const old = _media.view.MediaFrame.Select

Expand Down Expand Up @@ -186,7 +200,7 @@ domReady( () => {
}
}

createRoot( noticeDiv ).render( <CimoDownloadNotice onDismiss={ onDismiss } /> )
createRoot( noticeDiv ).render( <CimoDownloadNotice onDismiss={ onDismiss } inMediaLibrary={ true } /> )
details.insertAdjacentElement( 'afterend', noticeDiv )
}

Expand Down
1 change: 0 additions & 1 deletion src/lazy-components/cimo/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
background: none;
border: none;
height: 14px;
width: 14px;
position: absolute;
right: 4px;
top: 4px;
Expand Down
5 changes: 3 additions & 2 deletions src/welcome/useful-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ function check_cimo_status() {
wp_clean_plugins_cache();

if ( $action === 'install' && ! self::is_plugin_installed( $full_slug ) ) {
$response[ 'status' ] = 'installing';
$response[ 'status' ] = 'not_installed';
} else if ( ! self::is_plugin_activated( $full_slug ) ) {
$response[ 'status' ] = $action === 'install' ? 'installed' : 'activating';
$response[ 'status' ] = 'installed';
// If the plugin is installed and not activated, provide the action link to activate it
$response[ 'action' ] = $action === 'install' ? html_entity_decode( wp_nonce_url(
add_query_arg(
[
Expand Down
Loading