| 1 |
import { __ } from '@wordpress/i18n'; |
| 2 |
|
| 3 |
export function openWpMedia( onSelect ) { |
| 4 |
if ( ! window.wp?.media ) return; |
| 5 |
const frame = window.wp.media( { |
| 6 |
title: __( 'Select Image', 'better-payment' ), |
| 7 |
multiple: false, |
| 8 |
library: { type: 'image' }, |
| 9 |
button: { text: __( 'Select', 'better-payment' ) }, |
| 10 |
} ); |
| 11 |
frame.on( 'select', () => { |
| 12 |
const att = frame.state().get( 'selection' ).first().toJSON(); |
| 13 |
onSelect( { url: att.url, id: att.id, sizes: att.sizes || {} } ); |
| 14 |
} ); |
| 15 |
frame.open(); |
| 16 |
} |
| 17 |
|