{"id":4214,"date":"2020-09-04T15:21:26","date_gmt":"2020-09-04T12:21:26","guid":{"rendered":"https:\/\/www.margarit.com.tr\/?p=4214"},"modified":"2020-09-10T00:46:59","modified_gmt":"2020-09-09T21:46:59","slug":"wordpress-backend-ve-ust-bar-erisimini-engellemek","status":"publish","type":"post","link":"https:\/\/www.margarit.com.tr\/en\/wordpress-backend-ve-ust-bar-erisimini-engellemek\/","title":{"rendered":"Blocking WordPress Backend and Top Bar Access"},"content":{"rendered":"<p>To prevent unauthorized users from accessing the WordPress backplane:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>wpse_11244_restrict_admin() { if ( ! current_user_can( &#039;manage_options&#039; ) ) { wp_die( __(&#039;You are not allowed to access this part of the site&#039;) ); } } add_action( &#039;admin_init&#039;, &#039;wpse_11244_restrict_admin&#039;, 1 );<\/code><\/pre><\/div>\n\n\n\n<p>To allow an unwanted user accessing the WordPress backplane to access the homepage:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>function wpse_11244_restrict_admin() { if ( ! current_user_can( &#039;manage_options&#039; ) &amp;&amp; $_SERVER[&#039;PHP_SELF&#039;] != &#039;\/wp-ajax.\/phpurl1; { } } add_action( &#039;admin_init&#039;, &#039;wpse_11244_restrict_admin&#039;, 1 );<\/code><\/pre><\/div>\n\n\n\n<p>To block the appearance of the WordPress admin top bar and menu:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>&lt;?php show_admin_bar(false); ?&gt;<\/code><\/pre><\/div>\n\n\n\n<p>Just add it to your theme&#039;s .functions.php file.<\/p>\n\n\n\n<p>As a last alternative, if you want the admin bar to be visible only to administrators and closed to all other roles:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>add_action(&#039;after_setup_theme&#039;, &#039;remove_admin_bar&#039;);function remove_admin_bar() { if (!current_user_can(&#039;administrator&#039;) &amp;&amp; !is_admin() {bar(show)) } }<\/code><\/pre><\/div>\n\n\n\n<p>Just add the codes to your theme&#039;s .functions.php file.<\/p>","protected":false},"excerpt":{"rendered":"<p>You can use these codes to prevent unauthorized users from accessing the WordPress back panel.<\/p>","protected":false},"author":1,"featured_media":4284,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[161,160,163,162],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/posts\/4214"}],"collection":[{"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/comments?post=4214"}],"version-history":[{"count":1,"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/posts\/4214\/revisions"}],"predecessor-version":[{"id":4215,"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/posts\/4214\/revisions\/4215"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/media\/4284"}],"wp:attachment":[{"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/media?parent=4214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/categories?post=4214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.margarit.com.tr\/en\/wp-json\/wp\/v2\/tags?post=4214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}