Making WordPress.org


Ignore:
Timestamp:
12/15/2022 07:18:38 AM (2 years ago)
Author:
dd32
Message:

Support Forums: Blocks: Allow for a user to opt-out of using the Block Editor on the support forums.

The opt-out option is present on the individual Support Profiles.

See #6608.

File:
1 edited

Legend:

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

    r12331 r12332  
    1111
    1212    public $forum_enabled_by_default = false;
    13     public $user_enabled_by_default  = true;
    1413
    1514    public function __construct() {
     
    1716            $this->forum_enabled_by_default = get_option( 'forum_block_editor_enabled' );
    1817        }
    19         if ( null !== get_option( 'user_block_editor_enabled', null ) ) {
    20             $this->user_enabled_by_default = get_option( 'user_block_editor_enabled' );
    21         }
    2218
    2319        // Enable bbPress support.
     
    4844        add_filter( 'init', [ $this, 'register_predefs' ] );
    4945
    50         // Add user opt-in/out
     46        // Add user opt-out.
    5147        add_action( 'bbp_user_edit_after', [ $this, 'bbp_user_edit_after' ], 11 );
    5248        add_action( 'bbp_profile_update', [ $this, 'bbp_profile_update' ], 10, 1 );
     
    153149
    154150    /**
    155      * Add an option to the user profile to enable/disable it.
     151     * Add an option to the user profile to disable the block editor.
    156152     */
    157153    public function bbp_user_edit_after() {
    158         $user_id     = bbp_get_displayed_user_id();
    159         $user_status = get_user_option( 'block_editor', $user_id ) ?: 'default';
    160         $default     = $this->user_enabled_by_default ? 'enabled' : 'disabled';
    161 
    162         // TODO: Enable for all users
    163         if ( ! current_user_can( 'moderate' ) && 'default' === $user_status ) {
    164             return;
    165         }
    166 
    167         // TODO: Checkbox at public launch. A checkbox doesn't make sense until it's enabled-by-default.
     154        $user_id = bbp_get_displayed_user_id();
     155
    168156        printf(
    169157            '<p>
    170                 <select name="block_editor" id="block_editor">
    171                     <option value="default" %s>Default (%s)</option>
    172                     <option value="enabled" %s>Enabled (yes)</option>
    173                     <option value="disabled" %s>Disabled (no)</option>
    174                 </select>
    175                 <label for="disable_block_editor">%s</label>
     158                <input name="block_editor" id="block_editor" type="checkbox" value="disabled" %s />
     159                <label for="block_editor">%s</label>
    176160            </p>',
    177             selected( $user_status, 'default', false ),
    178             esc_html( $default ),
    179             selected( $user_status, 'enabled', false ),
    180             selected( $user_status, 'disabled', false ),
    181             'Use the Block Editor for new topics and replies.',
     161            checked( get_user_option( 'block_editor', $user_id ), 'disabled', false ),
     162            sprintf(
     163                __( 'Disable the <a href="%s">Block Editor</a> for new topics and replies.', 'wporg-forums' ),
     164                'https://wordpress.org/support/article/wordpress-editor/'
     165            )
    182166        );
    183167    }
     
    187171     */
    188172    public function bbp_profile_update( $user_id ) {
    189         if ( empty( $_REQUEST['block_editor'] ) ) {
    190             return;
    191         }
    192 
    193         $value = sanitize_key( wp_unslash( $_REQUEST['block_editor'] ) );
    194         if ( 'default' === $value ) {
     173        $disabled = ! empty( $_REQUEST['block_editor'] ) && 'disabled' === $_REQUEST['block_editor'];
     174
     175        if ( $disabled ) {
     176            update_user_option( $user_id, 'block_editor', 'disabled', false );
     177        } else {
    195178            delete_user_option( $user_id, 'block_editor' );
    196         } else {
    197             update_user_option( $user_id, 'block_editor', $value, false );
    198         }
    199 
     179        }
    200180    }
    201181
     
    230210        );
    231211    }
     212
    232213    /**
    233214     * Save the values for ::metabox_forum_optin().
     
    270251
    271252        // Respect the user option.
    272         $user_option = get_user_option( 'block_editor', $user_id );
    273         if ( ! $user_option ) {
    274             $user_option = $this->user_enabled_by_default ? 'enabled' : 'disabled';
    275         }
     253        $user_option = get_user_option( 'block_editor', $user_id ) ?: 'enabled';
    276254
    277255        // Determine if the forum has the editor enabled.
    278256        $forum             = bbp_get_forum( bbp_get_forum_id() );
    279257        $enabled_for_forum = $forum ? ( 'enabled' === $forum->block_editor || ( ! $forum->block_editor && $this->forum_enabled_by_default ) ) : true;
    280         $enabled_for_user  = ( 'disabled' !== $user_option );
     258        $enabled_for_user  = ( 'enabled' === $user_option );
    281259        $use_it            = ( $enabled_for_user && $enabled_for_forum );
    282260
     
    305283            unregister_block_pattern( $pattern['name'] );
    306284        }
    307    
     285
    308286        $registered = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
    309287        foreach ( $registered as $pattern ) {
    310288            unregister_block_pattern_category( $pattern['name'] );
    311289        }
    312    
     290
    313291        register_block_pattern_category( 'predef', [ 'label' => 'Pre-defined Replies' ] );
    314    
     292
    315293        register_block_pattern( 'wordpress-org/no-dashboard', [
    316294            'title'      => 'Cannot Access Dashboard',
     
    320298                <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>
    321299                <!-- /wp:paragraph -->
    322    
     300
    323301                <!-- wp:paragraph -->
    324302                <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>
    325303                <!-- /wp:paragraph -->',
    326304        ] );
    327    
     305
    328306        register_block_pattern( 'wordpress-org/theme-conflict', [
    329307            'title'      => 'Error Related to Plugin or Theme Conflict',
     
    333311                <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>
    334312                <!-- /wp:paragraph -->
    335    
     313
    336314                <!-- wp:paragraph -->
    337315                <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>
    338316                <!-- /wp:paragraph -->
    339    
     317
    340318                <!-- wp:paragraph -->
    341319                <p>It will add some additional features under the menu item under Tools &gt; Site Health.</p>
    342320                <!-- /wp:paragraph -->
    343    
     321
    344322                <!-- wp:paragraph -->
    345323                <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>
    346324                <!-- /wp:paragraph -->
    347    
     325
    348326                <!-- wp:paragraph -->
    349327                <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>
    350328                <!-- /wp:paragraph -->',
    351329        ] );
    352    
     330
    353331        register_block_pattern( 'wordpress-org/missing-files', [
    354332            'title'      => 'Error Related to Missing or Damaged Core Files',
     
    358336                <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>
    359337                <!-- /wp:paragraph -->
    360    
     338
    361339                <!-- wp:paragraph -->
    362340                <p>Some uploaders tend to be unreliable when overwriting files, so don\'t forget to delete the original files before replacing them.</p>
    363341                <!-- /wp:paragraph -->',
    364342        ] );
    365    
     343
    366344        register_block_pattern( 'wordpress-org/oom', [
    367345            'title'      => 'Out of Memory Errors',
     
    371349                <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>
    372350                <!-- /wp:paragraph -->
    373    
     351
    374352                <!-- wp:paragraph -->
    375353                <p>Otherwise, here are three ways to increase PHP\'s memory allocation:</p>
    376354                <!-- /wp:paragraph -->
    377    
     355
    378356                <!-- wp:list {"ordered":true} -->
    379357                <ol><!-- wp:list-item -->
    380358                <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>
    381359                <!-- /wp:list-item -->
    382    
     360
    383361                <!-- wp:list-item -->
    384362                <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>
    385363                <!-- /wp:list-item -->
    386    
     364
    387365                <!-- wp:list-item -->
    388366                <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>
    389367                <!-- /wp:list-item --></ol>
    390368                <!-- /wp:list -->
    391    
     369
    392370                <!-- wp:paragraph -->
    393371                <p>(in the above examples, the limit is set to 128MB)</p>
    394372                <!-- /wp:paragraph -->
    395    
     373
    396374                <!-- wp:paragraph -->
    397375                <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>
    398376                <!-- /wp:paragraph -->
    399    
     377
    400378                <!-- wp:paragraph -->
    401379                <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>
    402380                <!-- /wp:paragraph -->
    403    
     381
    404382                <!-- wp:paragraph -->
    405383                <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>
    406384                <!-- /wp:paragraph -->
    407    
     385
    408386                <!-- wp:paragraph -->
    409387                <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>
    410388                <!-- /wp:paragraph -->
    411    
     389
    412390                <!-- wp:paragraph -->
    413391                <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>
Note: See TracChangeset for help on using the changeset viewer.