has_cap($cap)) $role->add_cap($cap); } } update_option('blyzer_caps_version', self::CAPS_VERSION, true); } public static function removeCaps(): void { foreach (wp_roles()->role_objects as $role) { foreach (self::CAPS as $cap) { if ($role->has_cap($cap)) $role->remove_cap($cap); } } delete_option('blyzer_caps_version'); } public static function maybeAddCaps(): void { if (get_option('blyzer_caps_version') !== self::CAPS_VERSION) self::addCaps(); } public static function register(): void { add_action('init', [self::class, 'maybeAddCaps'], 5); add_action('before_delete_post', function ($postId) { if (get_post_type((int) $postId) === 'blyzer_event') Api::deleteAll((int) $postId); }); add_action('init', function () { register_post_type('blyzer_event', [ 'labels' => [ 'name' => __('Blyzer Events', 'blyzer-events'), 'singular_name' => __('Event', 'blyzer-events'), 'add_new' => __('Add New', 'blyzer-events'), 'add_new_item' => __('Add New Event', 'blyzer-events'), 'edit_item' => __('Edit Event', 'blyzer-events'), 'new_item' => __('New Event', 'blyzer-events'), 'view_item' => __('View Event', 'blyzer-events'), 'search_items' => __('Search Events', 'blyzer-events'), 'not_found' => __('No events found.', 'blyzer-events'), 'not_found_in_trash' => __('No events found in Trash.', 'blyzer-events'), 'all_items' => __('All Events', 'blyzer-events'), 'menu_name' => __('Blyzer Events', 'blyzer-events'), ], 'public' => false, 'show_ui' => true, 'show_in_menu' => true, 'menu_icon' => 'dashicons-awards', 'supports' => ['title'], 'exclude_from_search' => true, 'publicly_queryable' => false, 'capability_type' => ['blyzer_event', 'blyzer_events'], 'map_meta_cap' => true, ]); }); } }