snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#11512

PHP

add drupal permission for certain role

1
2
3
4
5
6
7
8
<?
$perm = db_result(db_query("SELECT perm from {permission} where rid=5"));
    $perm_arr = explode(',', $perm);
    $perm_arr[] = 'schedule (un)publishing of nodes';
    $ret[] = update_sql("UPDATE {permission} SET perm='" . implode(',', $perm_arr) .  "' where rid=5");

    cache_clear_all();
?>
https://snipt.net/embed/5c6639606dff7d78be0796e92f6800d9/
https://snipt.net/raw/5c6639606dff7d78be0796e92f6800d9/
5c6639606dff7d78be0796e92f6800d9
php
PHP
8
2014-04-25T00:36:57
True
False
/api/public/snipt/11512/
add-drupal-permission-for-certain-role
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$perm</span> <span class="o">=</span> <span class="nx">db_result</span><span class="p">(</span><span class="nx">db_query</span><span class="p">(</span><span class="s2">&quot;SELECT perm from {permission} where rid=5&quot;</span><span class="p">));</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$perm_arr</span> <span class="o">=</span> <span class="nb">explode</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="nv">$perm</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$perm_arr</span><span class="p">[]</span> <span class="o">=</span> <span class="s1">&#39;schedule (un)publishing of nodes&#39;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="nv">$ret</span><span class="p">[]</span> <span class="o">=</span> <span class="nx">update_sql</span><span class="p">(</span><span class="s2">&quot;UPDATE {permission} SET perm=&#39;&quot;</span> <span class="o">.</span> <span class="nb">implode</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="nv">$perm_arr</span><span class="p">)</span> <span class="o">.</span> <span class="s2">&quot;&#39; where rid=5&quot;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a> <span class="nx">cache_clear_all</span><span class="p">();</span> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
drupal, permission, programmatically, user