我遇到了一个类似的问题,我需要内容在“网络范围”内可用,并从一个位置(主站点)进行管理,因此我在主站点创建了一个名为“共享内容”的自定义帖子类型,以及一个从主站点提取内容的小快捷码。
这是它的“一个版本”,但不是测试版,因为我无法访问我当时使用的工作解决方案,但它应该可以正常工作:
<?php
/*
Plugin Name: WPMU Shared Content
Plugin URI: http://en.bainternet.info
Description: This plugin lets you create and manage content on the main MU installation and shared it accros you network
Version: 0.1
Author: Bainternet
License:
Copyright 2012 Bainternet ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Disallow direct access to the plugin file */
if (basename($_SERVER[\'PHP_SELF\']) == basename (__FILE__)) {
die(\'Sorry, but you cannot access this page directly.\');
}
if (!class_exists(\'wpmu_shared_content\')){
/**
* wpmu_shared_content
*/
class wpmu_shared_content
{
static $main_site_id;
static $current;
//class constructor
public function __construct($main_id = 1);
{
global $blog_id;
$this->main_site_id = $main_id
$this->current = $blog_id;
//only register the post type to the main side
if (is_main_site($this->main_site_id) && is_super_admin())
add_action( \'init\', array($this,\'register_shared_content\' ));
add_shortcode(\'sh\',array($this,\'load_shared_content\'));
add_shortcode(\'SH\',array($this,\'load_shared_content\'));
}
//register custom post type shared content
public function register_shared_content() {
$labels = array(
\'name\' => _x( \'Shared Content\', \'shared_content\' ),
\'singular_name\' => _x( \'shared_content\', \'shared_content\' ),
\'add_new\' => _x( \'Add New\', \'shared_content\' ),
\'add_new_item\' => _x( \'Add New shared_content\', \'shared_content\' ),
\'edit_item\' => _x( \'Edit shared_content\', \'shared_content\' ),
\'new_item\' => _x( \'New shared_content\', \'shared_content\' ),
\'view_item\' => _x( \'View shared_content\', \'shared_content\' ),
\'search_items\' => _x( \'Search Shared Content\', \'shared_content\' ),
\'not_found\' => _x( \'No shared content found\', \'shared_content\' ),
\'not_found_in_trash\' => _x( \'No shared content found in Trash\', \'shared_content\' ),
\'parent_item_colon\' => _x( \'Parent shared_content:\', \'shared_content\' ),
\'menu_name\' => _x( \'Shared Content\', \'shared_content\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => false,
\'description\' => \'Content to be shared with all sites but managed form main installation only.\',
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'custom-fields\' ),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_icon\' => \'http://i.imgur.com/LI2B6.png\',
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => false,
\'exclude_from_search\' => false,
\'has_archive\' => false,
\'query_var\' => false,
\'can_export\' => true,
\'rewrite\' => false,
\'capability_type\' => \'post\'
);
register_post_type( \'shared_content\', $args );
}
//shortcode handler
public function load_shared_content($atts,$content=null){
extract(shortcode_atts(
array(\'id\' => 0),
$atts));
$retVal = "";
if ($id <= 0)
return $retval;
$shared_content = get_blog_post($this->main_site_id,$id);
$retVal = apply_filters(\'the_content\',$shared_contents[\'post_content\']);
return $retVal;
}
}//end class
}//end if
if (is_multisite())
new wpmu_shared_content(apply_filters(\'wpmu_shared_content_main_site_id\', 1));
/**
* Usage: [sh id="3"] or [SH id= 3]
*/