0
0
Wordpressframework~10 mins

User capability checks in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the current user can edit posts.

Wordpress
<?php if (current_user_can([1])) { echo 'User can edit posts'; } ?>
Drag options to blanks, or click blank then click option'
A'edit_posts'
B'manage_options'
C'publish_posts'
D'delete_posts'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'manage_options' which is for admin settings.
Using 'publish_posts' which checks publishing rights, not editing.
2fill in blank
medium

Complete the code to check if the current user can delete pages.

Wordpress
<?php if (current_user_can([1])) { echo 'User can delete pages'; } ?>
Drag options to blanks, or click blank then click option'
A'edit_pages'
B'publish_pages'
C'delete_pages'
D'read_pages'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'edit_pages' which checks editing, not deleting.
Using 'publish_pages' which checks publishing rights.
3fill in blank
hard

Fix the error in the code to correctly check if the user can manage options.

Wordpress
<?php if (current_user_can([1])) { echo 'User can manage options'; } ?>
Drag options to blanks, or click blank then click option'
A'manage_options'
B'manage_option'
C'manage_optionss'
D'manage'
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling the capability string.
Using singular form instead of plural.
4fill in blank
hard

Fill both blanks to check if the user can edit a specific post with ID 42.

Wordpress
<?php if (current_user_can([1], [2])) { echo 'User can edit this post'; } ?>
Drag options to blanks, or click blank then click option'
A'edit_post'
B42
C'edit_posts'
D24
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'edit_posts' which checks general post editing, not a specific post.
Using wrong post ID.
5fill in blank
hard

Fill all three blanks to check if the user can publish a post of type 'book'.

Wordpress
<?php if (current_user_can([1], [2], [3])) { echo 'User can publish book'; } ?>
Drag options to blanks, or click blank then click option'
A'publish_post'
B'book'
C0
D'publish_books'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish_post' which is singular and generic.
Using wrong post type string.
Omitting the third argument.