Skip to:
Content

BuddyPress.org

Changeset 3446


Ignore:
Timestamp:
11/19/2010 04:44:13 PM (16 years ago)
Author:
johnjamesjacoby
Message:

Second pass at banned names (see r3441)

Location:
branches/1.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-core.php

    r3441 r3446  
    255255        dbDelta( $sql );
    256256
    257         /* Add names of root components to the banned blog list to avoid conflicts */
    258         if ( bp_core_is_multisite() )
    259                 bp_core_add_illegal_names();
     257        // Add names of root components to the banned name list to avoid conflicts
     258        bp_core_flush_illegal_names();
    260259
    261260        update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION );
     
    16791678
    16801679/**
    1681  * bp_core_add_illegal_names()
     1680 * bp_core_get_illegal_names()
    16821681 *
    16831682 * Adds illegal names to WP so that root components will not conflict with
     
    16861685 * For example, it would stop someone creating a blog with the slug "groups".
    16871686 */
    1688 function bp_core_add_illegal_names() {
    1689         update_site_option( 'illegal_names', get_site_option( 'illegal_names' ), array() );
     1687function bp_core_get_illegal_names() {
     1688
     1689        // BuddyPress core illegal names
     1690        $bp_illegal_names[] = defined( 'BP_GROUPS_SLUG'     ) ? BP_GROUPS_SLUG     : 'groups';
     1691        $bp_illegal_names[] = defined( 'BP_MEMBERS_SLUG'    ) ? BP_MEMBERS_SLUG    : 'members';
     1692        $bp_illegal_names[] = defined( 'BP_FORUMS_SLUG'     ) ? BP_FORUMS_SLUG     : 'forums';
     1693        $bp_illegal_names[] = defined( 'BP_BLOGS_SLUG'      ) ? BP_BLOGS_SLUG      : 'blogs';
     1694        $bp_illegal_names[] = defined( 'BP_ACTIVITY_SLUG'   ) ? BP_ACTIVITY_SLUG   : 'activity';
     1695        $bp_illegal_names[] = defined( 'BP_XPROFILE_SLUG'   ) ? BP_XPROFILE_SLUG   : 'profile';
     1696        $bp_illegal_names[] = defined( 'BP_FRIENDS_SLUG'    ) ? BP_FRIENDS_SLUG    : 'friends';
     1697        $bp_illegal_names[] = defined( 'BP_SEARCH_SLUG'     ) ? BP_SEARCH_SLUG     : 'search';
     1698        $bp_illegal_names[] = defined( 'BP_SETTINGS_SLUG'   ) ? BP_SETTINGS_SLUG   : 'settings';
     1699        $bp_illegal_names[] = defined( 'BP_REGISTER_SLUG'   ) ? BP_REGISTER_SLUG   : 'register';
     1700        $bp_illegal_names[] = defined( 'BP_ACTIVATION_SLUG' ) ? BP_ACTIVATION_SLUG : 'activation';
     1701
     1702        // WordPress core illegal names
     1703        $wp_illegal_names   = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' );
     1704
     1705        // Merge illegal names together and filter them
     1706        return apply_filters( 'bp_core_illegal_names', array_merge( $bp_illegal_names, $wp_illegal_names ) );
     1707}
     1708
     1709/**
     1710 * bp_core_update_illegal_names()
     1711 *
     1712 * Filter the illegal_names site option and make sure it includes a few
     1713 * specific BuddyPress and Multi-site slugs
     1714 *
     1715 * @param array|string $value Illegal names from field
     1716 * @param array|string $oldvalue The value as it is currently
     1717 * @return array Merged and unique array of illegal names
     1718 */
     1719function bp_core_update_illegal_names( $value = '', $oldvalue = '' ) {
     1720        if ( !bp_core_is_multisite() )
     1721                return false;
     1722
     1723        // Make sure $value is array
     1724        if ( is_array( $value ) )
     1725                $db_illegal_names = $value;
     1726        elseif ( is_string( $value ) )
     1727                $db_illegal_names = implode( ' ', $value );
     1728        elseif ( empty( $value ) )
     1729                $db_illegal_names = array();
     1730
     1731        // Get illegal names, merge with ones in DB, and remove duplicates
     1732        $bp_illegal_names = bp_core_get_illegal_names();
     1733        $merged_names     = array_merge( (array)$bp_illegal_names, (array)$db_illegal_names );
     1734        $illegal_names    = array_unique( (array)$merged_names );
     1735
     1736        return apply_filters( 'bp_core_update_illegal_names', $illegal_names );
     1737}
     1738add_filter( 'pre_update_site_option_illegal_names', 'bp_core_update_illegal_names', 10, 2 );
     1739
     1740/**
     1741 * bp_core_flush_illegal_names()
     1742 *
     1743 * Flush illegal names by getting and setting 'illegal_names' site option
     1744 */
     1745function bp_core_flush_illegal_names() {
     1746        $illegal_names = get_site_option( 'illegal_names' );
     1747        update_site_option( 'illegal_names', $illegal_names );
    16901748}
    16911749
  • branches/1.2/bp-core/bp-core-signup.php

    r3441 r3446  
    255255 * true or false on success or failure.
    256256 */
    257 
    258 /**
    259  * bp_core_flush_illegal_names()
    260  *
    261  * Flush illegal names by getting and setting 'illegal_names' site option
    262  */
    263 function bp_core_flush_illegal_names() {
    264         $illegal_names = get_site_option( 'illegal_names' );
    265         update_site_option( 'illegal_names', $illegal_names );
    266 }
    267 
    268 /**
    269  * bp_core_illegal_names()
    270  *
    271  * Filter the illegal_names site option and make sure it includes a few
    272  * specific BuddyPress and Multi-site slugs
    273  *
    274  * @param array|string $value Illegal names from field
    275  * @param array|string $oldvalue The value as it is currently
    276  * @return array Merged and unique array of illegal names
    277  */
    278 function bp_core_illegal_names( $value = '', $oldvalue = '' ) {
    279 
    280         // Make sure $value is array
    281         if ( empty( $value ) )
    282                 $db_illegal_names = array();
    283         if ( is_array( $value ) )
    284                 $db_illegal_names = $value;
    285         elseif ( is_string( $value ) )
    286                 $db_illegal_names = implode( ' ', $names );
    287 
    288         // Add the core components' slugs to the banned list even if their components aren't active.
    289         $bp_component_slugs = array( 'groups', 'members', 'forums', 'blogs', 'activity', 'profile', 'friends', 'search', 'settings', 'register', 'activate' );
    290 
    291         if ( defined( 'BP_GROUPS_SLUG' ) )
    292                 $bp_component_slugs[] = BP_GROUPS_SLUG;
    293 
    294         if ( defined( 'BP_MEMBERS_SLUG' ) )
    295                 $bp_component_slugs[] = BP_MEMBERS_SLUG;
    296 
    297         if ( defined( 'BP_FORUMS_SLUG' ) )
    298                 $bp_component_slugs[] = BP_FORUMS_SLUG;
    299 
    300         if ( defined( 'BP_BLOGS_SLUG' ) )
    301                 $bp_component_slugs[] = BP_BLOGS_SLUG;
    302 
    303         if ( defined( 'BP_ACTIVITY_SLUG' ) )
    304                 $bp_component_slugs[] = BP_ACTIVITY_SLUG;
    305 
    306         if ( defined( 'BP_XPROFILE_SLUG' ) )
    307                 $bp_component_slugs[] = BP_XPROFILE_SLUG;
    308 
    309         if ( defined( 'BP_FRIENDS_SLUG' ) )
    310                 $bp_component_slugs[] = BP_FRIENDS_SLUG;
    311 
    312         if ( defined( 'BP_SEARCH_SLUG' ) )
    313                 $bp_component_slugs[] = BP_SEARCH_SLUG;
    314 
    315         if ( defined( 'BP_SETTINGS_SLUG' ) )
    316                 $bp_component_slugs[] = BP_SETTINGS_SLUG;
    317 
    318         if ( defined( 'BP_REGISTER_SLUG' ) )
    319                 $bp_component_slugs[] = BP_REGISTER_SLUG;
    320 
    321         if ( defined( 'BP_ACTIVATION_SLUG' ) )
    322                 $bp_component_slugs[] = BP_ACTIVATION_SLUG;
    323        
    324         // Add our slugs to the array and allow them to be filtered
    325         $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array_merge( array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ), $bp_component_slugs ) );
    326 
    327         // Merge the arrays together
    328         $merged_names = array_merge( (array)$filtered_illegal_names, (array)$db_illegal_names );
    329 
    330         // Remove duplicates
    331         $illegal_names = array_unique( (array)$merged_names );
    332 
    333         return apply_filters( 'bp_core_illegal_names', $illegal_names );
    334 }
    335 add_filter( 'pre_update_site_option_illegal_names', 'bp_core_illegal_names', 10, 2 );
    336257
    337258/**
Note: See TracChangeset for help on using the changeset viewer.