what makes MU plugins work? I’m looking to port some non-MU ones over.

I have two plugins designed for the standard WP. I need to hack them & port them to MU, 1) for them to function correctly & 2) to allow them to remain activated on every secondary blog. For some reason, even when using Aaron’s plugin manager, they don’t stay active on secondary blogs… and I need them to 100% of the time.

Are there any tricks to writing *good* MU plugins? I could use any tips to ensure compatibility.

One plugin has a single-field form in an individual dashboard page that simply allows users to upload an image that is automatically placed in a specific location on the page (in this case, a logo). I assume a hack is needed here to upload to the appropriate /blogs.dir subfolder.

The other adds some form fields to the standard "write post" page. It allows users to add extra data (which then gets placed similarly as with the aforementioned logo plugin) without messing with custom fields/keys, which helps my site’s usability for non-technical members.

Any suggestions would be welcome. These aren’t complex plugins but I need them to work flawlessly with MU. Thanks!!

Scott

  • Aaron
    • Ex Staff

    Scott, your problems with Plugin Manager are probably caused by the supporter-plugins.php file in mu-plugins. Make sure it is removed as they are exclusive.

    You do have to watch out for plugins that write images or files. Single wordpress versions often add them to the uploads folder rather than the proper blogs.dir directory.

    Also the db issues like Andrew said. Scan the plugin source for $wpdb to see if they are accessing the db directly.

  • Scott Pruett
    • Design Lord, Child of Thor

    Interesting, thanks guys. I removed supporter-plugins.php; thanks for the tip Aaron. That makes sense.

    However, I still have a problem where the menu items that these plugins create (similar to how Supporter creates a new item) seem to disappear.

    I can get them to appear by manually typing in /wp-admin/post-new.php?ref=abc (where "abc" calls the plugin code to ammend add’l fields to post.php… but that’s not very user-friendly.

    Any idea why these menu items wouldn’t appear automatically when the dashboard loads?

  • Andrew
    • Champion of Loops

    Any idea why these menu items wouldn’t appear automatically when the dashboard loads?

    Not really sure without looking at the code. One of the easiest ways to figure out what’s wrong with a plugin is look at the code of a plugin that has the same type of feature. So if you’re having trouble with adding menu pages, take a look at a plugin that adds a menu page.

    Thanks,

    Andrew

  • Scott Pruett
    • Design Lord, Child of Thor

    Ah, common sense! Good call Andrew :slight_smile:

    Okay, I’ve had some time to look @ these plugins for db interaction. They do interact w/ the database. What’s this mean for me, practically speaking? Lots of hacking? Incompatibility?

    The least-involved is the plugin that amends the post.php form. Here are the $wpdb instances from that plugin (copied/pasted out of context):


    global $wpdb;

    $join .= " JOIN $wpdb->postmeta";

    $join .= " ON $wpdb->posts.ID = $wpdb->postmeta.post_id";

    $join .= " ON $wpdb->posts.ID = $wpdb->postmeta.post_id";

    $join .= " AND ($wpdb->postmeta.meta_key = ‘isabcplugin’:wink:";


    The other plugin has ~42 $wpdb mentions. I can go into further detail if need be… but all that one does is allow users to upload an image (& replace, if desired) that’ll be placed in the theme template.

    Thanks for the help. I’m not a back-end coder, so any input is more than welcome.

  • Andrew
    • Champion of Loops

    You should be ok with that query.

    Quick example for you:

    Good query:

    SELECT * FROM $wpdb->posts WHERE ID = 1

    Bad query:

    SELECT * FROM wp_posts WHERE ID = 1

    The ‘good’ query will pull the data from the correct table but the ‘bad’ query won’t because it has the table name hardcoded.

    Thanks,

    Andrew

  • Scott Pruett
    • Design Lord, Child of Thor

    Gotcha, thanks. That makes sense.

    As for the logo plugin, I have a friend who does understand how to write/manipulate this stuff. I may see if he can rewrite it to upload an image to the appropriate /blogs.dir subfolder for whatever secondary blog & use a simple variable to call w/in the page… and thus not touch the database at all.

    Would that work, or am I missing something?

  • Andrew
    • Champion of Loops

    Would that work, or am I missing something?

    If you just need to upload a logo for use in the theme then just do this:

    1) upload the file to the blogs.dir/{blogid}/files/ directory

    2) set a blog option with the image path

    3) Use a snippet like the following in the theme

    <img src='<?php echo get_option('logo_path'); ?>' />

    Thanks,

    Andrew