[wp-trac] [WordPress Trac] #58761: Make the filter option_page_capability_options available when access options.php directly

WordPress Trac noreply at wordpress.org
Fri Nov 22 18:23:24 UTC 2024


#58761: Make the filter option_page_capability_options available when access
options.php directly
--------------------------------+------------------------------
 Reporter:  amibe               |       Owner:  (none)
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:
--------------------------------+------------------------------

Comment (by jhonwhener):

 Replace the original code block with the following:


 {{{#!php

 $capability = 'manage_options';

 /**
  * Ensure $option_page defaults to 'options' if not set.
  * This avoids bypassing the capability filter when wp-admin/options.php
 is accessed directly.
  */
 if ( empty( $option_page ) ) {
     $option_page = 'options';
 }

 /**
  * Filters the capability required when using the Settings API.
  *
  * By default, the options groups for all registered settings require the
 manage_options capability.
  * This filter is required to change the capability required for a certain
 options page.
  *
  * @since 3.2.0
  *
  * @param string $capability The capability used for the page, which is
 manage_options by default.
  */
 $capability = apply_filters( "option_page_capability_{$option_page}",
 $capability );
 }}}

 This approach maintains backward compatibility while addressing the
 identified issue.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58761#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list