• Resolved woodypad

    (@woodypad)


    Hello,
    I was trying to limit changes for a role.
    As soon as I saved, it prevented me from logging in as an administrator,
    I can no longer access the Snippets codes that I had created, and also disappeared from the menu.
    The plugin remained in the plugin list, but if I try to log in they click on “Snippets”, this message is returned on a blank page.`

    Sorry, you are not allowed to access this page.

    Is there a way to undo the last change, so as to save all the other codes entered?

    Thank you

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Code Snippets checks for the manage_options capability when determining who can access the plugin. Resetting the administrator role so it once again has that capability would perhaps be the best way to fix this.

    Thread Starter woodypad

    (@woodypad)

    OK thank you!

    But if I wanted the codes of a “Snippets” page to be active only for a user role what should I write?
    Thank you

    Plugin Author Shea Bunge

    (@bungeshea)

    You can reassign the capability that Code Snippets checks for using a snippet:

    add_filer( 'code_snippets_cap', function () {
    	return 'some_capability';
    } );

    Just need to replace some_capability with the capability you want to use, either one that comes with WordPress or a custom one you have created.

    Thread Starter woodypad

    (@woodypad)

    for example if you wanted to insert some css in admin,
    should I write like this?
    Thank you

    
    add_filer( 'code_snippets_cap', function () {
    	return 'some_capability';
    } );
    add_action( 'admin_head', function () { ?>
    
    <style>
    
    
    Plugin Author Shea Bunge

    (@bungeshea)

    The snippet I posted doesn’t need to be included in everything you write. Add it as its own snippet, and it will work for the entire site.

    Thread Starter woodypad

    (@woodypad)

    sorry for me it’s not clear yet.
    What I try to do is activate some snippets by user role only.

    Plugin Author Shea Bunge

    (@bungeshea)

    Oh, I see. Okay, here’s an example you might use if you wanted to add some CSS to the admin area for a particular capability:

    add_action( 'admin_head', function () {
    	if ( ! current_user_can( 'do_something' ) return;
    
    	?>
    	<style>
    		
    	/* CSS code goes here */
    
    	</style>
    	<?php
    } );

    Replace do_something with the relevant capability. If you would prefer to check based on role instead, see my answer to this question.

    Thread Starter woodypad

    (@woodypad)

    Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Not allowed to access this page’ is closed to new replies.