Make WordPress Core

Ticket #14365: 14365.diff

File 14365.diff, 2.1 KB (added by nacin, 14 years ago)

Implements a filter and leverages it in Twenty Eleven.

  • wp-content/themes/twentyeleven/inc/theme-options.php

     
    5555add_action( 'admin_init', 'twentyeleven_theme_options_init' );
    5656
    5757/**
     58 * Change the capability required to save the 'twentyeleven_options' options group.
     59 *
     60 * @see twentyeleven_theme_options_init() First parameter to register_setting() is the name of the options group.
     61 * @see twentyeleven_theme_options_add_page() The edit_theme_options capability is used for viewing the page.
     62 *
     63 * By default, the options groups for all registered settings require the manage_options capability.
     64 * This filter is required to change our theme options page to edit_theme_options instead.
     65 * By default, only administrators have either of these capabilities, but the desire here is
     66 * to allow for finer-grained control for roles and users.
     67 *
     68 * @param string $capability The capability used for the page, which is manage_options by default.
     69 * @return string The capability to actually use.
     70 */
     71function twentyeleven_option_page_capability( $capability ) {
     72        return 'edit_theme_options';
     73}
     74add_filter( 'option_page_capability_twentyeleven_options', 'twentyeleven_option_page_capability' );
     75
     76/**
    5877 * Add our theme options page to the admin menu.
    5978 *
    6079 * This function is attached to the admin_menu action hook.
  • wp-admin/options.php

     
    2424
    2525wp_reset_vars(array('action', 'option_page'));
    2626
     27$capability = 'manage_options';
     28
    2729if ( empty($option_page) ) // This is for back compat and will eventually be removed.
    2830        $option_page = 'options';
     31else
     32        $capability = apply_filters( "option_page_capability_{$option_page}", $capability );
    2933
    30 if ( !current_user_can('manage_options') )
     34if ( !current_user_can( $capability ) )
    3135        wp_die(__('Cheatin’ uh?'));
    3236
    3337// Handle admin email change requests