WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Apr 09 2014

Enabling & Installing Posts to Posts When a New Blog Is Created

The other day I came across an issue where Posts to Posts requires an administrator or someone with `manage_options` capability in order to install Posts to Posts table on a new blog creation. This does not work if all new sites create the default user as an Editor, and you need to immediately make Posts to Posts available for immediate use.

So here is the code that I used in order to make this possible.

<?php
add_action( 'wpmu_new_blog', 'wps_install_p2p', 5, 6 );
/**
* Create P2P table on site creation regardless of admin presence.
*
* @see P2P_Tools_Page::maybe_install()
* @author Travis Smith <wpsmith.net>
*
* @param int $blog_id Blog ID.
* @param int $user_id User ID.
* @param string $domain Domain.
* @param string $path Path to domain.
* @param int $site_id Site ID.
* @param array $meta Site Meta.
*
*/
function wps_install_p2p( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
switch_to_blog( $blog_id );
$current_ver = get_option( 'p2p_storage' );
if ( $current_ver == P2P_Storage::$version ) {
return;
}
P2P_Storage::install();
update_option( 'p2p_storage', P2P_Storage::$version );
restore_current_blog();
}
view raw p2p-install.php hosted with ❤ by GitHub

Written by Travis Smith · Categorized: WordPress

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Comments

  1. Trent Chow says

    June 15, 2014 at 1:11 am

    Does that hack take away the fact that I have to be an admin? I tried it but now working for me!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in