-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a promotion notice to WP's Plugin Install screen based on the following conditions: - The user has a page containing "Support" in the title.
- Loading branch information
1 parent
ec03171
commit 47348ce
Showing
10 changed files
with
242 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-components', 'wp-element'), 'version' => '2f7b01c785d210cc0a66'); | ||
<?php return array('dependencies' => array('react', 'wp-components', 'wp-element'), 'version' => 'fc64a210bede1308e242'); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('wp-components', 'wp-element'), 'version' => 'ce3090dc0e13b5e1c2e4'); | ||
<?php return array('dependencies' => array('react', 'wp-components', 'wp-element'), 'version' => '80cf3f304af2c0a33ac3'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-hooks', 'wp-plugins'), 'version' => '2cd9ed3afc77de83f989'); | ||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-hooks', 'wp-plugins'), 'version' => 'dfd4ce8c8029dca3f091'); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { createRoot, useState } from '@wordpress/element'; | ||
import { Button } from '@wordpress/components'; | ||
import useSettings from "./common/useSettings"; | ||
import { activatePlugin, installPluginOrTheme } from './common/utils'; | ||
|
||
const HyveNotice = ({ | ||
onDismiss = () => {} | ||
}) => { | ||
const { | ||
title, | ||
option, | ||
optionKey, | ||
labels, | ||
hyveActivationUrl, | ||
hyveDash, | ||
} = window.themeisleSDKPromotions; | ||
|
||
const [ dismissed, setDismissed ] = useState( false ); | ||
const [ progress, setProgress ] = useState( null ); | ||
const [ getOption, updateOption ] = useSettings(); | ||
|
||
const dismissNotice = async () => { | ||
setDismissed( true ); | ||
const newValue = { ...option }; | ||
newValue['hyve-plugins-install'] = new Date().getTime() / 1000 | 0; | ||
window.themeisleSDKPromotions.option = newValue; | ||
await updateOption( optionKey, JSON.stringify( newValue ) ); | ||
|
||
if ( onDismiss ) { | ||
onDismiss(); | ||
} | ||
}; | ||
|
||
const installPluginRequest = async e => { | ||
e.preventDefault(); | ||
setProgress( 'installing' ); | ||
await installPluginOrTheme( 'hyve-lite' ); | ||
|
||
setProgress( 'activating' ); | ||
await activatePlugin( hyveActivationUrl ); | ||
|
||
updateOption( 'themeisle_sdk_promotions_hyve_installed', ! Boolean( getOption( 'themeisle_sdk_promotions_hyve_installed' ) ) ); | ||
setProgress('done'); | ||
}; | ||
|
||
if ( dismissed ) { | ||
return null; | ||
} | ||
|
||
const installPluginRequestStatus = () => { | ||
return progress === 'done' ? ( | ||
<div className="done"> | ||
<p>{ labels.all_set }</p> | ||
|
||
<Button | ||
icon="external" | ||
variant="primary" | ||
href={ hyveDash } | ||
target="_blank" | ||
> | ||
{ labels.hyve.gotodash } | ||
</Button> | ||
</div> | ||
) : ( | ||
<p className="om-progress"> | ||
<span className="dashicons dashicons-update spin"/> | ||
<span> | ||
{ progress === 'installing' && labels.installing } | ||
{ progress === 'activating' && labels.activating } | ||
… | ||
</span> | ||
</p> | ||
); | ||
}; | ||
|
||
const actionButtons = ( | ||
<div className="actions"> | ||
<Button | ||
variant="primary" | ||
onClick={ installPluginRequest } | ||
> | ||
{ labels.hyve.install } | ||
</Button> | ||
|
||
<Button | ||
variant="link" | ||
target="_blank" | ||
href="https://wordpress.org/plugins/hyve-lite/" | ||
> | ||
<span className="dashicons dashicons-external"/> | ||
<span>{ labels.learnmore }</span> | ||
</Button> | ||
</div> | ||
); | ||
|
||
return ( | ||
<> | ||
<Button | ||
disabled={ progress && progress !== 'done' } | ||
onClick={ dismissNotice } | ||
variant="link" | ||
className="om-notice-dismiss" | ||
> | ||
<span className="dashicons-no-alt dashicons"/> | ||
<span className="screen-reader-text">{ labels.hyve.dismisscta }</span> | ||
</Button> | ||
|
||
<div className="content"> | ||
<div> | ||
<p>{ title }</p> | ||
<p className="description">{labels.hyve.message}</p> | ||
{ progress ? installPluginRequestStatus() : actionButtons } | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
const renderHyveNotice = () => { | ||
if ( window.themeisleSDKPromotions.option['hyve-plugins-install']) { | ||
return; | ||
} | ||
|
||
const root = document.querySelector( '#ti-hyve-notice' ); | ||
|
||
if ( ! root ) { | ||
return; | ||
} | ||
|
||
createRoot( root ).render( | ||
<HyveNotice | ||
onDismiss={() => { | ||
root.style.display = 'none'; | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
renderHyveNotice(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters