Skip to main content
Code formatting improvements, fix grammar error in word 'contributor'
Source Link

I have a custom post type named project which has

'capability_type' => 'post'

while registering using register_post_type.

In my theme files and also functions.php file, I have situations where I should check if the project to be edited is authored by the user or not.

So I use this:

if ( !current_user_can( 'edit_post', $porject_id ) ) return;

where $project_id is post id of the project to be edited.

For example I have a page template named single_project.php where I can show single posts in project post type to users and I want these people can see each project single page:

  1. administrators
  2. editors
  3. the contributercontributor (post author)

but using the above code, It is ok with administrators and editors, while not for the contributercontributor himself!

When I use:

var_dump( current_user_can( 'edit_post', $project_id ) )
var_dump( current_user_can( 'edit_post', $project_id ) );

with the contributercontributor logged-in account, it returns

false

false, while this:

var_dump( current_user_can( 'edit_posts' ) )` (with trailing `'s'`)
var_dump( current_user_can( 'edit_posts' ) ); // (with trailing 's')

returns true (but for every post, not just does for him).

true (but for every post, not just does for him).

Any help with this?

I have a custom post type named project which has

'capability_type' => 'post'

while registering using register_post_type.

In my theme files and also functions.php file, I have situations where I should check if the project to be edited is authored by the user or not.

So I use this:

if ( !current_user_can( 'edit_post', $porject_id ) ) return;

where $project_id is post id of the project to be edited.

For example I have a page template named single_project.php where I can show single posts in project post type to users and I want these people can see each project single page:

  1. administrators
  2. editors
  3. the contributer (post author)

but using the above code, It is ok with administrators and editors, while not for the contributer himself!

When I use:

var_dump( current_user_can( 'edit_post', $project_id ) )

with the contributer logged-in account, it returns

false

while

var_dump( current_user_can( 'edit_posts' ) )` (with trailing `'s'`)

returns

true (but for every post, not just does for him).

Any help with this?

I have a custom post type named project which has

'capability_type' => 'post'

while registering using register_post_type.

In my theme files and also functions.php file, I have situations where I should check if the project to be edited is authored by the user or not.

So I use this:

if ( !current_user_can( 'edit_post', $porject_id ) ) return;

where $project_id is post id of the project to be edited.

For example I have a page template named single_project.php where I can show single posts in project post type to users and I want these people can see each project single page:

  1. administrators
  2. editors
  3. the contributor (post author)

but using the above code, It is ok with administrators and editors, while not for the contributor himself!

When I use:

var_dump( current_user_can( 'edit_post', $project_id ) );

with the contributor logged-in account, it returns false, while this:

var_dump( current_user_can( 'edit_posts' ) ); // (with trailing 's')

returns true (but for every post, not just does for him).

Any help with this?

Tweeted twitter.com/StackWordPress/status/1257007036887371776
added 25 characters in body
Source Link
WordPress Speed
  • 2.3k
  • 3
  • 19
  • 33

I have a custom post type named ÷project÷ which has 'capability_type' => 'post'project which has

'capability_type' => 'post'

while registering using ÷register_post_type÷register_post_type.

inIn my theme files and also functions.phpfunctions.php file, I have situations where I should check if the project to be edited is authored by the user or not. so

So I use this:

if ( !current_user_can( 'edit_post', $porject_id ) ) return;

where $project_id is post id of the project to be edited. for

For example I have a page template named single_project.php where I can show single posts in project post type to users and I want these people can see each project single page:

  1. administrators
  2. editors
  3. the contributer (post author)

but using the above code, It is ok with administrators and editors, while not for the contributer himself!

whenWhen I use var_dump( current_user_can( 'edit_post', $project_id ) ):

var_dump( current_user_can( 'edit_post', $project_id ) )

with the contributer logged-in account, it returns false,

false

while var_dump( current_user_can( 'edit_posts' ) ) (with trailing 's')

var_dump( current_user_can( 'edit_posts' ) )` (with trailing `'s'`)

returns true (but for every post, not just does for him).

true (but for every post, not just does for him).

Any help with this ??! Any help with this?

I have a custom post type named ÷project÷ which has 'capability_type' => 'post' while registering using ÷register_post_type÷.

in my theme files and also functions.php file, I have situations where I should check if the project to be edited is authored by the user or not. so I use this:

if ( !current_user_can( 'edit_post', $porject_id ) ) return;

where $project_id is post id of the project to be edited. for example I have a page template named single_project.php where I can show single posts in project post type to users and I want these people can see each project single page:

  1. administrators
  2. editors
  3. the contributer (post author)

but using the above code, It is ok with administrators and editors, while not for the contributer himself!

when I use var_dump( current_user_can( 'edit_post', $project_id ) ) with the contributer logged-in account, it returns false, while var_dump( current_user_can( 'edit_posts' ) ) (with trailing 's') returns true (but for every post, not just does for him).

Any help with this ??!

I have a custom post type named project which has

'capability_type' => 'post'

while registering using register_post_type.

In my theme files and also functions.php file, I have situations where I should check if the project to be edited is authored by the user or not.

So I use this:

if ( !current_user_can( 'edit_post', $porject_id ) ) return;

where $project_id is post id of the project to be edited.

For example I have a page template named single_project.php where I can show single posts in project post type to users and I want these people can see each project single page:

  1. administrators
  2. editors
  3. the contributer (post author)

but using the above code, It is ok with administrators and editors, while not for the contributer himself!

When I use:

var_dump( current_user_can( 'edit_post', $project_id ) )

with the contributer logged-in account, it returns

false

while

var_dump( current_user_can( 'edit_posts' ) )` (with trailing `'s'`)

returns

true (but for every post, not just does for him).

Any help with this?

added 5 characters in body
Source Link
WordPress Speed
  • 2.3k
  • 3
  • 19
  • 33

I have a custom post type named project÷project÷ which has 'capability_type' => 'post' while registering using register_post_type÷register_post_type÷.

in my theme files and also functions.php file, I have situations where I should check if the project to be edited is authored by the user or not. so I use this:

if ( !current_user_can( 'edit_post', $porject_id ) ) return;

where $project_id is post id of the project to be edited. for example I have a page template named single_project.php where I can show single posts in project post type to users and I want these people can see each project single page:

  1. administrators
  2. editors
  3. the contributer (post author)

but using the above code, It is ok with administrators and editors, while not for the contributer himself!

when I use var_dumvar_dump( current_user_can( 'edit_post', $project_id ) ) with the contributer logged-in account, it returns false, while var_dump( current_user_can( 'edit_posts' ) ) (with trailing 's') returns true (but for every post, not just does for him).

Any help with this ??!

I have a custom post type named project which has 'capability_type' => 'post' while registering using register_post_type.

in my theme files and also functions.php file, I have situations where I should check if the project to be edited is authored by the user or not. so I use this:

if ( !current_user_can( 'edit_post', $porject_id ) ) return;

where $project_id is post id of the project to be edited. for example I have a page template named single_project.php where I can show single posts in project post type to users and I want these people can see each project single page:

  1. administrators
  2. editors
  3. the contributer (post author)

but using the above code, It is ok with administrators and editors, while not for the contributer himself!

when I use var_dum( current_user_can( 'edit_post', $project_id ) ) with the contributer logged-in account, it returns false, while var_dump( current_user_can( 'edit_posts' ) ) (with trailing 's') returns true (but for every post, not just does for him).

Any help with this ??!

I have a custom post type named ÷project÷ which has 'capability_type' => 'post' while registering using ÷register_post_type÷.

in my theme files and also functions.php file, I have situations where I should check if the project to be edited is authored by the user or not. so I use this:

if ( !current_user_can( 'edit_post', $porject_id ) ) return;

where $project_id is post id of the project to be edited. for example I have a page template named single_project.php where I can show single posts in project post type to users and I want these people can see each project single page:

  1. administrators
  2. editors
  3. the contributer (post author)

but using the above code, It is ok with administrators and editors, while not for the contributer himself!

when I use var_dump( current_user_can( 'edit_post', $project_id ) ) with the contributer logged-in account, it returns false, while var_dump( current_user_can( 'edit_posts' ) ) (with trailing 's') returns true (but for every post, not just does for him).

Any help with this ??!

Source Link
WordPress Speed
  • 2.3k
  • 3
  • 19
  • 33
Loading