Skip to:
Content

bbPress.org

Changeset 4281


Ignore:
Timestamp:
10/30/2012 11:43:17 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Code Improvement:

  • More politely cast arrays in settings sections and fields.
  • Use esc_html() on some admin strings. See #1999.
  • Clean up bbp_converter_setting_callback_platform().
Location:
trunk/includes/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/admin/admin.php

    r4261 r4281  
    304304
    305305        // Bail if no sections available
    306         if ( ! $sections = bbp_admin_get_settings_sections() )
     306        $sections = bbp_admin_get_settings_sections();
     307        if ( empty( $sections ) )
    307308            return false;
    308309
    309310        // Loop through sections
    310         foreach ( $sections as $section_id => $section ) {
     311        foreach ( (array) $sections as $section_id => $section ) {
    311312
    312313            // Only proceed if current user can see this section
     
    315316
    316317            // Only add section and fields if section has fields
    317             if ( $fields = bbp_admin_get_settings_fields_for_section( $section_id ) ) {
    318 
    319                 // Add the section
    320                 add_settings_section( $section_id, $section['title'], $section['callback'], $section['page'] );
    321 
    322                 // Loop through fields for this section
    323                 foreach ( $fields as $field_id => $field ) {
    324 
    325                     // Add the field
    326                     add_settings_field( $field_id, $field['title'], $field['callback'], $section['page'], $section_id, $field['args'] );
    327 
    328                     // Register the setting
    329                     register_setting( $section['page'], $field_id, $field['sanitize_callback'] );
    330                 }
     318            $fields = bbp_admin_get_settings_fields_for_section( $section_id );
     319            if ( empty( $fields ) )
     320                continue;
     321
     322            // Add the section
     323            add_settings_section( $section_id, $section['title'], $section['callback'], $section['page'] );
     324
     325            // Loop through fields for this section
     326            foreach ( (array) $fields as $field_id => $field ) {
     327
     328                // Add the field
     329                add_settings_field( $field_id, $field['title'], $field['callback'], $section['page'], $section_id, $field['args'] );
     330
     331                // Register the setting
     332                register_setting( $section['page'], $field_id, $field['sanitize_callback'] );
    331333            }
    332334        }
     
    458460        // Add a few links to the existing links array
    459461        return array_merge( $links, array(
    460             'settings' => '<a href="' . add_query_arg( array( 'page' => 'bbpress'   ), admin_url( 'options-general.php' ) ) . '">' . __( 'Settings', 'bbpress' ) . '</a>',
    461             'about'    => '<a href="' . add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php'           ) ) . '">' . __( 'About',    'bbpress' ) . '</a>'
     462            'settings' => '<a href="' . add_query_arg( array( 'page' => 'bbpress'   ), admin_url( 'options-general.php' ) ) . '">' . esc_html__( 'Settings', 'bbpress' ) . '</a>',
     463            'about'    => '<a href="' . add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php'           ) ) . '">' . esc_html__( 'About',    'bbpress' ) . '</a>'
    462464        ) );
    463465    }
     
    12121214     */
    12131215    public function register_admin_style () {
    1214         wp_admin_css_color( 'bbpress', __( 'Green', 'bbpress' ), $this->styles_url . 'admin.css', array( '#222222', '#006600', '#deece1', '#6eb469' ) );
     1216        wp_admin_css_color( 'bbpress', esc_html_x( 'Green', 'admin color scheme', 'bbpress' ), $this->styles_url . 'admin.css', array( '#222222', '#006600', '#deece1', '#6eb469' ) );
    12151217    }
    12161218
  • trunk/includes/admin/settings.php

    r4279 r4281  
    2020 */
    2121function bbp_admin_get_settings_sections() {
    22     return apply_filters( 'bbp_admin_get_settings_sections', array(
     22    return (array) apply_filters( 'bbp_admin_get_settings_sections', array(
    2323        'bbp_settings_main' => array(
    2424            'title'    => __( 'Main Settings', 'bbpress' ),
     
    7171 */
    7272function bbp_admin_get_settings_fields() {
    73     return apply_filters( 'bbp_admin_get_settings_fields', array(
     73    return (array) apply_filters( 'bbp_admin_get_settings_fields', array(
    7474
    7575        /** Main Section ******************************************************/
     
    347347    $retval = isset( $fields[$section_id] ) ? $fields[$section_id] : false;
    348348
    349     return apply_filters( 'bbp_admin_get_settings_fields_for_section', $retval, $section_id );
     349    return (array) apply_filters( 'bbp_admin_get_settings_fields_for_section', $retval, $section_id );
    350350}
    351351
     
    10081008
    10091009    $platform_options = array();
    1010 
    1011     if ( $curdir = opendir( bbpress()->admin->admin_dir . 'converters/' ) ) {
    1012         while ( $file = readdir( $curdir ) ) {
    1013             if ( ( stristr( $file, '.php' ) ) && ( stristr( $file, 'index' ) === false ) ) {
    1014                 $file = preg_replace( '/.php/', '', $file );
    1015                 $platform_options .= '<option value="' . $file . '">' . $file . '</option>';
    1016             }
     1010    $curdir           = opendir( bbpress()->admin->admin_dir . 'converters/' );
     1011
     1012    // Bail if no directory was found (how did this happen?)
     1013    if ( empty( $curdir ) )
     1014        return;
     1015
     1016    // Loop through files in the converters folder and assemble some options
     1017    while ( $file = readdir( $curdir ) ) {
     1018        if ( ( stristr( $file, '.php' ) ) && ( stristr( $file, 'index' ) === false ) ) {
     1019            $file              = preg_replace( '/.php/', '', $file );
     1020            $platform_options .= '<option value="' . $file . '">' . $file . '</option>';
    10171021        }
    1018         closedir( $curdir );
    1019     } ?>
     1022    }
     1023
     1024    closedir( $curdir ); ?>
    10201025
    10211026    <select name="_bbp_converter_platform" id="_bbp_converter_platform" /><?php echo $platform_options ?></select>
     
    13381343
    13391344        // Slug?
    1340         if ( true === $slug )
     1345        if ( true === $slug ) {
    13411346            $value = esc_attr( apply_filters( 'editable_slug', $value ) );
    13421347
    13431348        // Not a slug
    1344         else
     1349        } else {
    13451350            $value = esc_attr( $value );
     1351        }
    13461352
    13471353        // Fallback to default
Note: See TracChangeset for help on using the changeset viewer.