FYI for Plugin Standards

This is an FYI more than anything...

I recently could not get a premium plugin to work, at all. I use multi-site in a multi-db environment, using all of the latest versions of said software and knowing there could be a number of things that could go wrong, I rolled up my sleeves to find the solution. It turns out that the premium.wpmu plugin was hard coding the table prefixes as in 'wp_'. Since wordpress allows us to change the table prefixes and it is a smart security move to do so, why not code the plugins to use the variable $table_prefix? This is found in the WP root config file.

I now do a search for all 'wp_' in all of your plugins and upgrade the code to reflect the variable $table_prefix and this solves my issues.... note, you must declare global $table_prefix before you can use it inside a function.

Hope this helps someone.

Gregg

  • Barry

    I now do a search for all 'wp_' in all of your plugins and upgrade the code to reflect the variable $table_prefix and this solves my issues.... note, you must declare global $table_prefix before you can use it inside a function.

    Can you let us know which plugin? I don't recommend using $table_prefix in a MS context.
    You should global $wpdb and use $wpdb->prefix if you are operating with local blog level tables or $wpdb->base_prefix if operating with global site level tables.

    Assuming the prefix you have set is wp_ within WordPress $wpdb->prefix will give you wp_2_ for a blog with an id of 2 and $wpdb->base_prefix would give you wp_

    In, multi-db, the base_prefix table will be looked for in the global database, the standard prefix one will be looked for in the database for that blog.

  • Brayne

    Hello Barry,

    Yes, absolutely correct. Using $wpdb with ->prefix and and ->base_prefix is the way to go....

    Here is an example of some offending hard code that I found...

    using the Membership plugin....

    inside the file -
    membership/membershipincludes/includes/default.rules.php

    inside the function is_user_blog_admin( $user_id, $blog_id )
    around line 1089
    $meta_key = "wp_" . $blog_id . "_capabilities";

    Since I saw that $blog_id was being passed to this function I just did the easiest thing and declared the global to use this.....

    $meta_key = $table_prefix . $blog_id . "_capabilities";

    Hope this makes sense...

    Cheers.

    Gregg

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.