{"id":8289165,"date":"2016-10-13T06:08:04","date_gmt":"2016-10-13T06:08:04","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/change-plugin-option-from-function-php\/"},"modified":"2016-10-13T06:08:04","modified_gmt":"2016-10-13T06:08:04","slug":"change-plugin-option-from-function-php","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/change-plugin-option-from-function-php\/","title":{"rendered":"Change plugin option from function.php"},"content":{"rendered":"<p>Hi there,<\/p>\n<p>For my website I&#8217;m using the plugin <a href=\"https:\/\/codecanyon.net\/item\/woocommerce-variations-to-table-grid\/10494620\">Woocommerce Variations to Table Grid<\/a>, but I would like to restrict this one only for some roles &#8216;Administrator&#8217; and &#8216;wholesaler&#8217;. (my website is for wholesalers and &#8216;normal&#8217; customer)<\/p>\n<p>Anyway I was thinking to just desactivate the plugin by checking the user role so I tried the following solution : http:\/\/wordpress.stackexchange.com\/questions\/159085\/deactivate-plugin-for-a-specific-user-group<br \/>\nDoesn&#8217;t work.<\/p>\n<p>I&#8217;ve got a variable in my plugin called $vartable_disabled which is a boolean which &#8220;Disable globally&#8221; the plugin.<\/p>\n<p>So I am thinking to do something in my functions.php like:<\/p>\n<pre><code>add_action(&#039;admin_init&#039;, &#039;my_option_change_plugins&#039;);    \nfunction my_option_change_plugins()\n{\n    global $current_user;\n    if (!in_array(&#039;administrator&#039; || &#039;wholesaler&#039;, $current_user-&gt;roles)) {\n        deactivate_plugins( \/\/ activate for variation-table\n\t\t\t$vartable_disabled == 0\n                        $vartable_position == &#039;under&#039;\n        );\n    } else { \/\/ desactivate for those than can&#039;t use it\n        activate_plugins(\n\t\t\t$vartable_disabled == 1\n                        $vartable_position == &#039;side&#039;\n        );\n    }<\/code><\/pre>\n<p>But for sure I&#8217;m doing something wrong, I tried plenty of different thing the whole day, impossible to figure it out.<\/p>\n<p>Anyone can help?<\/p>\n<p>Cheers \ud83d\ude42<\/p>\n","protected":false},"template":"","class_list":["post-8289165","topic","type-topic","status-publish","hentry","topic-tag-function-php","topic-tag-variation"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8289165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8289165\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=8289165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}