Giter Club home page Giter Club logo

blocks-everywhere's Introduction

Blocks Everywhere

110600033-c625d880-8183-11eb-9609-70ab7390c0d9

Switches the default WordPress editor for comments, bbPress, and BuddyPress to use Gutenberg. These can now use a richer set of editing tools, as well as having access to the full power of Gutenberg blocks.

Admin moderation is also upgraded to use Gutenberg, and blocks are processed on the front end.

For extra security the list of available blocks is determined by the allowed tags from WordPress.

Gutenberg is not bundled and instead is side-loaded from WordPress. For better compatibility you should use the plugin version of Gutenberg, which is typically several versions ahead of the one included in WordPress.

The condition of the Gutenberg replacements are:

  • bbPress - good (requires bbPress 2.6+)
  • comments - alright
  • BuddyPress - needs a lot of work

The plugin uses the Isolated Block Editor. This can also be found in:

  • Plain Text Editor - standalone JS file that can replace any textarea on any page with a full Gutenberg editor
  • Gutenberg Chrome Extension - a Chrome extension that allows Gutenberg to be used on any page
  • Gutenberg Desktop - a desktop editor that supports the loading and saving of HTML and Markdown files
  • P2 - WordPress as a collaborative workspace (coming soon for self-hosted)

Blocks Everywhere can be downloaded from WordPress.org:

https://wordpress.org/plugins/blocks-everywhere/

Caveats

Gutenberg is placed directly on the page along with your post, forum, etc. This means the contents of the editor will look like the page they will appear on. However, it also means that styles from the page may affect the editor.

Currently we don't have a perfect way of seperating these styles and it is possible that styles from the page or from Gutenberg may affect the other. If you are using this plugin then it is expected that you will be able to fix any differences as appropriate for your site.

The loading of Gutenberg will also increase the page size of any page it is loaded on. You should be aware of this and willing to accept this in the context of your site.

Usage

To enable Blocks Everywhere you need to add the relevant define to wp-config.php:

define( 'BLOCKS_EVERYWHERE_COMMENTS', true );
define( 'BLOCKS_EVERYWHERE_BBPRESS', true );
define( 'BLOCKS_EVERYWHERE_BUDDYPRESS', true );

You can also use the WordPress filter blocks_everywhere_comments, blocks_everywhere_bbpress, and blocks_everywhere_buddypress.

To enable back-end editing in bbPress:

define( 'BLOCKS_EVERYWHERE_ADMIN', true );

Or use the filter blocks_everywhere_admin. Back-end editing is restricted to users with the manage_options capability (can be changed with the blocks_everywhere_admin_cap filter).

To enable conversion of blocks in email:

define( 'BLOCKS_EVERYWHERE_EMAIL', true );

Or use the filter blocks_everywhere_email.

To enable Gutenberg when editing bbPress forums, topics, and replies you can use:

define( 'BLOCKS_EVERYWHERE_BBPRESS_ADMIN', true );

Or use blocks_everywhere_bbpress_admin

Settings

Some settings are available through the settings object, which is filterable with blocks_everywhere_editor_settings.

allowUrlEmbed - Enable or disable auto-embed for URLs replaceParagraphCode - Enable the custom paragraph that converts HTML and PHP code into a code block pastePlainText - Convert all pasted content to plain text patchEmoji - set to true to stop twemoji from affecting the editor iso.allowEmbeds - List of enabled embeds iso.blocks.allowBlocks - List of enabled blocks iso.className - String of classes to be assigned to the editor. iso.__experimentalOnChange - An optional callback that is triggered when the blocks are changed. iso.__experimentalOnInput - An optional callback that is triggered when text is input. iso.__experimentalOnSelection - An optional callback when a block is selected.

Theme compatibility

Gutenberg is placed directly on the page along with your post, forum, etc. This means the contents of the editor will look like the page they will appear on. However, it also means that styles from the page may affect the editor.

We don't have a perfect way of separating these styles and it is possible that styles from the page or from Gutenberg may affect the other. If you are using this plugin then it is expected that you will be able to fix any differences as appropriate for your site.

A theme compatibility option is provided which might help. You can use this with:

define( 'BLOCKS_EVERYWHERE_THEME_COMPAT', true );

Or using the filter blocks_everywhere_theme_compat.

It provides some overrides for common theme issues. However, it is generally better not to require overrides so if you are able to modify your theme and make CSS more specific then that is the best route.

For example, rather than defining a global button style (which would then affect Gutenberg), make the style specific to the areas where a button will be used.

Using Content Embed block

Content Embed block uses REST API to fetch content to be embedded. This means that site contains bbPress topics to embed should have topic REST API enabled.

Blocks Everywhere enables topic REST API on its own, so if the site with bbPress have this plugin installed and configured, its topics can be embedded.

To enable Content Embed block in the editor, pass these settings to blocks_everywhere_editor_settings filter:

add_filter( 'blocks_everywhere_editor_settings', function( $settings ) {
	$settings['iso']['blocks']['allowBlocks'][] = 'blocks-everywhere/support-content';
	return $settings;
} );

To enable REST API for forum topics, use next filters:

add_filter( 'blocks_everywhere_admin', '__return_true' );
add_filter( 'blocks_everywhere_admin_cap', '__return_empty_string' );

REST API is only used when creating content embed and not used to view it. So blocks_everywhere_admin_cap can return specific capability to limit users who will have access to API.

KSES

Gutenberg outputs HTML content and this may be affected by KSES (WordPress HTML sanitisation), as well as other functions.

The plugin provides some modifications to this so it works fine with basic blocks. You may run into problems if you are using different blocks or have customised permission levels.

Development

This repository can be used directly with WordPress. For example, in your wp-content/plugins directory you can:

git clone [email protected]:Automattic/blocks-everywhere.git

You can then activate the plugin as normal and can follow the 'Building' instructions to build the files.

Sandboxes

If you wish to sync changes with a remote sandbox you add blocks_everywhere to your ~/.npmrc file. The value should point to the remote directory (including host and username). The directory should have a trailing slash.

For example blocks_everywhere=sandbox:public_html/wp-content/plugins/blocks-everywhere/.

Building

The JS and CSS needs to be compiled. You can do this in development mode, which will monitor for updates to the files:

yarn start

You can perform the same function but also upload to a remote sandbox (see sandbox configuration above):

yarn start:sync

If you want to build production files (minified and without debugging) then:

yarn build

And

yarn build:sync

Releasing

A release packages up all the JS, CSS, and PHP files into a clean directory without any development tooling.

yarn release

The plugin will be available in the release directory.

You can sync to a remote sandbox with (see sandbox configuration above):

yarn release:sync

Distribution

To produce a released and versioned distribution of the plugin run:

yarn dist

This will produce a zip file, upload it to Github, and mark it as an official release.

You can sync this to the WordPress.org SVN repo with:

yarn dist:svn

You will need appropriate permissions.

blocks-everywhere's People

Contributors

akirk avatar arcangelini avatar audrasjb avatar bangank36 avatar dd32 avatar georgestephanis avatar johngodley avatar lezama avatar msurdi-a8c avatar vasyas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blocks-everywhere's Issues

Prevent Embedded links from being clickable

I have noticed a small discrepancy between the way the core embed block works and the way one in "blocks everyone" work.

In core, when a wp.org link embedded, the preview is NOT clickable in the editor. It is rare for the person writing the comment to want to click on that link, it has caused me some confusion while testing embeds.

Would it be possible to remove links from embed previews and match the way it works in core?

For reference, this is the URL I tried on my testing:
https://wordpress.org/support/article/wordpress-editor/

Thank you!

Push CSS overrides to the appropriate project

If we need to override a bbPress core style then it will be better to push a change to bbPress to make the CSS selector more specific and less able to interfere with other things.

Include a "Help" link

This "simplified" version of the blocks excludes the ellipsis menu and, hence, there is no link to the documentation on how to use the blocks.

@johngodley, could we include a link somewhere, maybe next to the undo/redo buttons?

Improve BuddyPress support

BuddyPress support is quite limited and not particularly well done. In part this is because BuddyPress does not make it easy to be extended.

For example, we should match the available blocks to what BuddyPress supports.

Investigate bbPress 'show_in_rest'

This modification is needed to enabled Gutenberg editing in wp-admin, but it doesn't seem to work. It may also be something where we only want to modify the API for admins.

Not able to save Gutenberg content on bbpress pages

Description

The plugin is not able to save the getenberg editor content on bbpress pages. On submitting topic description or reply field, It shows an error for an empty field. I tried with post comments where I had no such issue.

Step-by-step reproduction instructions

  • Add block content on forum/topic/reply form.
  • Submit the form.

Expected Behavior

Gutenberg content should be submitted successfully.

Current Behavior

Showing empty content field error on submission.

Screenshots or screen recording

gutenberg-everywhere

Other details

WordPress version: 5.8
bbpress version: 2.6.6
Gutenberg version: 11.1.0
Gutenberg Everywhere version: 1.1.0

Editor CSS should be isolated from the page

The Block editor loads the editor stylesheet into the context of the page, however the Block Editor CSS loaded is not scoped to the editor instance at all.

This causes an issue for sites where blocks are present outside of the editor, such as on WordPress.org Forums where the <header> and <footer> are blocks. In our case, it seems that some specific CSS rules we can add will resolve this, but it's likely that future Gutenberg style updates may break other blocks.

The editor should likely be loaded within an iframe, and communicate with the parent page through postMessage for ideal compatibility (props @StevenDufresne for the suggestion).

Editor pages not loading

The plugin overrides the WordPress the_editor so Gutenberg can load on admin pages. This was working, but something has broken.

For example:

  • Comment admin
  • BuddyPress admin

Better support for long messages

In some forums people will often paste long messages, such as system and error logs. It would be nice if there was better support for this:

  • Don't split into multiple blocks
  • Have some kind of text expander where the majority of text is hidden and expanded out

Plugin is broken in Wordpress 5.9 RC.1

The frontend block editors display an error with the following output:

cFS5/C/<@https://gutenburg.local/wp-includes/js/dist/keyboard-shortcuts.min.js?ver=77c30626bb8cf4f5306643107664a1ae:2:3817
Tj@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:179:399
unstable_runWithPriority@https://gutenburg.local/wp-includes/js/dist/vendor/react.min.js?ver=17.0.1:24:26
Za@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:73:8
Ra@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:178:368
gf@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:161:497
$g/<@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:73:230
unstable_runWithPriority@https://gutenburg.local/wp-includes/js/dist/vendor/react.min.js?ver=17.0.1:24:26
Za@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:73:8
$g@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:73:178
ja@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:73:111
Tj@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:180:72
unstable_runWithPriority@https://gutenburg.local/wp-includes/js/dist/vendor/react.min.js?ver=17.0.1:24:26
Za@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:73:8
Ra@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:178:368
Rj/<@https://gutenburg.local/wp-includes/js/dist/vendor/react-dom.min.js?ver=17.0.1:178:275
R@https://gutenburg.local/wp-includes/js/dist/vendor/react.min.js?ver=17.0.1:16:299
ua.port1.onmessage@https://gutenburg.local/wp-includes/js/dist/vendor/react.min.js?ver=17.0.1:22:361
Screenshot 2022-01-10 at 12-48-47 Activity – a – gutenburg

Imgur Block does not work

This is related to #62 but I thought in merited a separate issue.

I have tested the Imgur block with the two following links but neither seems to work:

https://imgur.com/a/C8Ft9Rz
https://imgur.com/a/j1Vo9Rs

In WordPress.com, the link is automatically added as a regular string and the block gets converted to a paragraph.

Screen.Capture.on.2022-12-05.at.20-02-06.mp4

In WordPress.org, the embed fails and I see the two options to "try again" or "add as link".

Screen.Capture.on.2022-12-05.at.19-51-40.mp4

bbPress: HTML within code tags unescaped

As per https://meta.trac.wordpress.org/ticket/6634 HTML within <code> is improperly unescaped and ultimately stripped.

This is because bbPress expects that code will always be within back ticks ``. It doesn't support code within <code>..</code>.

This might be a case where we can upstream something to bbPress sooner than later however.

I had originally suggested I didn't like the removal of bbp_encode_bad() in preference for simply adding the allowable tags, however, I wasn't aware of the shortcomings of the bbPress filtering within.
The hoops required to avoid the problematic code would likely be worse than just replacing it.. so I guess my stance has changed and I would support the wholesale removal of bbp_encode_bad() in preference for a replacement if it was tested appropriately.

Plugin branding

The plugin needs the usual assortment of branding, including:

  • Updated screenshot
  • Banner
  • Updated readme

Missing search box

When I first add a block by using the right '+', I can add so many blocks by searching like:
QQ20220209-114947
Even YouTube:
QQ20220209-115007
But when I try to add the second block, the search box missing.
QQ20220209-115035
Is it a bug? How could I fix it?

Unable to save comment if a paragraph block starts with "<"

As mentioned in #60, it is not possible to paste HTML or PHP into a paragraph block. Instead.

Additionally, if I manually type HTML and try to save it, this error will show:

Screen Shot on 2022-12-03 at 17:12:56
(On that note, the error message would be much more helpful if it provided context on what failed, why and how to fix it)

It should be possible to save HTML & PHP code in a paragraph block. Ideally the block should convert to a code block automatically as soon as a I either type "<" or paste a string that starts with "<".

Landing page

Would this plugin, as well as Gutenberg Desktop and Isolated Block Editor, benefit from a landing page of some kind?

Pasting text that ends with ">" does not work on paragraph blocks

If I have a piece of HTML or PHP and try to paste it into a paragraph block (the default one), it will just not paste AT ALL. This is problematic because users need to share code in their comments all the time.

We want to either allow HTML & PHP to paste on a paragraph block or, even better, detect that the string starts with <and automatically convert it to a code block.

bbPress email conversions isn't working

Unsure when this stopped working, but ::remove_blocks_from_email() no longer receives content which has <!-- ... --> in it.

As a result, ::remove_blocks_from_email() runs but the final preg_replace() can't match any blocks to replace.

bbPress: Empty block replies bypass bbPress empty reply prevention

Submitting an empty reply (or perhaps, several spaces within a paragraph) will bypass the bbPress "Sorry you can't post an empty reply" check.

This is because the submitted content is not "empty":

<!-- wp:paragraph -->
<p> </p>
<!-- /wp:paragraph -->

This affected the WordPress.org forums, temporarily worked around with https://meta.trac.wordpress.org/changeset/12340 (and https://meta.trac.wordpress.org/changeset/12341 for where it was renamed and applied to topics too)

Make it easier to embed images

Directing users on how to add a screenshot (and/or telling them what external service they can use) you makes life much easier for everyone.

@johngodley, do you know where we can find the list of what image services auto-embed in the block editor?

Aside from providing this information somewhere in the interface, we might want to consider adding an ad-hoc block for some of these services to increase discoverability.

Screen Shot on 2022-12-03 at 20:07:12

Another way to go about this would be to include an image block. If we do not provide hosting, we could disable the "Media Library" and "Upload" options and just leave the "Insert from URL" option.

ezgif com-gif-maker

If I can dream big, I would like to have an image block that will let you paste either an URL to an image or a link to a image hosting service, detect it, and parse it accordingly :)

Could patterns be used for pre-defined replies?

A forum would benefit greatly from a set of pre-defined replies, such as the ones listed here:

https://make.wordpress.org/support/handbook/giving-good-support/pre-defined-replies/
https://make.wordpress.org/support/handbook/contributing-to-the-wordpress-forums/stock-answers/

These could be represented by patterns which would then make them available from the block inserter.

Who could create these and how would they be created? Are they available to everyone or just a group of people (i.e. moderators)?

Add switch to HTML editor

Allow users to switch between the Block editor and source (HTML) editing.

Related: https://meta.trac.wordpress.org/ticket/6608#comment:9

I think there should be an option to fill out a simple form. In my professional opinion, I think Gutenberg still requires a bit too much of a learning process to really get the hang of it as a keyboard user. Screen readers only further complicate this. Since there is also no options menu, there is no keyboard shortcuts list or any helpful guides for new users to WordPress. I am not sure this is the experience we should be giving users who are new to WP wanting to ask their questions.

And: https://meta.trac.wordpress.org/ticket/6608#comment:57

I prefer to write in plain HTML [...] -- please give power users the option to switch between blocks and HTML.

Look into replacing bbp_encode_bad for bbPress

Several attempts have been made to work around the content filters in bbPress. As new problems come in they workarounds get more elaborate. It may make more sense to replace bbp_encode_bad (the main cause of these issues) with a version that accepts and sanitises block content, possibly in a similar way to how WP itself does it for posts.

See #123

Add editor block

The editor block is in a very rough state, and could be added here

bbPress: Emoji saved as images

Although not the worst thing, when Emoji is inserted into a reply in the Block Editor and wp-emoji is loaded on the page, wp-emoji will alter the entered emojis into img.emoji if appropriate.

Upon save, this saves as img.emoji elements rather than as emoji's.

#107 whitelisted the class attribute for emojis, so that they don't end up as large image embeds, but this causes other emoji-replacement atributes to be lost (such as role and alt).

See https://meta.trac.wordpress.org/changeset/12341 for some reversing I've applied on the WordPress.org forums.

Unfortunately, it's not possible to exclude wp-emoji from processing the editor content, without adding .wp-exclude-emoji to every element. See https://core.trac.wordpress.org/ticket/52219 for an upstream change to allow it to respect that element on parent nodes.

bbPress: When editing old posts with Classic Editor Block, full Kitchen Sink is shown

bbPress uses a minimal editor and supports a minimal set of tags, but when an existing post is edited with Blocks Everywhere enabled, the full "Kitchen Sink" TinyMCE editor is loaded.

This provides editing functionality which the user can use, but will be broken upon save.
Including the Media Inserter functionality.

This might be more of an issue with Upstream Gutenberg?
Ideally, the TinyMCE editor would not be loaded, and instead a textarea be present in it's place.

Screen Shot 2022-11-28 at 4 57 52 pm

Security review

A good review of potential security issues with loading Gutenberg on the front end and having it manage user-supplied data.

The editor should also be locked down as much as possible.

Content block assumes API URL

The content block makes request to the REST API to get topic details. However, this assumes the path:

https://${ blog }/wp-json/wp/v2/topic?slug=${ encodeURIComponent( slug ) }

It's possible the path is different. For example, if the site is installed in a subdirectory or doesn't have https enabled.

If we use @wordpress/api-fetch then it already knows the REST API URL.

Feature request / how-to request: Dark mode

Hello 👋 this is a really cool way to package Gutenberg outside of WordPress.

I've been messing around with adding it to my Trilium Notes as a custom note-type:

image

As you may notice from the above screenshot, Gutenberg is rendering in light-mode.

My computer, and app are set to dark-mode, so if it were using CSS preferences, then that would work, but likely be buggy.

If the page that Gutenberg is rendered on, has a light-mode theme, or does not support dark-mode, or is on an OS / browser where the app ignores preferences and allows the user to set independently; I guess this might be a set of use-cases you may also be interested in?

If there is any guidance anyone can offer, my page is sort-of the same as your index.html, apart from rendering Gutenberg to a textarea (present iteration only, I will eventually dispense with the HTML element backing) on-load instead of on button-click / toggle.

One other edit I made is to expose OnChange (preparation for getting rid of the textarea, and integration into Trilium). I Do not believe this should have any effects on Dark-mode support.

prop passed to <IsolatedBlockEditor> component

onChange={ (blocks, _settings, _loader, _options) => saveBlocks( serialize( blocks ), textarea ) }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.