Skip to content

Commit

Permalink
Merge pull request #2660 from Parsely/prepare/3.16.1
Browse files Browse the repository at this point in the history
Release wp-parsely 3.16.1
  • Loading branch information
vaurdan authored Jul 18, 2024
2 parents 8c417d5 + 73664ac commit c2d8cbd
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 84 deletions.
Binary file modified .wordpress-org/screenshot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.16.1](https://github.com/Parsely/wp-parsely/compare/3.16.0...3.16.1) - 2024-07-18

### Fixed

- PCH Performance Stats: Remove UTM parameters from the 'View in Parse.ly' button ([#2655](https://github.com/Parsely/wp-parsely/pull/2655))
- PCH Smart Linking: Show error when API returns empty list of Smart Link suggestions ([#2654](https://github.com/Parsely/wp-parsely/pull/2654))
- PCH Smart Linking: Fix CSS leaking from the Block Preview ([#2652](https://github.com/Parsely/wp-parsely/pull/2652))
- PCH Smart Linking: Use the post title as the Smart Link title. ([#2650](https://github.com/Parsely/wp-parsely/pull/2650))
- Permissions: Fix PHP Warning when the user role is invalid ([#2649](https://github.com/Parsely/wp-parsely/pull/2649))

## [3.16.0](https://github.com/Parsely/wp-parsely/compare/3.15.0...3.16.0) - 2024-07-08

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Parse.ly

Stable tag: 3.16.0
Stable tag: 3.16.1
Requires at least: 5.2
Tested up to: 6.5
Requires PHP: 7.2
Expand Down
2 changes: 1 addition & 1 deletion 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-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '629f8616ef4e8194995e');
<?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-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'b8c0240b984732a6e310');
2 changes: 1 addition & 1 deletion build/content-helper/editor-sidebar.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/content-helper/editor-sidebar.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-parsely",
"version": "3.16.0",
"version": "3.16.1",
"private": true,
"description": "The Parse.ly plugin facilitates real-time and historical analytics to your content through a platform designed and built for digital publishing.",
"author": "parsely, hbbtstar, jblz, mikeyarce, GaryJ, parsely_mike, acicovic, mehmoodak, vaurdan",
Expand Down
9 changes: 8 additions & 1 deletion src/Models/class-smart-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ public function __construct(
int $post_id = 0
) {
$this->set_href( $href );
$this->title = $title;

// Set the title to be the destination post title if the destination post ID is set.
if ( 0 !== $this->destination_post_id ) {
$this->title = get_the_title( $this->destination_post_id );
} else {
$this->title = $title;
}

$this->text = $text;
$this->offset = $offset;
$this->source_post_id = $post_id;
Expand Down
15 changes: 14 additions & 1 deletion src/class-dashboard-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ class Dashboard_Link {
*
* @since 2.6.0
* @since 3.1.0 Moved to class-dashboard-link.php. Added source parameter.
* @since 3.16.1 Made the $campaign and $source parameters optional.
*
* @param WP_Post $post Which post object or ID to check.
* @param string $site_id Site ID or empty string.
* @param string $campaign Campaign name for the `utm_campaign` URL parameter.
* @param string $source Source name for the `utm_source` URL parameter.
* @return string
*/
public static function generate_url( WP_Post $post, string $site_id, string $campaign, string $source ): string {
public static function generate_url( WP_Post $post, string $site_id, string $campaign = '', string $source = '' ): string {
/**
* Internal variable.
*
Expand All @@ -50,6 +51,18 @@ public static function generate_url( WP_Post $post, string $site_id, string $cam
'utm_medium' => 'wp-parsely',
);

if ( '' === $campaign ) {
unset( $query_args['utm_campaign'] );
}

if ( '' === $source ) {
unset( $query_args['utm_source'] );
}

if ( ! isset( $query_args['utm_campaign'] ) && ! isset( $query_args['utm_source'] ) ) {
unset( $query_args['utm_medium'] );
}

return add_query_arg( $query_args, Parsely::get_dash_url( $site_id ) );
}

Expand Down
30 changes: 17 additions & 13 deletions src/class-permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,34 @@ public static function current_user_can_use_pch_feature(
return false;
}

// Current user's role is not yet set.
$current_user = wp_get_current_user();
if ( 0 === count( $current_user->roles ) ) {
$user_roles = $current_user->roles;

// Current user's role is not yet set.
if ( 0 === count( $user_roles ) ) {
return false;
}

// Check that the user's role has the capability to edit posts.
$current_user_role = $current_user->roles[0];
$valid_roles = array_keys( self::get_user_roles_with_edit_posts_cap() );
if ( ! in_array( $current_user_role, $valid_roles, true ) ) {
// Get the roles with the capability to edit posts.
$valid_roles = array_keys( self::get_user_roles_with_edit_posts_cap() );

// Check that at least one of the user's roles has the capability to edit posts.
if ( 0 === count( array_intersect( $user_roles, $valid_roles ) ) ) {
return false;
}

// Check that the user's role has access to the specific feature/post.
// Check that at least one of the user's roles has access to the specific feature/post.
$allowed_roles = $feature_options['allowed_user_roles'];
if ( in_array( $current_user_role, $allowed_roles, true ) ) {
if ( (int) $post_id > 0 ) {
return current_user_can( 'edit_post', $post_id );
}
if ( 0 === count( array_intersect( $user_roles, $allowed_roles ) ) ) {
return false;
}

return true;
// Check if the user can edit the post.
if ( (int) $post_id > 0 ) {
return current_user_can( 'edit_post', $post_id );
}

return false;
return true;
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/content-helper/editor-sidebar/class-editor-sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ public static function get_style_id(): string {
* Returns the Parse.ly post dashboard URL for the current post.
*
* @since 3.14.0
* @since 3.16.1 Added the $show_utm_params parameter.
*
* @param int|null|WP_Post $post_id The post ID or post object. Default is the current post.
* @param bool $add_utm_params Whether to add UTM parameters in the URL.
* @return string|null The Parse.ly post dashboard URL, or false if the post ID is invalid.
*/
private function get_parsely_post_url( $post_id = null ): ?string {
private function get_parsely_post_url( $post_id = null, bool $add_utm_params = true ): ?string {
// Get permalink for the post.
$post_id = $post_id ?? get_the_ID();
if ( false === $post_id ) {
Expand All @@ -117,6 +119,10 @@ private function get_parsely_post_url( $post_id = null ): ?string {
return null;
}

if ( ! $add_utm_params ) {
return Dashboard_Link::generate_url( $post, $this->parsely->get_site_id() );
}

return Dashboard_Link::generate_url( $post, $this->parsely->get_site_id(), 'wp-page-single', 'editor-sidebar' );
}

Expand Down Expand Up @@ -159,8 +165,8 @@ public function run(): void {

$this->inject_inline_scripts( Editor_Sidebar_Settings_Endpoint::get_route() );

// Inject inline variables for the editor sidebar.
$parsely_post_url = $this->get_parsely_post_url();
// Inject inline variables for the editor sidebar, without UTM parameters.
$parsely_post_url = $this->get_parsely_post_url( null, false );
if ( null !== $parsely_post_url ) {
wp_add_inline_script(
static::get_script_id(),
Expand Down
12 changes: 11 additions & 1 deletion src/content-helper/editor-sidebar/smart-linking/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,17 @@ export const SmartLinkingPanel = ( {
try {
const generatedLinks = await generateSmartLinksWithRetry( MAX_NUMBER_OF_RETRIES );
await processSmartLinks( generatedLinks );
setIsReviewModalOpen( true );
if ( smartLinks.length === 0 ) {
const contentHelperError = new ContentHelperError(
__( 'No smart links were generated.', 'wp-parsely' ),
ContentHelperErrorCode.ParselyApiReturnedNoData,
''
);
await setError( contentHelperError );
contentHelperError.createErrorSnackbar();
} else {
setIsReviewModalOpen( true );
}
} catch ( e: any ) { // eslint-disable-line @typescript-eslint/no-explicit-any
const contentHelperError = new ContentHelperError(
e.message ?? 'An unknown error has occurred.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,33 @@ import { BlockEditorProvider, BlockList } from '@wordpress/block-editor';
import { BlockInstance, cloneBlock, getBlockContent } from '@wordpress/blocks';
import { Disabled } from '@wordpress/components';
import { select } from '@wordpress/data';
import { useCallback, useEffect, useMemo } from '@wordpress/element';
import { useCallback, useEffect, useMemo, useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import { SmartLink } from '../provider';
import { applyNodeToBlock } from '../utils';

/**
* The style object, a derivative from Gutenberg's `Style` type.
*
* @since 3.16.1
*/
type Style = {
css?: string,
assets?: string,
__unstableType?: string,
};

/**
* The props for the Styles component.
*
* @since 3.16.0
* @since 3.16.1 Extracted the styles prop to a new `Style` type.
*/
type StylesProps = {
styles: {
css?: string,
assets?: string,
__unstableType?: string,
}[],
styles: Style[],
};

/**
Expand All @@ -37,20 +45,85 @@ type StylesProps = {
* @param {StylesProps} props The component props.
*/
const Styles = ( { styles }: StylesProps ): React.JSX.Element => {
// Get only the theme and user styles.
const filteredStyles = styles
.filter( ( style ) => {
return (
style.__unstableType === 'theme' ||
style.__unstableType === 'user'
) && style.css;
/**
* Prefixes the selectors in the CSS with the given prefix.
*
* It also replaces the `body` selector with the prefix itself.
*
* @since 3.16.1
*
* @param {string} css The CSS to prefix.
* @param {string} prefix The prefix to use.
*/
const prefixSelectors = ( css: string, prefix: string ): string => {
// Split the CSS into individual rules.
const cssRules = css.split( '}' );

const prefixedRules = cssRules.map( ( rule ) => {
// If the rule is empty, skip it.
if ( ! rule.trim() ) {
return '';
}

// eslint-disable-next-line @wordpress/no-unused-vars-before-return
const [ selectors, properties ] = rule.split( '{' );

// If there are no properties, return the rule as is.
if ( ! properties ) {
return rule;
}

// Add the prefix to each selector.
const prefixedSelectors = selectors
.split( ',' )
.map( ( selector ) => {
const trimmedSelector = selector.trim();
if ( ! trimmedSelector ) {
return '';
}
// Replace the `body` selector with the prefix.
if ( trimmedSelector === 'body' ) {
return prefix;
}
return `${ prefix } ${ trimmedSelector }`;
} ).join( ', ' );

return `${ prefixedSelectors } {${ properties }}`;
} );

// Returns the styles, but replaces the body selector with the block editor selector.
return prefixedRules.join( ' ' );
};

const [ processedStyles, setProcessedStyles ] = useState<Style[]>( [] );

/**
* Processes the styles to prefix all the Editor styles selectors with the Preview Editor wrapper class.
*
* @since 3.16.1
*/
useEffect( () => {
const processStyles = () => {
const filteredStyles = styles.filter( ( style ) => {
return (
( style.__unstableType === 'theme' || style.__unstableType === 'user' ) && style.css
);
} );

const processed = filteredStyles.map( ( style ) => {
const prefixedCss = prefixSelectors( style.css ?? '', '.wp-parsely-preview-editor' );
return { ...style, css: prefixedCss };
} );

setProcessedStyles( processed );
};

processStyles();
}, [ styles ] );

return (
<>
{ filteredStyles.map( ( style, index ) => (
<style key={ index }>{ style.css?.replace( /body/g, '.wp-parsely-preview-editor' ) }</style>
{ processedStyles.map( ( style, index ) => (
<style key={ index }>{ style.css }</style>
) ) }
</>
);
Expand Down Expand Up @@ -185,19 +258,21 @@ export const BlockPreview = ( { block, link, useOriginalBlock }: BlockPreviewPro
const settings = select( 'core/block-editor' ).getSettings();

return (
<Disabled className="wp-block-post-content editor-styles-wrapper wp-parsely-preview-editor" >
<BlockEditorProvider
value={ [ clonedBlock ] }
settings={ {
...settings,
// @ts-ignore __unstableIsPreviewMode is not in the types.
__unstableIsPreviewMode: true,
templateLock: 'all',
} }
>
<Styles styles={ settings.styles } />
<BlockList />
</BlockEditorProvider>
</Disabled>
<div className="wp-parsely-preview-editor">
<Disabled className="wp-block-post-content editor-styles-wrapper" >
<BlockEditorProvider
value={ [ clonedBlock ] }
settings={ {
...settings,
// @ts-ignore __unstableIsPreviewMode is not in the types.
__unstableIsPreviewMode: true,
templateLock: 'all',
} }
>
<Styles styles={ settings.styles } />
<BlockList />
</BlockEditorProvider>
</Disabled>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,10 @@

.wp-parsely-preview-editor {

&.editor-styles-wrapper {
.editor-styles-wrapper {
padding-bottom: 0;
font-size: var(--font-size--medium);
background: var(--Gutenberg-White, #fff);
}

p[role="document"] {
Expand All @@ -503,6 +504,6 @@
background: hsla(var(--parsely-green-components), 0.5);
mix-blend-mode: multiply;
text-decoration-line: underline;
color: var(--sidebar-black);
color: var(--sidebar-black) !important;
}
}
Loading

0 comments on commit c2d8cbd

Please sign in to comment.