Skip to content

Commit

Permalink
Merge branch 'develop' into update/add-php-8.4-to-tests-and-move-pcov…
Browse files Browse the repository at this point in the history
…-to-php-8.2-retry
  • Loading branch information
acicovic committed Oct 25, 2024
2 parents b88e9ba + 4510ea3 commit 3a73b33
Show file tree
Hide file tree
Showing 39 changed files with 1,009 additions and 684 deletions.
5 changes: 3 additions & 2 deletions build/content-helper/editor-sidebar-rtl.css

Large diffs are not rendered by default.

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'), 'version' => '6e668f9bfad0f3f02bf6');
<?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' => 'd6febeb9486e0cff901d');
5 changes: 3 additions & 2 deletions build/content-helper/editor-sidebar.css

Large diffs are not rendered by default.

45 changes: 24 additions & 21 deletions build/content-helper/editor-sidebar.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion build/content-helper/excerpt-generator-rtl.css

This file was deleted.

1 change: 0 additions & 1 deletion build/content-helper/excerpt-generator.asset.php

This file was deleted.

1 change: 0 additions & 1 deletion build/content-helper/excerpt-generator.css

This file was deleted.

4 changes: 0 additions & 4 deletions build/content-helper/excerpt-generator.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/UI/class-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Parsely\UI;

use Parsely\Content_Helper\Excerpt_Generator;
use Parsely\Content_Helper\Excerpt_Suggestions;
use Parsely\Parsely;
use Parsely\Permissions;
use Parsely\Utils\Utils;
Expand Down Expand Up @@ -496,7 +496,7 @@ private function initialize_content_helper_section(): void {
'option_key' => $field_id,
'label_for' => $field_id,
'legend' => __( 'Excerpt Suggestions', 'wp-parsely' ),
'filter' => Excerpt_Generator::get_feature_filter_name(),
'filter' => Excerpt_Suggestions::get_feature_filter_name(),
);
add_settings_field(
$field_id,
Expand Down
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
10 changes: 10 additions & 0 deletions src/content-helper/common/css/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
}
}

.wp-parsely-dropdown-label {
align-self: stretch;
color: var(--sidebar-black);
font-size: var(--font-size--smaller);
font-style: normal;
font-weight: 600;
line-height: var(--grid-unit-20);
text-transform: uppercase;
}

.wp-parsely-content-helper-error {
margin: 0;
align-self: flex-start;
Expand Down
3 changes: 2 additions & 1 deletion src/content-helper/common/settings/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Import the settings types.
*/
import type {
ExcerptSuggestionsSettings,
PerformanceStatsSettings,
RelatedPostsSettings,
SidebarSettings,
Expand All @@ -14,6 +15,7 @@ import type { TopPostsSettings } from './top-posts-settings';
* Export the settings types.
*/
export type {
ExcerptSuggestionsSettings, // Part of SidebarSettings type.
PerformanceStatsSettings, // Part of SidebarSettings type.
RelatedPostsSettings, // Part of SidebarSettings type.
SidebarSettings,
Expand All @@ -24,4 +26,3 @@ export type {

// Generic type for settings.
export type Settings = SidebarSettings | TopPostsSettings;

12 changes: 12 additions & 0 deletions src/content-helper/common/settings/types/sidebar-settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface SidebarSettings {
RelatedPosts: RelatedPostsSettings;
SmartLinking: SmartLinkingSettings;
TitleSuggestions: TitleSuggestionsSettings;
ExcerptSuggestions: ExcerptSuggestionsSettings;
}

/**
Expand Down Expand Up @@ -58,3 +59,14 @@ export interface SmartLinkingSettings {
MaxLinks: number;
Open: boolean;
}

/**
* Defines the settings structure for the PostExcerptSuggestions component.
*
* @since 3.17.0
*/
export interface ExcerptSuggestionsSettings {
Open: boolean;
Persona: string;
Tone: string;
}
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
104 changes: 104 additions & 0 deletions src/content-helper/editor-sidebar/class-editor-sidebar-feature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* Editor Sidebar: Base class for all Editor Sidebar features
*
* @package Parsely
* @since 3.17.0
*/

declare(strict_types=1);

namespace Parsely\Content_Helper\Editor_Sidebar;

use Parsely\Content_Helper\Content_Helper_Feature;
use Parsely\Content_Helper\Editor_Sidebar;
use Parsely\Permissions;

/**
* Base class for all Editor Sidebar features.
*
* @since 3.17.0
*/
abstract class Editor_Sidebar_Feature extends Content_Helper_Feature {
/**
* Returns the feature's name.
*
* @since 3.17.0
*
* @return string
*/
abstract public static function get_feature_name(): string;

/**
* Constructor.
*
* @since 3.17.0
*
* @param Editor_Sidebar $editor_sidebar Instance of Editor_Sidebar class.
*/
public function __construct( Editor_Sidebar $editor_sidebar ) {
$this->parsely = $editor_sidebar->parsely;
}

/**
* Returns whether the feature can be enabled for the current user.
*
* @since 3.16.0
* @since 3.17.0 Moved to Editor_Sidebar_Feature class.
*
* @param bool ...$conditions Conditions that need to be met besides filters
* for the function to return true.
* @return bool Whether the feature can be enabled.
*/
protected function can_enable_feature( bool ...$conditions ): bool {
if ( ! parent::can_enable_feature( ...$conditions ) ) {
return false;
}

return Permissions::current_user_can_use_pch_feature(
static::get_feature_name(),
$this->parsely->get_options()['content_helper'],
get_the_ID()
);
}

/**
* Returns the feature's filter name. The feature filter controls the
* enabled/disabled state of a particular Content Helper feature.
*
* Not in use for Editor Sidebar features.
*
* @since 3.17.0
*
* @return string The filter name.
*/
public static function get_feature_filter_name(): string {
return ''; // Not in use for this feature.
}

/**
* Returns the feature's script ID.
*
* Not in use for Editor Sidebar features.
*
* @since 3.17.0
*
* @return string The script ID.
*/
public static function get_script_id(): string {
return '';
}

/**
* Returns the feature's style ID.
*
* Not in use for Editor Sidebar features.
*
* @since 3.17.0
*
* @return string The style ID.
*/
public static function get_style_id(): string {
return '';
}
}
7 changes: 4 additions & 3 deletions src/content-helper/editor-sidebar/class-editor-sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

namespace Parsely\Content_Helper;

use Parsely\Content_Helper\Editor_Sidebar\Editor_Sidebar_Feature;
use Parsely\Content_Helper\Editor_Sidebar\Smart_Linking;
use Parsely\Dashboard_Link;
use Parsely\Parsely;

use Parsely\REST_API\Settings\Endpoint_Editor_Sidebar_Settings;
use Parsely\Utils\Utils;
use WP_Post;
Expand All @@ -32,7 +32,7 @@ class Editor_Sidebar extends Content_Helper_Feature {
*
* @since 3.16.0
*
* @var array<Content_Helper_Feature>
* @var array<Editor_Sidebar_Feature>
*/
protected $features;

Expand All @@ -48,7 +48,8 @@ public function __construct( Parsely $parsely ) {

// Instantiate the features.
$this->features = array(
'Smart_Linking' => new Smart_Linking( $this ),
'Smart_Linking' => new Smart_Linking( $this ),
'Excerpt_Generator' => new Excerpt_Suggestions( $this ),
);
}

Expand Down
24 changes: 24 additions & 0 deletions src/content-helper/editor-sidebar/editor-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
isInEnum,
} from '../common/utils/constants';
import { getContentHelperPermissions } from '../common/utils/permissions';
import { initExcerptSuggestions } from './excerpt-suggestions/excerpt-suggestions';
import {
DEFAULT_MAX_LINKS,
initSmartLinking,
Expand All @@ -39,6 +40,7 @@ import { SidebarPerformanceTab } from './tabs/sidebar-performance-tab';
import { SidebarToolsTab } from './tabs/sidebar-tools-tab';

const BLOCK_PLUGIN_ID = 'wp-parsely-block-editor-sidebar';
export { BLOCK_PLUGIN_ID as PARSELY_SIDEBAR_PLUGIN_ID };

export type OnSettingChangeFunction = ( key: keyof SidebarSettings, value: string | boolean | number ) => void;

Expand Down Expand Up @@ -92,6 +94,11 @@ export const getSettingsFromJson = ( settingsJson: string = '' ): SidebarSetting
Tone: 'neutral',
Persona: 'journalist',
},
ExcerptSuggestions: {
Open: false,
Persona: 'journalist',
Tone: 'neutral',
},
};

// If the settings are empty, try to get them from the global variable.
Expand Down Expand Up @@ -165,6 +172,18 @@ export const getSettingsFromJson = ( settingsJson: string = '' ): SidebarSetting
if ( typeof mergedSettings.TitleSuggestions.Persona !== 'string' ) {
mergedSettings.TitleSuggestions.Persona = defaultSettings.TitleSuggestions.Persona;
}
if ( typeof mergedSettings.ExcerptSuggestions !== 'object' ) {
mergedSettings.ExcerptSuggestions = defaultSettings.ExcerptSuggestions;
}
if ( typeof mergedSettings.ExcerptSuggestions.Open !== 'boolean' ) {
mergedSettings.ExcerptSuggestions.Open = defaultSettings.ExcerptSuggestions.Open;
}
if ( typeof mergedSettings.ExcerptSuggestions.Tone !== 'string' ) {
mergedSettings.ExcerptSuggestions.Tone = defaultSettings.ExcerptSuggestions.Tone;
}
if ( typeof mergedSettings.ExcerptSuggestions.Persona !== 'string' ) {
mergedSettings.ExcerptSuggestions.Persona = defaultSettings.ExcerptSuggestions.Persona;
}

return mergedSettings;
};
Expand Down Expand Up @@ -274,6 +293,11 @@ const ContentHelperEditorSidebar = (): React.JSX.Element => {
);
};

// Initialize Excerpt Suggestions.
if ( initExcerptSuggestions ) {
initExcerptSuggestions();
}

// Registering Plugin to WordPress Block Editor.
registerPlugin( BLOCK_PLUGIN_ID, {
icon: LeafIcon,
Expand Down
Loading

0 comments on commit 3a73b33

Please sign in to comment.