Changeset 12332 for sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-blocks.php
- Timestamp:
- 12/15/2022 07:18:38 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-blocks.php
r12331 r12332 11 11 12 12 public $forum_enabled_by_default = false; 13 public $user_enabled_by_default = true;14 13 15 14 public function __construct() { … … 17 16 $this->forum_enabled_by_default = get_option( 'forum_block_editor_enabled' ); 18 17 } 19 if ( null !== get_option( 'user_block_editor_enabled', null ) ) {20 $this->user_enabled_by_default = get_option( 'user_block_editor_enabled' );21 }22 18 23 19 // Enable bbPress support. … … 48 44 add_filter( 'init', [ $this, 'register_predefs' ] ); 49 45 50 // Add user opt- in/out46 // Add user opt-out. 51 47 add_action( 'bbp_user_edit_after', [ $this, 'bbp_user_edit_after' ], 11 ); 52 48 add_action( 'bbp_profile_update', [ $this, 'bbp_profile_update' ], 10, 1 ); … … 153 149 154 150 /** 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. 156 152 */ 157 153 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 168 156 printf( 169 157 '<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> 176 160 </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 ) 182 166 ); 183 167 } … … 187 171 */ 188 172 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 { 195 178 delete_user_option( $user_id, 'block_editor' ); 196 } else { 197 update_user_option( $user_id, 'block_editor', $value, false ); 198 } 199 179 } 200 180 } 201 181 … … 230 210 ); 231 211 } 212 232 213 /** 233 214 * Save the values for ::metabox_forum_optin(). … … 270 251 271 252 // 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'; 276 254 277 255 // Determine if the forum has the editor enabled. 278 256 $forum = bbp_get_forum( bbp_get_forum_id() ); 279 257 $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 ); 281 259 $use_it = ( $enabled_for_user && $enabled_for_forum ); 282 260 … … 305 283 unregister_block_pattern( $pattern['name'] ); 306 284 } 307 285 308 286 $registered = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(); 309 287 foreach ( $registered as $pattern ) { 310 288 unregister_block_pattern_category( $pattern['name'] ); 311 289 } 312 290 313 291 register_block_pattern_category( 'predef', [ 'label' => 'Pre-defined Replies' ] ); 314 292 315 293 register_block_pattern( 'wordpress-org/no-dashboard', [ 316 294 'title' => 'Cannot Access Dashboard', … … 320 298 <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> 321 299 <!-- /wp:paragraph --> 322 300 323 301 <!-- wp:paragraph --> 324 302 <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> 325 303 <!-- /wp:paragraph -->', 326 304 ] ); 327 305 328 306 register_block_pattern( 'wordpress-org/theme-conflict', [ 329 307 'title' => 'Error Related to Plugin or Theme Conflict', … … 333 311 <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> 334 312 <!-- /wp:paragraph --> 335 313 336 314 <!-- wp:paragraph --> 337 315 <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> 338 316 <!-- /wp:paragraph --> 339 317 340 318 <!-- wp:paragraph --> 341 319 <p>It will add some additional features under the menu item under Tools > Site Health.</p> 342 320 <!-- /wp:paragraph --> 343 321 344 322 <!-- wp:paragraph --> 345 323 <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> 346 324 <!-- /wp:paragraph --> 347 325 348 326 <!-- wp:paragraph --> 349 327 <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> 350 328 <!-- /wp:paragraph -->', 351 329 ] ); 352 330 353 331 register_block_pattern( 'wordpress-org/missing-files', [ 354 332 'title' => 'Error Related to Missing or Damaged Core Files', … … 358 336 <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> 359 337 <!-- /wp:paragraph --> 360 338 361 339 <!-- wp:paragraph --> 362 340 <p>Some uploaders tend to be unreliable when overwriting files, so don\'t forget to delete the original files before replacing them.</p> 363 341 <!-- /wp:paragraph -->', 364 342 ] ); 365 343 366 344 register_block_pattern( 'wordpress-org/oom', [ 367 345 'title' => 'Out of Memory Errors', … … 371 349 <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> 372 350 <!-- /wp:paragraph --> 373 351 374 352 <!-- wp:paragraph --> 375 353 <p>Otherwise, here are three ways to increase PHP\'s memory allocation:</p> 376 354 <!-- /wp:paragraph --> 377 355 378 356 <!-- wp:list {"ordered":true} --> 379 357 <ol><!-- wp:list-item --> 380 358 <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> 381 359 <!-- /wp:list-item --> 382 360 383 361 <!-- wp:list-item --> 384 362 <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> 385 363 <!-- /wp:list-item --> 386 364 387 365 <!-- wp:list-item --> 388 366 <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> 389 367 <!-- /wp:list-item --></ol> 390 368 <!-- /wp:list --> 391 369 392 370 <!-- wp:paragraph --> 393 371 <p>(in the above examples, the limit is set to 128MB)</p> 394 372 <!-- /wp:paragraph --> 395 373 396 374 <!-- wp:paragraph --> 397 375 <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> 398 376 <!-- /wp:paragraph --> 399 377 400 378 <!-- wp:paragraph --> 401 379 <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> 402 380 <!-- /wp:paragraph --> 403 381 404 382 <!-- wp:paragraph --> 405 383 <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> 406 384 <!-- /wp:paragraph --> 407 385 408 386 <!-- wp:paragraph --> 409 387 <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> 410 388 <!-- /wp:paragraph --> 411 389 412 390 <!-- wp:paragraph --> 413 391 <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.