• First of all….Scribu you are awesome. Thanks so much for all the hard work that you’ve put into p2p. It’s a godsend. That being said, I’m hoping you can take a look at this and give me some guidance. It would be much appreciated.

    I’m working on a plugin that requires associations between cpts and posts and cpts and other cpts…and your plugin works wonders for it, so I dropped your plugin into my plugin with my cpt’s and my plugin’s core functions, etc. and then removed the headers from your posts-to-posts to make it work (and of course gave you credit and link to your pages in my loader.php file) and I can write connections in the theme’s functions.php just fine. Unfortunately, I’m trying to keep everything independent of themes, so I really need to keep the connections within the plugin files. I cannot seem to get it to work for the life of me inside my plugin.

    I keep getting “call to undefined function ‘p2p_register_connection_type’ ….”.

    I’ve tried this as well:

    function wpcram_connections() {
    	// ensure p2p is active and functioning first.
    	if ( !function_exists( 'p2p_register_connection_type' ) )
    		return;
    
    	p2p_register_connection_type( array(
    		'name' => 'user_to_clients',
    		'from' => 'clients',
    		'to' => 'user',
    		'admin_box' => array(
    			'show' => 'any',
    			'context' => 'side'
    			)
    		) );
    }
    add_action( 'wp-loaded', 'wpcram_connections', 50 );

    When I run the above function, I don’t get an error, however, the ‘p2p_register_connection_type’ doesn’t fire and no connection metabox appears in the ‘clients’ post editor screen.

    Just to note:

    the cpts are handwritten and are inside my plugin ‘wpcram’. You’re plugin folder (unmodified) is inside the same ‘wpcram’ folder.

    My loader.php IS executing properly, as I can include a ‘p2p_register_connection_type’ function inside the theme’s functions.php, just not within my plugin.

    I have no other plugins…even dolly and askimet are deleted…it’s just the single plugin which ONLY includes my cpts, a few minor functions (which I removed to see if they conflict, and they do not) and your plugin which is nested in mine.

    I’m obviously missing something….I just can’t seem to see it.

    Any guidance/help would be much appreciated. Thanks in advance. I’m hoping to get this bad boy done today and throw it up on git tomorrow after testing…as usual, I’m on the last leg and my foot just got chopped off….Murphy’s Law..lol

    https://www.ads-software.com/plugins/posts-to-posts/

Viewing 1 replies (of 1 total)
  • Thread Starter VegasKev88

    (@vegaskev)

    lol…I got it……here’s my revised code for anyone else that needs to do this.

    function wpcram_connections() {
    	// ensure p2p is active and functioning first.
    	if ( !function_exists( 'p2p_register_connection_type' ) ) {
    		return;
    	}
    
    	p2p_register_connection_type( array(
    		'name' => 'user_to_clients',
    		'from' => 'clients',
    		'to' => 'user',
    		'admin_box' => array(
    			'show' => 'any',
    			'context' => 'side'
    			)
    		) );
    }
    add_action( 'after_setup_theme', 'wpcram_connections', 50 );
Viewing 1 replies (of 1 total)
  • The topic ‘Using p2p in another plugin’ is closed to new replies.