Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelogs/issue-3165.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
significance: patch
type: fixed
entry: Fixed media protection block editor labels incorrectly showing "Protect Image" for file, video, and audio blocks.
23 changes: 23 additions & 0 deletions includes/admin/class.llms.admin.assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function __construct() {
add_action( 'admin_print_footer_scripts', array( $this, 'admin_print_footer_scripts' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'block_editor_assets' ) );
add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'elementor_editor_assets' ) );
add_filter( 'lifterlms_js_l10n_admin', array( $this, 'add_media_protection_js_l10n' ) );
}

/**
Expand Down Expand Up @@ -490,6 +491,28 @@ protected function get_analytics_options() {
return apply_filters( 'llms_get_analytics_js_options', compact( 'currency_format' ) );
}

/**
* Add translatable strings used by the media protection block editor toolbar.
*
* @since 10.0.6

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect hard-coded value. [version] instead.

*
* @param array $strings Array of JS l10n strings.
* @return array
*/
public function add_media_protection_js_l10n( $strings ) {
return array_merge(
$strings,
array(
'Protect %s' => __( 'Protect %s', 'lifterlms' ),
'Select a Course or Membership to protect this %s:' => __( 'Select a Course or Membership to protect this %s:', 'lifterlms' ),
'image' => __( 'image', 'lifterlms' ),
'audio' => __( 'audio', 'lifterlms' ),
'video' => __( 'video', 'lifterlms' ),
'file' => __( 'file', 'lifterlms' ),
)
);
}

/**
* Register and enqueue scripts used on and related-to reporting and analytics
*
Expand Down
27 changes: 22 additions & 5 deletions src/js/admin-media-protection-block-protect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@
}
};

const getMediaTypeLabel = ( blockName ) => {
switch ( blockName ) {
case 'core/image':
return LLMS.l10n.translate( 'image' );
case 'core/audio':
return LLMS.l10n.translate( 'audio' );
case 'core/video':
return LLMS.l10n.translate( 'video' );
case 'core/file':
return LLMS.l10n.translate( 'file' );
default:
return LLMS.l10n.translate( 'image' );
}
};

const withProtectImageToolbar = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
const warningText = createInterpolateElement(
Expand Down Expand Up @@ -62,7 +77,7 @@
}
}, [ isModalOpen ] );

const handleProtectImage = () => {
const handleProtectMedia = () => {
const selectedId = jQuery( selectRef.current ).val();

apiFetch( {
Expand Down Expand Up @@ -118,13 +133,15 @@
} );
}, [ isModalOpen, props.attributes.id ] );

const mediaTypeLabel = getMediaTypeLabel( props.name );

return (
<Fragment>
<BlockEdit { ...props } />
<BlockControls group="inline">
<ToolbarButton
icon="lock"
label="Protect Image"
label={ LLMS.l10n.replace( 'Protect %s', { '%s': mediaTypeLabel } ) }
onClick={ () => setModalOpen( true ) }
/>
</BlockControls>
Expand All @@ -136,7 +153,7 @@
>
<Flex direction="column" gap={4}>
<FlexItem>
<label htmlFor="llms-protect-image-select">{ LLMS.l10n.translate( 'Select a Course or Membership to protect this image:' ) }</label>
<label htmlFor="llms-protect-image-select">{ LLMS.l10n.replace( 'Select a Course or Membership to protect this %s:', { '%s': mediaTypeLabel } ) }</label>
</FlexItem>

<FlexItem>
Expand Down Expand Up @@ -165,10 +182,10 @@
<Button
isPrimary
onClick={ () => {
handleProtectImage();
handleProtectMedia();
} }
>
Protect Image
{ LLMS.l10n.replace( 'Protect %s', { '%s': mediaTypeLabel } ) }
</Button>
</FlexItem>
</Flex>
Expand Down
Loading