', self::getAccessCapability(), WPACU_PLUGIN_ID . '_go_pro', function() {} ); // [/wpacu_lite] // Add "Asset CleanUp Pro" Settings Link to the main "Settings" menu within the Dashboard // For easier navigation $GLOBALS['submenu']['options-general.php'][] = array( WPACU_PLUGIN_TITLE, self::getAccessCapability(), esc_url(admin_url( 'admin.php?page=' . WPACU_PLUGIN_ID . '_settings')), WPACU_PLUGIN_TITLE, ); // Rename first item from the menu which has the same title as the menu page $GLOBALS['submenu'][self::$_slug][0][0] = esc_attr__('Getting Started', 'wp-asset-clean-up'); } /** * @return bool */ public static function userCanManageAssets() { if (is_super_admin()) { return true; // For security reasons, super admins will always be able to access the plugin's settings } // Has self::$_capability been changed? Just user current_user_can() if (self::getAccessCapability() !== self::$_capability) { return current_user_can(self::getAccessCapability()); } // self::$_capability default value: "administrator" return current_user_can(self::getAccessCapability()); } /** * @return bool */ public static function isPluginPage() { return isset($_GET['page']) && in_array($_GET['page'], self::$allMenuPages); } /** * Here self::$_capability can be overridden * * @return mixed|void */ public static function getAccessCapability() { return apply_filters('wpacu_access_role', self::$_capability); } /** * @param $actions * @param $post * * @return mixed */ public function editPostRowActions($actions, $post) { // Check for your post type. if ( $post->post_type === 'post' ) { $wpacuFor = 'posts'; } elseif ( $post->post_type === 'page' ) { $wpacuFor = 'pages'; } elseif ( $post->post_type === 'attachment' ) { $wpacuFor = 'media-attachment'; } else { $wpacuFor = 'custom-post-types'; } $postTypeObject = get_post_type_object($post->post_type); if ( ! (isset($postTypeObject->public) && $postTypeObject->public == 1) ) { return $actions; } if ( ! in_array(get_post_status($post), array('publish', 'private')) ) { return $actions; } // Do not show the management link to specific post types that are marked as "public", but not relevant such as "ct_template" from Oxygen Builder if (in_array($post->post_type, MetaBoxes::$noMetaBoxesForPostTypes)) { return $actions; } // Build your links URL. $url = esc_url(admin_url( 'admin.php?page=wpassetcleanup_assets_manager' )); // Maybe put in some extra arguments based on the post status. $edit_link = add_query_arg( array( 'wpacu_for' => $wpacuFor, 'wpacu_post_id' => $post->ID ), $url ); // Only show it to the user that has "administrator" access, and it's in the following list (if a certain list of admins is provided) // "Settings" -> "Plugin Usage Preferences" -> "Allow managing assets to:" if (self::userCanManageAssets() && Main::currentUserCanViewAssetsList()) { /* * You can reset the default $actions with your own array, or simply merge them * here I want to rewrite my Edit link, remove the Quick-link, and introduce a * new link 'Copy' */ $actions['wpacu_manage_assets'] = sprintf( '%2$s', esc_url( $edit_link ), esc_html( __( 'Manage CSS & JS', 'wp-asset-clean-up' ) ) ); } return $actions; } /** * Message to show if the user does not have self::$_capability role and tries to access a plugin's page */ public function pluginPagesAccessDenied() { if ( ! self::isPluginPage() ) { // Not an Asset CleanUp page return; } $userMeta = get_userdata(get_current_user_id()); $userRoles = $userMeta->roles; wp_die( __('Sorry, you are not allowed to access this page.').'

'. sprintf(__('Asset CleanUp requires "%s" role and the ability to activate plugins in order to access its pages.', 'wp-asset-clean-up'), ''.self::getAccessCapability().'').'
'. sprintf(__('Your current role(s): %s', 'wp-asset-clean-up'), implode(', ', $userRoles)).'

'. __('The value (in green color) can be changed if you use the following snippet in functions.php (within your theme/child theme or a custom plugin):').'
'. '

add_filter(\'wpacu_access_role\', function($role) { return \'your_role_here\'; });

'. '

If the snippet is not used, it will default to "administrator".

'. '

Possible values: manage_options, activate_plugins, manager etc.

'. '

Read more: https://wordpress.org/support/article/roles-and-capabilities/#summary-of-roles

', 403 ); } }