• ResolvedPlugin Author Dion Hulse

    (@dd32)


    Meta Developer

    This post contains a super-long code block.

    Lorem ipsum dolor sit amet, consectetur
    adipiscing elit. Duis maximus leo eu risus
    tempus, accumsan tempor mauris volutpat. Maecenas
    vitae nisi nec turpis consequat euismod. Nullam
    fermentum suscipit enim placerat euismod.
    Suspendisse potenti. Integer et ullamcorper
    felis, porttitor iaculis magna. Quisque vel massa
    non tortor volutpat ultricies. Pellentesque
    habitant morbi tristique senectus et netus et
    malesuada fames ac turpis egestas. In eu sapien
    at ligula faucibus ultricies. Curabitur porta
    rutrum magna, eget tristique tortor lacinia ac.
    Pellentesque risus tortor, vestibulum ut bibendum
    quis, volutpat id ante. Ut consectetur vehicula
    lectus, sit amet dictum magna faucibus a.
    
    Nulla vitae eros quis diam mollis condimentum
    quis a tellus. Nunc ante tellus, vehicula sit
    amet libero at, mollis laoreet ipsum. Ut rhoncus
    varius lectus, ac cursus erat. Duis ultricies
    nisl justo, vel commodo lacus dignissim sit amet.
    Proin ultrices quis lorem vitae iaculis. In ut
    dui viverra, pretium arcu vitae, viverra lectus.
    Aliquam consequat non felis et molestie. Proin
    sit amet est luctus, pellentesque diam sit amet,
    congue nunc. Donec non arcu ultrices, interdum
    arcu id, condimentum erat. Integer ex mauris,
    consequat fermentum interdum sit amet, interdum
    et libero. Orci varius natoque penatibus et
    magnis dis parturient montes, nascetur ridiculus
    mus. Sed congue felis quam. Ut a mi malesuada,
    tempus eros quis, bibendum sapien. Nam feugiat,
    lectus quis venenatis maximus, nisi augue
    sollicitudin libero, sit amet cursus ex orci a
    dolor. Pellentesque congue libero urna, et
    maximus nisi fermentum eu.
    
    Etiam vel odio porta urna consequat vehicula.
    Quisque vestibulum sit amet ex in rutrum.
    Vestibulum feugiat dui felis, vel mollis felis
    scelerisque maximus. Cras ultricies accumsan
    lorem, vel volutpat ipsum fermentum ut. Aliquam
    non sapien ut sapien aliquam placerat. Maecenas
    vehicula quis nisl sit amet pharetra. Fusce
    venenatis dictum dui in aliquam. Donec nec
    molestie lectus, ut varius justo. Duis gravida,
    diam sit amet accumsan maximus, erat nunc
    volutpat turpis, id facilisis erat nisi vel diam.
    Mauris vitae mi mollis, efficitur ante a,
    efficitur magna. Sed non lacus pulvinar,
    condimentum odio quis, auctor risus. Nulla eu
    vehicula augue. Mauris scelerisque tortor id
    tellus fermentum, non placerat urna sodales.
    Donec convallis dolor ligula, eget efficitur nunc
    gravida et.
    
    Nam eu ex id arcu placerat volutpat non sed dui.
    Ut at nisl sed ante facilisis feugiat. Cras
    vehicula arcu id diam suscipit, ut accumsan lorem
    dapibus. Aliquam condimentum, enim non suscipit
    pellentesque, dolor ex euismod elit, non volutpat
    purus nunc quis ante. Sed augue tortor, facilisis
    vel metus id, ullamcorper vulputate enim. Nunc ac
    pellentesque leo, rhoncus finibus arcu. Curabitur
    maximus mi lectus, in varius metus venenatis
    vitae.
    
    Suspendisse vitae eros consequat, hendrerit nunc
    ac, volutpat libero. Quisque rutrum at ex a
    laoreet. Nam sit amet efficitur mauris. In
    malesuada tortor in metus eleifend ullamcorper.
    Phasellus turpis turpis, euismod tempus tristique
    sed, maximus a ante. Donec eu rutrum ex. Maecenas
    accumsan pretium diam in feugiat. Donec cursus
    nunc ut justo finibus, non posuere risus
    tincidunt. Proin nibh nisl, scelerisque sed
    fermentum gravida, euismod quis leo. Sed metus
    sem, vestibulum non convallis sed, bibendum ac
    leo. Mauris sit amet sapien at nisl consectetur
    dignissim. Cras semper massa quis lorem
    tincidunt, rutrum varius lorem maximus.
    Suspendisse lectus ex, semper id venenatis in,
    ullamcorper vehicula nibh.

    Ooops!

    • This topic was modified 4 years, 8 months ago by Dion Hulse.
    • This topic was modified 4 years, 8 months ago by Dion Hulse.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Dion Hulse

    (@dd32)

    Meta Developer

    Oh, and a short one:

    Lorem ipsum dolor sit amet, consectetur
    adipiscing elit. Duis maximus leo eu risus
    tempus, accumsan tempor mauris volutpat. Maecenas
    vitae nisi nec turpis consequat euismod. Nullam
    fermentum suscipit enim placerat euismod.
    Suspendisse potenti. Integer et ullamcorper
    felis, porttitor iaculis magna. Quisque vel massa
    non tortor volutpat ultricies.
    
    • This reply was modified 4 years, 8 months ago by Dion Hulse.
    Plugin Author Dion Hulse

    (@dd32)

    Meta Developer

    Slack
    style
    code.
         Woo.
    Trac
    style
    code.
         Woo.
    bbPress
    style
    code.
         Woo.

    Slack Inline

    Trac Inline

    bbPress style

    Okay.

    • This reply was modified 4 years, 8 months ago by Dion Hulse.
    • This reply was modified 4 years, 8 months ago by Dion Hulse.
    • This reply was modified 4 years, 8 months ago by Dion Hulse.
    • This reply was modified 4 years, 8 months ago by Dion Hulse.
    • This reply was modified 4 years, 8 months ago by Dion Hulse.
    Moderator Stephen Edgar

    (@netweb)

    Nice, thanks @dd32 ??

    Hello, I think this is fixed?

    Plugin Author Dion Hulse

    (@dd32)

    Meta Developer

    <?php
    namespace WordPressdotorg\Forums;
    use WP_Block_Patterns_Registry, WP_Block_Pattern_Categories_Registry;
    
    /**
     * Customizations for the Support Forum and the Blocks Everywhere plugin.
     *
     * To enable this file to be loaded on a bbPress install, activate the Blocks Everywhere plugin.
     */
    class Blocks {
    
    	public $forum_enabled_by_default = false;
    
    	public function __construct() {
    		if ( null !== get_option( 'forum_block_editor_enabled', null ) ) {
    			$this->forum_enabled_by_default = get_option( 'forum_block_editor_enabled' );
    		}
    
    		// Enable bbPress support.
    		add_filter( 'blocks_everywhere_bbpress', '__return_true' );
    
    		// Enable block processing in emails.
    		add_filter( 'blocks_everywhere_email', '__return_true' );
    
    		// Enable theme compatibility CSS.
    		add_filter( 'blocks_everywhere_theme_compat', '__return_true' );
    
    		// Theme Tweaks, these should be moved to the theme.
    		add_filter( 'after_setup_theme', [ $this, 'after_setup_theme' ] );
    
    		// Customize blocks for the Support Forums.
    		add_filter( 'blocks_everywhere_editor_settings', [ $this, 'editor_settings' ] );
    
    		// Enable the blocks on the server-side.
    		add_filter( 'blocks_everywhere_allowed_blocks', [ $this, 'allowed_blocks' ] );
    
    		// Allow the oEmbed proxy endpoint for any user who can publish a thread/reply..
    		add_filter( 'rest_api_init', [ $this, 'overwrite_oembed_10_proxy_permission' ], 20 );
    
    		// Hack to make Imgur embeds work. This should be fixed by Imgur.
    		add_filter( 'oembed_remote_get_args', [ $this, 'oembed_remote_get_args' ], 10, 2 );
    
    		// Add block patterns.
    		add_filter( 'init', [ $this, 'register_predefs' ] );
    
    		// Add user opt-out.
    		add_action( 'bbp_user_edit_after', [ $this, 'bbp_user_edit_after' ], 11 );
    		add_action( 'bbp_profile_update', [ $this, 'bbp_profile_update' ], 10, 1 );
    		add_filter( 'blocks_everywhere_bbpress_editor', [ $this, 'blocks_everywhere_bbpress_editor' ] );
    
    		// Add forum opt-in/out.
    		add_action( 'admin_init', [ $this, 'admin_init' ] );
    		add_action( 'save_post', [ $this, 'metabox_forum_optin_save_handler' ] );
    
    		// Reverse twemoji replacements. Before bbPress sanitization gets to it.
    		add_filter( 'bbp_new_reply_pre_content', [ $this, 'reverse_twemoji_upon_save' ], 5 );
    		add_filter( 'bbp_new_topic_pre_content', [ $this, 'reverse_twemoji_upon_save' ], 5 );
    	}
    
    	public function after_setup_theme() {
    		// This will make embeds resize properly.
    		add_theme_support( 'responsive-embeds' );
    	}
    
    	public function allowed_blocks( $blocks ) {
    		// See ::editor_settings();
    		$blocks[] = 'core/image';
    		$blocks[] = 'core/embed';
    
    		return array_unique( $blocks );
    	}
    
    	public function editor_settings( $settings ) {
    		// This adds the image block, but only with 'add from url' as an option.
    		$settings['iso']['blocks']['allowBlocks'][] = 'core/image';
    
    		// Allows embeds and might fix pasting links sometimes not working.
    		$settings['iso']['blocks']['allowBlocks'][] = 'core/embed';
    
    		// Adds a table of contents button in the toolbar.
    		$settings['toolbar']['toc'] = true;
    
    		// Adds a navigation button in the toolbar.
    		$settings['toolbar']['navigation'] = true;
    
    		// This will display a support link in an ellipsis menu in the top right of the editor.
    		$settings['iso']['moreMenu'] = true;
    		$settings['iso']['linkMenu'] = [
    			[
    				/* translators: Link title to the WordPress Editor support article. */
    				'title' => __( 'Help & Support', 'wporg-forums' ),
    				/* translators: Link to the WordPress Editor article, used as the forum 'Help & Support' destination. */
    				'url'   => __( 'https://www.ads-software.com/support/article/wordpress-editor/', 'wporg-forums' ),
    			]
    		];
    
    		$settings['iso']['allowEmbeds'] = array_values( array_diff(
    			$settings['iso']['allowEmbeds'],
    			[
    				// Disable screencast, it seems not to work.
    				'screencast',
    			]
    		) );
    
    		// Add patterns.
    		$settings['editor']['__experimentalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
    		$settings['editor']['__experimentalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
    
    		// Enable the custom paragraph that converts HTML and PHP code into a code block.
    		$settings['replaceParagraphCode'] = true;
    
    		return $settings;
    	}
    
    	public function overwrite_oembed_10_proxy_permission() {
    		// A register_route_args filter would be handy here... See https://core.trac.www.ads-software.com/ticket/54087
    		$oembed_proxy_route_args = rest_get_server()->get_routes( 'oembed/1.0' )['/oembed/1.0/proxy'] ?? false;
    		if ( ! $oembed_proxy_route_args ) {
    			return;
    		}
    
    		// Flip it from [ GET => true ] to [ GET ]
    		$oembed_proxy_route_args[0]['methods'] = array_keys( $oembed_proxy_route_args[0]['methods'] );
    
    		// Overwrite the permission_callback, allow any user who can create replies to use embeds.
    		$oembed_proxy_route_args[0]['permission_callback'] = function() {
    			return bbp_current_user_can_publish_topics() || bbp_current_user_can_publish_replies();
    		};
    
    		register_rest_route(
    			'oembed/1.0',
    			'/proxy',
    			$oembed_proxy_route_args,
    			true
    		);
    	}

    This is a bunch of code from the Blocks Plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Long Code Post’ is closed to new replies.