WordPress.org

Ready to get started?Download WordPress

Forums

Per-Blog Table Prefixes (2 posts)

  1. not2bug
    Member
    Posted 4 years ago #

    Hi,

    I’m trying to figure out a way of making it so that each blog gets its own table prefix instead of just getting the standard wp_2_*, wp_3_*, etc.

    For example, when you create a new blog in the Add Site section of the Sites page, it asks for a “Site Address”. If you create two blogs, one at /blogs/<strong>personal</strong>, and one at /blogs/<strong>school</strong>, then they would use personal_* and school_* for their tables in the database.

    (Yes, I know that this does not help with security, but it certainly does help with maintenance.)

    It looks like the primary place to make a change would be in the function get_blog_prefix in wp-db.php. It seems as though all that’s necessary is to change $this->base_prefix . $blog_id. (Yes, existing tables would need to be renamed, etc., but I’m just interested in the coding changes for the moment.)

    Would that work? Is that sufficient to correctly handle newly created blogs? How can I get the site address that was entered in the Add Site form to replace $blog_id with?

    Thanks a lot.

  2. not2bug
    Member
    Posted 4 years ago #

    I also replaced two lines in ms-functions.php:

    In is_blog_user, this:

      $cap_key = $wpdb->base_prefix . $blog_id . '_capabilities';

    with this:

      $cap_key = $wpdb->get_blog_prefix( $blog_id ) . '_capabilities';

    And in is_user_option_local, this:

      $local_key = $wpdb->base_prefix . $blog_id . '_' . $key;

    with this:

      $local_key = $wpdb->get_blog_prefix( $blog_id ) . $key;

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.