Search code examples
phpwordpresswordpress-rest-apijwt

rest_cannot_create for none admin wordpress api v2


this is error

i use jwt authentication plugin

# BEGIN WordPress
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
RewriteBase /badamsite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /badamsite/index.php [L]
</IfModule>

# END WordPress

and this error

 {
        "code": "rest_cannot_create",
        "message": "با عرض پوزش، شما اجازهٔ ایجاد نوشته با این نام کاربری را ندارید. ",
        "data": {
            "status": 403
        }
    }

enter image description here

but when I send request with administator it work ):

enter image description here


Solution

  • use this code instead of above in

    .htaccess

    file

    # BEGIN WordPress
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
    RewriteBase /badamsite/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /badamsite/index.php [L]
    </IfModule>
    
    # END WordPress