• I’m currently using both BadgeOS (which uses a version of Scribu’s Posts-2-Posts plug-in) as well as the Posts-2-Posts plug-in itself for other functionality on my blog.

    The problem I am encountering is that it seems like BadgeOS loads Posts-2-Posts a second time, after P2P has already initialized by itself (I assume this is because BadgeOS ignores that P2P initializes itself when P2P is installed as a standalone plug-in side-by-side with BadgeOS.)

    In particular, I’m noticing that P2P’s _p2p_load() function is executed twice on my blog.

    I’m not sure which other consequences this has, but one issue I’m noticing is that when I view the admin edit.php page for a post type, for which I have P2P add an additional admin column for a registered connection type, that column populates twice instead of once.

    Is there a way to make BadgeOS not load P2P a second time? I was thinking about adding the following to P2P’s _p2p_load() function. Apart from the fact that I don’t know if this would actually work, this is obviously far from ideal:

    static $p2p_counter = 0;
    
    $p2p_counter++;
    if ($p2p_counter > 1) {
    	return;
    }

    How can this be resolved?

    https://www.ads-software.com/plugins/badgeos/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    Honestly a good question that I don’t have an answer for at the moment. One big concern that I’d have is if they’re different versions of p2p, and the one that gets loaded first doesn’t have all the necessary parts. This would cause either issues with your own usage of the plugin, or cause issues with BadgeOS’.

    Thread Starter AngryGerman

    (@angrygerman)

    Assuming that the standalone version of P2P is kept up-to-date, is it an option for BadgeOS to just not initialize a second version when that standalone version is already present?

    I am also curious, because it looks like the _p2p_load() function inside the standalone plug-in actually gets called twice. I assume this might be because it’s being called through a hook that fires twice.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Just out of curiosity, is the double loading occurring with BadgeOS disabled?

    I’ve done a quick search of the entire BadgeOS core plugin for _p2p_load() and the following is the only thing I’m seeing:

    $ ack _p2p_load
    includes/p2p/load.php
    15:function _badgeos_p2p_load() {
    27: _badgeos_p2p_load_admin();
    31:scb_init( ‘_badgeos_p2p_load’ );
    38:function _badgeos_p2p_load_admin() {

    Essentially from what I can see, everything is prefixed with _badgeos for our usage.

    Thread Starter AngryGerman

    (@angrygerman)

    Double-loading occurs only when BadgeOS is enabled.

    To test, I added an echo 'load'; to the _p2p_load() function inside of the standalone P2P’s posts-to-posts.php file.

    This echoes twice with BadgeOS enabled, and only once with BadgeOS disabled.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Honestly, the best I can tell, the non-BOS posts-2-posts classes and whatnot get loaded first, and it does its thing. Then BadgeOS kicks in, and due to the class_exists() checks and the first one already being loaded, it passes its data into the first one, and along the way, a static private array property gets re-used and it is ending up with the posts-2-posts callback still stored as an index from the first run, causing it to be re-run.

    For what it’s worth, it’s not ignoring things, it’s re-using the first-loaded.

    I honestly don’t know how to get around this without breaking anything, and I’m also not that well versed in posts-2-posts in general either. Note I’m not the original developer of BadgeOS plugins, but I am lead support. My head is wandering around wondering if we could somehow get at that static array and empty it somehow, but I think the scopes/access are going to prevent that.

    Thread Starter AngryGerman

    (@angrygerman)

    Would it be an option to namespace the P2P plugin / classes used inside BadgeOS, to keep them separate?

    Or for BadgeOS to run a function_exists or class_exists by itself to detect whether P2P has already been defined, and, in that case, to not use its own version? (This would probably depend on plug-in initialization order, but could be made optional, so that the developer asking BadgeOS to use the standalone version instead is still responsible for making sure that the standalone P2P version is the newest.)

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    not in a way that i’m comfortable distributing in an official release, to be honest. We can’t use namespaces because we do need to make sure we keep PHP 5.2 in mind at this point, just in case.

    I also not necessarily sure that would work anyway, based on how scb/p2p is set up. It’d need heavy testing.

    It’s not using it’s own version now, it’s using the first one being detected/loaded, which is the one from https://www.ads-software.com/plugins/posts-to-posts that you have installed on your own. Same for my own local install that I was testing with with breakpoints. As mentioned, there’s an array key in the first loaded one that’s seeming to be stuck in the array instead of starting fresh.

    I contacted one of the others who worked on it in the past to see if there was reason we didn’t isolate the entire scb/p2p lib for our own, instead of just parts of it.

    As odd as it may sound, we actually don’t run into these conflicts often, since I figure most of our usual users aren’t that dev-heavy that they have other plugins that use p2p.

    Thread Starter AngryGerman

    (@angrygerman)

    Hi Michael,

    Have you been able to find out any more about why the integration was made this way?

    We’re currently using the above-described counter as a workaround, and it seems to work in our case, but it’s obviously not ideal by any means.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    No, sadly not.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘BadgeOS initializes Posts-2-Posts Plug-in twice’ is closed to new replies.