Making WordPress.org

Changeset 12294


Ignore:
Timestamp:
12/05/2022 02:17:16 AM (4 years ago)
Author:
dd32
Message:

Support Forums: Customise the Blocks Everywhere plugin slightly, and shift enabling the plugin from constants to filters.

Props johnny5 for filters.
See #6608.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-blocks.php

    r12292 r12294  
    33namespace WordPressdotorg\Forums;
    44
     5/**
     6 * Customizations for the Support Forum and the Blocks Everywhere plugin.
     7 *
     8 * To enable this file to be loaded on a bbPress install, activate the Blocks Everywhere plugin.
     9 */
    510class Blocks {
    611        public function __construct() {
    7                 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
     12                // Enable bbPress support.
     13                add_filter( 'blocks_everywhere_bbpress', '__return_true' );
     14
     15                // Enable block processing in emails.
     16                add_filter( 'blocks_everywhere_email', '__return_true' );
     17
     18                // Enable theme compatibility CSS.
     19                add_filter( 'blocks_everywhere_theme_compat', '__return_true' );
     20
     21                // Any Javascript / CSS tweaks needed.
     22                add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
     23
     24                // Theme Tweaks, these should be moved to the theme.
     25                add_filter( 'after_setup_theme', [ $this, 'after_setup_theme' ] );
     26
     27                // Customize blocks for the Support Forums.
     28                add_filter( 'blocks_everywhere_editor_settings', [ $this, 'editor_settings' ] );
    829        }
    930
    1031        public function enqueue_scripts() {
    11                 wp_enqueue_script( 'wporg-bbp-blocks', plugins_url( '/js/blocks.js', __DIR__ ), array( 'wp-block-editor', 'jquery' ), filemtime( dirname( __DIR__ ) . '/js/blocks.js' ), true );
     32                wp_enqueue_script(
     33                        'wporg-bbp-blocks',
     34                        plugins_url( '/js/blocks.js', __DIR__ ),
     35                        [ 'wp-block-editor', 'jquery' ],
     36                        filemtime( dirname( __DIR__ ) . '/js/blocks.js' ),
     37                        true
     38                );
     39        }
     40
     41        public function after_setup_theme() {
     42                // This will make embeds resize properly.
     43                add_theme_support( 'responsive-embeds' );
     44        }
     45
     46        public function editor_settings( $settings ) {
     47                // This adds the image block, but only with 'add from url' as an option.
     48                $settings['iso']['blocks']['allowBlocks'][] = 'core/image';
     49
     50                // Allows embeds and might fix pasting links sometimes not working.
     51                $settings['iso']['blocks']['allowBlocks'][] = 'core/embed';
     52
     53                // Adds a table of contents button in the toolbar.
     54                $settings['toolbar']['toc'] = true;
     55
     56                // Adds a navigation button in the toolbar.
     57                $settings['toolbar']['navigation'] = true;
     58
     59                // This will display a support link in an ellipsis menu in the top right of the editor.
     60                $settings['iso']['moreMenu'] = true;
     61                $settings['iso']['linkMenu'] = [
     62                        [
     63                                /* translators: Link title to the WordPress Editor support article. */
     64                                'title' => __( 'Help & Support', 'wporg' ),
     65                                /* translators: Link to the WordPress Editor article, used as the forum 'Help & Support' destination. */
     66                                'link' => __( 'https://wordpress.org/support/article/wordpress-editor/', 'wporg' ),
     67                        ]
     68                ];
     69
     70                // TODO: To modify the available embeds modify $settings['iso']['allowEmbeds']
     71
     72                return $settings;
    1273        }
    1374}
Note: See TracChangeset for help on using the changeset viewer.