Making WordPress.org

Changeset 12314


Ignore:
Timestamp:
12/12/2022 02:36:41 AM (15 months ago)
Author:
dd32
Message:

Support Forums: Blocks: Add an experimental predefs functionality through the usage of Block Patterns.

Props johnny5.
See #6608.

File:
1 edited

Legend:

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

    r12313 r12314  
    11<?php
    2 
    32namespace WordPressdotorg\Forums;
     3use WP_Block_Patterns_Registry, WP_Block_Pattern_Categories_Registry;
    44
    55/**
     
    3333        // Hack to make Imgur embeds work. This should be fixed by Imgur.
    3434        add_filter( 'oembed_remote_get_args', [ $this, 'oembed_remote_get_args' ], 10, 2 );
     35
     36        // Add block patterns.
     37        add_filter( 'init', [ $this, 'register_predefs' ] );
    3538    }
    3639
     
    7982            ]
    8083        ) );
     84
     85        // Add patterns
     86        $settings['editor']['__experimentalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
     87        $settings['editor']['__experimentalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
    8188
    8289        return $settings;
     
    121128        return $http_args;
    122129    }
     130
     131    /**
     132     * Register pre-defs for the forums.
     133     */
     134    public function register_predefs() {
     135        $registered = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
     136        foreach ( $registered as $pattern ) {
     137            unregister_block_pattern( $pattern['name'] );
     138        }
     139   
     140        $registered = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
     141        foreach ( $registered as $pattern ) {
     142            unregister_block_pattern_category( $pattern['name'] );
     143        }
     144   
     145        register_block_pattern_category( 'predef', [ 'label' => 'Pre-defined Replies' ] );
     146   
     147        register_block_pattern( 'wordpress-org/no-dashboard', [
     148            'title'      => 'Cannot Access Dashboard',
     149            'categories' => [ 'predef' ],
     150            'content'    => '
     151                <!-- wp:paragraph -->
     152                <p>Try <a href="https://wordpress.org/support/article/faq-troubleshooting/#how-to-deactivate-all-plugins-when-not-able-to-access-the-administrative-menus">manually resetting your plugins</a> (no Dashboard access required). If that resolves the issue, reactivate each one individually until you find the cause.</p>
     153                <!-- /wp:paragraph -->
     154   
     155                <!-- wp:paragraph -->
     156                <p>If that does not resolve the issue, access your server via <a href="https://wordpress.org/support/article/ftp-clients/">SFTP or FTP</a>, or a file manager in your hosting account\'s control panel, navigate to <code>/wp-content/themes/</code> and rename the directory of your currently active theme. This will force the default theme to activate and hopefully rule-out a theme-specific issue (theme functions can interfere like plugins).</p>
     157                <!-- /wp:paragraph -->',
     158        ] );
     159   
     160        register_block_pattern( 'wordpress-org/theme-conflict', [
     161            'title'      => 'Error Related to Plugin or Theme Conflict',
     162            'categories' => [ 'predef' ],
     163            'content'    => '
     164                <!-- wp:paragraph -->
     165                <p>This may be a plugin or theme conflict. Please attempt to disable all plugins, and use one of the default (Twenty*) themes. If the problem goes away, enable them one by one to identify the source of your troubles.</p>
     166                <!-- /wp:paragraph -->
     167   
     168                <!-- wp:paragraph -->
     169                <p>If you can install plugins, install and activate "Health Check": <a href="https://wordpress.org/plugins/health-check/">https://wordpress.org/plugins/health-check/</a></p>
     170                <!-- /wp:paragraph -->
     171   
     172                <!-- wp:paragraph -->
     173                <p>It will add some additional features under the menu item under Tools &gt; Site Health.</p>
     174                <!-- /wp:paragraph -->
     175   
     176                <!-- wp:paragraph -->
     177                <p>On its troubleshooting tab, you can Enable Troubleshooting Mode. This will disable all plugins, switch to a standard WordPress theme (if available), allow you to turn your plugins on and off and switch between themes, <strong>without affecting normal visitors to your site</strong>. This allows you to test for various compatibility issues.</p>
     178                <!-- /wp:paragraph -->
     179   
     180                <!-- wp:paragraph -->
     181                <p>There’s a more detailed description about how to use the Health Check plugin and its Troubleshooting Mode at <a href="https://make.wordpress.org/support/handbook/appendix/troubleshooting-using-the-health-check/">https://make.wordpress.org/support/handbook/appendix/troubleshooting-using-the-health-check/</a></p>
     182                <!-- /wp:paragraph -->',
     183        ] );
     184   
     185        register_block_pattern( 'wordpress-org/missing-files', [
     186            'title'      => 'Error Related to Missing or Damaged Core Files',
     187            'categories' => [ 'predef' ],
     188            'content'    => '
     189                <!-- wp:paragraph -->
     190                <p>Try <a href="https://wordpress.org/download/">downloading WordPress</a> again, access your server via <a href="https://wordpress.org/support/article/ftp-clients/">SFTP or FTP</a>, or a file manager in your hosting account\'s control panel, and delete then replace your copies of everything <strong>except</strong> the `wp-config.php` file and the <code>/wp-content/</code> directory with fresh copies from the download. This will effectively replace all of your core files without damaging your content and settings.</p>
     191                <!-- /wp:paragraph -->
     192   
     193                <!-- wp:paragraph -->
     194                <p>Some uploaders tend to be unreliable when overwriting files, so don\'t forget to delete the original files before replacing them.</p>
     195                <!-- /wp:paragraph -->',
     196        ] );
     197   
     198        register_block_pattern( 'wordpress-org/oom', [
     199            'title'      => 'Out of Memory Errors',
     200            'categories' => [ 'predef' ],
     201            'content'    => '
     202                <!-- wp:paragraph -->
     203                <p>If you\'re seeing this error either suddenly (no specific task was done to cause the error) or frequently, try deactivating all plugins to rule-out a plugin-specific issue and try switching themes to rule-out a theme-specific issue.</p>
     204                <!-- /wp:paragraph -->
     205   
     206                <!-- wp:paragraph -->
     207                <p>Otherwise, here are three ways to increase PHP\'s memory allocation:</p>
     208                <!-- /wp:paragraph -->
     209   
     210                <!-- wp:list {"ordered":true} -->
     211                <ol><!-- wp:list-item -->
     212                <li>If you can edit or override the system <code>php.ini</code> file, increase the memory limit. For example, <code>memory_limit = 128M</code></li>
     213                <!-- /wp:list-item -->
     214   
     215                <!-- wp:list-item -->
     216                <li>If you cannot edit or override the system <code>php.ini</code> file, add <code>php_value memory_limit 128M</code> to your <code>.htaccess</code> file.</li>
     217                <!-- /wp:list-item -->
     218   
     219                <!-- wp:list-item -->
     220                <li>If neither of these work, it\'s time to ask your hosting provider to temporarily increase PHP\'s memory allocation on your account.</li>
     221                <!-- /wp:list-item --></ol>
     222                <!-- /wp:list -->
     223   
     224                <!-- wp:paragraph -->
     225                <p>(in the above examples, the limit is set to 128MB)</p>
     226                <!-- /wp:paragraph -->
     227   
     228                <!-- wp:paragraph -->
     229                <p><a href="https://make.wordpress.org/support/handbook/giving-good-support/pre-defined-replies/#error-500-internal-server-error"><strong>Error 500: Internal Server Error</strong></a></p>
     230                <!-- /wp:paragraph -->
     231   
     232                <!-- wp:paragraph -->
     233                <p>Internal server errors (error 500) are often caused by plugin or theme function conflicts, so if you have access to your admin panel, try deactivating all plugins. If you don\'t have access to your admin panel, try <a href="https://wordpress.org/support/article/faq-troubleshooting/#how-to-deactivate-all-plugins-when-not-able-to-access-the-administrative-menus">manually resetting your plugins</a> (no Dashboard access required). If that resolves the issue, reactivate each one individually until you find the cause.</p>
     234                <!-- /wp:paragraph -->
     235   
     236                <!-- wp:paragraph -->
     237                <p>If that does not resolve the issue, try switching to the default theme for your version of WordPress to rule-out a theme-specific issue. If you don\'t have access to your admin panel, access your server via <a href="https://wordpress.org/support/article/ftp-clients/">SFTP or FTP</a>, or a file manager in your hosting account\'s control panel, navigate to <code>/wp-content/themes/</code> and rename the directory of your currently active theme. This will force the default theme to activate and hopefully rule-out a theme-specific issue.</p>
     238                <!-- /wp:paragraph -->
     239   
     240                <!-- wp:paragraph -->
     241                <p>If that does not resolve the issue, it\'s possible that a <code>.htaccess</code> rule could be the source of the problem. To check for this, access your server via SFTP or FTP, or a file manager in your hosting account\'s control panel, and rename the <code>.htaccess</code> file. If you can\'t find a <code>.htaccess</code> file, make sure that you have set your SFTP or FTP client to view invisible files.</p>
     242                <!-- /wp:paragraph -->
     243   
     244                <!-- wp:paragraph -->
     245                <p>If you weren’t able to resolve the issue by either resetting your plugins and theme or renaming your <code>.htaccess</code> file, we may be able to help, but we\'ll need a more detailed error message. Internal server errors are usually described in more detail in the server error log. If you have access to your server error log, generate the error again, note the date and time, then immediately check your server error log for any errors that occurred during that time period. If you don’t have access to your server error log, ask your hosting provider to look for you.</p>
     246                <!-- /wp:paragraph -->',
     247        ] );
     248    }
    123249}
Note: See TracChangeset for help on using the changeset viewer.