Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/24/2012 09:10:16 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Add sanity checks to bp_core_admin_slugs_options() and allow static pages to be filtered.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-slugs.php

    r5729 r5944  
    6161    $directory_pages = array();
    6262
    63     foreach( $bp->loaded_components as $component_slug => $component_id ) {
    64 
    65         // Only components that need directories should be listed here
    66         if ( isset( $bp->{$component_id} ) && !empty( $bp->{$component_id}->has_directory ) ) {
    67 
    68             // component->name was introduced in BP 1.5, so we must provide a fallback
    69             $component_name = !empty( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $component_id );
    70 
    71             $directory_pages[$component_id] = $component_name;
     63    // Loop through loaded components and collect directories
     64    if ( is_array( $bp->loaded_components ) ) {
     65        foreach( $bp->loaded_components as $component_slug => $component_id ) {
     66
     67            // Only components that need directories should be listed here
     68            if ( isset( $bp->{$component_id} ) && !empty( $bp->{$component_id}->has_directory ) ) {
     69
     70                // component->name was introduced in BP 1.5, so we must provide a fallback
     71                $directory_pages[$component_id] = !empty( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $component_id );
     72            }
    7273        }
    7374    }
    7475
     76    /** Directory Display *****************************************************/
     77
    7578    $directory_pages = apply_filters( 'bp_directory_pages', $directory_pages );
    7679
    77     ?>
    78 
    79     <h3><?php _e( 'Directories', 'buddypress' ); ?></h3>
    80 
    81     <p><?php _e( 'Associate a WordPress Page with each BuddyPress component directory.', 'buddypress' ); ?></p>
    82 
    83     <table class="form-table">
    84         <tbody>
    85 
    86             <?php foreach ( $directory_pages as $name => $label ) : ?>
    87                 <?php $disabled = !bp_is_active( $name ) ? ' disabled="disabled"' : ''; ?>
    88 
    89                 <tr valign="top">
    90                     <th scope="row">
    91                         <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
    92                     </th>
    93 
    94                     <td>
    95                         <?php if ( !bp_is_root_blog() )
    96                             switch_to_blog( bp_get_root_blog_id() ) ?>
    97 
    98                         <?php echo wp_dropdown_pages( array(
    99                             'name'             => 'bp_pages[' . esc_attr( $name ) . ']',
    100                             'echo'             => false,
    101                             'show_option_none' => __( '- None -', 'buddypress' ),
    102                             'selected'         => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
    103                         ) ); ?>
    104 
    105                         <a href="<?php echo admin_url( add_query_arg( array( 'post_type' => 'page' ), 'post-new.php' ) ); ?>" class="button-secondary"><?php _e( 'New Page' ); ?></a>
    106                         <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e( 'Save', 'buddypress' ) ?>" />
    107 
    108                         <?php if ( !empty( $existing_pages[$name] ) ) : ?>
    109 
    110                             <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View' ); ?></a>
    111 
    112                         <?php endif; ?>
    113 
    114                         <?php if ( !bp_is_root_blog() )
    115                             restore_current_blog() ?>
    116 
    117                     </td>
    118                 </tr>
    119 
    120 
    121             <?php endforeach ?>
    122 
    123             <?php do_action( 'bp_active_external_directories' ); ?>
    124 
    125         </tbody>
    126     </table>
     80    if ( !empty( $directory_pages ) ) : ?>
     81
     82        <h3><?php _e( 'Directories', 'buddypress' ); ?></h3>
     83
     84        <p><?php _e( 'Associate a WordPress Page with each BuddyPress component directory.', 'buddypress' ); ?></p>
     85
     86        <table class="form-table">
     87            <tbody>
     88
     89                <?php foreach ( $directory_pages as $name => $label ) : ?>
     90
     91                    <tr valign="top">
     92                        <th scope="row">
     93                            <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
     94                        </th>
     95
     96                        <td>
     97                            <?php if ( !bp_is_root_blog() )
     98                                switch_to_blog( bp_get_root_blog_id() ) ?>
     99
     100                            <?php echo wp_dropdown_pages( array(
     101                                'name'             => 'bp_pages[' . esc_attr( $name ) . ']',
     102                                'echo'             => false,
     103                                'show_option_none' => __( '- None -', 'buddypress' ),
     104                                'selected'         => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
     105                            ) ); ?>
     106
     107                            <a href="<?php echo admin_url( add_query_arg( array( 'post_type' => 'page' ), 'post-new.php' ) ); ?>" class="button-secondary"><?php _e( 'New Page' ); ?></a>
     108                            <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e( 'Save', 'buddypress' ) ?>" />
     109
     110                            <?php if ( !empty( $existing_pages[$name] ) ) : ?>
     111
     112                                <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View' ); ?></a>
     113
     114                            <?php endif; ?>
     115
     116                            <?php if ( !bp_is_root_blog() )
     117                                restore_current_blog() ?>
     118
     119                        </td>
     120                    </tr>
     121
     122
     123                <?php endforeach ?>
     124
     125                <?php do_action( 'bp_active_external_directories' ); ?>
     126
     127            </tbody>
     128        </table>
    127129
    128130    <?php
     131
     132    endif;
     133
     134    /** Static Display ********************************************************/
    129135
    130136    // Static pages
     
    132138        'register' => __( 'Register', 'buddypress' ),
    133139        'activate' => __( 'Activate', 'buddypress' ),
    134     ); ?>
    135 
    136     <h3><?php _e( 'Registration', 'buddypress' ); ?></h3>
    137 
    138     <p><?php _e( 'Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress' ); ?></p>
    139 
    140     <table class="form-table">
    141         <tbody>
    142 
    143             <?php foreach ( $static_pages as $name => $label ) : ?>
    144 
    145                 <tr valign="top">
    146                     <th scope="row">
    147                         <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
    148                     </th>
    149 
    150                     <td>
    151                         <?php echo wp_dropdown_pages( array(
    152                             'name'             => 'bp_pages[' . esc_attr( $name ) . ']',
    153                             'echo'             => false,
    154                             'show_option_none' => __( '- None -', 'buddypress' ),
    155                             'selected'         => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
    156                         ) ) ?>
    157 
    158                         <a href="<?php echo admin_url( add_query_arg( array( 'post_type' => 'page' ), 'post-new.php' ) ); ?>" class="button-secondary"><?php _e( 'New Page' ); ?></a>
    159                         <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e( 'Save', 'buddypress' ) ?>" />
    160 
    161                         <?php if ( !empty( $existing_pages[$name] ) ) : ?>
    162 
    163                             <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View' ); ?></a>
    164 
    165                         <?php endif; ?>
    166 
    167                     </td>
    168                 </tr>
    169 
    170             <?php endforeach ?>
    171 
    172             <?php do_action( 'bp_active_external_pages' ); ?>
    173 
    174         </tbody>
    175     </table>
    176 
    177     <?php
     140    );
     141   
     142    $static_pages = apply_filters( 'bp_static_pages', $static_pages );
     143   
     144    if ( !empty( $static_pages ) ) : ?>
     145
     146        <h3><?php _e( 'Registration', 'buddypress' ); ?></h3>
     147
     148        <p><?php _e( 'Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress' ); ?></p>
     149
     150        <table class="form-table">
     151            <tbody>
     152
     153                <?php foreach ( $static_pages as $name => $label ) : ?>
     154
     155                    <tr valign="top">
     156                        <th scope="row">
     157                            <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
     158                        </th>
     159
     160                        <td>
     161                            <?php echo wp_dropdown_pages( array(
     162                                'name'             => 'bp_pages[' . esc_attr( $name ) . ']',
     163                                'echo'             => false,
     164                                'show_option_none' => __( '- None -', 'buddypress' ),
     165                                'selected'         => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
     166                            ) ) ?>
     167
     168                            <a href="<?php echo admin_url( add_query_arg( array( 'post_type' => 'page' ), 'post-new.php' ) ); ?>" class="button-secondary"><?php _e( 'New Page' ); ?></a>
     169                            <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e( 'Save', 'buddypress' ) ?>" />
     170
     171                            <?php if ( !empty( $existing_pages[$name] ) ) : ?>
     172
     173                                <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View' ); ?></a>
     174
     175                            <?php endif; ?>
     176
     177                        </td>
     178                    </tr>
     179
     180                <?php endforeach ?>
     181
     182                <?php do_action( 'bp_active_external_pages' ); ?>
     183
     184            </tbody>
     185        </table>
     186
     187        <?php
     188    endif;
    178189}
    179190
Note: See TracChangeset for help on using the changeset viewer.