• I’ve never made a plugin before. But I have checked out the Plugin Editor to see the code and tinker with it. Question:

    Can I make a duplicate of Weighted_Words.php and call it Weighted_Words_2.php? I want to activate both versions, with just 1 little change in the code between them, and then show the output in 2 different places on my blog. Is that going to mess things up? If I do this, can I simply call
    <?php weighted_words2(); ?>
    instead of the regular
    <?php weighted_words(); ?>
    in my template? Or is there someplace in the plugin itself where I need to rename the function if I want “2 of them”?

    Reason why (if this matters): I enjoy the Weighted_Words plugin, and now I want to run 2 versions of it on the same blog. One version is in the sidebar, and I customized the plugin so the output is NOT sorted alphabetically. Now I want to run another version of the plugin on a Page called “Glossary” or “Vocabulary”, and in this case I *do* want the output sorted alphabetically. The trouble is, the alphabatizing is not an argument which I can put in the template_tag that calls the Weighted Words output. The place I change this is in the Plugin Editor, in the plugin itself.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You would need to change the name of the weighted_words() function (as well as any other functions it may define) in the file of your alternate version of the plugin to avoid any conflicts between the two.

    Thread Starter Dgold

    (@dgold)

    Thanks for your reply Kafkaesqui. I’m going to dive-in and try it. Not knowing PHP, I’m not sure if I know when/where it is defining a function, but I’ll just read the code and see what I notice. This particular plugin is well-commented in the plugin php.

    Also – I can avoid calling both plugins on the same page (either weighted_words, or weighted_words2), if this helps avoid any possible conflicts with other functions that may be in the plugin.

    But I’m going to try to take kafka’s advice and rename any/all.

    This is how a PHP function is ‘defined:’

    function name_of_function(optional args) {
    ...
    }

    The name_of_function portion is what we’re after. In your situation each function statement your modified plugin has will have to be renamed to avoid conflicts with those functions in the other plugin file. And if there are one or more additional functions it’s very likely you’ll find they are called at some point within the plugin, possibly more than once. Each instance of these would also have to be renamed.

    Finally, the issue is not when or where a function is used. WordPress loads all active plugins together, and as each available (defined) function in a script process must have a unique name…

    P.S. Call me Kaf. Kafka is a last name, but not mine. :)

    note that you don’t need two different versions of the plugin necessarily… you can probably use the original plugin, and just add a second function that does the modified output you are looking for. a second version of the plugin is certainly asking for trouble. ??

    -d

    I wouldn’t say it’s asking for trouble (well, ok, maybe I would), but it is something to be careful about. On the flip side, it’s a great way to learn how a plugin works, and even how to start writing your own.

    Thread Starter Dgold

    (@dgold)

    Good points, fellas. I’m quite new at this. Appreciate both of your ongoing help on this forum.

    There’s really only 1 line that I want to change in the 2 versions. So I like the idea of just making a second function, if I can figure out how. I’m guessing I can copy a big block of code where the weighted_words function is defined, and then rename this function & make the 1 little change in the duplicated block of code.

    You could also add a new, optional parameter to the end of the original function’s param list, default it to false, and if true use your new line (if false use the original line…). then you don’t need a second function at all… ??

    -d

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Can I activate 2 versions of the same plugin?’ is closed to new replies.