{"id":643,"date":"2023-10-22T12:23:12","date_gmt":"2023-10-22T12:23:12","guid":{"rendered":"https:\/\/wpshortcode.org\/?p=643"},"modified":"2023-10-22T12:23:12","modified_gmt":"2023-10-22T12:23:12","slug":"content-control","status":"publish","type":"post","link":"https:\/\/wpshortcode.org\/content-control\/","title":{"rendered":"Content Control Shortcode"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Below, you&#8217;ll find a detailed guide on how to add the <strong>Content Control Shortcode<\/strong> to your WordPress website, including its <strong>parameters<\/strong>, <strong>examples<\/strong>, and <strong>PHP function code<\/strong>. Additionally, we&#8217;ll assist you with common issues that might cause the Content Control Plugin shortcode not to show or not to work correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before starting, here is an overview of the Content Control Plugin and the shortcodes it provides:<\/p>\n\n\n<p>    <div class=\"plugin-info-box\">\n        <div class=\"top-main\">\n            <!-- SVG Image -->\n            <div class=\"plugin-image\">\n                <img decoding=\"async\" src=\"https:\/\/ps.w.org\/content-control\/assets\/icon-128x128.gif?rev=2968535\" alt=\"Plugin Icon\" \/>\n            <\/div>\n            \n            <div class=\"plugin-descriptive-part\">\n                <!-- Plugin Name with Link -->\n\n                    <a class=\"plugin-title\" href=\"https:\/\/wordpress.org\/plugins\/content-control\" target=\"_blank\" rel=\"noopener\">\n                        Content Control &#8211; The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks &amp; More                    <\/a>\n\n\n                <!-- Plugin Description -->\n                <p class=\"plugin-description\">\n                    Content Control is the ultimate plugin for WordPress, allowing you to restrict content, create conditional blocks, and more. Customize your content visibility with ease using this powerful tool.                <\/p>\n            <\/div>\n        <\/div>\n\n        <!-- Rating and Additional Info -->\n        <div class=\"plugin-meta\">\n            <span class=\"plugin-rating\">\n                <span class='stars'>\u2605\u2605\u2605\u2605\u2606<\/span> (486)\n            <\/span>\n            <span class=\"plugin-active-installs\">\n                <strong>Active Installs<\/strong>: 40000+\n            <\/span>\n            <span class=\"plugin-tested\">\n                <strong>Tested with<\/strong>: 6.3.2            <\/span>\n            <span class=\"plugin-php-version\">\n                <strong>PHP Version<\/strong>: 5.6            <\/span>\n        <\/div>\n\n        <!-- List of Included Shortcodes -->\n        <div class=\"plugin-shortcodes\">\n            <strong>Included Shortcodes:<\/strong>\n            <ul>\n                <li>[content_control]<\/li>            <\/ul>\n        <\/div>\n    <\/div>\n    <\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Content Control [content_control] Shortcode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Content Control shortcode is a powerful tool for managing user access in WordPress. It allows fine-tuning of user roles and status.\n\n\n\nThis shortcode lets you define whether a user is &#8216;logged_in&#8217; or &#8216;logged_out&#8217;, specify &#8216;allowed_roles&#8217; and &#8216;excluded_roles&#8217;, and customize the denial message. \n\nThe shortcode also handles deprecated attributes, providing backward compatibility. It can normalize attributes and convert classes to an array for easier processing. \n\nIn essence, it checks if a user meets specific requirements, then displays content accordingly, making it a valuable tool for content control.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode<\/strong>: <code>[content_control]<\/code><\/p>\n\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Parameters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a list of all possible content_control shortcode parameters and attributes:<\/p>\n\n\n<ul>\n<li><code>status<\/code> &#8211; defines if the user is &#8216;logged_in&#8217; or &#8216;logged_out&#8217;<\/li>\n<li><code>allowed_roles<\/code> &#8211; sets the user roles that can view the content<\/li>\n<li><code>excluded_roles<\/code> &#8211; sets the user roles that cannot view the content<\/li>\n<li><code>class<\/code> &#8211; adds custom classes to the container<\/li>\n<li><code>message<\/code> &#8211; displays a message if the user doesn&#8217;t meet the criteria<\/li>\n<\/ul>\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Examples and Usage<\/h3>\n\n\n<p><strong>Basic example<\/strong> &#8211; A shortcode that uses the content control function to display content only to logged-in users.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_control status=\"logged_in\"]Your exclusive content here[\/content_control]<\/code><\/pre>\n\n\n<p><strong>Advanced examples<\/strong><\/p>\n<p>Using the shortcode to display content only to users with specific roles. In this case, the content is only visible to users with the role of &#8216;editor&#8217; or &#8216;administrator&#8217;.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_control status=\"logged_in\" allowed_roles=\"editor, administrator\"]Your exclusive content here[\/content_control]<\/code><\/pre>\n\n\n<p>Using the shortcode to display a custom message to users who do not meet the specified conditions. In this case, the message is displayed to users who are not logged in.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_control status=\"logged_out\" message=\"You must be logged in to view this content.\"]Your exclusive content here[\/content_control]<\/code><\/pre>\n\n\n<p>Using the shortcode to exclude certain user roles from viewing the content. Here, the content is hidden from users with the &#8216;subscriber&#8217; role.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_control status=\"logged_in\" excluded_roles=\"subscriber\"]Your exclusive content here[\/content_control]<\/code><\/pre>\n\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">PHP Function Code<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In case you have difficulties debugging what causing issues with <code>[content_control]<\/code> shortcode, check below the related PHP functions code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode line<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_shortcode( 'content_control', [ $this, 'content_control' ] );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode PHP function<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; light: false; title: ; toolbar: true; notranslate\" title=\"\">\nfunction content_control( $atts, $content = &#039;&#039; ) {\n\t\t\/\/ Deprecated.\n\t\t$deprecated_atts = shortcode_atts( &#91;\n\t\t\t&#039;logged_out&#039; =&gt; null, \/\/ @deprecated 2.0.\n\t\t\t&#039;roles&#039;      =&gt; null, \/\/ @deprecated 2.0.\n\t\t], $atts );\n\n\t\t$atts = shortcode_atts( &#91;\n\t\t\t&#039;status&#039;         =&gt; &#039;logged_in&#039;, \/\/ &#039;logged_in&#039; or &#039;logged_out\n\t\t\t&#039;allowed_roles&#039;  =&gt; null,\n\t\t\t&#039;excluded_roles&#039; =&gt; null,\n\t\t\t&#039;class&#039;          =&gt; &#039;&#039;,\n\t\t\t&#039;message&#039;        =&gt; $this-&gt;container-&gt;get_option( &#039;defaultDenialMessage&#039;, &#039;&#039; ),\n\t\t], $this-&gt;normalize_empty_atts( $atts ), &#039;content_control&#039; );\n\n\t\t\/\/ Handle old args.\n\t\tif ( isset( $deprecated_atts&#91;&#039;logged_out&#039;] ) ) {\n\t\t\t$atts&#91;&#039;status&#039;] = (bool) $deprecated_atts&#91;&#039;logged_out&#039;] ? &#039;logged_out&#039; : &#039;logged_in&#039;;\n\t\t}\n\n\t\tif ( isset( $deprecated_atts&#91;&#039;roles&#039;] ) &amp;&amp; ! empty( $deprecated_atts&#91;&#039;roles&#039;] ) ) {\n\t\t\t$atts&#91;&#039;allowed_roles&#039;] = $deprecated_atts&#91;&#039;roles&#039;];\n\t\t}\n\n\t\t$user_roles = &#91;];\n\t\t$match_type = &#039;any&#039;;\n\n\t\t\/\/ Normalize args.\n\t\tif ( ! empty( $atts&#91;&#039;excluded_roles&#039;] ) ) {\n\t\t\t$user_roles = $atts&#91;&#039;excluded_roles&#039;];\n\t\t\t$match_type = &#039;exclude&#039;;\n\t\t} elseif ( ! empty( $atts&#91;&#039;allowed_roles&#039;] ) ) {\n\t\t\t$user_roles = $atts&#91;&#039;allowed_roles&#039;];\n\t\t\t$match_type = &#039;match&#039;;\n\t\t}\n\n\t\t\/\/ Convert classes to array.\n\t\t$classes = ! empty( $atts&#91;&#039;class&#039;] ) ? explode( &#039; &#039;, $atts&#91;&#039;class&#039;] ) : &#91;];\n\n\t\t$classes&#91;] = &#039;content-control-container&#039;;\n\t\t\/\/ @deprecated 2.0.0\n\t\t$classes&#91;] = &#039;jp-cc&#039;;\n\n\t\tif ( user_meets_requirements( $atts&#91;&#039;status&#039;], $user_roles, $match_type ) ) {\n\t\t\t$classes&#91;] = &#039;content-control-accessible&#039;;\n\t\t\t\/\/ @deprecated 2.0.0\n\t\t\t$classes&#91;] = &#039;jp-cc-accessible&#039;;\n\t\t\t$container = &#039;&lt;div class=&quot;%1$s&quot;&gt;%2$s&lt;\/div&gt;&#039;;\n\t\t} else {\n\t\t\t$classes&#91;] = &#039;content-control-not-accessible&#039;;\n\t\t\t\/\/ @deprecated 2.0.0\n\t\t\t$classes&#91;] = &#039;jp-cc-not-accessible&#039;;\n\t\t\t$container = &#039;&lt;div class=&quot;%1$s&quot;&gt;%3$s&lt;\/div&gt;&#039;;\n\t\t}\n\n\t\t$classes = implode( &#039; &#039;, $classes );\n\n\t\treturn sprintf( $container, esc_attr( $classes ), do_shortcode( $content ), do_shortcode( $atts&#91;&#039;message&#039;] ) );\n\t}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Code file location<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">content-control\/content-control\/classes\/Controllers\/Shortcodes.php<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you&#8217;ve learned how to embed the <strong>Content Control Plugin shortcode<\/strong>, understood the parameters, and seen code examples, it&#8217;s easy to use and debug any issue that might cause it to &#8216;not work&#8217;. If you still have difficulties with it, don&#8217;t hesitate to leave a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below, you&#8217;ll find a detailed guide on how to add the Content Control Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we&#8217;ll assist you with common issues that might cause the Content Control Plugin shortcode not to show or not to work correctly. Before starting, here is an overview [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"name":"Content Control &#8211; The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks &amp; More","slug":"","version":"2.0.11","author":"<a href=\"https:\/\/code-atlantic.com\/?utm_campaign=plugin-info&utm_source=php-file-header&utm_medium=plugin-ui&utm_content=author-uri\">Code Atlantic<\/a>","icons":"https:\/\/ps.w.org\/content-control\/assets\/icon-128x128.gif?rev=2968535","plugin_tags":"{\"access-control\":\"access-control\",\"content\":\"content\",\"content-restriction\":\"content restriction\",\"permission\":\"permission\",\"private\":\"private\"}","author_profile":"https:\/\/profiles.wordpress.org\/codeatlantic\/","requires":"5.6","tested":"6.3.2","requires_php":"5.6","rating":98,"num_ratings":486,"active_installs":40000,"downloaded":400037,"last_updated":"2023-10-05 12:07am GMT","added":"2016-09-30","homepage":"https:\/\/contentcontrolplugin.com\/?utm_campaign=plugin-info&utm_source=php-file-header&utm_medium=plugin-ui&utm_content=plugin-uri","short_description":"Unleash your WordPress content&#039;s potential! With Content Control, restrict your content, pages, posts, widgets, and even individual blocks with p &hellip;","description":"Content Control is the ultimate plugin for WordPress, allowing you to restrict content, create conditional blocks, and more. Customize your content visibility with ease using this powerful tool.","shortcodes":"[\"content_control\"]","footnotes":""},"categories":[1],"tags":[],"class_list":["post-643","post","type-post","status-publish","format-standard","hentry","category-plugins"],"_links":{"self":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/comments?post=643"}],"version-history":[{"count":1,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/643\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/643\/revisions\/785"}],"wp:attachment":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/media?parent=643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/categories?post=643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/tags?post=643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}