diff --git a/.changelogs/issue-3165.yml b/.changelogs/issue-3165.yml new file mode 100644 index 0000000000..b56d8a263f --- /dev/null +++ b/.changelogs/issue-3165.yml @@ -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. diff --git a/includes/admin/class.llms.admin.assets.php b/includes/admin/class.llms.admin.assets.php index ad6bc9feae..f085e0d17c 100644 --- a/includes/admin/class.llms.admin.assets.php +++ b/includes/admin/class.llms.admin.assets.php @@ -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' ) ); } /** @@ -391,7 +392,7 @@ public function admin_scripts() { /** * Register the media protection scripts when the media is enqueued. * - * @since 9.0.6 + * @since [version] * * @return void */ @@ -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 [version] + * + * @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 * diff --git a/src/js/admin-media-protection-block-protect.js b/src/js/admin-media-protection-block-protect.js index 2673b526e8..f704aa808e 100644 --- a/src/js/admin-media-protection-block-protect.js +++ b/src/js/admin-media-protection-block-protect.js @@ -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( @@ -62,7 +77,7 @@ } }, [ isModalOpen ] ); - const handleProtectImage = () => { + const handleProtectMedia = () => { const selectedId = jQuery( selectRef.current ).val(); apiFetch( { @@ -118,13 +133,15 @@ } ); }, [ isModalOpen, props.attributes.id ] ); + const mediaTypeLabel = getMediaTypeLabel( props.name ); + return ( setModalOpen( true ) } /> @@ -136,7 +153,7 @@ > - + @@ -165,10 +182,10 @@