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(); | |
} |
Trent Chow says
Does that hack take away the fact that I have to be an admin? I tried it but now working for me!