Skip to content

Commit

Permalink
Fix PCH permissions for Excerpt Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
vaurdan committed Sep 24, 2024
1 parent f19fd17 commit b409dcd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/content-helper/editor-sidebar.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => 'db69c114d741ca9a2460');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '6cff2a59e0a708629834');
4 changes: 2 additions & 2 deletions build/content-helper/editor-sidebar.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/class-permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ public static function current_user_can_use_pch_feature(
public static function get_pch_permissions_json( $pch_options ): string {
$permissions = array();
$features = array(
'SmartLinking' => 'smart_linking',
'TitleSuggestions' => 'title_suggestions',
'SmartLinking' => 'smart_linking',
'TitleSuggestions' => 'title_suggestions',
'ExcerptSuggestions' => 'excerpt_suggestions',
);

foreach ( $features as $key => $value ) {
Expand Down
2 changes: 2 additions & 0 deletions src/content-helper/common/utils/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export interface ContentHelperPermissions {
SmartLinking: boolean;
TitleSuggestions: boolean;
ExcerptSuggestions: boolean;
}

/**
Expand All @@ -19,6 +20,7 @@ export function getContentHelperPermissions(): ContentHelperPermissions {
const defaultPermissions: ContentHelperPermissions = {
SmartLinking: false,
TitleSuggestions: false,
ExcerptSuggestions: false,
};

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { registerPlugin } from '@wordpress/plugins';
* Internal dependencies
*/
import { dispatchCoreEditPost } from '../../../@types/gutenberg/types';
import { getContentHelperPermissions } from '../../common/utils/permissions';
import { ExcerptPanel } from './component-panel';
import './excerpt-suggestions.scss';

Expand All @@ -29,6 +30,12 @@ const ExcerptSuggestions = ( settings: never, name: string ) => {
return settings;
}

// Check if the user has the necessary permissions to use the ExcerptSuggestions feature.
const permissions = getContentHelperPermissions();
if ( ! permissions.ExcerptSuggestions ) {
return settings;
}

const isJetpackAiEnabled =
window?.Jetpack_Editor_Initial_State?.available_blocks[ 'ai-content-lens' ];

Expand Down

0 comments on commit b409dcd

Please sign in to comment.