Forum Replies Created
-
AuthorPosts
-
VladimirKeymaster
OK. I made own test.
Set for the post ID=3267 at the post editor these values:
– View Access: Prohibit view;
– For Users: All visitors (logged in or not);
– Action: Return HTTP 404 error.As a result the post is not accessible for not logged-in and logged-in users.
Then I added the code:add_filter( 'ure_content_view_access_data_for_role', 'my_content_view_access_data_for_role', 10, 2 ); function my_content_view_access_data_for_role( $restriction, $role_id ) { if ( $role_id=='author' ) { $restriction['access_model'] = 2; $restriction['access_error_action'] = 1; $restriction['data']['posts'] = array( 3267 ); // posts/pages ID list } return $restriction; }
The post is not accessible for not logged-in and logged-in users with any role except administrator and author.
VladimirKeymasterHi,
I need first to allow “All user login” to view these Posts
Why do you need this? Did you try to prohibit view for all user login for those posts at the post level and overwrite the condition via hook for select role(s) only? I mean restriction define at the hook will be final and overwrite one which define earlier at the post editor.
VladimirKeymasterHi,
Yes, it’s possible. Just select suitable access model:
$restriction[‘access_model’] = 1; // Prohibit view
and
$restriction[‘access_model’] = 2; // Allow view$restriction[‘data’][‘posts’] = array( 10, 20, 30 ); // posts/pages/custom post types ID list
Post ID array works for any post type: as WordPress built-in posts and page, as any custom post type.
VladimirKeymasterWhile code version above work for the user with ‘user-manager’ role only, this version works for all users including one with ‘administrator’ role:
add_filter('ure_show_additional_capabilities_section', 'ure_show_additional_capabilities_section'); function ure_show_additional_capabilities_section( $show ) { /* Remove comment if do not wish to apply this for administrators also $lib = URE_Lib::get_instance(); if ($lib->is_super_admin()) { return $show; } */ return false; }
04/01/2021 at 10:24 in reply to: Gravity Forms Access: Can’t view second page in backend form lists #7242VladimirKeymaster“Popup Builder” plugin has own permissions settings. You have to add web_master role to the list of roles, for which “Popup Builder” is available at its “Settings” page.
04/01/2021 at 09:14 in reply to: Gravity Forms Access: Can’t view second page in backend form lists #7241VladimirKeymasterHi,
Is it possible to look at your site with admin permissions?
If Yes, send URL and credentials to support[at-sign] role-editor.comVladimirKeymasterYes, ‘block’ rule has a higher priority. If post has few categories assigned and at least 1 of them is prohibited for view to the current user role – user can not see this post.
Look if you can to re-structure your categories to exclude the mentioned overlapping.VladimirKeymasterHi,
It’s possible. Code below redefines gTranslate menu with ‘manage_options’ capability:
add_action('plugins_loaded', 'redefine_gtranslate_menu'); function redefine_gtranslate_menu() { remove_action('admin_menu', array('GTranslate', 'admin_menu'), 10 ); add_action('admin_menu', 'replace_gtranslate_menu' ); } function replace_gtranslate_menu() { add_options_page(__('GTranslate Options', 'gtranslate'), 'GTranslate', 'manage_options', 'gtranslate_options', array('GTranslate', 'options') ); }
VladimirKeymasterHi Wolfgang,
You can try this version:
add_filter( 'allowed_block_types', 'misha_allowed_block_types', 10, 2 ); function misha_allowed_block_types( $allowed_blocks, $post ) { $user = wp_get_current_user(); if ( in_array('administrator', $user->roles ) ) { // Do not change the list of default blocks for user with administrator role return $allowed_blocks; } if ( in_array('author', $user->roles ) ) { // Customize the list of allowed blockes for user with role author $allowed_blocks = array( 'core/image', 'core/paragraph', 'core/heading', 'core/list' ); return $allowed_blocks; } return $allowed_blocks; }
VladimirKeymasterHi,
Try beta version 4.58.3.b1. It’s available from the Download page after login and contains related fix:
Fix: Content View Restrictions add-on: Posts with “Show 404 HTTP error” option were available via AJAX requests.
The single .php file was changed:
pro/includes/classes/content-view-restrictions-posts-list.php
.VladimirKeymasterThanks. I got plugin copy. I will look what is going wrong.
VladimirKeymasterHi,
Send me the link to plugin (with ajax related features) from wordpress.org/plugins in order I can test this issue.
VladimirKeymasterThis script placed into functions.php file of the active theme of added as a Must Use plugin will redirect not logged-in user to the wp-login.php page:
// Block URLs from the list for not logged-in users add_action('wp_head', 'your_prefix_protect_urls', 110); function your_prefix_protect_urls() { if ( is_user_logged_in() ) { return; } $blocked_paths = array( '/wp-test2/category/post-category-1/' ); $redirect = false; $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); foreach( $blocked_paths as $blocked_path ) { if ( $blocked_path==$path ) { $redirect = true; break; } } if ( !$redirect ) { return; } // URL where do you wish redirect not logged-in user $redirect_to = '/wp-test2/wp-login.php'; if (headers_sent()) { ?> <script> document.location.href = '<?php echo $redirect_to; ?>'; </script> <?php } else { wp_redirect( $redirect_to ); } die; }
Just replace blocked path from ‘/wp-test2/category/post-category-1/’ to yours, like ‘/cat/tutoriels/’, and $redirect_to value to from ‘/wp-test2/wp-login.php’ to the path/URL of your login page.
VladimirKeymasterYou should not input this code anywhere. I took it from Amelia plugin source code, just to show why “Amelia” menu is not available for the user with custom role.
Solution, grant to a user with shop_manager role the 2nd role – wpamelia-manager. Such user will get access to ‘Amelia’ menu after that.
VladimirKeymasterYou have to take into account that Amelia plugin create its admin menu “Amelia” with submenu items only for user who has at least one of Amelia’s user roles or who is a superadmin:
$ameliaRole = UserRoles::getUserAmeliaRole(wp_get_current_user()); // Init menu if user is logged in with amelia role if (in_array($ameliaRole, ['admin', 'manager', 'provider', 'customer'])) { if ($ameliaRole === 'admin') { ErrorService::setNotices(); } $menuItems = new Menu($settingsService);
where:
– ‘admin’=’administrator’ WordPress role;
– ‘manager’=’wpamelia-manager’;
– ‘provider’=’wpamelia-provider’;
– ‘customer’=’wpamelia-customer’.
So you can use your own custom user role but grant it to a user together with one of Amelia own user roles from the list above. -
AuthorPosts