true ), $caps, array( 'edit_posts' => true ) ) ); } } /** * The role => capabilities the plugin grants, additively. Full access * (including the R1 admin-menu-page caps) for Administrator/ * SEO-менеджер; content+audit access for Editor and Author (their own * posts, scoped by edit_post at the REST layer) — audit mirrors * CONTENT_CAPABILITY's existing scope, per the R1 plan sign-off. * * @return array Role slug => capabilities to add. */ public static function capability_map(): array { $full = array( self::CAPABILITY, self::CONTENT_CAPABILITY, self::MANAGE_CAPABILITY, self::AUDIT_CAPABILITY, self::SETTINGS_CAPABILITY, ); return array( 'administrator' => $full, 'seo_manager' => $full, 'editor' => array( self::CONTENT_CAPABILITY, self::AUDIT_CAPABILITY ), 'author' => array( self::CONTENT_CAPABILITY, self::AUDIT_CAPABILITY ), ); } /** * Additively grants the plugin's capabilities to their roles. Uses * WP_Role::add_cap, which is idempotent and never removes an existing * capability — so re-running never revokes access, and a site owner * who has hand-tuned role assignments keeps them. Runs on activation * and, via maybe_upgrade_caps(), once per CAPS_VERSION bump on sites * that predate a change. */ public static function assign_capabilities() { foreach ( self::capability_map() as $role_slug => $capabilities ) { $role = get_role( $role_slug ); if ( ! $role ) { continue; } foreach ( $capabilities as $capability ) { if ( ! $role->has_cap( $capability ) ) { $role->add_cap( $capability ); } } } update_option( self::CAPS_VERSION_OPTION, self::CAPS_VERSION ); } /** * Re-applies the additive capability grants once per CAPS_VERSION on * already-active sites (activation only fires once, and existing sites * never re-run activate()). Hooked to plugins_loaded. Safe to call on * every request — it no-ops when the stored revision is current. */ public static function maybe_upgrade_caps() { if ( get_option( self::CAPS_VERSION_OPTION ) === self::CAPS_VERSION ) { return; } self::assign_capabilities(); } /** * Seeds the plugin's default settings option if it doesn't already exist. */ protected static function set_default_options() { add_option( 'abds_seo_settings', array( 'migration_completed' => false, 'ai_provider' => '', 'ai_api_key_encrypted' => '', 'keep_data_on_uninstall' => true, ) ); } }