Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1484441

    Dear support members, hi @Ismael,

    in 2021 I got a helpful piece of code that is misbehaving in the latest version of the theme right now. See this thread and post #858672.

    It ist still working to load the ALB for defined user roles (in this example editor and administrator), while the option in the theme settings is set to restrict the ALB only for admins:

    function ava_enable_alb_for_editor() {
    	add_filter('avf_allow_drag_drop', 'avia_disable_alb_drag_drop_mod', 40, 1);
    }
    add_action('init', 'ava_enable_alb_for_editor');
    
    function avia_disable_alb_drag_drop_mod( $disable )
    {
        $user = wp_get_current_user();
        $allowed_roles = array('editor', 'administrator', 'author');
    	$check = array_intersect( $allowed_roles, $user->roles );
    
    	if( ! empty( $check ) )
    	{
    		$disable = avia_get_option('lock_alb', 'disabled') != "lock_alb" ? true : false;
    	}
    
    	return $disable;
    }

    I can access the ALB as administrator and as editor, so this part of the code is alright. Perfect! But as editor I can’t load a template from the template dropdown in the upper right corner. Everything else is editable and finde, but as I want to load an ALB template I get an error message:

    An error has occurred
    Error retrieving content – please reload the page and try again

    Seems to be a rights problem. If I delete the code above from functions.php I can’t access the ALB as editor. If I furthermore toggle the option to access the ALB for everybody I can use the ALB as editor and load ALB templates from the dropdown. But: I want only admins and editors to use ALB (and ALB templates).

    Any ideas why the behaviour of the code changed and I can’t access the ALB templates anymore?

    I appreciate your help!

    Kind regards,
    Daniel

    #1484477

    Hey Daniel,

    Thank you for the inquiry.

    Did you try the modified code or ava_enable_alb_for_editor function from the previous thread?

    function ava_enable_alb_for_editor() {
    	remove_filter('avf_allow_drag_drop', 'avia_disable_alb_drag_drop', 30, 1);
    	add_filter('avf_allow_drag_drop', 'avia_disable_alb_drag_drop_mod', 40, 1);
    }
    add_action('init', 'ava_enable_alb_for_editor');
    

    Best regards,
    Ismael

    #1484486

    Hi Ismael,

    see your post #1276219. I asked in 2021 because the line remove_filter destroys the code and again everyone is able to use ALB. You suggested to delete the first line and in this way it worked for years. And it still does, but right now the users besides administrators can’t access the ALB templates from the dropdown.

    And they even get the error message when I add the remove_filter line to the code. It is like that:

    With remove_filter: Everyone can use ALB exept templates
    Without remove_filter: Only the user roles from the arry can use ALB exept templates

    Seems as if there are certain rights necessary to use the templates and those rights aren’t granted with the function. What do you think?

    Cheers,
    Daniel

    #1484512

    Hi,

    Thank you for the update.

    In enfold/config-templatebuilder/avia-template-builder/php/class-save-buildertemplate.php file, the aviaSaveBuilderTemplate methods have a permission check that only allows users with the edit_posts capability to interact with the builder templates.

    if( ! current_user_can( 'edit_posts' ) )
    			{
    				die();
    			}

    Please make sure that the Editor role has the capability to “edit_posts”.

    https://wordpress.org/documentation/article/roles-and-capabilities/#edit_posts

    If the issue persists, post the login details for an admin and editor account in the private field so we can check the issue further.

    Best regards,
    Ismael

    #1484532

    Hi Ismael,

    I do have the problem on multiple installs right now. The editor can “edit_posts” and I still get the error …

    You find the login details in private.

    The settings are:
    • Deactivated ALB for everyone exept admin
    • Code in functions.php to allow it for admin AND editor
    • Without “remove_filter” because change in 2021 (see above)
    • Both have “edit_posts” capability
    • Error occurs only in Enfold 7

    Hope you find a solution. Thanks in advance!

    Best regards,
    Daniel

    #1484602

    Hi,

    I think the code you need is:

    
    add_filter('avf_allow_drag_drop', 'avia_disable_alb_drag_drop_mod', 40, 1);
    
    function avia_disable_alb_drag_drop_mod( $disable )
    {
        $user = wp_get_current_user();
        $allowed_roles = array('editor', 'administrator', 'author');
    	$check = array_intersect( $allowed_roles, $user->roles );
    
    	if( ! empty( $check ) )
    	{
    		$disable = avia_get_option('lock_alb', 'disabled') != "lock_alb" ? true : false;
    	}
    
    	return $disable;
    }
    

    Can you check this please.

    Best regards,
    Günter

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.