Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

Add Gravity Forms and menus access to Editor users

1
2
3
4
5
6
7
<?php
function add_editor_cap(){
    $role = get_role('editor');
    $role->add_cap('gform_full_access'); // Gravity Forms
    $role->add_cap('edit_theme_options'); // Appearance menu
}
add_action('admin_init','add_editor_cap');
https://snipt.net/embed/b425bed94d5ee521f785ee42c150761a/
https://snipt.net/raw/b425bed94d5ee521f785ee42c150761a/
b425bed94d5ee521f785ee42c150761a
php
PHP
7
2016-12-06T04:27:51
True
False
False
Feb 16, 2016 at 12:17 PM
/api/public/snipt/144290/
add-gravity-forms-and-menus-access-to-editor-users
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">add_editor_cap</span><span class="p">(){</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$role</span> <span class="o">=</span> <span class="nx">get_role</span><span class="p">(</span><span class="s1">&#39;editor&#39;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$role</span><span class="o">-&gt;</span><span class="na">add_cap</span><span class="p">(</span><span class="s1">&#39;gform_full_access&#39;</span><span class="p">);</span> <span class="c1">// Gravity Forms</span> </span><span id="L-5"><a name="L-5"></a> <span class="nv">$role</span><span class="o">-&gt;</span><span class="na">add_cap</span><span class="p">(</span><span class="s1">&#39;edit_theme_options&#39;</span><span class="p">);</span> <span class="c1">// Appearance menu</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span><span id="L-7"><a name="L-7"></a><span class="nx">add_action</span><span class="p">(</span><span class="s1">&#39;admin_init&#39;</span><span class="p">,</span><span class="s1">&#39;add_editor_cap&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
users, wordpress

PHP

Get current author's role

1
2
3
4
5
6
7
8
<?php
function get_author_role() {
    global $authordata;
    $author_roles = $authordata->roles;
    $author_role = array_shift($author_roles);
    return $author_role;
}
word
https://snipt.net/embed/0416b0ef3f3f1edc6af2ca6ff767b979/
https://snipt.net/raw/0416b0ef3f3f1edc6af2ca6ff767b979/
0416b0ef3f3f1edc6af2ca6ff767b979
php
PHP
8
2016-12-06T12:47:21
True
False
False
Feb 16, 2016 at 12:12 PM
/api/public/snipt/144281/
get-current-authors-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></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">get_author_role</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">global</span> <span class="nv">$authordata</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$author_roles</span> <span class="o">=</span> <span class="nv">$authordata</span><span class="o">-&gt;</span><span class="na">roles</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="nv">$author_role</span> <span class="o">=</span> <span class="nb">array_shift</span><span class="p">(</span><span class="nv">$author_roles</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">return</span> <span class="nv">$author_role</span><span class="p">;</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span><span id="L-8"><a name="L-8"></a><span class="nx">word</span> </span></pre></div> </td></tr></table>
users, wordpress

Bash

On Mac OS X you have to add the encrypted version of the user's password when using subversion with apache.

# as_root command arg file username password
sudo htpasswd -b passwd user userpassword
https://snipt.net/embed/f1b65b79bbe82fab33ccdced43b4c391/
https://snipt.net/raw/f1b65b79bbe82fab33ccdced43b4c391/
f1b65b79bbe82fab33ccdced43b4c391
bash
Bash
2
2016-12-07T12:34:01
True
False
False
/api/public/snipt/2082/
on-mac-os-x-you-have-to-add-the-encrypted-version-of-the-users-password-when-using-subversion-with-apache
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># as_root command arg file username password</span> </span><span id="L-2"><a name="L-2"></a>sudo htpasswd -b passwd user userpassword </span></pre></div> </td></tr></table>
apache, encrypted, file, passwd, password, subversion, svn, users
Copyrighted, illegal, or inappropriate content? Email [email protected].