导入 AKSRT 主题开发源码

This commit is contained in:
Claude Code committed 2026-07-03 22:50:34 +08:00
1 parent 9681dd3d48
commit 1268a55dd0
595 files changed
+127705

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
export function openMediaPicker(options = {}) {
const wpMedia = window.wp?.media
if (!wpMedia) {
throw new Error('当前后台未加载 WordPress 媒体库。')
}
const frame = wpMedia({
title: options.title || '选择图片',
button: {
text: options.buttonText || '使用此图片',
},
library: {
type: options.type || 'image',
},
multiple: false,
})
return new Promise((resolve, reject) => {
frame.on('select', () => {
const attachment = frame.state().get('selection').first()?.toJSON()
if (!attachment?.url) {
reject(new Error('未选择有效的媒体资源。'))
return
}
resolve(attachment)
})
frame.on('close', () => {
const hasSelection = frame.state().get('selection').length > 0
if (!hasSelection) {
resolve(null)
}
})
frame.open()
})
}