Skip to content

Commit 9eb22b6

Browse files
committed
Fix ACF
1 parent af0a990 commit 9eb22b6

File tree

4 files changed

+85
-23
lines changed

4 files changed

+85
-23
lines changed

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
* [ARVE Pro changelog](https://nextgenthemes.com/plugins/arve-pro/#changelog)
44
* [ARVE Random Videos changelog](https://nextgenthemes.com/plugins/arve-random-video/#changelog)
55

6+
### 2025-03-16 10.6.7 ###
7+
8+
* Fixed: Compatibility with Advanced Custom Fields WYSIWYG editors. The ARVE shortcode creation button now finally works there.
9+
610
### 2025-03-15 10.6.6 ###
711

812
* Improved: Tested with WP 6.8-beta2

php/Admin/fn-admin.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,8 @@ function add_action_links( array $links ): array {
388388

389389
function admin_enqueue_styles(): void {
390390

391-
if ( did_action( 'wp_enqueue_editor' ) ) {
392-
return;
393-
}
391+
// This shit prevents 'arve-admin-css was added to the iframe incorrectly.' error but it doesn't work with enqueue_block_editor_assets
392+
// if ( did_action( 'wp_enqueue_editor' ) ) { return; }
394393

395394
wp_enqueue_style(
396395
'arve-admin',
@@ -431,13 +430,11 @@ function admin_enqueue_scripts(): void {
431430
ver( PLUGIN_DIR . '/build/admin.js', VERSION ),
432431
array( 'strategy' => 'defer' ),
433432
);
434-
435433
wp_add_inline_script(
436434
'arve-admin',
437435
'var arveSCSettings = ' . wp_json_encode( $settings_data ) . ';',
438436
'before'
439437
);
440-
441438
wp_enqueue_script( 'arve-admin' );
442439

443440
if ( is_plugin_active( 'shortcode-ui/shortcode-ui.php' ) ) {

php/Admin/fn-shortcode-creator.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111

1212
const DIALOG_NAMESPACE = 'nextgenthemes_arve_dialog';
1313

14-
function add_media_button(): void {
14+
/**
15+
* Adds a media button to the Classic Editor or other editors that use the same API.
16+
*
17+
* The button triggers a shortcode creator dialog when clicked.
18+
*
19+
* @param string $editor_id The ID of the editor to add the button to.
20+
*/
21+
function add_media_button( string $editor_id ): void {
1522

1623
dialog_interactivity();
1724

@@ -29,6 +36,7 @@ function add_media_button(): void {
2936
),
3037
'data-wp-interactive' => DIALOG_NAMESPACE,
3138
'data-wp-on--click' => 'actions.openShortcodeDialog',
39+
'data-editor' => $editor_id,
3240
],
3341
);
3442

@@ -79,6 +87,13 @@ function create_shortcode_dialog(): void {
7987
ob_start();
8088

8189
?>
90+
<button
91+
type="button"
92+
data-wp-interactive="<?= esc_attr( DIALOG_NAMESPACE ); ?>"
93+
data-wp-on--click="actions.openShortcodeDialog"
94+
data-editor="content"
95+
hidden
96+
></button>
8297
<dialog
8398
class="arve-sc-dialog"
8499
data-wp-interactive="<?= esc_attr( DIALOG_NAMESPACE ); ?>"
@@ -91,15 +106,15 @@ class="arve-sc-dialog"
91106
<button type="button" class="media-modal-close" data-wp-on--click="actions.toggleHelp">
92107
<span class="media-modal-icon dashicons dashicons-editor-help">
93108
<span class="screen-reader-text">
94-
Toggle Help
109+
<?php esc_html_e( 'Toggle Help', 'advanced-responsive-video-embedder' ); ?>
95110
</span>
96111
</span>
97112
</button>
98113

99114
<button type="button" class="media-modal-close" data-wp-on--click="actions.closeShortcodeDialog">
100115
<span class="media-modal-icon">
101116
<span class="screen-reader-text">
102-
Close dialog
117+
<?php esc_html_e( 'Close dialog', 'advanced-responsive-video-embedder' ); ?>
103118
</span>
104119
</span>
105120
</button>

vendor/nextgenthemes/wp-settings/src/settings.ts

+61-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { store, getContext, getConfig } from '@wordpress/interactivity';
44
const domParser = new DOMParser();
55
const d = document;
66
const qs = d.querySelector.bind( d ) as typeof document.querySelector;
7+
const dialog = qs< HTMLDialogElement >( 'dialog[data-wp-interactive="nextgenthemes_arve_dialog"]' );
78

89
setupInteractivityApi();
910
setBodyBackgroundColorAsCssVar();
@@ -17,6 +18,23 @@ function setBodyBackgroundColorAsCssVar() {
1718
}
1819
}
1920

21+
// ACF
22+
window.jQuery( document ).on( 'click', '.arve-btn:not([data-editor="content"])', ( e: Event ) => {
23+
e.preventDefault();
24+
25+
const openBtn = qs< HTMLButtonElement >(
26+
'[data-wp-on--click="actions.openShortcodeDialog"][data-editor="content"]'
27+
);
28+
const insertBtn = qs< HTMLButtonElement >( '[data-wp-on--click="actions.insertShortcode"]' );
29+
30+
if ( ! openBtn || ! insertBtn || ! dialog ) {
31+
console.error( 'Open btn, insert btn od dialog not found' ); // eslint-disable-line
32+
return;
33+
}
34+
35+
openBtn.dispatchEvent( new Event( 'click' ) );
36+
} );
37+
2038
function setupInteractivityApi() {
2139
const namespace = qs< HTMLElement >( '[data-wp-interactive^="nextgenthemes"]' )?.dataset
2240
?.wpInteractive;
@@ -51,18 +69,43 @@ function setupInteractivityApi() {
5169
toggleHelp: () => {
5270
state.help = ! state.help;
5371
},
54-
openShortcodeDialog: () => {
55-
state.dialog = document.querySelector(
56-
'dialog[data-wp-interactive="nextgenthemes_arve_dialog"]'
57-
);
58-
state.dialog.showModal();
72+
openShortcodeDialog: ( event: Event ) => {
73+
const editorId = event.target instanceof HTMLElement && event.target.dataset.editor;
74+
75+
if ( ! dialog || ! editorId ) {
76+
console.error( 'Dialog or editorId not found' ); // eslint-disable-line
77+
return;
78+
}
79+
80+
dialog.dataset.editor = editorId;
81+
dialog.showModal();
5982
},
6083
insertShortcode: () => {
61-
window.wp.media.editor.insert( state.shortcode );
62-
state.dialog.close();
84+
const editorId = dialog?.dataset.editor;
85+
86+
if ( ! editorId ) {
87+
console.error( 'Editor ID not found' ); // eslint-disable-line
88+
} else if ( 'content' === editorId ) {
89+
window.wp.media.editor.insert( state.shortcode );
90+
} else {
91+
// Ensure TinyMCE is loaded and the editor exists
92+
if (
93+
typeof window.tinymce === 'undefined' ||
94+
! window.tinymce.get( editorId )
95+
) {
96+
console.error( 'TinyMCE not initialized for field: ' + editorId ); // eslint-disable-line
97+
return;
98+
}
99+
100+
window.tinymce.get( editorId ).insertContent( state.shortcode );
101+
}
102+
103+
actions.closeShortcodeDialog();
63104
},
64105
closeShortcodeDialog: () => {
65-
state.dialog.close();
106+
if ( dialog ) {
107+
dialog.close();
108+
}
66109
},
67110
changeTab: () => {
68111
const context = getContext< optionContext >();
@@ -101,8 +144,8 @@ function setupInteractivityApi() {
101144
}
102145
},
103146
selectImage: () => {
104-
if ( state.dialog ) {
105-
state.dialog.close();
147+
if ( dialog ) {
148+
dialog.close();
106149
}
107150

108151
const context = getContext< optionContext >();
@@ -118,13 +161,13 @@ function setupInteractivityApi() {
118161
// We convert uploadedImage to a JSON object to make accessing it easier
119162
const attachmentID = uploadedImage.toJSON().id;
120163
state.options[ context.option_key ] = attachmentID;
121-
if ( state.dialog ) {
122-
state.dialog.showModal();
164+
if ( dialog ) {
165+
dialog.showModal();
123166
}
124167
} )
125168
.on( 'close', function () {
126-
if ( state.dialog ) {
127-
state.dialog.showModal();
169+
if ( dialog ) {
170+
dialog.showModal();
128171
}
129172
} );
130173
},
@@ -301,6 +344,10 @@ declare global {
301344
wp: {
302345
media: wpMedia;
303346
};
347+
jQuery: any;
348+
tinymce: {
349+
get: ( id: string ) => any;
350+
};
304351
}
305352
}
306353

@@ -317,7 +364,6 @@ interface storeInterface {
317364
state: {
318365
options: Record< string, string | number | boolean >;
319366
help: boolean;
320-
dialog: HTMLDialogElement;
321367
isSaving: boolean;
322368
message: string;
323369
shortcode: string;

0 commit comments

Comments
 (0)