Skip to content

Commit

Permalink
Merge branch 'release/21.6' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
enricobattocchi committed Nov 3, 2023
2 parents 23281fa + dcf89ed commit a4bc970
Show file tree
Hide file tree
Showing 10 changed files with 558 additions and 65 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"typescript": "^4.2.4"
},
"yoast": {
"pluginVersion": "21.6-RC1"
"pluginVersion": "21.6-RC2"
},
"version": "0.0.0"
}
49 changes: 49 additions & 0 deletions packages/js/src/ai-generator/components/modal-content.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable complexity */
import { useDispatch, useSelect } from "@wordpress/data";
import { useMemo } from "@wordpress/element";
import { AiGenerateTitlesAndDescriptionsUpsell } from "../../shared-admin/components";
import { __, sprintf } from "@wordpress/i18n";

const STORE = "yoast-seo/editor";

Expand All @@ -9,6 +11,52 @@ const STORE = "yoast-seo/editor";
*/
export const ModalContent = () => {
const learnMoreLink = useSelect( select => select( STORE ).selectLink( "https://www.yoa.st/ai-generator-learn-more" ), [] );
const upsellLinkPremium = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell" ), [] );
const upsellLinkWooPremiumBundle = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell-woo-seo-premium-bundle" ), [] );
const upsellLinkWoo = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell-woo-seo" ), [] );
const isPremium = useSelect( select => select( STORE ).getIsPremium(), [] );
const isWooSeoUpsell = useSelect( select => select( STORE ).getIsWooSeoUpsell(), [] );
const isProduct = useSelect( select => select( STORE ).getIsProduct(), [] );
const wooSeoNoPremium = isProduct && ! isWooSeoUpsell && ! isPremium;
const isProductCopy = !! ( isWooSeoUpsell || wooSeoNoPremium );
const postModalprops = {
isProductCopy,
upsellLink: upsellLinkPremium,
};

if ( isProductCopy ) {
const upsellPremiumWooLabel = sprintf(
/* translators: %1$s expands to Yoast SEO Premium, %2$s expands to Yoast WooCommerce SEO. */
__( "%1$s + %2$s", "wordpress-seo" ),
"Yoast SEO Premium",
"Yoast WooCommerce SEO"
);
postModalprops.newToText = sprintf(
/* translators: %1$s expands to Yoast SEO Premium and Yoast WooCommerce SEO. */
__( "New to %1$s", "wordpress-seo" ),
upsellPremiumWooLabel
);
postModalprops.title = __( "Generate product titles & descriptions with AI!", "wordpress-seo" );
if ( ! isPremium && isWooSeoUpsell ) {
postModalprops.upsellLabel = `${ sprintf(
/* translators: %1$s expands to Woo Premium bundle. */
__( "Unlock with the %1$s", "wordpress-seo" ),
"Woo Premium bundle"
)}*`;
postModalprops.bundleNote = <div className="yst-text-xs yst-text-slate-500 yst-mt-2">
{ `*${upsellPremiumWooLabel}` }
</div>;
postModalprops.upsellLink = upsellLinkWooPremiumBundle;
}
if ( isPremium ) {
postModalprops.upsellLabel = sprintf(
/* translators: %1$s expands to Yoast WooCommerce SEO. */
__( "Unlock with %1$s", "wordpress-seo" ),
"Yoast WooCommerce SEO"
);
postModalprops.upsellLink = upsellLinkWoo;
}
}


const imageLink = useSelect( select => select( STORE ).selectImageLink( "ai-generator-preview.png" ), [] );
Expand All @@ -29,6 +77,7 @@ export const ModalContent = () => {
learnMoreLink={ learnMoreLink }
thumbnail={ thumbnail }
wistiaEmbedPermission={ wistiaEmbedPermission }
{ ...postModalprops }
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
/* eslint-disable complexity */
import { LockOpenIcon } from "@heroicons/react/outline";
import { ArrowNarrowRightIcon } from "@heroicons/react/solid";
import { createInterpolateElement } from "@wordpress/element";
import { useSelect } from "@wordpress/data";
import { __, sprintf } from "@wordpress/i18n";
import { Badge, Button, useModalContext } from "@yoast/ui-library";
import PropTypes from "prop-types";
import { OutboundLink, VideoFlow } from ".";

const STORE = "yoast-seo/editor";

/**
* @param {string} learnMoreLink The learn more link.
* @param {Object} thumbnail The thumbnail: img props.
* @param {Object} wistiaEmbedPermission The value, status and set for the Wistia embed permission.
* @param {string} upsellLink The upsell link.
* @param {boolean} isProductCopy Whether the upsell is for a product.
* @param {string} title The title.
* @param {string} upsellLabel The upsell label.
* @param {string} newToText The new to text.
* @param {string|JSX.Element } bundleNote The bundle note.
* @returns {JSX.Element} The element.
*/
export const AiGenerateTitlesAndDescriptionsUpsell = ( { learnMoreLink, thumbnail, wistiaEmbedPermission } ) => {
export const AiGenerateTitlesAndDescriptionsUpsell = ( {
learnMoreLink,
thumbnail,
wistiaEmbedPermission,
upsellLink,
isProductCopy,
title,
upsellLabel,
newToText,
bundleNote,
} ) => {
const { onClose, initialFocus } = useModalContext();
const upsellLinkPremium = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell" ), [] );
const upsellLinkWooPremiumBundle = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell-woo-seo-premium-bundle" ), [] );
const upsellLinkWoo = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell-woo-seo" ), [] );
const isPremium = useSelect( select => select( STORE ).getIsPremium(), [] );
const isWooSeoUpsell = useSelect( select => select( STORE ).getIsWooSeoUpsell(), [] );
const isProduct = useSelect( select => select( STORE ).getIsProduct(), [] );

const wooSeoNoPremium = isProduct && ! isWooSeoUpsell && ! isPremium;
const isProductCopy = isWooSeoUpsell || wooSeoNoPremium;
let upsellLink = upsellLinkPremium;
let newToText = sprintf(
/* translators: %1$s expands to Yoast SEO Premium. */
__( "New to %1$s", "wordpress-seo" ),
"Yoast SEO Premium"
);
const learnMoreLinkStructure = {
// eslint-disable-next-line jsx-a11y/anchor-has-content
a: <OutboundLink
Expand All @@ -43,49 +41,6 @@ export const AiGenerateTitlesAndDescriptionsUpsell = ( { learnMoreLink, thumbnai
ArrowNarrowRightIcon: <ArrowNarrowRightIcon className="yst-w-4 yst-h-4 rtl:yst-rotate-180" />,
};

let upsellLabel = sprintf(
/* translators: %1$s expands to Yoast SEO Premium. */
__( "Unlock with %1$s", "wordpress-seo" ),
"Yoast SEO Premium"
);
let bundleNote = "";
let title = __( "Generate titles & descriptions with Yoast AI!", "wordpress-seo" );


if ( isProductCopy ) {
const upsellPremiumWooLabel = sprintf(
/* translators: %1$s expands to Yoast SEO Premium, %2$s expands to Yoast WooCommerce SEO. */
__( "%1$s + %2$s", "wordpress-seo" ),
"Yoast SEO Premium",
"Yoast WooCommerce SEO"
);
newToText = sprintf(
/* translators: %1$s expands to Yoast SEO Premium and Yoast WooCommerce SEO. */
__( "New to %1$s", "wordpress-seo" ),
upsellPremiumWooLabel
);
title = __( "Generate product titles & descriptions with AI!", "wordpress-seo" );
if ( ! isPremium && isWooSeoUpsell ) {
upsellLabel = `${sprintf(
/* translators: %1$s expands to Woo Premium bundle. */
__( "Unlock with the %1$s", "wordpress-seo" ),
"Woo Premium bundle"
)}*`;
bundleNote = <div className="yst-text-xs yst-text-slate-500 yst-mt-2">
{ `*${upsellPremiumWooLabel}` }
</div>;
upsellLink = upsellLinkWooPremiumBundle;
}
if ( isPremium ) {
upsellLabel = sprintf(
/* translators: %1$s expands to Yoast WooCommerce SEO. */
__( "Unlock with %1$s", "wordpress-seo" ),
"Yoast WooCommerce SEO"
);
upsellLink = upsellLinkWoo;
}
}

return (
<div className="yst-flex yst-flex-col yst-items-center yst-p-10">
<div className="yst-relative yst-w-full">
Expand Down Expand Up @@ -170,6 +125,7 @@ export const AiGenerateTitlesAndDescriptionsUpsell = ( { learnMoreLink, thumbnai
};
AiGenerateTitlesAndDescriptionsUpsell.propTypes = {
learnMoreLink: PropTypes.string.isRequired,
upsellLink: PropTypes.string.isRequired,
thumbnail: PropTypes.shape( {
src: PropTypes.string.isRequired,
width: PropTypes.string,
Expand All @@ -180,4 +136,28 @@ AiGenerateTitlesAndDescriptionsUpsell.propTypes = {
status: PropTypes.string.isRequired,
set: PropTypes.func.isRequired,
} ).isRequired,
title: PropTypes.string,
upsellLabel: PropTypes.string,
newToText: PropTypes.string,
isProductCopy: PropTypes.bool,
bundleNote: PropTypes.oneOfType( [
PropTypes.string,
PropTypes.element,
] ),
};

AiGenerateTitlesAndDescriptionsUpsell.defaultProps = {
title: __( "Generate titles & descriptions with Yoast AI!", "wordpress-seo" ),
upsellLabel: sprintf(
/* translators: %1$s expands to Yoast SEO Premium. */
__( "Unlock with %1$s", "wordpress-seo" ),
"Yoast SEO Premium"
),
newToText: sprintf(
/* translators: %1$s expands to Yoast SEO Premium. */
__( "New to %1$s", "wordpress-seo" ),
"Yoast SEO Premium"
),
isProductCopy: false,
bundleNote: "",
};
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ Release date: 2023-11-28
#### Other

* Adds defensive coding to the supress warnings on archive pages with the `/%category%/%postname%/` permalink structure. Props to [@Mte90](https://github.com/Mte90).
* Adds notification when WooCommerce new beta product editor is enabled.

= 21.5 =

Expand Down
137 changes: 137 additions & 0 deletions src/integrations/watchers/woocommerce-beta-editor-watcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

namespace Yoast\WP\SEO\Integrations\Watchers;

use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Conditionals\Not_Admin_Ajax_Conditional;
use Yoast\WP\SEO\Helpers\Notification_Helper;
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\Presenters\Admin\Woocommerce_Beta_Editor_Presenter;
use Yoast_Notification;
use Yoast_Notification_Center;

/**
* Shows a notification for users who have Woocommerce product beta editor enabled.
*
* @class Woocommerce_Beta_Editor_Watcher
*/
class Woocommerce_Beta_Editor_Watcher implements Integration_Interface {

/**
* The notification ID.
*/
const NOTIFICATION_ID = 'wpseo-woocommerce-beta-editor-warning';

/**
* The short link helper.
*
* @var Short_Link_Helper
*/
protected $short_link_helper;

/**
* The Yoast notification center.
*
* @var Yoast_Notification_Center
*/
protected $notification_center;

/**
* The notification helper.
*
* @var Notification_Helper
*/
protected $notification_helper;

/**
* The Woocommerce beta editor presenter.
*
* @var Woocommerce_Beta_Editor_Presenter
*/
protected $presenter;

/**
* Woocommerce_Beta_Editor_Watcher constructor.
*
* @param Yoast_Notification_Center $notification_center The notification center.
* @param Notification_Helper $notification_helper The notification helper.
* @param Short_Link_Helper $short_link_helper The short link helper.
*/
public function __construct(
Yoast_Notification_Center $notification_center,
Notification_Helper $notification_helper,
Short_Link_Helper $short_link_helper
) {
$this->notification_center = $notification_center;
$this->notification_helper = $notification_helper;
$this->short_link_helper = $short_link_helper;
$this->presenter = new Woocommerce_Beta_Editor_Presenter( $this->short_link_helper );
}

/**
* Returns the conditionals based on which this loadable should be active.
*
* @return string[] The conditionals.
*/
public static function get_conditionals() {
return [ Admin_Conditional::class, Not_Admin_Ajax_Conditional::class ];
}

/**
* Initializes the integration.
*
* On admin_init, it is checked whether the notification about Woocommerce product beta editor enabled should be shown.
*
* @return void
*/
public function register_hooks() {
\add_action( 'admin_init', [ $this, 'manage_woocommerce_beta_editor_notification' ] );
}

/**
* Manage the Woocommerce product beta editor notification.
*
* Shows the notification if needed and deletes it if needed.
*
* @return void
*/
public function manage_woocommerce_beta_editor_notification() {
if ( \get_option( 'woocommerce_feature_product_block_editor_enabled' ) === 'yes' ) {
$this->maybe_add_woocommerce_beta_editor_notification();
}
else {
$this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID );
}
}

/**
* Add the Woocommerce product beta editor enabled notification if it does not exist yet.
*
* @return void
*/
public function maybe_add_woocommerce_beta_editor_notification() {
if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) {
$notification = $this->notification();
$this->notification_helper->restore_notification( $notification );
$this->notification_center->add_notification( $notification );
}
}

/**
* Returns an instance of the notification.
*
* @return Yoast_Notification The notification to show.
*/
protected function notification() {
return new Yoast_Notification(
$this->presenter->present(),
[
'type' => Yoast_Notification::ERROR,
'id' => self::NOTIFICATION_ID,
'capabilities' => 'wpseo_manage_options',
'priority' => 1,
]
);
}
}
Loading

0 comments on commit a4bc970

Please sign in to comment.