Title: Using p2p in another plugin
Last modified: August 21, 2016

---

# Using p2p in another plugin

 *  [VegasKev88](https://wordpress.org/support/users/vegaskev/)
 * (@vegaskev)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/using-p2p-in-another-plugin/)
 * 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
 * [http://wordpress.org/plugins/posts-to-posts/](http://wordpress.org/plugins/posts-to-posts/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [VegasKev88](https://wordpress.org/support/users/vegaskev/)
 * (@vegaskev)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/using-p2p-in-another-plugin/#post-4090352)
 * 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.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

## Tags

 * [p2p](https://wordpress.org/support/topic-tag/p2p/)

 * 1 reply
 * 1 participant
 * Last reply from: [VegasKev88](https://wordpress.org/support/users/vegaskev/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/using-p2p-in-another-plugin/#post-4090352)
 * Status: not resolved