Iptanus File Upload and Gutenberg

This article covers how the Iptanus File Upload plugin behaves in Gutenberg, WordPress’s block editor, and how to move a page that still uses the classic editor across to it.

The Gutenberg editor icon

Gutenberg builds a page out of blocks, in the manner of a page builder. It arrived as an optional plugin in WordPress 4.9.8 and became the default editor in WordPress 5.0, released in December 2018.

The plugin has been compatible with it since Gutenberg’s public release. If you are starting a new page today, the plugin’s own Gutenberg blocks are the easiest route; the rest of this article is about pages written in the classic editor.

Shortcodes

The plugin uses the [wordpress_file_upload] shortcode for an upload form, and [wordpress_file_upload_browser] for the front-end file viewer. Both can be configured through the plugin’s shortcode composer.

Gutenberg has a Shortcode block for exactly this purpose:

A Gutenberg Shortcode block holding a plugin shortcode

That is the recommended place for them, though they also work inside Custom HTML blocks, Classic blocks and others. The plugin’s shortcodes are fully compatible with Gutenberg however they are added.

So is the shortcode composer: changes made there are reflected in the page or post straight away, which is more than can be said for some page builders.

Custom code

In the classic editor, custom JavaScript went into the HTML view wrapped in <script> tags, with limitations and the occasional problem.

In Gutenberg, JavaScript and CSS both belong in a Custom HTML block — JavaScript in <script> tags, CSS in <style> tags. That block is a far better place to write code, with line numbers, syntax highlighting and auto-completion.

What happens to a classic page

Here is a page, in HTML view, holding an upload form, a file viewer and a piece of custom JavaScript that fills the form’s ID field with a random string:

The classic editor's HTML view showing two shortcodes and a script

In a browser it looks like this — both shortcodes render, and the ID field carries its random string:

The page in a browser, with the upload form, file viewer and populated ID field

Open that page with Gutenberg enabled and its contents appear inside a single Classic block:

The same page opened in Gutenberg, shown inside one Classic block

The shortcodes are where they were. But switch to “Edit as HTML” from the The block options menu icon menu and something has changed:

The HTML view showing br elements inserted inside the script

The shortcodes and the script have been wrapped in paragraph (<p>) tags, which does them no harm. But line breaks (<br />) have been inserted inside the script, which makes it invalid — so it no longer runs.

Pressing “Convert to Blocks” from the same menu makes matters worse:

After conversion: two Shortcode blocks and the script mangled into a Paragraph block

The two shortcodes convert cleanly into Shortcode blocks, but the script becomes a Paragraph block and is mangled. Save the page and this is the result:

The published page with the script's source printed on screen instead of running

The script’s source is printed on the page and does nothing — the ID field is empty.

Migrating the shortcodes

Shortcodes should end up as Shortcode blocks. The quickest way is “Convert to Blocks” from the The block options menu icon menu, which converts them directly. Nothing further is needed.

Alternatively, add Shortcode blocks by hand and paste the shortcode text into them.

Migrating the custom code

Custom script code is the part that needs care. Add a Custom HTML block by hand and paste the code into it:

The script pasted into a Custom HTML block

Before you do, check that the code carries no <br /> elements, because those will break it.

Save the page, open it in a browser, and both the shortcodes and the script work as they did.

For any questions or problems with Iptanus File Upload and Gutenberg, please contact us.

The Iptanus team

Did this solve your problem?

1 discussion

Most recent: August 2018

Questions answered by Iptanus and other users.

  1. Why don’t you ever make videos how to use this Plugin? It is so frustrating that you have NO VIDEOS showing how to do things.

    1. You have a point. I have focused so much on improving the plugin and adding features that I have missed that. I will consider your remarks and will make some ones.

      Nickolas

Ask a question

Answered by Iptanus, usually within a working day.

Ask a question

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top