How it works...

In this recipe, we restricted a post and assigned access only to a single user. We started the process by adding a meta box into the post create/edit screen in step 2. We used an add_meta_boxes action with a wpccp_chapter6_user_meta_box callback function.

Inside the function, we used a permission check with a current_user_can('manage_options') function to make sure only the administrator was accessing this setting. Inside the condition, we called the built-in add_meta_box function to add a custom meta box to the post create/edit screen. Let's take a look at the parameters of this function.

  • Id—This is the unique ID for the meta box. This should be unique within all plugins and themes. So, you should add a unique ID with a ...

Get WordPress 5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.