Skip to:
Content

BuddyPress.org


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

Second pass at banned names (see r3441)

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.