Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add capabilities to administrator and change structure #877

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions includes/admin/feedzy-rss-feeds-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ public function register_post_type() {
$supports = array(
'title',
);
$capability = feedzy_current_user_can();
$args = array(
'labels' => $labels,
'supports' => $supports,
Expand All @@ -283,18 +282,35 @@ public function register_post_type() {
'rest_controller_class' => 'WP_REST_Posts_Controller',
'map_meta_cap' => true,
'capabilities' => array(
'publish_posts' => $capability,
'edit_posts' => $capability,
'edit_others_posts' => $capability,
'delete_posts' => $capability,
'delete_others_posts' => $capability,
'read_private_posts' => $capability,
'edit_post' => 'edit_feedzy_category',
'read_post' => 'read_feedzy_category',
'delete_post' => 'delete_feedzy_category',
'edit_posts' => 'edit_feedzy_categories',
'edit_others_posts' => 'edit_others_feedzy_categories',
'publish_posts' => 'publish_feedzy_categories',
'read_private_posts' => 'read_private_feedzy_categories',
),
);
$args = apply_filters( 'feedzy_post_type_args', $args );
register_post_type( 'feedzy_categories', $args );
}

/**
* Only allow admin to modify or delete categories.
*
* @return void
*/
public function register_admin_capabilities() {
$admin_role = get_role( 'administrator' );
$admin_role->add_cap( 'edit_feedzy_category' );
$admin_role->add_cap( 'read_feedzy_category' );
$admin_role->add_cap( 'delete_feedzy_category' );
$admin_role->add_cap( 'edit_feedzy_categories' );
$admin_role->add_cap( 'edit_others_feedzy_categories' );
$admin_role->add_cap( 'publish_feedzy_categories' );
$admin_role->add_cap( 'read_private_feedzy_categories' );
}

/**
* Method to add a meta box to `feedzy_categories`
* custom post type.
Expand Down
1 change: 1 addition & 0 deletions includes/feedzy-rss-feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ private function define_admin_hooks() {
self::$instance->loader->add_action( 'admin_init', $plugin_ui, 'register_init' );

self::$instance->loader->add_action( 'wp_head', $plugin_ui, 'add_feedzy_global_style', 10, 1 );
self::$instance->loader->add_action( 'admin_init', self::$instance->admin, 'register_admin_capabilities' );
self::$instance->loader->add_action( 'init', self::$instance->admin, 'register_post_type' );
self::$instance->loader->add_action( 'save_post', self::$instance->admin, 'save_feedzy_post_type_meta', 1, 2 );
self::$instance->loader->add_action( 'feedzy_pre_http_setup', self::$instance->admin, 'pre_http_setup', 10, 1 );
Expand Down
Loading