| @@ -13,69 +13,11 @@ | ||
| 13 | 13 | public $database; |
| 14 | 14 | |
| 15 | 15 | public function __construct( Database $database ) { |
| 16 | 16 | $this->database = $database; |
| 17 | - | |
| 18 | - $this->assign_admin_capabilities(); //will run when it is called | |
| 19 | 17 | } |
| 20 | 18 | |
| 21 | 19 | /** |
| 22 | - * Ensure the administrator role always has every BetterDocs capability. | |
| 23 | - * | |
| 24 | - * Capabilities are normally granted on activation via Install::activate() -> | |
| 25 | - * setup(). But when BetterDocs is installed/activated silently by another | |
| 26 | - * plugin (e.g. Essential Addons from its Integrations screen, or BetterDocs | |
| 27 | - * Pro), the activation hook does not fire, so setup() never runs and the | |
| 28 | - * administrator never receives caps like edit_docs, edit_docs_settings or | |
| 29 | - * read_docs_analytics. That hides most of the BetterDocs admin menu (leaving | |
| 30 | - * only Quick Setup, gated by the core `delete_users` cap, and FAQ Builder) | |
| 31 | - * and makes the pages return "Sorry, you are not allowed to access this page." | |
| 32 | - * | |
| 33 | - * This self-heals that on every request: any missing admin cap is added back. | |
| 34 | - * add_cap() is only called for caps the role lacks, so once healed there are | |
| 35 | - * no further DB writes. | |
| 36 | - * | |
| 37 | - * @return void | |
| 38 | - */ | |
| 39 | - public function assign_admin_capabilities() { | |
| 40 | - if ( ! current_user_can( 'administrator' ) ) { | |
| 41 | - return; | |
| 42 | - } | |
| 43 | - | |
| 44 | - $capabilities = $this->defaults_capabilities(); | |
| 45 | - $admin_caps = isset( $capabilities['administrator'] ) ? $capabilities['administrator'] : []; | |
| 46 | - | |
| 47 | - if ( empty( $admin_caps ) ) { | |
| 48 | - return; | |
| 49 | - } | |
| 50 | - | |
| 51 | - $administrator = get_role( 'administrator' ); | |
| 52 | - if ( ! $administrator ) { | |
| 53 | - return; | |
| 54 | - } | |
| 55 | - | |
| 56 | - foreach ( $admin_caps as $cap ) { | |
| 57 | - if ( ! $administrator->has_cap( $cap ) ) { | |
| 58 | - $administrator->add_cap( $cap ); | |
| 59 | - } | |
| 60 | - } | |
| 61 | - } | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * Assign FAQ Builder Capability To The Admin | |
| 65 | - * | |
| 66 | - * @deprecated Use assign_admin_capabilities() which grants the full admin | |
| 67 | - * capability set (including read_faq_builder). Kept for backward | |
| 68 | - * compatibility with any external callers. | |
| 69 | - */ | |
| 70 | - public function assgin_faq_builder_capability_to_admin() { | |
| 71 | - if( current_user_can('administrator') && ! current_user_can('read_faq_builder') ) { // if the current user is admin, and current user does not have faq menu visibility option, then assign the faq menu visibility capability | |
| 72 | - $current_user_role = get_role('administrator'); | |
| 73 | - $current_user_role->add_cap('read_faq_builder'); | |
| 74 | - } | |
| 75 | - } | |
| 76 | - | |
| 77 | - /** | |
| 78 | 20 | * Default Roles Capabilities |
| 79 | 21 | * |
| 80 | 22 | * @var array |
| 81 | 23 | */ |
| @@ -105,10 +47,9 @@ | ||
| 105 | 47 | 'delete_knowledge_base_terms', |
| 106 | 48 | |
| 107 | 49 | // Settings and Analytics Related caps |
| 108 | 50 | 'edit_docs_settings', |
| 109 | - 'read_docs_analytics', | |
| 110 | - 'read_faq_builder' | |
| 51 | + 'read_docs_analytics' | |
| 111 | 52 | ], |
| 112 | 53 | 'editor' => [ |
| 113 | 54 | // post type related caps |
| 114 | 55 | 'edit_docs', |
| @@ -176,7 +117,7 @@ | ||
| 176 | 117 | $wp_roles->add_cap( $role, $cap ); |
| 177 | 118 | } |
| 178 | 119 | } |
| 179 | 120 | |
| 180 | - $this->database->save( '_betterdocs_caps_initialized', ! $remove ); | |
| 121 | + $this->database->get( '_betterdocs_caps_initialized', ! $remove ); | |
| 181 | 122 | } |
| 182 | 123 | } |