Skip to content

fix(media): use correct media type labels for block protection toolbar#3182

Open
faisalahammad wants to merge 1 commit into
gocodebox:devfrom
faisalahammad:fix/3165-media-protection-block-labels-dev
Open

fix(media): use correct media type labels for block protection toolbar#3182
faisalahammad wants to merge 1 commit into
gocodebox:devfrom
faisalahammad:fix/3165-media-protection-block-labels-dev

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

The media protection toolbar button and modal always said "Protect Image" even when the selected block was a file, video, or audio block. This change makes the label match the actual media type.

Fixes #3165

Changes

src/js/admin-media-protection-block-protect.js

Before:

<ToolbarButton
    icon="lock"
    label="Protect Image"
    onClick={ () => setModalOpen( true ) }
/>

After:

const mediaTypeLabel = getMediaTypeLabel( props.name );

<ToolbarButton
    icon="lock"
    label={ LLMS.l10n.replace( 'Protect %s', { '%s': mediaTypeLabel } ) }
    onClick={ () => setModalOpen( true ) }
/>

Why: core/image, core/video, core/audio, and core/file are all supported, but the labels were hardcoded for images. A new getMediaTypeLabel() helper returns the correct noun for each block type.

includes/admin/class.llms.admin.assets.php

Before:
Core did not provide the translatable strings used by the new dynamic labels, so the toolbar would fall back to the literal English strings.

After:
Core now adds the needed strings via the existing lifterlms_js_l10n_admin filter:

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' ),
        )
    );
}

Why: This keeps the change inside the existing LLMS.l10n system instead of introducing a new wp-i18n dependency for one script.

Testing

Test 1: File block label

  1. Create a page and add a File block with an uploaded file.
  2. Click the lock icon in the toolbar.

Result: toolbar tooltip and modal button say "Protect File", and the select label says "Select a Course or Membership to protect this file:".

Test 2: Video and Audio blocks

  1. Add a Video block and an Audio block.
  2. Click the lock icon for each.

Result: labels say "Protect Video" and "Protect Audio" respectively.

Test 3: Image block remains unchanged

  1. Add an Image block.
  2. Click the lock icon.

Result: labels still say "Protect Image".

- Replace hardcoded 'Protect Image' labels with dynamic labels based on block type.
- Add getMediaTypeLabel() helper for image, audio, video, and file blocks.
- Add translatable strings for dynamic protection labels via the existing JS l10n filter.

Fixes gocodebox#3165
@faisalahammad
faisalahammad requested a review from brianhogg as a code owner June 15, 2026 19:18
@brianhogg brianhogg moved this to Awaiting Review in Development Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting Review

Development

Successfully merging this pull request may close these issues.

2 participants