Similar to the [private] shortcode that we created back in the Creating a new enclosing shortcode recipe in Chapter 2, Plugin Framework Basics, the new [paid] shortcode that this recipe puts in place can be used by content creators to identify one or more sections of a post or page that can only be viewed by users whose user level is set as a paid member.
To do this, our shortcode implementation first checks whether the visitor is logged in. If that is the case, it further validates the user by asking WordPress to provide data on the current user, then uses the user ID to retrieve the user_level metadata that we stored in the previous recipes in this chapter. Alternatively, it checks if the user is a site administrator by using the current_user_can WordPress function and specifying 'activate_plugins' as the argument, since only administrators can perform this action. If all of these conditions are met, the enclosed post content will be displayed. Otherwise, a message will be shown to indicate that users must be paid members to see this content.