Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have custom plugin which registers multiple CPT's and i want to reuse the features of wp-posts-to-posts to define relationships. I'm just wondering what is the correct/best way to include the api.php file within my own plugin?

function my_connection_types() {

    require_once( ABSPATH . 'wp-content/plugins/posts-to-posts/core/api.php' );
    // Make sure the Posts 2 Posts plugin is active.
    if ( !function_exists( 'p2p_register_connection_type' ) )
        return;

    p2p_register_connection_type( array(
            'name' => 'events_to_races',
            'from' => 'event',
            'to' => 'race',
            'cardinality' => 'one-to-many'
    ) );
}
share|improve this question

closed as off-topic by Pieter Goosen, s_ha_dum Oct 15 at 20:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
If the posts-to-posts plugin is running on your site, I am not sure you'd need to include api.php but of course that depends on how the plugin works making the question off-topic as dependent on third party code. –  s_ha_dum Oct 15 at 20:00

1 Answer 1

up vote 1 down vote accepted

Don't try to load the plugin yourself, check for its existence on your activation hook.

If it's not activated, throw an error; WordPress will display the message & prevent activation of your plugin.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.