首先,我要说我没有插件的经验或知识,这个答案完全基于对注册插件中使用的帖子类型的代码的30秒扫描,因此您可能会发现这个解决方案的问题,而我快速点击测试事件并没有发现这些问题。话虽如此。。。
其基本要点是取消设置插件注册的post类型,然后使用相同的设置重新注册它,但修改后的重写slug除外。要了解其工作原理,您应该熟悉register_post_type
如果您还没有完成,请执行函数。
为插件注册post类型的代码位于文件中app/helper/class-ai1ec-app-helper.php
.
下面的代码在2011主题的函数中进行了测试。php文件。您可以在自己的插件中执行此操作,但必须确保它在事件日历插件的init之后运行。
请务必阅读代码中的所有注释,以了解更改的内容,重要的细节是rewrite
的参数register_post_type
这为我们提供了所需的URL:\'rewrite\' => array( \'slug\' => \'calendar/event\', \'with_front\' => false )
add_action( \'init\', \'wpa64981_event_calendar_init\' );
function wpa64981_event_calendar_init() {
// make sure the plugin is active and has set itself up
if( defined( \'AI1EC_POST_TYPE\' ) ) :
// globalize the post types array and some plugin settings we\'ll need
global $wp_post_types, $ai1ec_settings, $ai1ec_app_helper;
// unset the original post type created by the plugin
unset( $wp_post_types[ AI1EC_POST_TYPE ] );
// the labels array was copied wholesale from the plugin
// EXCEPT \'all_items\' value, which originally reference $this
$labels = array(
\'name\' => _x( \'Events\', \'Custom post type name\', AI1EC_PLUGIN_NAME ),
\'singular_name\' => _x( \'Event\', \'Custom post type name (singular)\', AI1EC_PLUGIN_NAME ),
\'add_new\' => __( \'Add New\', AI1EC_PLUGIN_NAME ),
\'add_new_item\' => __( \'Add New Event\', AI1EC_PLUGIN_NAME ),
\'edit_item\' => __( \'Edit Event\', AI1EC_PLUGIN_NAME ),
\'new_item\' => __( \'New Event\', AI1EC_PLUGIN_NAME ),
\'view_item\' => __( \'View Event\', AI1EC_PLUGIN_NAME ),
\'search_items\' => __( \'Search Events\', AI1EC_PLUGIN_NAME ),
\'not_found\' => __( \'No Events found\', AI1EC_PLUGIN_NAME ),
\'not_found_in_trash\' => __( \'No Events found in Trash\', AI1EC_PLUGIN_NAME ),
\'parent_item_colon\' => __( \'Parent Event\', AI1EC_PLUGIN_NAME ),
\'menu_name\' => __( \'Events\', AI1EC_PLUGIN_NAME ),
\'all_items\' => $ai1ec_app_helper->get_all_items_name()
);
// identical to plugin\'s original values
$supports = array( \'title\', \'editor\', \'comments\', \'custom-fields\', \'thumbnail\' );
// this is where the important change is made
// to get our own rewrite slug:
//
// \'rewrite\' => true
//
// changes to:
//
// \'rewrite\' => array( \'slug\' => \'calendar/event\', \'with_front\' => false )
//
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'calendar/event\', \'with_front\' => false ),
\'capability_type\' => array( \'ai1ec_event\', \'ai1ec_events\' ),
\'capabilities\' => array(
\'read_post\' => \'read_ai1ec_event\',
\'edit_post\' => \'edit_ai1ec_event\',
\'edit_posts\' => \'edit_ai1ec_events\',
\'edit_others_posts\' => \'edit_others_ai1ec_events\',
\'edit_private_posts\' => \'edit_private_ai1ec_events\',
\'edit_published_posts\' => \'edit_published_ai1ec_events\',
\'delete_post\' => \'delete_ai1ec_event\',
\'delete_posts\' => \'delete_ai1ec_events\',
\'delete_others_posts\' => \'delete_others_ai1ec_events\',
\'delete_published_posts\' => \'delete_published_ai1ec_events\',
\'delete_private_posts\' => \'delete_private_ai1ec_events\',
\'publish_posts\' => \'publish_ai1ec_events\',
\'read_private_posts\' => \'read_private_ai1ec_events\' ),
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => 5,
\'supports\' => $supports,
\'exclude_from_search\' => $ai1ec_settings->exclude_from_search,
);
// register the post type with our new settings
register_post_type( AI1EC_POST_TYPE, $args );
endif;
}