How to securely set dynamic HTML content with JavaScript?

Using wp_kses_post to escape the texts before setting them in wp_add_inline_script is a good approach to prevent malicious content from being added to the page. This will ensure that the text is properly sanitized and only contains allowed HTML tags and attributes. If you want to allow certain HTML tags and attributes, you can use … Read more

How can I show a Slot/Fill in the block editor

By wrapping everything in a <SlotFillProvider> and rendering MyTestFill it works, here is the code: const { Fill, Slot } = createSlotFill( ‘MyFill’ ); const TestFill = () => <Fill>My item in the editor</Fill>; export default function Edit() { return ( <p { …useBlockProps() }> <SlotFillProvider> <Slot /> { __( ‘Fill Test – hello from … Read more

How to detect if we are in the Site Editor part of the Block Editor (as opposed to editing a Page/Post) in JavaScript?

The Block Editor, in both the context of the editing pages or the Site Editor, actually does provide some simple variables in JavaScript similar to the data that is available via get_current_screen in PHP. Sample variables in Page Editor: var ajaxurl=”/mysite/wp-admin/admin-ajax.php”, pagenow = ‘page’, typenow = ‘page’, adminpage=”post-new-php”, thousandsSeparator=”,”, decimalPoint=”.”, isRtl = 0; Sample variables … Read more

Why is this script not working?

I think the issue that the Google maps API isn’t loading correctly. You need to make sure that the both jQuery and Google maps API are being loaded. https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js http://maps.google.com/maps/api/js It can be any recent version of jQuery, and from any source. Assuming that your jQuery function is contained within your google-maps-address.js file the following … Read more