我正在使用插件Custom CSS JS 它注册自己的职位类型,但能力分配给"post".
我想把它改成"manage_options".
有没有一种不改变插件就可以做到这一点的正确方法?调用钩子、函数或其他什么?
public function register_post_type() {
$labels = array (
\'name\' => _x( \'Custom Code\', \'post type general name\' ),
\'singular_name\' => _x( \'Custom Code\', \'post type singular name\' ),
\'menu_name\' => _x( \'Custom CSS & JS\', \'admin menu\' ),
\'name_admin_bar\' => _x( \'Custom Code\', \'add new on admin bar\' ),
\'add_new\' => _x( \'Add Custom Code\', \'add new\' ),
\'add_new_item\' => __( \'Add Custom Code\' ),
\'new_item\' => __( \'New Custom Code\' ),
\'edit_item\' => __( \'Edit Custom Code\' ),
\'view_item\' => __( \'View Custom Code\' ),
\'all_items\' => __( \'All Custom Code\' ),
\'search_items\' => __( \'Search Custom Code\' ),
\'parent_item_colon\' => __( \'Parent Custom Code:\' ),
\'not_found\' => __( \'No Custom Code found.\' ),
\'not_found_in_trash\' => __( \'No Custom Code found in Trash.\' ),
);
$args = array (
\'labels\' => $labels,
\'description\' => __( \'Custom CSS and JS code\' ),
\'public\' => false,
\'publicly_queryable\' => false,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 100,
\'menu_icon\' => \'dashicons-plus-alt\',
\'query_var\' => false,
\'rewrite\' => array ( \'slug\' => \'custom-css-js\' ),
\'capability_type\' => \'post\', // <--- I want to manipulate this
\'has_archive\' => true,
\'hierarchical\' => false,
\'exclude_from_search\' => true,
\'menu_position\' => null,
\'can_export\' => false,
\'supports\' => array ( \'title\' ),
);
register_post_type( \'custom-css-js\', $args );
}
上述代码位于
custom-css-js.php 线
200-239.
最合适的回答,由SO网友:Nathan Powell 整理而成
@彼得·古森很酷,仍然像我一样清醒,像老板一样回答。
为了简化他的代码,并使其具体实现这一点,您的页面上没有一堆垃圾:
/**
* Pieter Goosen writes awesome code
*/
add_filter( \'register_post_type_args\', \'change_capabilities_of_the_custom_css_js_posttype\' , 10, 2 );
function change_capabilities_of_the_custom_css_js_posttype( $args, $post_type ){
// Do not filter any other post type
if ( \'custom-css-js\' !== $post_type ) {
// Give other post_types their original arguments
return $args;
}
// Change the capability_type of the "custom-css-js" post_type
$args[\'capability_type\'] = \'manage_options\';
// Give the custom-css-js post type it\'s arguments
return $args;
}
您选择的插件是以广泛的方式编写的。它有一些不安全感。